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 m_count; } | |
175 static void setNeedsLayout(LayoutObject&); | |
176 static bool relayoutNeeded() { return m_count == 0 && m_relayoutNeeded; } | |
177 static void resetRelayoutNeeded(); | |
178 | |
179 private: | |
180 static void increment(); | |
181 static void decrement(); | |
182 | |
183 static int m_count; | |
184 static SubtreeLayoutScope* m_layoutScope; | |
185 static bool m_relayoutNeeded; | |
186 static WTF::Vector<LayoutObject*>* m_needsRelayout; | |
187 }; | |
188 | |
189 // If a FreezeScrollbarScope object is alive, updateAfterLayout() will not | |
190 // recompute the existence of overflow:auto scrollbars. | |
191 class FreezeScrollbarsScope { | |
192 public: | |
193 FreezeScrollbarsScope() { m_count++; } | |
194 ~FreezeScrollbarsScope() { m_count--; } | |
195 | |
196 static bool scrollbarsAreFrozen() { return m_count; } | |
197 | |
198 private: | |
199 static int m_count; | |
200 }; | |
201 | |
202 // If a DelayScrollPositionClampScope object is alive, updateAfterLayout() w ill not | |
203 // clamp scroll positions to ensure they are in the valid range. When | |
204 // the last DelayScrollPositionClampScope object is destructed, all PaintLay erScrollableArea's | |
205 // that delayed clamping their positions will immediately clamp them. | |
206 class DelayScrollPositionClampScope { | |
207 public: | |
208 DelayScrollPositionClampScope(); | |
209 ~DelayScrollPositionClampScope(); | |
210 | |
211 static bool clampingIsDelayed() { return m_count; } | |
212 static void setNeedsClamp(PaintLayerScrollableArea*); | |
213 | |
214 private: | |
215 static void increment(); | |
216 static void decrement(); | |
217 static void clampScrollableAreas(); | |
218 | |
219 static int m_count; | |
220 static PersistentHeapVector<Member<PaintLayerScrollableArea>>* m_needsCl amp; | |
221 }; | |
222 | |
169 // FIXME: We should pass in the LayoutBox but this opens a window | 223 // FIXME: We should pass in the LayoutBox but this opens a window |
170 // for crashers during PaintLayer setup (see crbug.com/368062). | 224 // for crashers during PaintLayer setup (see crbug.com/368062). |
171 static PaintLayerScrollableArea* create(PaintLayer& layer) | 225 static PaintLayerScrollableArea* create(PaintLayer& layer) |
172 { | 226 { |
173 return new PaintLayerScrollableArea(layer); | 227 return new PaintLayerScrollableArea(layer); |
174 } | 228 } |
175 | 229 |
176 ~PaintLayerScrollableArea() override; | 230 ~PaintLayerScrollableArea() override; |
177 void dispose(); | 231 void dispose(); |
178 | 232 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 void scrollToYOffset(double y, ScrollOffsetClamping clamp = ScrollOffsetUncl amped, ScrollBehavior scrollBehavior = ScrollBehaviorInstant) | 313 void scrollToYOffset(double y, ScrollOffsetClamping clamp = ScrollOffsetUncl amped, ScrollBehavior scrollBehavior = ScrollBehaviorInstant) |
260 { | 314 { |
261 scrollToOffset(DoubleSize(scrollXOffset(), y), clamp, scrollBehavior); | 315 scrollToOffset(DoubleSize(scrollXOffset(), y), clamp, scrollBehavior); |
262 } | 316 } |
263 | 317 |
264 void setScrollPosition(const DoublePoint& position, ScrollType scrollType, S crollBehavior scrollBehavior = ScrollBehaviorInstant) override | 318 void setScrollPosition(const DoublePoint& position, ScrollType scrollType, S crollBehavior scrollBehavior = ScrollBehaviorInstant) override |
265 { | 319 { |
266 scrollToOffset(toDoubleSize(position), ScrollOffsetClamped, scrollBehavi or, scrollType); | 320 scrollToOffset(toDoubleSize(position), ScrollOffsetClamped, scrollBehavi or, scrollType); |
267 } | 321 } |
268 | 322 |
269 // Returns true if a layout object was marked for layout. In such a case, th e layout scope's root | 323 void updateAfterLayout(); |
leviw_travelin_and_unemployed
2016/04/28 22:50:04
Can you add a TODO or comment about how this is ra
szager1
2016/05/12 20:44:51
Done.
| |
270 // should be laid out again. | 324 void clampScrollPositionsAfterLayout(); |
leviw_travelin_and_unemployed
2016/04/28 22:50:04
Is there a reason we can't do this in the layer up
szager1
2016/05/12 20:44:51
It's not totally clear to me that this value isn't
| |
271 bool updateAfterLayout(SubtreeLayoutScope* = nullptr); | |
272 void updateAfterStyleChange(const ComputedStyle*); | 325 void updateAfterStyleChange(const ComputedStyle*); |
273 void updateAfterOverflowRecalc(); | 326 void updateAfterOverflowRecalc(); |
274 | 327 |
275 bool updateAfterCompositingChange() override; | 328 bool updateAfterCompositingChange() override; |
276 | 329 |
277 bool hasScrollbar() const { return hasHorizontalScrollbar() || hasVerticalSc rollbar(); } | 330 bool hasScrollbar() const { return hasHorizontalScrollbar() || hasVerticalSc rollbar(); } |
278 bool hasOverflowControls() const { return hasScrollbar() || scrollCorner() | | resizer(); } | 331 bool hasOverflowControls() const { return hasScrollbar() || scrollCorner() | | resizer(); } |
279 | 332 |
280 LayoutScrollbarPart* scrollCorner() const override { return m_scrollCorner; } | 333 LayoutScrollbarPart* scrollCorner() const override { return m_scrollCorner; } |
281 | 334 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 IntRect rectForVerticalScrollbar(const IntRect& borderBoxRect) const; | 399 IntRect rectForVerticalScrollbar(const IntRect& borderBoxRect) const; |
347 | 400 |
348 Widget* getWidget() override; | 401 Widget* getWidget() override; |
349 ScrollAnchor& scrollAnchor() { return m_scrollAnchor; } | 402 ScrollAnchor& scrollAnchor() { return m_scrollAnchor; } |
350 bool isPaintLayerScrollableArea() const override { return true; } | 403 bool isPaintLayerScrollableArea() const override { return true; } |
351 | 404 |
352 bool shouldRebuildHorizontalScrollbarLayer() const { return m_rebuildHorizon talScrollbarLayer; } | 405 bool shouldRebuildHorizontalScrollbarLayer() const { return m_rebuildHorizon talScrollbarLayer; } |
353 bool shouldRebuildVerticalScrollbarLayer() const { return m_rebuildVerticalS crollbarLayer; } | 406 bool shouldRebuildVerticalScrollbarLayer() const { return m_rebuildVerticalS crollbarLayer; } |
354 void resetRebuildScrollbarLayerFlags(); | 407 void resetRebuildScrollbarLayerFlags(); |
355 | 408 |
409 bool needsScrollPositionClamp() const { return m_needsScrollPositionClamp; } | |
410 void setNeedsScrollPositionClamp(bool val) { m_needsScrollPositionClamp = va l; } | |
411 | |
356 StickyConstraintsMap& stickyConstraintsMap() { return ensureRareData().m_sti ckyConstraintsMap; } | 412 StickyConstraintsMap& stickyConstraintsMap() { return ensureRareData().m_sti ckyConstraintsMap; } |
357 void invalidateAllStickyConstraints(); | 413 void invalidateAllStickyConstraints(); |
358 void invalidateStickyConstraintsFor(PaintLayer*, bool needsCompositingUpdate = true); | 414 void invalidateStickyConstraintsFor(PaintLayer*, bool needsCompositingUpdate = true); |
359 | 415 |
360 DECLARE_VIRTUAL_TRACE(); | 416 DECLARE_VIRTUAL_TRACE(); |
361 | 417 |
362 private: | 418 private: |
363 explicit PaintLayerScrollableArea(PaintLayer&); | 419 explicit PaintLayerScrollableArea(PaintLayer&); |
364 | 420 |
365 bool hasHorizontalOverflow() const; | 421 bool hasHorizontalOverflow() const; |
366 bool hasVerticalOverflow() const; | 422 bool hasVerticalOverflow() const; |
367 bool hasScrollableHorizontalOverflow() const; | 423 bool hasScrollableHorizontalOverflow() const; |
368 bool hasScrollableVerticalOverflow() const; | 424 bool hasScrollableVerticalOverflow() const; |
369 bool visualViewportSuppliesScrollbars() const; | 425 bool visualViewportSuppliesScrollbars() const; |
370 | 426 |
371 bool needsScrollbarReconstruction() const; | 427 bool needsScrollbarReconstruction() const; |
372 | 428 |
373 void computeScrollDimensions(); | 429 void updateScrollOrigin(); |
430 void updateScrollDimensions(); | |
374 | 431 |
375 void setScrollOffset(const DoublePoint&, ScrollType) override; | 432 void setScrollOffset(const DoublePoint&, ScrollType) override; |
376 | 433 |
377 int verticalScrollbarStart(int minX, int maxX) const; | 434 int verticalScrollbarStart(int minX, int maxX) const; |
378 int horizontalScrollbarStart(int minX) const; | 435 int horizontalScrollbarStart(int minX) const; |
379 IntSize scrollbarOffset(const Scrollbar&) const; | 436 IntSize scrollbarOffset(const Scrollbar&) const; |
380 | 437 |
381 void setHasHorizontalScrollbar(bool hasScrollbar); | 438 void setHasHorizontalScrollbar(bool hasScrollbar); |
382 void setHasVerticalScrollbar(bool hasScrollbar); | 439 void setHasVerticalScrollbar(bool hasScrollbar); |
383 | 440 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 // 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 |
422 // no longer need this bit. | 479 // no longer need this bit. |
423 unsigned m_needsCompositedScrolling : 1; | 480 unsigned m_needsCompositedScrolling : 1; |
424 | 481 |
425 // 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 |
426 // in the next compositing update because the underlying blink::Scrollbar | 483 // in the next compositing update because the underlying blink::Scrollbar |
427 // instance has been reconstructed. | 484 // instance has been reconstructed. |
428 unsigned m_rebuildHorizontalScrollbarLayer : 1; | 485 unsigned m_rebuildHorizontalScrollbarLayer : 1; |
429 unsigned m_rebuildVerticalScrollbarLayer : 1; | 486 unsigned m_rebuildVerticalScrollbarLayer : 1; |
430 | 487 |
488 unsigned m_needsScrollPositionClamp : 1; | |
489 | |
431 // The width/height of our scrolled area. | 490 // The width/height of our scrolled area. |
432 // This is OverflowModel's layout overflow translated to physical | 491 // This is OverflowModel's layout overflow translated to physical |
433 // coordinates. See OverflowModel for the different overflow and | 492 // coordinates. See OverflowModel for the different overflow and |
434 // LayoutBoxModelObject for the coordinate systems. | 493 // LayoutBoxModelObject for the coordinate systems. |
435 LayoutRect m_overflowRect; | 494 LayoutRect m_overflowRect; |
436 | 495 |
437 // ScrollbarManager holds the Scrollbar instances. | 496 // ScrollbarManager holds the Scrollbar instances. |
438 ScrollbarManager m_scrollbarManager; | 497 ScrollbarManager m_scrollbarManager; |
439 | 498 |
440 // This is the (scroll) offset from scrollOrigin(). | 499 // This is the (scroll) offset from scrollOrigin(). |
(...skipping 16 matching lines...) Expand all Loading... | |
457 #endif | 516 #endif |
458 }; | 517 }; |
459 | 518 |
460 DEFINE_TYPE_CASTS(PaintLayerScrollableArea, ScrollableArea, scrollableArea, | 519 DEFINE_TYPE_CASTS(PaintLayerScrollableArea, ScrollableArea, scrollableArea, |
461 scrollableArea->isPaintLayerScrollableArea(), | 520 scrollableArea->isPaintLayerScrollableArea(), |
462 scrollableArea.isPaintLayerScrollableArea()); | 521 scrollableArea.isPaintLayerScrollableArea()); |
463 | 522 |
464 } // namespace blink | 523 } // namespace blink |
465 | 524 |
466 #endif // LayerScrollableArea_h | 525 #endif // LayerScrollableArea_h |
OLD | NEW |