Title: [150653] trunk/Source
Revision
150653
Author
[email protected]
Date
2013-05-24 12:41:37 -0700 (Fri, 24 May 2013)

Log Message

Add more lines to the context during Dictionary lookups
https://bugs.webkit.org/show_bug.cgi?id=115256

Patch by Thomas Deniau <[email protected]> on 2013-05-24
Reviewed by Ryosuke Niwa.

Source/WebCore:

No new tests - no new functionality.

* WebCore.exp.in: Export a few methods in VisibleUnits needed to be able
to call previousLinePosition(), nextLinePosition(), startOfLine() and
endOfLine() in WebPageMac.mm when determining the context while looking
up a dictionary definition. These symbols used to be exported for iOS
only, export them on the desktop too.

Source/WebKit2:

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation):
Instead of using the current paragraph as the context (which stops at
line breaks), get a few lines before and after the point, so that the
context contains at least four lines in each direction.
This way the Dictionary will be able to look up things that extend past
the current line.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (150652 => 150653)


--- trunk/Source/WebCore/ChangeLog	2013-05-24 19:07:02 UTC (rev 150652)
+++ trunk/Source/WebCore/ChangeLog	2013-05-24 19:41:37 UTC (rev 150653)
@@ -1,3 +1,18 @@
+2013-05-24  Thomas Deniau  <[email protected]>
+
+        Add more lines to the context during Dictionary lookups
+        https://bugs.webkit.org/show_bug.cgi?id=115256
+
+        Reviewed by Ryosuke Niwa.
+
+        No new tests - no new functionality.
+
+        * WebCore.exp.in: Export a few methods in VisibleUnits needed to be able
+        to call previousLinePosition(), nextLinePosition(), startOfLine() and
+        endOfLine() in WebPageMac.mm when determining the context while looking
+        up a dictionary definition. These symbols used to be exported for iOS
+        only, export them on the desktop too.
+
 2013-05-24  Anders Carlsson  <[email protected]>
 
         Remove PagePopup code

Modified: trunk/Source/WebCore/WebCore.exp.in (150652 => 150653)


--- trunk/Source/WebCore/WebCore.exp.in	2013-05-24 19:07:02 UTC (rev 150652)
+++ trunk/Source/WebCore/WebCore.exp.in	2013-05-24 19:41:37 UTC (rev 150653)
@@ -168,6 +168,7 @@
 __ZN7WebCore11URLWithDataEP6NSDataP5NSURL
 __ZN7WebCore11iBeamCursorEv
 __ZN7WebCore11memoryCacheEv
+__ZN7WebCore11startOfLineERKNS_15VisiblePositionE
 __ZN7WebCore11startOfWordERKNS_15VisiblePositionENS_9EWordSideE
 __ZN7WebCore11writeToFileEiPKci
 __ZN7WebCore12ChromeClient23paintCustomOverhangAreaEPNS_15GraphicsContextERKNS_7IntRectES5_S5_
@@ -566,6 +567,7 @@
 __ZN7WebCore16enclosingIntRectERKNS_9FloatRectE
 __ZN7WebCore16isEndOfParagraphERKNS_15VisiblePositionENS_27EditingBoundaryCrossingRuleE
 __ZN7WebCore16isUserVisibleURLEP8NSString
+__ZN7WebCore16nextLinePositionERKNS_15VisiblePositionEiNS_12EditableTypeE
 __ZN7WebCore16scriptNameToCodeERKN3WTF6StringE
 __ZN7WebCore16startOfParagraphERKNS_15VisiblePositionENS_27EditingBoundaryCrossingRuleE
 __ZN7WebCore17CredentialStorage24getFromPersistentStorageERKNS_15ProtectionSpaceE
@@ -686,6 +688,7 @@
 __ZN7WebCore20UserGestureIndicatorD1Ev
 __ZN7WebCore20deleteEmptyDirectoryERKN3WTF6StringE
 __ZN7WebCore20makeRGBA32FromFloatsEffff
+__ZN7WebCore20previousLinePositionERKNS_15VisiblePositionEiNS_12EditableTypeE
 __ZN7WebCore20protocolIsJavaScriptERKN3WTF6StringE
 __ZN7WebCore20toUInt32EnforceRangeEPN3JSC9ExecStateENS0_7JSValueE
 __ZN7WebCore21BackForwardController11itemAtIndexEi
