Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: third_party/WebKit/Source/web/ResizeViewportAnchor.cpp

Issue 2184333002: Fix scroll anchoring during viewport resize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "web/ResizeViewportAnchor.h" 5 #include "web/ResizeViewportAnchor.h"
6 6
7 #include "core/frame/FrameHost.h"
7 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
8 #include "core/frame/VisualViewport.h" 9 #include "core/frame/VisualViewport.h"
10 #include "core/page/Page.h"
9 #include "platform/geometry/DoubleRect.h" 11 #include "platform/geometry/DoubleRect.h"
10 #include "platform/geometry/DoubleSize.h" 12 #include "platform/geometry/DoubleSize.h"
11 #include "platform/geometry/FloatSize.h" 13 #include "platform/geometry/FloatSize.h"
12 14
13 namespace blink { 15 namespace blink {
14 16
15 ResizeViewportAnchor::ResizeViewportAnchor(FrameView& rootFrameView, VisualViewp ort& visualViewport) 17 void ResizeViewportAnchor::resizeFrameView(IntSize size)
16 : ViewportAnchor(rootFrameView, visualViewport)
17 , m_visualViewportInDocument(rootFrameView.getScrollableArea()->scrollPositi onDouble())
18 { 18 {
19 FrameView* frameView = rootFrameView();
20 DCHECK(frameView);
21
22 ScrollableArea* rootViewport = frameView->getScrollableArea();
23 DoublePoint position = rootViewport->scrollPositionDouble();
24
25 frameView->resize(size);
bokan 2016/07/28 14:55:55 I was a little concerned about this at first since
skobes 2016/07/28 15:45:50 ScrollAnchor shouldn't actually be doing anything
26 m_drift += rootViewport->scrollPositionDouble() - position;
19 } 27 }
20 28
21 ResizeViewportAnchor::~ResizeViewportAnchor() 29 void ResizeViewportAnchor::endScope()
22 { 30 {
31 if (--m_scopeCount > 0)
32 return;
33
34 FrameView* frameView = rootFrameView();
35 if (!frameView)
36 return;
37
38 VisualViewport& visualViewport = m_page->frameHost().visualViewport();
39 DoublePoint visualViewportInDocument =
40 frameView->getScrollableArea()->scrollPositionDouble() - m_drift;
41
23 // TODO(bokan): Don't use RootFrameViewport::setScrollPosition since it 42 // TODO(bokan): Don't use RootFrameViewport::setScrollPosition since it
24 // assumes we can just set a sub-pixel precision offset on the FrameView. 43 // assumes we can just set a sub-pixel precision offset on the FrameView.
25 // While we "can" do this, the offset that will be shipped to CC will be the 44 // While we "can" do this, the offset that will be shipped to CC will be the
26 // truncated number and this class is used to handle TopControl movement 45 // truncated number and this class is used to handle TopControl movement
27 // which needs the two threads to match exactly pixel-for-pixel. We can 46 // which needs the two threads to match exactly pixel-for-pixel. We can
28 // replace this with RFV::setScrollPosition once Blink is sub-pixel scroll 47 // replace this with RFV::setScrollPosition once Blink is sub-pixel scroll
29 // offset aware. crbug.com/414283. 48 // offset aware. crbug.com/414283.
30 49
31 ScrollableArea* rootViewport = m_rootFrameView->getScrollableArea(); 50 ScrollableArea* rootViewport = frameView->getScrollableArea();
32 ScrollableArea* layoutViewport = 51 ScrollableArea* layoutViewport =
33 m_rootFrameView->layoutViewportScrollableArea(); 52 frameView->layoutViewportScrollableArea();
34 53
35 // Clamp the scroll offset of each viewport now so that we force any invalid 54 // Clamp the scroll offset of each viewport now so that we force any invalid
36 // offsets to become valid so we can compute the correct deltas. 55 // offsets to become valid so we can compute the correct deltas.
37 m_visualViewport->clampToBoundaries(); 56 visualViewport.clampToBoundaries();
38 layoutViewport->setScrollPosition( 57 layoutViewport->setScrollPosition(
39 layoutViewport->scrollPositionDouble(), ProgrammaticScroll); 58 layoutViewport->scrollPositionDouble(), ProgrammaticScroll);
40 59
41 DoubleSize delta = m_visualViewportInDocument 60 DoubleSize delta = visualViewportInDocument
42 - rootViewport->scrollPositionDouble(); 61 - rootViewport->scrollPositionDouble();
43 62
44 m_visualViewport->move(toFloatSize(delta)); 63 visualViewport.move(toFloatSize(delta));
45 64
46 delta = m_visualViewportInDocument 65 delta = visualViewportInDocument
47 - rootViewport->scrollPositionDouble(); 66 - rootViewport->scrollPositionDouble();
48 67
49 // Since the main thread FrameView has integer scroll offsets, scroll it to 68 // Since the main thread FrameView has integer scroll offsets, scroll it to
50 // the next pixel and then we'll scroll the visual viewport again to 69 // the next pixel and then we'll scroll the visual viewport again to
51 // compensate for the sub-pixel offset. We need this "overscroll" to ensure 70 // compensate for the sub-pixel offset. We need this "overscroll" to ensure
52 // the pixel of which we want to be partially in appears fully inside the 71 // the pixel of which we want to be partially in appears fully inside the
53 // FrameView since the VisualViewport is bounded by the FrameView. 72 // FrameView since the VisualViewport is bounded by the FrameView.
54 IntSize layoutDelta = IntSize( 73 IntSize layoutDelta = IntSize(
55 delta.width() < 0 ? floor(delta.width()) : ceil(delta.width()), 74 delta.width() < 0 ? floor(delta.width()) : ceil(delta.width()),
56 delta.height() < 0 ? floor(delta.height()) : ceil(delta.height())); 75 delta.height() < 0 ? floor(delta.height()) : ceil(delta.height()));
57 76
58 layoutViewport->setScrollPosition( 77 layoutViewport->setScrollPosition(
59 layoutViewport->scrollPosition() + layoutDelta, 78 layoutViewport->scrollPosition() + layoutDelta,
60 ProgrammaticScroll); 79 ProgrammaticScroll);
61 80
62 delta = m_visualViewportInDocument 81 delta = visualViewportInDocument
63 - rootViewport->scrollPositionDouble(); 82 - rootViewport->scrollPositionDouble();
64 m_visualViewport->move(toFloatSize(delta)); 83 visualViewport.move(toFloatSize(delta));
84 m_drift = DoubleSize();
85 }
86
87 FrameView* ResizeViewportAnchor::rootFrameView()
88 {
89 if (Frame* frame = m_page->mainFrame()) {
90 if (frame->isLocalFrame())
91 return toLocalFrame(frame)->view();
92 }
93 return nullptr;
65 } 94 }
66 95
67 } // namespace blink 96 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698