Title: [202524] trunk/Source/WebKit/mac
Revision
202524
Author
[email protected]
Date
2016-06-27 17:33:28 -0700 (Mon, 27 Jun 2016)

Log Message

REGRESSION (r189052): Clipping occurs when using context menu to Look Up words within the Dictionary app
https://bugs.webkit.org/show_bug.cgi?id=159184
<rdar://problem/26370206>

Reviewed by Beth Dakin.

* WebView/WebHTMLView.mm:
(-[WebHTMLView _lookUpInDictionaryFromMenu:]):
* WebView/WebImmediateActionController.h:
* WebView/WebImmediateActionController.mm:
(+[WebImmediateActionController _dictionaryPopupInfoForRange:inFrame:withLookupOptions:indicatorOptions:transition:]):
(-[WebImmediateActionController _animationControllerForText]):
(dictionaryPopupInfoForRange): Deleted.
WebImmediateActionController's code to make a DictionaryPopupInfo and TextIndicator
from a Range in WebKit1 is much better than WebHTMLView's; use it in both cases.

Modified Paths

Diff

Modified: trunk/Source/WebKit/mac/ChangeLog (202523 => 202524)


--- trunk/Source/WebKit/mac/ChangeLog	2016-06-28 00:26:31 UTC (rev 202523)
+++ trunk/Source/WebKit/mac/ChangeLog	2016-06-28 00:33:28 UTC (rev 202524)
@@ -1,3 +1,21 @@
+2016-06-27  Tim Horton  <[email protected]>
+
+        REGRESSION (r189052): Clipping occurs when using context menu to Look Up words within the Dictionary app
+        https://bugs.webkit.org/show_bug.cgi?id=159184
+        <rdar://problem/26370206>
+
+        Reviewed by Beth Dakin.
+
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView _lookUpInDictionaryFromMenu:]):
+        * WebView/WebImmediateActionController.h:
+        * WebView/WebImmediateActionController.mm:
+        (+[WebImmediateActionController _dictionaryPopupInfoForRange:inFrame:withLookupOptions:indicatorOptions:transition:]):
+        (-[WebImmediateActionController _animationControllerForText]):
+        (dictionaryPopupInfoForRange): Deleted.
+        WebImmediateActionController's code to make a DictionaryPopupInfo and TextIndicator
+        from a Range in WebKit1 is much better than WebHTMLView's; use it in both cases.
+
 2016-06-24  Jer Noble  <[email protected]>
 
         Playback controls refer to wrong element when playing multiple items in a page.

Modified: trunk/Source/WebKit/mac/WebView/WebHTMLView.mm (202523 => 202524)


--- trunk/Source/WebKit/mac/WebView/WebHTMLView.mm	2016-06-28 00:26:31 UTC (rev 202523)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLView.mm	2016-06-28 00:33:28 UTC (rev 202524)
@@ -6360,30 +6360,15 @@
 
 - (void)_lookUpInDictionaryFromMenu:(id)sender
 {
-    // Dictionary API will accept a whitespace-only string and display UI as if it were real text,
-    // so bail out early to avoid that.
-    if ([[[self selectedString] _webkit_stringByTrimmingWhitespace] length] == 0)
-        return;
-
-    NSAttributedString *attrString = [self selectedAttributedString];
-
     Frame* coreFrame = core([self _frame]);
     if (!coreFrame)
         return;
 
-    NSRect rect = coreFrame->selection().selectionBounds();
+    RefPtr<Range> selectionRange = coreFrame->selection().selection().firstRange();
+    if (!selectionRange)
+        return;
 
-    NSDictionary *attributes = [attrString fontAttributesInRange:NSMakeRange(0, 1)];
-    NSFont *font = [attributes objectForKey:NSFontAttributeName];
-    if (font)
-        rect.origin.y += [font descender];
-
-    DictionaryPopupInfo info;
-    info.attributedString = attrString;
-    info.origin = coreFrame->view()->contentsToWindow(enclosingIntRect(rect)).location();
-    if (auto textIndicator = TextIndicator::createWithSelectionInFrame(*coreFrame, TextIndicatorOptionIncludeSnapshotWithSelectionHighlight, TextIndicatorPresentationTransition::BounceAndCrossfade))
-        info.textIndicator = textIndicator->data();
-    [[self _webView] _showDictionaryLookupPopup:info];
+    [[self _webView] _showDictionaryLookupPopup:[WebImmediateActionController _dictionaryPopupInfoForRange:*selectionRange inFrame:coreFrame withLookupOptions:nil indicatorOptions:TextIndicatorOptionIncludeSnapshotWithSelectionHighlight transition:TextIndicatorPresentationTransition::BounceAndCrossfade]];
 }
 
 - (void)quickLookWithEvent:(NSEvent *)event

Modified: trunk/Source/WebKit/mac/WebView/WebImmediateActionController.h (202523 => 202524)


