| 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/line/InlineTextBox.h" | 9 #include "core/layout/line/InlineTextBox.h" |
| 10 #include "core/paint/PaintLayerScrollableArea.h" | 10 #include "core/paint/PaintLayerScrollableArea.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 m_hasBounced = false; | 234 m_hasBounced = false; |
| 235 m_lastAdjustment = IntSize(); | 235 m_lastAdjustment = IntSize(); |
| 236 m_lastAdjusted.clear(); | 236 m_lastAdjusted.clear(); |
| 237 return; | 237 return; |
| 238 } | 238 } |
| 239 adjust(adjustment); | 239 adjust(adjustment); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void ScrollAnchor::adjust(IntSize adjustment) | 242 void ScrollAnchor::adjust(IntSize adjustment) |
| 243 { | 243 { |
| 244 DoublePoint desiredPos = m_scroller->scrollPositionDouble() + adjustment; | 244 m_scroller->scrollAnimator().adjustAnimationAndSetScrollPosition(adjustment,
AnchoringScroll); |
| 245 ScrollAnimatorBase* animator = m_scroller->existingScrollAnimator(); | |
| 246 if (!animator || !animator->hasRunningAnimation()) { | |
| 247 m_scroller->setScrollPosition(desiredPos, AnchoringScroll); | |
| 248 animator->adjustImplOnlyScrollOffsetAnimation(FloatSize(adjustment)); | |
| 249 } else { | |
| 250 // If in the middle of a scroll animation, stop the animation, make | |
| 251 // the adjustment, and continue the animation on the pending delta. | |
| 252 // TODO(skobes): This is not quite right, we are starting a new curve wi
thout | |
| 253 // saving our progress on the existing curve. | |
| 254 FloatSize pendingDelta = animator->desiredTargetPosition() - | |
| 255 FloatPoint(m_scroller->scrollPositionDouble()); | |
| 256 animator->cancelAnimation(); | |
| 257 m_scroller->setScrollPosition(desiredPos, AnchoringScroll); | |
| 258 animator->userScroll(ScrollByPixel, pendingDelta); | |
| 259 } | |
| 260 | 245 |
| 261 if (m_current && m_lastAdjusted.m_anchorObject != m_current.m_anchorObject)
{ | 246 if (m_current && m_lastAdjusted.m_anchorObject != m_current.m_anchorObject)
{ |
| 262 m_lastAdjusted.clear(); | 247 m_lastAdjusted.clear(); |
| 263 m_lastAdjusted = m_current; | 248 m_lastAdjusted = m_current; |
| 264 } | 249 } |
| 265 m_hasBounced = (m_lastAdjustment == -adjustment); | 250 m_hasBounced = (m_lastAdjustment == -adjustment); |
| 266 m_lastAdjustment = adjustment; | 251 m_lastAdjustment = adjustment; |
| 267 | 252 |
| 268 // Update UMA metric. | 253 // Update UMA metric. |
| 269 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, | 254 DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 294 | 279 |
| 295 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) | 280 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) |
| 296 { | 281 { |
| 297 if (m_current.m_anchorObject == layoutObject) | 282 if (m_current.m_anchorObject == layoutObject) |
| 298 m_current.clear(); | 283 m_current.clear(); |
| 299 if (m_lastAdjusted.m_anchorObject == layoutObject) | 284 if (m_lastAdjusted.m_anchorObject == layoutObject) |
| 300 m_lastAdjusted.clear(); | 285 m_lastAdjusted.clear(); |
| 301 } | 286 } |
| 302 | 287 |
| 303 } // namespace blink | 288 } // namespace blink |
| OLD | NEW |