Title: [122225] trunk
Revision
122225
Author
[email protected]
Date
2012-07-10 09:01:26 -0700 (Tue, 10 Jul 2012)

Log Message

WebSurroundingText layout tests should use the same code path as the rest of the feature.
https://bugs.webkit.org/show_bug.cgi?id=90807

Reviewed by Adam Barth.

Source/WebKit/chromium:

Replace the offset-based initialize method used only by LayoutTestController
with a point-based version to follow the same code path.

* public/WebSurroundingText.h:
(WebKit):
(WebSurroundingText):
* src/WebSurroundingText.cpp:
(WebKit::WebSurroundingText::initialize):

Tools:

Make the textSurroundingNode method take a pair of point coordinates
instead of a node offset.

* DumpRenderTree/chromium/LayoutTestController.cpp:
(LayoutTestController::textSurroundingNode):
* DumpRenderTree/chromium/LayoutTestController.h:
(LayoutTestController):

LayoutTests:

Make the textSurroundingNode method take a pair of point coordinates
instead of a node offset.

* platform/chromium/editing/surrounding-text/surrounding-text-expected.txt:
* platform/chromium/editing/surrounding-text/surrounding-text.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (122224 => 122225)


--- trunk/LayoutTests/ChangeLog	2012-07-10 15:51:28 UTC (rev 122224)
+++ trunk/LayoutTests/ChangeLog	2012-07-10 16:01:26 UTC (rev 122225)
@@ -1,3 +1,16 @@
+2012-07-10  Leandro Gracia Gil  <[email protected]>
+
+        WebSurroundingText layout tests should use the same code path as the rest of the feature.
+        https://bugs.webkit.org/show_bug.cgi?id=90807
+
+        Reviewed by Adam Barth.
+
+        Make the textSurroundingNode method take a pair of point coordinates
+        instead of a node offset.
+
+        * platform/chromium/editing/surrounding-text/surrounding-text-expected.txt:
+        * platform/chromium/editing/surrounding-text/surrounding-text.html:
+
 2012-07-10  Kevin Ellis  <[email protected]>
 
         Input type=range issue with events not being raised when value set in js

Modified: trunk/LayoutTests/platform/chromium/editing/surrounding-text/surrounding-text-expected.txt (122224 => 122225)


--- trunk/LayoutTests/platform/chromium/editing/surrounding-text/surrounding-text-expected.txt	2012-07-10 15:51:28 UTC (rev 122224)
+++ trunk/LayoutTests/platform/chromium/editing/surrounding-text/surrounding-text-expected.txt	2012-07-10 16:01:26 UTC (rev 122225)
@@ -8,7 +8,6 @@
 PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 5, 0) is ""
 PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 5, 1) is "1"
 PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 6, 2) is "12"
-PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 100, 5) is ""
 PASS surroundingText('<select>.</select><div>57th Street and Lake Shore Drive</div> <span>Chicago</span> <span id="here">IL</span> <span>60637</span><select>.</select>', 0, 100) is "57th Street and Lake Shore Drive Chicago IL 60637"
 PASS surroundingText('<fieldset>.</fieldset>12345<button>abc</button><p>6789<br id="here"/>12345</p>6789<textarea>abc</textarea>0123<fieldset>.</fieldset>', 0, 100) is "6789 12345 6789"
 PASS surroundingText('<button>.</button><div id="here">This is <!-- comment --!>a test <' + 'script language="_javascript_"><' + '/script>example<button>.</button>', 0, 100) is "This is a test example"

Modified: trunk/LayoutTests/platform/chromium/editing/surrounding-text/surrounding-text.html (122224 => 122225)


--- trunk/LayoutTests/platform/chromium/editing/surrounding-text/surrounding-text.html	2012-07-10 15:51:28 UTC (rev 122224)
+++ trunk/LayoutTests/platform/chromium/editing/surrounding-text/surrounding-text.html	2012-07-10 16:01:26 UTC (rev 122225)
@@ -9,6 +9,22 @@
 <script>
 description('Test the extraction of the text surrounding an element.');
 
+function findOffsetCoordinates(node, offset) {
+    var nodeRange = document.createRange();
+    nodeRange.selectNode(node);
+
+    var offsetRange = document.createRange();
+    offsetRange.setStart(node, offset);
+    offsetRange.setEnd(node, offset + 1);
+
+    var nodeRect = nodeRange.getBoundingClientRect();
+    var offsetRect = offsetRange.getBoundingClientRect();
+    var x = (offsetRect.left + offsetRect.right) / 2 - nodeRect.left;
+    var y = (offsetRect.top + offsetRect.bottom) / 2 - nodeRect.top;
+
+    return { x: x, y: y };
+}
+
 function surroundingText(html, offset, maxLength) {
     document.getElementById('test').innerHTML = html;
 
@@ -20,7 +36,8 @@
     if (node == null)
         throw 'No node after "here" element';
 
-    var text = window.testRunner.textSurroundingNode(node, offset, maxLength);
+    var coords = findOffsetCoordinates(node, offset);
+    var text = window.testRunner.textSurroundingNode(node, coords.x, coords.y, maxLength);
     return text.replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, '');
 }
 
