Skip to content

Commit

Permalink
Cherry-pick 58a2cf8. rdar://problem/113605121
Browse files Browse the repository at this point in the history
    Cherry-pick e41f567. rdar://problem/110872395

        [UI-side compositing] REGRESSION: empty Mail compose window always shows a scrollbar
        https://bugs.webkit.org/show_bug.cgi?id=259323
        rdar://110872395

        Reviewed by Simon Fraser.

        To properly set NSScrollerImps as enabled in the UI-process, send accross the web
        process state from the Scrollbar class. It is also necessary to set the state in
        setScrollingNodeScrollableAreaGeometry because the first time setting this state
        on the Scrollbar class can happen before the corresponding scrollable area has been
        added to the scrolling tree.

        * Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp:
        (WebCore::AsyncScrollingCoordinator::setScrollbarEnabled):
        (WebCore::AsyncScrollingCoordinator::setScrollingNodeScrollableAreaGeometry):
        * Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h:
        * Source/WebCore/page/scrolling/ScrollingCoordinator.h:
        (WebCore::ScrollingCoordinator::setScrollbarEnabled):
        * Source/WebCore/page/scrolling/ScrollingStateNode.h:
        * Source/WebCore/page/scrolling/ScrollingStateScrollingNode.cpp:
        (WebCore::ScrollingStateScrollingNode::ScrollingStateScrollingNode):
        (WebCore::ScrollingStateScrollingNode::setScrollbarEnabledState):
        * Source/WebCore/page/scrolling/ScrollingStateScrollingNode.h:
        (WebCore::ScrollingStateScrollingNode::scrollbarEnabledState const):
        * Source/WebCore/page/scrolling/mac/ScrollerMac.h:
        (WebCore::ScrollerMac::setEnabled):
        * Source/WebCore/page/scrolling/mac/ScrollerMac.mm:
        (WebCore::ScrollerMac::updateValues):
        * Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
        (WebCore::ScrollingTreeScrollingNodeDelegateMac::updateFromStateNode):
        * Source/WebCore/platform/Scrollbar.cpp:
        (WebCore::Scrollbar::setEnabled):
        * Source/WebCore/platform/ScrollbarsController.h:
        (WebCore::ScrollbarsController::setScrollbarEnabledSate):
        * Source/WebKit/Shared/RemoteLayerTree/RemoteScrollingCoordinatorTransaction.cpp:
        (ArgumentCoder<ScrollingStateScrollingNode>::encode):
        (ArgumentCoder<ScrollingStateScrollingNode>::decode):
        * Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
        * Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollbarsController.h:
        * Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollbarsController.mm:
        (WebKit::RemoteScrollbarsController::setScrollbarEnabledSate):

        Canonical link: https://commits.webkit.org/266261@main

Identifier: 265870.263@safari-7616-branch
  • Loading branch information
nmoucht authored and MyahCobbs committed Aug 9, 2023
1 parent e297950 commit 2cefba2
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 30 deletions.
18 changes: 18 additions & 0 deletions Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,20 @@ void AsyncScrollingCoordinator::setMouseMovedInContentArea(ScrollableArea& scrol
stateNode->setMouseMovedInContentArea(state);
}

void AsyncScrollingCoordinator::setScrollbarEnabled(Scrollbar& scrollbar)
{
ASSERT(isMainThread());
ASSERT(m_page);
auto scrollingNodeID = scrollbar.scrollableArea().scrollingNodeID();
if (!scrollingNodeID)
return;

auto stateNode = dynamicDowncast<ScrollingStateScrollingNode>(m_scrollingStateTree->stateNodeForID(scrollingNodeID));
if (!stateNode)
return;
stateNode->setScrollbarEnabledState(scrollbar.orientation(), scrollbar.enabled());
}

