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 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++; } | |
eae
2016/06/02 22:57:25
Could we add a test or assert or something to guar
szager1
2016/06/03 22:33:11
I made these classes STACK_ALLOCATED, is that good
| |
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 | |
173 // 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 |
174 // for crashers during PaintLayer setup (see crbug.com/368062). | 219 // for crashers during PaintLayer setup (see crbug.com/368062). |
175 static PaintLayerScrollableArea* create(PaintLayer& layer) | 220 static PaintLayerScrollableArea* create(PaintLayer& layer) |
176 { | 221 { |
177 return new PaintLayerScrollableArea(layer); | 222 return new PaintLayerScrollableArea(layer); |
178 } | 223 } |
179 | 224 |
180 ~PaintLayerScrollableArea() override; | 225 ~PaintLayerScrollableArea() override; |
181 void dispose(); | 226 void dispose(); |
182 | 227 |
(...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) | 306 void scrollToYOffset(double y, ScrollOffsetClamping clamp = ScrollOffsetUncl amped, ScrollBehavior scrollBehavior = ScrollBehaviorInstant) |
262 { | 307 { |
263 scrollToOffset(DoubleSize(scrollXOffset(), y), clamp, scrollBehavior); | 308 scrollToOffset(DoubleSize(scrollXOffset(), y), clamp, scrollBehavior); |
264 } | 309 } |
265 | 310 |
266 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 |
267 { | 312 { |
268 scrollToOffset(toDoubleSize(position), ScrollOffsetClamped, scrollBehavi or, scrollType); | 313 scrollToOffset(toDoubleSize(position), ScrollOffsetClamped, scrollBehavi or, scrollType); |
269 } | 314 } |
270 | 315 |
271 // 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 |
272 // should be laid out again. | 317 // run at the end of box()'es layout (or after all flexbox layout has finish ed) but while |
273 bool updateAfterLayout(SubtreeLayoutScope* = nullptr); | 318 // document layout is still happening. |
319 void updateAfterLayout(); | |
320 void clampScrollPositionsAfterLayout(); | |
321 | |
274 void updateAfterStyleChange(const ComputedStyle*); | 322 void updateAfterStyleChange(const ComputedStyle*); |
275 void updateAfterOverflowRecalc(); | 323 void updateAfterOverflowRecalc(); |
276 | 324 |
277 bool updateAfterCompositingChange() override; | 325 bool updateAfterCompositingChange() override; |
278 | 326 |
279 bool hasScrollbar() const { return hasHorizontalScrollbar() || hasVerticalSc rollbar(); } | 327 bool hasScrollbar() const { return hasHorizontalScrollbar() || hasVerticalSc rollbar(); } |
280 bool hasOverflowControls() const { return hasScrollbar() || scrollCorner() | | resizer(); } | 328 bool hasOverflowControls() const { return hasScrollbar() || scrollCorner() | | resizer(); } |
281 | 329 |
282 LayoutScrollbarPart* scrollCorner() const override { return m_scrollCorner; } | 330 LayoutScrollbarPart* scrollCorner() const override { return m_scrollCorner; } |
283 | 331 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 IntRect rectForVerticalScrollbar(const IntRect& borderBoxRect) const; | 396 IntRect rectForVerticalScrollbar(const IntRect& borderBoxRect) const; |
349 | 397 |
350 Widget* getWidget() override; | 398 Widget* getWidget() override; |
351 ScrollAnchor& scrollAnchor() { return m_scrollAnchor; } | 399 ScrollAnchor& scrollAnchor() { return m_scrollAnchor; } |
352 bool isPaintLayerScrollableArea() const override { return true; } | 400 bool isPaintLayerScrollableArea() const override { return true; } |
353 | 401 |
354 bool shouldRebuildHorizontalScrollbarLayer() const { return m_rebuildHorizon talScrollbarLayer; } | 402 bool shouldRebuildHorizontalScrollbarLayer() const { return m_rebuildHorizon talScrollbarLayer; } |
355 bool shouldRebuildVerticalScrollbarLayer() const { return m_rebuildVerticalS crollbarLayer; } | 403 bool shouldRebuildVerticalScrollbarLayer() const { return m_rebuildVerticalS crollbarLayer; } |
356 void resetRebuildScrollbarLayerFlags(); | 404 void resetRebuildScrollbarLayerFlags(); |
357 | 405 |
406 bool needsScrollPositionClamp() const { return m_needsScrollPositionClamp; } | |
407 void setNeedsScrollPositionClamp(bool val) { m_needsScrollPositionClamp = va l; } | |
408 | |
358 StickyConstraintsMap& stickyConstraintsMap() { return ensureRareData().m_sti ckyConstraintsMap; } | 409 StickyConstraintsMap& stickyConstraintsMap() { return ensureRareData().m_sti ckyConstraintsMap; } |
359 void invalidateAllStickyConstraints(); | 410 void invalidateAllStickyConstraints(); |
360 void invalidateStickyConstraintsFor(PaintLayer*, bool needsCompositingUpdate = true); | 411 void invalidateStickyConstraintsFor(PaintLayer*, bool needsCompositingUpdate = true); |
361 | 412 |
362 DECLARE_VIRTUAL_TRACE(); | 413 DECLARE_VIRTUAL_TRACE(); |
363 | 414 |
364 private: | 415 private: |
365 explicit PaintLayerScrollableArea(PaintLayer&); | 416 explicit PaintLayerScrollableArea(PaintLayer&); |
366 | 417 |
367 bool hasHorizontalOverflow() const; | 418 bool hasHorizontalOverflow() const; |
368 bool hasVerticalOverflow() const; | 419 bool hasVerticalOverflow() const; |
369 bool hasScrollableHorizontalOverflow() const; | 420 bool hasScrollableHorizontalOverflow() const; |
370 bool hasScrollableVerticalOverflow() const; | 421 bool hasScrollableVerticalOverflow() const; |
371 bool visualViewportSuppliesScrollbars() const; | 422 bool visualViewportSuppliesScrollbars() const; |
372 | 423 |
373 bool needsScrollbarReconstruction() const; | 424 bool needsScrollbarReconstruction() const; |
374 | 425 |
375 void computeScrollDimensions(); | 426 void updateScrollOrigin(); |
427 void updateScrollDimensions(); | |
376 | 428 |
377 void setScrollOffset(const DoublePoint&, ScrollType) override; | 429 void setScrollOffset(const DoublePoint&, ScrollType) override; |
378 | 430 |
379 int verticalScrollbarStart(int minX, int maxX) const; | 431 int verticalScrollbarStart(int minX, int maxX) const; |
380 int horizontalScrollbarStart(int minX) const; | 432 int horizontalScrollbarStart(int minX) const; |
381 IntSize scrollbarOffset(const Scrollbar&) const; | 433 IntSize scrollbarOffset(const Scrollbar&) const; |
382 | 434 |
383 void setHasHorizontalScrollbar(bool hasScrollbar); | 435 void setHasHorizontalScrollbar(bool hasScrollbar); |
384 void setHasVerticalScrollbar(bool hasScrollbar); | 436 void setHasVerticalScrollbar(bool hasScrollbar); |
385 | 437 |
(...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 | 475 // FIXME: once cc can handle composited scrolling with clip paths, we will |
424 // no longer need this bit. | 476 // no longer need this bit. |
425 unsigned m_needsCompositedScrolling : 1; | 477 unsigned m_needsCompositedScrolling : 1; |
426 | 478 |
427 // 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 |
428 // in the next compositing update because the underlying blink::Scrollbar | 480 // in the next compositing update because the underlying blink::Scrollbar |
429 // instance has been reconstructed. | 481 // instance has been reconstructed. |
430 unsigned m_rebuildHorizontalScrollbarLayer : 1; | 482 unsigned m_rebuildHorizontalScrollbarLayer : 1; |
431 unsigned m_rebuildVerticalScrollbarLayer : 1; | 483 unsigned m_rebuildVerticalScrollbarLayer : 1; |
432 | 484 |
485 unsigned m_needsScrollPositionClamp : 1; | |
486 | |
433 // The width/height of our scrolled area. | 487 // The width/height of our scrolled area. |
434 // This is OverflowModel's layout overflow translated to physical | 488 // This is OverflowModel's layout overflow translated to physical |
435 // coordinates. See OverflowModel for the different overflow and | 489 // coordinates. See OverflowModel for the different overflow and |
436 // LayoutBoxModelObject for the coordinate systems. | 490 // LayoutBoxModelObject for the coordinate systems. |
437 LayoutRect m_overflowRect; | 491 LayoutRect m_overflowRect; |
438 | 492 |
439 // ScrollbarManager holds the Scrollbar instances. | 493 // ScrollbarManager holds the Scrollbar instances. |
440 ScrollbarManager m_scrollbarManager; | 494 ScrollbarManager m_scrollbarManager; |
441 | 495 |
442 // This is the (scroll) offset from scrollOrigin(). | 496 // This is the (scroll) offset from scrollOrigin(). |
(...skipping 16 matching lines...) Expand all Loading... | |
459 #endif | 513 #endif |
460 }; | 514 }; |
461 | 515 |
462 DEFINE_TYPE_CASTS(PaintLayerScrollableArea, ScrollableArea, scrollableArea, | 516 DEFINE_TYPE_CASTS(PaintLayerScrollableArea, ScrollableArea, scrollableArea, |
463 scrollableArea->isPaintLayerScrollableArea(), | 517 scrollableArea->isPaintLayerScrollableArea(), |
464 scrollableArea.isPaintLayerScrollableArea()); | 518 scrollableArea.isPaintLayerScrollableArea()); |
465 | 519 |
466 } // namespace blink | 520 } // namespace blink |
467 | 521 |
468 #endif // LayerScrollableArea_h | 522 #endif // LayerScrollableArea_h |
OLD | NEW |