@@ -1264,6 +1267,7 @@
 __ZN7WebCore9TimerBaseC2Ev
 __ZN7WebCore9TimerBaseD2Ev
 __ZN7WebCore9closeFileERi
+__ZN7WebCore9endOfLineERKNS_15VisiblePositionE
 __ZN7WebCore9endOfWordERKNS_15VisiblePositionENS_9EWordSideE
 __ZN7WebCore9fontCacheEv
 __ZN7WebCore9makeRangeERKNS_15VisiblePositionES2_
@@ -1449,6 +1453,7 @@
 __ZNK7WebCore15VisiblePosition14characterAfterEv
 __ZNK7WebCore15VisiblePosition14localCaretRectERPNS_12RenderObjectE
 __ZNK7WebCore15VisiblePosition19absoluteCaretBoundsEv
+__ZNK7WebCore15VisiblePosition45lineDirectionPointForBlockDirectionNavigationEv
 __ZNK7WebCore15VisiblePosition4nextENS_27EditingBoundaryCrossingRuleE
 __ZNK7WebCore15VisiblePosition8previousENS_27EditingBoundaryCrossingRuleE
 __ZNK7WebCore16EventListenerMap8containsERKN3WTF12AtomicStringE
@@ -1638,6 +1643,7 @@
 __ZNK7WebCore8Position24parentAnchoredEquivalentEv
 __ZNK7WebCore8Position25leadingWhitespacePositionENS_9EAffinityEb
 __ZNK7WebCore8Position26trailingWhitespacePositionENS_9EAffinityEb
+__ZNK7WebCore8Position28offsetForPositionAfterAnchorEv
 __ZNK7WebCore8Position8upstreamENS_27EditingBoundaryCrossingRuleE
 __ZNK7WebCore9DOMWindow27pendingUnloadEventListenersEv
 __ZNK7WebCore9FloatQuad11boundingBoxEv
@@ -2070,7 +2076,6 @@
 __ZN7WebCore11MemoryCache18pruneLiveResourcesEb
 __ZN7WebCore11MemoryCache20removeImageFromCacheERKNS_4KURLE
 __ZN7WebCore11isEndOfLineERKNS_15VisiblePositionE
-__ZN7WebCore11startOfLineERKNS_15VisiblePositionE
 __ZN7WebCore12EventHandler10mouseMovedEP8WebEvent
 __ZN7WebCore12EventHandler10wheelEventEP8WebEvent
 __ZN7WebCore12EventHandler15sendScrollEventEv
@@ -2119,7 +2124,6 @@
 __ZN7WebCore16VisibleSelection27selectionFromContentsOfNodeEPNS_4NodeE
 __ZN7WebCore16VisibleSelectionC1Ev
 __ZN7WebCore16jsStringWithCacheSlowCaseEPN3JSC9ExecStateERN3WTF7HashMapIPNS3_10StringImplENS0_4WeakINS0_8JSStringEEENS3_10StringHashENS3_10HashTraitsIS6_EENSB_IS9_EEEES6_
-__ZN7WebCore16nextLinePositionERKNS_15VisiblePositionEiNS_12EditableTypeE
 __ZN7WebCore16nextWordPositionERKNS_15VisiblePositionE
 __ZN7WebCore17CredentialStorage16clearCredentialsEv
 __ZN7WebCore17isStartOfDocumentERKNS_15VisiblePositionE
@@ -2134,7 +2138,6 @@
 __ZN7WebCore20lastOffsetForEditingEPKNS_4NodeE
 __ZN7WebCore20networkStateNotifierEv
 __ZN7WebCore20nextSentencePositionERKNS_15VisiblePositionE
-__ZN7WebCore20previousLinePositionERKNS_15VisiblePositionEiNS_12EditableTypeE
 __ZN7WebCore20previousWordPositionERKNS_15VisiblePositionE
 __ZN7WebCore21MemoryPressureHandler19clearMemoryPressureEv
 __ZN7WebCore21MemoryPressureHandler25hasReceivedMemoryPressureEv
@@ -2214,7 +2217,6 @@
 __ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLERKNS3_6VectorIS4_Lm0ENS3_15CrashOnOverflowEEESE_NS_25UserContentInjectedFramesENS_14UserStyleLevelENS_22UserStyleInjectionTimeE
 __ZN7WebCore9TileCache14drainLayerPoolEv
 __ZN7WebCore9TileCache20setLayerPoolCapacityEj
