2011-04-25 Jon Lee <jonlee@apple.com>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Apr 2011 08:26:32 +0000 (08:26 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Apr 2011 08:26:32 +0000 (08:26 +0000)
        Reviewed by Maciej Stachowiak.

        Overlay scroller hard to see on pages with dark background (59183)
        https://bugs.webkit.org/show_bug.cgi?id=59183
        <rdar://problem/8975367>

        Switch the scrollbar's overlay style depending on its frame's background color.
        This refactors the getDocumentBackgroundColor method needed for gestures. The style
        is determined and set on every paint() call to the Mac scrollbar theme.

        * WebCore.exp.in: adding method to allow changing style
        * page/Frame.cpp:
        (WebCore::Frame::getDocumentBackgroundColor): moving code from WebFrame for reuse by FrameView
        * page/Frame.h:
        * page/FrameView.cpp:
        (WebCore::FrameView::recommendedScrollbarOverlayStyle): overridden to suggest a style based on CSS background color
        * page/FrameView.h:
        * platform/ScrollTypes.h: new enum to represent different overlay scrollbar styles
        * platform/ScrollableArea.h:
        (WebCore::ScrollableArea::recommendedScrollbarOverlayStyle): new virtual function to return a suggested overlay style
        * platform/mac/ScrollbarThemeMac.mm:
        (WebCore::ScrollbarThemeMac::paint):
        * platform/mac/WebCoreSystemInterface.h:
        * platform/mac/WebCoreSystemInterface.mm:
2011-04-25  Jon Lee  <jonlee@apple.com>

        Reviewed by Maciej Stachowiak.

        Overlay scroller hard to see on pages with dark background (59183)
        https://bugs.webkit.org/show_bug.cgi?id=59183
        <rdar://problem/8975367>

        * WebCoreSupport/WebSystemInterface.mm:
        (InitWebCoreSystemInterface): adding method to allow changing style
2011-04-25  Jon Lee  <jonlee@apple.com>

        Reviewed by Maciej Stachowiak.

        Overlay scroller hard to see on pages with dark background (59183)
        https://bugs.webkit.org/show_bug.cgi?id=59183
        <rdar://problem/8975367>

        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
        (InitWebCoreSystemInterface): adding method to allow changing style
        * WebProcess/WebPage/WebFrame.cpp:
        (WebKit::WebFrame::getDocumentBackgroundColor): refactoring to use common code for retrieving background color

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@84769 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/page/Frame.cpp
Source/WebCore/page/Frame.h
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebCore/platform/ScrollTypes.h
Source/WebCore/platform/ScrollableArea.h
Source/WebCore/platform/mac/ScrollbarThemeMac.mm
Source/WebCore/platform/mac/WebCoreSystemInterface.h
Source/WebCore/platform/mac/WebCoreSystemInterface.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm
Source/WebKit2/WebProcess/WebPage/WebFrame.cpp

index fd05a93..dfb6e74 100644 (file)
@@ -1,3 +1,30 @@
+2011-04-25  Jon Lee  <jonlee@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Overlay scroller hard to see on pages with dark background (59183)
+        https://bugs.webkit.org/show_bug.cgi?id=59183
+        <rdar://problem/8975367>
+
+        Switch the scrollbar's overlay style depending on its frame's background color.
+        This refactors the getDocumentBackgroundColor method needed for gestures. The style
+        is determined and set on every paint() call to the Mac scrollbar theme.
+
+        * WebCore.exp.in: adding method to allow changing style
+        * page/Frame.cpp:
+        (WebCore::Frame::getDocumentBackgroundColor): moving code from WebFrame for reuse by FrameView
+        * page/Frame.h:
+        * page/FrameView.cpp:
+        (WebCore::FrameView::recommendedScrollbarOverlayStyle): overridden to suggest a style based on CSS background color
+        * page/FrameView.h:
+        * platform/ScrollTypes.h: new enum to represent different overlay scrollbar styles
+        * platform/ScrollableArea.h:
+        (WebCore::ScrollableArea::recommendedScrollbarOverlayStyle): new virtual function to return a suggested overlay style
+        * platform/mac/ScrollbarThemeMac.mm:
+        (WebCore::ScrollbarThemeMac::paint):
+        * platform/mac/WebCoreSystemInterface.h:
+        * platform/mac/WebCoreSystemInterface.mm:
+
 2011-04-25  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Maciej Stachowiak.
index 12a9a94..2efd0ec 100644 (file)
@@ -1011,6 +1011,7 @@ __ZN7WebCore9plainTextEPKNS_5RangeENS_20TextIteratorBehaviorE
 __ZN7WebCore9toElementEN3JSC7JSValueE
 __ZNK3JSC8Bindings10RootObject12globalObjectEv
 __ZNK3WTF6String14createCFStringEv
+__ZNK7WebCore5Frame26getDocumentBackgroundColorEv
 __ZNK7WebCore10Credential11persistenceEv
 __ZNK7WebCore10Credential4userEv
 __ZNK7WebCore10Credential8passwordEv
@@ -1437,6 +1438,7 @@ _wkScrollbarPainterSetDelegate
 _wkScrollbarPainterSetOverlayState
 _wkScrollbarPainterTrackAlpha
 _wkScrollbarPainterUsesOverlayScrollers
+_wkSetScrollbarPainterKnobStyle
 _wkScrollbarThickness
 _wkSetPainterForPainterController
 _wkSetScrollbarPainterControllerStyle
index 800356c..09a9167 100644 (file)
@@ -500,6 +500,31 @@ String Frame::matchLabelsAgainstElement(const Vector<String>& labels, Element* e
     
     return matchLabelsAgainstString(labels, element->getAttribute(idAttr));
 }
+    
+Color Frame::getDocumentBackgroundColor() const
+{
+    // FIXME: This is a basic implementation adopted originally from WebFrame,
+    // but ultimately is wrong. Body painting propagates up to the document (see
+    // RenderBox::paintRootBoxDecorations()), so code from that method should be
+    // adopted here to get the style used to paint the root background.
+
+    // Return invalid Color objects if we are not able to obtain the color
+    // for whatever reason.
+    if (!m_doc)
+        return Color();
+    
+    Element* rootElementToUse = m_doc->body();
+    if (!rootElementToUse)
+        rootElementToUse = m_doc->documentElement();
+    if (!rootElementToUse)
+        return Color();
+    
+    RenderObject* renderer = rootElementToUse->renderer();
+    if (!renderer)
+        return Color();
+    
+    return renderer->style()->visitedDependentColor(CSSPropertyBackgroundColor);
+}
 
 void Frame::setPrinting(bool printing, const FloatSize& pageSize, float maximumShrinkRatio, AdjustViewSizeOrNot shouldAdjustViewSize)
 {
index 05805cf..3532fe4 100644 (file)
@@ -190,6 +190,8 @@ namespace WebCore {
         String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
         String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
 
+        Color getDocumentBackgroundColor() const;
+        
 #if PLATFORM(MAC)
         NSString* searchForLabelsBeforeElement(NSArray* labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
         NSString* matchLabelsAgainstElement(NSArray* labels, Element*);
index 8c8c39f..fb94bc2 100644 (file)
@@ -306,6 +306,23 @@ void FrameView::detachCustomScrollbars()
     }
 }
 
+ScrollbarOverlayStyle FrameView::recommendedScrollbarOverlayStyle() const
+{
+    Color bgColor = m_frame->getDocumentBackgroundColor();
+    if (!bgColor.isValid())
+        return ScrollbarOverlayStyleDefault;
+    
+    // Reduce the background color from RGB to a lightness value
+    // and determine which scrollbar style to use based on a lightness
+    // heuristic.
+    double hue, saturation, lightness;
+    bgColor.getHSL(hue, saturation, lightness);
+    if (lightness > .5)
+        return ScrollbarOverlayStyleDefault;
+    
+    return ScrollbarOverlayStyleLight;
+}
+
 void FrameView::clear()
 {
     setCanBlitOnScroll(true);
index fc33e88..35a9411 100644 (file)
@@ -133,6 +133,7 @@ public:
     void resetScrollbars();
     void resetScrollbarsAndClearContentsSize();
     void detachCustomScrollbars();
+    virtual ScrollbarOverlayStyle recommendedScrollbarOverlayStyle() const;
 
     void clear();
 
index 62b4645..a02198d 100644 (file)
@@ -150,6 +150,12 @@ namespace WebCore {
         ScrollbarButtonsDoubleBoth
     };
     
+    enum ScrollbarOverlayStyle {
+        ScrollbarOverlayStyleDefault,
+        ScrollbarOverlayStyleDark,
+        ScrollbarOverlayStyleLight
+    };
+    
     typedef unsigned ScrollbarControlPartMask;
 
 }
index 1097ab4..30db7d1 100644 (file)
@@ -77,6 +77,7 @@ public:
     void willRemoveHorizontalScrollbar(Scrollbar*);
 
     bool hasOverlayScrollbars() const;
+    virtual ScrollbarOverlayStyle recommendedScrollbarOverlayStyle() const { return ScrollbarOverlayStyleDefault; }
 
     ScrollAnimator* scrollAnimator() const { return m_scrollAnimator.get(); }
     const IntPoint& scrollOrigin() const { return m_scrollOrigin; }
index 0e57cd6..1d6abb5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -429,6 +429,20 @@ static int scrollbarPartToHIPressedState(ScrollbarPart part)
     }
 }
 
