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 #include "core/dom/IntersectionObservation.h" | 5 #include "core/dom/IntersectionObservation.h" |
6 | 6 |
7 #include "core/dom/ElementRareData.h" | 7 #include "core/dom/ElementRareData.h" |
8 #include "core/dom/IntersectionObserver.h" | 8 #include "core/dom/IntersectionObserver.h" |
9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
10 #include "core/layout/LayoutBox.h" | 10 #include "core/layout/LayoutBox.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 , m_shouldReportRootBounds(shouldReportRootBounds) | 21 , m_shouldReportRootBounds(shouldReportRootBounds) |
22 , m_lastThresholdIndex(0) | 22 , m_lastThresholdIndex(0) |
23 { | 23 { |
24 } | 24 } |
25 | 25 |
26 Element* IntersectionObservation::target() const | 26 Element* IntersectionObservation::target() const |
27 { | 27 { |
28 return toElement(m_target.get()); | 28 return toElement(m_target.get()); |
29 } | 29 } |
30 | 30 |
31 void IntersectionObservation::initializeGeometry(IntersectionGeometry& geometry) | 31 void IntersectionObservation::applyRootMargin(LayoutRect& rect) const |
| 32 { |
| 33 if (m_shouldReportRootBounds) |
| 34 m_observer->applyRootMargin(rect); |
| 35 } |
| 36 |
| 37 void IntersectionObservation::initializeGeometry(IntersectionGeometry& geometry)
const |
32 { | 38 { |
33 ASSERT(m_target); | 39 ASSERT(m_target); |
34 LayoutObject* targetLayoutObject = target()->layoutObject(); | 40 LayoutObject* targetLayoutObject = target()->layoutObject(); |
35 if (targetLayoutObject->isBoxModelObject()) | 41 if (targetLayoutObject->isBoxModelObject()) |
36 geometry.targetRect = toLayoutBoxModelObject(targetLayoutObject)->visual
OverflowRect(); | 42 geometry.targetRect = toLayoutBoxModelObject(targetLayoutObject)->visual
OverflowRect(); |
37 else | 43 else |
38 geometry.targetRect = toLayoutText(targetLayoutObject)->visualOverflowRe
ct(); | 44 geometry.targetRect = toLayoutText(targetLayoutObject)->visualOverflowRe
ct(); |
39 if (!geometry.targetRect.size().width()) | 45 if (!geometry.targetRect.size().width()) |
40 geometry.targetRect.setWidth(LayoutUnit(1)); | 46 geometry.targetRect.setWidth(LayoutUnit(1)); |
41 if (!geometry.targetRect.size().height()) | 47 if (!geometry.targetRect.size().height()) |
42 geometry.targetRect.setHeight(LayoutUnit(1)); | 48 geometry.targetRect.setHeight(LayoutUnit(1)); |
43 geometry.intersectionRect = geometry.targetRect; | 49 geometry.intersectionRect = geometry.targetRect; |
44 } | 50 } |
45 | 51 |
46 void IntersectionObservation::clipToRoot(LayoutRect& rect) | 52 void IntersectionObservation::clipToRoot(LayoutRect& rect) const |
47 { | 53 { |
48 // Map and clip rect into root element coordinates. | 54 // Map and clip rect into root element coordinates. |
49 // TODO(szager): the writing mode flipping needs a test. | 55 // TODO(szager): the writing mode flipping needs a test. |
50 ASSERT(m_target); | 56 ASSERT(m_target); |
51 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 57 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
52 LayoutObject* targetLayoutObject = target()->layoutObject(); | 58 LayoutObject* targetLayoutObject = target()->layoutObject(); |
53 targetLayoutObject->mapToVisibleRectInAncestorSpace(toLayoutBoxModelObject(r
ootLayoutObject), rect, nullptr); | 59 targetLayoutObject->mapToVisibleRectInAncestorSpace(toLayoutBoxModelObject(r
ootLayoutObject), rect, nullptr); |
54 if (rootLayoutObject->hasOverflowClip()) { | 60 if (rootLayoutObject->hasOverflowClip()) { |
55 LayoutBox* rootLayoutBox = toLayoutBox(rootLayoutObject); | 61 LayoutBox* rootLayoutBox = toLayoutBox(rootLayoutObject); |
56 LayoutRect clipRect(LayoutPoint(), LayoutSize(rootLayoutBox->layer()->si
ze())); | 62 LayoutRect clipRect(LayoutPoint(), LayoutSize(rootLayoutBox->layer()->si
ze())); |
57 m_observer->applyRootMargin(clipRect); | 63 applyRootMargin(clipRect); |
58 rootLayoutBox->flipForWritingMode(rect); | 64 rootLayoutBox->flipForWritingMode(rect); |
59 rect.intersect(clipRect); | 65 rect.intersect(clipRect); |
60 rootLayoutBox->flipForWritingMode(rect); | 66 rootLayoutBox->flipForWritingMode(rect); |
61 } | 67 } |
62 } | 68 } |
63 | 69 |
64 void IntersectionObservation::clipToFrameView(IntersectionGeometry& geometry) | 70 void IntersectionObservation::clipToFrameView(IntersectionGeometry& geometry) co
nst |
65 { | 71 { |
66 Node* rootNode = m_observer->rootNode(); | 72 Node* rootNode = m_observer->rootNode(); |
67 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 73 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
68 if (rootLayoutObject->isLayoutView()) { | 74 if (rootLayoutObject->isLayoutView()) { |
69 geometry.rootRect = LayoutRect(toLayoutView(rootLayoutObject)->frameView
()->visibleContentRect()); | 75 geometry.rootRect = LayoutRect(toLayoutView(rootLayoutObject)->frameView
()->visibleContentRect()); |
70 m_observer->applyRootMargin(geometry.rootRect); | 76 applyRootMargin(geometry.rootRect); |
71 geometry.intersectionRect.intersect(geometry.rootRect); | 77 geometry.intersectionRect.intersect(geometry.rootRect); |
72 } else { | 78 } else { |
73 if (rootLayoutObject->isBox()) | 79 if (rootLayoutObject->isBox()) |
74 geometry.rootRect = LayoutRect(toLayoutBox(rootLayoutObject)->absolu
teContentBox()); | 80 geometry.rootRect = LayoutRect(toLayoutBox(rootLayoutObject)->absolu
teContentBox()); |
75 else | 81 else |
76 geometry.rootRect = LayoutRect(rootLayoutObject->absoluteBoundingBox
Rect()); | 82 geometry.rootRect = LayoutRect(rootLayoutObject->absoluteBoundingBox
Rect()); |
77 m_observer->applyRootMargin(geometry.rootRect); | 83 applyRootMargin(geometry.rootRect); |
78 } | 84 } |
79 | 85 |
80 LayoutPoint scrollPosition(rootNode->document().view()->scrollPosition()); | 86 LayoutPoint scrollPosition(rootNode->document().view()->scrollPosition()); |
81 geometry.targetRect.moveBy(-scrollPosition); | 87 geometry.targetRect.moveBy(-scrollPosition); |
82 geometry.intersectionRect.moveBy(-scrollPosition); | 88 geometry.intersectionRect.moveBy(-scrollPosition); |
83 geometry.rootRect.moveBy(-scrollPosition); | 89 geometry.rootRect.moveBy(-scrollPosition); |
84 } | 90 } |
85 | 91 |
86 static void mapRectToDocumentCoordinates(LayoutObject& layoutObject, LayoutRect&
rect) | 92 static void mapRectToDocumentCoordinates(LayoutObject& layoutObject, LayoutRect&
rect) |
87 { | 93 { |
88 rect = LayoutRect(layoutObject.localToAbsoluteQuad(FloatQuad(FloatRect(rect)
), UseTransforms | ApplyContainerFlip | TraverseDocumentBoundaries).boundingBox(
)); | 94 rect = LayoutRect(layoutObject.localToAbsoluteQuad(FloatQuad(FloatRect(rect)
), UseTransforms | ApplyContainerFlip | TraverseDocumentBoundaries).boundingBox(
)); |
89 } | 95 } |
90 | 96 |
91 static bool isContainingBlockChainDescendant(LayoutObject* descendant, LayoutObj
ect* ancestor) | 97 static bool isContainingBlockChainDescendant(LayoutObject* descendant, LayoutObj
ect* ancestor) |
92 { | 98 { |
93 LocalFrame* ancestorFrame = ancestor->document().frame(); | 99 LocalFrame* ancestorFrame = ancestor->document().frame(); |
94 LocalFrame* descendantFrame = descendant->document().frame(); | 100 LocalFrame* descendantFrame = descendant->document().frame(); |
95 | 101 |
96 if (ancestor->isLayoutView()) | 102 if (ancestor->isLayoutView()) |
97 return descendantFrame && descendantFrame->tree().top() == ancestorFrame
; | 103 return descendantFrame && descendantFrame->tree().top() == ancestorFrame
; |
98 | 104 |
99 if (ancestorFrame != descendantFrame) | 105 if (ancestorFrame != descendantFrame) |
100 return false; | 106 return false; |
101 | 107 |
102 while (descendant && descendant != ancestor) | 108 while (descendant && descendant != ancestor) |
103 descendant = descendant->containingBlock(); | 109 descendant = descendant->containingBlock(); |
104 return descendant; | 110 return descendant; |
105 } | 111 } |
106 | 112 |
107 bool IntersectionObservation::computeGeometry(IntersectionGeometry& geometry) | 113 bool IntersectionObservation::computeGeometry(IntersectionGeometry& geometry) co
nst |
108 { | 114 { |
109 // Pre-oilpan, there will be a delay between the time when the target Elemen
t gets deleted | 115 // Pre-oilpan, there will be a delay between the time when the target Elemen
t gets deleted |
110 // (because its ref count dropped to zero) and when this IntersectionObserva
tion gets | 116 // (because its ref count dropped to zero) and when this IntersectionObserva
tion gets |
111 // deleted (during the next gc run, because the target Element is the only t
hing keeping | 117 // deleted (during the next gc run, because the target Element is the only t
hing keeping |
112 // the IntersectionObservation alive). During that interval, we need to che
ck that m_target | 118 // the IntersectionObservation alive). During that interval, we need to che
ck that m_target |
113 // hasn't been cleared. | 119 // hasn't been cleared. |
114 Element* targetElement = target(); | 120 Element* targetElement = target(); |
115 if (!targetElement || !targetElement->inDocument()) | 121 if (!targetElement || !targetElement->inDocument()) |
116 return false; | 122 return false; |
117 LayoutObject* targetLayoutObject = targetElement->layoutObject(); | 123 LayoutObject* targetLayoutObject = targetElement->layoutObject(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 m_observer.clear(); | 199 m_observer.clear(); |
194 } | 200 } |
195 | 201 |
196 DEFINE_TRACE(IntersectionObservation) | 202 DEFINE_TRACE(IntersectionObservation) |
197 { | 203 { |
198 visitor->trace(m_observer); | 204 visitor->trace(m_observer); |
199 visitor->trace(m_target); | 205 visitor->trace(m_target); |
200 } | 206 } |
201 | 207 |
202 } // namespace blink | 208 } // namespace blink |
OLD | NEW |