WebCore/rendering/HitTestResult.h
changeset 0 4f2f89ce4247
child 2 303757a437d3
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2006 Apple Computer, Inc.
       
     3  *
       
     4  * This library is free software; you can redistribute it and/or
       
     5  * modify it under the terms of the GNU Library General Public
       
     6  * License as published by the Free Software Foundation; either
       
     7  * version 2 of the License, or (at your option) any later version.
       
     8  *
       
     9  * This library is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    12  * Library General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU Library General Public License
       
    15  * along with this library; see the file COPYING.LIB.  If not, write to
       
    16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    17  * Boston, MA 02110-1301, USA.
       
    18  *
       
    19 */
       
    20 #ifndef HitTestResult_h
       
    21 #define HitTestResult_h
       
    22 
       
    23 #include "IntPoint.h"
       
    24 #include "IntRect.h"
       
    25 #include "IntSize.h"
       
    26 #include "TextDirection.h"
       
    27 #include <wtf/ListHashSet.h>
       
    28 #include <wtf/RefPtr.h>
       
    29 
       
    30 namespace WebCore {
       
    31 
       
    32 class Element;
       
    33 class Frame;
       
    34 class Image;
       
    35 class IntRect;
       
    36 class KURL;
       
    37 class Node;
       
    38 class Scrollbar;
       
    39 class String;
       
    40 
       
    41 class HitTestResult {
       
    42 public:
       
    43     HitTestResult(const IntPoint&);
       
    44     // Pass a non-negative IntSize value as padding to perform a rect-based hit test.
       
    45     HitTestResult(const IntPoint& centerPoint, const IntSize& padding);
       
    46     HitTestResult(const HitTestResult&);
       
    47     ~HitTestResult();
       
    48     HitTestResult& operator=(const HitTestResult&);
       
    49 
       
    50     Node* innerNode() const { return m_innerNode.get(); }
       
    51     Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); }
       
    52     IntPoint point() const { return m_point; }
       
    53     IntPoint localPoint() const { return m_localPoint; }
       
    54     Element* URLElement() const { return m_innerURLElement.get(); }
       
    55     Scrollbar* scrollbar() const { return m_scrollbar.get(); }
       
    56     bool isOverWidget() const { return m_isOverWidget; }
       
    57 
       
    58     void setToNonShadowAncestor();
       
    59 
       
    60     void setInnerNode(Node*);
       
    61     void setInnerNonSharedNode(Node*);
       
    62     void setPoint(const IntPoint& p) { m_point = p; }
       
    63     void setLocalPoint(const IntPoint& p) { m_localPoint = p; }
       
    64     void setURLElement(Element*);
       
    65     void setScrollbar(Scrollbar*);
       
    66     void setIsOverWidget(bool b) { m_isOverWidget = b; }
       
    67 
       
    68     Frame* targetFrame() const;
       
    69     bool isSelected() const;
       
    70     String spellingToolTip(TextDirection&) const;
       
    71     String replacedString() const;
       
    72     String title(TextDirection&) const;
       
    73     String altDisplayString() const;
       
    74     String titleDisplayString() const;
       
    75     Image* image() const;
       
    76     IntRect imageRect() const;
       
    77     KURL absoluteImageURL() const;
       
    78     KURL absoluteMediaURL() const;
       
    79     KURL absoluteLinkURL() const;
       
    80     String textContent() const;
       
    81     bool isLiveLink() const;
       
    82     bool isContentEditable() const;
       
    83 
       
    84     // Rect-based hit test related methods.
       
    85     bool isRectBasedTest() const { return m_isRectBased; }
       
    86     IntRect rectFromPoint(int x, int y) const;
       
    87     IntRect rectFromPoint(const IntPoint&) const;
       
    88     IntSize padding() const { return m_padding; }
       
    89     int paddingWidth() const { return m_padding.width() >= 0 ? m_padding.width() : 0; }
       
    90     int paddingHeight() const { return m_padding.height() >= 0 ? m_padding.height() : 0; }
       
    91     // Returns true if it is rect-based hit test and needs to continue until the rect is fully
       
    92     // enclosed by the boundaries of a node.
       
    93     bool addNodeToRectBasedTestResult(Node*, int x, int y, const IntRect& rect = IntRect());
       
    94     const ListHashSet<RefPtr<Node> >& rectBasedTestResult() const { return m_rectBasedTestResult; }
       
    95     void append(const HitTestResult&);
       
    96 
       
    97 private:
       
    98 
       
    99     RefPtr<Node> m_innerNode;
       
   100     RefPtr<Node> m_innerNonSharedNode;
       
   101     IntPoint m_point;
       
   102     IntPoint m_localPoint; // A point in the local coordinate space of m_innerNonSharedNode's renderer.  Allows us to efficiently
       
   103                            // determine where inside the renderer we hit on subsequent operations.
       
   104     RefPtr<Element> m_innerURLElement;
       
   105     RefPtr<Scrollbar> m_scrollbar;
       
   106     bool m_isOverWidget; // Returns true if we are over a widget (and not in the border/padding area of a RenderWidget for example).
       
   107     bool m_isRectBased;
       
   108     IntSize m_padding;
       
   109     ListHashSet<RefPtr<Node> > m_rectBasedTestResult;
       
   110 };
       
   111 
       
   112 inline IntRect HitTestResult::rectFromPoint(int x, int y) const
       
   113 {
       
   114     return rectFromPoint(IntPoint(x, y));
       
   115 }
       
   116 
       
   117 // Formula:
       
   118 // x = p.x() - padding.width()
       
   119 // y = p.y() - padding.height()
       
   120 // width = 2 * padding.width() + 1
       
   121 // height = 2 * m_padding.height() + 1
       
   122 inline IntRect HitTestResult::rectFromPoint(const IntPoint& point) const
       
   123 {
       
   124     IntPoint realPoint(point);
       
   125     IntSize realPadding(m_padding);
       
   126 
       
   127     // Real IntPoint for the rect.
       
   128     realPadding.clampNegativeToZero();
       
   129     realPoint -= realPadding;
       
   130 
       
   131     // Real IntSize for the rect.
       
   132     realPadding.scale(2);
       
   133     realPadding += IntSize(1, 1);
       
   134 
       
   135     return IntRect(realPoint, realPadding);
       
   136 }
       
   137 
       
   138 String displayString(const String&, const Node*);
       
   139 
       
   140 } // namespace WebCore
       
   141 
       
   142 #endif // HitTestResult_h