Skip to content

Commit 38b3703

Browse files
committed
RTL scrollbar has incorrect spacing for content added with delay
https://bugs.webkit.org/show_bug.cgi?id=284713 rdar://141556436 Reviewed by Simon Fraser. This patch works around a couple of AppKit issues, where setting the user direction when there isn't a host layer causes that setting to be lost, and setting the user direction doesn't immediately update. * Source/WebCore/page/scrolling/mac/ScrollerMac.h: * Source/WebCore/page/scrolling/mac/ScrollerMac.mm: (WebCore::ScrollerMac::updateValues): (WebCore::ScrollerMac::setScrollbarLayoutDirection): Canonical link: https://commits.webkit.org/292177@main
1 parent 1e164ea commit 38b3703

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Test that rtl bit is set on scrollbar for rtl scrollable area when set with delay
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS Scrollbar state: enabled,RTL
7+
PASS successfullyParsed is true
8+
9+
TEST COMPLETE
10+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE html> <!-- webkit-test-runner [ MockScrollbarsEnabled=false AsyncOverflowScrollingEnabled=true ] -->
2+
<html dir="rtl">
3+
<head>
4+
<style>
5+
.scroller {
6+
margin: 10px;
7+
width: 200px;
8+
height: 200px;
9+
border: 1px solid black;
10+
overflow: auto;
11+
}
12+
.contents {
13+
width: 100%;
14+
height: 200%;
15+
}
16+
</style>
17+
<script src="../../../../resources/js-test.js"></script>
18+
<script src="../../../../resources/ui-helper.js"></script>
19+
20+
<script>
21+
jsTestIsAsync = true;
22+
23+
if (window.internals)
24+
internals.setUsesOverlayScrollbars(true);
25+
26+
async function doTest()
27+
{
28+
description('Test that rtl bit is set on scrollbar for rtl scrollable area when set with delay');
29+
document.body.style.height = "1000px";
30+
31+
if (!window.internals) {
32+
finishJSTest();
33+
return;
34+
}
35+
36+
await UIHelper.waitForConditionAsync(async () => {
37+
let state = await UIHelper.verticalScrollbarState();
38+
let isRTL = state.indexOf('RTL') != -1;
39+
if (isRTL)
40+
testPassed('Scrollbar state: ' + state);
41+
return isRTL;
42+
});
43+
44+
finishJSTest();
45+
}
46+
47+
window.addEventListener('load', () => {
48+
setTimeout(() => {
49+
doTest();
50+
}, 500);
51+
}, false);
52+
</script>
53+
</head>
54+
<body>
55+
</body>
56+
</html>

Source/WebCore/page/scrolling/mac/ScrollerMac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ScrollerMac {
8989
ScrollerPairMac& m_pair;
9090
const ScrollbarOrientation m_orientation;
9191
IntPoint m_lastKnownMousePositionInScrollbar;
92+
UserInterfaceLayoutDirection m_scrollbarLayoutDirection { UserInterfaceLayoutDirection::LTR };
9293

9394
RetainPtr<CALayer> m_hostLayer;
9495
RetainPtr<NSScrollerImp> m_scrollerImp;

Source/WebCore/page/scrolling/mac/ScrollerMac.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ - (void)invalidate
370370

371371
BEGIN_BLOCK_OBJC_EXCEPTIONS
372372
[m_scrollerImp setEnabled:m_isEnabled];
373+
[m_scrollerImp setUserInterfaceLayoutDirection: m_scrollbarLayoutDirection == UserInterfaceLayoutDirection::RTL ? NSUserInterfaceLayoutDirectionRightToLeft : NSUserInterfaceLayoutDirectionLeftToRight];
373374
[m_scrollerImp setBoundsSize:NSSizeFromCGSize([m_hostLayer bounds].size)];
374375
[m_scrollerImp setDoubleValue:values.value];
375376
[m_scrollerImp setPresentationValue:values.value];
@@ -465,6 +466,11 @@ - (void)invalidate
465466

466467
void ScrollerMac::setScrollbarLayoutDirection(UserInterfaceLayoutDirection scrollbarLayoutDirection)
467468
{
469+
if (m_scrollbarLayoutDirection == scrollbarLayoutDirection)
470+
return;
471+
472+
m_scrollbarLayoutDirection = scrollbarLayoutDirection;
473+
updateScrollbarStyle();
468474
[m_scrollerImp setUserInterfaceLayoutDirection: scrollbarLayoutDirection == UserInterfaceLayoutDirection::RTL ? NSUserInterfaceLayoutDirectionRightToLeft : NSUserInterfaceLayoutDirectionLeftToRight];
469475
}
470476

0 commit comments

Comments
 (0)