Diff
Modified: trunk/Source/WebCore/ChangeLog (238696 => 238697)
--- trunk/Source/WebCore/ChangeLog 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/ChangeLog 2018-11-29 22:59:07 UTC (rev 238697)
@@ -1,3 +1,24 @@
+2018-11-29 Megan Gardner <megan_gard...@apple.com>
+
+ Move Lookup Code for better cross platform usage
+ https://bugs.webkit.org/show_bug.cgi?id=191732
+
+ Reviewed by Alex Christensen.
+
+ Not currenlty testable
+
+ DictionaryLookup uses Reveal now, which is slated to be cross-platform.
+ That patch gates the parts of DictionaryLookup that currently do not have
+ an available implementation on iOS. Once Reveal is ready, this code will be
+ replaced or expanded upon, as appropriate.
+
+ * editing/mac/DictionaryLookup.h:
+ * editing/mac/DictionaryLookup.mm:
+ (WebCore::showPopupOrCreateAnimationController):
+ (WebCore::DictionaryLookup::showPopup):
+ (WebCore::DictionaryLookup::hidePopup):
+ (WebCore::DictionaryLookup::animationControllerForPopup):
+
2018-11-29 Joseph Pecoraro <pecor...@apple.com>
[Cocoa] Move ServerTimingParser.* into a better group in the Xcode project
Modified: trunk/Source/WebCore/PAL/ChangeLog (238696 => 238697)
--- trunk/Source/WebCore/PAL/ChangeLog 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/PAL/ChangeLog 2018-11-29 22:59:07 UTC (rev 238697)
@@ -1,3 +1,13 @@
+2018-11-29 Megan Gardner <megan_gard...@apple.com>
+
+ Move Lookup Code for better cross platform usage
+ https://bugs.webkit.org/show_bug.cgi?id=191732
+
+ Reviewed by Alex Christensen.
+
+ * pal/spi/mac/LookupSPI.h:
+ * pal/spi/mac/RevealSPI.h:
+
2018-11-29 Eric Carlson <eric.carl...@apple.com>
[iOS] Tell AirPlay picker when a file has video
Modified: trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj (238696 => 238697)
--- trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj 2018-11-29 22:59:07 UTC (rev 238697)
@@ -406,6 +406,7 @@
0C2DA1391F3BEB4900DBC317 /* PassKitSPI.h */,
0C2DA13A1F3BEB4900DBC317 /* pthreadSPI.h */,
0C2DA13B1F3BEB4900DBC317 /* QuartzCoreSPI.h */,
+ 442956CC218A72DE0080DB54 /* RevealSPI.h */,
570AB8F020AE2E8D00B8BE87 /* SecKeyProxySPI.h */,
0C2DA13C1F3BEB4900DBC317 /* ServersSPI.h */,
0C2DA12B1F3BEB4900DBC317 /* URLFormattingSPI.h */,
@@ -471,7 +472,6 @@
0C7785861F45130F00F4EBB6 /* QTKitSPI.h */,
A102658A1F56748C00B4C844 /* QuickDrawSPI.h */,
0C7785871F45130F00F4EBB6 /* QuickLookMacSPI.h */,
- 442956CC218A72DE0080DB54 /* RevealSPI.h */,
A1175B481F6AFF8E00C4B9F0 /* SpeechSynthesisSPI.h */,
0C7785881F45130F00F4EBB6 /* TUCallSPI.h */,
);
Copied: trunk/Source/WebCore/PAL/pal/spi/cocoa/RevealSPI.h (from rev 238696, trunk/Source/WebCore/PAL/pal/spi/mac/RevealSPI.h) (0 => 238697)
--- trunk/Source/WebCore/PAL/pal/spi/cocoa/RevealSPI.h (rev 0)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/RevealSPI.h 2018-11-29 22:59:07 UTC (rev 238697)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <objc/runtime.h>
+#if PLATFORM(MAC)
+#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
+#endif // PLATFORM(MAC)
+#import <wtf/SoftLinking.h>
+
+SOFT_LINK_PRIVATE_FRAMEWORK(Reveal)
+SOFT_LINK_PRIVATE_FRAMEWORK(RevealCore)
+SOFT_LINK_CLASS_OPTIONAL(Reveal, RVPresenter)
+SOFT_LINK_CLASS_OPTIONAL(Reveal, RVPresentingContext)
+SOFT_LINK_CLASS_OPTIONAL(RevealCore, RVItem)
+SOFT_LINK_CLASS_OPTIONAL(RevealCore, RVSelection)
+
+#if ENABLE(REVEAL)
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#if PLATFORM(MAC)
+#import <Reveal/RVPresenter.h>
+#import <Reveal/Reveal.h>
+#endif // PLATFORM(MAC)
+#import <RevealCore/RVSelection.h>
+#import <RevealCore/RevealCore.h>
+
+#else // USE(APPLE_INTERNAL_SDK)
+
+
+@protocol RVPresenterHighlightDelegate;
+
+@interface RVItem : NSObject <NSSecureCoding>
+- (instancetype)initWithText:(NSString *)text selectedRange:(NSRange)selectedRange NS_DESIGNATED_INITIALIZER;
+@end
+
+@interface RVSelection : NSObject
++ (NSRange)revealRangeAtIndex:(NSUInteger)clickIndex selectedRanges:(NSArray <NSValue *> *)selectedRanges shouldUpdateSelection:(BOOL *)shouldUpdateSelection;
+@end
+
+#if PLATFORM(MAC)
+@interface RVPresentingContext : NSObject
+- (instancetype)initWithPointerLocationInView:(NSPoint)pointerLocationInView inView:(NSView *)view highlightDelegate:(id<RVPresenterHighlightDelegate>)highlightDelegate;
+@end
+#endif
+
+@protocol RVPresenterHighlightDelegate <NSObject>
+@required
+- (NSArray <NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item;
+@optional
+- (void)revealContext:(RVPresentingContext *)context stopHighlightingItem:(RVItem *)item;
+- (void)revealContext:(RVPresentingContext *)context drawRectsForItem:(RVItem *)item;
+@end
+
+@interface RVDocumentContext : NSObject < NSSecureCoding >
+@end
+
+@interface RVPresenter : NSObject
+#if PLATFORM(MAC)
+- (id<NSImmediateActionAnimationController>)animationControllerForItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options;
+#endif // PLATFORM(MAC)
+- (BOOL)revealItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options;
+@end
+
+#endif // !USE(APPLE_INTERNAL_SDK)
+
+#endif // ENABLE(REVEAL)
Modified: trunk/Source/WebCore/PAL/pal/spi/mac/LookupSPI.h (238696 => 238697)
--- trunk/Source/WebCore/PAL/pal/spi/mac/LookupSPI.h 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/LookupSPI.h 2018-11-29 22:59:07 UTC (rev 238697)
@@ -23,12 +23,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+
+#if PLATFORM(MAC)
+
#import <objc/runtime.h>
#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
#import <wtf/SoftLinking.h>
-#if PLATFORM(MAC)
-
SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(Lookup)
SOFT_LINK_CLASS_OPTIONAL(Lookup, LULookupDefinitionModule)
Deleted: trunk/Source/WebCore/PAL/pal/spi/mac/RevealSPI.h (238696 => 238697)
--- trunk/Source/WebCore/PAL/pal/spi/mac/RevealSPI.h 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/RevealSPI.h 2018-11-29 22:59:07 UTC (rev 238697)
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import <objc/runtime.h>
-#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
-#import <wtf/SoftLinking.h>
-
-SOFT_LINK_PRIVATE_FRAMEWORK(Reveal)
-SOFT_LINK_PRIVATE_FRAMEWORK(RevealCore)
-SOFT_LINK_CLASS_OPTIONAL(Reveal, RVPresenter)
-SOFT_LINK_CLASS_OPTIONAL(Reveal, RVPresentingContext)
-SOFT_LINK_CLASS_OPTIONAL(RevealCore, RVItem)
-SOFT_LINK_CLASS_OPTIONAL(RevealCore, RVSelection)
-
-#if USE(APPLE_INTERNAL_SDK)
-
-#import <Reveal/RVPresenter.h>
-#import <Reveal/Reveal.h>
-#import <RevealCore/RVSelection.h>
-#import <RevealCore/RevealCore.h>
-
-
-#else
-
-@interface RVItem : NSObject <NSSecureCoding>
-- (instancetype)initWithText:(NSString *)text selectedRange:(NSRange)selectedRange NS_DESIGNATED_INITIALIZER;
-@end
-
-@interface RVSelection : NSObject
-+ (NSRange)revealRangeAtIndex:(NSUInteger)clickIndex selectedRanges:(NSArray <NSValue *> *)selectedRanges shouldUpdateSelection:(BOOL *)shouldUpdateSelection;
-@end
-
-@interface RVPresenter : NSObject
-- (id<NSImmediateActionAnimationController>)animationControllerForItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options;
-- (BOOL)revealItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options;
-@end
-
-#endif // !USE(APPLE_INTERNAL_SDK)
Modified: trunk/Source/WebCore/SourcesCocoa.txt (238696 => 238697)
--- trunk/Source/WebCore/SourcesCocoa.txt 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2018-11-29 22:59:07 UTC (rev 238697)
@@ -77,6 +77,7 @@
editing/SmartReplaceCF.cpp
editing/cocoa/DataDetection.mm
+editing/cocoa/DictionaryLookup.mm
editing/cocoa/EditorCocoa.mm
editing/cocoa/FontAttributeChangesCocoa.mm
editing/cocoa/FontAttributesCocoa.mm
@@ -90,7 +91,6 @@
editing/ios/EditorIOS.mm
editing/mac/AlternativeTextUIController.mm
-editing/mac/DictionaryLookup.mm
editing/mac/DictionaryLookupLegacy.mm
editing/mac/EditorMac.mm
editing/mac/FrameSelectionMac.mm
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (238696 => 238697)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-11-29 22:59:07 UTC (rev 238697)
@@ -20520,6 +20520,7 @@
children = (
C5227DEF1C3C6DD700F5ED54 /* DataDetection.h */,
C5227DF01C3C6DD700F5ED54 /* DataDetection.mm */,
+ 937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */,
9B55EEE81B3E8898005342BC /* EditorCocoa.mm */,
F42CEB54214031EE002DCA72 /* FontAttributeChangesCocoa.mm */,
F48D2A752156FE5700C6752B /* FontAttributesCocoa.mm */,
@@ -26228,7 +26229,6 @@
CE7B2DAF1586ABAD0098B3FA /* AlternativeTextUIController.h */,
CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */,
937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */,
- 937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */,
442956CA218A6D300080DB54 /* DictionaryLookupLegacy.mm */,
ED501DC50B249F2900AE18D9 /* EditorMac.mm */,
4A8C96EA0BE69032004EEFF0 /* FrameSelectionMac.mm */,
Copied: trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm (from rev 238696, trunk/Source/WebCore/editing/mac/DictionaryLookup.mm) (0 => 238697)
--- trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -0,0 +1,433 @@
+/*
+ * Copyright (C) 2014-2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "DictionaryLookup.h"
+
+#if PLATFORM(COCOA)
+
+#if ENABLE(REVEAL)
+
+#import "Document.h"
+#import "Editing.h"
+#import "FocusController.h"
+#import "Frame.h"
+#import "FrameSelection.h"
+#import "HTMLConverter.h"
+#import "HitTestResult.h"
+#import "NotImplemented.h"
+#import "Page.h"
+#import "Range.h"
+#import "RenderObject.h"
+#import "TextIterator.h"
+#import "VisiblePosition.h"
+#import "VisibleSelection.h"
+#import "VisibleUnits.h"
+#import <pal/spi/cocoa/RevealSPI.h>
+#import <pal/spi/mac/LookupSPI.h>
+#import <wtf/BlockObjCExceptions.h>
+#import <wtf/RefPtr.h>
+
+#if !PLATFORM(WATCH)
+
+#import <PDFKit/PDFKit.h>
+
+#endif // !PLATFORM(WATCH)
+
+#if PLATFORM(MAC)
+
+@interface WebRevealHighlight <RVPresenterHighlightDelegate> : NSObject {
+@private
+ Function<void()> _clearTextIndicator;
+ NSRect _highlightRect;
+ BOOL _useDefaultHighlight;
+ NSAttributedString *_attributedString;
+}
+
+@property (nonatomic, readonly) NSRect highlightRect;
+@property (nonatomic, readonly) BOOL useDefaultHighlight;
+@property (nonatomic, readonly) NSAttributedString *attributedString;
+
+- (instancetype)initWithHighlightRect:(NSRect)highlightRect useDefaultHighlight:(BOOL)useDefaultHighlight attributedString:(NSAttributedString *) attributedString;
+- (void)setClearTextIndicator:(Function<void()>&&)clearTextIndicator;
+
+@end
+
+@implementation WebRevealHighlight
+
+@synthesize highlightRect=_highlightRect;
+@synthesize useDefaultHighlight=_useDefaultHighlight;
+@synthesize attributedString=_attributedString;
+
+- (instancetype)initWithHighlightRect:(NSRect)highlightRect useDefaultHighlight:(BOOL)useDefaultHighlight attributedString:(NSAttributedString *) attributedString
+{
+ if (!(self = [super init]))
+ return nil;
+
+ _highlightRect = highlightRect;
+ _useDefaultHighlight = useDefaultHighlight;
+ _attributedString = attributedString;
+
+ return self;
+}
+
+- (void)setClearTextIndicator:(Function<void()>&&)clearTextIndicator
+{
+ _clearTextIndicator = WTFMove(clearTextIndicator);
+}
+
+- (NSArray<NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(item);
+ return @[[NSValue valueWithRect:self.highlightRect]];
+}
+
+- (void)revealContext:(RVPresentingContext *)context drawRectsForItem:(RVItem *)item
+{
+ UNUSED_PARAM(item);
+
+ for (NSValue *rectVal in context.itemRectsInView) {
+ NSRect rect = rectVal.rectValue;
+
+ // Get current font attributes from the attributed string above, and add paragraph style attribute in order to center text.
+ RetainPtr<NSMutableDictionary> attributes = adoptNS([[NSMutableDictionary alloc] initWithDictionary:[self.attributedString fontAttributesInRange:NSMakeRange(0, [self.attributedString length])]]);
+ RetainPtr<NSMutableParagraphStyle> paragraph = adoptNS([[NSMutableParagraphStyle alloc] init]);
+ [paragraph setAlignment:NSTextAlignmentCenter];
+ [attributes setObject:paragraph.get() forKey:NSParagraphStyleAttributeName];
+
+ RetainPtr<NSAttributedString> string = adoptNS([[NSAttributedString alloc] initWithString:[self.attributedString string] attributes:attributes.get()]);
+ [string drawInRect:rect];
+ }
+}
+
+- (BOOL)revealContext:(RVPresentingContext *)context shouldUseDefaultHighlightForItem:(RVItem *)item
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(item);
+ return self.useDefaultHighlight;
+}
+
+- (void)revealContext:(RVPresentingContext *)context stopHighlightingItem:(RVItem *)item
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(item);
+ auto block = WTFMove(_clearTextIndicator);
+ if (block)
+ block();
+}
+
+@end
+
+#endif // PLATFORM(MAC)
+
+#endif // ENABLE(REVEAL)
+
+namespace WebCore {
+
+#if ENABLE(REVEAL)
+
+std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection& selection)
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+ if (!getRVItemClass())
+ return { nullptr, nil };
+
+ auto selectedRange = selection.toNormalizedRange();
+ if (!selectedRange)
+ return { nullptr, nil };
+
+ // Since we already have the range we want, we just need to grab the returned options.
+ auto selectionStart = selection.visibleStart();
+ auto selectionEnd = selection.visibleEnd();
+
+ // As context, we are going to use the surrounding paragraphs of text.
+ auto paragraphStart = startOfParagraph(selectionStart);
+ auto paragraphEnd = endOfParagraph(selectionEnd);
+
+ int lengthToSelectionStart = TextIterator::rangeLength(makeRange(paragraphStart, selectionStart).get());
+ int lengthToSelectionEnd = TextIterator::rangeLength(makeRange(paragraphStart, selectionEnd).get());
+ NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, lengthToSelectionEnd - lengthToSelectionStart);
+
+ RefPtr<Range> fullCharacterRange = makeRange(paragraphStart, paragraphEnd);
+ String itemString = plainText(fullCharacterRange.get());
+ RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:rangeToPass]);
+ NSRange highlightRange = item.get().highlightRange;
+
+ return { TextIterator::subrange(*fullCharacterRange, highlightRange.location, highlightRange.length), nil };
+
+ END_BLOCK_OBJC_EXCEPTIONS;
+
+ return { nullptr, nil };
+}
+
+std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeAtHitTestResult(const HitTestResult& hitTestResult)
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+ if (!getRVItemClass())
+ return { nullptr, nil };
+
+ auto* node = hitTestResult.innerNonSharedNode();
+ if (!node || !node->renderer())
+ return { nullptr, nil };
+
+ auto* frame = node->document().frame();
+ if (!frame)
+ return { nullptr, nil };
+
+ // Don't do anything if there is no character at the point.
+ auto framePoint = hitTestResult.roundedPointInInnerNodeFrame();
+ if (!frame->rangeForPoint(framePoint))
+ return { nullptr, nil };
+
+ auto position = frame->visiblePositionForPoint(framePoint);
+ if (position.isNull())
+ position = firstPositionInOrBeforeNode(node);
+
+ auto selection = frame->page()->focusController().focusedOrMainFrame().selection().selection();
+ NSRange selectionRange;
+ int hitIndex;
+ RefPtr<Range> fullCharacterRange;
+
+ if (selection.selectionType() == VisibleSelection::RangeSelection) {
+ auto selectionStart = selection.visibleStart();
+ auto selectionEnd = selection.visibleEnd();
+
+ // As context, we are going to use the surrounding paragraphs of text.
+ auto paragraphStart = startOfParagraph(selectionStart);
+ auto paragraphEnd = endOfParagraph(selectionEnd);
+
+ auto rangeToSelectionStart = makeRange(paragraphStart, selectionStart);
+ auto rangeToSelectionEnd = makeRange(paragraphStart, selectionEnd);
+
+ fullCharacterRange = makeRange(paragraphStart, paragraphEnd);
+
+ selectionRange = NSMakeRange(TextIterator::rangeLength(rangeToSelectionStart.get()), TextIterator::rangeLength(makeRange(selectionStart, selectionEnd).get()));
+
+ hitIndex = TextIterator::rangeLength(makeRange(paragraphStart, position).get());
+ } else {
+ VisibleSelection selectionAccountingForLineRules { position };
+ selectionAccountingForLineRules.expandUsingGranularity(WordGranularity);
+ position = selectionAccountingForLineRules.start();
+ // As context, we are going to use 250 characters of text before and after the point.
+ fullCharacterRange = rangeExpandedAroundPositionByCharacters(position, 250);
+
+ if (!fullCharacterRange)
+ return { nullptr, nil };
+
+ selectionRange = NSMakeRange(NSNotFound, 0);
+ hitIndex = TextIterator::rangeLength(makeRange(fullCharacterRange->startPosition(), position).get());
+ }
+
+ NSRange selectedRange = [getRVSelectionClass() revealRangeAtIndex:hitIndex selectedRanges:@[[NSValue valueWithRange:selectionRange]] shouldUpdateSelection:nil];
+
+ String itemString = plainText(fullCharacterRange.get());
+ RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:selectedRange]);
+ NSRange highlightRange = item.get().highlightRange;
+
+ if (highlightRange.location == NSNotFound || !highlightRange.length)
+ return { nullptr, nil };
+
+ return { TextIterator::subrange(*fullCharacterRange, highlightRange.location, highlightRange.length), nil };
+
+ END_BLOCK_OBJC_EXCEPTIONS;
+
+ return { nullptr, nil };
+
+}
+
+#if !PLATFORM(WATCH)
+
+static void expandSelectionByCharacters(PDFSelection *selection, NSInteger numberOfCharactersToExpand, NSInteger& charactersAddedBeforeStart, NSInteger& charactersAddedAfterEnd)
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+ size_t originalLength = selection.string.length;
+ [selection extendSelectionAtStart:numberOfCharactersToExpand];
+
+ charactersAddedBeforeStart = selection.string.length - originalLength;
+
+ [selection extendSelectionAtEnd:numberOfCharactersToExpand];
+ charactersAddedAfterEnd = selection.string.length - originalLength - charactersAddedBeforeStart;
+
+ END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+std::tuple<NSString *, NSDictionary *> DictionaryLookup::stringForPDFSelection(PDFSelection *selection)
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+ if (!getRVItemClass())
+ return { nullptr, nil };
+
+ // Don't do anything if there is no character at the point.
+ if (!selection || !selection.string.length)
+ return { @"", nil };
+
+ RetainPtr<PDFSelection> selectionForLookup = adoptNS([selection copy]);
+
+ // As context, we are going to use 250 characters of text before and after the point.
+ auto originalLength = [selectionForLookup string].length;
+ NSInteger charactersAddedBeforeStart = 0;
+ NSInteger charactersAddedAfterEnd = 0;
+ expandSelectionByCharacters(selectionForLookup.get(), 250, charactersAddedBeforeStart, charactersAddedAfterEnd);
+
+ auto fullPlainTextString = [selectionForLookup string];
+ auto rangeToPass = NSMakeRange(charactersAddedBeforeStart, 0);
+
+ RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:fullPlainTextString selectedRange:rangeToPass]);
+ NSRange extractedRange = item.get().highlightRange;
+
+ if (extractedRange.location == NSNotFound)
+ return { selection.string, nil };
+
+ NSInteger lookupAddedBefore = rangeToPass.location - extractedRange.location;
+ NSInteger lookupAddedAfter = (extractedRange.location + extractedRange.length) - (rangeToPass.location + originalLength);
+
+ [selection extendSelectionAtStart:lookupAddedBefore];
+ [selection extendSelectionAtEnd:lookupAddedAfter];
+
+ ASSERT([selection.string isEqualToString:[fullPlainTextString substringWithRange:extractedRange]]);
+ return { selection.string, nil };
+
+ END_BLOCK_OBJC_EXCEPTIONS;
+
+ return { @"", nil };
+}
+
+#endif // !PLATFORM(WATCH)
+
+static WKRevealController showPopupOrCreateAnimationController(bool createAnimationController, const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
+{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+#if PLATFORM(MAC)
+
+ if (!getRVItemClass() || !getRVPresenterClass())
+ return nil;
+
+ RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([[NSMutableDictionary alloc] init]);
+ if (NSDictionary *options = dictionaryPopupInfo.options.get())
+ [mutableOptions addEntriesFromDictionary:options];
+
+ auto textIndicator = TextIndicator::create(dictionaryPopupInfo.textIndicator);
+
+ RetainPtr<RVPresenter> presenter = adoptNS([allocRVPresenterInstance() init]);
+
+ NSRect highlightRect;
+ NSPoint pointerLocation;
+
+ if (textIndicator.get().contentImage()) {
+ textIndicatorInstallationCallback(textIndicator.get());
+
+ FloatRect firstTextRectInViewCoordinates = textIndicator.get().textRectsInBoundingRectCoordinates()[0];
+ FloatRect textBoundingRectInViewCoordinates = textIndicator.get().textBoundingRectInRootViewCoordinates();
+ FloatRect selectionBoundingRectInViewCoordinates = textIndicator.get().selectionRectInRootViewCoordinates();
+
+ if (rootViewToViewConversionCallback) {
+ textBoundingRectInViewCoordinates = rootViewToViewConversionCallback(textBoundingRectInViewCoordinates);
+ selectionBoundingRectInViewCoordinates = rootViewToViewConversionCallback(selectionBoundingRectInViewCoordinates);
+ }
+
+ firstTextRectInViewCoordinates.moveBy(textBoundingRectInViewCoordinates.location());
+ highlightRect = selectionBoundingRectInViewCoordinates;
+ pointerLocation = firstTextRectInViewCoordinates.location();
+
+ } else {
+ NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
+
+ highlightRect = textIndicator->selectionRectInRootViewCoordinates();
+ pointerLocation = [view convertPoint:textBaselineOrigin toView:nil];
+ }
+
+ RetainPtr<WebRevealHighlight> webHighlight = adoptNS([[WebRevealHighlight alloc] initWithHighlightRect: highlightRect useDefaultHighlight:!textIndicator.get().contentImage() attributedString:dictionaryPopupInfo.attributedString.get()]);
+ RetainPtr<RVPresentingContext> context = adoptNS([allocRVPresentingContextInstance() initWithPointerLocationInView:pointerLocation inView:view highlightDelegate:(id<RVPresenterHighlightDelegate>) webHighlight.get()]);
+
+ RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:dictionaryPopupInfo.attributedString.get().string selectedRange:NSMakeRange(0, 0)]);
+
+ [webHighlight setClearTextIndicator:[webHighlight = WTFMove(webHighlight), clearTextIndicator = WTFMove(clearTextIndicator)] {
+ if (clearTextIndicator)
+ clearTextIndicator();
+ }];
+
+ if (createAnimationController)
+ return [presenter animationControllerForItem:item.get() documentContext:nil presentingContext:context.get() options:nil];
+ [presenter revealItem:item.get() documentContext:nil presentingContext:context.get() options:nil];
+ return nil;
+
+#else // PLATFORM(MAC)
+
+ UNUSED_PARAM(createAnimationController);
+ UNUSED_PARAM(dictionaryPopupInfo);
+ UNUSED_PARAM(view);
+ UNUSED_PARAM(textIndicatorInstallationCallback);
+ UNUSED_PARAM(rootViewToViewConversionCallback);
+ UNUSED_PARAM(clearTextIndicator);
+
+ return nil;
+#endif // PLATFORM(MAC)
+
+ END_BLOCK_OBJC_EXCEPTIONS;
+
+}
+
+void DictionaryLookup::showPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
+{
+ showPopupOrCreateAnimationController(false, dictionaryPopupInfo, view, textIndicatorInstallationCallback, rootViewToViewConversionCallback, WTFMove(clearTextIndicator));
+}
+
+void DictionaryLookup::hidePopup()
+{
+ notImplemented();
+}
+
+#if PLATFORM(MAC)
+
+WKRevealController DictionaryLookup::animationControllerForPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
+{
+ return showPopupOrCreateAnimationController(true, dictionaryPopupInfo, view, textIndicatorInstallationCallback, rootViewToViewConversionCallback, WTFMove(clearTextIndicator));
+}
+
+#endif // PLATFORM(MAC)
+
+#elif PLATFORM(IOS_FAMILY) // ENABLE(REVEAL)
+
+std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection&)
+{
+ return { nullptr, nil };
+}
+
+std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeAtHitTestResult(const HitTestResult&)
+{
+ return { nullptr, nil };
+}
+
+#endif // ENABLE(REVEAL)
+
+} // namespace WebCore
+
+#endif // PLATFORM(COCOA)
Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (238696 => 238697)
--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -34,6 +34,8 @@
#import "Document.h"
#import "DocumentFragment.h"
#import "DocumentLoader.h"
+#import "Editor.h"
+#import "EditorClient.h"
#import "File.h"
#import "FileSystem.h"
#import "Frame.h"
Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.h (238696 => 238697)
--- trunk/Source/WebCore/editing/mac/DictionaryLookup.h 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.h 2018-11-29 22:59:07 UTC (rev 238697)
@@ -23,15 +23,25 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#if PLATFORM(MAC)
+#pragma once
+#if PLATFORM(COCOA)
+
#include "DictionaryPopupInfo.h"
-#include <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
+#if PLATFORM(MAC)
+#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
+#endif // PLATFORM(MAC)
#include <wtf/Function.h>
OBJC_CLASS NSView;
OBJC_CLASS PDFSelection;
+#if PLATFORM(MAC)
+typedef id <NSImmediateActionAnimationController> WKRevealController;
+#else
+typedef id WKRevealController;
+#endif // PLATFORM(MAC)
+
namespace WebCore {
class HitTestResult;
@@ -48,8 +58,11 @@
WEBCORE_EXPORT static void showPopup(const DictionaryPopupInfo&, NSView *, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback = nullptr, WTF::Function<void()>&& clearTextIndicator = nullptr);
WEBCORE_EXPORT static void hidePopup();
-
- WEBCORE_EXPORT static id <NSImmediateActionAnimationController> animationControllerForPopup(const DictionaryPopupInfo&, NSView *, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback = nullptr, WTF::Function<void()>&& clearTextIndicator = nullptr);
+
+#if PLATFORM(MAC)
+ WEBCORE_EXPORT static WKRevealController animationControllerForPopup(const DictionaryPopupInfo&, NSView *, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback = nullptr, WTF::Function<void()>&& clearTextIndicator = nullptr);
+#endif // PLATFORM(MAC)
+
};
} // namespace WebCore
Deleted: trunk/Source/WebCore/editing/mac/DictionaryLookup.mm (238696 => 238697)
--- trunk/Source/WebCore/editing/mac/DictionaryLookup.mm 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -1,388 +0,0 @@
-/*
- * Copyright (C) 2014-2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "DictionaryLookup.h"
-
-#if PLATFORM(MAC) && ENABLE(REVEAL)
-
-#import "Document.h"
-#import "Editing.h"
-#import "FocusController.h"
-#import "Frame.h"
-#import "FrameSelection.h"
-#import "HTMLConverter.h"
-#import "HitTestResult.h"
-#import "Page.h"
-#import "Range.h"
-#import "RenderObject.h"
-#import "TextIterator.h"
-#import "VisiblePosition.h"
-#import "VisibleSelection.h"
-#import "VisibleUnits.h"
-#import <PDFKit/PDFKit.h>
-#import <pal/spi/mac/LookupSPI.h>
-#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
-#import <pal/spi/mac/RevealSPI.h>
-#import <wtf/BlockObjCExceptions.h>
-#import <wtf/RefPtr.h>
-
-@interface WebRevealHighlight <RVPresenterHighlightDelegate> : NSObject {
-@private
- Function<void()> _clearTextIndicator;
- NSRect _highlightRect;
- BOOL _useDefaultHighlight;
- NSAttributedString *_attributedString;
-}
-
-@property (nonatomic, readonly) NSRect highlightRect;
-@property (nonatomic, readonly) BOOL useDefaultHighlight;
-@property (nonatomic, readonly) NSAttributedString *attributedString;
-
-- (instancetype)initWithHighlightRect:(NSRect)highlightRect useDefaultHighlight:(BOOL)useDefaultHighlight attributedString:(NSAttributedString *) attributedString;
-- (void)setClearTextIndicator:(Function<void()>&&)clearTextIndicator;
-
-@end
-
-@implementation WebRevealHighlight
-
-@synthesize highlightRect=_highlightRect;
-@synthesize useDefaultHighlight=_useDefaultHighlight;
-@synthesize attributedString=_attributedString;
-
-- (instancetype)initWithHighlightRect:(NSRect)highlightRect useDefaultHighlight:(BOOL)useDefaultHighlight attributedString:(NSAttributedString *) attributedString
-{
- if (!(self = [super init]))
- return nil;
-
- _highlightRect = highlightRect;
- _useDefaultHighlight = useDefaultHighlight;
- _attributedString = attributedString;
-
- return self;
-}
-
-- (void)setClearTextIndicator:(Function<void()>&&)clearTextIndicator
-{
- _clearTextIndicator = WTFMove(clearTextIndicator);
-}
-
-- (NSArray<NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item
-{
- UNUSED_PARAM(context);
- UNUSED_PARAM(item);
- return @[[NSValue valueWithRect:self.highlightRect]];
-}
-
-- (void)revealContext:(RVPresentingContext *)context drawRectsForItem:(RVItem *)item
-{
- UNUSED_PARAM(item);
-
- for (NSValue *rectVal in context.itemRectsInView) {
- NSRect rect = rectVal.rectValue;
-
- // Get current font attributes from the attributed string above, and add paragraph style attribute in order to center text.
- RetainPtr<NSMutableDictionary> attributes = adoptNS([[NSMutableDictionary alloc] initWithDictionary:[self.attributedString fontAttributesInRange:NSMakeRange(0, [self.attributedString length])]]);
- RetainPtr<NSMutableParagraphStyle> paragraph = adoptNS([[NSMutableParagraphStyle alloc] init]);
- [paragraph setAlignment:NSTextAlignmentCenter];
- [attributes setObject:paragraph.get() forKey:NSParagraphStyleAttributeName];
-
- RetainPtr<NSAttributedString> string = adoptNS([[NSAttributedString alloc] initWithString:[self.attributedString string] attributes:attributes.get()]);
- [string drawInRect:rect];
- }
-}
-
-- (BOOL)revealContext:(RVPresentingContext *)context shouldUseDefaultHighlightForItem:(RVItem *)item
-{
- UNUSED_PARAM(context);
- UNUSED_PARAM(item);
- return self.useDefaultHighlight;
-}
-
-- (void)revealContext:(RVPresentingContext *)context stopHighlightingItem:(RVItem *)item
-{
- UNUSED_PARAM(context);
- UNUSED_PARAM(item);
- auto block = WTFMove(_clearTextIndicator);
- if (block)
- block();
-}
-
-@end
-
-namespace WebCore {
-
-std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection& selection)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
- if (!getRVItemClass())
- return { nullptr, nil };
-
- auto selectedRange = selection.toNormalizedRange();
- if (!selectedRange)
- return { nullptr, nil };
-
- // Since we already have the range we want, we just need to grab the returned options.
- auto selectionStart = selection.visibleStart();
- auto selectionEnd = selection.visibleEnd();
-
- // As context, we are going to use the surrounding paragraphs of text.
- auto paragraphStart = startOfParagraph(selectionStart);
- auto paragraphEnd = endOfParagraph(selectionEnd);
-
- int lengthToSelectionStart = TextIterator::rangeLength(makeRange(paragraphStart, selectionStart).get());
- int lengthToSelectionEnd = TextIterator::rangeLength(makeRange(paragraphStart, selectionEnd).get());
- NSRange rangeToPass = NSMakeRange(lengthToSelectionStart, lengthToSelectionEnd - lengthToSelectionStart);
-
- RefPtr<Range> fullCharacterRange = makeRange(paragraphStart, paragraphEnd);
- String itemString = plainText(fullCharacterRange.get());
- RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:rangeToPass]);
- NSRange highlightRange = item.get().highlightRange;
-
- return { TextIterator::subrange(*fullCharacterRange, highlightRange.location, highlightRange.length), nil };
-
- END_BLOCK_OBJC_EXCEPTIONS;
-
- return { nullptr, nil };
-}
-
-std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeAtHitTestResult(const HitTestResult& hitTestResult)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
- if (!getRVItemClass())
- return { nullptr, nil };
-
- auto* node = hitTestResult.innerNonSharedNode();
- if (!node || !node->renderer())
- return { nullptr, nil };
-
- auto* frame = node->document().frame();
- if (!frame)
- return { nullptr, nil };
-
- // Don't do anything if there is no character at the point.
- auto framePoint = hitTestResult.roundedPointInInnerNodeFrame();
- if (!frame->rangeForPoint(framePoint))
- return { nullptr, nil };
-
- auto position = frame->visiblePositionForPoint(framePoint);
- if (position.isNull())
- position = firstPositionInOrBeforeNode(node);
-
- auto selection = frame->page()->focusController().focusedOrMainFrame().selection().selection();
- NSRange selectionRange;
- int hitIndex;
- RefPtr<Range> fullCharacterRange;
-
- if (selection.selectionType() == VisibleSelection::RangeSelection) {
- auto selectionStart = selection.visibleStart();
- auto selectionEnd = selection.visibleEnd();
-
- // As context, we are going to use the surrounding paragraphs of text.
- auto paragraphStart = startOfParagraph(selectionStart);
- auto paragraphEnd = endOfParagraph(selectionEnd);
-
- auto rangeToSelectionStart = makeRange(paragraphStart, selectionStart);
- auto rangeToSelectionEnd = makeRange(paragraphStart, selectionEnd);
-
- fullCharacterRange = makeRange(paragraphStart, paragraphEnd);
-
- selectionRange = NSMakeRange(TextIterator::rangeLength(rangeToSelectionStart.get()), TextIterator::rangeLength(makeRange(selectionStart, selectionEnd).get()));
-
- hitIndex = TextIterator::rangeLength(makeRange(paragraphStart, position).get());
- } else {
- VisibleSelection selectionAccountingForLineRules { position };
- selectionAccountingForLineRules.expandUsingGranularity(WordGranularity);
- position = selectionAccountingForLineRules.start();
- // As context, we are going to use 250 characters of text before and after the point.
- fullCharacterRange = rangeExpandedAroundPositionByCharacters(position, 250);
-
- if (!fullCharacterRange)
- return { nullptr, nil };
-
- selectionRange = NSMakeRange(NSNotFound, 0);
- hitIndex = TextIterator::rangeLength(makeRange(fullCharacterRange->startPosition(), position).get());
- }
-
- NSRange selectedRange = [getRVSelectionClass() revealRangeAtIndex:hitIndex selectedRanges:@[[NSValue valueWithRange:selectionRange]] shouldUpdateSelection:nil];
-
- String itemString = plainText(fullCharacterRange.get());
- RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:selectedRange]);
- NSRange highlightRange = item.get().highlightRange;
-
- if (highlightRange.location == NSNotFound || !highlightRange.length)
- return { nullptr, nil };
-
- return { TextIterator::subrange(*fullCharacterRange, highlightRange.location, highlightRange.length), nil };
-
- END_BLOCK_OBJC_EXCEPTIONS;
-
- return { nullptr, nil };
-
-}
-
-static void expandSelectionByCharacters(PDFSelection *selection, NSInteger numberOfCharactersToExpand, NSInteger& charactersAddedBeforeStart, NSInteger& charactersAddedAfterEnd)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
- size_t originalLength = selection.string.length;
- [selection extendSelectionAtStart:numberOfCharactersToExpand];
-
- charactersAddedBeforeStart = selection.string.length - originalLength;
-
- [selection extendSelectionAtEnd:numberOfCharactersToExpand];
- charactersAddedAfterEnd = selection.string.length - originalLength - charactersAddedBeforeStart;
-
- END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-std::tuple<NSString *, NSDictionary *> DictionaryLookup::stringForPDFSelection(PDFSelection *selection)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
- if (!getRVItemClass())
- return { nullptr, nil };
-
- // Don't do anything if there is no character at the point.
- if (!selection || !selection.string.length)
- return { @"", nil };
-
- RetainPtr<PDFSelection> selectionForLookup = adoptNS([selection copy]);
-
- // As context, we are going to use 250 characters of text before and after the point.
- auto originalLength = [selectionForLookup string].length;
- NSInteger charactersAddedBeforeStart = 0;
- NSInteger charactersAddedAfterEnd = 0;
- expandSelectionByCharacters(selectionForLookup.get(), 250, charactersAddedBeforeStart, charactersAddedAfterEnd);
-
- auto fullPlainTextString = [selectionForLookup string];
- auto rangeToPass = NSMakeRange(charactersAddedBeforeStart, 0);
-
- RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:fullPlainTextString selectedRange:rangeToPass]);
- NSRange extractedRange = item.get().highlightRange;
-
- if (extractedRange.location == NSNotFound)
- return { selection.string, nil };
-
- NSInteger lookupAddedBefore = rangeToPass.location - extractedRange.location;
- NSInteger lookupAddedAfter = (extractedRange.location + extractedRange.length) - (rangeToPass.location + originalLength);
-
- [selection extendSelectionAtStart:lookupAddedBefore];
- [selection extendSelectionAtEnd:lookupAddedAfter];
-
- ASSERT([selection.string isEqualToString:[fullPlainTextString substringWithRange:extractedRange]]);
- return { selection.string, nil };
-
- END_BLOCK_OBJC_EXCEPTIONS;
-
- return { @"", nil };
-}
-
-static id <NSImmediateActionAnimationController> showPopupOrCreateAnimationController(bool createAnimationController, const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
- if (!getRVItemClass())
- return nil;
-
- RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([[NSMutableDictionary alloc] init]);
- if (NSDictionary *options = dictionaryPopupInfo.options.get())
- [mutableOptions addEntriesFromDictionary:options];
-
- auto textIndicator = TextIndicator::create(dictionaryPopupInfo.textIndicator);
-
- RetainPtr<RVPresenter> presenter = adoptNS([allocRVPresenterInstance() init]);
-
- NSRect highlightRect;
- NSPoint pointerLocation;
-
- if (textIndicator.get().contentImage()) {
- textIndicatorInstallationCallback(textIndicator.get());
-
- FloatRect firstTextRectInViewCoordinates = textIndicator.get().textRectsInBoundingRectCoordinates()[0];
- FloatRect textBoundingRectInViewCoordinates = textIndicator.get().textBoundingRectInRootViewCoordinates();
- FloatRect selectionBoundingRectInViewCoordinates = textIndicator.get().selectionRectInRootViewCoordinates();
-
- if (rootViewToViewConversionCallback) {
- textBoundingRectInViewCoordinates = rootViewToViewConversionCallback(textBoundingRectInViewCoordinates);
- selectionBoundingRectInViewCoordinates = rootViewToViewConversionCallback(selectionBoundingRectInViewCoordinates);
- }
-
- firstTextRectInViewCoordinates.moveBy(textBoundingRectInViewCoordinates.location());
- highlightRect = selectionBoundingRectInViewCoordinates;
- pointerLocation = firstTextRectInViewCoordinates.location();
-
- } else {
- NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
-
- highlightRect = textIndicator->selectionRectInRootViewCoordinates();
- pointerLocation = [view convertPoint:textBaselineOrigin toView:nil];
- }
-
- RetainPtr<WebRevealHighlight> webHighlight = adoptNS([[WebRevealHighlight alloc] initWithHighlightRect: highlightRect useDefaultHighlight:!textIndicator.get().contentImage() attributedString:dictionaryPopupInfo.attributedString.get()]);
- RetainPtr<RVPresentingContext> context = adoptNS([allocRVPresentingContextInstance() initWithPointerLocationInView:pointerLocation inView:view highlightDelegate:(id<RVPresenterHighlightDelegate>) webHighlight.get()]);
-
- RetainPtr<RVItem> item = adoptNS([allocRVItemInstance() initWithText:dictionaryPopupInfo.attributedString.get().string selectedRange:NSMakeRange(0, 0)]);
-
- [webHighlight setClearTextIndicator:[webHighlight = WTFMove(webHighlight), clearTextIndicator = WTFMove(clearTextIndicator)] {
- if (clearTextIndicator)
- clearTextIndicator();
- }];
-
- if (createAnimationController)
- return [presenter animationControllerForItem:item.get() documentContext:nil presentingContext:context.get() options:nil];
- [presenter revealItem:item.get() documentContext:nil presentingContext:context.get() options:nil];
- return nil;
-
- END_BLOCK_OBJC_EXCEPTIONS;
- return nil;
-}
-
-void DictionaryLookup::showPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
-{
- showPopupOrCreateAnimationController(false, dictionaryPopupInfo, view, textIndicatorInstallationCallback, rootViewToViewConversionCallback, WTFMove(clearTextIndicator));
-}
-
-void DictionaryLookup::hidePopup()
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
- if (!getLULookupDefinitionModuleClass())
- return;
- [getLULookupDefinitionModuleClass() hideDefinition];
-
- END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-id <NSImmediateActionAnimationController> DictionaryLookup::animationControllerForPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
-{
- return showPopupOrCreateAnimationController(true, dictionaryPopupInfo, view, textIndicatorInstallationCallback, rootViewToViewConversionCallback, WTFMove(clearTextIndicator));
-}
-
-} // namespace WebCore
-
-#endif // PLATFORM(MAC)
Modified: trunk/Source/WebKit/ChangeLog (238696 => 238697)
--- trunk/Source/WebKit/ChangeLog 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/ChangeLog 2018-11-29 22:59:07 UTC (rev 238697)
@@ -1,3 +1,51 @@
+2018-11-29 Megan Gardner <megan_gard...@apple.com>
+
+ Move Lookup Code for better cross platform usage
+ https://bugs.webkit.org/show_bug.cgi?id=191732
+
+ Reviewed by Alex Christensen.
+
+ Lookup is being replaced by Reveal. This framework should work on all platforms.
+ The patch moves the code that we expect will be needed for all platforms to the more
+ general cocoa area. This patch changes no funcationality, and should not change
+ anything currently. This work will be build on later when Reveal is ready to support
+ multiple platforms.
+
+ * Platform/spi/ios/UIKitSPI.h:
+ * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+ (WebKit::WebPageProxy::performDictionaryLookupAtLocation):
+ (WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection):
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView setupInteraction]):
+ (-[WKContentView cleanupInteraction]):
+ (-[WKContentView _removeDefaultGestureRecognizers]):
+ (-[WKContentView _addDefaultGestureRecognizers]):
+ (-[WKContentView gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]):
+ (-[WKContentView _lookupGestureRecognized:]):
+ * UIProcess/ios/WebPageProxyIOS.mm:
+ (WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted.
+ * UIProcess/mac/WebPageProxyMac.mm:
+ (WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted.
+ (WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection): Deleted.
+ * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+ (WebKit::WebPage::performDictionaryLookupAtLocation):
+ (WebKit::WebPage::performDictionaryLookupForSelection):
+ (WebKit::WebPage::performDictionaryLookupOfCurrentSelection):
+ (WebKit::WebPage::performDictionaryLookupForRange):
+ (WebKit::WebPage::dictionaryPopupInfoForRange):
+ * WebProcess/WebPage/WebPage.messages.in:
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::performDictionaryLookupAtLocation): Deleted.
+ (WebKit::WebPage::performDictionaryLookupForSelection): Deleted.
+ (WebKit::WebPage::performDictionaryLookupForRange): Deleted.
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::performDictionaryLookupAtLocation): Deleted.
+ (WebKit::WebPage::performDictionaryLookupForSelection): Deleted.
+ (WebKit::WebPage::performDictionaryLookupOfCurrentSelection): Deleted.
+ (WebKit::WebPage::dictionaryPopupInfoForRange): Deleted.
+ (WebKit::WebPage::performDictionaryLookupForRange): Deleted.
+
2018-11-29 Zalan Bujtas <za...@apple.com>
[ContentObservation] Decouple content change and DOM timer scheduling observation
Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (238696 => 238697)
--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2018-11-29 22:59:07 UTC (rev 238697)
@@ -733,6 +733,9 @@
bool isPotentialTap;
};
+@interface _UILookupGestureRecognizer : UIGestureRecognizer
+@end
+
@class UIWebTouchEventsGestureRecognizer;
@protocol UIWebTouchEventsGestureRecognizerDelegate <NSObject>
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (238696 => 238697)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -33,6 +33,7 @@
#import "PageClient.h"
#import "SafeBrowsingSPI.h"
#import "SafeBrowsingWarning.h"
+#import "WebPageMessages.h"
#import "WebProcessProxy.h"
#import <WebCore/DragItem.h>
#import <WebCore/NotImplemented.h>
@@ -189,5 +190,21 @@
}
#endif // ENABLE(ATTACHMENT_ELEMENT)
+
+void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)
+{
+ if (!isValid())
+ return;
+
+ process().send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID);
+}
+void WebPageProxy::performDictionaryLookupOfCurrentSelection()
+{
+ if (!isValid())
+ return;
+
+ process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_pageID);
}
+
+} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (238696 => 238697)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2018-11-29 22:59:07 UTC (rev 238697)
@@ -87,6 +87,7 @@
class WebPageProxy;
}
+@class _UILookupGestureRecognizer;
@class _UIHighlightView;
@class _UIWebHighlightLongPressGestureRecognizer;
@class UIHoverGestureRecognizer;
@@ -215,6 +216,7 @@
#if PLATFORM(IOSMAC)
RetainPtr<UIHoverGestureRecognizer> _hoverGestureRecognizer;
+ RetainPtr<_UILookupGestureRecognizer> _lookupGestureRecognizer;
#endif
RetainPtr<UIWKTextInteractionAssistant> _textSelectionAssistant;
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (238696 => 238697)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -112,6 +112,7 @@
#if PLATFORM(IOSMAC)
#import "NativeWebMouseEvent.h"
#import <UIKit/UIHoverGestureRecognizer.h>
+#import <UIKit/_UILookupGestureRecognizer.h>
#import <pal/spi/ios/GraphicsServicesSPI.h>
#endif
@@ -649,6 +650,11 @@
_hoverGestureRecognizer = adoptNS([[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(_hoverGestureRecognizerChanged:)]);
[_hoverGestureRecognizer setDelegate:self];
[self addGestureRecognizer:_hoverGestureRecognizer.get()];
+
+ _lookupGestureRecognizer = adoptNS([[_UILookupGestureRecognizer alloc] initWithTarget:self action:@selector(_lookupGestureRecognized:)]);
+ [_lookupGestureRecognizer setDelegate:self];
+ [self addGestureRecognizer:_lookupGestureRecognizer.get()];
+
#endif
_singleTapGestureRecognizer = adoptNS([[WKSyntheticClickTapGestureRecognizer alloc] initWithTarget:self action:@selector(_singleTapCommited:)]);
@@ -759,6 +765,9 @@
#if PLATFORM(IOSMAC)
[_hoverGestureRecognizer setDelegate:nil];
[self removeGestureRecognizer:_hoverGestureRecognizer.get()];
+
+ [_lookupGestureRecognizer setDelegate:nil];
+ [self removeGestureRecognizer:_lookupGestureRecognizer.get()];
#endif
[_singleTapGestureRecognizer setDelegate:nil];
@@ -846,6 +855,7 @@
[self removeGestureRecognizer:_stylusSingleTapGestureRecognizer.get()];
#if PLATFORM(IOSMAC)
[self removeGestureRecognizer:_hoverGestureRecognizer.get()];
+ [self removeGestureRecognizer:_lookupGestureRecognizer.get()];
#endif
}
@@ -861,6 +871,7 @@
[self addGestureRecognizer:_stylusSingleTapGestureRecognizer.get()];
#if PLATFORM(IOSMAC)
[self addGestureRecognizer:_hoverGestureRecognizer.get()];
+ [self addGestureRecognizer:_lookupGestureRecognizer.get()];
#endif
}
@@ -1467,6 +1478,10 @@
if ([gestureRecognizer isKindOfClass:[UIHoverGestureRecognizer class]] || [otherGestureRecognizer isKindOfClass:[UIHoverGestureRecognizer class]])
return YES;
+
+ if (([gestureRecognizer isKindOfClass:[_UILookupGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) || ([otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && [gestureRecognizer isKindOfClass:[_UILookupGestureRecognizer class]]))
+ return YES;
+
#endif
if (isSamePair(gestureRecognizer, otherGestureRecognizer, _highlightLongPressGestureRecognizer.get(), _textSelectionAssistant.get().forcePressGesture))
return YES;
@@ -6057,6 +6072,12 @@
#endif // PLATFORM(WATCHOS)
#if PLATFORM(IOSMAC)
+- (void)_lookupGestureRecognized:(UIGestureRecognizer *)gestureRecognizer
+{
+ NSPoint locationInViewCoordinates = [gestureRecognizer locationInView:self];
+ _page->performDictionaryLookupAtLocation(WebCore::FloatPoint(locationInViewCoordinates));
+}
+
- (void)_hoverGestureRecognizerChanged:(UIGestureRecognizer *)gestureRecognizer
{
if (!_page->isValid())
Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (238696 => 238697)
--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -121,11 +121,6 @@
return false;
}
-void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint&)
-{
- notImplemented();
-}
-
void WebPageProxy::gestureCallback(const WebCore::IntPoint& point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, CallbackID callbackID)
{
auto callback = m_callbacks.take<GestureCallback>(callbackID);
Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (238696 => 238697)
--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -323,22 +323,6 @@
#endif
-void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)
-{
- if (!isValid())
- return;
-
- process().send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID);
-}
-
-void WebPageProxy::performDictionaryLookupOfCurrentSelection()
-{
- if (!isValid())
- return;
-
- process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_pageID);
-}
-
// Complex text input support for plug-ins.
void WebPageProxy::sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput)
{
Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (238696 => 238697)
--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -26,9 +26,20 @@
#import "config.h"
#import "WebPage.h"
+
#import "LoadParameters.h"
+#import "PluginView.h"
#import "WebPageProxyMessages.h"
+#import <WebCore/DictionaryLookup.h>
+#import <WebCore/Editor.h>
+#import <WebCore/EventHandler.h>
+#import <WebCore/FocusController.h>
+#import <WebCore/HTMLConverter.h>
+#import <WebCore/HitTestResult.h>
+#import <WebCore/NodeRenderStyle.h>
#import <WebCore/PlatformMediaSessionManager.h>
+#import <WebCore/RenderElement.h>
+#import <WebCore/RenderObject.h>
#if PLATFORM(COCOA)
@@ -59,7 +70,115 @@
send(Messages::WebPageProxy::NowPlayingInfoCallback(hasActiveSession, registeredAsNowPlayingApplication, title, duration, elapsedTime, uniqueIdentifier, callbackID));
}
+
+void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
+{
+ if (auto* pluginView = pluginViewForFrame(&m_page->mainFrame())) {
+ if (pluginView->performDictionaryLookupAtLocation(floatPoint))
+ return;
+ }
+
+ // Find the frame the point is over.
+ HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)));
+ RefPtr<Range> range;
+ NSDictionary *options;
+ std::tie(range, options) = DictionaryLookup::rangeAtHitTestResult(result);
+ if (!range)
+ return;
+
+ auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
+ if (!frame)
+ return;
+
+ performDictionaryLookupForRange(*frame, *range, options, TextIndicatorPresentationTransition::Bounce);
+}
+void WebPage::performDictionaryLookupForSelection(Frame& frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition)
+{
+ RefPtr<Range> selectedRange;
+ NSDictionary *options;
+ std::tie(selectedRange, options) = DictionaryLookup::rangeForSelection(selection);
+ if (selectedRange)
+ performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition);
+}
+
+void WebPage::performDictionaryLookupOfCurrentSelection()
+{
+ auto& frame = m_page->focusController().focusedOrMainFrame();
+ performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);
+}
+
+void WebPage::performDictionaryLookupForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
+{
+ send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfoForRange(frame, range, options, presentationTransition)));
+}
+
+DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
+{
+ Editor& editor = frame.editor();
+ editor.setIsGettingDictionaryPopupInfo(true);
+
+ DictionaryPopupInfo dictionaryPopupInfo;
+ if (range.text().stripWhiteSpace().isEmpty()) {
+ editor.setIsGettingDictionaryPopupInfo(false);
+ return dictionaryPopupInfo;
+ }
+
+ Vector<FloatQuad> quads;
+ range.absoluteTextQuads(quads);
+ if (quads.isEmpty()) {
+ editor.setIsGettingDictionaryPopupInfo(false);
+ return dictionaryPopupInfo;
+ }
+
+ IntRect rangeRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox());
+
+ const RenderStyle* style = range.startContainer().renderStyle();
+ float scaledAscent = style ? style->fontMetrics().ascent() * pageScaleFactor() : 0;
+ dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + scaledAscent);
+ dictionaryPopupInfo.options = options;
+
+#if PLATFORM(MAC)
+
+ NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range, IncludeImagesInAttributedString::No);
+
+ RetainPtr<NSMutableAttributedString> scaledNSAttributedString = adoptNS([[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]);
+
+ NSFontManager *fontManager = [NSFontManager sharedFontManager];
+
+ [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
+ RetainPtr<NSMutableDictionary> scaledAttributes = adoptNS([attributes mutableCopy]);
+
+ NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName];
+ if (font)
+ font = [fontManager convertFont:font toSize:font.pointSize * pageScaleFactor()];
+ if (font)
+ [scaledAttributes setObject:font forKey:NSFontAttributeName];
+
+ [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
+ }];
+
+#endif // PLATFORM(MAC)
+
+ TextIndicatorOptions indicatorOptions = TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges;
+ if (presentationTransition == TextIndicatorPresentationTransition::BounceAndCrossfade)
+ indicatorOptions |= TextIndicatorOptionIncludeSnapshotWithSelectionHighlight;
+
+ RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, indicatorOptions, presentationTransition);
+ if (!textIndicator) {
+ editor.setIsGettingDictionaryPopupInfo(false);
+ return dictionaryPopupInfo;
+ }
+
+ dictionaryPopupInfo.textIndicator = textIndicator->data();
+#if PLATFORM(MAC)
+ dictionaryPopupInfo.attributedString = scaledNSAttributedString;
+#endif // PLATFORM(MAC)
+
+ editor.setIsGettingDictionaryPopupInfo(false);
+ return dictionaryPopupInfo;
+}
+
} // namespace WebKit
#endif // PLATFORM(COCOA)
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (238696 => 238697)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2018-11-29 22:59:07 UTC (rev 238697)
@@ -191,6 +191,7 @@
#if PLATFORM(COCOA)
# Dictionary support.
+ PerformDictionaryLookupOfCurrentSelection()
PerformDictionaryLookupAtLocation(WebCore::FloatPoint point)
#endif
@@ -199,10 +200,6 @@
RemoveDataDetectedLinks() -> (struct WebKit::DataDetectionResult result) Async
#endif
-#if PLATFORM(MAC)
- PerformDictionaryLookupOfCurrentSelection()
-#endif
-
ChangeFont(WebCore::FontChanges changes)
ChangeFontAttributes(WebCore::FontAttributeChanges changes)
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (238696 => 238697)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -417,21 +417,6 @@
notImplemented();
}
-void WebPage::performDictionaryLookupAtLocation(const FloatPoint&)
-{
- notImplemented();
-}
-
-void WebPage::performDictionaryLookupForSelection(Frame&, const VisibleSelection&, TextIndicatorPresentationTransition)
-{
- notImplemented();
-}
-
-void WebPage::performDictionaryLookupForRange(Frame&, Range&, NSDictionary *, TextIndicatorPresentationTransition)
-{
- notImplemented();
-}
-
bool WebPage::performNonEditingBehaviorForSelector(const String&, WebCore::KeyboardEvent*)
{
notImplemented();
Modified: trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (238696 => 238697)
--- trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2018-11-29 22:56:04 UTC (rev 238696)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2018-11-29 22:59:07 UTC (rev 238697)
@@ -389,103 +389,8 @@
send(Messages::WebPageProxy::FontAtSelectionCallback(fontName, fontSize, selectionHasMultipleFonts, callbackID));
}
-void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
-{
- if (auto* pluginView = pluginViewForFrame(&m_page->mainFrame())) {
- if (pluginView->performDictionaryLookupAtLocation(floatPoint))
- return;
- }
- // Find the frame the point is over.
- HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)));
- RefPtr<Range> range;
- NSDictionary *options;
- std::tie(range, options) = DictionaryLookup::rangeAtHitTestResult(result);
- if (!range)
- return;
- auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
- if (!frame)
- return;
-
- performDictionaryLookupForRange(*frame, *range, options, TextIndicatorPresentationTransition::Bounce);
-}
-
-void WebPage::performDictionaryLookupForSelection(Frame& frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition)
-{
- RefPtr<Range> selectedRange;
- NSDictionary *options;
- std::tie(selectedRange, options) = DictionaryLookup::rangeForSelection(selection);
- if (selectedRange)
- performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition);
-}
-
-void WebPage::performDictionaryLookupOfCurrentSelection()
-{
- auto& frame = m_page->focusController().focusedOrMainFrame();
- performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);
-}
-
-DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
-{
- Editor& editor = frame.editor();
- editor.setIsGettingDictionaryPopupInfo(true);
-
- DictionaryPopupInfo dictionaryPopupInfo;
- if (range.text().stripWhiteSpace().isEmpty()) {
- editor.setIsGettingDictionaryPopupInfo(false);
- return dictionaryPopupInfo;
- }
-
- Vector<FloatQuad> quads;
- range.absoluteTextQuads(quads);
- if (quads.isEmpty()) {
- editor.setIsGettingDictionaryPopupInfo(false);
- return dictionaryPopupInfo;
- }
-
- IntRect rangeRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox());
-
- const RenderStyle* style = range.startContainer().renderStyle();
- float scaledAscent = style ? style->fontMetrics().ascent() * pageScaleFactor() : 0;
- dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + scaledAscent);
- dictionaryPopupInfo.options = options;
-
- NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range, IncludeImagesInAttributedString::No);
-
- RetainPtr<NSMutableAttributedString> scaledNSAttributedString = adoptNS([[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]);
-
- NSFontManager *fontManager = [NSFontManager sharedFontManager];
-
- [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
- RetainPtr<NSMutableDictionary> scaledAttributes = adoptNS([attributes mutableCopy]);
-
- NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName];
- if (font)
- font = [fontManager convertFont:font toSize:font.pointSize * pageScaleFactor()];
- if (font)
- [scaledAttributes setObject:font forKey:NSFontAttributeName];
-
- [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
- }];
-
- TextIndicatorOptions indicatorOptions = TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges;
- if (presentationTransition == TextIndicatorPresentationTransition::BounceAndCrossfade)
- indicatorOptions |= TextIndicatorOptionIncludeSnapshotWithSelectionHighlight;
-
- RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, indicatorOptions, presentationTransition);
- if (!textIndicator) {
- editor.setIsGettingDictionaryPopupInfo(false);
- return dictionaryPopupInfo;
- }
-
- dictionaryPopupInfo.textIndicator = textIndicator->data();
- dictionaryPopupInfo.attributedString = scaledNSAttributedString;
-
- editor.setIsGettingDictionaryPopupInfo(false);
- return dictionaryPopupInfo;
-}
-
#if ENABLE(PDFKIT_PLUGIN)
DictionaryPopupInfo WebPage::dictionaryPopupInfoForSelectionInPDFPlugin(PDFSelection *selection, PDFPlugin& pdfPlugin, NSDictionary *options, WebCore::TextIndicatorPresentationTransition presentationTransition)
@@ -539,11 +444,6 @@
#endif
-void WebPage::performDictionaryLookupForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
-{
- send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfoForRange(frame, range, options, presentationTransition)));
-}
-
bool WebPage::performNonEditingBehaviorForSelector(const String& selector, KeyboardEvent* event)
{
// First give accessibility a chance to handle the event.