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