+#if USE(WK_SCROLLBAR_PAINTER)
+static inline wkScrollerKnobStyle toScrollbarPainterKnobStyle(ScrollbarOverlayStyle style)
+{
+    switch (style) {
+    case ScrollbarOverlayStyleDark:
+        return wkScrollerKnobStyleDark;
+    case ScrollbarOverlayStyleLight:
+        return wkScrollerKnobStyleLight;
+    default:
+        return wkScrollerKnobStyleDefault;
+    }
+}
+#endif
+
 bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, const IntRect& damageRect)
 {
 #if USE(WK_SCROLLBAR_PAINTER)
@@ -451,10 +465,14 @@ bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, co
         else
             value = 0;
     }
-
+    
     ScrollAnimatorMac* scrollAnimator = static_cast<ScrollAnimatorMac*>(scrollbar->scrollableArea()->scrollAnimator());
     scrollAnimator->setIsDrawingIntoLayer(context->isCALayerContext());
 
+#if USE(WK_SCROLLBAR_PAINTER)
+    wkSetScrollbarPainterKnobStyle(painterForScrollbar(scrollbar), toScrollbarPainterKnobStyle(scrollbar->scrollableArea()->recommendedScrollbarOverlayStyle()));
+#endif
+    
     GraphicsContextStateSaver stateSaver(*context);
     context->clip(damageRect);
     context->translate(scrollbar->frameRect().x(), scrollbar->frameRect().y());