@@ -33,7 +50,6 @@
     shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 5, 0)', '');
     shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 5, 1)', '1');
     shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 6, 2)', '12');
-    shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 100, 5)', '');
     shouldBeEqualToString('surroundingText(\'<select>.</select><div>57th Street and Lake Shore Drive</div> <span>Chicago</span> <span id="here">IL</span> <span>60637</span><select>.</select>\', 0, 100)', '57th Street and Lake Shore Drive Chicago IL 60637');
     shouldBeEqualToString('surroundingText(\'<fieldset>.</fieldset>12345<button>abc</button><p>6789<br id="here"/>12345</p>6789<textarea>abc</textarea>0123<fieldset>.</fieldset>\', 0, 100)', '6789 12345 6789');
     shouldBeEqualToString('surroundingText(\'<button>.</button><div id="here">This is <!-- comment --!>a test <\' + \'script language="_javascript_"><\' + \'/script>example<button>.</button>\', 0, 100)', 'This is a test example');

Modified: trunk/Source/WebKit/chromium/ChangeLog (122224 => 122225)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-07-10 15:51:28 UTC (rev 122224)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-07-10 16:01:26 UTC (rev 122225)
@@ -1,3 +1,19 @@
+2012-07-10  Leandro Gracia Gil  <[email protected]>
+
+        WebSurroundingText layout tests should use the same code path as the rest of the feature.
+        https://bugs.webkit.org/show_bug.cgi?id=90807
+
+        Reviewed by Adam Barth.
+
+        Replace the offset-based initialize method used only by LayoutTestController
+        with a point-based version to follow the same code path.
+
+        * public/WebSurroundingText.h:
+        (WebKit):
+        (WebSurroundingText):
+        * src/WebSurroundingText.cpp:
+        (WebKit::WebSurroundingText::initialize):
+
 2012-07-10  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r122207.

Modified: trunk/Source/WebKit/chromium/public/WebSurroundingText.h (122224 => 122225)


