OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. | 4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. |
5 * | 5 * |
6 * Other contributors: | 6 * Other contributors: |
7 * Robert O'Callahan <roc+@cs.cmu.edu> | 7 * Robert O'Callahan <roc+@cs.cmu.edu> |
8 * David Baron <dbaron@fas.harvard.edu> | 8 * David Baron <dbaron@fas.harvard.edu> |
9 * Christian Biesinger <cbiesinger@web.de> | 9 * Christian Biesinger <cbiesinger@web.de> |
10 * Randall Jesup <rjesup@wgate.com> | 10 * Randall Jesup <rjesup@wgate.com> |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 // ScrollbarManager allows a ScrollableArea to delay the destruction of
a scrollbar that | 126 // ScrollbarManager allows a ScrollableArea to delay the destruction of
a scrollbar that |
127 // is no longer needed, until the end of multi-pass layout. If the scro
llbar is then | 127 // is no longer needed, until the end of multi-pass layout. If the scro
llbar is then |
128 // re-added before multi-pass layout finishes, the previously "deleted"
scrollbar will | 128 // re-added before multi-pass layout finishes, the previously "deleted"
scrollbar will |
129 // be restored, rather than constructing a new one. | 129 // be restored, rather than constructing a new one. |
130 public: | 130 public: |
131 ScrollbarManager(PaintLayerScrollableArea&); | 131 ScrollbarManager(PaintLayerScrollableArea&); |
132 | 132 |
133 void dispose(); | 133 void dispose(); |
134 | 134 |
135 // When canDetachScrollbars is true, calls to setHas*Scrollbar(false) wi
ll NOT destroy | |
136 // an existing scrollbar, but instead detach it without destroying it.
If, subsequently, | |
137 // setHas*Scrollbar(true) is called, the existing scrollbar will be reat
tached. When | |
138 // setCanDetachScrollbars(false) is called, any detached scrollbars will
be destructed. | |
139 bool canDetachScrollbars() const { return m_canDetachScrollbars; } | |
140 void setCanDetachScrollbars(bool); | |
141 | |
142 Scrollbar* horizontalScrollbar() const { return m_hBarIsAttached ? m_hBa
r.get(): nullptr; } | 135 Scrollbar* horizontalScrollbar() const { return m_hBarIsAttached ? m_hBa
r.get(): nullptr; } |
143 Scrollbar* verticalScrollbar() const { return m_vBarIsAttached ? m_vBar.
get() : nullptr; } | 136 Scrollbar* verticalScrollbar() const { return m_vBarIsAttached ? m_vBar.
get() : nullptr; } |
144 bool hasHorizontalScrollbar() const { return horizontalScrollbar(); } | 137 bool hasHorizontalScrollbar() const { return horizontalScrollbar(); } |
145 bool hasVerticalScrollbar() const { return verticalScrollbar(); } | 138 bool hasVerticalScrollbar() const { return verticalScrollbar(); } |
146 | 139 |
147 void setHasHorizontalScrollbar(bool hasScrollbar); | 140 // setHas*Scrollbar(false, true) will NOT destroy an existing scrollbar,
but instead |
148 void setHasVerticalScrollbar(bool hasScrollbar); | 141 // detach it without destroying it. If, subsequently, setHas*Scrollbar(
true, [true|false]) |
| 142 // is called, the existing scrollbar will be reattached. When destroyDe
tachedScrollbars |
| 143 // is called, any detached scrollbars will be immediately destroyed. |
| 144 void setHasHorizontalScrollbar(bool hasScrollbar, bool canDetach = false
); |
| 145 void setHasVerticalScrollbar(bool hasScrollbar, bool canDetach = false); |
| 146 void destroyDetachedScrollbars(); |
149 | 147 |
150 DECLARE_TRACE(); | 148 DECLARE_TRACE(); |
151 | 149 |
152 private: | 150 private: |
153 Scrollbar* createScrollbar(ScrollbarOrientation); | 151 Scrollbar* createScrollbar(ScrollbarOrientation); |
154 void destroyScrollbar(ScrollbarOrientation); | 152 void destroyScrollbar(ScrollbarOrientation); |
155 | 153 |
156 private: | 154 private: |
157 Member<PaintLayerScrollableArea> m_scrollableArea; | 155 Member<PaintLayerScrollableArea> m_scrollableArea; |
158 | 156 |
159 // The scrollbars associated with m_scrollableArea. Both can nullptr. | 157 // The scrollbars associated with m_scrollableArea. Both can nullptr. |
160 Member<Scrollbar> m_hBar; | 158 Member<Scrollbar> m_hBar; |
161 Member<Scrollbar> m_vBar; | 159 Member<Scrollbar> m_vBar; |
162 | 160 |
163 unsigned m_canDetachScrollbars: 1; | |
164 unsigned m_hBarIsAttached: 1; | 161 unsigned m_hBarIsAttached: 1; |
165 unsigned m_vBarIsAttached: 1; | 162 unsigned m_vBarIsAttached: 1; |
166 }; | 163 }; |
167 | 164 |
168 public: | 165 public: |
| 166 |
| 167 // If a PreventRelayoutScope object is alive, updateAfterLayout() will not |
| 168 // re-run box layout as a result of adding or removing scrollbars. |
| 169 class PreventRelayoutScope { |
| 170 public: |
| 171 PreventRelayoutScope(SubtreeLayoutScope&); |
| 172 ~PreventRelayoutScope(); |
| 173 |
| 174 static bool relayoutIsPrevented() { return s_count; } |
| 175 static void setNeedsLayout(LayoutObject&); |
| 176 static bool relayoutNeeded() { return s_count == 0 && s_relayoutNeeded;
} |
| 177 static void resetRelayoutNeeded(); |
| 178 |
| 179 private: |
| 180 static int s_count; |
| 181 static SubtreeLayoutScope* s_layoutScope; |
| 182 static bool s_relayoutNeeded; |
| 183 static WTF::Vector<LayoutObject*>* s_needsRelayout; |
| 184 }; |
| 185 |
| 186 // If a FreezeScrollbarScope object is alive, updateAfterLayout() will not |
| 187 // recompute the existence of overflow:auto scrollbars. |
| 188 class FreezeScrollbarsScope { |
| 189 public: |
| 190 FreezeScrollbarsScope() { s_count++; } |
| 191 ~FreezeScrollbarsScope() { s_count--; } |
| 192 |
| 193 static bool scrollbarsAreFrozen() { return s_count; } |
| 194 |
| 195 private: |
| 196 static int s_count; |
| 197 }; |
| 198 |
| 199 // If a DelayScrollPositionClampScope object is alive, updateAfterLayout() w
ill not |
| 200 // clamp scroll positions to ensure they are in the valid range. When |
| 201 // the last DelayScrollPositionClampScope object is destructed, all PaintLay
erScrollableArea's |
| 202 // that delayed clamping their positions will immediately clamp them. |
| 203 class DelayScrollPositionClampScope { |
| 204 public: |
| 205 DelayScrollPositionClampScope(); |
| 206 ~DelayScrollPositionClampScope(); |
| 207 |
| 208 static bool clampingIsDelayed() { return s_count; } |
| 209 static void setNeedsClamp(PaintLayerScrollableArea*); |
| 210 |
| 211 private: |
| 212 static void clampScrollableAreas(); |
| 213 |
| 214 static int s_count; |
| 215 static PersistentHeapVector<Member<PaintLayerScrollableArea>>* s_needsCl
amp; |
| 216 }; |
| 217 |
169 // FIXME: We should pass in the LayoutBox but this opens a window | 218 // FIXME: We should pass in the LayoutBox but this opens a window |
170 // for crashers during PaintLayer setup (see crbug.com/368062). | 219 // for crashers during PaintLayer setup (see crbug.com/368062). |
171 static PaintLayerScrollableArea* create(PaintLayer& layer) | 220 static PaintLayerScrollableArea* create(PaintLayer& layer) |
172 { | 221 { |
173 return new PaintLayerScrollableArea(layer); | 222 return new PaintLayerScrollableArea(layer); |
174 } | 223 } |
175 | 224 |
176 ~PaintLayerScrollableArea() override; | 225 ~PaintLayerScrollableArea() override; |
177 void dispose(); | 226 void dispose(); |
178 | 227 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 void scrollToYOffset(double y, ScrollOffsetClamping clamp = ScrollOffsetUncl
amped, ScrollBehavior scrollBehavior = ScrollBehaviorInstant) | 306 void scrollToYOffset(double y, ScrollOffsetClamping clamp = ScrollOffsetUncl
amped, ScrollBehavior scrollBehavior = ScrollBehaviorInstant) |
258 { | 307 { |
259 scrollToOffset(DoubleSize(scrollXOffset(), y), clamp, scrollBehavior); | 308 scrollToOffset(DoubleSize(scrollXOffset(), y), clamp, scrollBehavior); |
260 } | 309 } |
261 | 310 |
262 void setScrollPosition(const DoublePoint& position, ScrollType scrollType, S
crollBehavior scrollBehavior = ScrollBehaviorInstant) override | 311 void setScrollPosition(const DoublePoint& position, ScrollType scrollType, S
crollBehavior scrollBehavior = ScrollBehaviorInstant) override |
263 { | 312 { |
264 scrollToOffset(toDoubleSize(position), ScrollOffsetClamped, scrollBehavi
or, scrollType); | 313 scrollToOffset(toDoubleSize(position), ScrollOffsetClamped, scrollBehavi
or, scrollType); |
265 } | 314 } |
266 | 315 |
267 // Returns true if a layout object was marked for layout. In such a case, th
e layout scope's root | 316 // TODO(szager): Actually run these after all of layout is finished. Curren
tly, they |
268 // should be laid out again. | 317 // run at the end of box()'es layout (or after all flexbox layout has finish
ed) but while |
269 bool updateAfterLayout(SubtreeLayoutScope* = nullptr); | 318 // document layout is still happening. |
| 319 void updateAfterLayout(); |
| 320 void clampScrollPositionsAfterLayout(); |
| 321 |
270 void updateAfterStyleChange(const ComputedStyle*); | 322 void updateAfterStyleChange(const ComputedStyle*); |
271 void updateAfterOverflowRecalc(); | 323 void updateAfterOverflowRecalc(); |
272 | 324 |
273 bool updateAfterCompositingChange() override; | 325 bool updateAfterCompositingChange() override; |
274 | 326 |
275 bool hasScrollbar() const { return hasHorizontalScrollbar() || hasVerticalSc
rollbar(); } | 327 bool hasScrollbar() const { return hasHorizontalScrollbar() || hasVerticalSc
rollbar(); } |
276 bool hasOverflowControls() const { return hasScrollbar() || scrollCorner() |
| resizer(); } | 328 bool hasOverflowControls() const { return hasScrollbar() || scrollCorner() |
| resizer(); } |
277 | 329 |
278 LayoutScrollbarPart* scrollCorner() const override { return m_scrollCorner;
} | 330 LayoutScrollbarPart* scrollCorner() const override { return m_scrollCorner;
} |
279 | 331 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 IntRect rectForVerticalScrollbar(const IntRect& borderBoxRect) const; | 396 IntRect rectForVerticalScrollbar(const IntRect& borderBoxRect) const; |
345 | 397 |
346 Widget* getWidget() override; | 398 Widget* getWidget() override; |
347 ScrollAnchor& scrollAnchor() { return m_scrollAnchor; } | 399 ScrollAnchor& scrollAnchor() { return m_scrollAnchor; } |
348 bool isPaintLayerScrollableArea() const override { return true; } | 400 bool isPaintLayerScrollableArea() const override { return true; } |
349 | 401 |
350 bool shouldRebuildHorizontalScrollbarLayer() const { return m_rebuildHorizon
talScrollbarLayer; } | 402 bool shouldRebuildHorizontalScrollbarLayer() const { return m_rebuildHorizon
talScrollbarLayer; } |
351 bool shouldRebuildVerticalScrollbarLayer() const { return m_rebuildVerticalS
crollbarLayer; } | 403 bool shouldRebuildVerticalScrollbarLayer() const { return m_rebuildVerticalS
crollbarLayer; } |
352 void resetRebuildScrollbarLayerFlags(); | 404 void resetRebuildScrollbarLayerFlags(); |
353 | 405 |
| 406 bool needsScrollPositionClamp() const { return m_needsScrollPositionClamp; } |
| 407 void setNeedsScrollPositionClamp(bool val) { m_needsScrollPositionClamp = va
l; } |
| 408 |
354 StickyConstraintsMap& stickyConstraintsMap() { return ensureRareData().m_sti
ckyConstraintsMap; } | 409 StickyConstraintsMap& stickyConstraintsMap() { return ensureRareData().m_sti
ckyConstraintsMap; } |
355 void invalidateAllStickyConstraints(); | 410 void invalidateAllStickyConstraints(); |
356 void invalidateStickyConstraintsFor(PaintLayer*, bool needsCompositingUpdate
= true); | 411 void invalidateStickyConstraintsFor(PaintLayer*, bool needsCompositingUpdate
= true); |
357 | 412 |
358 DECLARE_VIRTUAL_TRACE(); | 413 DECLARE_VIRTUAL_TRACE(); |
359 | 414 |
360 private: | 415 private: |
361 explicit PaintLayerScrollableArea(PaintLayer&); | 416 explicit PaintLayerScrollableArea(PaintLayer&); |
362 | 417 |
363 bool hasHorizontalOverflow() const; | 418 bool hasHorizontalOverflow() const; |
364 bool hasVerticalOverflow() const; | 419 bool hasVerticalOverflow() const; |
365 bool hasScrollableHorizontalOverflow() const; | 420 bool hasScrollableHorizontalOverflow() const; |
366 bool hasScrollableVerticalOverflow() const; | 421 bool hasScrollableVerticalOverflow() const; |
367 bool visualViewportSuppliesScrollbars() const; | 422 bool visualViewportSuppliesScrollbars() const; |
368 | 423 |
369 bool needsScrollbarReconstruction() const; | 424 bool needsScrollbarReconstruction() const; |
370 | 425 |
371 void computeScrollDimensions(); | 426 void updateScrollOrigin(); |
| 427 void updateScrollDimensions(); |
372 | 428 |
373 void setScrollOffset(const DoublePoint&, ScrollType) override; | 429 void setScrollOffset(const DoublePoint&, ScrollType) override; |
374 | 430 |
375 int verticalScrollbarStart(int minX, int maxX) const; | 431 int verticalScrollbarStart(int minX, int maxX) const; |
376 int horizontalScrollbarStart(int minX) const; | 432 int horizontalScrollbarStart(int minX) const; |
377 IntSize scrollbarOffset(const Scrollbar&) const; | 433 IntSize scrollbarOffset(const Scrollbar&) const; |
378 | 434 |
379 void setHasHorizontalScrollbar(bool hasScrollbar); | 435 void setHasHorizontalScrollbar(bool hasScrollbar); |
380 void setHasVerticalScrollbar(bool hasScrollbar); | 436 void setHasVerticalScrollbar(bool hasScrollbar); |
381 | 437 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 // FIXME: once cc can handle composited scrolling with clip paths, we will | 475 // FIXME: once cc can handle composited scrolling with clip paths, we will |
420 // no longer need this bit. | 476 // no longer need this bit. |
421 unsigned m_needsCompositedScrolling : 1; | 477 unsigned m_needsCompositedScrolling : 1; |
422 | 478 |
423 // Set to indicate that a scrollbar layer, if present, needs to be rebuilt | 479 // Set to indicate that a scrollbar layer, if present, needs to be rebuilt |
424 // in the next compositing update because the underlying blink::Scrollbar | 480 // in the next compositing update because the underlying blink::Scrollbar |
425 // instance has been reconstructed. | 481 // instance has been reconstructed. |
426 unsigned m_rebuildHorizontalScrollbarLayer : 1; | 482 unsigned m_rebuildHorizontalScrollbarLayer : 1; |
427 unsigned m_rebuildVerticalScrollbarLayer : 1; | 483 unsigned m_rebuildVerticalScrollbarLayer : 1; |
428 | 484 |
| 485 unsigned m_needsScrollPositionClamp : 1; |
| 486 |
429 // The width/height of our scrolled area. | 487 // The width/height of our scrolled area. |
430 // This is OverflowModel's layout overflow translated to physical | 488 // This is OverflowModel's layout overflow translated to physical |
431 // coordinates. See OverflowModel for the different overflow and | 489 // coordinates. See OverflowModel for the different overflow and |
432 // LayoutBoxModelObject for the coordinate systems. | 490 // LayoutBoxModelObject for the coordinate systems. |
433 LayoutRect m_overflowRect; | 491 LayoutRect m_overflowRect; |
434 | 492 |
435 // ScrollbarManager holds the Scrollbar instances. | 493 // ScrollbarManager holds the Scrollbar instances. |
436 ScrollbarManager m_scrollbarManager; | 494 ScrollbarManager m_scrollbarManager; |
437 | 495 |
438 // This is the (scroll) offset from scrollOrigin(). | 496 // This is the (scroll) offset from scrollOrigin(). |
(...skipping 16 matching lines...) Expand all Loading... |
455 #endif | 513 #endif |
456 }; | 514 }; |
457 | 515 |
458 DEFINE_TYPE_CASTS(PaintLayerScrollableArea, ScrollableArea, scrollableArea, | 516 DEFINE_TYPE_CASTS(PaintLayerScrollableArea, ScrollableArea, scrollableArea, |
459 scrollableArea->isPaintLayerScrollableArea(), | 517 scrollableArea->isPaintLayerScrollableArea(), |
460 scrollableArea.isPaintLayerScrollableArea()); | 518 scrollableArea.isPaintLayerScrollableArea()); |
461 | 519 |
462 } // namespace blink | 520 } // namespace blink |
463 | 521 |
464 #endif // LayerScrollableArea_h | 522 #endif // LayerScrollableArea_h |
OLD | NEW |