Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: third_party/WebKit/Source/core/dom/IntersectionObservation.cpp

Issue 1559593002: Add root margin support for IntersectionObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@intersection-observer-no-root-margin
Patch Set: rebaseline Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
ojan 2016/01/12 01:08:49 Nit: you are repeating this line in both the if an
szager1 2016/01/12 19:24:43 applyRootMargin has to happen before the call to g
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 m_observer.clear(); 157 m_observer.clear();
155 } 158 }
156 159
157 DEFINE_TRACE(IntersectionObservation) 160 DEFINE_TRACE(IntersectionObservation)
158 { 161 {
159 visitor->trace(m_observer); 162 visitor->trace(m_observer);
160 visitor->trace(m_target); 163 visitor->trace(m_target);
161 } 164 }
162 165
163 } // namespace blink 166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698