index caf9ee9..0dfb69b 100644 (file)
@@ -228,6 +228,14 @@ extern bool (*wkScrollbarPainterIsHorizontal)(WKScrollbarPainterRef);
 extern CGRect (*wkScrollbarPainterKnobRect)(WKScrollbarPainterRef);
 extern void (*wkScrollbarPainterSetOverlayState)(WKScrollbarPainterRef, int overlayScrollerState);
 
+enum {
+    wkScrollerKnobStyleDefault = 0,
+    wkScrollerKnobStyleDark = 1,
+    wkScrollerKnobStyleLight = 2
+};
+typedef uint32 wkScrollerKnobStyle;
+extern void (*wkSetScrollbarPainterKnobStyle)(WKScrollbarPainterRef, wkScrollerKnobStyle);
+    
 extern WKScrollbarPainterControllerRef (*wkMakeScrollbarPainterController)(id painterControllerDelegate);
 extern void (*wkSetPainterForPainterController)(WKScrollbarPainterControllerRef, WKScrollbarPainterRef, bool isHorizontal);
 extern WKScrollbarPainterRef (*wkVerticalScrollbarPainterForController)(WKScrollbarPainterControllerRef);
index 5948ff4..eadacec 100644 (file)
@@ -150,6 +150,7 @@ void (*wkSetScrollbarPainterTrackAlpha)(WKScrollbarPainterRef, CGFloat);
 bool (*wkScrollbarPainterIsHorizontal)(WKScrollbarPainterRef);
 CGRect (*wkScrollbarPainterKnobRect)(WKScrollbarPainterRef);
 void (*wkScrollbarPainterSetOverlayState)(WKScrollbarPainterRef, int overlayScrollerState);
