Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2006 Apple Computer, Inc.
      3  * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  *
     20 */
     21 
     22 #ifndef HitTestResult_h
     23 #define HitTestResult_h
     24 
     25 #include "core/platform/graphics/FloatQuad.h"
     26 #include "core/platform/graphics/FloatRect.h"
     27 #include "core/platform/graphics/LayoutRect.h"
     28 #include "core/platform/text/TextDirection.h"
     29 #include "core/rendering/HitTestLocation.h"
     30 #include "core/rendering/HitTestRequest.h"
     31 #include "wtf/Forward.h"
     32 #include "wtf/ListHashSet.h"
     33 #include "wtf/OwnPtr.h"
     34 #include "wtf/RefPtr.h"
     35 
     36 namespace WebCore {
     37 
     38 class Element;
     39 class Frame;
     40 class HTMLMediaElement;
     41 class Image;
     42 class KURL;
     43 class Node;
     44 class RenderRegion;
     45 class Scrollbar;
     46 
     47 class HitTestResult {
     48 public:
     49     typedef ListHashSet<RefPtr<Node> > NodeSet;
     50 
     51     HitTestResult();
     52     HitTestResult(const LayoutPoint&);
     53     // Pass non-negative padding values to perform a rect-based hit test.
     54     HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
     55     HitTestResult(const HitTestLocation&);
     56     HitTestResult(const HitTestResult&);
     57     ~HitTestResult();
     58     HitTestResult& operator=(const HitTestResult&);
     59 
     60     Node* innerNode() const { return m_innerNode.get(); }
     61     Element* innerElement() const;
     62     Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); }
     63     Element* URLElement() const { return m_innerURLElement.get(); }
     64     Scrollbar* scrollbar() const { return m_scrollbar.get(); }
     65     bool isOverWidget() const { return m_isOverWidget; }
     66 
     67     // Forwarded from HitTestLocation
     68     bool isRectBasedTest() const { return m_hitTestLocation.isRectBasedTest(); }
     69 
     70     // The hit-tested point in the coordinates of the main frame.
     71     const LayoutPoint& pointInMainFrame() const { return m_hitTestLocation.point(); }
     72     IntPoint roundedPointInMainFrame() const { return roundedIntPoint(pointInMainFrame()); }
     73 
     74     // The hit-tested point in the coordinates of the innerNode frame, the frame containing innerNode.
     75     const LayoutPoint& pointInInnerNodeFrame() const { return m_pointInInnerNodeFrame; }
     76     IntPoint roundedPointInInnerNodeFrame() const { return roundedIntPoint(pointInInnerNodeFrame()); }
     77     Frame* innerNodeFrame() const;
     78 
     79     // The hit-tested point in the coordinates of the inner node.
     80     const LayoutPoint& localPoint() const { return m_localPoint; }
     81     void setLocalPoint(const LayoutPoint& p) { m_localPoint = p; }
     82 
     83     void setToNodesInDocumentTreeScope();
     84     void setToShadowHostIfInUserAgentShadowRoot();
     85 
     86     const HitTestLocation& hitTestLocation() const { return m_hitTestLocation; }
     87 
     88     void setInnerNode(Node*);
     89     void setInnerNonSharedNode(Node*);
     90     void setURLElement(Element*);
     91     void setScrollbar(Scrollbar*);
     92     void setIsOverWidget(bool b) { m_isOverWidget = b; }
     93 
     94     Frame* targetFrame() const;
     95     bool isSelected() const;
     96     String spellingToolTip(TextDirection&) const;
     97     String title(TextDirection&) const;
     98     String altDisplayString() const;
     99     String titleDisplayString() const;
    100     Image* image() const;
    101     IntRect imageRect() const;
    102     KURL absoluteImageURL() const;
    103     KURL absoluteMediaURL() const;
    104     KURL absoluteLinkURL() const;
    105     String textContent() const;
    106     bool isLiveLink() const;
    107     bool isMisspelled() const;
    108     bool isContentEditable() const;
    109 
    110     // Returns true if it is rect-based hit test and needs to continue until the rect is fully
    111     // enclosed by the boundaries of a node.
    112     bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const LayoutRect& = LayoutRect());
    113     bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const FloatRect&);
    114     void append(const HitTestResult&);
    115 
    116     // If m_rectBasedTestResult is 0 then set it to a new NodeSet. Return *m_rectBasedTestResult. Lazy allocation makes
    117     // sense because the NodeSet is seldom necessary, and it's somewhat expensive to allocate and initialize. This method does
    118     // the same thing as mutableRectBasedTestResult(), but here the return value is const.
    119     const NodeSet& rectBasedTestResult() const;
    120 
    121     Node* targetNode() const;
    122 
    123 private:
    124     NodeSet& mutableRectBasedTestResult(); // See above.
    125     HTMLMediaElement* mediaElement() const;
    126 
    127     HitTestLocation m_hitTestLocation;
    128 
    129     RefPtr<Node> m_innerNode;
    130     RefPtr<Node> m_innerNonSharedNode;
    131     LayoutPoint m_pointInInnerNodeFrame; // The hit-tested point in innerNode frame coordinates.
    132     LayoutPoint m_localPoint; // A point in the local coordinate space of m_innerNonSharedNode's renderer. Allows us to efficiently
    133                               // determine where inside the renderer we hit on subsequent operations.
    134     RefPtr<Element> m_innerURLElement;
    135     RefPtr<Scrollbar> m_scrollbar;
    136     bool m_isOverWidget; // Returns true if we are over a widget (and not in the border/padding area of a RenderWidget for example).
    137 
    138     mutable OwnPtr<NodeSet> m_rectBasedTestResult;
    139 };
    140 
    141 String displayString(const String&, const Node*);
    142 
    143 } // namespace WebCore
    144 
    145 #endif // HitTestResult_h
    146