OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IntersectionGeometry_h | 5 #ifndef IntersectionGeometry_h |
6 #define IntersectionGeometry_h | 6 #define IntersectionGeometry_h |
7 | 7 |
8 #include "platform/Length.h" | 8 #include "platform/Length.h" |
9 #include "platform/geometry/LayoutRect.h" | 9 #include "platform/geometry/LayoutRect.h" |
10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
11 #include "wtf/Vector.h" | 11 #include "wtf/Vector.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 class Node; | |
16 class Element; | 15 class Element; |
17 class LayoutObject; | 16 class LayoutObject; |
18 | 17 |
19 class IntersectionGeometry final | 18 // Computes the intersection between an ancestor (root) element and a |
20 : public GarbageCollectedFinalized<IntersectionGeometry> { | 19 // descendant (target) element, with overflow and CSS clipping applied, but not |
20 // paint occlusion. | |
21 // | |
22 // If the root argument to the constructor is null, computes the intersection | |
23 // of the target with the top-level frame viewport (AKA the "implicit root"). | |
24 class IntersectionGeometry { | |
25 STACK_ALLOCATED() | |
21 public: | 26 public: |
22 enum ReportRootBounds { | 27 IntersectionGeometry(Element* root, |
23 kShouldReportRootBounds, | 28 Element& target, |
24 kShouldNotReportRootBounds, | |
25 }; | |
26 | |
27 IntersectionGeometry(Node* root, | |
28 Element* target, | |
29 const Vector<Length>& rootMargin, | 29 const Vector<Length>& rootMargin, |
30 ReportRootBounds shouldReportRootBounds); | 30 bool shouldReportRootBounds); |
31 ~IntersectionGeometry(); | 31 ~IntersectionGeometry(); |
32 | 32 |
33 void computeGeometry(); | 33 void computeGeometry(); |
34 | |
35 LayoutObject* root() const { return m_root; } | |
36 LayoutObject* target() const { return m_target; } | |
37 | |
38 // Client rect in the coordinate system of the frame containing target. | |
34 LayoutRect targetRect() const { return m_targetRect; } | 39 LayoutRect targetRect() const { return m_targetRect; } |
40 | |
41 // Client rect in the coordinate system of the frame containing target. | |
35 LayoutRect intersectionRect() const { return m_intersectionRect; } | 42 LayoutRect intersectionRect() const { return m_intersectionRect; } |
43 | |
44 // Client rect in the coordinate system of the frame containing root. | |
36 LayoutRect rootRect() const { return m_rootRect; } | 45 LayoutRect rootRect() const { return m_rootRect; } |
46 | |
37 bool doesIntersect() const { return m_doesIntersect; } | 47 bool doesIntersect() const { return m_doesIntersect; } |
38 | 48 |
39 IntRect intersectionIntRect() const { | 49 IntRect intersectionIntRect() const { |
40 return pixelSnappedIntRect(m_intersectionRect); | 50 return pixelSnappedIntRect(m_intersectionRect); |
41 } | 51 } |
42 | 52 |
43 IntRect targetIntRect() const { return pixelSnappedIntRect(m_targetRect); } | 53 IntRect targetIntRect() const { return pixelSnappedIntRect(m_targetRect); } |
44 | 54 |
45 IntRect rootIntRect() const { return pixelSnappedIntRect(m_rootRect); } | 55 IntRect rootIntRect() const { return pixelSnappedIntRect(m_rootRect); } |
46 | 56 |
47 DECLARE_TRACE(); | |
48 | |
49 private: | 57 private: |
50 void initializeGeometry(); | 58 bool initializeGeometry(Element* root, Element& target); |
51 void initializeTargetRect(); | 59 void initializeTargetRect(); |
52 void initializeRootRect(); | 60 void initializeRootRect(); |
53 void clipToRoot(); | 61 void clipToRoot(); |
54 void mapTargetRectToTargetFrameCoordinates(); | 62 void mapTargetRectToTargetFrameCoordinates(); |
55 void mapRootRectToRootFrameCoordinates(); | 63 void mapRootRectToRootFrameCoordinates(); |
56 void mapRootRectToTargetFrameCoordinates(); | 64 void mapIntersectionRectToTargetFrameCoordinates(); |
57 Element* root() const; | |
58 LayoutObject* getRootLayoutObject() const; | |
59 void applyRootMargin(); | 65 void applyRootMargin(); |
60 | 66 |
61 Member<Node> m_root; | 67 // Returns true iff it's possible to compute an intersection between root |
62 Member<Element> m_target; | 68 // and target. |
69 bool isValid() const { return m_isValid; } | |
70 bool rootIsImplicit() const { return m_rootIsImplicit; } | |
71 bool shouldReportRootBounds() const { return m_shouldReportRootBounds; } | |
72 | |
73 LayoutObject* m_root; | |
74 LayoutObject* m_target; | |
63 const Vector<Length> m_rootMargin; | 75 const Vector<Length> m_rootMargin; |
64 const ReportRootBounds m_shouldReportRootBounds; | |
65 LayoutRect m_targetRect; | 76 LayoutRect m_targetRect; |
66 LayoutRect m_intersectionRect; | 77 LayoutRect m_intersectionRect; |
67 LayoutRect m_rootRect; | 78 LayoutRect m_rootRect; |
68 bool m_doesIntersect = false; | 79 unsigned m_doesIntersect : 1; |
80 const unsigned m_shouldReportRootBounds : 1; | |
ojan
2016/12/10 01:18:26
What does this "const" do?
szager1
2016/12/10 01:47:11
It means that it can only be assigned to in the co
| |
81 const unsigned m_rootIsImplicit : 1; | |
82 const unsigned m_isValid : 1; | |
69 }; | 83 }; |
70 | 84 |
71 } // namespace blink | 85 } // namespace blink |
72 | 86 |
73 #endif // IntersectionGeometry_h | 87 #endif // IntersectionGeometry_h |
OLD | NEW |