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

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

Issue 1958973004: Always anchor to top of the anchor element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 years, 7 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/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/frame/UseCounter.h" 8 #include "core/frame/UseCounter.h"
9 #include "core/layout/LayoutView.h" 9 #include "core/layout/LayoutView.h"
10 #include "core/layout/line/InlineTextBox.h" 10 #include "core/layout/line/InlineTextBox.h"
(...skipping 30 matching lines...) Expand all
41 41
42 static LayoutBoxItem scrollerLayoutBoxItem(const ScrollableArea* scroller) 42 static LayoutBoxItem scrollerLayoutBoxItem(const ScrollableArea* scroller)
43 { 43 {
44 LayoutBoxItem box = scroller->isFrameView() 44 LayoutBoxItem box = scroller->isFrameView()
45 ? toFrameView(scroller)->layoutViewItem() 45 ? toFrameView(scroller)->layoutViewItem()
46 : LayoutBoxItem(&toPaintLayerScrollableArea(scroller)->box()); 46 : LayoutBoxItem(&toPaintLayerScrollableArea(scroller)->box());
47 ASSERT(!box.isNull()); 47 ASSERT(!box.isNull());
48 return box; 48 return box;
49 } 49 }
50 50
51 static Corner cornerFromCandidateRect(LayoutRect candidateRect, LayoutRect visib leRect) 51 static Corner cornerFromCandidateRect(const LayoutObject* layoutObject)
52 { 52 {
53 if (visibleRect.contains(candidateRect.minXMinYCorner())) 53 ASSERT(layoutObject);
54 return Corner::TopLeft; 54 if (layoutObject->style()->isFlippedBlocksWritingMode()
55 if (visibleRect.contains(candidateRect.maxXMinYCorner())) 55 || !layoutObject->style()->isLeftToRightDirection())
56 return Corner::TopRight; 56 return Corner::TopRight;
57 if (visibleRect.contains(candidateRect.minXMaxYCorner()))
58 return Corner::BottomLeft;
59 if (visibleRect.contains(candidateRect.maxXMaxYCorner()))
60 return Corner::BottomRight;
61 return Corner::TopLeft; 57 return Corner::TopLeft;
62 } 58 }
63 59
64 static LayoutPoint cornerPointOfRect(LayoutRect rect, Corner whichCorner) 60 static LayoutPoint cornerPointOfRect(LayoutRect rect, Corner whichCorner)
65 { 61 {
66 switch (whichCorner) { 62 switch (whichCorner) {
67 case Corner::TopLeft: return rect.minXMinYCorner(); 63 case Corner::TopLeft: return rect.minXMinYCorner();
68 case Corner::TopRight: return rect.maxXMinYCorner(); 64 case Corner::TopRight: return rect.maxXMinYCorner();
69 case Corner::BottomLeft: return rect.minXMaxYCorner();
70 case Corner::BottomRight: return rect.maxXMaxYCorner();
71 } 65 }
72 ASSERT_NOT_REACHED(); 66 ASSERT_NOT_REACHED();
73 return LayoutPoint(); 67 return LayoutPoint();
74 } 68 }
75 69
76 // Bounds of the LayoutObject relative to the scroller's visible content rect. 70 // Bounds of the LayoutObject relative to the scroller's visible content rect.
77 static LayoutRect relativeBounds(const LayoutObject* layoutObject, const Scrolla bleArea* scroller) 71 static LayoutRect relativeBounds(const LayoutObject* layoutObject, const Scrolla bleArea* scroller)
78 { 72 {
79 LayoutRect localBounds; 73 LayoutRect localBounds;
80 if (layoutObject->isBox()) { 74 if (layoutObject->isBox()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (!candidateMovesWithScroller(candidate, m_scroller)) 114 if (!candidateMovesWithScroller(candidate, m_scroller))
121 return ExamineResult(Skip); 115 return ExamineResult(Skip);
122 116
123 LayoutRect candidateRect = relativeBounds(candidate, m_scroller); 117 LayoutRect candidateRect = relativeBounds(candidate, m_scroller);
124 LayoutRect visibleRect = scrollerLayoutBoxItem(m_scroller).overflowClipRect( LayoutPoint()); 118 LayoutRect visibleRect = scrollerLayoutBoxItem(m_scroller).overflowClipRect( LayoutPoint());
125 119
126 bool occupiesSpace = candidateRect.width() > 0 && candidateRect.height() > 0 ; 120 bool occupiesSpace = candidateRect.width() > 0 && candidateRect.height() > 0 ;
127 if (occupiesSpace && visibleRect.intersects(candidateRect)) { 121 if (occupiesSpace && visibleRect.intersects(candidateRect)) {
128 return ExamineResult( 122 return ExamineResult(
129 visibleRect.contains(candidateRect) ? Return : Constrain, 123 visibleRect.contains(candidateRect) ? Return : Constrain,
130 cornerFromCandidateRect(candidateRect, visibleRect)); 124 cornerFromCandidateRect(candidate));
131 } else { 125 } else {
132 return ExamineResult(Skip); 126 return ExamineResult(Skip);
133 } 127 }
134 } 128 }
135 129
136 void ScrollAnchor::findAnchor() 130 void ScrollAnchor::findAnchor()
137 { 131 {
138 LayoutObject* stayWithin = scrollerLayoutBox(m_scroller); 132 LayoutObject* stayWithin = scrollerLayoutBox(m_scroller);
139 LayoutObject* candidate = stayWithin->nextInPreOrder(stayWithin); 133 LayoutObject* candidate = stayWithin->nextInPreOrder(stayWithin);
140 while (candidate) { 134 while (candidate) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void ScrollAnchor::clear() 203 void ScrollAnchor::clear()
210 { 204 {
211 LayoutObject* anchorObject = m_anchorObject; 205 LayoutObject* anchorObject = m_anchorObject;
212 m_anchorObject = nullptr; 206 m_anchorObject = nullptr;
213 207
214 if (anchorObject) 208 if (anchorObject)
215 anchorObject->maybeClearIsScrollAnchorObject(); 209 anchorObject->maybeClearIsScrollAnchorObject();
216 } 210 }
217 211
218 } // namespace blink 212 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ScrollAnchor.h ('k') | third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698