| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 // Clip intersectionRect to FrameView visible area if necessary, and map all
geometry to frame coordinates. | 118 // Clip intersectionRect to FrameView visible area if necessary, and map all
geometry to frame coordinates. |
| 119 clipToFrameView(geometry); | 119 clipToFrameView(geometry); |
| 120 | 120 |
| 121 if (geometry.intersectionRect.size().isZero()) | 121 if (geometry.intersectionRect.size().isZero()) |
| 122 geometry.intersectionRect = LayoutRect(); | 122 geometry.intersectionRect = LayoutRect(); |
| 123 | 123 |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void IntersectionObservation::computeIntersectionObservations(double timestamp) | 127 void IntersectionObservation::computeIntersectionObservations(DOMHighResTimeStam
p timestamp) |
| 128 { | 128 { |
| 129 // Pre-oilpan, there will be a delay between the time when the target Elemen
t gets deleted | 129 // Pre-oilpan, there will be a delay between the time when the target Elemen
t gets deleted |
| 130 // (because its ref count dropped to zero) and when this IntersectionObserva
tion gets | 130 // (because its ref count dropped to zero) and when this IntersectionObserva
tion gets |
| 131 // deleted (during the next gc run, because the target Element is the only t
hing keeping | 131 // deleted (during the next gc run, because the target Element is the only t
hing keeping |
| 132 // the IntersectionObservation alive). During that interval, we need to che
ck that m_target | 132 // the IntersectionObservation alive). During that interval, we need to che
ck that m_target |
| 133 // hasn't been cleared. | 133 // hasn't been cleared. |
| 134 Element* targetElement = target(); | 134 Element* targetElement = target(); |
| 135 if (!targetElement || !isActive()) | 135 if (!targetElement || !isActive()) |
| 136 return; | 136 return; |
| 137 LayoutObject* targetLayoutObject = targetElement->layoutObject(); | 137 LayoutObject* targetLayoutObject = targetElement->layoutObject(); |
| 138 // TODO(szager): Support SVG | 138 // TODO(szager): Support SVG |
| 139 if (!targetLayoutObject || (!targetLayoutObject->isBox() && !targetLayoutObj
ect->isInline())) | 139 if (!targetLayoutObject || (!targetLayoutObject->isBox() && !targetLayoutObj
ect->isInline())) |
| 140 return; | 140 return; |
| 141 | 141 |
| 142 IntersectionGeometry geometry; | 142 IntersectionGeometry geometry; |
| 143 if (!computeGeometry(geometry)) | 143 if (!computeGeometry(geometry)) |
| 144 return; | 144 return; |
| 145 | 145 |
| 146 float intersectionArea = geometry.intersectionRect.size().width().toFloat()
* geometry.intersectionRect.size().height().toFloat(); | 146 float intersectionArea = geometry.intersectionRect.size().width().toFloat()
* geometry.intersectionRect.size().height().toFloat(); |
| 147 float targetArea = geometry.targetRect.size().width().toFloat() * geometry.t
argetRect.size().height().toFloat(); | 147 float targetArea = geometry.targetRect.size().width().toFloat() * geometry.t
argetRect.size().height().toFloat(); |
| 148 if (!targetArea) | 148 if (!targetArea) |
| 149 return; | 149 return; |
| 150 float newVisibleRatio = intersectionArea / targetArea; | 150 float newVisibleRatio = intersectionArea / targetArea; |
| 151 unsigned newThresholdIndex = observer().firstThresholdGreaterThan(newVisible
Ratio); | 151 unsigned newThresholdIndex = observer().firstThresholdGreaterThan(newVisible
Ratio); |
| 152 IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect); | 152 IntRect snappedRootBounds = pixelSnappedIntRect(geometry.rootRect); |
| 153 IntRect* rootBoundsPointer = m_shouldReportRootBounds ? &snappedRootBounds :
nullptr; | 153 IntRect* rootBoundsPointer = m_shouldReportRootBounds ? &snappedRootBounds :
nullptr; |
| 154 if (m_lastThresholdIndex != newThresholdIndex) { | 154 if (m_lastThresholdIndex != newThresholdIndex) { |
| 155 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry( | 155 IntersectionObserverEntry* newEntry = new IntersectionObserverEntry( |
| 156 timestamp / 1000.0, | 156 timestamp, |
| 157 pixelSnappedIntRect(geometry.targetRect), | 157 pixelSnappedIntRect(geometry.targetRect), |
| 158 rootBoundsPointer, | 158 rootBoundsPointer, |
| 159 pixelSnappedIntRect(geometry.intersectionRect), | 159 pixelSnappedIntRect(geometry.intersectionRect), |
| 160 targetElement); | 160 targetElement); |
| 161 observer().enqueueIntersectionObserverEntry(*newEntry); | 161 observer().enqueueIntersectionObserverEntry(*newEntry); |
| 162 } | 162 } |
| 163 setLastThresholdIndex(newThresholdIndex); | 163 setLastThresholdIndex(newThresholdIndex); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void IntersectionObservation::disconnect() | 166 void IntersectionObservation::disconnect() |
| (...skipping 10 matching lines...) Expand all Loading... |
| 177 m_observer.clear(); | 177 m_observer.clear(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 DEFINE_TRACE(IntersectionObservation) | 180 DEFINE_TRACE(IntersectionObservation) |
| 181 { | 181 { |
| 182 visitor->trace(m_observer); | 182 visitor->trace(m_observer); |
| 183 visitor->trace(m_target); | 183 visitor->trace(m_target); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace blink | 186 } // namespace blink |
| OLD | NEW |