| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/frame/RootFrameViewport.h" | 6 #include "core/frame/RootFrameViewport.h" |
| 7 | 7 |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/layout/ScrollAlignment.h" | 9 #include "core/layout/ScrollAlignment.h" |
| 10 #include "platform/geometry/DoubleRect.h" | 10 #include "platform/geometry/DoubleRect.h" |
| 11 #include "platform/geometry/FloatRect.h" | 11 #include "platform/geometry/FloatRect.h" |
| 12 #include "platform/geometry/LayoutRect.h" | 12 #include "platform/geometry/LayoutRect.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 RootFrameViewport::RootFrameViewport(ScrollableArea& visualViewport, ScrollableA
rea& layoutViewport, bool invertScrollOrder) | 16 RootFrameViewport::RootFrameViewport(ScrollableArea& visualViewport, ScrollableA
rea& layoutViewport, bool invertScrollOrder) |
| 17 : m_visualViewport(visualViewport) | 17 : m_visualViewport(visualViewport) |
| 18 , m_layoutViewport(layoutViewport) | 18 , m_layoutViewport(layoutViewport) |
| 19 , m_invertScrollOrder(invertScrollOrder) | 19 , m_invertScrollOrder(invertScrollOrder) |
| 20 { | 20 { |
| 21 } | 21 } |
| 22 | 22 |
| 23 void RootFrameViewport::updateScrollAnimator() | 23 void RootFrameViewport::updateScrollAnimator() |
| 24 { | 24 { |
| 25 scrollAnimator()->setCurrentPosition(toFloatPoint(scrollOffsetFromScrollAnim
ators())); | 25 scrollAnimator().setCurrentPosition(toFloatPoint(scrollOffsetFromScrollAnima
tors())); |
| 26 } | 26 } |
| 27 | 27 |
| 28 DoublePoint RootFrameViewport::scrollOffsetFromScrollAnimators() const | 28 DoublePoint RootFrameViewport::scrollOffsetFromScrollAnimators() const |
| 29 { | 29 { |
| 30 return visualViewport().scrollAnimator()->currentPosition() + layoutViewport
().scrollAnimator()->currentPosition(); | 30 return visualViewport().scrollAnimator().currentPosition() + layoutViewport(
).scrollAnimator().currentPosition(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 DoubleRect RootFrameViewport::visibleContentRectDouble(IncludeScrollbarsInRect s
crollbarInclusion) const | 33 DoubleRect RootFrameViewport::visibleContentRectDouble(IncludeScrollbarsInRect s
crollbarInclusion) const |
| 34 { | 34 { |
| 35 return DoubleRect(scrollPositionDouble(), visualViewport().visibleContentRec
tDouble(scrollbarInclusion).size()); | 35 return DoubleRect(scrollPositionDouble(), visualViewport().visibleContentRec
tDouble(scrollbarInclusion).size()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 IntRect RootFrameViewport::visibleContentRect(IncludeScrollbarsInRect scrollbarI
nclusion) const | 38 IntRect RootFrameViewport::visibleContentRect(IncludeScrollbarsInRect scrollbarI
nclusion) const |
| 39 { | 39 { |
| 40 return enclosingIntRect(visibleContentRectDouble(scrollbarInclusion)); | 40 return enclosingIntRect(visibleContentRectDouble(scrollbarInclusion)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 | 95 |
| 96 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, co
nst ScrollAlignment& alignX, const ScrollAlignment& alignY, ScrollType scrollTyp
e) | 96 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, co
nst ScrollAlignment& alignX, const ScrollAlignment& alignY, ScrollType scrollTyp
e) |
| 97 { | 97 { |
| 98 // We want to move the rect into the viewport that excludes the scrollbars s
o we intersect | 98 // We want to move the rect into the viewport that excludes the scrollbars s
o we intersect |
| 99 // the visual viewport with the scrollbar-excluded frameView content rect. H
owever, we don't | 99 // the visual viewport with the scrollbar-excluded frameView content rect. H
owever, we don't |
| 100 // use visibleContentRect directly since it floors the scroll position. Inst
ead, we use | 100 // use visibleContentRect directly since it floors the scroll position. Inst
ead, we use |
| 101 // ScrollAnimatorBase::currentPosition and construct a LayoutRect from that. | 101 // ScrollAnimatorBase::currentPosition and construct a LayoutRect from that. |
| 102 | 102 |
| 103 LayoutRect frameRectInContent = LayoutRect( | 103 LayoutRect frameRectInContent = LayoutRect( |
| 104 layoutViewport().scrollAnimator()->currentPosition(), | 104 layoutViewport().scrollAnimator().currentPosition(), |
| 105 layoutViewport().visibleContentRect().size()); | 105 layoutViewport().visibleContentRect().size()); |
| 106 LayoutRect visualRectInContent = LayoutRect( | 106 LayoutRect visualRectInContent = LayoutRect( |
| 107 scrollOffsetFromScrollAnimators(), | 107 scrollOffsetFromScrollAnimators(), |
| 108 visualViewport().visibleContentRect().size()); | 108 visualViewport().visibleContentRect().size()); |
| 109 | 109 |
| 110 // Intersect layout and visual rects to exclude the scrollbar from the view
rect. | 110 // Intersect layout and visual rects to exclude the scrollbar from the view
rect. |
| 111 LayoutRect viewRectInContent = intersection(visualRectInContent, frameRectIn
Content); | 111 LayoutRect viewRectInContent = intersection(visualRectInContent, frameRectIn
Content); |
| 112 LayoutRect targetViewport = | 112 LayoutRect targetViewport = |
| 113 ScrollAlignment::getRectToExpose(viewRectInContent, rectInContent, align
X, alignY); | 113 ScrollAlignment::getRectToExpose(viewRectInContent, rectInContent, align
X, alignY); |
| 114 DoublePoint targetOffset(targetViewport.x(), targetViewport.y()); | 114 DoublePoint targetOffset(targetViewport.x(), targetViewport.y()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 137 DoublePoint oldPosition = scrollOffsetFromScrollAnimators(); | 137 DoublePoint oldPosition = scrollOffsetFromScrollAnimators(); |
| 138 | 138 |
| 139 DoubleSize delta = offset - oldPosition; | 139 DoubleSize delta = offset - oldPosition; |
| 140 | 140 |
| 141 if (delta.isZero()) | 141 if (delta.isZero()) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 ScrollableArea& primary = !m_invertScrollOrder ? layoutViewport() : visualVi
ewport(); | 144 ScrollableArea& primary = !m_invertScrollOrder ? layoutViewport() : visualVi
ewport(); |
| 145 ScrollableArea& secondary = !m_invertScrollOrder ? visualViewport() : layout
Viewport(); | 145 ScrollableArea& secondary = !m_invertScrollOrder ? visualViewport() : layout
Viewport(); |
| 146 | 146 |
| 147 DoublePoint targetPosition = primary.clampScrollPosition(primary.scrollAnima
tor()->currentPosition() + delta); | 147 DoublePoint targetPosition = primary.clampScrollPosition(primary.scrollAnima
tor().currentPosition() + delta); |
| 148 primary.setScrollPosition(targetPosition, scrollType, behavior); | 148 primary.setScrollPosition(targetPosition, scrollType, behavior); |
| 149 | 149 |
| 150 // Scroll the secondary viewport if all of the scroll was not applied to the | 150 // Scroll the secondary viewport if all of the scroll was not applied to the |
| 151 // primary viewport. | 151 // primary viewport. |
| 152 DoublePoint updatedPosition = secondary.scrollAnimator()->currentPosition()
+ FloatPoint(targetPosition); | 152 DoublePoint updatedPosition = secondary.scrollAnimator().currentPosition() +
FloatPoint(targetPosition); |
| 153 DoubleSize applied = updatedPosition - oldPosition; | 153 DoubleSize applied = updatedPosition - oldPosition; |
| 154 delta -= applied; | 154 delta -= applied; |
| 155 | 155 |
| 156 if (delta.isZero()) | 156 if (delta.isZero()) |
| 157 return; | 157 return; |
| 158 | 158 |
| 159 targetPosition = secondary.clampScrollPosition(secondary.scrollAnimator()->c
urrentPosition() + delta); | 159 targetPosition = secondary.clampScrollPosition(secondary.scrollAnimator().cu
rrentPosition() + delta); |
| 160 secondary.setScrollPosition(targetPosition, scrollType, behavior); | 160 secondary.setScrollPosition(targetPosition, scrollType, behavior); |
| 161 } | 161 } |
| 162 | 162 |
| 163 IntPoint RootFrameViewport::scrollPosition() const | 163 IntPoint RootFrameViewport::scrollPosition() const |
| 164 { | 164 { |
| 165 return flooredIntPoint(scrollPositionDouble()); | 165 return flooredIntPoint(scrollPositionDouble()); |
| 166 } | 166 } |
| 167 | 167 |
| 168 DoublePoint RootFrameViewport::scrollPositionDouble() const | 168 DoublePoint RootFrameViewport::scrollPositionDouble() const |
| 169 { | 169 { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 283 } |
| 284 | 284 |
| 285 DEFINE_TRACE(RootFrameViewport) | 285 DEFINE_TRACE(RootFrameViewport) |
| 286 { | 286 { |
| 287 visitor->trace(m_visualViewport); | 287 visitor->trace(m_visualViewport); |
| 288 visitor->trace(m_layoutViewport); | 288 visitor->trace(m_layoutViewport); |
| 289 ScrollableArea::trace(visitor); | 289 ScrollableArea::trace(visitor); |
| 290 } | 290 } |
| 291 | 291 |
| 292 } // namespace blink | 292 } // namespace blink |
| OLD | NEW |