blob: 3a625f97abdc565ede7ce245005955966498d8ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_INTERSECTION_GEOMETRY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_INTERSECTION_GEOMETRY_H_
#include "third_party/blink/renderer/platform/geometry/layout_rect.h"
#include "third_party/blink/renderer/platform/geometry/length.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
class Element;
class LayoutObject;
// Computes the intersection between an ancestor (root) element and a
// descendant (target) element, with overflow and CSS clipping applied, but not
// paint occlusion.
//
// If the root argument to the constructor is null, computes the intersection
// of the target with the top-level frame viewport (AKA the "implicit root").
class IntersectionGeometry {
STACK_ALLOCATED();
public:
IntersectionGeometry(Element* root,
Element& target,
const Vector<Length>& root_margin,
bool should_report_root_bounds);
~IntersectionGeometry();
void ComputeGeometry();
LayoutObject* Root() const { return root_; }
LayoutObject* Target() const { return target_; }
// Client rect in the coordinate system of the frame containing target.
LayoutRect TargetRect() const { return target_rect_; }
// Target rect in CSS pixels
LayoutRect UnZoomedTargetRect() const;
// Client rect in the coordinate system of the frame containing target.
LayoutRect IntersectionRect() const { return intersection_rect_; }
// Intersection rect in CSS pixels
LayoutRect UnZoomedIntersectionRect() const;
// Client rect in the coordinate system of the frame containing root.
LayoutRect RootRect() const { return root_rect_; }
// Root rect in CSS pixels
LayoutRect UnZoomedRootRect() const;
bool DoesIntersect() const { return does_intersect_; }
IntRect IntersectionIntRect() const {
return PixelSnappedIntRect(intersection_rect_);
}
IntRect TargetIntRect() const { return PixelSnappedIntRect(target_rect_); }
IntRect RootIntRect() const { return PixelSnappedIntRect(root_rect_); }
private:
bool InitializeCanComputeGeometry(Element* root, Element& target) const;
void InitializeGeometry();
void InitializeTargetRect();
void InitializeRootRect();
void ClipToRoot();
void MapTargetRectToTargetFrameCoordinates();
void MapRootRectToRootFrameCoordinates();
void MapIntersectionRectToTargetFrameCoordinates();
void ApplyRootMargin();
// Returns true iff it's possible to compute an intersection between root
// and target.
bool CanComputeGeometry() const { return can_compute_geometry_; }
bool RootIsImplicit() const { return root_is_implicit_; }
bool ShouldReportRootBounds() const { return should_report_root_bounds_; }
LayoutObject* root_;
LayoutObject* target_;
const Vector<Length> root_margin_;
LayoutRect target_rect_;
LayoutRect intersection_rect_;
LayoutRect root_rect_;
unsigned does_intersect_ : 1;
const unsigned should_report_root_bounds_ : 1;
const unsigned root_is_implicit_ : 1;
const unsigned can_compute_geometry_ : 1;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_INTERSECTION_GEOMETRY_H_
|