--- trunk/Source/WebKit/chromium/public/WebSurroundingText.h	2012-07-10 15:51:28 UTC (rev 122224)
+++ trunk/Source/WebKit/chromium/public/WebSurroundingText.h	2012-07-10 16:01:26 UTC (rev 122225)
@@ -37,6 +37,8 @@
 namespace WebKit {
 
 class WebHitTestResult;
+class WebNode;
+class WebPoint;
 
 class WebSurroundingText {
 public:
@@ -50,9 +52,9 @@
     // The maximum length of the contents retrieved is defined by maxLength.
     WEBKIT_EXPORT void initialize(const WebHitTestResult&, size_t maxLength);
 
-    // Initializes the object go get the surrounding text centered in the selected offset of the given node.
+    // Initializes the object to get the surrounding text centered in the position relative to a provided node.
     // The maximum length of the contents retrieved is defined by maxLength.
-    WEBKIT_EXPORT void initialize(WebNode textNode, size_t offset, size_t maxLength);
+    WEBKIT_EXPORT void initialize(const WebNode&, const WebPoint&, size_t maxLength);
 
     // Surrounding text content retrieved.
     WEBKIT_EXPORT WebString textContent() const;

Modified: trunk/Source/WebKit/chromium/src/WebSurroundingText.cpp (122224 => 122225)


--- trunk/Source/WebKit/chromium/src/WebSurroundingText.cpp	2012-07-10 15:51:28 UTC (rev 122224)
+++ trunk/Source/WebKit/chromium/src/WebSurroundingText.cpp	2012-07-10 16:01:26 UTC (rev 122225)
@@ -40,22 +40,22 @@
 
 namespace WebKit {
 
-void WebSurroundingText::initialize(const WebHitTestResult& hitTestInfo, size_t maxLength)
+void WebSurroundingText::initialize(const WebHitTestResult& hitTestResult, size_t maxLength)
 {
-    Node* node = hitTestInfo.node().unwrap<Node>();
+    Node* node = hitTestResult.node().unwrap<Node>();
     if (!node || !node->renderer())
         return;
 
-    m_private.reset(new SurroundingText(VisiblePosition(node->renderer()->positionForPoint(static_cast<IntPoint>(hitTestInfo.localPoint()))), maxLength));
+    m_private.reset(new SurroundingText(VisiblePosition(node->renderer()->positionForPoint(static_cast<IntPoint>(hitTestResult.localPoint()))), maxLength));
 }
 
-void WebSurroundingText::initialize(WebNode textNode, size_t offset, size_t maxLength)
+void WebSurroundingText::initialize(const WebNode& webNode, const WebPoint& nodePoint, size_t maxLength)
 {
-    Node* node = textNode.unwrap<Node>();
-    if (!node || !node->isTextNode() || offset >= node->nodeValue().length())
+    const Node* node = webNode.constUnwrap<Node>();
+    if (!node || !node->renderer())
         return;
 
-    m_private.reset(new SurroundingText(VisiblePosition(Position(toText(node), offset).parentAnchoredEquivalent(), DOWNSTREAM), maxLength));
+    m_private.reset(new SurroundingText(node->renderer()->positionForPoint(static_cast<IntPoint>(nodePoint)), maxLength));
 }
 
 WebString WebSurroundingText::textContent() const

Modified: trunk/Tools/ChangeLog (122224 => 122225)


--- trunk/Tools/ChangeLog	2012-07-10 15:51:28 UTC (rev 122224)
+++ trunk/Tools/ChangeLog	2012-07-10 16:01:26 UTC (rev 122225)
@@ -1,3 +1,18 @@
+2012-07-10  Leandro Gracia Gil  <[email protected]>
+
+        WebSurroundingText layout tests should use the same code path as the rest of the feature.
+        https://bugs.webkit.org/show_bug.cgi?id=90807
+
+        Reviewed by Adam Barth.
+
+        Make the textSurroundingNode method take a pair of point coordinates
+        instead of a node offset.
+
+        * DumpRenderTree/chromium/LayoutTestController.cpp:
+        (LayoutTestController::textSurroundingNode):
+        * DumpRenderTree/chromium/LayoutTestController.h:
+        (LayoutTestController):
+
 2012-07-10  Csaba Osztrogonác  <[email protected]>
 
         [Qt] REGRESSION(r122175): It broke the Windows build

Modified: trunk/Tools/DumpRenderTree/chromium/LayoutTestController.cpp (122224 => 122225)


--- trunk/Tools/DumpRenderTree/chromium/LayoutTestController.cpp	2012-07-10 15:51:28 UTC (rev 122224)
+++ trunk/Tools/DumpRenderTree/chromium/LayoutTestController.cpp	2012-07-10 16:01:26 UTC (rev 122225)
@@ -2349,7 +2349,7 @@
 void LayoutTestController::textSurroundingNode(const CppArgumentList& arguments, CppVariant* result)
 {
     result->setNull();
-    if (arguments.size() < 3 || !arguments[0].isObject() || !arguments[1].isNumber() || !arguments[2].isNumber())
+    if (arguments.size() < 4 || !arguments[0].isObject() || !arguments[1].isNumber() || !arguments[2].isNumber() || !arguments[3].isNumber())
         return;
 
     WebNode node;
@@ -2359,14 +2359,13 @@
     if (node.isNull() || !node.isTextNode())
         return;
 
-    unsigned offset = arguments[1].toInt32();
-    if (offset >= node.nodeValue().length()) {
-        result->set(WebString().utf8());
-        return;
-    }
+    WebPoint point(arguments[1].toInt32(), arguments[2].toInt32());
+    unsigned maxLength = arguments[3].toInt32();
 
     WebSurroundingText surroundingText;
-    unsigned maxLength = arguments[2].toInt32();
-    surroundingText.initialize(node, offset, maxLength);
+    surroundingText.initialize(node, point, maxLength);
+    if (surroundingText.isNull())
+        return;
+
     result->set(surroundingText.textContent().utf8());
 }

Modified: trunk/Tools/DumpRenderTree/chromium/LayoutTestController.h (122224 => 122225)


--- trunk/Tools/DumpRenderTree/chromium/LayoutTestController.h	2012-07-10 15:51:28 UTC (rev 122224)
+++ trunk/Tools/DumpRenderTree/chromium/LayoutTestController.h	2012-07-10 16:01:26 UTC (rev 122225)
@@ -457,8 +457,9 @@
     void setBackingScaleFactor(const CppArgumentList&, CppVariant*);
 
     // Retrieves the text surrounding a position in a text node.
-    // Expects the first argument to be a text node, the second to be an offset
-    // in the node contents and the third the maximum text length to retrieve.
+    // Expects the first argument to be a text node, the second and third to be
+    // point coordinates relative to the node and the fourth the maximum text
+    // length to retrieve.
     void textSurroundingNode(const CppArgumentList&, CppVariant*);
 
 public:
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to