Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement scrollbar-gutter on viewports #15459

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 31 additions & 3 deletions Source/WebCore/platform/ScrollView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "PlatformWheelEvent.h"
#include "ScrollAnimator.h"
#include "Scrollbar.h"
#include "ScrollbarGutter.h"
#include "ScrollbarTheme.h"
#include <wtf/HexNumber.h>
#include <wtf/SetForScope.h>
Expand Down Expand Up @@ -441,7 +442,7 @@ void ScrollView::cacheCurrentScrollState()
ScrollPosition ScrollView::documentScrollPositionRelativeToViewOrigin() const
{
return scrollPosition() - IntSize(
shouldPlaceVerticalScrollbarOnLeft() && m_verticalScrollbar ? m_verticalScrollbar->occupiedWidth() : 0,
(shouldPlaceVerticalScrollbarOnLeft() || scrollbarGutterStyle().bothEdges) ? verticalScrollbarWidth() : 0,
headerHeight() + topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset));
}

Expand Down Expand Up @@ -839,6 +840,33 @@ IntRect ScrollView::rectToCopyOnScroll() const
return scrollViewRect;
}

int ScrollView::verticalScrollbarWidth(bool isHorizontalWritingMode) const
{
WTFLogAlways("Test");
// TODO should this check overlay scrollbars and return width at the end not occupiedWidth

if (!m_verticalScrollbar && !(scrollbarGutterStyle().isAuto || ScrollbarTheme::theme().usesOverlayScrollbars()) && isHorizontalWritingMode)
return ScrollbarTheme::theme().scrollbarThickness(scrollbarWidthStyle());

if (!m_verticalScrollbar)
return 0;

return m_verticalScrollbar->occupiedWidth();
}

int ScrollView::horizontalScrollbarHeight(bool isHorizontalWritingMode) const
{
// TODO should this check overlay scrollbars and return height at the end not occupiedHeight

if (!m_horizontalScrollbar && !(scrollbarGutterStyle().isAuto || ScrollbarTheme::theme().usesOverlayScrollbars()) && !isHorizontalWritingMode)
return ScrollbarTheme::theme().scrollbarThickness(scrollbarWidthStyle());

if (!m_horizontalScrollbar)
return 0;

return m_horizontalScrollbar->occupiedHeight();
}

void ScrollView::scrollContents(const IntSize& scrollDelta)
{
HostWindow* window = hostWindow();
Expand Down Expand Up @@ -1613,8 +1641,8 @@ void ScrollView::styleAndRenderTreeDidChange()
IntPoint ScrollView::locationOfContents() const
{
IntPoint result = location();
if (shouldPlaceVerticalScrollbarOnLeft() && m_verticalScrollbar)
result.move(m_verticalScrollbar->occupiedWidth(), 0);
if ((shouldPlaceVerticalScrollbarOnLeft() || scrollbarGutterStyle().bothEdges))
result.move(verticalScrollbarWidth(), 0);
return result;
}

Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/platform/ScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class ScrollView : public Widget, public ScrollableArea {
void setVerticalScrollbarLock(bool lock = true) { m_verticalScrollbarLock = lock; }
bool verticalScrollbarLock() const { return m_verticalScrollbarLock; }

int verticalScrollbarWidth(bool isHorizontalWritingMode = true) const;
int horizontalScrollbarHeight(bool isHorizontalWritingMode = true) const;

void setScrollingModesLock(bool lock = true) { m_horizontalScrollbarLock = m_verticalScrollbarLock = lock; }

WEBCORE_EXPORT virtual void setCanHaveScrollbars(bool);
Expand Down
16 changes: 14 additions & 2 deletions Source/WebCore/rendering/RenderBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,18 @@ bool RenderBox::fixedElementLaysOutRelativeToFrame(const LocalFrameView& frameVi

bool RenderBox::includeVerticalScrollbarSize() const
{
return hasNonVisibleOverflow() && layer() && !layer()->hasOverlayScrollbars()
&& (style().overflowY() == Overflow::Scroll || style().overflowY() == Overflow::Auto
if (layer() && layer()->hasOverlayScrollbars())
return false;

if (hasNonVisibleOverflow()) {
return (style().overflowY() == Overflow::Scroll || style().overflowY() == Overflow::Auto
|| (style().overflowY() == Overflow::Hidden && !style().scrollbarGutter().isAuto));
}

if (isDocumentElementRenderer())
return !style().scrollbarGutter().isAuto;

return false;
}

bool RenderBox::includeHorizontalScrollbarSize() const
Expand All @@ -935,6 +944,9 @@ int RenderBox::verticalScrollbarWidth() const
auto* scrollableArea = layer() ? layer()->scrollableArea() : nullptr;
if (!scrollableArea)
return 0;

if (isDocumentElementRenderer())
return includeVerticalScrollbarSize() ? view().frameView().verticalScrollbarWidth(isHorizontalWritingMode()) : 0;
return includeVerticalScrollbarSize() ? scrollableArea->verticalScrollbarWidth(IgnoreOverlayScrollbarSize, isHorizontalWritingMode()) : 0;
}

Expand Down