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 HitTestLocation_h
     23 #define HitTestLocation_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/graphics/RoundedRect.h"
     29 #include "core/platform/text/TextDirection.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 Image;
     41 class KURL;
     42 class Node;
     43 class RenderRegion;
     44 class Scrollbar;
     45 
     46 class HitTestLocation {
     47 public:
     48 
     49     HitTestLocation();
     50     HitTestLocation(const LayoutPoint&);
     51     HitTestLocation(const FloatPoint&);
     52     HitTestLocation(const FloatPoint&, const FloatQuad&);
     53     // Pass non-zero padding values to perform a rect-based hit test.
     54     HitTestLocation(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
     55     // Make a copy the HitTestLocation in a new region by applying given offset to internal point and area.
     56     HitTestLocation(const HitTestLocation&, const LayoutSize& offset, RenderRegion* = 0);
     57     HitTestLocation(const HitTestLocation&);
     58     ~HitTestLocation();
     59     HitTestLocation& operator=(const HitTestLocation&);
     60 
     61     const LayoutPoint& point() const { return m_point; }
     62     IntPoint roundedPoint() const { return roundedIntPoint(m_point); }
     63 
     64     RenderRegion* region() const { return m_region; }
     65 
     66     // Rect-based hit test related methods.
     67     bool isRectBasedTest() const { return m_isRectBased; }
     68     bool isRectilinear() const { return m_isRectilinear; }
     69     IntRect boundingBox() const { return m_boundingBox; }
     70 
     71     static IntRect rectForPoint(const LayoutPoint&, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
     72     int topPadding() const { return roundedPoint().y() - m_boundingBox.y(); }
     73     int rightPadding() const { return m_boundingBox.maxX() - roundedPoint().x() - 1; }
     74     int bottomPadding() const { return m_boundingBox.maxY() - roundedPoint().y() - 1; }
     75     int leftPadding() const { return roundedPoint().x() - m_boundingBox.x(); }
     76 
     77     bool intersects(const LayoutRect&) const;
     78     bool intersects(const FloatRect&) const;
     79     bool intersects(const RoundedRect&) const;
     80 
     81     const FloatPoint& transformedPoint() const { return m_transformedPoint; }
     82     const FloatQuad& transformedRect() const { return m_transformedRect; }
     83 
     84 private:
     85     template<typename RectType>
     86     bool intersectsRect(const RectType&) const;
     87     void move(const LayoutSize& offset);
     88 
     89     // This is cached forms of the more accurate point and area below.
     90     LayoutPoint m_point;
     91     IntRect m_boundingBox;
     92 
     93     FloatPoint m_transformedPoint;
     94     FloatQuad m_transformedRect;
     95 
     96     RenderRegion* m_region; // The region we're inside.
     97 
     98     bool m_isRectBased;
     99     bool m_isRectilinear;
    100 };
    101 
    102 } // namespace WebCore
    103 
    104 #endif // HitTestLocation_h
    105