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 "platform/geometry/DoubleRect.h" | 9 #include "platform/geometry/DoubleRect.h" |
10 #include "platform/geometry/FloatRect.h" | 10 #include "platform/geometry/FloatRect.h" |
11 #include "platform/geometry/LayoutRect.h" | 11 #include "platform/geometry/LayoutRect.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 RootFrameViewport::RootFrameViewport(ScrollableArea& visualViewport, ScrollableA
rea& layoutViewport) | 15 RootFrameViewport::RootFrameViewport(ScrollableArea& visualViewport, ScrollableA
rea& layoutViewport) |
16 : m_visualViewport(visualViewport) | 16 : m_visualViewport(visualViewport) |
17 , m_layoutViewport(layoutViewport) | 17 , m_layoutViewport(layoutViewport) |
18 { | 18 { |
19 } | 19 } |
20 | 20 |
21 void RootFrameViewport::setLayoutViewport(ScrollableArea& newLayoutViewport) | 21 void RootFrameViewport::setLayoutViewport(ScrollableArea& newLayoutViewport) |
22 { | 22 { |
23 m_layoutViewport = &newLayoutViewport; | 23 m_layoutViewport = &newLayoutViewport; |
24 } | 24 } |
25 | 25 |
| 26 void RootFrameViewport::restoreToAnchor(const DoublePoint& targetPosition) |
| 27 { |
| 28 // Clamp the scroll offset of each viewport now so that we force any invalid |
| 29 // offsets to become valid so we can compute the correct deltas. |
| 30 visualViewport().setScrollPosition( |
| 31 visualViewport().scrollPositionDouble(), ProgrammaticScroll); |
| 32 layoutViewport().setScrollPosition( |
| 33 layoutViewport().scrollPositionDouble(), ProgrammaticScroll); |
| 34 |
| 35 DoubleSize delta = targetPosition - scrollPositionDouble(); |
| 36 |
| 37 visualViewport().setScrollPosition( |
| 38 visualViewport().scrollPositionDouble() + delta, ProgrammaticScroll); |
| 39 |
| 40 delta = targetPosition - scrollPositionDouble(); |
| 41 |
| 42 // Since the main thread FrameView has integer scroll offsets, scroll it to |
| 43 // the next pixel and then we'll scroll the visual viewport again to |
| 44 // compensate for the sub-pixel offset. We need this "overscroll" to ensure |
| 45 // the pixel of which we want to be partially in appears fully inside the |
| 46 // FrameView since the VisualViewport is bounded by the FrameView. |
| 47 IntSize layoutDelta = IntSize( |
| 48 delta.width() < 0 ? floor(delta.width()) : ceil(delta.width()), |
| 49 delta.height() < 0 ? floor(delta.height()) : ceil(delta.height())); |
| 50 |
| 51 layoutViewport().setScrollPosition( |
| 52 layoutViewport().scrollPosition() + layoutDelta, ProgrammaticScroll); |
| 53 |
| 54 delta = targetPosition - scrollPositionDouble(); |
| 55 visualViewport().setScrollPosition( |
| 56 visualViewport().scrollPositionDouble() + delta, ProgrammaticScroll); |
| 57 } |
| 58 |
26 LayoutBox* RootFrameViewport::layoutBox() const | 59 LayoutBox* RootFrameViewport::layoutBox() const |
27 { | 60 { |
28 return layoutViewport().layoutBox(); | 61 return layoutViewport().layoutBox(); |
29 } | 62 } |
30 | 63 |
31 void RootFrameViewport::updateScrollAnimator() | 64 void RootFrameViewport::updateScrollAnimator() |
32 { | 65 { |
33 scrollAnimator().setCurrentPosition(toFloatPoint(scrollOffsetFromScrollAnima
tors())); | 66 scrollAnimator().setCurrentPosition(toFloatPoint(scrollOffsetFromScrollAnima
tors())); |
34 } | 67 } |
35 | 68 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 } | 393 } |
361 | 394 |
362 DEFINE_TRACE(RootFrameViewport) | 395 DEFINE_TRACE(RootFrameViewport) |
363 { | 396 { |
364 visitor->trace(m_visualViewport); | 397 visitor->trace(m_visualViewport); |
365 visitor->trace(m_layoutViewport); | 398 visitor->trace(m_layoutViewport); |
366 ScrollableArea::trace(visitor); | 399 ScrollableArea::trace(visitor); |
367 } | 400 } |
368 | 401 |
369 } // namespace blink | 402 } // namespace blink |
OLD | NEW |