-__ZN7WebCore9endOfLineERKNS_15VisiblePositionE
 __ZNK7WebCore10FloatPointcv7CGPointEv
 __ZNK7WebCore14FrameSelection17wordOffsetInRangeEPKNS_5RangeE
 __ZNK7WebCore14FrameSelection20selectionAtWordStartEv
@@ -2228,7 +2230,6 @@
 __ZNK7WebCore14FrameSelection35characterInRelationToCaretSelectionEi
 __ZNK7WebCore14FrameSelection36elementRangeContainingCaretSelectionEv
 __ZNK7WebCore14SecurityOrigin8toStringEv
-__ZNK7WebCore15VisiblePosition45lineDirectionPointForBlockDirectionNavigationEv
 __ZNK7WebCore15VisiblePosition4leftEb
 __ZNK7WebCore15VisiblePosition5rightEb
 __ZNK7WebCore17RenderTextControl22textFormControlElementEv
@@ -2256,7 +2257,6 @@
 __ZNK7WebCore6Editor6clientEv
 __ZNK7WebCore7IntSizecv6CGSizeEv
 __ZNK7WebCore8Document31isTelephoneNumberParsingEnabledEv
-__ZNK7WebCore8Position28offsetForPositionAfterAnchorEv
 __ZNK7WebCore9FloatRectcv6CGRectEv
 __ZNK7WebCore9FloatSizecv6CGSizeEv
 _webThreadShouldYield

Modified: trunk/Source/WebKit2/ChangeLog (150652 => 150653)


--- trunk/Source/WebKit2/ChangeLog	2013-05-24 19:07:02 UTC (rev 150652)
+++ trunk/Source/WebKit2/ChangeLog	2013-05-24 19:41:37 UTC (rev 150653)
@@ -1,3 +1,18 @@
+2013-05-24  Thomas Deniau  <[email protected]>
+
+        Add more lines to the context during Dictionary lookups
+        https://bugs.webkit.org/show_bug.cgi?id=115256
+
+        Reviewed by Ryosuke Niwa.
+
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performDictionaryLookupAtLocation):
+        Instead of using the current paragraph as the context (which stops at
+        line breaks), get a few lines before and after the point, so that the
+        context contains at least four lines in each direction.
+        This way the Dictionary will be able to look up things that extend past
+        the current line.
+
 2013-05-24  Anders Carlsson  <[email protected]>
 
         Intermittent crash when typing in Address Bar

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (150652 => 150653)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2013-05-24 19:07:02 UTC (rev 150652)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2013-05-24 19:41:37 UTC (rev 150653)
@@ -507,13 +507,28 @@
 
     NSDictionary *options = nil;
 
-    // As context, we are going to use the surrounding paragraph of text.
-    VisiblePosition paragraphStart = startOfParagraph(position);
-    VisiblePosition paragraphEnd = endOfParagraph(position);
+    // As context, we are going to use four lines of text before and after the point. (Dictionary can sometimes look up things that are four lines long)
+    const int numberOfLinesOfContext = 4;
+    VisiblePosition contextStart = position;
+    VisiblePosition contextEnd = position;
+    for (int i = 0; i < numberOfLinesOfContext; i++) {
+        VisiblePosition n = previousLinePosition(contextStart, contextStart.lineDirectionPointForBlockDirectionNavigation());
+        if (n.isNull() || n == contextStart)
+            break;
+        contextStart = n;
+    }
+    for (int i = 0; i < numberOfLinesOfContext; i++) {
+        VisiblePosition n = nextLinePosition(contextEnd, contextEnd.lineDirectionPointForBlockDirectionNavigation());
+        if (n.isNull() || n == contextEnd)
+            break;
+        contextEnd = n;
+    }
+    contextStart = startOfLine(contextStart);
+    contextEnd = endOfLine(contextEnd);
+    
+    NSRange rangeToPass = NSMakeRange(TextIterator::rangeLength(makeRange(contextStart, position).get()), 0);
 
-    NSRange rangeToPass = NSMakeRange(TextIterator::rangeLength(makeRange(paragraphStart, position).get()), 0);
-
-    RefPtr<Range> fullCharacterRange = makeRange(paragraphStart, paragraphEnd);
+    RefPtr<Range> fullCharacterRange = makeRange(contextStart, contextEnd);
     String fullPlainTextString = plainText(fullCharacterRange.get());
 
     NSRange extractedRange = WKExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, &options);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to