- Revision
- 237466
- Author
- [email protected]
- Date
- 2018-10-26 10:47:10 -0700 (Fri, 26 Oct 2018)
Log Message
Use dark appearance scrollbar when page background is dark or document supports dark mode.
https://bugs.webkit.org/show_bug.cgi?id=190937
rdar://problem/41225839
Reviewed by Beth Dakin.
Source/WebCore:
* page/FrameView.cpp:
(WebCore::FrameView::useDarkAppearance const): Added. Ask the document.
(WebCore::FrameView::paintScrollCorner): Set LocalDefaultSystemAppearance based
on the scrollbar overlay style too.
* page/FrameView.h:
* platform/ScrollableArea.h:
(WebCore::ScrollableArea::useDarkAppearance const): Added. Default to false.
* platform/mac/ScrollAnimatorMac.mm:
(-[WebScrollerImpDelegate effectiveAppearanceForScrollerImp:]): Added.
Ask the ScrollableArea if a dark appearance is desired.
Source/WebCore/PAL:
* pal/spi/mac/NSScrollerImpSPI.h: Added effectiveAppearanceForScrollerImp:.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (237465 => 237466)
--- trunk/Source/WebCore/ChangeLog 2018-10-26 17:44:38 UTC (rev 237465)
+++ trunk/Source/WebCore/ChangeLog 2018-10-26 17:47:10 UTC (rev 237466)
@@ -1,3 +1,22 @@
+2018-10-26 Timothy Hatcher <[email protected]>
+
+ Use dark appearance scrollbar when page background is dark or document supports dark mode.
+ https://bugs.webkit.org/show_bug.cgi?id=190937
+ rdar://problem/41225839
+
+ Reviewed by Beth Dakin.
+
+ * page/FrameView.cpp:
+ (WebCore::FrameView::useDarkAppearance const): Added. Ask the document.
+ (WebCore::FrameView::paintScrollCorner): Set LocalDefaultSystemAppearance based
+ on the scrollbar overlay style too.
+ * page/FrameView.h:
+ * platform/ScrollableArea.h:
+ (WebCore::ScrollableArea::useDarkAppearance const): Added. Default to false.
+ * platform/mac/ScrollAnimatorMac.mm:
+ (-[WebScrollerImpDelegate effectiveAppearanceForScrollerImp:]): Added.
+ Ask the ScrollableArea if a dark appearance is desired.
+
2018-10-26 Antti Koivisto <[email protected]>
Use random() instead of begin() to limit cache sizes
Modified: trunk/Source/WebCore/PAL/ChangeLog (237465 => 237466)
--- trunk/Source/WebCore/PAL/ChangeLog 2018-10-26 17:44:38 UTC (rev 237465)
+++ trunk/Source/WebCore/PAL/ChangeLog 2018-10-26 17:47:10 UTC (rev 237466)
@@ -1,3 +1,13 @@
+2018-10-26 Timothy Hatcher <[email protected]>
+
+ Use dark appearance scrollbar when page background is dark or document supports dark mode.
+ https://bugs.webkit.org/show_bug.cgi?id=190937
+ rdar://problem/41225839
+
+ Reviewed by Beth Dakin.
+
+ * pal/spi/mac/NSScrollerImpSPI.h: Added effectiveAppearanceForScrollerImp:.
+
2018-10-26 Jer Noble <[email protected]>
Adopt -setOverrideRouteSharingPolicy:routingContextUID: SPI
Modified: trunk/Source/WebCore/PAL/pal/spi/mac/NSScrollerImpSPI.h (237465 => 237466)
--- trunk/Source/WebCore/PAL/pal/spi/mac/NSScrollerImpSPI.h 2018-10-26 17:44:38 UTC (rev 237465)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/NSScrollerImpSPI.h 2018-10-26 17:47:10 UTC (rev 237466)
@@ -106,6 +106,7 @@
- (NSPoint)mouseLocationInScrollerForScrollerImp:(NSScrollerImp *)scrollerImp;
- (NSRect)convertRectToLayer:(NSRect)aRect;
- (BOOL)shouldUseLayerPerPartForScrollerImp:(NSScrollerImp *)scrollerImp;
+- (NSAppearance *)effectiveAppearanceForScrollerImp:(NSScrollerImp *)scrollerImp;
@end
@protocol NSScrollerImpPairDelegate;
Modified: trunk/Source/WebCore/page/FrameView.cpp (237465 => 237466)
--- trunk/Source/WebCore/page/FrameView.cpp 2018-10-26 17:44:38 UTC (rev 237465)
+++ trunk/Source/WebCore/page/FrameView.cpp 2018-10-26 17:47:10 UTC (rev 237466)
@@ -118,6 +118,10 @@
#include "LegacyTileCache.h"
#endif
+#if PLATFORM(MAC)
+#include "LocalDefaultSystemAppearance.h"
+#endif
+
#define RELEASE_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(frame().page() && frame().page()->isAlwaysOnLoggingAllowed(), Layout, "%p - FrameView::" fmt, this, ##__VA_ARGS__)
namespace WebCore {
@@ -2035,6 +2039,13 @@
return page && page->isVisible() && page->focusController().isActive();
}
+bool FrameView::useDarkAppearance() const
+{
+ ASSERT(frame().document());
+ auto& document = *frame().document();
+ return document.useDarkAppearance();
+}
+
bool FrameView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
{
if (!m_viewportConstrainedObjects || m_viewportConstrainedObjects->isEmpty()) {
@@ -3892,6 +3903,14 @@
return;
}
+#if PLATFORM(MAC)
+ // If dark appearance is used or the overlay style is light (because of a dark page background), set the dark apppearance.
+ // Keep this in sync with ScrollAnimatorMac's effectiveAppearanceForScrollerImp:.
+ auto* document = frame().document();
+ bool useDarkAppearance = (document && document->useDarkAppearance()) || scrollbarOverlayStyle() == WebCore::ScrollbarOverlayStyleLight;
+ LocalDefaultSystemAppearance localAppearance(useDarkAppearance);
+#endif
+
ScrollView::paintScrollCorner(context, cornerRect);
}
Modified: trunk/Source/WebCore/page/FrameView.h (237465 => 237466)
--- trunk/Source/WebCore/page/FrameView.h 2018-10-26 17:44:38 UTC (rev 237465)
+++ trunk/Source/WebCore/page/FrameView.h 2018-10-26 17:47:10 UTC (rev 237466)
@@ -507,6 +507,8 @@
bool isHandlingWheelEvent() const final;
bool shouldSetCursor() const;
+ bool useDarkAppearance() const final;
+
// FIXME: Remove this method once plugin loading is decoupled from layout.
void flushAnyPendingPostLayoutTasks();
Modified: trunk/Source/WebCore/platform/ScrollableArea.h (237465 => 237466)
--- trunk/Source/WebCore/platform/ScrollableArea.h 2018-10-26 17:44:38 UTC (rev 237465)
+++ trunk/Source/WebCore/platform/ScrollableArea.h 2018-10-26 17:47:10 UTC (rev 237466)
@@ -251,6 +251,8 @@
// The totalContentsSize() is equivalent to the contentsSize() plus the header and footer heights.
WEBCORE_EXPORT IntSize totalContentsSize() const;
+ virtual bool useDarkAppearance() const { return false; }
+
virtual bool shouldSuspendScrollAnimations() const { return true; }
WEBCORE_EXPORT virtual void scrollbarStyleChanged(ScrollbarStyle /*newStyle*/, bool /*forceUpdate*/);
virtual void setVisibleScrollerThumbRect(const IntRect&) { }
Modified: trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm (237465 => 237466)
--- trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2018-10-26 17:44:38 UTC (rev 237465)
+++ trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2018-10-26 17:47:10 UTC (rev 237466)
@@ -527,6 +527,21 @@
return _scrollbar->supportsUpdateOnSecondaryThread();
}
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+- (NSAppearance *)effectiveAppearanceForScrollerImp:(NSScrollerImp *)scrollerImp
+{
+ UNUSED_PARAM(scrollerImp);
+
+ if (!_scrollbar)
+ return [NSAppearance currentAppearance];
+
+ // If dark appearance is used or the overlay style is light (because of a dark page background), return the dark apppearance.
+ // Keep this in sync with FrameView::paintScrollCorner.
+ bool useDarkAppearance = _scrollbar->scrollableArea().useDarkAppearance() || _scrollbar->scrollableArea().scrollbarOverlayStyle() == WebCore::ScrollbarOverlayStyleLight;
+ return [NSAppearance appearanceNamed:useDarkAppearance ? NSAppearanceNameDarkAqua : NSAppearanceNameAqua];
+}
+#endif
+
- (void)setUpAlphaAnimation:(RetainPtr<WebScrollbarPartAnimation>&)scrollbarPartAnimation scrollerPainter:(NSScrollerImp *)scrollerPainter part:(WebCore::ScrollbarPart)part animateAlphaTo:(CGFloat)newAlpha duration:(NSTimeInterval)duration
{
// If the user has scrolled the page, then the scrollbars must be animated here.