Changeset 238678 in webkit
- Timestamp:
- Nov 29, 2018 10:54:19 AM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 19 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r238677 r238678 1 2018-11-29 Megan Gardner <megan_gardner@apple.com> 2 3 Move Lookup Code for better cross platform usage 4 https://bugs.webkit.org/show_bug.cgi?id=191732 5 6 Reviewed by Alex Christensen. 7 8 Not currenlty testable 9 10 DictionaryLookup uses Reveal now, which is slated to be cross-platform. 11 That patch gates the parts of DictionaryLookup that currently do not have 12 an available implementation on iOS. Once Reveal is ready, this code will be 13 replaced or expanded upon, as appropriate. 14 15 * editing/mac/DictionaryLookup.h: 16 * editing/mac/DictionaryLookup.mm: 17 (WebCore::showPopupOrCreateAnimationController): 18 (WebCore::DictionaryLookup::showPopup): 19 (WebCore::DictionaryLookup::hidePopup): 20 (WebCore::DictionaryLookup::animationControllerForPopup): 21 1 22 2018-11-29 Sihui Liu <sihui_liu@apple.com> 2 23 -
trunk/Source/WebCore/PAL/ChangeLog
r238657 r238678 1 2018-11-29 Megan Gardner <megan_gardner@apple.com> 2 3 Move Lookup Code for better cross platform usage 4 https://bugs.webkit.org/show_bug.cgi?id=191732 5 6 Reviewed by Alex Christensen. 7 8 * pal/spi/mac/LookupSPI.h: 9 * pal/spi/mac/RevealSPI.h: 10 1 11 2018-11-28 Commit Queue <commit-queue@webkit.org> 2 12 -
trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
r238657 r238678 407 407 0C2DA13A1F3BEB4900DBC317 /* pthreadSPI.h */, 408 408 0C2DA13B1F3BEB4900DBC317 /* QuartzCoreSPI.h */, 409 442956CC218A72DE0080DB54 /* RevealSPI.h */, 409 410 570AB8F020AE2E8D00B8BE87 /* SecKeyProxySPI.h */, 410 411 0C2DA13C1F3BEB4900DBC317 /* ServersSPI.h */, … … 472 473 A102658A1F56748C00B4C844 /* QuickDrawSPI.h */, 473 474 0C7785871F45130F00F4EBB6 /* QuickLookMacSPI.h */, 474 442956CC218A72DE0080DB54 /* RevealSPI.h */,475 475 A1175B481F6AFF8E00C4B9F0 /* SpeechSynthesisSPI.h */, 476 476 0C7785881F45130F00F4EBB6 /* TUCallSPI.h */, -
trunk/Source/WebCore/PAL/pal/spi/cocoa/RevealSPI.h
r238677 r238678 25 25 26 26 #import <objc/runtime.h> 27 #if PLATFORM(MAC) 27 28 #import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h> 29 #endif // PLATFORM(MAC) 28 30 #import <wtf/SoftLinking.h> 29 31 … … 37 39 #if USE(APPLE_INTERNAL_SDK) 38 40 41 #if PLATFORM(MAC) 39 42 #import <Reveal/RVPresenter.h> 40 43 #import <Reveal/Reveal.h> 44 #endif // PLATFORM(MAC) 41 45 #import <RevealCore/RVSelection.h> 42 46 #import <RevealCore/RevealCore.h> 43 47 48 #else // USE(APPLE_INTERNAL_SDK) 44 49 45 #else 50 51 @protocol RVPresenterHighlightDelegate; 46 52 47 53 @interface RVItem : NSObject <NSSecureCoding> … … 53 59 @end 54 60 61 #if PLATFORM(MAC) 62 @interface RVPresentingContext : NSObject 63 - (instancetype)initWithPointerLocationInView:(NSPoint)pointerLocationInView inView:(NSView *)view highlightDelegate:(id<RVPresenterHighlightDelegate>)highlightDelegate; 64 @end 65 #endif 66 67 @protocol RVPresenterHighlightDelegate <NSObject> 68 @required 69 - (NSArray <NSValue *> *)revealContext:(RVPresentingContext *)context rectsForItem:(RVItem *)item; 70 @optional 71 - (void)revealContext:(RVPresentingContext *)context stopHighlightingItem:(RVItem *)item; 72 - (void)revealContext:(RVPresentingContext *)context drawRectsForItem:(RVItem *)item; 73 @end 74 75 @interface RVDocumentContext : NSObject < NSSecureCoding > 76 @end 77 55 78 @interface RVPresenter : NSObject 79 #if PLATFORM(MAC) 56 80 - (id<NSImmediateActionAnimationController>)animationControllerForItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options; 81 #endif // PLATFORM(MAC) 57 82 - (BOOL)revealItem:(RVItem *)item documentContext:(RVDocumentContext *)documentContext presentingContext:(RVPresentingContext *)presentingContext options:(NSDictionary *)options; 58 83 @end -
trunk/Source/WebCore/PAL/pal/spi/mac/LookupSPI.h
r238657 r238678 24 24 */ 25 25 26 27 #if PLATFORM(MAC) 28 26 29 #import <objc/runtime.h> 27 30 #import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h> 28 31 #import <wtf/SoftLinking.h> 29 30 #if PLATFORM(MAC)31 32 32 33 SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(Lookup) -
trunk/Source/WebCore/SourcesCocoa.txt
r238657 r238678 78 78 79 79 editing/cocoa/DataDetection.mm 80 editing/cocoa/DictionaryLookup.mm 80 81 editing/cocoa/EditorCocoa.mm 81 82 editing/cocoa/FontAttributeChangesCocoa.mm … … 91 92 92 93 editing/mac/AlternativeTextUIController.mm 93 editing/mac/DictionaryLookup.mm94 94 editing/mac/DictionaryLookupLegacy.mm 95 95 editing/mac/EditorMac.mm -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r238667 r238678 20524 20524 C5227DEF1C3C6DD700F5ED54 /* DataDetection.h */, 20525 20525 C5227DF01C3C6DD700F5ED54 /* DataDetection.mm */, 20526 937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */, 20526 20527 9B55EEE81B3E8898005342BC /* EditorCocoa.mm */, 20527 20528 F42CEB54214031EE002DCA72 /* FontAttributeChangesCocoa.mm */, … … 26230 26231 CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */, 26231 26232 937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */, 26232 937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */,26233 26233 442956CA218A6D300080DB54 /* DictionaryLookupLegacy.mm */, 26234 26234 ED501DC50B249F2900AE18D9 /* EditorMac.mm */, -
trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm
r238677 r238678 27 27 #import "DictionaryLookup.h" 28 28 29 #if PLATFORM( MAC) && ENABLE(REVEAL)29 #if PLATFORM(COCOA) 30 30 31 31 #import "Document.h" … … 36 36 #import "HTMLConverter.h" 37 37 #import "HitTestResult.h" 38 #import "NotImplemented.h" 38 39 #import "Page.h" 39 40 #import "Range.h" … … 44 45 #import "VisibleUnits.h" 45 46 #import <PDFKit/PDFKit.h> 47 #import <pal/spi/cocoa/RevealSPI.h> 46 48 #import <pal/spi/mac/LookupSPI.h> 47 #import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>48 #import <pal/spi/mac/RevealSPI.h>49 49 #import <wtf/BlockObjCExceptions.h> 50 50 #import <wtf/RefPtr.h> 51 52 #if ENABLE(REVEAL) 53 54 #if PLATFORM(MAC) 51 55 52 56 @interface WebRevealHighlight <RVPresenterHighlightDelegate> : NSObject { … … 133 137 @end 134 138 139 #endif // PLATFORM(MAC) 140 141 #endif // ENABLE(REVEAL) 142 135 143 namespace WebCore { 144 145 #if ENABLE(REVEAL) 136 146 137 147 std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection& selection) … … 303 313 } 304 314 305 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)315 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) 306 316 { 307 317 BEGIN_BLOCK_OBJC_EXCEPTIONS; 308 318 309 if (!getRVItemClass()) 319 #if PLATFORM(MAC) 320 321 if (!getRVItemClass() || !getRVPresenterClass()) 310 322 return nil; 311 323 … … 358 370 [presenter revealItem:item.get() documentContext:nil presentingContext:context.get() options:nil]; 359 371 return nil; 360 372 373 #else // PLATFORM(MAC) 374 375 UNUSED_PARAM(createAnimationController); 376 UNUSED_PARAM(dictionaryPopupInfo); 377 UNUSED_PARAM(view); 378 UNUSED_PARAM(textIndicatorInstallationCallback); 379 UNUSED_PARAM(rootViewToViewConversionCallback); 380 UNUSED_PARAM(clearTextIndicator); 381 382 return nil; 383 #endif // PLATFORM(MAC) 384 361 385 END_BLOCK_OBJC_EXCEPTIONS; 362 return nil;386 363 387 } 364 388 … … 370 394 void DictionaryLookup::hidePopup() 371 395 { 372 BEGIN_BLOCK_OBJC_EXCEPTIONS; 373 374 if (!getLULookupDefinitionModuleClass()) 375 return; 376 [getLULookupDefinitionModuleClass() hideDefinition]; 377 378 END_BLOCK_OBJC_EXCEPTIONS; 379 } 380 381 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) 396 notImplemented(); 397 } 398 399 #if PLATFORM(MAC) 400 401 WKRevealController DictionaryLookup::animationControllerForPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator) 382 402 { 383 403 return showPopupOrCreateAnimationController(true, dictionaryPopupInfo, view, textIndicatorInstallationCallback, rootViewToViewConversionCallback, WTFMove(clearTextIndicator)); 384 404 } 385 405 406 #endif // PLATFORM(MAC) 407 408 #elif PLATFORM(IOS_FAMILY) // ENABLE(REVEAL) 409 410 std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection&) 411 { 412 return { nullptr, nil }; 413 } 414 415 std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeAtHitTestResult(const HitTestResult&) 416 { 417 return { nullptr, nil }; 418 } 419 420 #endif // ENABLE(REVEAL) 421 386 422 } // namespace WebCore 387 423 388 #endif // PLATFORM( MAC)424 #endif // PLATFORM(COCOA) -
trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
r238661 r238678 35 35 #import "DocumentFragment.h" 36 36 #import "DocumentLoader.h" 37 #import "Editor.h" 38 #import "EditorClient.h" 37 39 #import "File.h" 38 40 #import "FileSystem.h" -
trunk/Source/WebCore/editing/mac/DictionaryLookup.h
r238657 r238678 24 24 */ 25 25 26 #if PLATFORM(MAC) 26 #pragma once 27 28 #if PLATFORM(COCOA) 27 29 28 30 #include "DictionaryPopupInfo.h" 29 #include <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h> 31 #if PLATFORM(MAC) 32 #import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h> 33 #endif // PLATFORM(MAC) 30 34 #include <wtf/Function.h> 31 35 32 36 OBJC_CLASS NSView; 33 37 OBJC_CLASS PDFSelection; 38 39 #if PLATFORM(MAC) 40 typedef id <NSImmediateActionAnimationController> WKRevealController; 41 #else 42 typedef id WKRevealController; 43 #endif // PLATFORM(MAC) 34 44 35 45 namespace WebCore { … … 49 59 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); 50 60 WEBCORE_EXPORT static void hidePopup(); 51 52 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); 61 62 #if PLATFORM(MAC) 63 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); 64 #endif // PLATFORM(MAC) 65 53 66 }; 54 67 -
trunk/Source/WebKit/ChangeLog
r238674 r238678 1 2018-11-29 Megan Gardner <megan_gardner@apple.com> 2 3 Move Lookup Code for better cross platform usage 4 https://bugs.webkit.org/show_bug.cgi?id=191732 5 6 Reviewed by Alex Christensen. 7 8 Lookup is being replaced by Reveal. This framework should work on all platforms. 9 The patch moves the code that we expect will be needed for all platforms to the more 10 general cocoa area. This patch changes no funcationality, and should not change 11 anything currently. This work will be build on later when Reveal is ready to support 12 multiple platforms. 13 14 * Platform/spi/ios/UIKitSPI.h: 15 * UIProcess/Cocoa/WebPageProxyCocoa.mm: 16 (WebKit::WebPageProxy::performDictionaryLookupAtLocation): 17 (WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection): 18 * UIProcess/ios/WKContentViewInteraction.h: 19 * UIProcess/ios/WKContentViewInteraction.mm: 20 (-[WKContentView setupInteraction]): 21 (-[WKContentView cleanupInteraction]): 22 (-[WKContentView _removeDefaultGestureRecognizers]): 23 (-[WKContentView _addDefaultGestureRecognizers]): 24 (-[WKContentView gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]): 25 (-[WKContentView _lookupGestureRecognized:]): 26 * UIProcess/ios/WebPageProxyIOS.mm: 27 (WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted. 28 * UIProcess/mac/WebPageProxyMac.mm: 29 (WebKit::WebPageProxy::performDictionaryLookupAtLocation): Deleted. 30 (WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection): Deleted. 31 * WebProcess/WebPage/Cocoa/WebPageCocoa.mm: 32 (WebKit::WebPage::performDictionaryLookupAtLocation): 33 (WebKit::WebPage::performDictionaryLookupForSelection): 34 (WebKit::WebPage::performDictionaryLookupOfCurrentSelection): 35 (WebKit::WebPage::performDictionaryLookupForRange): 36 (WebKit::WebPage::dictionaryPopupInfoForRange): 37 * WebProcess/WebPage/WebPage.messages.in: 38 * WebProcess/WebPage/ios/WebPageIOS.mm: 39 (WebKit::WebPage::performDictionaryLookupAtLocation): Deleted. 40 (WebKit::WebPage::performDictionaryLookupForSelection): Deleted. 41 (WebKit::WebPage::performDictionaryLookupForRange): Deleted. 42 * WebProcess/WebPage/mac/WebPageMac.mm: 43 (WebKit::WebPage::performDictionaryLookupAtLocation): Deleted. 44 (WebKit::WebPage::performDictionaryLookupForSelection): Deleted. 45 (WebKit::WebPage::performDictionaryLookupOfCurrentSelection): Deleted. 46 (WebKit::WebPage::dictionaryPopupInfoForRange): Deleted. 47 (WebKit::WebPage::performDictionaryLookupForRange): Deleted. 48 1 49 2018-11-29 Conrad Shultz <conrad_shultz@apple.com> 2 50 -
trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h
r238657 r238678 734 734 }; 735 735 736 @interface _UILookupGestureRecognizer : UIGestureRecognizer 737 @end 738 736 739 @class UIWebTouchEventsGestureRecognizer; 737 740 -
trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
r238657 r238678 34 34 #import "SafeBrowsingSPI.h" 35 35 #import "SafeBrowsingWarning.h" 36 #import "WebPageMessages.h" 36 37 #import "WebProcessProxy.h" 37 38 #import <WebCore/DragItem.h> … … 190 191 191 192 #endif // ENABLE(ATTACHMENT_ELEMENT) 192 193 } 193 194 void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point) 195 { 196 if (!isValid()) 197 return; 198 199 process().send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID); 200 } 201 202 void WebPageProxy::performDictionaryLookupOfCurrentSelection() 203 { 204 if (!isValid()) 205 return; 206 207 process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_pageID); 208 } 209 210 } // namespace WebKit -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
r238657 r238678 88 88 } 89 89 90 @class _UILookupGestureRecognizer; 90 91 @class _UIHighlightView; 91 92 @class _UIWebHighlightLongPressGestureRecognizer; … … 216 217 #if PLATFORM(IOSMAC) 217 218 RetainPtr<UIHoverGestureRecognizer> _hoverGestureRecognizer; 219 RetainPtr<_UILookupGestureRecognizer> _lookupGestureRecognizer; 218 220 #endif 219 221 -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r238657 r238678 113 113 #import "NativeWebMouseEvent.h" 114 114 #import <UIKit/UIHoverGestureRecognizer.h> 115 #import <UIKit/_UILookupGestureRecognizer.h> 115 116 #import <pal/spi/ios/GraphicsServicesSPI.h> 116 117 #endif … … 650 651 [_hoverGestureRecognizer setDelegate:self]; 651 652 [self addGestureRecognizer:_hoverGestureRecognizer.get()]; 653 654 _lookupGestureRecognizer = adoptNS([[_UILookupGestureRecognizer alloc] initWithTarget:self action:@selector(_lookupGestureRecognized:)]); 655 [_lookupGestureRecognizer setDelegate:self]; 656 [self addGestureRecognizer:_lookupGestureRecognizer.get()]; 657 652 658 #endif 653 659 … … 760 766 [_hoverGestureRecognizer setDelegate:nil]; 761 767 [self removeGestureRecognizer:_hoverGestureRecognizer.get()]; 768 769 [_lookupGestureRecognizer setDelegate:nil]; 770 [self removeGestureRecognizer:_lookupGestureRecognizer.get()]; 762 771 #endif 763 772 … … 847 856 #if PLATFORM(IOSMAC) 848 857 [self removeGestureRecognizer:_hoverGestureRecognizer.get()]; 858 [self removeGestureRecognizer:_lookupGestureRecognizer.get()]; 849 859 #endif 850 860 } … … 862 872 #if PLATFORM(IOSMAC) 863 873 [self addGestureRecognizer:_hoverGestureRecognizer.get()]; 874 [self addGestureRecognizer:_lookupGestureRecognizer.get()]; 864 875 #endif 865 876 } … … 1468 1479 if ([gestureRecognizer isKindOfClass:[UIHoverGestureRecognizer class]] || [otherGestureRecognizer isKindOfClass:[UIHoverGestureRecognizer class]]) 1469 1480 return YES; 1481 1482 if (([gestureRecognizer isKindOfClass:[_UILookupGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) || ([otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && [gestureRecognizer isKindOfClass:[_UILookupGestureRecognizer class]])) 1483 return YES; 1484 1470 1485 #endif 1471 1486 if (isSamePair(gestureRecognizer, otherGestureRecognizer, _highlightLongPressGestureRecognizer.get(), _textSelectionAssistant.get().forcePressGesture)) … … 6058 6073 6059 6074 #if PLATFORM(IOSMAC) 6075 - (void)_lookupGestureRecognized:(UIGestureRecognizer *)gestureRecognizer 6076 { 6077 NSPoint locationInViewCoordinates = [gestureRecognizer locationInView:self]; 6078 _page->performDictionaryLookupAtLocation(WebCore::FloatPoint(locationInViewCoordinates)); 6079 } 6080 6060 6081 - (void)_hoverGestureRecognizerChanged:(UIGestureRecognizer *)gestureRecognizer 6061 6082 { -
trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
r238657 r238678 122 122 } 123 123 124 void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint&)125 {126 notImplemented();127 }128 129 124 void WebPageProxy::gestureCallback(const WebCore::IntPoint& point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, CallbackID callbackID) 130 125 { -
trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
r238657 r238678 324 324 #endif 325 325 326 void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)327 {328 if (!isValid())329 return;330 331 process().send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID);332 }333 334 void WebPageProxy::performDictionaryLookupOfCurrentSelection()335 {336 if (!isValid())337 return;338 339 process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_pageID);340 }341 342 326 // Complex text input support for plug-ins. 343 327 void WebPageProxy::sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput) -
trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
r238657 r238678 27 27 #import "WebPage.h" 28 28 29 29 30 #import "LoadParameters.h" 31 #import "PluginView.h" 30 32 #import "WebPageProxyMessages.h" 33 #import <WebCore/DictionaryLookup.h> 34 #import <WebCore/Editor.h> 35 #import <WebCore/EventHandler.h> 36 #import <WebCore/FocusController.h> 37 #import <WebCore/HTMLConverter.h> 38 #import <WebCore/HitTestResult.h> 39 #import <WebCore/NodeRenderStyle.h> 31 40 #import <WebCore/PlatformMediaSessionManager.h> 41 #import <WebCore/RenderElement.h> 42 #import <WebCore/RenderObject.h> 32 43 33 44 #if PLATFORM(COCOA) … … 60 71 send(Messages::WebPageProxy::NowPlayingInfoCallback(hasActiveSession, registeredAsNowPlayingApplication, title, duration, elapsedTime, uniqueIdentifier, callbackID)); 61 72 } 73 74 void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint) 75 { 76 if (auto* pluginView = pluginViewForFrame(&m_page->mainFrame())) { 77 if (pluginView->performDictionaryLookupAtLocation(floatPoint)) 78 return; 79 } 80 81 // Find the frame the point is over. 82 HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint))); 83 RefPtr<Range> range; 84 NSDictionary *options; 85 std::tie(range, options) = DictionaryLookup::rangeAtHitTestResult(result); 86 if (!range) 87 return; 88 89 auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame(); 90 if (!frame) 91 return; 92 93 performDictionaryLookupForRange(*frame, *range, options, TextIndicatorPresentationTransition::Bounce); 94 } 95 96 void WebPage::performDictionaryLookupForSelection(Frame& frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition) 97 { 98 RefPtr<Range> selectedRange; 99 NSDictionary *options; 100 std::tie(selectedRange, options) = DictionaryLookup::rangeForSelection(selection); 101 if (selectedRange) 102 performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition); 103 } 104 105 void WebPage::performDictionaryLookupOfCurrentSelection() 106 { 107 auto& frame = m_page->focusController().focusedOrMainFrame(); 108 performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade); 109 } 110 111 void WebPage::performDictionaryLookupForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition) 112 { 113 send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfoForRange(frame, range, options, presentationTransition))); 114 } 115 116 DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition) 117 { 118 Editor& editor = frame.editor(); 119 editor.setIsGettingDictionaryPopupInfo(true); 120 121 DictionaryPopupInfo dictionaryPopupInfo; 122 if (range.text().stripWhiteSpace().isEmpty()) { 123 editor.setIsGettingDictionaryPopupInfo(false); 124 return dictionaryPopupInfo; 125 } 126 127 Vector<FloatQuad> quads; 128 range.absoluteTextQuads(quads); 129 if (quads.isEmpty()) { 130 editor.setIsGettingDictionaryPopupInfo(false); 131 return dictionaryPopupInfo; 132 } 133 134 IntRect rangeRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox()); 135 136 const RenderStyle* style = range.startContainer().renderStyle(); 137 float scaledAscent = style ? style->fontMetrics().ascent() * pageScaleFactor() : 0; 138 dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + scaledAscent); 139 dictionaryPopupInfo.options = options; 140 141 #if PLATFORM(MAC) 142 143 NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range, IncludeImagesInAttributedString::No); 144 145 RetainPtr<NSMutableAttributedString> scaledNSAttributedString = adoptNS([[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]); 146 147 NSFontManager *fontManager = [NSFontManager sharedFontManager]; 148 149 [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) { 150 RetainPtr<NSMutableDictionary> scaledAttributes = adoptNS([attributes mutableCopy]); 151 152 NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName]; 153 if (font) 154 font = [fontManager convertFont:font toSize:font.pointSize * pageScaleFactor()]; 155 if (font) 156 [scaledAttributes setObject:font forKey:NSFontAttributeName]; 157 158 [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range]; 159 }]; 160 161 #endif // PLATFORM(MAC) 162 163 TextIndicatorOptions indicatorOptions = TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges; 164 if (presentationTransition == TextIndicatorPresentationTransition::BounceAndCrossfade) 165 indicatorOptions |= TextIndicatorOptionIncludeSnapshotWithSelectionHighlight; 166 167 RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, indicatorOptions, presentationTransition); 168 if (!textIndicator) { 169 editor.setIsGettingDictionaryPopupInfo(false); 170 return dictionaryPopupInfo; 171 } 172 173 dictionaryPopupInfo.textIndicator = textIndicator->data(); 174 #if PLATFORM(MAC) 175 dictionaryPopupInfo.attributedString = scaledNSAttributedString; 176 #endif // PLATFORM(MAC) 177 178 editor.setIsGettingDictionaryPopupInfo(false); 179 return dictionaryPopupInfo; 180 } 62 181 63 182 } // namespace WebKit -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r238623 r238678 190 190 ForceRepaint(WebKit::CallbackID callbackID) 191 191 192 #if PLATFORM(COCOA)193 # Dictionary support.194 PerformDictionaryLookupAtLocation(WebCore::FloatPoint point)195 #endif196 197 192 #if ENABLE(DATA_DETECTION) 198 193 DetectDataInAllFrames(uint64_t types) -> (struct WebKit::DataDetectionResult result) Async … … 200 195 #endif 201 196 202 #if PLATFORM(MAC) 197 #if PLATFORM(COCOA) 198 # Dictionary support. 199 PerformDictionaryLookupAtLocation(WebCore::FloatPoint point) 203 200 PerformDictionaryLookupOfCurrentSelection() 204 201 #endif -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r238657 r238678 418 418 } 419 419 420 void WebPage::performDictionaryLookupAtLocation(const FloatPoint&)421 {422 notImplemented();423 }424 425 void WebPage::performDictionaryLookupForSelection(Frame&, const VisibleSelection&, TextIndicatorPresentationTransition)426 {427 notImplemented();428 }429 430 void WebPage::performDictionaryLookupForRange(Frame&, Range&, NSDictionary *, TextIndicatorPresentationTransition)431 {432 notImplemented();433 }434 435 420 bool WebPage::performNonEditingBehaviorForSelector(const String&, WebCore::KeyboardEvent*) 436 421 { -
trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
r238657 r238678 390 390 } 391 391 392 void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint) 393 { 394 if (auto* pluginView = pluginViewForFrame(&m_page->mainFrame())) { 395 if (pluginView->performDictionaryLookupAtLocation(floatPoint)) 396 return; 397 } 398 399 // Find the frame the point is over. 400 HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint))); 401 RefPtr<Range> range; 402 NSDictionary *options; 403 std::tie(range, options) = DictionaryLookup::rangeAtHitTestResult(result); 404 if (!range) 405 return; 406 407 auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame(); 408 if (!frame) 409 return; 410 411 performDictionaryLookupForRange(*frame, *range, options, TextIndicatorPresentationTransition::Bounce); 412 } 413 414 void WebPage::performDictionaryLookupForSelection(Frame& frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition) 415 { 416 RefPtr<Range> selectedRange; 417 NSDictionary *options; 418 std::tie(selectedRange, options) = DictionaryLookup::rangeForSelection(selection); 419 if (selectedRange) 420 performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition); 421 } 422 423 void WebPage::performDictionaryLookupOfCurrentSelection() 424 { 425 auto& frame = m_page->focusController().focusedOrMainFrame(); 426 performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade); 427 } 428 429 DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition) 430 { 431 Editor& editor = frame.editor(); 432 editor.setIsGettingDictionaryPopupInfo(true); 433 434 DictionaryPopupInfo dictionaryPopupInfo; 435 if (range.text().stripWhiteSpace().isEmpty()) { 436 editor.setIsGettingDictionaryPopupInfo(false); 437 return dictionaryPopupInfo; 438 } 439 440 Vector<FloatQuad> quads; 441 range.absoluteTextQuads(quads); 442 if (quads.isEmpty()) { 443 editor.setIsGettingDictionaryPopupInfo(false); 444 return dictionaryPopupInfo; 445 } 446 447 IntRect rangeRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox()); 448 449 const RenderStyle* style = range.startContainer().renderStyle(); 450 float scaledAscent = style ? style->fontMetrics().ascent() * pageScaleFactor() : 0; 451 dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + scaledAscent); 452 dictionaryPopupInfo.options = options; 453 454 NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range, IncludeImagesInAttributedString::No); 455 456 RetainPtr<NSMutableAttributedString> scaledNSAttributedString = adoptNS([[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]); 457 458 NSFontManager *fontManager = [NSFontManager sharedFontManager]; 459 460 [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) { 461 RetainPtr<NSMutableDictionary> scaledAttributes = adoptNS([attributes mutableCopy]); 462 463 NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName]; 464 if (font) 465 font = [fontManager convertFont:font toSize:font.pointSize * pageScaleFactor()]; 466 if (font) 467 [scaledAttributes setObject:font forKey:NSFontAttributeName]; 468 469 [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range]; 470 }]; 471 472 TextIndicatorOptions indicatorOptions = TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges; 473 if (presentationTransition == TextIndicatorPresentationTransition::BounceAndCrossfade) 474 indicatorOptions |= TextIndicatorOptionIncludeSnapshotWithSelectionHighlight; 475 476 RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, indicatorOptions, presentationTransition); 477 if (!textIndicator) { 478 editor.setIsGettingDictionaryPopupInfo(false); 479 return dictionaryPopupInfo; 480 } 481 482 dictionaryPopupInfo.textIndicator = textIndicator->data(); 483 dictionaryPopupInfo.attributedString = scaledNSAttributedString; 484 485 editor.setIsGettingDictionaryPopupInfo(false); 486 return dictionaryPopupInfo; 487 } 392 488 393 489 394 #if ENABLE(PDFKIT_PLUGIN) … … 539 444 540 445 #endif 541 542 void WebPage::performDictionaryLookupForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)543 {544 send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfoForRange(frame, range, options, presentationTransition)));545 }546 446 547 447 bool WebPage::performNonEditingBehaviorForSelector(const String& selector, KeyboardEvent* event)
Note: See TracChangeset
for help on using the changeset viewer.