| 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, | |
| 213 ScrollType scroll_type) { | 212 ScrollType scroll_type) { |
| 214 // We want to move the rect into the viewport that excludes the scrollbars so | 213 // We want to move the rect into the viewport that excludes the scrollbars so |
| 215 // we intersect the visual viewport with the scrollbar-excluded frameView | 214 // we intersect the visual viewport with the scrollbar-excluded frameView |
| 216 // content rect. However, we don't use visibleContentRect directly since it | 215 // content rect. However, we don't use visibleContentRect directly since it |
| 217 // floors the scroll offset. Instead, we use ScrollAnimatorBase::currentOffset | 216 // floors the scroll offset. Instead, we use ScrollAnimatorBase::currentOffset |
| 218 // and construct a LayoutRect from that. | 217 // and construct a LayoutRect from that. |
| 219 LayoutRect frame_rect_in_content = LayoutRect( | 218 LayoutRect frame_rect_in_content = LayoutRect( |
| 220 FloatPoint(LayoutViewport().GetScrollAnimator().CurrentOffset()), | 219 FloatPoint(LayoutViewport().GetScrollAnimator().CurrentOffset()), |
| 221 FloatSize(LayoutViewport().VisibleContentRect().Size())); | 220 FloatSize(LayoutViewport().VisibleContentRect().Size())); |
| 222 LayoutRect visual_rect_in_content = | 221 LayoutRect visual_rect_in_content = |
| 223 LayoutRect(FloatPoint(ScrollOffsetFromScrollAnimators()), | 222 LayoutRect(FloatPoint(ScrollOffsetFromScrollAnimators()), |
| 224 FloatSize(VisualViewport().VisibleContentRect().Size())); | 223 FloatSize(VisualViewport().VisibleContentRect().Size())); |
| 225 | 224 |
| 226 // Intersect layout and visual rects to exclude the scrollbar from the view | 225 // Intersect layout and visual rects to exclude the scrollbar from the view |
| 227 // rect. | 226 // rect. |
| 228 LayoutRect view_rect_in_content = | 227 LayoutRect view_rect_in_content = |
| 229 Intersection(visual_rect_in_content, frame_rect_in_content); | 228 Intersection(visual_rect_in_content, frame_rect_in_content); |
| 230 LayoutRect target_viewport = ScrollAlignment::GetRectToExpose( | 229 LayoutRect target_viewport = ScrollAlignment::GetRectToExpose( |
| 231 view_rect_in_content, rect_in_content, align_x, align_y); | 230 view_rect_in_content, rect_in_content, align_x, align_y); |
| 232 if (target_viewport != view_rect_in_content) { | 231 if (target_viewport != view_rect_in_content) { |
| 233 ScrollOffset target_offset(target_viewport.X(), target_viewport.Y()); | 232 SetScrollOffset(ScrollOffset(target_viewport.X(), target_viewport.Y()), |
| 234 if (is_smooth) { | 233 scroll_type); |
| 235 DCHECK(scroll_type == kProgrammaticScroll); | |
| 236 GetSmoothScrollSequencer()->QueueAnimation(this, target_offset); | |
| 237 } else { | |
| 238 SetScrollOffset(target_offset, scroll_type); | |
| 239 } | |
| 240 } | 234 } |
| 241 | 235 |
| 242 // RootFrameViewport only changes the viewport relative to the document so we | 236 // RootFrameViewport only changes the viewport relative to the document so we |
| 243 // can't change the input rect's location relative to the document origin. | 237 // can't change the input rect's location relative to the document origin. |
| 244 return rect_in_content; | 238 return rect_in_content; |
| 245 } | 239 } |
| 246 | 240 |
| 247 void RootFrameViewport::UpdateScrollOffset(const ScrollOffset& offset, | 241 void RootFrameViewport::UpdateScrollOffset(const ScrollOffset& offset, |
| 248 ScrollType scroll_type) { | 242 ScrollType scroll_type) { |
| 249 DistributeScrollBetweenViewports(offset, scroll_type, kScrollBehaviorInstant, | 243 DistributeScrollBetweenViewports(offset, scroll_type, kScrollBehaviorInstant, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 424 } |
| 431 | 425 |
| 432 bool RootFrameViewport::ScrollAnimatorEnabled() const { | 426 bool RootFrameViewport::ScrollAnimatorEnabled() const { |
| 433 return LayoutViewport().ScrollAnimatorEnabled(); | 427 return LayoutViewport().ScrollAnimatorEnabled(); |
| 434 } | 428 } |
| 435 | 429 |
| 436 PlatformChromeClient* RootFrameViewport::GetChromeClient() const { | 430 PlatformChromeClient* RootFrameViewport::GetChromeClient() const { |
| 437 return LayoutViewport().GetChromeClient(); | 431 return LayoutViewport().GetChromeClient(); |
| 438 } | 432 } |
| 439 | 433 |
| 440 SmoothScrollSequencer* RootFrameViewport::GetSmoothScrollSequencer() const { | |
| 441 return LayoutViewport().GetSmoothScrollSequencer(); | |
| 442 } | |
| 443 | |
| 444 void RootFrameViewport::ServiceScrollAnimations(double monotonic_time) { | 434 void RootFrameViewport::ServiceScrollAnimations(double monotonic_time) { |
| 445 ScrollableArea::ServiceScrollAnimations(monotonic_time); | 435 ScrollableArea::ServiceScrollAnimations(monotonic_time); |
| 446 LayoutViewport().ServiceScrollAnimations(monotonic_time); | 436 LayoutViewport().ServiceScrollAnimations(monotonic_time); |
| 447 VisualViewport().ServiceScrollAnimations(monotonic_time); | 437 VisualViewport().ServiceScrollAnimations(monotonic_time); |
| 448 } | 438 } |
| 449 | 439 |
| 450 void RootFrameViewport::UpdateCompositorScrollAnimations() { | 440 void RootFrameViewport::UpdateCompositorScrollAnimations() { |
| 451 ScrollableArea::UpdateCompositorScrollAnimations(); | 441 ScrollableArea::UpdateCompositorScrollAnimations(); |
| 452 LayoutViewport().UpdateCompositorScrollAnimations(); | 442 LayoutViewport().UpdateCompositorScrollAnimations(); |
| 453 VisualViewport().UpdateCompositorScrollAnimations(); | 443 VisualViewport().UpdateCompositorScrollAnimations(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 465 VisualViewport().ClearScrollableArea(); | 455 VisualViewport().ClearScrollableArea(); |
| 466 } | 456 } |
| 467 | 457 |
| 468 DEFINE_TRACE(RootFrameViewport) { | 458 DEFINE_TRACE(RootFrameViewport) { |
| 469 visitor->Trace(visual_viewport_); | 459 visitor->Trace(visual_viewport_); |
| 470 visitor->Trace(layout_viewport_); | 460 visitor->Trace(layout_viewport_); |
| 471 ScrollableArea::Trace(visitor); | 461 ScrollableArea::Trace(visitor); |
| 472 } | 462 } |
| 473 | 463 |
| 474 } // namespace blink | 464 } // namespace blink |
| OLD | NEW |