| 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/line/InlineTextBox.h" | 9 #include "core/layout/line/InlineTextBox.h" |
| 10 #include "core/paint/PaintLayerScrollableArea.h" | 10 #include "core/paint/PaintLayerScrollableArea.h" |
| 11 #include "platform/Histogram.h" | 11 #include "platform/Histogram.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 using Corner = ScrollAnchor::Corner; | 15 using Corner = ScrollAnchor::Corner; |
| 16 | 16 |
| 17 ScrollAnchor::ScrollAnchor() | 17 ScrollAnchor::ScrollAnchor() |
| 18 : m_anchorObject(nullptr) | 18 : m_anchorObject(nullptr) |
| 19 , m_corner(Corner::TopLeft) | 19 , m_corner(Corner::TopLeft) |
| 20 , m_scrollAnchorDisablingStyleChanged(false) | 20 , m_scrollAnchorDisablingStyleChanged(false) |
| 21 , m_saved(false) |
| 21 { | 22 { |
| 22 } | 23 } |
| 23 | 24 |
| 24 ScrollAnchor::ScrollAnchor(ScrollableArea* scroller) | 25 ScrollAnchor::ScrollAnchor(ScrollableArea* scroller) |
| 25 : ScrollAnchor() | 26 : ScrollAnchor() |
| 26 { | 27 { |
| 27 setScroller(scroller); | 28 setScroller(scroller); |
| 28 } | 29 } |
| 29 | 30 |
| 30 ScrollAnchor::~ScrollAnchor() | 31 ScrollAnchor::~ScrollAnchor() |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 if (current->scrollAnchorDisablingStyleChanged()) | 199 if (current->scrollAnchorDisablingStyleChanged()) |
| 199 return true; | 200 return true; |
| 200 if (current == scrollerBox) | 201 if (current == scrollerBox) |
| 201 return false; | 202 return false; |
| 202 current = current->parent(); | 203 current = current->parent(); |
| 203 } | 204 } |
| 204 } | 205 } |
| 205 | 206 |
| 206 void ScrollAnchor::save() | 207 void ScrollAnchor::save() |
| 207 { | 208 { |
| 209 if (m_saved) |
| 210 return; |
| 211 m_saved = true; |
| 208 DCHECK(m_scroller); | 212 DCHECK(m_scroller); |
| 209 if (m_scroller->scrollPosition() == IntPoint::zero()) { | 213 if (m_scroller->scrollPosition() == IntPoint::zero()) { |
| 210 clear(); | 214 clear(); |
| 211 return; | 215 return; |
| 212 } | 216 } |
| 213 | 217 |
| 214 if (!m_anchorObject) { | 218 if (!m_anchorObject) { |
| 215 findAnchor(); | 219 findAnchor(); |
| 216 if (!m_anchorObject) | 220 if (!m_anchorObject) |
| 217 return; | 221 return; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 235 // anchor node may round differently from the snapping of the scroll positio
n. | 239 // anchor node may round differently from the snapping of the scroll positio
n. |
| 236 // (For example, anchor moving from 2.4px -> 2.6px is really 2px -> 3px, so
we | 240 // (For example, anchor moving from 2.4px -> 2.6px is really 2px -> 3px, so
we |
| 237 // should scroll by 1px instead of 0.2px.) This is true regardless of whethe
r | 241 // should scroll by 1px instead of 0.2px.) This is true regardless of whethe
r |
| 238 // the ScrollableArea actually uses fractional scroll positions. | 242 // the ScrollableArea actually uses fractional scroll positions. |
| 239 return roundedIntSize(computeRelativeOffset(m_anchorObject, m_scroller, m_co
rner)) - | 243 return roundedIntSize(computeRelativeOffset(m_anchorObject, m_scroller, m_co
rner)) - |
| 240 roundedIntSize(m_savedRelativeOffset); | 244 roundedIntSize(m_savedRelativeOffset); |
| 241 } | 245 } |
| 242 | 246 |
| 243 void ScrollAnchor::restore() | 247 void ScrollAnchor::restore() |
| 244 { | 248 { |
| 249 if (!m_saved) |
| 250 return; |
| 251 m_saved = false; |
| 245 DCHECK(m_scroller); | 252 DCHECK(m_scroller); |
| 246 if (!m_anchorObject) | 253 if (!m_anchorObject) |
| 247 return; | 254 return; |
| 248 IntSize adjustment = computeAdjustment(); | 255 IntSize adjustment = computeAdjustment(); |
| 249 if (adjustment.isZero()) | 256 if (adjustment.isZero()) |
| 250 return; | 257 return; |
| 251 | 258 |
| 252 if (m_scrollAnchorDisablingStyleChanged) { | 259 if (m_scrollAnchorDisablingStyleChanged) { |
| 253 // Note that we only clear if the adjustment would have been non-zero. | 260 // Note that we only clear if the adjustment would have been non-zero. |
| 254 // This minimizes redundant calls to findAnchor. | 261 // This minimizes redundant calls to findAnchor. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 280 return m_anchorObject == layoutObject; | 287 return m_anchorObject == layoutObject; |
| 281 } | 288 } |
| 282 | 289 |
| 283 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) | 290 void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) |
| 284 { | 291 { |
| 285 if (m_anchorObject == layoutObject) | 292 if (m_anchorObject == layoutObject) |
| 286 clear(); | 293 clear(); |
| 287 } | 294 } |
| 288 | 295 |
| 289 } // namespace blink | 296 } // namespace blink |
| OLD | NEW |