| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // should scroll by 1px instead of 0.2px.) This is true regardless of whethe
r | 188 // should scroll by 1px instead of 0.2px.) This is true regardless of whethe
r |
| 189 // the ScrollableArea actually uses fractional scroll positions. | 189 // the ScrollableArea actually uses fractional scroll positions. |
| 190 IntSize adjustment = | 190 IntSize adjustment = |
| 191 roundedIntSize(computeRelativeOffset(m_anchorObject, m_scroller, m_corne
r)) - | 191 roundedIntSize(computeRelativeOffset(m_anchorObject, m_scroller, m_corne
r)) - |
| 192 roundedIntSize(m_savedRelativeOffset); | 192 roundedIntSize(m_savedRelativeOffset); |
| 193 if (!adjustment.isZero()) { | 193 if (!adjustment.isZero()) { |
| 194 DoublePoint desiredPos = m_scroller->scrollPositionDouble() + adjustment
; | 194 DoublePoint desiredPos = m_scroller->scrollPositionDouble() + adjustment
; |
| 195 ScrollAnimatorBase* animator = m_scroller->existingScrollAnimator(); | 195 ScrollAnimatorBase* animator = m_scroller->existingScrollAnimator(); |
| 196 if (!animator || !animator->hasRunningAnimation()) { | 196 if (!animator || !animator->hasRunningAnimation()) { |
| 197 m_scroller->setScrollPosition(desiredPos, AnchoringScroll); | 197 m_scroller->setScrollPosition(desiredPos, AnchoringScroll); |
| 198 animator->updateImplOnlyScrollOffsetAnimation(FloatSize(adjustment))
; |
| 198 } else { | 199 } else { |
| 199 // If in the middle of a scroll animation, stop the animation, make | 200 // If in the middle of a scroll animation, stop the animation, make |
| 200 // the adjustment, and continue the animation on the pending delta. | 201 // the adjustment, and continue the animation on the pending delta. |
| 201 FloatSize pendingDelta = animator->desiredTargetPosition() - FloatPo
int(m_scroller->scrollPositionDouble()); | 202 FloatSize pendingDelta = animator->desiredTargetPosition() - FloatPo
int(m_scroller->scrollPositionDouble()); |
| 202 animator->cancelAnimation(); | 203 animator->cancelAnimation(); |
| 203 m_scroller->setScrollPosition(desiredPos, AnchoringScroll); | 204 m_scroller->setScrollPosition(desiredPos, AnchoringScroll); |
| 204 animator->userScroll(ScrollByPixel, pendingDelta); | 205 animator->userScroll(ScrollByPixel, pendingDelta); |
| 205 } | 206 } |
| 206 // Update UMA metric. | 207 // Update UMA metric. |
| 207 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, | 208 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, |
| 208 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2)); | 209 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2)); |
| 209 adjustedOffsetHistogram.count(1); | 210 adjustedOffsetHistogram.count(1); |
| 210 UseCounter::count(scrollerLayoutBox(m_scroller)->document(), UseCounter:
:ScrollAnchored); | 211 UseCounter::count(scrollerLayoutBox(m_scroller)->document(), UseCounter:
:ScrollAnchored); |
| 211 } | 212 } |
| 212 } | 213 } |
| 213 | 214 |
| 214 void ScrollAnchor::clear() | 215 void ScrollAnchor::clear() |
| 215 { | 216 { |
| 216 LayoutObject* anchorObject = m_anchorObject; | 217 LayoutObject* anchorObject = m_anchorObject; |
| 217 m_anchorObject = nullptr; | 218 m_anchorObject = nullptr; |
| 218 | 219 |
| 219 if (anchorObject) | 220 if (anchorObject) |
| 220 anchorObject->maybeClearIsScrollAnchorObject(); | 221 anchorObject->maybeClearIsScrollAnchorObject(); |
| 221 } | 222 } |
| 222 | 223 |
| 223 } // namespace blink | 224 } // namespace blink |
| OLD | NEW |