--- trunk/Source/WebKit/mac/WebView/WebImmediateActionController.h	2016-06-28 00:26:31 UTC (rev 202523)
+++ trunk/Source/WebKit/mac/WebView/WebImmediateActionController.h	2016-06-28 00:33:28 UTC (rev 202524)
@@ -28,12 +28,20 @@
 #import "WebUIDelegatePrivate.h"
 #import <WebCore/HitTestResult.h>
 #import <WebCore/NSImmediateActionGestureRecognizerSPI.h>
+#import <WebCore/TextIndicator.h>
 #import <wtf/RetainPtr.h>
 
 @class DDActionContext;
 @class QLPreviewMenuItem;
+@class NSDictionary;
 @class WebView;
 
+namespace WebCore {
+class Frame;
+class Range;
+struct DictionaryPopupInfo;
+};
+
 @interface WebImmediateActionController : NSObject <NSImmediateActionGestureRecognizerDelegate> {
 @private
     WebView *_webView;
@@ -55,6 +63,8 @@
 
 - (NSImmediateActionGestureRecognizer *)immediateActionRecognizer;
 
++ (WebCore::DictionaryPopupInfo)_dictionaryPopupInfoForRange:(WebCore::Range&)range inFrame:(WebCore::Frame*)frame withLookupOptions:(NSDictionary *)lookupOptions indicatorOptions:(WebCore::TextIndicatorOptions)indicatorOptions transition:(WebCore::TextIndicatorPresentationTransition)presentationTransition;
+
 @end
 
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit/mac/WebView/WebImmediateActionController.mm (202523 => 202524)


--- trunk/Source/WebKit/mac/WebView/WebImmediateActionController.mm	2016-06-28 00:26:31 UTC (rev 202523)
+++ trunk/Source/WebKit/mac/WebView/WebImmediateActionController.mm	2016-06-28 00:33:28 UTC (rev 202524)
@@ -502,12 +502,14 @@
 
 #pragma mark Text action
 
-static DictionaryPopupInfo dictionaryPopupInfoForRange(Frame* frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
++ (DictionaryPopupInfo)_dictionaryPopupInfoForRange:(Range&)range inFrame:(Frame*)frame withLookupOptions:(NSDictionary *)lookupOptions indicatorOptions:(TextIndicatorOptions)indicatorOptions transition:(TextIndicatorPresentationTransition)presentationTransition
 {
+    // Dictionary API will accept a whitespace-only string and display UI as if it were real text,
+    // so bail out early to avoid that.
     DictionaryPopupInfo popupInfo;
     if (range.text().stripWhiteSpace().isEmpty())
         return popupInfo;
-    
+
     RenderObject* renderer = range.startContainer().renderer();
     const RenderStyle& style = renderer->style();
 
@@ -519,13 +521,13 @@
     IntRect rangeRect = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
 
     popupInfo.origin = NSMakePoint(rangeRect.x(), rangeRect.y() + (style.fontMetrics().descent() * frame->page()->pageScaleFactor()));
-    popupInfo.options = options;
+    popupInfo.options = lookupOptions;
 
     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) {
+    [nsAttributedString enumerateAttributesInRange:NSMakeRange(0, [nsAttributedString length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange attributeRange, BOOL *stop) {
         RetainPtr<NSMutableDictionary> scaledAttributes = adoptNS([attributes mutableCopy]);
 
         NSFont *font = [scaledAttributes objectForKey:NSFontAttributeName];
@@ -534,12 +536,12 @@
             [scaledAttributes setObject:font forKey:NSFontAttributeName];
         }
 
-        [scaledNSAttributedString addAttributes:scaledAttributes.get() range:range];
+        [scaledNSAttributedString addAttributes:scaledAttributes.get() range:attributeRange];
     }];
 
     popupInfo.attributedString = scaledNSAttributedString.get();
 
-    if (auto textIndicator = TextIndicator::createWithRange(range, TextIndicatorOptionDefault, presentationTransition))
+    if (auto textIndicator = TextIndicator::createWithRange(range, indicatorOptions, presentationTransition))
         popupInfo.textIndicator = textIndicator->data();
     return popupInfo;
 }
@@ -562,8 +564,7 @@
     if (!dictionaryRange)
         return nil;
 
-    RefPtr<Range> selectionRange = frame->page()->focusController().focusedOrMainFrame().selection().selection().firstRange();
-    DictionaryPopupInfo dictionaryPopupInfo = dictionaryPopupInfoForRange(frame, *dictionaryRange, options, TextIndicatorPresentationTransition::FadeIn);
+    DictionaryPopupInfo dictionaryPopupInfo = [WebImmediateActionController _dictionaryPopupInfoForRange:*dictionaryRange inFrame:frame withLookupOptions:options indicatorOptions:TextIndicatorOptionDefault transition: TextIndicatorPresentationTransition::FadeIn];
     if (!dictionaryPopupInfo.attributedString)
         return nil;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to