| 1 | /* |
| 2 | * Copyright (C) 2006 Apple 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 | #pragma once |
| 23 | |
| 24 | #include "FloatQuad.h" |
| 25 | #include "FloatRect.h" |
| 26 | #include "LayoutRect.h" |
| 27 | #include "RoundedRect.h" |
| 28 | #include <wtf/Forward.h> |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | class HitTestLocation { |
| 33 | public: |
| 34 | WEBCORE_EXPORT HitTestLocation(); |
| 35 | HitTestLocation(const LayoutPoint&); |
| 36 | WEBCORE_EXPORT HitTestLocation(const FloatPoint&); |
| 37 | HitTestLocation(const FloatPoint&, const FloatQuad&); |
| 38 | // Pass non-zero padding values to perform a rect-based hit test. |
| 39 | HitTestLocation(const LayoutPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding); |
| 40 | // Make a copy the HitTestLocation in a new region by applying given offset to internal point and area. |
| 41 | HitTestLocation(const HitTestLocation&, const LayoutSize& offset); |
| 42 | WEBCORE_EXPORT HitTestLocation(const HitTestLocation&); |
| 43 | WEBCORE_EXPORT ~HitTestLocation(); |
| 44 | HitTestLocation& operator=(const HitTestLocation&); |
| 45 | |
| 46 | const LayoutPoint& point() const { return m_point; } |
| 47 | IntPoint roundedPoint() const { return roundedIntPoint(m_point); } |
| 48 | |
| 49 | // Rect-based hit test related methods. |
| 50 | bool isRectBasedTest() const { return m_isRectBased; } |
| 51 | bool isRectilinear() const { return m_isRectilinear; } |
| 52 | IntRect boundingBox() const { return m_boundingBox; } |
| 53 | |
| 54 | WEBCORE_EXPORT static IntRect rectForPoint(const LayoutPoint&, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding); |
| 55 | int topPadding() const { return roundedPoint().y() - m_boundingBox.y(); } |
| 56 | int rightPadding() const { return m_boundingBox.maxX() - roundedPoint().x() - 1; } |
| 57 | int bottomPadding() const { return m_boundingBox.maxY() - roundedPoint().y() - 1; } |
| 58 | int leftPadding() const { return roundedPoint().x() - m_boundingBox.x(); } |
| 59 | |
| 60 | bool intersects(const LayoutRect&) const; |
| 61 | bool intersects(const FloatRect&) const; |
| 62 | bool intersects(const RoundedRect&) const; |
| 63 | |
| 64 | const FloatPoint& transformedPoint() const { return m_transformedPoint; } |
| 65 | const FloatQuad& transformedRect() const { return m_transformedRect; } |
| 66 | |
| 67 | private: |
| 68 | template<typename RectType> |
| 69 | bool intersectsRect(const RectType&) const; |
| 70 | void move(const LayoutSize& offset); |
| 71 | |
| 72 | // This is cached forms of the more accurate point and area below. |
| 73 | LayoutPoint m_point; |
| 74 | IntRect m_boundingBox; |
| 75 | |
| 76 | FloatPoint m_transformedPoint; |
| 77 | FloatQuad m_transformedRect; |
| 78 | |
| 79 | bool m_isRectBased; |
| 80 | bool m_isRectilinear; |
| 81 | }; |
| 82 | |
| 83 | } // namespace WebCore |
| 84 | |