Title: [278527] trunk/Source/WebCore
- Revision
- 278527
- Author
- [email protected]
- Date
- 2021-06-05 15:54:07 -0700 (Sat, 05 Jun 2021)
Log Message
Remove some duplicated code related to scrollbars
https://bugs.webkit.org/show_bug.cgi?id=226685
Reviewed by Alan Bujtas.
RenderLayerScrollableArea and RenderBox had some very similar code related to
computing whether scrollbars are present, so remove the duplication, and prepare
for ScrollbarOrientation to become an enum class.
* rendering/RenderBox.cpp:
(WebCore::RenderBox::hasAutoScrollbar const):
(WebCore::RenderBox::hasAlwaysPresentScrollbar const):
(WebCore::RenderBox::hasVerticalScrollbarWithAutoBehavior const): Deleted.
(WebCore::RenderBox::hasHorizontalScrollbarWithAutoBehavior const): Deleted.
* rendering/RenderBox.h:
* rendering/RenderLayerScrollableArea.cpp:
(WebCore::RenderLayerScrollableArea::updateScrollbarsAfterLayout):
(WebCore::RenderLayerScrollableArea::updateScrollbarsAfterStyleChange):
(WebCore::styleRequiresScrollbar): Deleted.
(WebCore::styleDefinesAutomaticScrollbar): Deleted.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (278526 => 278527)
--- trunk/Source/WebCore/ChangeLog 2021-06-05 21:18:30 UTC (rev 278526)
+++ trunk/Source/WebCore/ChangeLog 2021-06-05 22:54:07 UTC (rev 278527)
@@ -1,3 +1,26 @@
+2021-06-05 Simon Fraser <[email protected]>
+
+ Remove some duplicated code related to scrollbars
+ https://bugs.webkit.org/show_bug.cgi?id=226685
+
+ Reviewed by Alan Bujtas.
+
+ RenderLayerScrollableArea and RenderBox had some very similar code related to
+ computing whether scrollbars are present, so remove the duplication, and prepare
+ for ScrollbarOrientation to become an enum class.
+
+ * rendering/RenderBox.cpp:
+ (WebCore::RenderBox::hasAutoScrollbar const):
+ (WebCore::RenderBox::hasAlwaysPresentScrollbar const):
+ (WebCore::RenderBox::hasVerticalScrollbarWithAutoBehavior const): Deleted.
+ (WebCore::RenderBox::hasHorizontalScrollbarWithAutoBehavior const): Deleted.
+ * rendering/RenderBox.h:
+ * rendering/RenderLayerScrollableArea.cpp:
+ (WebCore::RenderLayerScrollableArea::updateScrollbarsAfterLayout):
+ (WebCore::RenderLayerScrollableArea::updateScrollbarsAfterStyleChange):
+ (WebCore::styleRequiresScrollbar): Deleted.
+ (WebCore::styleDefinesAutomaticScrollbar): Deleted.
+
2021-06-04 Dean Jackson <[email protected]>
[WebXR] WebXR on Cocoa doesn't work with webgl 1 contexts
Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (278526 => 278527)
--- trunk/Source/WebCore/rendering/RenderBox.cpp 2021-06-05 21:18:30 UTC (rev 278526)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp 2021-06-05 22:54:07 UTC (rev 278527)
@@ -1063,14 +1063,40 @@
return !style().hasPseudoStyle(PseudoId::Scrollbar) && ScrollbarTheme::theme().usesOverlayScrollbars();
}
-bool RenderBox::hasVerticalScrollbarWithAutoBehavior() const
+bool RenderBox::hasAutoScrollbar(ScrollbarOrientation orientation) const
{
- return hasOverflowClip() && (style().overflowY() == Overflow::Auto || (style().overflowY() == Overflow::Scroll && canUseOverlayScrollbars()));
+ if (!hasOverflowClip())
+ return false;
+
+ auto isAutoOrScrollWithOverlayScrollbar = [&](Overflow overflow) {
+ return overflow == Overflow::Auto || (overflow == Overflow::Scroll && canUseOverlayScrollbars());
+ };
+
+ switch (orientation) {
+ case ScrollbarOrientation::HorizontalScrollbar:
+ return isAutoOrScrollWithOverlayScrollbar(style().overflowX());
+ case ScrollbarOrientation::VerticalScrollbar:
+ return isAutoOrScrollWithOverlayScrollbar(style().overflowY());
+ }
+ return false;
}
-bool RenderBox::hasHorizontalScrollbarWithAutoBehavior() const
+bool RenderBox::hasAlwaysPresentScrollbar(ScrollbarOrientation orientation) const
{
- return hasOverflowClip() && (style().overflowX() == Overflow::Auto || (style().overflowX() == Overflow::Scroll && canUseOverlayScrollbars()));
+ if (!hasOverflowClip())
+ return false;
+
+ auto isAlwaysVisibleScrollbar = [&](Overflow overflow) {
+ return overflow == Overflow::Scroll && !canUseOverlayScrollbars();
+ };
+
+ switch (orientation) {
+ case ScrollbarOrientation::HorizontalScrollbar:
+ return isAlwaysVisibleScrollbar(style().overflowX());
+ case ScrollbarOrientation::VerticalScrollbar:
+ return isAlwaysVisibleScrollbar(style().overflowY());
+ }
+ return false;
}
bool RenderBox::needsPreferredWidthsRecalculation() const
Modified: trunk/Source/WebCore/rendering/RenderBox.h (278526 => 278527)
--- trunk/Source/WebCore/rendering/RenderBox.h 2021-06-05 21:18:30 UTC (rev 278526)
+++ trunk/Source/WebCore/rendering/RenderBox.h 2021-06-05 22:54:07 UTC (rev 278527)
@@ -485,10 +485,9 @@
virtual void stopAutoscroll() { }
virtual void panScroll(const IntPoint&);
- bool hasVerticalScrollbarWithAutoBehavior() const;
- bool hasHorizontalScrollbarWithAutoBehavior() const;
-
bool canUseOverlayScrollbars() const;
+ bool hasAutoScrollbar(ScrollbarOrientation) const;
+ bool hasAlwaysPresentScrollbar(ScrollbarOrientation) const;
bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
bool scrollsOverflowX() const { return hasOverflowClip() && (style().overflowX() == Overflow::Scroll || style().overflowX() == Overflow::Auto); }
Modified: trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp (278526 => 278527)
--- trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp 2021-06-05 21:18:30 UTC (rev 278526)
+++ trunk/Source/WebCore/rendering/RenderLayerScrollableArea.cpp 2021-06-05 22:54:07 UTC (rev 278527)
@@ -1063,20 +1063,6 @@
return scrollHeight() > roundToInt(m_layer.renderBox()->clientHeight());
}
-static bool styleRequiresScrollbar(const RenderStyle& style, ScrollbarOrientation axis)
-{
- Overflow overflow = axis == ScrollbarOrientation::HorizontalScrollbar ? style.overflowX() : style.overflowY();
- bool overflowScrollActsLikeAuto = overflow == Overflow::Scroll && !style.hasPseudoStyle(PseudoId::Scrollbar) && ScrollbarTheme::theme().usesOverlayScrollbars();
- return overflow == Overflow::Scroll && !overflowScrollActsLikeAuto;
-}
-
-static bool styleDefinesAutomaticScrollbar(const RenderStyle& style, ScrollbarOrientation axis)
-{
- Overflow overflow = axis == ScrollbarOrientation::HorizontalScrollbar ? style.overflowX() : style.overflowY();
- bool overflowScrollActsLikeAuto = overflow == Overflow::Scroll && !style.hasPseudoStyle(PseudoId::Scrollbar) && ScrollbarTheme::theme().usesOverlayScrollbars();
- return overflow == Overflow::Auto || overflowScrollActsLikeAuto;
-}
-
void RenderLayerScrollableArea::updateScrollbarsAfterLayout()
{
RenderBox* box = m_layer.renderBox();
@@ -1091,19 +1077,19 @@
// If overflow requires a scrollbar, then we just need to enable or disable.
auto& renderer = m_layer.renderer();
- if (m_hBar && styleRequiresScrollbar(renderer.style(), HorizontalScrollbar))
+ if (m_hBar && box->hasAlwaysPresentScrollbar(ScrollbarOrientation::HorizontalScrollbar))
m_hBar->setEnabled(hasHorizontalOverflow);
- if (m_vBar && styleRequiresScrollbar(renderer.style(), VerticalScrollbar))
+ if (m_vBar && box->hasAlwaysPresentScrollbar(ScrollbarOrientation::VerticalScrollbar))
m_vBar->setEnabled(hasVerticalOverflow);
// Scrollbars with auto behavior may need to lay out again if scrollbars got added or removed.
- bool autoHorizontalScrollBarChanged = box->hasHorizontalScrollbarWithAutoBehavior() && (hasHorizontalScrollbar() != hasHorizontalOverflow);
- bool autoVerticalScrollBarChanged = box->hasVerticalScrollbarWithAutoBehavior() && (hasVerticalScrollbar() != hasVerticalOverflow);
+ bool autoHorizontalScrollBarChanged = box->hasAutoScrollbar(ScrollbarOrientation::HorizontalScrollbar) && (hasHorizontalScrollbar() != hasHorizontalOverflow);
+ bool autoVerticalScrollBarChanged = box->hasAutoScrollbar(ScrollbarOrientation::VerticalScrollbar) && (hasVerticalScrollbar() != hasVerticalOverflow);
if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged) {
- if (box->hasHorizontalScrollbarWithAutoBehavior())
+ if (box->hasAutoScrollbar(ScrollbarOrientation::HorizontalScrollbar))
setHasHorizontalScrollbar(hasHorizontalOverflow);
- if (box->hasVerticalScrollbarWithAutoBehavior())
+ if (box->hasAutoScrollbar(ScrollbarOrientation::VerticalScrollbar))
setHasVerticalScrollbar(hasVerticalOverflow);
if (autoVerticalScrollBarChanged && shouldPlaceVerticalScrollbarOnLeft())
@@ -1567,8 +1553,8 @@
// To avoid doing a relayout in updateScrollbarsAfterLayout, we try to keep any automatic scrollbar that was already present.
bool hadVerticalScrollbar = m_vBar;
- bool needsHorizontalScrollbar = box->hasOverflowClip() && ((m_hBar && styleDefinesAutomaticScrollbar(box->style(), HorizontalScrollbar)) || styleRequiresScrollbar(box->style(), HorizontalScrollbar));
- bool needsVerticalScrollbar = box->hasOverflowClip() && ((m_vBar && styleDefinesAutomaticScrollbar(box->style(), VerticalScrollbar)) || styleRequiresScrollbar(box->style(), VerticalScrollbar));
+ bool needsHorizontalScrollbar = (m_hBar && box->hasAutoScrollbar(ScrollbarOrientation::HorizontalScrollbar)) || box->hasAlwaysPresentScrollbar(ScrollbarOrientation::HorizontalScrollbar);
+ bool needsVerticalScrollbar = (m_vBar && box->hasAutoScrollbar(ScrollbarOrientation::VerticalScrollbar)) || box->hasAlwaysPresentScrollbar(ScrollbarOrientation::VerticalScrollbar);
setHasHorizontalScrollbar(needsHorizontalScrollbar);
setHasVerticalScrollbar(needsVerticalScrollbar);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes