Changeset 122225 in webkit


Ignore:
Timestamp:
Jul 10, 2012 9:01:26 AM (12 years ago)
Author:
leandrogracia@chromium.org
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:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r122224 r122225  
     12012-07-10  Leandro Gracia Gil  <leandrogracia@chromium.org>
     2
     3        WebSurroundingText layout tests should use the same code path as the rest of the feature.
     4        https://bugs.webkit.org/show_bug.cgi?id=90807
     5
     6        Reviewed by Adam Barth.
     7
     8        Make the textSurroundingNode method take a pair of point coordinates
     9        instead of a node offset.
     10
     11        * platform/chromium/editing/surrounding-text/surrounding-text-expected.txt:
     12        * platform/chromium/editing/surrounding-text/surrounding-text.html:
     13
    1142012-07-10  Kevin Ellis  <kevers@chromium.org>
    215
  • trunk/LayoutTests/platform/chromium/editing/surrounding-text/surrounding-text-expected.txt

    r122139 r122225  
    99PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 5, 1) is "1"
    1010PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 6, 2) is "12"
    11 PASS surroundingText('<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>', 100, 5) is ""
    1211PASS 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"
    1312PASS 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"
  • trunk/LayoutTests/platform/chromium/editing/surrounding-text/surrounding-text.html

    r122139 r122225  
    99<script>
    1010description('Test the extraction of the text surrounding an element.');
     11
     12function findOffsetCoordinates(node, offset) {
     13    var nodeRange = document.createRange();
     14    nodeRange.selectNode(node);
     15
     16    var offsetRange = document.createRange();
     17    offsetRange.setStart(node, offset);
     18    offsetRange.setEnd(node, offset + 1);
     19
     20    var nodeRect = nodeRange.getBoundingClientRect();
     21    var offsetRect = offsetRange.getBoundingClientRect();
     22    var x = (offsetRect.left + offsetRect.right) / 2 - nodeRect.left;
     23    var y = (offsetRect.top + offsetRect.bottom) / 2 - nodeRect.top;
     24
     25    return { x: x, y: y };
     26}
    1127
    1228function surroundingText(html, offset, maxLength) {
     
    2137        throw 'No node after "here" element';
    2238
    23     var text = window.testRunner.textSurroundingNode(node, offset, maxLength);
     39    var coords = findOffsetCoordinates(node, offset);
     40    var text = window.testRunner.textSurroundingNode(node, coords.x, coords.y, maxLength);
    2441    return text.replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, '');
    2542}
     
    3451    shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 5, 1)', '1');
    3552    shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 6, 2)', '12');
    36     shouldBeEqualToString('surroundingText(\'<button>.</button>12345<p id="here">6789 12345</p>6789<button>.</button>\', 100, 5)', '');
    3753    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');
    3854    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');
  • trunk/Source/WebKit/chromium/ChangeLog

    r122220 r122225  
     12012-07-10  Leandro Gracia Gil  <leandrogracia@chromium.org>
     2
     3        WebSurroundingText layout tests should use the same code path as the rest of the feature.
     4        https://bugs.webkit.org/show_bug.cgi?id=90807
     5
     6        Reviewed by Adam Barth.
     7
     8        Replace the offset-based initialize method used only by LayoutTestController
     9        with a point-based version to follow the same code path.
     10
     11        * public/WebSurroundingText.h:
     12        (WebKit):
     13        (WebSurroundingText):
     14        * src/WebSurroundingText.cpp:
     15        (WebKit::WebSurroundingText::initialize):
     16
    1172012-07-10  Sheriff Bot  <webkit.review.bot@gmail.com>
    218
  • trunk/Source/WebKit/chromium/public/WebSurroundingText.h

    r115472 r122225  
    3838
    3939class WebHitTestResult;
     40class WebNode;
     41class WebPoint;
    4042
    4143class WebSurroundingText {
     
    5153    WEBKIT_EXPORT void initialize(const WebHitTestResult&, size_t maxLength);
    5254
    53     // Initializes the object go get the surrounding text centered in the selected offset of the given node.
     55    // Initializes the object to get the surrounding text centered in the position relative to a provided node.
    5456    // The maximum length of the contents retrieved is defined by maxLength.
    55     WEBKIT_EXPORT void initialize(WebNode textNode, size_t offset, size_t maxLength);
     57    WEBKIT_EXPORT void initialize(const WebNode&, const WebPoint&, size_t maxLength);
    5658
    5759    // Surrounding text content retrieved.
  • trunk/Source/WebKit/chromium/src/WebSurroundingText.cpp

    r122139 r122225  
    4141namespace WebKit {
    4242
    43 void WebSurroundingText::initialize(const WebHitTestResult& hitTestInfo, size_t maxLength)
     43void WebSurroundingText::initialize(const WebHitTestResult& hitTestResult, size_t maxLength)
    4444{
    45     Node* node = hitTestInfo.node().unwrap<Node>();
     45    Node* node = hitTestResult.node().unwrap<Node>();
    4646    if (!node || !node->renderer())
    4747        return;
    4848
    49     m_private.reset(new SurroundingText(VisiblePosition(node->renderer()->positionForPoint(static_cast<IntPoint>(hitTestInfo.localPoint()))), maxLength));
     49    m_private.reset(new SurroundingText(VisiblePosition(node->renderer()->positionForPoint(static_cast<IntPoint>(hitTestResult.localPoint()))), maxLength));
    5050}
    5151
    52 void WebSurroundingText::initialize(WebNode textNode, size_t offset, size_t maxLength)
     52void WebSurroundingText::initialize(const WebNode& webNode, const WebPoint& nodePoint, size_t maxLength)
    5353{
    54     Node* node = textNode.unwrap<Node>();
    55     if (!node || !node->isTextNode() || offset >= node->nodeValue().length())
     54    const Node* node = webNode.constUnwrap<Node>();
     55    if (!node || !node->renderer())
    5656        return;
    5757
    58     m_private.reset(new SurroundingText(VisiblePosition(Position(toText(node), offset).parentAnchoredEquivalent(), DOWNSTREAM), maxLength));
     58    m_private.reset(new SurroundingText(node->renderer()->positionForPoint(static_cast<IntPoint>(nodePoint)), maxLength));
    5959}
    6060
  • trunk/Tools/ChangeLog

    r122219 r122225  
     12012-07-10  Leandro Gracia Gil  <leandrogracia@chromium.org>
     2
     3        WebSurroundingText layout tests should use the same code path as the rest of the feature.
     4        https://bugs.webkit.org/show_bug.cgi?id=90807
     5
     6        Reviewed by Adam Barth.
     7
     8        Make the textSurroundingNode method take a pair of point coordinates
     9        instead of a node offset.
     10
     11        * DumpRenderTree/chromium/LayoutTestController.cpp:
     12        (LayoutTestController::textSurroundingNode):
     13        * DumpRenderTree/chromium/LayoutTestController.h:
     14        (LayoutTestController):
     15
    1162012-07-10  Csaba Osztrogonác  <ossy@webkit.org>
    217
  • trunk/Tools/DumpRenderTree/chromium/LayoutTestController.cpp

    r122077 r122225  
    23502350{
    23512351    result->setNull();
    2352     if (arguments.size() < 3 || !arguments[0].isObject() || !arguments[1].isNumber() || !arguments[2].isNumber())
     2352    if (arguments.size() < 4 || !arguments[0].isObject() || !arguments[1].isNumber() || !arguments[2].isNumber() || !arguments[3].isNumber())
    23532353        return;
    23542354
     
    23602360        return;
    23612361
    2362     unsigned offset = arguments[1].toInt32();
    2363     if (offset >= node.nodeValue().length()) {
    2364         result->set(WebString().utf8());
    2365         return;
    2366     }
     2362    WebPoint point(arguments[1].toInt32(), arguments[2].toInt32());
     2363    unsigned maxLength = arguments[3].toInt32();
    23672364
    23682365    WebSurroundingText surroundingText;
    2369     unsigned maxLength = arguments[2].toInt32();
    2370     surroundingText.initialize(node, offset, maxLength);
     2366    surroundingText.initialize(node, point, maxLength);
     2367    if (surroundingText.isNull())
     2368        return;
     2369
    23712370    result->set(surroundingText.textContent().utf8());
    23722371}
  • trunk/Tools/DumpRenderTree/chromium/LayoutTestController.h

    r122077 r122225  
    458458
    459459    // Retrieves the text surrounding a position in a text node.
    460     // Expects the first argument to be a text node, the second to be an offset
    461     // in the node contents and the third the maximum text length to retrieve.
     460    // Expects the first argument to be a text node, the second and third to be
     461    // point coordinates relative to the node and the fourth the maximum text
     462    // length to retrieve.
    462463    void textSurroundingNode(const CppArgumentList&, CppVariant*);
    463464
Note: See TracChangeset for help on using the changeset viewer.