| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 scrollPositionDouble(), | 113 scrollPositionDouble(), |
| 114 visualViewport().visibleContentRectDouble(scrollbarInclusion).size()); | 114 visualViewport().visibleContentRectDouble(scrollbarInclusion).size()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 IntRect RootFrameViewport::visibleContentRect( | 117 IntRect RootFrameViewport::visibleContentRect( |
| 118 IncludeScrollbarsInRect scrollbarInclusion) const { | 118 IncludeScrollbarsInRect scrollbarInclusion) const { |
| 119 return enclosingIntRect(visibleContentRectDouble(scrollbarInclusion)); | 119 return enclosingIntRect(visibleContentRectDouble(scrollbarInclusion)); |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool RootFrameViewport::shouldUseIntegerScrollOffset() const { | 122 bool RootFrameViewport::shouldUseIntegerScrollOffset() const { |
| 123 // Fractionals are floored in the ScrollAnimatorBase but it's important that t
he ScrollAnimators of the | 123 // Fractionals are floored in the ScrollAnimatorBase but it's important that |
| 124 // visual and layout viewports get the precise fractional number so never use
integer scrolling for | 124 // the ScrollAnimators of the visual and layout viewports get the precise |
| 125 // RootFrameViewport, we'll let the truncation happen in the subviewports. | 125 // fractional number so never use integer scrolling for RootFrameViewport, |
| 126 // we'll let the truncation happen in the subviewports. |
| 126 return false; | 127 return false; |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool RootFrameViewport::isActive() const { | 130 bool RootFrameViewport::isActive() const { |
| 130 return layoutViewport().isActive(); | 131 return layoutViewport().isActive(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 int RootFrameViewport::scrollSize(ScrollbarOrientation orientation) const { | 134 int RootFrameViewport::scrollSize(ScrollbarOrientation orientation) const { |
| 134 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition(); | 135 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition(); |
| 135 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() | 136 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 175 } |
| 175 | 176 |
| 176 ScrollBehavior RootFrameViewport::scrollBehaviorStyle() const { | 177 ScrollBehavior RootFrameViewport::scrollBehaviorStyle() const { |
| 177 return layoutViewport().scrollBehaviorStyle(); | 178 return layoutViewport().scrollBehaviorStyle(); |
| 178 } | 179 } |
| 179 | 180 |
| 180 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, | 181 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, |
| 181 const ScrollAlignment& alignX, | 182 const ScrollAlignment& alignX, |
| 182 const ScrollAlignment& alignY, | 183 const ScrollAlignment& alignY, |
| 183 ScrollType scrollType) { | 184 ScrollType scrollType) { |
| 184 // We want to move the rect into the viewport that excludes the scrollbars so
we intersect | 185 // We want to move the rect into the viewport that excludes the scrollbars so |
| 185 // the visual viewport with the scrollbar-excluded frameView content rect. How
ever, we don't | 186 // we intersect the visual viewport with the scrollbar-excluded frameView |
| 186 // use visibleContentRect directly since it floors the scroll position. Instea
d, we use | 187 // content rect. However, we don't use visibleContentRect directly since it |
| 188 // floors the scroll position. Instead, we use |
| 187 // ScrollAnimatorBase::currentPosition and construct a LayoutRect from that. | 189 // ScrollAnimatorBase::currentPosition and construct a LayoutRect from that. |
| 188 | 190 |
| 189 LayoutRect frameRectInContent = | 191 LayoutRect frameRectInContent = |
| 190 LayoutRect(layoutViewport().scrollAnimator().currentPosition(), | 192 LayoutRect(layoutViewport().scrollAnimator().currentPosition(), |
| 191 layoutViewport().visibleContentRect().size()); | 193 layoutViewport().visibleContentRect().size()); |
| 192 LayoutRect visualRectInContent = | 194 LayoutRect visualRectInContent = |
| 193 LayoutRect(scrollOffsetFromScrollAnimators(), | 195 LayoutRect(scrollOffsetFromScrollAnimators(), |
| 194 visualViewport().visibleContentRect().size()); | 196 visualViewport().visibleContentRect().size()); |
| 195 | 197 |
| 196 // Intersect layout and visual rects to exclude the scrollbar from the view re
ct. | 198 // Intersect layout and visual rects to exclude the scrollbar from the view |
| 199 // rect. |
| 197 LayoutRect viewRectInContent = | 200 LayoutRect viewRectInContent = |
| 198 intersection(visualRectInContent, frameRectInContent); | 201 intersection(visualRectInContent, frameRectInContent); |
| 199 LayoutRect targetViewport = ScrollAlignment::getRectToExpose( | 202 LayoutRect targetViewport = ScrollAlignment::getRectToExpose( |
| 200 viewRectInContent, rectInContent, alignX, alignY); | 203 viewRectInContent, rectInContent, alignX, alignY); |
| 201 if (targetViewport != viewRectInContent) | 204 if (targetViewport != viewRectInContent) |
| 202 setScrollPosition(DoublePoint(targetViewport.x(), targetViewport.y()), | 205 setScrollPosition(DoublePoint(targetViewport.x(), targetViewport.y()), |
| 203 scrollType); | 206 scrollType); |
| 204 | 207 |
| 205 // RootFrameViewport only changes the viewport relative to the document so we
can't change the input | 208 // RootFrameViewport only changes the viewport relative to the document so we |
| 206 // rect's location relative to the document origin. | 209 // can't change the input rect's location relative to the document origin. |
| 207 return rectInContent; | 210 return rectInContent; |
| 208 } | 211 } |
| 209 | 212 |
| 210 void RootFrameViewport::setScrollOffset(const DoublePoint& offset, | 213 void RootFrameViewport::setScrollOffset(const DoublePoint& offset, |
| 211 ScrollType scrollType) { | 214 ScrollType scrollType) { |
| 212 distributeScrollBetweenViewports(DoublePoint(offset), scrollType, | 215 distributeScrollBetweenViewports(DoublePoint(offset), scrollType, |
| 213 ScrollBehaviorInstant, VisualViewport); | 216 ScrollBehaviorInstant, VisualViewport); |
| 214 } | 217 } |
| 215 | 218 |
| 216 void RootFrameViewport::distributeScrollBetweenViewports( | 219 void RootFrameViewport::distributeScrollBetweenViewports( |
| 217 const DoublePoint& offset, | 220 const DoublePoint& offset, |
| 218 ScrollType scrollType, | 221 ScrollType scrollType, |
| 219 ScrollBehavior behavior, | 222 ScrollBehavior behavior, |
| 220 ViewportToScrollFirst scrollFirst) { | 223 ViewportToScrollFirst scrollFirst) { |
| 221 // Make sure we use the scroll positions as reported by each viewport's Scroll
AnimatorBase, since its | 224 // Make sure we use the scroll positions as reported by each viewport's |
| 222 // ScrollableArea's position may have the fractional part truncated off. | 225 // ScrollAnimatorBase, since its ScrollableArea's position may have the |
| 226 // fractional part truncated off. |
| 223 DoublePoint oldPosition = scrollOffsetFromScrollAnimators(); | 227 DoublePoint oldPosition = scrollOffsetFromScrollAnimators(); |
| 224 | 228 |
| 225 DoubleSize delta = offset - oldPosition; | 229 DoubleSize delta = offset - oldPosition; |
| 226 | 230 |
| 227 if (delta.isZero()) | 231 if (delta.isZero()) |
| 228 return; | 232 return; |
| 229 | 233 |
| 230 ScrollableArea& primary = | 234 ScrollableArea& primary = |
| 231 scrollFirst == VisualViewport ? visualViewport() : layoutViewport(); | 235 scrollFirst == VisualViewport ? visualViewport() : layoutViewport(); |
| 232 ScrollableArea& secondary = | 236 ScrollableArea& secondary = |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 visualViewport().clearScrollAnimators(); | 428 visualViewport().clearScrollAnimators(); |
| 425 } | 429 } |
| 426 | 430 |
| 427 DEFINE_TRACE(RootFrameViewport) { | 431 DEFINE_TRACE(RootFrameViewport) { |
| 428 visitor->trace(m_visualViewport); | 432 visitor->trace(m_visualViewport); |
| 429 visitor->trace(m_layoutViewport); | 433 visitor->trace(m_layoutViewport); |
| 430 ScrollableArea::trace(visitor); | 434 ScrollableArea::trace(visitor); |
| 431 } | 435 } |
| 432 | 436 |
| 433 } // namespace blink | 437 } // namespace blink |
| OLD | NEW |