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