Chromium Code Reviews| 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(clampedOffset, scrollType, scrollBehavior); | 202 ScrollableArea::setScrollOffset(clampedOffset, scrollType, scrollBehavior); |
| 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& rectInContent, | 209 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, |
| 210 const ScrollAlignment& alignX, | 210 const ScrollAlignment& alignX, |
| 211 const ScrollAlignment& alignY, | 211 const ScrollAlignment& alignY, |
| 212 ScrollType scrollType) { | 212 ScrollType scrollType, |
| 213 ScrollBehavior scrollBehavior) { | |
| 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 frameRectInContent = | 219 LayoutRect frameRectInContent = |
| 219 LayoutRect(FloatPoint(layoutViewport().scrollAnimator().currentOffset()), | 220 LayoutRect(FloatPoint(layoutViewport().scrollAnimator().currentOffset()), |
| 220 FloatSize(layoutViewport().visibleContentRect().size())); | 221 FloatSize(layoutViewport().visibleContentRect().size())); |
| 221 LayoutRect visualRectInContent = | 222 LayoutRect visualRectInContent = |
| 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 viewRectInContent = | 228 LayoutRect viewRectInContent = |
| 228 intersection(visualRectInContent, frameRectInContent); | 229 intersection(visualRectInContent, frameRectInContent); |
| 229 LayoutRect targetViewport = ScrollAlignment::getRectToExpose( | 230 LayoutRect targetViewport = ScrollAlignment::getRectToExpose( |
| 230 viewRectInContent, rectInContent, alignX, alignY); | 231 viewRectInContent, rectInContent, alignX, alignY); |
| 231 if (targetViewport != viewRectInContent) { | 232 if (targetViewport != viewRectInContent) { |
| 232 setScrollOffset(ScrollOffset(targetViewport.x(), targetViewport.y()), | 233 if (scrollType == ProgrammaticScroll && |
|
bokan
2017/02/02 22:51:50
Ditto here for DCHECK
sunyunjia
2017/02/10 23:25:20
Done.
| |
| 233 scrollType); | 234 scrollBehavior == ScrollBehaviorSmooth) { |
| 235 getProgrammaticScrollCoordinator()->queueAnimation( | |
| 236 this, ScrollOffset(targetViewport.x(), targetViewport.y())); | |
| 237 } else { | |
| 238 setScrollOffset(ScrollOffset(targetViewport.x(), targetViewport.y()), | |
| 239 scrollType); | |
| 240 } | |
| 234 } | 241 } |
| 235 | 242 |
| 236 // RootFrameViewport only changes the viewport relative to the document so we | 243 // 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. | 244 // can't change the input rect's location relative to the document origin. |
| 238 return rectInContent; | 245 return rectInContent; |
| 239 } | 246 } |
| 240 | 247 |
| 241 void RootFrameViewport::updateScrollOffset(const ScrollOffset& offset, | 248 void RootFrameViewport::updateScrollOffset(const ScrollOffset& offset, |
| 242 ScrollType scrollType) { | 249 ScrollType scrollType) { |
| 243 distributeScrollBetweenViewports(offset, scrollType, ScrollBehaviorInstant, | 250 distributeScrollBetweenViewports(offset, scrollType, ScrollBehaviorInstant, |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 } | 430 } |
| 424 | 431 |
| 425 bool RootFrameViewport::scrollAnimatorEnabled() const { | 432 bool RootFrameViewport::scrollAnimatorEnabled() const { |
| 426 return layoutViewport().scrollAnimatorEnabled(); | 433 return layoutViewport().scrollAnimatorEnabled(); |
| 427 } | 434 } |
| 428 | 435 |
| 429 HostWindow* RootFrameViewport::getHostWindow() const { | 436 HostWindow* RootFrameViewport::getHostWindow() const { |
| 430 return layoutViewport().getHostWindow(); | 437 return layoutViewport().getHostWindow(); |
| 431 } | 438 } |
| 432 | 439 |
| 440 ProgrammaticScrollCoordinator* | |
| 441 RootFrameViewport::getProgrammaticScrollCoordinator() const { | |
| 442 return layoutViewport().getProgrammaticScrollCoordinator(); | |
| 443 } | |
| 444 | |
| 433 void RootFrameViewport::serviceScrollAnimations(double monotonicTime) { | 445 void RootFrameViewport::serviceScrollAnimations(double monotonicTime) { |
| 434 ScrollableArea::serviceScrollAnimations(monotonicTime); | 446 ScrollableArea::serviceScrollAnimations(monotonicTime); |
| 435 layoutViewport().serviceScrollAnimations(monotonicTime); | 447 layoutViewport().serviceScrollAnimations(monotonicTime); |
| 436 visualViewport().serviceScrollAnimations(monotonicTime); | 448 visualViewport().serviceScrollAnimations(monotonicTime); |
| 437 } | 449 } |
| 438 | 450 |
| 439 void RootFrameViewport::updateCompositorScrollAnimations() { | 451 void RootFrameViewport::updateCompositorScrollAnimations() { |
| 440 ScrollableArea::updateCompositorScrollAnimations(); | 452 ScrollableArea::updateCompositorScrollAnimations(); |
| 441 layoutViewport().updateCompositorScrollAnimations(); | 453 layoutViewport().updateCompositorScrollAnimations(); |
| 442 visualViewport().updateCompositorScrollAnimations(); | 454 visualViewport().updateCompositorScrollAnimations(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 458 visualViewport().clearScrollableArea(); | 470 visualViewport().clearScrollableArea(); |
| 459 } | 471 } |
| 460 | 472 |
| 461 DEFINE_TRACE(RootFrameViewport) { | 473 DEFINE_TRACE(RootFrameViewport) { |
| 462 visitor->trace(m_visualViewport); | 474 visitor->trace(m_visualViewport); |
| 463 visitor->trace(m_layoutViewport); | 475 visitor->trace(m_layoutViewport); |
| 464 ScrollableArea::trace(visitor); | 476 ScrollableArea::trace(visitor); |
| 465 } | 477 } |
| 466 | 478 |
| 467 } // namespace blink | 479 } // namespace blink |
| OLD | NEW |