| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 m_savedRelativeOffset = computeRelativeOffset(m_anchorObject, m_scroller, m_
corner); | 165 m_savedRelativeOffset = computeRelativeOffset(m_anchorObject, m_scroller, m_
corner); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void ScrollAnchor::restore() | 168 void ScrollAnchor::restore() |
| 169 { | 169 { |
| 170 if (!m_anchorObject) | 170 if (!m_anchorObject) |
| 171 return; | 171 return; |
| 172 | 172 |
| 173 LayoutSize adjustment = computeRelativeOffset(m_anchorObject, m_scroller, m_
corner) - m_savedRelativeOffset; | 173 LayoutSize adjustment = computeRelativeOffset(m_anchorObject, m_scroller, m_
corner) - m_savedRelativeOffset; |
| 174 if (!adjustment.isZero()) { | 174 if (!adjustment.isZero()) { |
| 175 m_scroller->setScrollPosition( | 175 ScrollAnimatorBase* animator = m_scroller->existingScrollAnimator(); |
| 176 m_scroller->scrollPositionDouble() + DoubleSize(adjustment), | 176 if (!animator || !animator->hasRunningAnimation()) { |
| 177 AnchoringScroll); | 177 m_scroller->setScrollPosition( |
| 178 m_scroller->scrollPositionDouble() + DoubleSize(adjustment), |
| 179 AnchoringScroll); |
| 180 } else { |
| 181 // If in the middle of a scroll animation, stop the animation, make |
| 182 // the adjustment, and continue the animation on the pending delta. |
| 183 FloatSize pendingDelta = animator->desiredTargetPosition() - FloatPo
int(m_scroller->scrollPositionDouble()); |
| 184 animator->cancelAnimation(); |
| 185 m_scroller->setScrollPosition( |
| 186 m_scroller->scrollPositionDouble() + DoubleSize(adjustment), |
| 187 AnchoringScroll); |
| 188 animator->userScroll(ScrollByPixel, pendingDelta); |
| 189 } |
| 178 // Update UMA metric. | 190 // Update UMA metric. |
| 179 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, | 191 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, |
| 180 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2)); | 192 ("Layout.ScrollAnchor.AdjustedScrollOffset", 2)); |
| 181 adjustedOffsetHistogram.count(1); | 193 adjustedOffsetHistogram.count(1); |
| 182 UseCounter::count(scrollerLayoutBox(m_scroller)->document(), UseCounter:
:ScrollAnchored); | 194 UseCounter::count(scrollerLayoutBox(m_scroller)->document(), UseCounter:
:ScrollAnchored); |
| 183 } | 195 } |
| 184 } | 196 } |
| 185 | 197 |
| 186 void ScrollAnchor::clear() | 198 void ScrollAnchor::clear() |
| 187 { | 199 { |
| 188 LayoutObject* anchorObject = m_anchorObject; | 200 LayoutObject* anchorObject = m_anchorObject; |
| 189 m_anchorObject = nullptr; | 201 m_anchorObject = nullptr; |
| 190 | 202 |
| 191 if (anchorObject) | 203 if (anchorObject) |
| 192 anchorObject->maybeClearIsScrollAnchorObject(); | 204 anchorObject->maybeClearIsScrollAnchorObject(); |
| 193 } | 205 } |
| 194 | 206 |
| 195 } // namespace blink | 207 } // namespace blink |
| OLD | NEW |