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/frame/RootFrameViewport.h" | 5 #include "core/frame/RootFrameViewport.h" |
6 | 6 |
7 #include "core/frame/LocalFrameView.h" | 7 #include "core/frame/LocalFrameView.h" |
8 #include "core/layout/ScrollAlignment.h" | 8 #include "core/layout/ScrollAlignment.h" |
9 #include "core/layout/ScrollAnchor.h" | 9 #include "core/layout/ScrollAnchor.h" |
10 #include "platform/geometry/DoubleRect.h" | 10 #include "platform/geometry/DoubleRect.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 ScrollableArea::SetScrollOffset(clamped_offset, scroll_type, scroll_behavior); | 202 ScrollableArea::SetScrollOffset(clamped_offset, scroll_type, scroll_behavior); |
203 } | 203 } |
204 | 204 |
205 ScrollBehavior RootFrameViewport::ScrollBehaviorStyle() const { | 205 ScrollBehavior RootFrameViewport::ScrollBehaviorStyle() const { |
206 return LayoutViewport().ScrollBehaviorStyle(); | 206 return LayoutViewport().ScrollBehaviorStyle(); |
207 } | 207 } |
208 | 208 |
209 LayoutRect RootFrameViewport::ScrollIntoView(const LayoutRect& rect_in_content, | 209 LayoutRect RootFrameViewport::ScrollIntoView(const LayoutRect& rect_in_content, |
210 const ScrollAlignment& align_x, | 210 const ScrollAlignment& align_x, |
211 const ScrollAlignment& align_y, | 211 const ScrollAlignment& align_y, |
| 212 bool is_smooth, |
212 ScrollType scroll_type) { | 213 ScrollType scroll_type) { |
213 // We want to move the rect into the viewport that excludes the scrollbars so | 214 // We want to move the rect into the viewport that excludes the scrollbars so |
214 // we intersect the visual viewport with the scrollbar-excluded frameView | 215 // we intersect the visual viewport with the scrollbar-excluded frameView |
215 // content rect. However, we don't use visibleContentRect directly since it | 216 // content rect. However, we don't use visibleContentRect directly since it |
216 // floors the scroll offset. Instead, we use ScrollAnimatorBase::currentOffset | 217 // floors the scroll offset. Instead, we use ScrollAnimatorBase::currentOffset |
217 // and construct a LayoutRect from that. | 218 // and construct a LayoutRect from that. |
218 LayoutRect frame_rect_in_content = LayoutRect( | 219 LayoutRect frame_rect_in_content = LayoutRect( |
219 FloatPoint(LayoutViewport().GetScrollAnimator().CurrentOffset()), | 220 FloatPoint(LayoutViewport().GetScrollAnimator().CurrentOffset()), |
220 FloatSize(LayoutViewport().VisibleContentRect().Size())); | 221 FloatSize(LayoutViewport().VisibleContentRect().Size())); |
221 LayoutRect visual_rect_in_content = | 222 LayoutRect visual_rect_in_content = |
222 LayoutRect(FloatPoint(ScrollOffsetFromScrollAnimators()), | 223 LayoutRect(FloatPoint(ScrollOffsetFromScrollAnimators()), |
223 FloatSize(VisualViewport().VisibleContentRect().Size())); | 224 FloatSize(VisualViewport().VisibleContentRect().Size())); |
224 | 225 |
225 // Intersect layout and visual rects to exclude the scrollbar from the view | 226 // Intersect layout and visual rects to exclude the scrollbar from the view |
226 // rect. | 227 // rect. |
227 LayoutRect view_rect_in_content = | 228 LayoutRect view_rect_in_content = |
228 Intersection(visual_rect_in_content, frame_rect_in_content); | 229 Intersection(visual_rect_in_content, frame_rect_in_content); |
229 LayoutRect target_viewport = ScrollAlignment::GetRectToExpose( | 230 LayoutRect target_viewport = ScrollAlignment::GetRectToExpose( |
230 view_rect_in_content, rect_in_content, align_x, align_y); | 231 view_rect_in_content, rect_in_content, align_x, align_y); |
231 if (target_viewport != view_rect_in_content) { | 232 if (target_viewport != view_rect_in_content) { |
232 SetScrollOffset(ScrollOffset(target_viewport.X(), target_viewport.Y()), | 233 ScrollOffset target_offset(target_viewport.X(), target_viewport.Y()); |
233 scroll_type); | 234 if (is_smooth) { |
| 235 DCHECK(scroll_type == kProgrammaticScroll); |
| 236 GetSmoothScrollSequencer()->QueueAnimation(this, target_offset); |
| 237 } else { |
| 238 SetScrollOffset(target_offset, scroll_type); |
| 239 } |
234 } | 240 } |
235 | 241 |
236 // RootFrameViewport only changes the viewport relative to the document so we | 242 // RootFrameViewport only changes the viewport relative to the document so we |
237 // can't change the input rect's location relative to the document origin. | 243 // can't change the input rect's location relative to the document origin. |
238 return rect_in_content; | 244 return rect_in_content; |
239 } | 245 } |
240 | 246 |
241 void RootFrameViewport::UpdateScrollOffset(const ScrollOffset& offset, | 247 void RootFrameViewport::UpdateScrollOffset(const ScrollOffset& offset, |
242 ScrollType scroll_type) { | 248 ScrollType scroll_type) { |
243 DistributeScrollBetweenViewports(offset, scroll_type, kScrollBehaviorInstant, | 249 DistributeScrollBetweenViewports(offset, scroll_type, kScrollBehaviorInstant, |
(...skipping 18 matching lines...) Expand all Loading... |
262 return; | 268 return; |
263 | 269 |
264 ScrollableArea& primary = | 270 ScrollableArea& primary = |
265 scroll_first == kVisualViewport ? VisualViewport() : LayoutViewport(); | 271 scroll_first == kVisualViewport ? VisualViewport() : LayoutViewport(); |
266 ScrollableArea& secondary = | 272 ScrollableArea& secondary = |
267 scroll_first == kVisualViewport ? LayoutViewport() : VisualViewport(); | 273 scroll_first == kVisualViewport ? LayoutViewport() : VisualViewport(); |
268 | 274 |
269 ScrollOffset target_offset = primary.ClampScrollOffset( | 275 ScrollOffset target_offset = primary.ClampScrollOffset( |
270 primary.GetScrollAnimator().CurrentOffset() + delta); | 276 primary.GetScrollAnimator().CurrentOffset() + delta); |
271 | 277 |
| 278 // DistributeScrollBetweenViewports can be called from SetScrollOffset, |
| 279 // so we assume that aborting sequenced smooth scrolls has been handled. |
| 280 // It can also be called from inside an animation to set the offset in |
| 281 // each frame. In that case, we shouldn't abort sequenced smooth scrolls. |
272 primary.SetScrollOffset(target_offset, scroll_type, behavior); | 282 primary.SetScrollOffset(target_offset, scroll_type, behavior); |
273 | 283 |
274 // Scroll the secondary viewport if all of the scroll was not applied to the | 284 // Scroll the secondary viewport if all of the scroll was not applied to the |
275 // primary viewport. | 285 // primary viewport. |
276 ScrollOffset updated_offset = | 286 ScrollOffset updated_offset = |
277 secondary.GetScrollAnimator().CurrentOffset() + FloatSize(target_offset); | 287 secondary.GetScrollAnimator().CurrentOffset() + FloatSize(target_offset); |
278 ScrollOffset applied = updated_offset - old_offset; | 288 ScrollOffset applied = updated_offset - old_offset; |
279 delta -= applied; | 289 delta -= applied; |
280 | 290 |
281 if (delta.IsZero()) | 291 if (delta.IsZero()) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 : 0); | 403 : 0); |
394 | 404 |
395 // If there won't be any scrolling, bail early so we don't produce any side | 405 // If there won't be any scrolling, bail early so we don't produce any side |
396 // effects like cancelling existing animations. | 406 // effects like cancelling existing animations. |
397 if (visual_consumed_delta.IsZero() && scrollable_axis_delta.IsZero()) { | 407 if (visual_consumed_delta.IsZero() && scrollable_axis_delta.IsZero()) { |
398 return ScrollResult(false, false, pixel_delta.Width(), | 408 return ScrollResult(false, false, pixel_delta.Width(), |
399 pixel_delta.Height()); | 409 pixel_delta.Height()); |
400 } | 410 } |
401 | 411 |
402 CancelProgrammaticScrollAnimation(); | 412 CancelProgrammaticScrollAnimation(); |
| 413 if (SmoothScrollSequencer* sequencer = GetSmoothScrollSequencer()) |
| 414 sequencer->AbortAnimations(); |
403 | 415 |
404 // TODO(bokan): Why do we call userScroll on the animators directly and | 416 // TODO(bokan): Why do we call userScroll on the animators directly and |
405 // not through the ScrollableAreas? | 417 // not through the ScrollableAreas? |
406 ScrollResult visual_result = VisualViewport().GetScrollAnimator().UserScroll( | 418 ScrollResult visual_result = VisualViewport().GetScrollAnimator().UserScroll( |
407 granularity, visual_consumed_delta); | 419 granularity, visual_consumed_delta); |
408 | 420 |
409 if (visual_consumed_delta == pixel_delta) | 421 if (visual_consumed_delta == pixel_delta) |
410 return visual_result; | 422 return visual_result; |
411 | 423 |
412 ScrollResult layout_result = LayoutViewport().GetScrollAnimator().UserScroll( | 424 ScrollResult layout_result = LayoutViewport().GetScrollAnimator().UserScroll( |
(...skipping 11 matching lines...) Expand all Loading... |
424 } | 436 } |
425 | 437 |
426 bool RootFrameViewport::ScrollAnimatorEnabled() const { | 438 bool RootFrameViewport::ScrollAnimatorEnabled() const { |
427 return LayoutViewport().ScrollAnimatorEnabled(); | 439 return LayoutViewport().ScrollAnimatorEnabled(); |
428 } | 440 } |
429 | 441 |
430 PlatformChromeClient* RootFrameViewport::GetChromeClient() const { | 442 PlatformChromeClient* RootFrameViewport::GetChromeClient() const { |
431 return LayoutViewport().GetChromeClient(); | 443 return LayoutViewport().GetChromeClient(); |
432 } | 444 } |
433 | 445 |
| 446 SmoothScrollSequencer* RootFrameViewport::GetSmoothScrollSequencer() const { |
| 447 return LayoutViewport().GetSmoothScrollSequencer(); |
| 448 } |
| 449 |
434 void RootFrameViewport::ServiceScrollAnimations(double monotonic_time) { | 450 void RootFrameViewport::ServiceScrollAnimations(double monotonic_time) { |
435 ScrollableArea::ServiceScrollAnimations(monotonic_time); | 451 ScrollableArea::ServiceScrollAnimations(monotonic_time); |
436 LayoutViewport().ServiceScrollAnimations(monotonic_time); | 452 LayoutViewport().ServiceScrollAnimations(monotonic_time); |
437 VisualViewport().ServiceScrollAnimations(monotonic_time); | 453 VisualViewport().ServiceScrollAnimations(monotonic_time); |
438 } | 454 } |
439 | 455 |
440 void RootFrameViewport::UpdateCompositorScrollAnimations() { | 456 void RootFrameViewport::UpdateCompositorScrollAnimations() { |
441 ScrollableArea::UpdateCompositorScrollAnimations(); | 457 ScrollableArea::UpdateCompositorScrollAnimations(); |
442 LayoutViewport().UpdateCompositorScrollAnimations(); | 458 LayoutViewport().UpdateCompositorScrollAnimations(); |
443 VisualViewport().UpdateCompositorScrollAnimations(); | 459 VisualViewport().UpdateCompositorScrollAnimations(); |
(...skipping 11 matching lines...) Expand all Loading... |
455 VisualViewport().ClearScrollableArea(); | 471 VisualViewport().ClearScrollableArea(); |
456 } | 472 } |
457 | 473 |
458 DEFINE_TRACE(RootFrameViewport) { | 474 DEFINE_TRACE(RootFrameViewport) { |
459 visitor->Trace(visual_viewport_); | 475 visitor->Trace(visual_viewport_); |
460 visitor->Trace(layout_viewport_); | 476 visitor->Trace(layout_viewport_); |
461 ScrollableArea::Trace(visitor); | 477 ScrollableArea::Trace(visitor); |
462 } | 478 } |
463 | 479 |
464 } // namespace blink | 480 } // namespace blink |
OLD | NEW |