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 27 matching lines...) Expand all Loading... |
38 { | 38 { |
39 // Map and clip rect into root element coordinates. | 39 // Map and clip rect into root element coordinates. |
40 // TODO(szager): the writing mode flipping needs a test. | 40 // TODO(szager): the writing mode flipping needs a test. |
41 ASSERT(m_target); | 41 ASSERT(m_target); |
42 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 42 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
43 LayoutObject* targetLayoutObject = m_target->layoutObject(); | 43 LayoutObject* targetLayoutObject = m_target->layoutObject(); |
44 targetLayoutObject->mapToVisibleRectInAncestorSpace(toLayoutBoxModelObject(r
ootLayoutObject), rect, nullptr); | 44 targetLayoutObject->mapToVisibleRectInAncestorSpace(toLayoutBoxModelObject(r
ootLayoutObject), rect, nullptr); |
45 if (rootLayoutObject->hasOverflowClip()) { | 45 if (rootLayoutObject->hasOverflowClip()) { |
46 LayoutBox* rootLayoutBox = toLayoutBox(rootLayoutObject); | 46 LayoutBox* rootLayoutBox = toLayoutBox(rootLayoutObject); |
47 LayoutRect clipRect(LayoutPoint(), LayoutSize(rootLayoutBox->layer()->si
ze())); | 47 LayoutRect clipRect(LayoutPoint(), LayoutSize(rootLayoutBox->layer()->si
ze())); |
| 48 m_observer->applyRootMargin(clipRect); |
48 rootLayoutBox->flipForWritingMode(rect); | 49 rootLayoutBox->flipForWritingMode(rect); |
49 rect.intersect(clipRect); | 50 rect.intersect(clipRect); |
50 rootLayoutBox->flipForWritingMode(rect); | 51 rootLayoutBox->flipForWritingMode(rect); |
51 } | 52 } |
52 } | 53 } |
53 | 54 |
54 void IntersectionObservation::clipToFrameView(IntersectionGeometry& geometry) | 55 void IntersectionObservation::clipToFrameView(IntersectionGeometry& geometry) |
55 { | 56 { |
56 Element* rootElement = m_observer->root(); | 57 Element* rootElement = m_observer->root(); |
57 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 58 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
58 if (rootElement == rootElement->document().documentElement()) { | 59 if (rootElement == rootElement->document().documentElement()) { |
59 geometry.rootRect = LayoutRect(rootElement->document().view()->visibleCo
ntentRect()); | 60 geometry.rootRect = LayoutRect(rootElement->document().view()->visibleCo
ntentRect()); |
| 61 m_observer->applyRootMargin(geometry.rootRect); |
60 geometry.intersectionRect.intersect(geometry.rootRect); | 62 geometry.intersectionRect.intersect(geometry.rootRect); |
61 } else { | 63 } else { |
62 if (rootLayoutObject->isBox()) | 64 if (rootLayoutObject->isBox()) |
63 geometry.rootRect = LayoutRect(toLayoutBox(rootLayoutObject)->absolu
teContentBox()); | 65 geometry.rootRect = LayoutRect(toLayoutBox(rootLayoutObject)->absolu
teContentBox()); |
64 else | 66 else |
65 geometry.rootRect = LayoutRect(rootLayoutObject->absoluteBoundingBox
Rect()); | 67 geometry.rootRect = LayoutRect(rootLayoutObject->absoluteBoundingBox
Rect()); |
| 68 m_observer->applyRootMargin(geometry.rootRect); |
66 } | 69 } |
67 | 70 |
68 LayoutPoint scrollPosition(rootElement->document().view()->scrollPosition())
; | 71 LayoutPoint scrollPosition(rootElement->document().view()->scrollPosition())
; |
69 geometry.targetRect.moveBy(-scrollPosition); | 72 geometry.targetRect.moveBy(-scrollPosition); |
70 geometry.intersectionRect.moveBy(-scrollPosition); | 73 geometry.intersectionRect.moveBy(-scrollPosition); |
71 geometry.rootRect.moveBy(-scrollPosition); | 74 geometry.rootRect.moveBy(-scrollPosition); |
72 } | 75 } |
73 | 76 |
74 static void mapRectToDocumentCoordinates(LayoutObject& layoutObject, LayoutRect&
rect) | 77 static void mapRectToDocumentCoordinates(LayoutObject& layoutObject, LayoutRect&
rect) |
75 { | 78 { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 m_observer.clear(); | 162 m_observer.clear(); |
160 } | 163 } |
161 | 164 |
162 DEFINE_TRACE(IntersectionObservation) | 165 DEFINE_TRACE(IntersectionObservation) |
163 { | 166 { |
164 visitor->trace(m_observer); | 167 visitor->trace(m_observer); |
165 visitor->trace(m_target); | 168 visitor->trace(m_target); |
166 } | 169 } |
167 | 170 |
168 } // namespace blink | 171 } // namespace blink |
OLD | NEW |