Implement yellow highlight for WebKit1 data detectors
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Dec 2014 20:48:39 +0000 (20:48 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Dec 2014 20:48:39 +0000 (20:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138956
<rdar://problem/18992185>

Reviewed by Beth Dakin.

* page/TextIndicator.cpp:
(WebCore::TextIndicator::createWithSelectionInFrame):
(WebCore::TextIndicator::TextIndicator):
* page/TextIndicator.h:
(WebCore::TextIndicator::selectionRectInScreenCoordinates):
(WebCore::TextIndicator::textBoundingRectInScreenCoordinates):
(WebCore::TextIndicator::selectionRectInWindowCoordinates): Deleted.
(WebCore::TextIndicator::textBoundingRectInWindowCoordinates): Deleted.
Store TextIndicator rects in screen coordinates, since that's what we
want anyway, and this makes it easier to share this code between the WebKits.

* page/mac/TextIndicatorWindow.mm:
(-[WebTextIndicatorView initWithFrame:textIndicator:margin:]):
(WebCore::TextIndicatorWindow::setTextIndicator):
Avoid some rect conversion because the TextIndicator rects are already in screen coordinates.

* WebView/WebActionMenuController.h:
* WebView/WebActionMenuController.mm:
(-[WebActionMenuController webView:willHandleMouseDown:]):
(-[WebActionMenuController webView:didHandleScrollWheel:]):
(-[WebActionMenuController prepareForMenu:withEvent:]):
(-[WebActionMenuController didCloseMenu:withEvent:]):
(-[WebActionMenuController _defaultMenuItemsForDataDetectedText]):
(-[WebActionMenuController _showTextIndicator]):
(-[WebActionMenuController _hideTextIndicator]):
(-[WebActionMenuController _dismissActionMenuPopovers]):
Copy the WebKit2 WKActionMenuController TextIndicator implementation
into WebActionMenuController. The only significant difference is
that we build the TextIndicator right at menu construction time
instead of in the Web process.

* WebView/WebHTMLView.mm:
(-[WebHTMLView scrollWheel:]):
Let the WebActionMenuController know that we're handling a scroll.

(-[WebHTMLView mouseDown:]):
Let the WebActionMenuController know that we're handling a mouseDown.

* WebView/WebView.mm:
(-[WebView _setTextIndicator:fadeOut:animationCompletionHandler:]):
(-[WebView _clearTextIndicator]):
(-[WebView _actionMenuController]):
(-[WebView _convertRectFromRootView:]): Deleted.
* WebView/WebViewData.h:
* WebView/WebViewData.mm:
* WebView/WebViewInternal.h:
Keep a TextIndicatorWindow on WebView, just like WKView does.
Expose the WebActionMenuController on WebView (internally).

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<TextIndicatorData>::encode):
(IPC::ArgumentCoder<TextIndicatorData>::decode):
* WebProcess/WebPage/FindController.cpp:
(WebKit::FindController::updateFindIndicator):
(WebKit::FindController::drawRect):
Adjust to the fact that TextIndicator keeps screen-relative rects.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176599 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/TextIndicator.cpp
Source/WebCore/page/TextIndicator.h
Source/WebCore/page/mac/TextIndicatorWindow.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebActionMenuController.h
Source/WebKit/mac/WebView/WebActionMenuController.mm
Source/WebKit/mac/WebView/WebHTMLView.mm
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/mac/WebView/WebViewData.h
Source/WebKit/mac/WebView/WebViewData.mm
Source/WebKit/mac/WebView/WebViewInternal.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp
Source/WebKit2/WebProcess/WebPage/FindController.cpp

index a793706bf797bfaabe85b2196e74f83bb0b8488a..71677d586f4ca446f71859cb1bc3271cd461fe74 100644 (file)
@@ -1,3 +1,27 @@
+2014-12-01  Tim Horton  <timothy_horton@apple.com>
+
+        Implement yellow highlight for WebKit1 data detectors
+        https://bugs.webkit.org/show_bug.cgi?id=138956
+        <rdar://problem/18992185>
+
+        Reviewed by Beth Dakin.
+
+        * page/TextIndicator.cpp:
+        (WebCore::TextIndicator::createWithSelectionInFrame):
+        (WebCore::TextIndicator::TextIndicator):
+        * page/TextIndicator.h:
+        (WebCore::TextIndicator::selectionRectInScreenCoordinates):
+        (WebCore::TextIndicator::textBoundingRectInScreenCoordinates):
+        (WebCore::TextIndicator::selectionRectInWindowCoordinates): Deleted.
+        (WebCore::TextIndicator::textBoundingRectInWindowCoordinates): Deleted.
+        Store TextIndicator rects in screen coordinates, since that's what we
+        want anyway, and this makes it easier to share this code between the WebKits.
+
+        * page/mac/TextIndicatorWindow.mm:
+        (-[WebTextIndicatorView initWithFrame:textIndicator:margin:]):
+        (WebCore::TextIndicatorWindow::setTextIndicator):
+        Avoid some rect conversion because the TextIndicator rects are already in screen coordinates.
+
 2014-12-01  Anders Carlsson  <andersca@apple.com>
 
         Remove old site specific quirks code that was added in 2009
index 2ea6b210953bce2689b84776e5779bc31e2012f6..49e5f7e1eb33f873f05975ffa7e7c7592d977d35 100644 (file)
@@ -143,7 +143,7 @@ PassRefPtr<TextIndicator> TextIndicator::createWithSelectionInFrame(Frame& frame
 
     // Store the selection rect in window coordinates, to be used subsequently
     // to determine if the indicator and selection still precisely overlap.
-    IntRect selectionRectInWindowCoordinates = frame.view()->contentsToWindow(selectionRect);
+    IntRect selectionRectInScreenCoordinates = frame.view()->contentsToScreen(selectionRect);
 
     Vector<FloatRect> textRects;
     frame.selection().getClippedVisibleTextRectangles(textRects);
@@ -151,23 +151,23 @@ PassRefPtr<TextIndicator> TextIndicator::createWithSelectionInFrame(Frame& frame
     // The bounding rect of all the text rects can be different than the selection
     // rect when the selection spans multiple lines; the indicator doesn't actually
     // care where the selection highlight goes, just where the text actually is.
-    FloatRect textBoundingRectInWindowCoordinates;
-    Vector<FloatRect> textRectsInWindowCoordinates;
+    FloatRect textBoundingRectInScreenCoordinates;
+    Vector<FloatRect> textRectsInScreenCoordinates;
     for (const FloatRect& textRect : textRects) {
-        FloatRect textRectInWindowCoordinates = frame.view()->contentsToWindow(enclosingIntRect(textRect));
-        textRectsInWindowCoordinates.append(textRectInWindowCoordinates);
-        textBoundingRectInWindowCoordinates.unite(textRectInWindowCoordinates);
+        FloatRect textRectInScreenCoordinates = frame.view()->contentsToScreen(enclosingIntRect(textRect));
+        textRectsInScreenCoordinates.append(textRectInScreenCoordinates);
+        textBoundingRectInScreenCoordinates.unite(textRectInScreenCoordinates);
     }
 
     Vector<FloatRect> textRectsInBoundingRectCoordinates;
-    for (auto rect : textRectsInWindowCoordinates) {
-        rect.moveBy(-textBoundingRectInWindowCoordinates.location());
+    for (auto rect : textRectsInScreenCoordinates) {
+        rect.moveBy(-textBoundingRectInScreenCoordinates.location());
         textRectsInBoundingRectCoordinates.append(rect);
     }
 
     TextIndicatorData data;
-    data.selectionRectInWindowCoordinates = selectionRectInWindowCoordinates;
-    data.textBoundingRectInWindowCoordinates = textBoundingRectInWindowCoordinates;
+    data.selectionRectInScreenCoordinates = selectionRectInScreenCoordinates;
+    data.textBoundingRectInScreenCoordinates = textBoundingRectInScreenCoordinates;
     data.textRectsInBoundingRectCoordinates = textRectsInBoundingRectCoordinates;
     data.contentImageScaleFactor = frame.page()->deviceScaleFactor();
     data.contentImage = indicatorBitmap;
@@ -180,7 +180,7 @@ PassRefPtr<TextIndicator> TextIndicator::createWithSelectionInFrame(Frame& frame
 TextIndicator::TextIndicator(const TextIndicatorData& data)
     : m_data(data)
 {
-    ASSERT(m_data.contentImageScaleFactor != 1 || m_data.contentImage->size() == enclosingIntRect(m_data.selectionRectInWindowCoordinates).size());
+    ASSERT(m_data.contentImageScaleFactor != 1 || m_data.contentImage->size() == enclosingIntRect(m_data.selectionRectInScreenCoordinates).size());
 
     if (textIndicatorsForTextRectsOverlap(m_data.textRectsInBoundingRectCoordinates)) {
         m_data.textRectsInBoundingRectCoordinates[0] = unionRect(m_data.textRectsInBoundingRectCoordinates);
index be10a3333f2fee235713ef708f0a2d81f4c68d24..47ba6c323798e63964388aa6e916ba7446b81e6c 100644 (file)
@@ -51,8 +51,8 @@ enum class TextIndicatorPresentationTransition {
 };
 
 struct TextIndicatorData {
-    FloatRect selectionRectInWindowCoordinates;
-    FloatRect textBoundingRectInWindowCoordinates;
+    FloatRect selectionRectInScreenCoordinates;
+    FloatRect textBoundingRectInScreenCoordinates;
     Vector<FloatRect> textRectsInBoundingRectCoordinates;
     float contentImageScaleFactor;
     RefPtr<Image> contentImageWithHighlight;
@@ -68,8 +68,8 @@ public:
 
     ~TextIndicator();
 
-    FloatRect selectionRectInWindowCoordinates() const { return m_data.selectionRectInWindowCoordinates; }
-    FloatRect textBoundingRectInWindowCoordinates() const { return m_data.textBoundingRectInWindowCoordinates; }
+    FloatRect selectionRectInScreenCoordinates() const { return m_data.selectionRectInScreenCoordinates; }
+    FloatRect textBoundingRectInScreenCoordinates() const { return m_data.textBoundingRectInScreenCoordinates; }
     const Vector<FloatRect>& textRectsInBoundingRectCoordinates() const { return m_data.textRectsInBoundingRectCoordinates; }
     float contentImageScaleFactor() const { return m_data.contentImageScaleFactor; }
     Image *contentImageWithHighlight() const { return m_data.contentImageWithHighlight.get(); }
index 0ac426c7576acdf4a89c655aa407e33df4bac148..1f9be07bc9d68c002879b74decd852ed242a913e 100644 (file)
@@ -171,7 +171,7 @@ using namespace WebCore;
         [textLayer setContents:(id)contentsImage.get()];
 
         FloatRect imageRect = textRect;
-        imageRect.move(_textIndicator->textBoundingRectInWindowCoordinates().location() - _textIndicator->selectionRectInWindowCoordinates().location());
+        imageRect.move(_textIndicator->textBoundingRectInScreenCoordinates().location() - _textIndicator->selectionRectInScreenCoordinates().location());
         [textLayer setContentsRect:CGRectMake(imageRect.x() / contentsImageLogicalSize.width(), imageRect.y() / contentsImageLogicalSize.height(), imageRect.width() / contentsImageLogicalSize.width(), imageRect.height() / contentsImageLogicalSize.height())];
         [textLayer setContentsGravity:kCAGravityCenter];
         [textLayer setContentsScale:_textIndicator->contentImageScaleFactor()];
@@ -279,16 +279,12 @@ void TextIndicatorWindow::setTextIndicator(PassRefPtr<TextIndicator> textIndicat
     if (!m_textIndicator)
         return;
 
-    NSRect contentRect = m_textIndicator->textBoundingRectInWindowCoordinates();
-
+    NSRect contentRect = m_textIndicator->textBoundingRectInScreenCoordinates();
     CGFloat horizontalMargin = std::max(dropShadowBlurRadius * 2 + horizontalBorder, contentRect.size.width * 2);
     CGFloat verticalMargin = std::max(dropShadowBlurRadius * 2 + verticalBorder, contentRect.size.height * 2);
 
     contentRect = NSInsetRect(contentRect, -horizontalMargin, -verticalMargin);
-    NSRect windowFrameRect = NSIntegralRect([m_targetView convertRect:contentRect toView:nil]);
-    windowFrameRect = [[m_targetView window] convertRectToScreen:windowFrameRect];
-    NSRect windowContentRect = [NSWindow contentRectForFrameRect:windowFrameRect styleMask:NSBorderlessWindowMask];
-
+    NSRect windowContentRect = [NSWindow contentRectForFrameRect:NSIntegralRect(contentRect) styleMask:NSBorderlessWindowMask];
     m_textIndicatorWindow = adoptNS([[NSWindow alloc] initWithContentRect:windowContentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
 
     [m_textIndicatorWindow setBackgroundColor:[NSColor clearColor]];
index 2a42ad2bb205e9baa63ecde79697634296a88566..94ef098af584d96c41a7d6af5078df9c2c763a97 100644 (file)
@@ -1,3 +1,44 @@
+2014-12-01  Tim Horton  <timothy_horton@apple.com>
+
+        Implement yellow highlight for WebKit1 data detectors
+        https://bugs.webkit.org/show_bug.cgi?id=138956
+        <rdar://problem/18992185>
+
+        Reviewed by Beth Dakin.
+
+        * WebView/WebActionMenuController.h:
+        * WebView/WebActionMenuController.mm:
+        (-[WebActionMenuController webView:willHandleMouseDown:]):
+        (-[WebActionMenuController webView:didHandleScrollWheel:]):
+        (-[WebActionMenuController prepareForMenu:withEvent:]):
+        (-[WebActionMenuController didCloseMenu:withEvent:]):
+        (-[WebActionMenuController _defaultMenuItemsForDataDetectedText]):
+        (-[WebActionMenuController _showTextIndicator]):
+        (-[WebActionMenuController _hideTextIndicator]):
+        (-[WebActionMenuController _dismissActionMenuPopovers]):
+        Copy the WebKit2 WKActionMenuController TextIndicator implementation
+        into WebActionMenuController. The only significant difference is
+        that we build the TextIndicator right at menu construction time
+        instead of in the Web process.
+
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView scrollWheel:]):
+        Let the WebActionMenuController know that we're handling a scroll.
+
+        (-[WebHTMLView mouseDown:]):
+        Let the WebActionMenuController know that we're handling a mouseDown.
+
+        * WebView/WebView.mm:
+        (-[WebView _setTextIndicator:fadeOut:animationCompletionHandler:]):
+        (-[WebView _clearTextIndicator]):
+        (-[WebView _actionMenuController]):
+        (-[WebView _convertRectFromRootView:]): Deleted.
+        * WebView/WebViewData.h:
+        * WebView/WebViewData.mm:
+        * WebView/WebViewInternal.h:
+        Keep a TextIndicatorWindow on WebView, just like WKView does.
+        Expose the WebActionMenuController on WebView (internally).
+
 2014-12-01  Anders Carlsson  <andersca@apple.com>
 
         Remove old site specific quirks code that was added in 2009
index d5e4c74a1807fef2d8db8ef4dcc622d5cad79c05..6579125fff3c0627771f5c3adf72ca9caceadfa3 100644 (file)
@@ -34,6 +34,7 @@
 
 namespace WebCore {
 class Range;
+class TextIndicator;
 }
 
 @interface WebActionMenuController : NSObject <NSSharingServiceDelegate, NSSharingServicePickerDelegate> {
@@ -44,6 +45,9 @@ class Range;
     RetainPtr<NSSharingServicePicker> _sharingServicePicker;
     RetainPtr<DDActionContext> _currentActionContext;
     RefPtr<WebCore::Range> _currentDetectedDataRange;
+    BOOL _isShowingTextIndicator;
+    RefPtr<WebCore::TextIndicator> _currentDetectedDataTextIndicator;
+    BOOL _hasActivatedActionContext;
 }
 
 - (id)initWithWebView:(WebView *)webView;
@@ -52,4 +56,7 @@ class Range;
 - (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
 - (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
 
+- (void)webView:(WebView *)webView willHandleMouseDown:(NSEvent *)event;
+- (void)webView:(WebView *)webView didHandleScrollWheel:(NSEvent *)event;
+
 @end
index 3fb34d773bce9c9f421ade356a63d9dedd569878..a976a9bf1851c97593204d969b2776f70f0d0a7b 100644 (file)
@@ -61,6 +61,7 @@
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/SoftLinking.h>
 #import <WebCore/TextCheckerClient.h>
+#import <WebCore/TextIndicator.h>
 #import <WebKitSystemInterface.h>
 #import <objc/objc-class.h>
 #import <objc/objc.h>
@@ -130,6 +131,19 @@ struct DictionaryPopupInfo {
     return [[[WebElementDictionary alloc] initWithHitTestResult:_hitTestResult] autorelease];
 }
 
+- (void)webView:(WebView *)webView willHandleMouseDown:(NSEvent *)event
+{
+    if (_type == WebActionMenuDataDetectedItem && _currentActionContext && _hasActivatedActionContext) {
+        [getDDActionsManagerClass() didUseActions];
+        _hasActivatedActionContext = NO;
+    }
+}
+
+- (void)webView:(WebView *)webView didHandleScrollWheel:(NSEvent *)event
+{
+    [self _dismissActionMenuPopovers];
+}
+
 - (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event
 {
     if (!_webView)
@@ -139,6 +153,7 @@ struct DictionaryPopupInfo {
     if (menu != actionMenu)
         return;
 
+    [self _dismissActionMenuPopovers];
     [actionMenu removeAllItems];
 
     WebElementDictionary *hitTestResult = [self performHitTestAtPoint:event.locationInWindow];
@@ -151,9 +166,12 @@ struct DictionaryPopupInfo {
     for (NSMenuItem *item in menuItems)
         [actionMenu addItem:item];
 
-    if (_type == WebActionMenuDataDetectedItem && _currentActionContext && ![getDDActionsManagerClass() shouldUseActionsWithContext:_currentActionContext.get()]) {
-        [menu cancelTracking];
-        [menu removeAllItems];
+    if (_type == WebActionMenuDataDetectedItem && _currentActionContext) {
+        _hasActivatedActionContext = YES;
+        if (![getDDActionsManagerClass() shouldUseActionsWithContext:_currentActionContext.get()]) {
+            [menu cancelTracking];
+            [menu removeAllItems];
+        }
     }
 }
 
@@ -219,11 +237,16 @@ struct DictionaryPopupInfo {
     if (menu != _webView.actionMenu)
         return;
 
-    if (_type == WebActionMenuDataDetectedItem && _currentActionContext)
+    if (_type == WebActionMenuDataDetectedItem && _currentActionContext && _hasActivatedActionContext) {
         [getDDActionsManagerClass() didUseActions];
+        _hasActivatedActionContext = NO;
+    }
 
     _type = WebActionMenuNone;
     _sharingServicePicker = nil;
+    _currentDetectedDataTextIndicator = nil;
+    _currentDetectedDataRange = nil;
+    _currentActionContext = nil;
 }
 
 #pragma mark Link actions
@@ -578,16 +601,22 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
             return @[ ];
     }
 
-    // FIXME: We should hide/show the yellow highlight here.
+    _currentDetectedDataTextIndicator = TextIndicator::createWithRange(*detectedDataRange, TextIndicatorPresentationTransition::BounceAndCrossfade);
+
     _currentActionContext = [actionContext contextForView:_webView altMode:YES interactionStartedHandler:^() {
     } interactionChangedHandler:^() {
+        [self _showTextIndicator];
     } interactionStoppedHandler:^() {
+        [self _hideTextIndicator];
     }];
     _currentDetectedDataRange = detectedDataRange;
 
-    [_currentActionContext setHighlightFrame:[_webView.window convertRectToScreen:[_webView convertRect:detectedDataBoundingBox toView:nil]]];
+    [_currentActionContext setHighlightFrame:[_webView.window convertRectToScreen:detectedDataBoundingBox]];
 
-    return [[getDDActionsManagerClass() sharedManager] menuItemsForResult:[_currentActionContext mainResult] actionContext:_currentActionContext.get()];
+    NSArray *menuItems = [[getDDActionsManagerClass() sharedManager] menuItemsForResult:[_currentActionContext mainResult] actionContext:_currentActionContext.get()];
+    if (menuItems.count == 1 && _currentDetectedDataTextIndicator)
+        _currentDetectedDataTextIndicator->setPresentationTransition(TextIndicatorPresentationTransition::Bounce);
+    return menuItems;
 }
 
 - (void)_copySelection:(id)sender
@@ -902,4 +931,35 @@ static DictionaryPopupInfo performDictionaryLookupForRange(Frame* frame, Range&
     return @[ ];
 }
 
+#pragma mark Text Indicator
+
+- (void)_showTextIndicator
+{
+    if (_isShowingTextIndicator)
+        return;
+
+    if (_type == WebActionMenuDataDetectedItem && _currentDetectedDataTextIndicator) {
+        [_webView _setTextIndicator:_currentDetectedDataTextIndicator.get() fadeOut:NO animationCompletionHandler:^ { }];
+        _isShowingTextIndicator = YES;
+    }
+}
+
+- (void)_hideTextIndicator
+{
+    if (!_isShowingTextIndicator)
+        return;
+
+    [_webView _clearTextIndicator];
+    _isShowingTextIndicator = NO;
+}
+
+- (void)_dismissActionMenuPopovers
+{
+    DDActionsManager *actionsManager = [getDDActionsManagerClass() sharedManager];
+    if ([actionsManager respondsToSelector:@selector(requestBubbleClosureUnanchorOnFailure:)])
+        [actionsManager requestBubbleClosureUnanchorOnFailure:YES];
+
+    [self _hideTextIndicator];
+}
+
 @end
index 156f1f15569f795182f6dccfe92f2d7f3f5eb8b0..267da344688ac70cf3a5f34f405e41518bf74c6a 100644 (file)
@@ -34,6 +34,7 @@
 #import "DOMDocumentInternal.h"
 #import "DOMNodeInternal.h"
 #import "DOMRangeInternal.h"
+#import "WebActionMenuController.h"
 #import "WebArchive.h"
 #import "WebClipView.h"
 #import "WebDOMOperationsInternal.h"
@@ -3700,6 +3701,8 @@ static void setMenuTargets(NSMenu* menu)
 #if !PLATFORM(IOS)
     if (!frame || !frame->eventHandler().wheelEvent(event))
         [super scrollWheel:event];
+
+    [[[self _webView] _actionMenuController] webView:[self _webView] didHandleScrollWheel:event];
 #else
     if (frame)
         frame->eventHandler().wheelEvent(event);
@@ -3812,6 +3815,10 @@ static void setMenuTargets(NSMenu* menu)
     // Record the mouse down position so we can determine drag hysteresis.
     [self _setMouseDownEvent:event];
 
+#if PLATFORM(MAC)
+    [[[self _webView] _actionMenuController] webView:[self _webView] willHandleMouseDown:event];
+#endif
+
 #if PLATFORM(IOS)
     // TEXTINPUT: if there is marked text and the current input
     // manager wants to handle mouse events, we need to make sure to
index 8396e22613f106203ca075f40098e701db07bacf..a9ecacce24c09ece61abb7b0944a38c18f10d353 100644 (file)
 #import "WebNSPrintOperationExtras.h"
 #import "WebPDFView.h"
 #import <WebCore/NSViewSPI.h>
+#import <WebCore/TextIndicator.h>
+#import <WebCore/TextIndicatorWindow.h>
 #import <WebCore/WebVideoFullscreenController.h>
 #else
 #import "MemoryMeasure.h"
@@ -8560,7 +8562,7 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
     return NSMakeRect(rect.origin.x, [self bounds].size.height - rect.origin.y - rect.size.height, rect.size.width, rect.size.height);
 }
 
-#if !PLATFORM(IOS)
+#if PLATFORM(MAC)
 - (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event
 {
     if (menu != self.actionMenu)
@@ -8584,6 +8586,29 @@ static void glibContextIterationCallback(CFRunLoopObserverRef, CFRunLoopActivity
 
     [_private->actionMenuController didCloseMenu:menu withEvent:event];
 }
+
+- (void)_setTextIndicator:(TextIndicator *)textIndicator fadeOut:(BOOL)fadeOut animationCompletionHandler:(std::function<void ()>)completionHandler
+{
+    if (!textIndicator) {
+        _private->textIndicatorWindow = nullptr;
+        return;
+    }
+
+    if (!_private->textIndicatorWindow)
+        _private->textIndicatorWindow = std::make_unique<TextIndicatorWindow>(self);
+
+    _private->textIndicatorWindow->setTextIndicator(textIndicator, fadeOut, WTF::move(completionHandler));
+}
+
+- (void)_clearTextIndicator
+{
+    [self _setTextIndicator:nullptr fadeOut:NO animationCompletionHandler:^ { }];
+}
+
+- (WebActionMenuController *)_actionMenuController
+{
+    return _private->actionMenuController;
+}
 #endif
 
 @end
index f447a0126cbf149eb31ff8d7fcec5dd7ad01435a..934e9f8d909cacad78982f385a45ed6ce2f2e484 100644 (file)
@@ -47,6 +47,7 @@ namespace WebCore {
 class AlternativeTextUIController;
 class HistoryItem;
 class Page;
+class TextIndicatorWindow;
 }
 
 @class WebActionMenuController;
@@ -147,6 +148,7 @@ private:
     WebNodeHighlight *currentNodeHighlight;
 
     WebActionMenuController *actionMenuController;
+    std::unique_ptr<WebCore::TextIndicatorWindow> textIndicatorWindow;
 
     BOOL allowsUndo;
         
index 89704c98ec2b6d0dd95cb6641764bada6f4a0965..4cf6de1795408c5d7aba13e098f42cbe5b371ba8 100644 (file)
@@ -36,6 +36,7 @@
 #import <WebCore/AlternativeTextUIController.h>
 #import <WebCore/WebCoreObjCExtras.h>
 #import <WebCore/HistoryItem.h>
+#import <WebCore/TextIndicatorWindow.h>
 #import <objc/objc-auto.h>
 #import <runtime/InitializeThreading.h>
 #import <wtf/MainThread.h>
index 3776f55168c07d64e7d40f65204c6ab459cbee56..ba616186ff5c886cafa7fae481d2efc3b94cdcbe 100644 (file)
 #import <WebCore/LayoutMilestones.h>
 #import <WebCore/TextAlternativeWithRange.h>
 #import <WebCore/WebCoreKeyboardUIMode.h>
-
-#include <wtf/Forward.h>
-#include <wtf/RetainPtr.h>
+#import <functional>
+#import <wtf/Forward.h>
+#import <wtf/RetainPtr.h>
 
 namespace WebCore {
 class Element;
 class Event;
 class Frame;
+class HTMLVideoElement;
 class HistoryItem;
-class URL;
 class KeyboardEvent;
 class Page;
 class RenderBox;
-class HTMLVideoElement;
+class TextIndicator;
+class URL;
 struct DictationAlternative;
 }
 
 class WebSelectionServiceController;
 #endif
 
+@class WebActionMenuController;
 @class WebBasePluginPackage;
 @class WebDownload;
 @class WebNodeHighlight;
@@ -254,4 +256,10 @@ OBJC_CLASS NSTextAlternatives;
 - (NSPoint)_convertPointFromRootView:(NSPoint)point;
 - (NSRect)_convertRectFromRootView:(NSRect)rect;
 
+#if PLATFORM(MAC) && defined(__cplusplus)
+- (void)_setTextIndicator:(WebCore::TextIndicator*)textIndicator fadeOut:(BOOL)fadeOut animationCompletionHandler:(std::function<void ()>)completionHandler;
+- (void)_clearTextIndicator;
+- (WebActionMenuController *)_actionMenuController;
+#endif
+
 @end
index 17aae4aea46339471751cf40e99b5f11bae530fe..fe7a53c4bcda8661badd735dfaee123569f1ddde 100644 (file)
@@ -1,3 +1,19 @@
+2014-12-01  Tim Horton  <timothy_horton@apple.com>
+
+        Implement yellow highlight for WebKit1 data detectors
+        https://bugs.webkit.org/show_bug.cgi?id=138956
+        <rdar://problem/18992185>
+
+        Reviewed by Beth Dakin.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<TextIndicatorData>::encode):
+        (IPC::ArgumentCoder<TextIndicatorData>::decode):
+        * WebProcess/WebPage/FindController.cpp:
+        (WebKit::FindController::updateFindIndicator):
+        (WebKit::FindController::drawRect):
+        Adjust to the fact that TextIndicator keeps screen-relative rects.
+
 2014-12-01  Anders Carlsson  <andersca@apple.com>
 
         Remove old site specific quirks code that was added in 2009
index 2b3fb563903ead750fae810d9852300396043ce5..d2fda12d23e6b7809c478e44bcb06b04c44745f2 100644 (file)
@@ -1963,8 +1963,8 @@ bool ArgumentCoder<BlobPart>::decode(ArgumentDecoder& decoder, BlobPart& blobPar
 
 void ArgumentCoder<TextIndicatorData>::encode(ArgumentEncoder& encoder, const TextIndicatorData& textIndicatorData)
 {
-    encoder << textIndicatorData.selectionRectInWindowCoordinates;
-    encoder << textIndicatorData.textBoundingRectInWindowCoordinates;
+    encoder << textIndicatorData.selectionRectInScreenCoordinates;
+    encoder << textIndicatorData.textBoundingRectInScreenCoordinates;
     encoder << textIndicatorData.textRectsInBoundingRectCoordinates;
     encoder << textIndicatorData.contentImageScaleFactor;
     encoder.encodeEnum(textIndicatorData.presentationTransition);
@@ -1982,10 +1982,10 @@ void ArgumentCoder<TextIndicatorData>::encode(ArgumentEncoder& encoder, const Te
 
 bool ArgumentCoder<TextIndicatorData>::decode(ArgumentDecoder& decoder, TextIndicatorData& textIndicatorData)
 {
-    if (!decoder.decode(textIndicatorData.selectionRectInWindowCoordinates))
+    if (!decoder.decode(textIndicatorData.selectionRectInScreenCoordinates))
         return false;
 
-    if (!decoder.decode(textIndicatorData.textBoundingRectInWindowCoordinates))
+    if (!decoder.decode(textIndicatorData.textBoundingRectInScreenCoordinates))
         return false;
 
     if (!decoder.decode(textIndicatorData.textRectsInBoundingRectCoordinates))
index a86b09611a8faf91f14f7376cf02f40f4aa25baa..05e31776cfb3448f32f7b682a17487250d7dc218 100644 (file)
@@ -318,7 +318,7 @@ bool FindController::updateFindIndicator(Frame& selectedFrame, bool isShowingOve
     if (!indicator)
         return false;
 
-    m_findIndicatorRect = enclosingIntRect(indicator->selectionRectInWindowCoordinates());
+    m_findIndicatorRect = enclosingIntRect(indicator->selectionRectInScreenCoordinates());
     m_webPage->send(Messages::WebPageProxy::SetTextIndicator(indicator->data(), !isShowingOverlay));
     m_isShowingFindIndicator = true;
 
@@ -450,7 +450,7 @@ void FindController::drawRect(PageOverlay&, GraphicsContext& graphicsContext, co
         return;
 
     if (Frame* selectedFrame = frameWithSelection(m_webPage->corePage())) {
-        IntRect findIndicatorRect = selectedFrame->view()->contentsToWindow(enclosingIntRect(selectedFrame->selection().selectionBounds()));
+        IntRect findIndicatorRect = selectedFrame->view()->contentsToScreen(enclosingIntRect(selectedFrame->selection().selectionBounds()));
 
         if (findIndicatorRect != m_findIndicatorRect)
             hideFindIndicator();