void AsyncScrollingCoordinator::applyScrollingTreeLayerPositions()
{
m_scrollingTree->applyLayerPositions();
Expand Down Expand Up @@ -933,6 +947,10 @@ void AsyncScrollingCoordinator::setScrollingNodeScrollableAreaGeometry(Scrolling
auto* verticalScrollbar = scrollableArea.verticalScrollbar();
auto* horizontalScrollbar = scrollableArea.horizontalScrollbar();
scrollingNode->setScrollerImpsFromScrollbars(verticalScrollbar, horizontalScrollbar);
if (horizontalScrollbar)
scrollingNode->setScrollbarEnabledState(ScrollbarOrientation::Horizontal, horizontalScrollbar->enabled());
if (verticalScrollbar)
scrollingNode->setScrollbarEnabledState(ScrollbarOrientation::Vertical, verticalScrollbar->enabled());

scrollingNode->setScrollOrigin(scrollableArea.scrollOrigin());
scrollingNode->setScrollPosition(scrollableArea.scrollPosition());
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class AsyncScrollingCoordinator : public ScrollingCoordinator {
void wheelEventScrollDidEndForNode(ScrollingNodeID);

WEBCORE_EXPORT void setMouseIsOverScrollbar(Scrollbar*, bool isOverScrollbar) override;
WEBCORE_EXPORT void setScrollbarEnabled(Scrollbar&) override;

void hysterisisTimerFired(PAL::HysteresisState);

Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/page/scrolling/ScrollingCoordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class ScrollingCoordinator : public ThreadSafeRefCountedAndCanMakeThreadSafeWeak
WEBCORE_EXPORT virtual void setMouseIsOverContentArea(ScrollableArea&, bool) { }
WEBCORE_EXPORT virtual void setMouseMovedInContentArea(ScrollableArea&) { }
WEBCORE_EXPORT virtual void setMouseIsOverScrollbar(Scrollbar*, bool) { }
WEBCORE_EXPORT virtual void setScrollbarEnabled(Scrollbar&) { }

protected:
explicit ScrollingCoordinator(Page*);
Expand Down
55 changes: 28 additions & 27 deletions Source/WebCore/page/scrolling/ScrollingStateNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,37 +228,38 @@ enum class ScrollingStateNodeProperty : uint64_t {
ContentAreaHoverState = 1LLU << 19,
MouseActivityState = 1LLU << 20,
ScrollbarHoverState = 1LLU << 21,
ScrollbarEnabledState = 1LLU << 22,
// ScrollingStateFrameScrollingNode
FrameScaleFactor = 1LLU << 22,
EventTrackingRegion = 1LLU << 23,
RootContentsLayer = 1LLU << 24,
CounterScrollingLayer = 1LLU << 25,
InsetClipLayer = 1LLU << 26,
ContentShadowLayer = 1LLU << 27,
HeaderHeight = 1LLU << 28,
FooterHeight = 1LLU << 29,
HeaderLayer = 1LLU << 30,
FooterLayer = 1LLU << 31,
BehaviorForFixedElements = 1LLU << 32,
TopContentInset = 1LLU << 33,
FixedElementsLayoutRelativeToFrame = 1LLU << 34,
VisualViewportIsSmallerThanLayoutViewport = 1LLU << 35,
AsyncFrameOrOverflowScrollingEnabled = 1LLU << 36,
WheelEventGesturesBecomeNonBlocking = 1LLU << 37,
ScrollingPerformanceTestingEnabled = 1LLU << 38,
LayoutViewport = 1LLU << 39,
MinLayoutViewportOrigin = 1LLU << 40,
MaxLayoutViewportOrigin = 1LLU << 41,
OverrideVisualViewportSize = 1LLU << 42,
OverlayScrollbarsEnabled = 1LLU << 43,
FrameScaleFactor = 1LLU << 23,
EventTrackingRegion = 1LLU << 24,
RootContentsLayer = 1LLU << 25,
CounterScrollingLayer = 1LLU << 26,
InsetClipLayer = 1LLU << 27,
ContentShadowLayer = 1LLU << 28,
HeaderHeight = 1LLU << 29,
FooterHeight = 1LLU << 30,
HeaderLayer = 1LLU << 31,
FooterLayer = 1LLU << 32,
BehaviorForFixedElements = 1LLU << 33,
TopContentInset = 1LLU << 34,
FixedElementsLayoutRelativeToFrame = 1LLU << 35,
VisualViewportIsSmallerThanLayoutViewport = 1LLU << 36,
AsyncFrameOrOverflowScrollingEnabled = 1LLU << 37,
WheelEventGesturesBecomeNonBlocking = 1LLU << 38,
ScrollingPerformanceTestingEnabled = 1LLU << 39,
LayoutViewport = 1LLU << 40,
MinLayoutViewportOrigin = 1LLU << 41,
MaxLayoutViewportOrigin = 1LLU << 42,
OverrideVisualViewportSize = 1LLU << 43,
OverlayScrollbarsEnabled = 1LLU << 44,
// ScrollingStatePositionedNode
RelatedOverflowScrollingNodes = 1LLU << 44,
LayoutConstraintData = 1LLU << 45,
RelatedOverflowScrollingNodes = 1LLU << 45,
LayoutConstraintData = 1LLU << 46,
// ScrollingStateFixedNode, ScrollingStateStickyNode
ViewportConstraints = 1LLU << 46,
ViewportConstraints = 1LLU << 47,
// ScrollingStateOverflowScrollProxyNode
OverflowScrollingNode = 1LLU << 47,
KeyboardScrollData = 1LLU << 48,
OverflowScrollingNode = 1LLU << 48,
KeyboardScrollData = 1LLU << 49,
};

class ScrollingStateNode : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr<ScrollingStateNode> {
Expand Down
14 changes: 14 additions & 0 deletions Source/WebCore/page/scrolling/ScrollingStateScrollingNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ScrollingStateScrollingNode::ScrollingStateScrollingNode(const ScrollingStateScr
#if PLATFORM(MAC)
, m_scrollbarHoverState(stateNode.scrollbarHoverState())
, m_mouseLocationState(stateNode.mouseLocationState())
, m_scrollbarEnabledState(stateNode.scrollbarEnabledState())
, m_verticalScrollerImp(stateNode.verticalScrollerImp())
, m_horizontalScrollerImp(stateNode.horizontalScrollerImp())
#endif
Expand Down Expand Up @@ -302,6 +303,19 @@ void ScrollingStateScrollingNode::setScrollbarHoverState(ScrollbarHoverState hov
setPropertyChanged(Property::ScrollbarHoverState);
}

void ScrollingStateScrollingNode::setScrollbarEnabledState(ScrollbarOrientation orientation, bool enabled)
{
if ((orientation == ScrollbarOrientation::Horizontal ? m_scrollbarEnabledState.horizontalScrollbarIsEnabled : m_scrollbarEnabledState.verticalScrollbarIsEnabled) == enabled)
return;

if (orientation == ScrollbarOrientation::Horizontal)
m_scrollbarEnabledState.horizontalScrollbarIsEnabled = enabled;
else
m_scrollbarEnabledState.verticalScrollbarIsEnabled = enabled;

setPropertyChanged(Property::ScrollbarEnabledState);
}

void ScrollingStateScrollingNode::dumpProperties(TextStream& ts, OptionSet<ScrollingStateTreeAsTextBehavior> behavior) const
{
ScrollingStateNode::dumpProperties(ts, behavior);
Expand Down
9 changes: 9 additions & 0 deletions Source/WebCore/page/scrolling/ScrollingStateScrollingNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ struct MouseLocationState {
IntPoint locationInVerticalScrollbar;
};

struct ScrollbarEnabledState {
bool horizontalScrollbarIsEnabled { false };
bool verticalScrollbarIsEnabled { false };
};

class ScrollingStateScrollingNode : public ScrollingStateNode {
public:
virtual ~ScrollingStateScrollingNode();
Expand Down Expand Up @@ -124,6 +129,9 @@ class ScrollingStateScrollingNode : public ScrollingStateNode {
ScrollbarHoverState scrollbarHoverState() const { return m_scrollbarHoverState; }
WEBCORE_EXPORT void setScrollbarHoverState(ScrollbarHoverState);

ScrollbarEnabledState scrollbarEnabledState() const { return m_scrollbarEnabledState; }
WEBCORE_EXPORT void setScrollbarEnabledState(ScrollbarOrientation, bool);

void setScrollerImpsFromScrollbars(Scrollbar* verticalScrollbar, Scrollbar* horizontalScrollbar);

WEBCORE_EXPORT void setMouseIsOverContentArea(bool);
Expand Down Expand Up @@ -157,6 +165,7 @@ class ScrollingStateScrollingNode : public ScrollingStateNode {

ScrollbarHoverState m_scrollbarHoverState;
MouseLocationState m_mouseLocationState;
ScrollbarEnabledState m_scrollbarEnabledState;

#if PLATFORM(MAC)
RetainPtr<NSScrollerImp> m_verticalScrollerImp;
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/page/scrolling/mac/ScrollerMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ class ScrollerMac {
void visibilityChanged(bool);
void updateMinimumKnobLength(int);
void detach();
void setEnabled(bool flag) { m_isEnabled = flag; }

private:
int m_minimumKnobLength { 0 };

bool m_isEnabled { false };
bool m_isVisible { false };

ScrollerPairMac& m_pair;
const ScrollbarOrientation m_orientation;
IntPoint m_lastKnownMousePositionInScrollbar;
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/page/scrolling/mac/ScrollerMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ - (void)invalidate
auto values = m_pair.valuesForOrientation(m_orientation);

BEGIN_BLOCK_OBJC_EXCEPTIONS

[m_scrollerImp setEnabled:!!m_hostLayer];
[m_scrollerImp setEnabled:m_isEnabled];
[m_scrollerImp setBoundsSize:NSSizeFromCGSize([m_hostLayer bounds].size)];
[m_scrollerImp setDoubleValue:values.value];
[m_scrollerImp setPresentationValue:values.value];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@
if (scrollingStateNode.scrollableAreaParameters().verticalNativeScrollbarVisibility != NativeScrollbarVisibility::Visible)
m_scrollerPair->verticalScroller().setHostLayer(nullptr);
}


if (scrollingStateNode.hasChangedProperty(ScrollingStateNode::Property::ScrollbarEnabledState)) {
auto scrollbarEnabledState = scrollingStateNode.scrollbarEnabledState();
m_scrollerPair->horizontalScroller().setEnabled(scrollbarEnabledState.horizontalScrollbarIsEnabled);
m_scrollerPair->verticalScroller().setEnabled(scrollbarEnabledState.verticalScrollbarIsEnabled);
}

if (scrollingStateNode.hasChangedProperty(ScrollingStateNode::Property::ContentAreaHoverState)) {
if (scrollingStateNode.mouseIsOverContentArea())
m_scrollerPair->mouseEnteredContentArea();
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/Scrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ void Scrollbar::setEnabled(bool e)
return;
m_enabled = e;
theme().updateEnabledState(*this);
m_scrollableArea.scrollbarsController().updateScrollbarEnabledState(*this);
invalidate();
}

Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/ScrollbarsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ScrollbarsController {

WEBCORE_EXPORT virtual bool shouldDrawIntoScrollbarLayer(Scrollbar&) const { return true; }
WEBCORE_EXPORT virtual bool shouldRegisterScrollbars() const { return true; }
WEBCORE_EXPORT virtual void updateScrollbarEnabledState(Scrollbar&) { }

WEBCORE_EXPORT virtual void setScrollbarMinimumThumbLength(WebCore::ScrollbarOrientation, int) { }
WEBCORE_EXPORT virtual int minimumThumbLength(WebCore::ScrollbarOrientation) { return 0; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ void ArgumentCoder<ScrollingStateScrollingNode>::encode(Encoder& encoder, const
encoder << mouseLocationState.locationInHorizontalScrollbar;
encoder << mouseLocationState.locationInVerticalScrollbar;
}

if (node.hasChangedProperty(ScrollingStateNode::Property::ScrollbarEnabledState)) {
auto scrollbarEnabledState = node.scrollbarEnabledState();
encoder << scrollbarEnabledState.horizontalScrollbarIsEnabled;
encoder << scrollbarEnabledState.verticalScrollbarIsEnabled;
}
}

void ArgumentCoder<ScrollingStateFrameScrollingNode>::encode(Encoder& encoder, const ScrollingStateFrameScrollingNode& node)
Expand Down Expand Up @@ -322,6 +328,18 @@ bool ArgumentCoder<ScrollingStateScrollingNode>::decode(Decoder& decoder, Scroll
node.setMouseMovedInContentArea({ locationInHorizontalScrollbar, locationInVerticalScrollbar });
}

if (node.hasChangedProperty(ScrollingStateNode::Property::ScrollbarEnabledState)) {
bool horizontalScrollbarEnabled;
if (!decoder.decode(horizontalScrollbarEnabled))
return false;

bool verticalScrollbarEnabled;
if (!decoder.decode(verticalScrollbarEnabled))
return false;
node.setScrollbarEnabledState(ScrollbarOrientation::Horizontal, horizontalScrollbarEnabled);
node.setScrollbarEnabledState(ScrollbarOrientation::Vertical, verticalScrollbarEnabled);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3106,6 +3106,7 @@ header: <WebCore/ScrollingStateNode.h>
ContentAreaHoverState
MouseActivityState
ScrollbarHoverState
ScrollbarEnabledState
FrameScaleFactor
EventTrackingRegion
RootContentsLayer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RemoteScrollbarsController final : public WebCore::ScrollbarsController {
bool shouldDrawIntoScrollbarLayer(WebCore::Scrollbar&) const final;
bool shouldRegisterScrollbars() const final { return scrollableArea().isListBox(); }
int minimumThumbLength(WebCore::ScrollbarOrientation) final;
void updateScrollbarEnabledState(WebCore::Scrollbar&) final;

private:
bool m_horizontalOverlayScrollbarIsVisible { false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,11 @@
return orientation == WebCore::ScrollbarOrientation::Horizontal ? m_horizontalMinimumThumbLength : m_verticalMinimumThumbLength;
}

void RemoteScrollbarsController::updateScrollbarEnabledState(WebCore::Scrollbar& scrollbar)
{
if (auto scrollingCoordinator = m_coordinator.get())
scrollingCoordinator->setScrollbarEnabled(scrollbar);
}

}
#endif // PLATFORM(MAC)

0 comments on commit 2cefba2

Please sign in to comment.