Chromium Code Reviews| 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/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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 if (scroller->isFrameView()) | 98 if (scroller->isFrameView()) |
| 99 relativeBounds.moveBy(-flooredIntPoint(scroller->scrollPositionDouble()) ); | 99 relativeBounds.moveBy(-flooredIntPoint(scroller->scrollPositionDouble()) ); |
| 100 return relativeBounds; | 100 return relativeBounds; |
| 101 } | 101 } |
| 102 | 102 |
| 103 static LayoutPoint computeRelativeOffset(const LayoutObject* layoutObject, const ScrollableArea* scroller, Corner corner) | 103 static LayoutPoint computeRelativeOffset(const LayoutObject* layoutObject, const ScrollableArea* scroller, Corner corner) |
| 104 { | 104 { |
| 105 return cornerPointOfRect(relativeBounds(layoutObject, scroller), corner); | 105 return cornerPointOfRect(relativeBounds(layoutObject, scroller), corner); |
| 106 } | 106 } |
| 107 | 107 |
| 108 static bool candidateMovesWithScroller(const LayoutObject* candidate, const Scro llableArea* scroller) | 108 static bool candidateMayMoveWithScroller(const LayoutObject* candidate, const Sc rollableArea* scroller) |
| 109 { | 109 { |
| 110 if (candidate->style() && candidate->style()->hasViewportConstrainedPosition ()) | 110 const ComputedStyle* style = candidate->style(); |
| 111 if (style && (style->hasViewportConstrainedPosition() || style->hasOutOfFlow Position())) { | |
| 112 // Elements with absolute positioning are often used for social nav | |
|
skobes
2016/05/28 00:18:10
"social nav bars" is too specific, just say that t
ymalik
2016/05/31 22:47:02
Done.
| |
| 113 // bars that move with the viewort. | |
| 111 return false; | 114 return false; |
| 115 } | |
| 112 | 116 |
| 113 bool skippedByContainerLookup = false; | 117 bool skippedByContainerLookup = false; |
| 114 candidate->container(scrollerLayoutBox(scroller), &skippedByContainerLookup) ; | 118 candidate->container(scrollerLayoutBox(scroller), &skippedByContainerLookup) ; |
|
skobes
2016/05/28 00:18:10
I think we don't need this anymore?
ymalik
2016/05/30 18:13:03
You're right that we don't need this if we don't s
ymalik
2016/05/31 22:47:01
As per your comment below and our offline conversa
| |
| 115 return !skippedByContainerLookup; | 119 return !skippedByContainerLookup; |
| 116 } | 120 } |
| 117 | 121 |
| 118 ScrollAnchor::ExamineResult ScrollAnchor::examine(const LayoutObject* candidate) const | 122 ScrollAnchor::ExamineResult ScrollAnchor::examine(const LayoutObject* candidate) const |
| 119 { | 123 { |
| 120 if (candidate->isLayoutInline()) | 124 if (candidate->isLayoutInline()) |
| 121 return ExamineResult(Continue); | 125 return ExamineResult(Continue); |
| 122 | 126 |
| 123 if (!candidate->isText() && !candidate->isBox()) | 127 if (!candidate->isText() && !candidate->isBox()) |
| 124 return ExamineResult(Skip); | 128 return ExamineResult(Skip); |
| 125 | 129 |
| 126 if (!candidateMovesWithScroller(candidate, m_scroller)) | 130 if (!candidateMayMoveWithScroller(candidate, m_scroller)) |
| 127 return ExamineResult(Skip); | 131 return ExamineResult(Skip); |
| 128 | 132 |
| 129 LayoutRect candidateRect = relativeBounds(candidate, m_scroller); | 133 LayoutRect candidateRect = relativeBounds(candidate, m_scroller); |
| 130 LayoutRect visibleRect = scrollerLayoutBoxItem(m_scroller).overflowClipRect( LayoutPoint()); | 134 LayoutRect visibleRect = scrollerLayoutBoxItem(m_scroller).overflowClipRect( LayoutPoint()); |
| 131 | 135 |
| 132 bool occupiesSpace = candidateRect.width() > 0 && candidateRect.height() > 0 ; | 136 bool occupiesSpace = candidateRect.width() > 0 && candidateRect.height() > 0 ; |
| 133 if (occupiesSpace && visibleRect.intersects(candidateRect)) { | 137 if (occupiesSpace && visibleRect.intersects(candidateRect)) { |
| 134 return ExamineResult( | 138 return ExamineResult( |
| 135 visibleRect.contains(candidateRect) ? Return : Constrain, | 139 visibleRect.contains(candidateRect) ? Return : Constrain, |
| 136 cornerFromCandidateRect(candidate)); | 140 cornerFromCandidateRect(candidate)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 return; | 186 return; |
| 183 | 187 |
| 184 m_current.m_anchorObject->setIsScrollAnchorObject(); | 188 m_current.m_anchorObject->setIsScrollAnchorObject(); |
| 185 m_current.m_savedRelativeOffset = computeRelativeOffset( | 189 m_current.m_savedRelativeOffset = computeRelativeOffset( |
| 186 m_current.m_anchorObject, m_scroller, m_current.m_corner); | 190 m_current.m_anchorObject, m_scroller, m_current.m_corner); |
| 187 | 191 |
| 188 if (m_lastAdjusted) { | 192 if (m_lastAdjusted) { |
| 189 // We need to update m_lastAdjusted.m_savedRelativeOffset, since it is | 193 // We need to update m_lastAdjusted.m_savedRelativeOffset, since it is |
| 190 // relative to the visible rect and the user may have scrolled since the | 194 // relative to the visible rect and the user may have scrolled since the |
| 191 // last adjustment. | 195 // last adjustment. |
| 192 if (!candidateMovesWithScroller(m_lastAdjusted.m_anchorObject, m_scrolle r)) { | 196 if (!candidateMayMoveWithScroller(m_lastAdjusted.m_anchorObject, m_scrol ler)) { |
| 193 m_lastAdjusted.clear(); | 197 m_lastAdjusted.clear(); |
| 194 } else if (m_lastAdjusted.m_anchorObject == m_current.m_anchorObject | 198 } else if (m_lastAdjusted.m_anchorObject == m_current.m_anchorObject |
| 195 && m_lastAdjusted.m_corner == m_current.m_corner) { | 199 && m_lastAdjusted.m_corner == m_current.m_corner) { |
| 196 m_lastAdjusted.m_savedRelativeOffset = m_current.m_savedRelativeOffs et; | 200 m_lastAdjusted.m_savedRelativeOffset = m_current.m_savedRelativeOffs et; |
| 197 } else { | 201 } else { |
| 198 m_lastAdjusted.m_savedRelativeOffset = computeRelativeOffset( | 202 m_lastAdjusted.m_savedRelativeOffset = computeRelativeOffset( |
| 199 m_lastAdjusted.m_anchorObject, m_scroller, m_lastAdjusted.m_corn er); | 203 m_lastAdjusted.m_anchorObject, m_scroller, m_lastAdjusted.m_corn er); |
| 200 } | 204 } |
| 201 } | 205 } |
| 202 } | 206 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 | 298 |
| 295 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) | 299 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) |
| 296 { | 300 { |
| 297 if (m_current.m_anchorObject == layoutObject) | 301 if (m_current.m_anchorObject == layoutObject) |
| 298 m_current.clear(); | 302 m_current.clear(); |
| 299 if (m_lastAdjusted.m_anchorObject == layoutObject) | 303 if (m_lastAdjusted.m_anchorObject == layoutObject) |
| 300 m_lastAdjusted.clear(); | 304 m_lastAdjusted.clear(); |
| 301 } | 305 } |
| 302 | 306 |
| 303 } // namespace blink | 307 } // namespace blink |
| OLD | NEW |