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

Side by Side Diff: third_party/WebKit/Source/core/layout/IntersectionGeometry.cpp

Issue 2431473003: Intersection Observer support for OOPIF (Closed)
Patch Set: Rebase only Created 3 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/layout/IntersectionGeometry.h" 5 #include "core/layout/IntersectionGeometry.h"
6 6
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/frame/LocalFrame.h" 8 #include "core/frame/LocalFrame.h"
9 #include "core/html/HTMLFrameOwnerElement.h" 9 #include "core/html/HTMLFrameOwnerElement.h"
10 #include "core/layout/LayoutBox.h" 10 #include "core/layout/LayoutBox.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 m_intersectionRect = m_targetRect; 102 m_intersectionRect = m_targetRect;
103 initializeRootRect(); 103 initializeRootRect();
104 } 104 }
105 105
106 void IntersectionGeometry::initializeTargetRect() { 106 void IntersectionGeometry::initializeTargetRect() {
107 m_targetRect = 107 m_targetRect =
108 LayoutRect(toLayoutBoxModelObject(target())->borderBoundingBox()); 108 LayoutRect(toLayoutBoxModelObject(target())->borderBoundingBox());
109 } 109 }
110 110
111 void IntersectionGeometry::initializeRootRect() { 111 void IntersectionGeometry::initializeRootRect() {
112 // TODO(szager): In OOPIF, m_root will be the LayoutView of the
113 // localFrameRoot(). Once viewport intersection support lands,
114 // add a call to mapToVisualRectInAncestorSpace to map the rect up to
115 // top-level frame coordinates.
116 if (m_root->isLayoutView()) { 112 if (m_root->isLayoutView()) {
117 m_rootRect = 113 m_rootRect =
118 LayoutRect(toLayoutView(m_root)->frameView()->visibleContentRect()); 114 LayoutRect(toLayoutView(m_root)->frameView()->visibleContentRect());
115 m_root->mapToVisualRectInAncestorSpace(nullptr, m_rootRect);
119 } else if (m_root->isBox() && m_root->hasOverflowClip()) { 116 } else if (m_root->isBox() && m_root->hasOverflowClip()) {
120 m_rootRect = LayoutRect(toLayoutBox(m_root)->contentBoxRect()); 117 m_rootRect = LayoutRect(toLayoutBox(m_root)->contentBoxRect());
121 } else { 118 } else {
122 m_rootRect = 119 m_rootRect =
123 LayoutRect(toLayoutBoxModelObject(m_root)->borderBoundingBox()); 120 LayoutRect(toLayoutBoxModelObject(m_root)->borderBoundingBox());
124 } 121 }
125 applyRootMargin(); 122 applyRootMargin();
126 } 123 }
127 124
128 void IntersectionGeometry::applyRootMargin() { 125 void IntersectionGeometry::applyRootMargin() {
129 if (m_rootMargin.isEmpty()) 126 if (m_rootMargin.isEmpty())
130 return; 127 return;
131 128
132 // TODO(szager): Make sure the spec is clear that left/right margins are 129 // TODO(szager): Make sure the spec is clear that left/right margins are
133 // resolved against width and not height. 130 // resolved against width and not height.
134 LayoutUnit topMargin = computeMargin(m_rootMargin[0], m_rootRect.height()); 131 LayoutUnit topMargin = computeMargin(m_rootMargin[0], m_rootRect.height());
135 LayoutUnit rightMargin = computeMargin(m_rootMargin[1], m_rootRect.width()); 132 LayoutUnit rightMargin = computeMargin(m_rootMargin[1], m_rootRect.width());
136 LayoutUnit bottomMargin = computeMargin(m_rootMargin[2], m_rootRect.height()); 133 LayoutUnit bottomMargin = computeMargin(m_rootMargin[2], m_rootRect.height());
137 LayoutUnit leftMargin = computeMargin(m_rootMargin[3], m_rootRect.width()); 134 LayoutUnit leftMargin = computeMargin(m_rootMargin[3], m_rootRect.width());
138 135
139 m_rootRect.setX(m_rootRect.x() - leftMargin); 136 m_rootRect.setX(m_rootRect.x() - leftMargin);
140 m_rootRect.setWidth(m_rootRect.width() + leftMargin + rightMargin); 137 m_rootRect.setWidth(m_rootRect.width() + leftMargin + rightMargin);
141 m_rootRect.setY(m_rootRect.y() - topMargin); 138 m_rootRect.setY(m_rootRect.y() - topMargin);
142 m_rootRect.setHeight(m_rootRect.height() + topMargin + bottomMargin); 139 m_rootRect.setHeight(m_rootRect.height() + topMargin + bottomMargin);
143 } 140 }
144 141
145 void IntersectionGeometry::clipToRoot() { 142 void IntersectionGeometry::clipToRoot() {
146 // Map and clip rect into root element coordinates. 143 // Map and clip rect into root element coordinates.
147 // TODO(szager): the writing mode flipping needs a test. 144 // TODO(szager): the writing mode flipping needs a test.
148 // TODO(szager): Once the OOPIF viewport intersection code lands,
149 // use nullptr for ancestor to map to the top frame.
150 LayoutBox* ancestor = toLayoutBox(m_root); 145 LayoutBox* ancestor = toLayoutBox(m_root);
151 m_doesIntersect = m_target->mapToVisualRectInAncestorSpace( 146 m_doesIntersect = m_target->mapToVisualRectInAncestorSpace(
152 ancestor, m_intersectionRect, EdgeInclusive); 147 (rootIsImplicit() ? nullptr : ancestor), m_intersectionRect,
148 EdgeInclusive);
153 if (ancestor && ancestor->hasOverflowClip()) 149 if (ancestor && ancestor->hasOverflowClip())
154 m_intersectionRect.move(-ancestor->scrolledContentOffset()); 150 m_intersectionRect.move(-ancestor->scrolledContentOffset());
155 if (!m_doesIntersect) 151 if (!m_doesIntersect)
156 return; 152 return;
157 LayoutRect rootClipRect(m_rootRect); 153 LayoutRect rootClipRect(m_rootRect);
158 if (ancestor) 154 if (ancestor)
159 ancestor->flipForWritingMode(rootClipRect); 155 ancestor->flipForWritingMode(rootClipRect);
160 m_doesIntersect &= m_intersectionRect.inclusiveIntersect(rootClipRect); 156 m_doesIntersect &= m_intersectionRect.inclusiveIntersect(rootClipRect);
161 } 157 }
162 158
163 void IntersectionGeometry::mapTargetRectToTargetFrameCoordinates() { 159 void IntersectionGeometry::mapTargetRectToTargetFrameCoordinates() {
164 Document& targetDocument = m_target->document(); 160 Document& targetDocument = m_target->document();
165 LayoutSize scrollPosition = 161 LayoutSize scrollPosition =
166 LayoutSize(targetDocument.view()->getScrollOffset()); 162 LayoutSize(targetDocument.view()->getScrollOffset());
167 mapRectUpToDocument(m_targetRect, *m_target, targetDocument); 163 mapRectUpToDocument(m_targetRect, *m_target, targetDocument);
168 m_targetRect.move(-scrollPosition); 164 m_targetRect.move(-scrollPosition);
169 } 165 }
170 166
171 void IntersectionGeometry::mapRootRectToRootFrameCoordinates() { 167 void IntersectionGeometry::mapRootRectToRootFrameCoordinates() {
172 Document& rootDocument = m_root->document(); 168 m_root->frameView()->mapQuadToAncestorFrameIncludingScrollOffset(
173 if (!rootIsImplicit()) 169 m_rootRect, m_root,
174 mapRectUpToDocument(m_rootRect, *m_root, rootDocument); 170 rootIsImplicit() ? nullptr : m_root->document().layoutView(),
175 // TODO(szager): When OOPIF support lands, this scroll offset adjustment 171 UseTransforms | ApplyContainerFlip);
176 // will probably be wrong.
177 LayoutSize scrollPosition =
178 LayoutSize(rootDocument.view()->getScrollOffset());
179 m_rootRect.move(-scrollPosition);
180 } 172 }
181 173
182 void IntersectionGeometry::mapIntersectionRectToTargetFrameCoordinates() { 174 void IntersectionGeometry::mapIntersectionRectToTargetFrameCoordinates() {
183 Document& targetDocument = m_target->document(); 175 Document& targetDocument = m_target->document();
184 if (rootIsImplicit()) { 176 if (rootIsImplicit()) {
185 LocalFrame* targetFrame = targetDocument.frame(); 177 LocalFrame* targetFrame = targetDocument.frame();
186 Frame* rootFrame = targetFrame->tree().top(); 178 Frame* rootFrame = targetFrame->tree().top();
187 LayoutSize scrollPosition = 179 LayoutSize scrollPosition =
188 LayoutSize(targetDocument.view()->getScrollOffset()); 180 LayoutSize(targetDocument.view()->getScrollOffset());
189 if (targetFrame != rootFrame) 181 if (targetFrame != rootFrame)
(...skipping 16 matching lines...) Expand all
206 mapIntersectionRectToTargetFrameCoordinates(); 198 mapIntersectionRectToTargetFrameCoordinates();
207 else 199 else
208 m_intersectionRect = LayoutRect(); 200 m_intersectionRect = LayoutRect();
209 // Small optimization: if we're not going to report root bounds, don't bother 201 // Small optimization: if we're not going to report root bounds, don't bother
210 // transforming them to the frame. 202 // transforming them to the frame.
211 if (shouldReportRootBounds()) 203 if (shouldReportRootBounds())
212 mapRootRectToRootFrameCoordinates(); 204 mapRootRectToRootFrameCoordinates();
213 } 205 }
214 206
215 } // namespace blink 207 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698