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

Side by Side Diff: third_party/WebKit/Source/core/layout/ScrollAnchor.cpp

Issue 1647793002: Use ScrollAnchor in FrameView and PaintLayerScrollableArea. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@anchor-skeleton
Patch Set: move save/restore from LayoutBlockFlow into LayoutBlock Created 4 years, 10 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 "core/layout/ScrollAnchor.h" 5 #include "core/layout/ScrollAnchor.h"
6 6
7 #include "core/layout/LayoutObject.h"
7 #include "platform/scroll/ScrollableArea.h" 8 #include "platform/scroll/ScrollableArea.h"
8 #include "wtf/Assertions.h" 9 #include "wtf/Assertions.h"
9 10
10 namespace blink { 11 namespace blink {
11 12
12 ScrollAnchor::ScrollAnchor(ScrollableArea* scroller) 13 ScrollAnchor::ScrollAnchor(ScrollableArea* scroller)
13 : m_scroller(scroller) 14 : m_scroller(scroller)
14 , m_anchorObject(nullptr) 15 , m_anchorObject(nullptr)
15 { 16 {
16 ASSERT(m_scroller); 17 ASSERT(m_scroller);
(...skipping 11 matching lines...) Expand all
28 } 29 }
29 30
30 static DoublePoint computeRelativeOffset(const ScrollableArea* scroller, const L ayoutObject* layoutObject) 31 static DoublePoint computeRelativeOffset(const ScrollableArea* scroller, const L ayoutObject* layoutObject)
31 { 32 {
32 // TODO(skobes): implement. 33 // TODO(skobes): implement.
33 return DoublePoint(); 34 return DoublePoint();
34 } 35 }
35 36
36 void ScrollAnchor::save() 37 void ScrollAnchor::save()
37 { 38 {
38 if (!m_anchorObject) 39 if (!m_anchorObject) {
39 m_anchorObject = findAnchor(m_scroller); 40 m_anchorObject = findAnchor(m_scroller);
40 41 if (!m_anchorObject)
41 if (m_anchorObject) 42 return;
42 m_savedRelativeOffset = computeRelativeOffset(m_scroller, m_anchorObject ); 43 m_anchorObject->setIsScrollAnchorObject();
44 }
45 m_savedRelativeOffset = computeRelativeOffset(m_scroller, m_anchorObject);
ojan 2016/02/05 11:01:52 I think this could be inside the if clause above a
skobes 2016/02/05 17:52:31 In theory, yes, but that seems brittle to me. Sup
ojan 2016/02/06 00:09:27 I can't think of any scenario in which it would ma
43 } 46 }
44 47
45 void ScrollAnchor::restore() 48 void ScrollAnchor::restore()
46 { 49 {
47 if (!m_anchorObject) 50 if (!m_anchorObject)
48 return; 51 return;
49 52
50 DoubleSize adjustment = computeRelativeOffset(m_scroller, m_anchorObject) - m_savedRelativeOffset; 53 DoubleSize adjustment = computeRelativeOffset(m_scroller, m_anchorObject) - m_savedRelativeOffset;
51 if (!adjustment.isZero()) 54 if (!adjustment.isZero())
52 m_scroller->setScrollPosition(m_scroller->scrollPositionDouble() + adjus tment, AnchoringScroll); 55 m_scroller->setScrollPosition(m_scroller->scrollPositionDouble() + adjus tment, AnchoringScroll);
53 } 56 }
54 57
58 void ScrollAnchor::clear()
59 {
60 LayoutObject* anchorObject = m_anchorObject;
61 m_anchorObject = nullptr;
62
63 if (anchorObject)
64 anchorObject->maybeClearIsScrollAnchorObject();
65 }
66
55 } // namespace blink 67 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ScrollAnchor.h ('k') | third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698