| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ScrollAnchor.h" | 5 #include "core/layout/ScrollAnchor.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/frame/UseCounter.h" | 8 #include "core/frame/UseCounter.h" |
| 9 #include "core/layout/LayoutView.h" | 9 #include "core/layout/LayoutView.h" |
| 10 #include "core/layout/line/InlineTextBox.h" | 10 #include "core/layout/line/InlineTextBox.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if (!m_anchorObject) | 181 if (!m_anchorObject) |
| 182 return; | 182 return; |
| 183 | 183 |
| 184 LayoutSize adjustment = computeRelativeOffset(m_anchorObject, m_scroller, m_
corner) - m_savedRelativeOffset; | 184 LayoutSize adjustment = computeRelativeOffset(m_anchorObject, m_scroller, m_
corner) - m_savedRelativeOffset; |
| 185 if (!adjustment.isZero()) { | 185 if (!adjustment.isZero()) { |
| 186 ScrollAnimatorBase* animator = m_scroller->existingScrollAnimator(); | 186 ScrollAnimatorBase* animator = m_scroller->existingScrollAnimator(); |
| 187 if (!animator || !animator->hasRunningAnimation()) { | 187 if (!animator || !animator->hasRunningAnimation()) { |
| 188 m_scroller->setScrollPosition( | 188 m_scroller->setScrollPosition( |
| 189 m_scroller->scrollPositionDouble() + DoubleSize(adjustment), | 189 m_scroller->scrollPositionDouble() + DoubleSize(adjustment), |
| 190 AnchoringScroll); | 190 AnchoringScroll); |
| 191 animator->updateImplOnlyAnimationWithAdjustment(FloatSize(adjustment
)); |
| 191 } else { | 192 } else { |
| 192 // If in the middle of a scroll animation, stop the animation, make | 193 // If in the middle of a scroll animation, stop the animation, make |
| 193 // the adjustment, and continue the animation on the pending delta. | 194 // the adjustment, and continue the animation on the pending delta. |
| 194 FloatSize pendingDelta = animator->desiredTargetPosition() - FloatPo
int(m_scroller->scrollPositionDouble()); | 195 FloatSize pendingDelta = animator->desiredTargetPosition() - FloatPo
int(m_scroller->scrollPositionDouble()); |
| 195 animator->cancelAnimation(); | 196 animator->cancelAnimation(); |
| 196 m_scroller->setScrollPosition( | 197 m_scroller->setScrollPosition( |
| 197 m_scroller->scrollPositionDouble() + DoubleSize(adjustment), | 198 m_scroller->scrollPositionDouble() + DoubleSize(adjustment), |
| 198 AnchoringScroll); | 199 AnchoringScroll); |
| 199 animator->userScroll(ScrollByPixel, pendingDelta); | 200 animator->userScroll(ScrollByPixel, pendingDelta); |
| 200 } | 201 } |
| 201 // Update UMA metric. | 202 // Update UMA metric. |
| 202 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, | 203 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, |
| 203 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2)); | 204 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2)); |
| 204 adjustedOffsetHistogram.count(1); | 205 adjustedOffsetHistogram.count(1); |
| 205 UseCounter::count(scrollerLayoutBox(m_scroller)->document(), UseCounter:
:ScrollAnchored); | 206 UseCounter::count(scrollerLayoutBox(m_scroller)->document(), UseCounter:
:ScrollAnchored); |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 | 209 |
| 209 void ScrollAnchor::clear() | 210 void ScrollAnchor::clear() |
| 210 { | 211 { |
| 211 LayoutObject* anchorObject = m_anchorObject; | 212 LayoutObject* anchorObject = m_anchorObject; |
| 212 m_anchorObject = nullptr; | 213 m_anchorObject = nullptr; |
| 213 | 214 |
| 214 if (anchorObject) | 215 if (anchorObject) |
| 215 anchorObject->maybeClearIsScrollAnchorObject(); | 216 anchorObject->maybeClearIsScrollAnchorObject(); |
| 216 } | 217 } |
| 217 | 218 |
| 218 } // namespace blink | 219 } // namespace blink |
| OLD | NEW |