Changeset 117091 in webkit


Ignore:
Timestamp:
May 15, 2012 10:41:34 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Factor HitTestPoint out of HitTestResult.
https://bugs.webkit.org/show_bug.cgi?id=85965

Patch by Allan Sandfeld Jensen <allan.jensen@nokia.com> on 2012-05-15
Reviewed by Simon Fraser.

In preparation for handling transformations on area-based hit-testing,
we need to factor test-point and test-area out of HitTestResult so that
it can be transformed independently.

To maintain the current API as closely as possible HitTestResult now
inherit from HitTestPoint, representing the original untransformed
hitTestPoint.

No change in functionality. No new tests.

  • rendering/HitTestResult.cpp:

(WebCore::HitTestPoint::HitTestPoint):
(WebCore::HitTestPoint::~HitTestPoint):
(WebCore::HitTestPoint::operator=):
(WebCore::HitTestPoint::rectForPoint):
(WebCore::HitTestResult::HitTestResult):
(WebCore::HitTestResult::operator=):
(WebCore::HitTestResult::isSelected):
(WebCore::HitTestResult::spellingToolTip):
(WebCore::HitTestResult::replacedString):

  • rendering/HitTestResult.h:

(HitTestPoint):
(WebCore::HitTestPoint::point):
(WebCore::HitTestPoint::roundedPoint):
(WebCore::HitTestPoint::setPoint):
(WebCore::HitTestPoint::isRectBasedTest):
(WebCore::HitTestPoint::topPadding):
(WebCore::HitTestPoint::rightPadding):
(WebCore::HitTestPoint::bottomPadding):
(WebCore::HitTestPoint::leftPadding):
(HitTestResult):
(WebCore::HitTestResult::hitTestPoint):
(WebCore::HitTestPoint::rectForPoint):

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::hitTestLayer):
(WebCore::RenderLayer::hitTestList):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117086 r117091  
     12012-05-15  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
     2
     3        Factor HitTestPoint out of HitTestResult.
     4        https://bugs.webkit.org/show_bug.cgi?id=85965
     5
     6        Reviewed by Simon Fraser.
     7
     8        In preparation for handling transformations on area-based hit-testing,
     9        we need to factor test-point and test-area out of HitTestResult so that
     10        it can be transformed independently.
     11
     12        To maintain the current API as closely as possible HitTestResult now
     13        inherit from HitTestPoint, representing the original untransformed
     14        hitTestPoint.
     15
     16        No change in functionality. No new tests.
     17
     18        * rendering/HitTestResult.cpp:
     19        (WebCore::HitTestPoint::HitTestPoint):
     20        (WebCore::HitTestPoint::~HitTestPoint):
     21        (WebCore::HitTestPoint::operator=):
     22        (WebCore::HitTestPoint::rectForPoint):
     23        (WebCore::HitTestResult::HitTestResult):
     24        (WebCore::HitTestResult::operator=):
     25        (WebCore::HitTestResult::isSelected):
     26        (WebCore::HitTestResult::spellingToolTip):
     27        (WebCore::HitTestResult::replacedString):
     28        * rendering/HitTestResult.h:
     29        (HitTestPoint):
     30        (WebCore::HitTestPoint::point):
     31        (WebCore::HitTestPoint::roundedPoint):
     32        (WebCore::HitTestPoint::setPoint):
     33        (WebCore::HitTestPoint::isRectBasedTest):
     34        (WebCore::HitTestPoint::topPadding):
     35        (WebCore::HitTestPoint::rightPadding):
     36        (WebCore::HitTestPoint::bottomPadding):
     37        (WebCore::HitTestPoint::leftPadding):
     38        (HitTestResult):
     39        (WebCore::HitTestResult::hitTestPoint):
     40        (WebCore::HitTestPoint::rectForPoint):
     41        * rendering/RenderLayer.cpp:
     42        (WebCore::RenderLayer::hitTestLayer):
     43        (WebCore::RenderLayer::hitTestList):
     44
    1452012-05-15  Rob Buis  <rbuis@rim.com>
    246
  • trunk/Source/WebCore/rendering/HitTestResult.cpp

    r114926 r117091  
    11/*
    22 * Copyright (C) 2006, 2008, 2011 Apple Inc. All rights reserved.
     3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    4849using namespace HTMLNames;
    4950
    50 HitTestResult::HitTestResult()
    51     : m_isOverWidget(false)
     51HitTestPoint::HitTestPoint()
     52    : m_topPadding(0)
     53    , m_rightPadding(0)
     54    , m_bottomPadding(0)
     55    , m_leftPadding(0)
    5256    , m_isRectBased(false)
     57{
     58}
     59
     60HitTestPoint::HitTestPoint(const LayoutPoint& point)
     61    : m_point(point)
    5362    , m_topPadding(0)
    5463    , m_rightPadding(0)
    5564    , m_bottomPadding(0)
    5665    , m_leftPadding(0)
    57     , m_shadowContentFilterPolicy(DoNotAllowShadowContent)
    58     , m_region(0)
    59 {
    60 }
    61 
    62 HitTestResult::HitTestResult(const LayoutPoint& point)
    63     : m_point(point)
    64     , m_isOverWidget(false)
    6566    , m_isRectBased(false)
    66     , m_topPadding(0)
    67     , m_rightPadding(0)
    68     , m_bottomPadding(0)
    69     , m_leftPadding(0)
    70     , m_shadowContentFilterPolicy(DoNotAllowShadowContent)
    71     , m_region(0)
    72 {
    73 }
    74 
    75 HitTestResult::HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, ShadowContentFilterPolicy allowShadowContent)
     67{
     68}
     69
     70HitTestPoint::HitTestPoint(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding)
    7671    : m_point(centerPoint)
    77     , m_isOverWidget(false)
    7872    , m_topPadding(topPadding)
    7973    , m_rightPadding(rightPadding)
    8074    , m_bottomPadding(bottomPadding)
    8175    , m_leftPadding(leftPadding)
     76{
     77    // If all padding values passed in are zero then it is not a rect based hit test.
     78    m_isRectBased = topPadding || rightPadding || bottomPadding || leftPadding;
     79}
     80
     81HitTestPoint::HitTestPoint(const HitTestPoint& other)
     82    : m_point(other.m_point)
     83    , m_topPadding(other.m_topPadding)
     84    , m_rightPadding(other.m_rightPadding)
     85    , m_bottomPadding(other.m_bottomPadding)
     86    , m_leftPadding(other.m_leftPadding)
     87    , m_isRectBased(other.m_isRectBased)
     88{
     89}
     90
     91HitTestPoint::~HitTestPoint()
     92{
     93}
     94
     95HitTestPoint& HitTestPoint::operator=(const HitTestPoint& other)
     96{
     97    m_point = other.m_point;
     98    m_topPadding = other.m_topPadding;
     99    m_rightPadding = other.m_rightPadding;
     100    m_bottomPadding = other.m_bottomPadding;
     101    m_leftPadding = other.m_leftPadding;
     102    m_isRectBased = other.m_isRectBased;
     103
     104    return *this;
     105}
     106
     107IntRect HitTestPoint::rectForPoint(const LayoutPoint& point, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding)
     108{
     109    IntPoint actualPoint(roundedIntPoint(point));
     110    actualPoint -= IntSize(leftPadding, topPadding);
     111
     112    IntSize actualPadding(leftPadding + rightPadding, topPadding + bottomPadding);
     113    // As IntRect is left inclusive and right exclusive (seeing IntRect::contains(x, y)), adding "1".
     114    // FIXME: Remove this once non-rect based hit-detection stops using IntRect:intersects.
     115    actualPadding += IntSize(1, 1);
     116
     117    return IntRect(actualPoint, actualPadding);
     118}
     119
     120HitTestResult::HitTestResult() : HitTestPoint()
     121    , m_isOverWidget(false)
     122    , m_shadowContentFilterPolicy(DoNotAllowShadowContent)
     123    , m_region(0)
     124{
     125}
     126
     127HitTestResult::HitTestResult(const LayoutPoint& point) : HitTestPoint(point)
     128    , m_isOverWidget(false)
     129    , m_shadowContentFilterPolicy(DoNotAllowShadowContent)
     130    , m_region(0)
     131{
     132}
     133
     134HitTestResult::HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, ShadowContentFilterPolicy allowShadowContent)
     135    : HitTestPoint(centerPoint, topPadding, rightPadding, bottomPadding, leftPadding)
     136    , m_isOverWidget(false)
    82137    , m_shadowContentFilterPolicy(allowShadowContent)
    83138    , m_region(0)
    84139{
    85     // If all padding values passed in are zero then it is not a rect based hit test.
    86     m_isRectBased = topPadding || rightPadding || bottomPadding || leftPadding;
    87 
    88     // Make sure all padding values are clamped to zero if it is not a rect hit test.
    89     if (!m_isRectBased)
    90         m_topPadding = m_rightPadding = m_bottomPadding = m_leftPadding = 0;
     140}
     141
     142HitTestResult::HitTestResult(const HitTestPoint& other, ShadowContentFilterPolicy allowShadowContent)
     143    : HitTestPoint(other)
     144    , m_isOverWidget(false)
     145    , m_shadowContentFilterPolicy(allowShadowContent)
     146    , m_region(0)
     147{
    91148}
    92149
    93150HitTestResult::HitTestResult(const HitTestResult& other)
    94     : m_innerNode(other.innerNode())
     151    : HitTestPoint(other)
     152    , m_innerNode(other.innerNode())
    95153    , m_innerNonSharedNode(other.innerNonSharedNode())
    96     , m_point(other.point())
    97154    , m_localPoint(other.localPoint())
    98155    , m_innerURLElement(other.URLElement())
     
    102159    , m_region(other.region())
    103160{
    104     // Only copy the padding and NodeSet in case of rect hit test.
    105     // Copying the later is rather expensive.
    106     if ((m_isRectBased = other.isRectBasedTest())) {
    107         m_topPadding = other.m_topPadding;
    108         m_rightPadding = other.m_rightPadding;
    109         m_bottomPadding = other.m_bottomPadding;
    110         m_leftPadding = other.m_leftPadding;
    111     } else
    112         m_topPadding = m_rightPadding = m_bottomPadding = m_leftPadding = 0;
    113 
     161    // Only copy the NodeSet in case of rect hit test.
    114162    m_rectBasedTestResult = adoptPtr(other.m_rectBasedTestResult ? new NodeSet(*other.m_rectBasedTestResult) : 0);
    115163}
     
    121169HitTestResult& HitTestResult::operator=(const HitTestResult& other)
    122170{
     171    HitTestPoint::operator=(other);
    123172    m_innerNode = other.innerNode();
    124173    m_innerNonSharedNode = other.innerNonSharedNode();
    125     m_point = other.point();
    126174    m_localPoint = other.localPoint();
    127175    m_innerURLElement = other.URLElement();
    128176    m_scrollbar = other.scrollbar();
    129177    m_isOverWidget = other.isOverWidget();
    130     // Only copy the padding and NodeSet in case of rect hit test.
    131     // Copying the later is rather expensive.
    132     if ((m_isRectBased = other.isRectBasedTest())) {
    133         m_topPadding = other.m_topPadding;
    134         m_rightPadding = other.m_rightPadding;
    135         m_bottomPadding = other.m_bottomPadding;
    136         m_leftPadding = other.m_leftPadding;
    137     } else
    138         m_topPadding = m_rightPadding = m_bottomPadding = m_leftPadding = 0;
    139 
     178
     179    // Only copy the NodeSet in case of rect hit test.
    140180    m_rectBasedTestResult = adoptPtr(other.m_rectBasedTestResult ? new NodeSet(*other.m_rectBasedTestResult) : 0);
    141     m_shadowContentFilterPolicy = other.shadowContentFilterPolicy();
     181    m_shadowContentFilterPolicy  = other.shadowContentFilterPolicy();
    142182
    143183    m_region = other.m_region;
     
    199239        return false;
    200240
    201     return frame->selection()->contains(m_point);
     241    return frame->selection()->contains(point());
    202242}
    203243
     
    210250        return String();
    211251   
    212     DocumentMarker* marker = m_innerNonSharedNode->document()->markers()->markerContainingPoint(m_point, DocumentMarker::Grammar);
     252    DocumentMarker* marker = m_innerNonSharedNode->document()->markers()->markerContainingPoint(point(), DocumentMarker::Grammar);
    213253    if (!marker)
    214254        return String();
     
    226266        return String();
    227267   
    228     DocumentMarker* marker = m_innerNonSharedNode->document()->markers()->markerContainingPoint(m_point, DocumentMarker::Replacement);
     268    DocumentMarker* marker = m_innerNonSharedNode->document()->markers()->markerContainingPoint(point(), DocumentMarker::Replacement);
    229269    if (!marker)
    230270        return String();
     
    653693}
    654694
    655 IntRect HitTestResult::rectForPoint(const LayoutPoint& point, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding)
    656 {
    657     IntPoint actualPoint(roundedIntPoint(point));
    658     actualPoint -= IntSize(leftPadding, topPadding);
    659 
    660     IntSize actualPadding(leftPadding + rightPadding, topPadding + bottomPadding);
    661     // As IntRect is left inclusive and right exclusive (seeing IntRect::contains(x, y)), adding "1".
    662     actualPadding += IntSize(1, 1);
    663 
    664     return IntRect(actualPoint, actualPadding);
    665 }
    666 
    667695const HitTestResult::NodeSet& HitTestResult::rectBasedTestResult() const
    668696{
  • trunk/Source/WebCore/rendering/HitTestResult.h

    r114926 r117091  
    11/*
    22 * Copyright (C) 2006 Apple Computer, Inc.
     3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    2324
    2425#include "FloatRect.h"
     26#include "HitTestRequest.h"
    2527#include "LayoutTypes.h"
    2628#include "TextDirection.h"
     
    4547enum ShadowContentFilterPolicy { DoNotAllowShadowContent, AllowShadowContent };
    4648
    47 class HitTestResult {
     49class HitTestPoint {
     50public:
     51
     52    HitTestPoint();
     53    HitTestPoint(const LayoutPoint&);
     54    // Pass non-negative padding values to perform a rect-based hit test.
     55    HitTestPoint(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
     56    HitTestPoint(const HitTestPoint&);
     57    ~HitTestPoint();
     58    HitTestPoint& operator=(const HitTestPoint&);
     59
     60    LayoutPoint point() const { return m_point; }
     61    IntPoint roundedPoint() const { return roundedIntPoint(m_point); }
     62
     63    void setPoint(const LayoutPoint& p) { m_point = p; }
     64
     65    // Rect-based hit test related methods.
     66    bool isRectBasedTest() const { return m_isRectBased; }
     67    IntRect rectForPoint(const LayoutPoint&) const;
     68    static IntRect rectForPoint(const LayoutPoint&, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
     69    int topPadding() const { return m_topPadding; }
     70    int rightPadding() const { return m_rightPadding; }
     71    int bottomPadding() const { return m_bottomPadding; }
     72    int leftPadding() const { return m_leftPadding; }
     73
     74private:
     75    LayoutPoint m_point;
     76
     77    int m_topPadding;
     78    int m_rightPadding;
     79    int m_bottomPadding;
     80    int m_leftPadding;
     81    bool m_isRectBased;
     82};
     83
     84class HitTestResult : public HitTestPoint {
    4885public:
    4986    typedef ListHashSet<RefPtr<Node> > NodeSet;
     
    5390    // Pass non-negative padding values to perform a rect-based hit test.
    5491    HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, ShadowContentFilterPolicy);
     92    HitTestResult(const HitTestPoint&, ShadowContentFilterPolicy);
    5593    HitTestResult(const HitTestResult&);
    5694    ~HitTestResult();
     
    5997    Node* innerNode() const { return m_innerNode.get(); }
    6098    Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); }
    61     LayoutPoint point() const { return m_point; }
    62     IntPoint roundedPoint() const { return roundedIntPoint(m_point); }
    6399    LayoutPoint localPoint() const { return m_localPoint; }
    64100    Element* URLElement() const { return m_innerURLElement.get(); }
     
    71107    void setToNonShadowAncestor();
    72108
     109    const HitTestPoint& hitTestPoint() const { return *this; }
    73110    ShadowContentFilterPolicy shadowContentFilterPolicy() const { return m_shadowContentFilterPolicy; }
    74111
    75112    void setInnerNode(Node*);
    76113    void setInnerNonSharedNode(Node*);
    77     void setPoint(const LayoutPoint& p) { m_point = p; }
    78114    void setLocalPoint(const LayoutPoint& p) { m_localPoint = p; }
    79115    void setURLElement(Element*);
     
    111147    void toggleMediaMuteState() const;
    112148
    113     // Rect-based hit test related methods.
    114     bool isRectBasedTest() const { return m_isRectBased; }
    115     IntRect rectForPoint(const LayoutPoint&) const;
    116     static IntRect rectForPoint(const LayoutPoint&, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
    117     int topPadding() const { return m_topPadding; }
    118     int rightPadding() const { return m_rightPadding; }
    119     int bottomPadding() const { return m_bottomPadding; }
    120     int leftPadding() const { return m_leftPadding; }
    121 
    122149    // Returns true if it is rect-based hit test and needs to continue until the rect is fully
    123150    // enclosed by the boundaries of a node.
     
    140167    RefPtr<Node> m_innerNode;
    141168    RefPtr<Node> m_innerNonSharedNode;
    142     LayoutPoint m_point;
    143169    LayoutPoint m_localPoint; // A point in the local coordinate space of m_innerNonSharedNode's renderer. Allows us to efficiently
    144170                              // determine where inside the renderer we hit on subsequent operations.
     
    146172    RefPtr<Scrollbar> m_scrollbar;
    147173    bool m_isOverWidget; // Returns true if we are over a widget (and not in the border/padding area of a RenderWidget for example).
    148     bool m_isRectBased;
    149     int m_topPadding;
    150     int m_rightPadding;
    151     int m_bottomPadding;
    152     int m_leftPadding;
     174
    153175    ShadowContentFilterPolicy m_shadowContentFilterPolicy;
    154    
     176
    155177    RenderRegion* m_region; // The region we're inside.
    156178
     
    163185// width = leftPadding + rightPadding + 1
    164186// height = topPadding + bottomPadding + 1
    165 inline IntRect HitTestResult::rectForPoint(const LayoutPoint& point) const
     187inline IntRect HitTestPoint::rectForPoint(const LayoutPoint& point) const
    166188{
    167189    return rectForPoint(point, m_topPadding, m_rightPadding, m_bottomPadding, m_leftPadding);
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r117032 r117091  
    35743574    if (fgRect.intersects(hitTestArea) && isSelfPaintingLayer()) {
    35753575        // Hit test with a temporary HitTestResult, because we only want to commit to 'result' if we know we're frontmost.
    3576         HitTestResult tempResult(result.point(), result.topPadding(), result.rightPadding(), result.bottomPadding(), result.leftPadding(), result.shadowContentFilterPolicy());
     3576        HitTestResult tempResult(result.hitTestPoint(), result.shadowContentFilterPolicy());
    35773577        if (hitTestContents(request, tempResult, layerBounds, hitTestPoint, HitTestDescendants) &&
    35783578            isHitCandidate(this, false, zOffsetForContentsPtr, unflattenedTransformState.get())) {
     
    36033603
    36043604    if (bgRect.intersects(hitTestArea) && isSelfPaintingLayer()) {
    3605         HitTestResult tempResult(result.point(), result.topPadding(), result.rightPadding(), result.bottomPadding(), result.leftPadding(), result.shadowContentFilterPolicy());
     3605        HitTestResult tempResult(result.hitTestPoint(), result.shadowContentFilterPolicy());
    36063606        if (hitTestContents(request, tempResult, layerBounds, hitTestPoint, HitTestSelf) &&
    36073607            isHitCandidate(this, false, zOffsetForContentsPtr, unflattenedTransformState.get())) {
     
    36593659        RenderLayer* childLayer = list->at(i);
    36603660        RenderLayer* hitLayer = 0;
    3661         HitTestResult tempResult(result.point(), result.topPadding(), result.rightPadding(), result.bottomPadding(), result.leftPadding(), result.shadowContentFilterPolicy());
     3661        HitTestResult tempResult(result.hitTestPoint(), result.shadowContentFilterPolicy());
    36623662        if (childLayer->isPaginated())
    36633663            hitLayer = hitTestPaginatedChildLayer(childLayer, rootLayer, request, tempResult, hitTestRect, hitTestPoint, transformState, zOffsetForDescendants);
Note: See TracChangeset for help on using the changeset viewer.