| 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/FrameView.h" | 7 #include "core/frame/FrameView.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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 430 } |
| 425 | 431 |
| 426 bool RootFrameViewport::ScrollAnimatorEnabled() const { | 432 bool RootFrameViewport::ScrollAnimatorEnabled() const { |
| 427 return LayoutViewport().ScrollAnimatorEnabled(); | 433 return LayoutViewport().ScrollAnimatorEnabled(); |
| 428 } | 434 } |
| 429 | 435 |
| 430 PlatformChromeClient* RootFrameViewport::GetChromeClient() const { | 436 PlatformChromeClient* RootFrameViewport::GetChromeClient() const { |
| 431 return LayoutViewport().GetChromeClient(); | 437 return LayoutViewport().GetChromeClient(); |
| 432 } | 438 } |
| 433 | 439 |
| 440 bool RootFrameViewport::ScheduleAnimation() { |
| 441 return LayoutViewport().ScheduleAnimation(); |
| 442 } |
| 443 |
| 444 SmoothScrollSequencer* RootFrameViewport::GetSmoothScrollSequencer() const { |
| 445 return LayoutViewport().GetSmoothScrollSequencer(); |
| 446 } |
| 447 |
| 434 void RootFrameViewport::ServiceScrollAnimations(double monotonic_time) { | 448 void RootFrameViewport::ServiceScrollAnimations(double monotonic_time) { |
| 435 ScrollableArea::ServiceScrollAnimations(monotonic_time); | 449 ScrollableArea::ServiceScrollAnimations(monotonic_time); |
| 436 LayoutViewport().ServiceScrollAnimations(monotonic_time); | 450 LayoutViewport().ServiceScrollAnimations(monotonic_time); |
| 437 VisualViewport().ServiceScrollAnimations(monotonic_time); | 451 VisualViewport().ServiceScrollAnimations(monotonic_time); |
| 438 } | 452 } |
| 439 | 453 |
| 440 void RootFrameViewport::UpdateCompositorScrollAnimations() { | 454 void RootFrameViewport::UpdateCompositorScrollAnimations() { |
| 441 ScrollableArea::UpdateCompositorScrollAnimations(); | 455 ScrollableArea::UpdateCompositorScrollAnimations(); |
| 442 LayoutViewport().UpdateCompositorScrollAnimations(); | 456 LayoutViewport().UpdateCompositorScrollAnimations(); |
| 443 VisualViewport().UpdateCompositorScrollAnimations(); | 457 VisualViewport().UpdateCompositorScrollAnimations(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 455 VisualViewport().ClearScrollableArea(); | 469 VisualViewport().ClearScrollableArea(); |
| 456 } | 470 } |
| 457 | 471 |
| 458 DEFINE_TRACE(RootFrameViewport) { | 472 DEFINE_TRACE(RootFrameViewport) { |
| 459 visitor->Trace(visual_viewport_); | 473 visitor->Trace(visual_viewport_); |
| 460 visitor->Trace(layout_viewport_); | 474 visitor->Trace(layout_viewport_); |
| 461 ScrollableArea::Trace(visitor); | 475 ScrollableArea::Trace(visitor); |
| 462 } | 476 } |
| 463 | 477 |
| 464 } // namespace blink | 478 } // namespace blink |
| OLD | NEW |