blob: e4c95df2b6f0ee329967e4482bc7db15e6fb9161 [file] [log] [blame]
* Copyright (C) 2006 Apple Computer, Inc.
* Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* Library General Public License for more details.
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/geometry/float_quad.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class FloatRoundedRect;
class CORE_EXPORT HitTestLocation {
// Note that all points are in contents (aka "page") coordinate space for the
// document that is being hit tested. All points and size are in root frame
// coordinates (physical pixel scaled by page_scale when zoom for dsf is
// enabled; otherwise in dip scaled by page_scale), Which means the points
// should already applied page_scale_factor, but not page_zoom_factor and
// scroll offset. See:
explicit HitTestLocation(const LayoutPoint&);
explicit HitTestLocation(const IntPoint&);
explicit HitTestLocation(const FloatPoint&);
explicit HitTestLocation(const DoublePoint&);
explicit HitTestLocation(const FloatPoint&, const FloatQuad&);
explicit HitTestLocation(const LayoutRect&);
HitTestLocation(const HitTestLocation&, const LayoutSize& offset);
HitTestLocation(const HitTestLocation&);
HitTestLocation& operator=(const HitTestLocation&);
const LayoutPoint& Point() const { return point_; }
IntPoint RoundedPoint() const { return RoundedIntPoint(point_); }
// Rect-based hit test related methods.
bool IsRectBasedTest() const { return is_rect_based_; }
bool IsRectilinear() const { return is_rectilinear_; }
const LayoutRect& BoundingBox() const { return bounding_box_; }
IntRect EnclosingIntRect() const {
return ::blink::EnclosingIntRect(bounding_box_);
// Returns the 1px x 1px hit test rect for a point.
// TODO(pdr): Should we be using a one-layout-unit rect instead?
static LayoutRect RectForPoint(const LayoutPoint& point) {
return LayoutRect(FlooredIntPoint(point), IntSize(1, 1));
bool Intersects(const LayoutRect&) const;
// Uses floating-point intersection, which uses inclusive intersection
// (see LayoutRect::InclusiveIntersect for a definition)
bool Intersects(const FloatRect&) const;
bool Intersects(const FloatRoundedRect&) const;
bool Intersects(const FloatQuad&) const;
bool ContainsPoint(const FloatPoint&) const;
const FloatPoint& TransformedPoint() const { return transformed_point_; }
const FloatQuad& TransformedRect() const { return transformed_rect_; }
template <typename RectType>
bool IntersectsRect(const RectType&, const RectType& bounding_box) const;
void Move(const LayoutSize& offset);
// These are cached forms of the more accurate |transformed_point_| and
// |transformed_rect_|, below.
LayoutPoint point_;
LayoutRect bounding_box_;
FloatPoint transformed_point_;
FloatQuad transformed_rect_;
bool is_rect_based_;
bool is_rectilinear_;
} // namespace blink