| 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 26 matching lines...) Expand all Loading... |
| 37 void IntersectionObservation::initializeGeometry(IntersectionGeometry& geometry)
const | 37 void IntersectionObservation::initializeGeometry(IntersectionGeometry& geometry)
const |
| 38 { | 38 { |
| 39 initializeTargetRect(geometry.targetRect); | 39 initializeTargetRect(geometry.targetRect); |
| 40 geometry.intersectionRect = geometry.targetRect; | 40 geometry.intersectionRect = geometry.targetRect; |
| 41 initializeRootRect(geometry.rootRect); | 41 initializeRootRect(geometry.rootRect); |
| 42 geometry.doesIntersect = true; | 42 geometry.doesIntersect = true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void IntersectionObservation::initializeTargetRect(LayoutRect& rect) const | 45 void IntersectionObservation::initializeTargetRect(LayoutRect& rect) const |
| 46 { | 46 { |
| 47 ASSERT(m_target); | 47 DCHECK(m_target); |
| 48 LayoutObject* targetLayoutObject = target()->layoutObject(); | 48 LayoutObject* targetLayoutObject = target()->layoutObject(); |
| 49 ASSERT(targetLayoutObject && targetLayoutObject->isBoxModelObject()); | 49 DCHECK(targetLayoutObject && targetLayoutObject->isBoxModelObject()); |
| 50 rect = toLayoutBoxModelObject(targetLayoutObject)->visualOverflowRect(); | 50 rect = toLayoutBoxModelObject(targetLayoutObject)->visualOverflowRect(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void IntersectionObservation::initializeRootRect(LayoutRect& rect) const | 53 void IntersectionObservation::initializeRootRect(LayoutRect& rect) const |
| 54 { | 54 { |
| 55 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 55 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
| 56 if (rootLayoutObject->isLayoutView()) | 56 if (rootLayoutObject->isLayoutView()) |
| 57 rect = LayoutRect(toLayoutView(rootLayoutObject)->frameView()->visibleCo
ntentRect()); | 57 rect = LayoutRect(toLayoutView(rootLayoutObject)->frameView()->visibleCo
ntentRect()); |
| 58 else if (rootLayoutObject->isBox() && rootLayoutObject->hasOverflowClip()) | 58 else if (rootLayoutObject->isBox() && rootLayoutObject->hasOverflowClip()) |
| 59 rect = LayoutRect(toLayoutBox(rootLayoutObject)->contentBoxRect()); | 59 rect = LayoutRect(toLayoutBox(rootLayoutObject)->contentBoxRect()); |
| 60 else | 60 else |
| 61 rect = LayoutRect(toLayoutBoxModelObject(rootLayoutObject)->borderBoundi
ngBox()); | 61 rect = LayoutRect(toLayoutBoxModelObject(rootLayoutObject)->borderBoundi
ngBox()); |
| 62 applyRootMargin(rect); | 62 applyRootMargin(rect); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void IntersectionObservation::clipToRoot(IntersectionGeometry& geometry) const | 65 void IntersectionObservation::clipToRoot(IntersectionGeometry& geometry) const |
| 66 { | 66 { |
| 67 // Map and clip rect into root element coordinates. | 67 // Map and clip rect into root element coordinates. |
| 68 // TODO(szager): the writing mode flipping needs a test. | 68 // TODO(szager): the writing mode flipping needs a test. |
| 69 ASSERT(m_target); | 69 DCHECK(m_target); |
| 70 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 70 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
| 71 LayoutObject* targetLayoutObject = target()->layoutObject(); | 71 LayoutObject* targetLayoutObject = target()->layoutObject(); |
| 72 | 72 |
| 73 geometry.doesIntersect = targetLayoutObject->mapToVisualRectInAncestorSpace(
toLayoutBoxModelObject(rootLayoutObject), geometry.intersectionRect, EdgeInclusi
ve); | 73 geometry.doesIntersect = targetLayoutObject->mapToVisualRectInAncestorSpace(
toLayoutBoxModelObject(rootLayoutObject), geometry.intersectionRect, EdgeInclusi
ve); |
| 74 if (!geometry.doesIntersect) | 74 if (!geometry.doesIntersect) |
| 75 return; | 75 return; |
| 76 LayoutRect rootClipRect(geometry.rootRect); | 76 LayoutRect rootClipRect(geometry.rootRect); |
| 77 toLayoutBox(rootLayoutObject)->flipForWritingMode(rootClipRect); | 77 toLayoutBox(rootLayoutObject)->flipForWritingMode(rootClipRect); |
| 78 geometry.doesIntersect &= geometry.intersectionRect.inclusiveIntersect(rootC
lipRect); | 78 geometry.doesIntersect &= geometry.intersectionRect.inclusiveIntersect(rootC
lipRect); |
| 79 } | 79 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 { | 147 { |
| 148 // Pre-oilpan, there will be a delay between the time when the target Elemen
t gets deleted | 148 // Pre-oilpan, there will be a delay between the time when the target Elemen
t gets deleted |
| 149 // (because its ref count dropped to zero) and when this IntersectionObserva
tion gets | 149 // (because its ref count dropped to zero) and when this IntersectionObserva
tion gets |
| 150 // deleted (during the next gc run, because the target Element is the only t
hing keeping | 150 // deleted (during the next gc run, because the target Element is the only t
hing keeping |
| 151 // the IntersectionObservation alive). During that interval, we need to che
ck that m_target | 151 // the IntersectionObservation alive). During that interval, we need to che
ck that m_target |
| 152 // hasn't been cleared. | 152 // hasn't been cleared. |
| 153 Element* targetElement = target(); | 153 Element* targetElement = target(); |
| 154 if (!targetElement || !targetElement->inShadowIncludingDocument()) | 154 if (!targetElement || !targetElement->inShadowIncludingDocument()) |
| 155 return false; | 155 return false; |
| 156 LayoutObject* targetLayoutObject = targetElement->layoutObject(); | 156 LayoutObject* targetLayoutObject = targetElement->layoutObject(); |
| 157 ASSERT(m_observer); | 157 DCHECK(m_observer); |
| 158 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); | 158 LayoutObject* rootLayoutObject = m_observer->rootLayoutObject(); |
| 159 // TODO(szager): Support SVG | 159 // TODO(szager): Support SVG |
| 160 if (!targetLayoutObject) | 160 if (!targetLayoutObject) |
| 161 return false; | 161 return false; |
| 162 if (!targetLayoutObject->isBoxModelObject() && !targetLayoutObject->isText()
) | 162 if (!targetLayoutObject->isBoxModelObject() && !targetLayoutObject->isText()
) |
| 163 return false; | 163 return false; |
| 164 if (!rootLayoutObject || !rootLayoutObject->isBoxModelObject()) | 164 if (!rootLayoutObject || !rootLayoutObject->isBoxModelObject()) |
| 165 return false; | 165 return false; |
| 166 if (!isContainingBlockChainDescendant(targetLayoutObject, rootLayoutObject)) | 166 if (!isContainingBlockChainDescendant(targetLayoutObject, rootLayoutObject)) |
| 167 return false; | 167 return false; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 m_observer.clear(); | 241 m_observer.clear(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 DEFINE_TRACE(IntersectionObservation) | 244 DEFINE_TRACE(IntersectionObservation) |
| 245 { | 245 { |
| 246 visitor->trace(m_observer); | 246 visitor->trace(m_observer); |
| 247 visitor->trace(m_target); | 247 visitor->trace(m_target); |
| 248 } | 248 } |
| 249 | 249 |
| 250 } // namespace blink | 250 } // namespace blink |
| OLD | NEW |