+void (*wkSetScrollbarPainterKnobStyle)(WKScrollbarPainterRef, wkScrollerKnobStyle);
 
 WKScrollbarPainterControllerRef (*wkMakeScrollbarPainterController)(id painterControllerDelegate);
 void (*wkSetPainterForPainterController)(WKScrollbarPainterControllerRef, WKScrollbarPainterRef, bool isHorizontal);
index df35604..0b6898c 100644 (file)
@@ -1,3 +1,14 @@
+2011-04-25  Jon Lee  <jonlee@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Overlay scroller hard to see on pages with dark background (59183)
+        https://bugs.webkit.org/show_bug.cgi?id=59183
+        <rdar://problem/8975367>
+        
+        * WebCoreSupport/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface): adding method to allow changing style
+
 2011-04-23  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r84740.
index aafc3f2..098aeea 100644 (file)
@@ -146,6 +146,7 @@ void InitWebCoreSystemInterface(void)
     INIT(ScrollbarPainterIsHorizontal);
     INIT(ScrollbarPainterKnobRect);
     INIT(ScrollbarPainterSetOverlayState);
+    INIT(SetScrollbarPainterKnobStyle);
     INIT(MakeScrollbarPainterController);
     INIT(MakeScrollbarReplacementPainter);
     INIT(SetPainterForPainterController);
index c24d66d..3a1c0f7 100644 (file)
@@ -1,3 +1,16 @@
+2011-04-25  Jon Lee  <jonlee@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Overlay scroller hard to see on pages with dark background (59183)
+        https://bugs.webkit.org/show_bug.cgi?id=59183
+        <rdar://problem/8975367>
+
+        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface): adding method to allow changing style
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::getDocumentBackgroundColor): refactoring to use common code for retrieving background color
+
 2011-04-24  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Maciej Stachowiak.
index 280d2a3..06cf6c5 100644 (file)
@@ -124,6 +124,7 @@ void InitWebCoreSystemInterface(void)
         INIT(ScrollbarPainterIsHorizontal);
         INIT(ScrollbarPainterKnobRect);
         INIT(ScrollbarPainterSetOverlayState);
+        INIT(SetScrollbarPainterKnobStyle);
         INIT(MakeScrollbarPainterController);
         INIT(MakeScrollbarReplacementPainter);
         INIT(SetPainterForPainterController);
index 0d550c9..6a1f067 100644 (file)
@@ -540,24 +540,11 @@ bool WebFrame::getDocumentBackgroundColor(double* red, double* green, double* bl
 {
     if (!m_coreFrame)
         return false;
-    Document* document = m_coreFrame->document();
-    if (!document)
-        return false;
-
-    Element* rootElementToUse = document->body();
-    if (!rootElementToUse)
-        rootElementToUse = document->documentElement();
-    if (!rootElementToUse)
-        return false;
-
-    RenderObject* renderer = rootElementToUse->renderer();
-    if (!renderer)
-        return false;
-    Color color = renderer->style()->visitedDependentColor(CSSPropertyBackgroundColor);
-    if (!color.isValid())
+    Color bgColor = m_coreFrame->getDocumentBackgroundColor();
+    if (!bgColor.isValid())
         return false;
 
-    color.getRGBA(*red, *green, *blue, *alpha);
+    bgColor.getRGBA(*red, *green, *blue, *alpha);
     return true;
 }