Changeset 173857 in webkit


Ignore:
Timestamp:
Sep 22, 2014 5:23:54 PM (10 years ago)
Author:
Simon Fraser
Message:

Move nodeFromPoint() back to Document where it belongs
https://bugs.webkit.org/show_bug.cgi?id=137012

Reviewed by Zalan Bujtas.
Source/WebCore:

nodeFromPoint() was moved into TreeScope for ShadowDOM work, but now we can move
it back to its logical place.

Make versions of elementFromPoint and caretRangeFromPoint that take LayoutPoints,
and change the current scale/offset code to be in layout units (which results
in a small behavior change).

elementFromPoint(int, int) and caretRangeFromPoint(int, int) are still required
for bindings code.

  • dom/Document.cpp:

(WebCore::Document::nodeFromPoint):
(WebCore::Document::elementFromPoint):
(WebCore::Document::caretRangeFromPoint):

  • dom/Document.h:

(WebCore::Document::elementFromPoint): Move logic from TreeScope::elementFromPoint()
here.

  • dom/TreeScope.cpp:

(WebCore::nodeFromPoint): Deleted.
(WebCore::TreeScope::elementFromPoint): Deleted.

  • dom/TreeScope.h:

LayoutTests:

All platforms use subpixel layout now, so remove the conditional behavior in this test.
Fix the test to account for scaling now being done in layout units.

  • fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport-expected.txt:
  • fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport.html:
  • platform/mac/fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport-expected.txt:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r173856 r173857  
     12014-09-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Move nodeFromPoint() back to Document where it belongs
     4        https://bugs.webkit.org/show_bug.cgi?id=137012
     5
     6        Reviewed by Zalan Bujtas.
     7       
     8        All platforms use subpixel layout now, so remove the conditional behavior in this test.
     9        Fix the test to account for scaling now being done in layout units.
     10
     11        * fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport-expected.txt:
     12        * fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport.html:
     13        * platform/mac/fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport-expected.txt:
     14
    1152014-09-22  Benjamin Poulain  <bpoulain@apple.com>
    216
  • trunk/LayoutTests/fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport-expected.txt

    r49990 r173857  
    2525PASS Range.startOffset check (got 1, expected 1)
    2626PASS Range.startContainer check (got [object Text], expected [object Text])
    27 PASS Range.startOffset check (got 13, expected 13)
     27PASS Range.startOffset check (got 6, expected 6)
    2828PASS Range.startContainer check (got [object Text], expected [object Text])
    2929PASS Range.startOffset check (got 4, expected 4)
    3030PASS Range.startContainer check (got [object Text], expected [object Text])
    31 PASS Range.startOffset check (got 16, expected 16)
     31PASS Range.startOffset check (got 10, expected 10)
    3232 
    3333PASS successfullyParsed is true
  • trunk/LayoutTests/fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport.html

    r155265 r173857  
    2727
    2828<script>
    29     var r = document.getElementById('subpixel-test').getBoundingClientRect();
    30     var hasSubpixelSupport = r.right - r.left == 4.5;
    31    
    3229    if (window.testRunner)
    3330        testRunner.dumpAsText();
    3431
    35     description('This checks for proper behavior of caretRangeFromPoint before and after scrolling.');       
     32    description('This checks for proper behavior of caretRangeFromPoint before and after scrolling.');
    3633
    3734    var elementTop = document.getElementById('test-top'),
     
    7269
    7370        if (zoomOrNot == "zoom") {
    74             test(hasSubpixelSupport ? 0 : 1, 0, 0);
    75             test(hasSubpixelSupport ? 12 : 13, 0, 25);
     71            test(0, 0, 0);
     72            test(6, 0, 25);
    7673            test(4, 50, 0);
    77             test(16, 50, 25);
     74            test(10, 50, 25);
    7875        } else {
    7976            test(0, 0, 0);
  • trunk/LayoutTests/platform/mac/fast/dom/Document/CaretRangeFromPoint/hittest-relative-to-viewport-expected.txt

    r161884 r173857  
    2525PASS Range.startOffset check (got 0, expected 0)
    2626PASS Range.startContainer check (got [object Text], expected [object Text])
    27 PASS Range.startOffset check (got 12, expected 12)
     27PASS Range.startOffset check (got 6, expected 6)
    2828PASS Range.startContainer check (got [object Text], expected [object Text])
    2929PASS Range.startOffset check (got 4, expected 4)
    3030PASS Range.startContainer check (got [object Text], expected [object Text])
    31 PASS Range.startOffset check (got 16, expected 16)
     31PASS Range.startOffset check (got 10, expected 10)
    3232 
    3333PASS successfullyParsed is true
  • trunk/Source/WebCore/ChangeLog

    r173853 r173857  
     12014-09-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Move nodeFromPoint() back to Document where it belongs
     4        https://bugs.webkit.org/show_bug.cgi?id=137012
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        nodeFromPoint() was moved into TreeScope for ShadowDOM work, but now we can move
     9        it back to its logical place.
     10       
     11        Make versions of elementFromPoint and caretRangeFromPoint that take LayoutPoints,
     12        and change the current scale/offset code to be in layout units (which results
     13        in a small behavior change).
     14       
     15        elementFromPoint(int, int) and caretRangeFromPoint(int, int) are still required
     16        for bindings code.
     17
     18        * dom/Document.cpp:
     19        (WebCore::Document::nodeFromPoint):
     20        (WebCore::Document::elementFromPoint):
     21        (WebCore::Document::caretRangeFromPoint):
     22        * dom/Document.h:
     23        (WebCore::Document::elementFromPoint): Move logic from TreeScope::elementFromPoint()
     24        here.
     25        * dom/TreeScope.cpp:
     26        (WebCore::nodeFromPoint): Deleted.
     27        (WebCore::TreeScope::elementFromPoint): Deleted.
     28        * dom/TreeScope.h:
     29
    1302014-09-22  Benjamin Poulain  <bpoulain@apple.com>
    231
  • trunk/Source/WebCore/dom/Document.cpp

    r173765 r173857  
    13781378}
    13791379
    1380 Element* Document::elementFromPoint(int x, int y) const
     1380Node* Document::nodeFromPoint(const LayoutPoint& clientPoint, LayoutPoint* localPoint)
     1381{
     1382    if (!frame() || !view())
     1383        return nullptr;
     1384   
     1385    Frame& frame = *this->frame();
     1386   
     1387    float scaleFactor = frame.pageZoomFactor() * frame.frameScaleFactor();
     1388
     1389    LayoutPoint contentsPoint = clientPoint;
     1390    contentsPoint.scale(scaleFactor, scaleFactor);
     1391    contentsPoint.moveBy(view()->contentsScrollPosition());
     1392
     1393    LayoutRect visibleRect;
     1394#if PLATFORM(IOS)
     1395    visibleRect = view()->unobscuredContentRect();
     1396#else
     1397    visibleRect = view()->visibleContentRect();
     1398#endif
     1399    if (!visibleRect.contains(contentsPoint))
     1400        return nullptr;
     1401
     1402    HitTestResult result(contentsPoint);
     1403    renderView()->hitTest(HitTestRequest(), result);
     1404
     1405    if (localPoint)
     1406        *localPoint = result.localPoint();
     1407
     1408    return result.innerNode();
     1409}
     1410
     1411Element* Document::elementFromPoint(const LayoutPoint& clientPoint)
    13811412{
    13821413    if (!hasLivingRenderTree())
    13831414        return nullptr;
    13841415
    1385     return TreeScope::elementFromPoint(x, y);
     1416    Node* node = nodeFromPoint(clientPoint);
     1417    while (node && !node->isElementNode())
     1418        node = node->parentNode();
     1419
     1420    if (node)
     1421        node = ancestorInThisScope(node);
     1422
     1423    return toElement(node);
    13861424}
    13871425
    13881426PassRefPtr<Range> Document::caretRangeFromPoint(int x, int y)
     1427{
     1428    return caretRangeFromPoint(LayoutPoint(x, y));
     1429}
     1430
     1431PassRefPtr<Range> Document::caretRangeFromPoint(const LayoutPoint& clientPoint)
    13891432{
    13901433    if (!hasLivingRenderTree())
    13911434        return nullptr;
     1435
    13921436    LayoutPoint localPoint;
    1393     Node* node = nodeFromPoint(this, x, y, &localPoint);
     1437    Node* node = nodeFromPoint(clientPoint, &localPoint);
    13941438    if (!node)
    13951439        return nullptr;
  • trunk/Source/WebCore/dom/Document.h

    r173765 r173857  
    444444    NamedFlowCollection& namedFlows();
    445445
    446     Element* elementFromPoint(int x, int y) const;
     446    Element* elementFromPoint(int x, int y) { return elementFromPoint(LayoutPoint(x, y)); }
     447    Element* elementFromPoint(const LayoutPoint& clientPoint);
     448
    447449    PassRefPtr<Range> caretRangeFromPoint(int x, int y);
     450    PassRefPtr<Range> caretRangeFromPoint(const LayoutPoint& clientPoint);
    448451
    449452    String readyState() const;
     
    13451348    PageVisibilityState pageVisibilityState() const;
    13461349
     1350    Node* nodeFromPoint(const LayoutPoint& clientPoint, LayoutPoint* localPoint = nullptr);
     1351
    13471352    PassRefPtr<HTMLCollection> ensureCachedCollection(CollectionType);
    13481353
  • trunk/Source/WebCore/dom/TreeScope.cpp

    r173766 r173857  
    3333#include "FocusController.h"
    3434#include "Frame.h"
    35 #include "FrameView.h"
    3635#include "HTMLAnchorElement.h"
    3736#include "HTMLFrameOwnerElement.h"
     
    4140#include "IdTargetObserverRegistry.h"
    4241#include "Page.h"
    43 #include "RenderView.h"
    4442#include "RuntimeEnabledFeatures.h"
    4543#include "ShadowRoot.h"
     
    215213    }
    216214    return m_imageMapsByName->getElementByMapName(*AtomicString(name).impl(), *this);
    217 }
    218 
    219 Node* nodeFromPoint(Document* document, int x, int y, LayoutPoint* localPoint)
    220 {
    221     Frame* frame = document->frame();
    222 
    223     if (!frame)
    224         return nullptr;
    225     FrameView* frameView = frame->view();
    226     if (!frameView)
    227         return nullptr;
    228 
    229     float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor();
    230 
    231     IntPoint scrollPosition = frameView->contentsScrollPosition();
    232     IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor  + scrollPosition.x(), y * scaleFactor + scrollPosition.y()));
    233 
    234     IntRect visibleRect;
    235 #if PLATFORM(IOS)
    236     visibleRect = frameView->unobscuredContentRect();
    237 #else
    238     visibleRect = frameView->visibleContentRect();
    239 #endif
    240     if (!visibleRect.contains(point))
    241         return nullptr;
    242 
    243     HitTestResult result(point);
    244     document->renderView()->hitTest(HitTestRequest(), result);
    245 
    246     if (localPoint)
    247         *localPoint = result.localPoint();
    248 
    249     return result.innerNode();
    250 }
    251 
    252 Element* TreeScope::elementFromPoint(int x, int y) const
    253 {
    254     Node* node = nodeFromPoint(&m_rootNode.document(), x, y);
    255     while (node && !node->isElementNode())
    256         node = node->parentNode();
    257     if (node)
    258         node = ancestorInThisScope(node);
    259     return toElement(node);
    260215}
    261216
  • trunk/Source/WebCore/dom/TreeScope.h

    r172849 r173857  
    7878    HTMLMapElement* getImageMap(const String& url) const;
    7979
    80     Element* elementFromPoint(int x, int y) const;
    81 
    8280    // For accessibility.
    8381    bool shouldCacheLabelsByForAttribute() const { return !!m_labelsByForAttribute; }
     
    149147}
    150148
    151 Node* nodeFromPoint(Document*, int x, int y, LayoutPoint* localPoint = 0);
    152149TreeScope* commonTreeScope(Node*, Node*);
    153150
  • trunk/Source/WebCore/page/FrameView.cpp

    r173785 r173857  
    31273127        frame().document()->enqueueOverflowEvent(overflowEvent.release());
    31283128    }
    3129    
    31303129}
    31313130
Note: See TracChangeset for help on using the changeset viewer.