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/rendering/HitTestLocation.h"
     26 #include "core/rendering/HitTestRequest.h"
     27 #include "platform/geometry/FloatQuad.h"
     28 #include "platform/geometry/FloatRect.h"
     29 #include "platform/geometry/LayoutRect.h"
     30 #include "platform/heap/Handle.h"
     31 #include "platform/text/TextDirection.h"
     32 #include "wtf/Forward.h"
     33 #include "wtf/ListHashSet.h"
     34 #include "wtf/OwnPtr.h"
     35 #include "wtf/RefPtr.h"
     36 
     37 namespace WebCore {
     38 
     39 class Element;
     40 class LocalFrame;
     41 class HTMLMediaElement;
     42 class Image;
     43 class KURL;
     44 class Node;
     45 class RenderObject;
     46 class Scrollbar;
     47 
     48 class HitTestResult {
     49 public:
     50     typedef WillBeHeapListHashSet<RefPtrWillBeMember<Node> > NodeSet;
     51 
     52     HitTestResult();
     53     HitTestResult(const LayoutPoint&);
     54     // Pass non-negative padding values to perform a rect-based hit test.
     55     HitTestResult(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
     56     HitTestResult(const HitTestLocation&);
     57     HitTestResult(const HitTestResult&);
     58     ~HitTestResult();
     59     HitTestResult& operator=(const HitTestResult&);
     60 
     61     Node* innerNode() const { return m_innerNode.get(); }
     62     Node* innerPossiblyPseudoNode() const { return m_innerPossiblyPseudoNode.get(); }
     63     Element* innerElement() const;
     64     Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); }
     65     Element* URLElement() const { return m_innerURLElement.get(); }
     66     Scrollbar* scrollbar() const { return m_scrollbar.get(); }
     67     bool isOverWidget() const { return m_isOverWidget; }
     68 
     69     // Forwarded from HitTestLocation
     70     bool isRectBasedTest() const { return m_hitTestLocation.isRectBasedTest(); }
     71 
     72     // The hit-tested point in the coordinates of the main frame.
     73     const LayoutPoint& pointInMainFrame() const { return m_hitTestLocation.point(); }
     74     IntPoint roundedPointInMainFrame() const { return roundedIntPoint(pointInMainFrame()); }
     75 
     76     // The hit-tested point in the coordinates of the innerNode frame, the frame containing innerNode.
     77     const LayoutPoint& pointInInnerNodeFrame() const { return m_pointInInnerNodeFrame; }
     78     IntPoint roundedPointInInnerNodeFrame() const { return roundedIntPoint(pointInInnerNodeFrame()); }
     79     LocalFrame* innerNodeFrame() const;
     80 
     81     // The hit-tested point in the coordinates of the inner node.
     82     const LayoutPoint& localPoint() const { return m_localPoint; }
     83     void setLocalPoint(const LayoutPoint& p) { m_localPoint = p; }
     84 
     85     RenderObject* renderer() const;
     86 
     87     void setToNodesInDocumentTreeScope();
     88     void setToShadowHostIfInUserAgentShadowRoot();
     89 
     90     const HitTestLocation& hitTestLocation() const { return m_hitTestLocation; }
     91 
     92     void setInnerNode(Node*);
     93     void setInnerNonSharedNode(Node*);
     94     void setURLElement(Element*);
     95     void setScrollbar(Scrollbar*);
     96     void setIsFirstLetter(bool b) { m_isFirstLetter = b; }
     97     void setIsOverWidget(bool b) { m_isOverWidget = b; }
     98 
     99     bool isSelected() const;
    100     String spellingToolTip(TextDirection&) const;
    101     String title(TextDirection&) const;
    102     const AtomicString& altDisplayString() const;
    103     Image* image() const;
    104     IntRect imageRect() const;
    105     KURL absoluteImageURL() const;
    106     // This variant of absoluteImageURL will also convert <canvas> elements
    107     // to huge image data URLs (very expensive).
    108     KURL absoluteImageURLIncludingCanvasDataURL() const;
    109     KURL absoluteMediaURL() const;
    110     KURL absoluteLinkURL() const;
    111     String textContent() const;
    112     bool isLiveLink() const;
    113     bool isMisspelled() const;
    114     bool isContentEditable() const;
    115 
    116     bool isOverLink() const;
    117     // Returns true if it is rect-based hit test and needs to continue until the rect is fully
    118     // enclosed by the boundaries of a node.
    119     bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const LayoutRect& = LayoutRect());
    120     bool addNodeToRectBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const FloatRect&);
    121     void append(const HitTestResult&);
    122 
    123     // If m_rectBasedTestResult is 0 then set it to a new NodeSet. Return *m_rectBasedTestResult. Lazy allocation makes
    124     // sense because the NodeSet is seldom necessary, and it's somewhat expensive to allocate and initialize. This method does
    125     // the same thing as mutableRectBasedTestResult(), but here the return value is const.
    126     const NodeSet& rectBasedTestResult() const;
    127 
    128     Node* targetNode() const;
    129 
    130 private:
    131     KURL absoluteImageURLInternal(bool allowCanvas) const;
    132     NodeSet& mutableRectBasedTestResult(); // See above.
    133     HTMLMediaElement* mediaElement() const;
    134 
    135     HitTestLocation m_hitTestLocation;
    136 
    137     RefPtrWillBePersistent<Node> m_innerNode;
    138     RefPtrWillBePersistent<Node> m_innerPossiblyPseudoNode;
    139     RefPtrWillBePersistent<Node> m_innerNonSharedNode;
    140     LayoutPoint m_pointInInnerNodeFrame; // The hit-tested point in innerNode frame coordinates.
    141     LayoutPoint m_localPoint; // A point in the local coordinate space of m_innerNonSharedNode's renderer. Allows us to efficiently
    142                               // determine where inside the renderer we hit on subsequent operations.
    143     RefPtrWillBePersistent<Element> m_innerURLElement;
    144     RefPtr<Scrollbar> m_scrollbar;
    145     bool m_isOverWidget; // Returns true if we are over a widget (and not in the border/padding area of a RenderWidget for example).
    146     bool m_isFirstLetter;
    147 
    148     mutable OwnPtrWillBePersistent<NodeSet> m_rectBasedTestResult;
    149 };
    150 
    151 } // namespace WebCore
    152 
    153 #endif // HitTestResult_h
    154