Changeset 84769 in webkit


Ignore:
Timestamp:
Apr 25, 2011 1:26:32 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

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 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
Location:
trunk/Source
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r84768 r84769  
     12011-04-25  Jon Lee  <jonlee@apple.com>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Overlay scroller hard to see on pages with dark background (59183)
     6        https://bugs.webkit.org/show_bug.cgi?id=59183
     7        <rdar://problem/8975367>
     8
     9        Switch the scrollbar's overlay style depending on its frame's background color.
     10        This refactors the getDocumentBackgroundColor method needed for gestures. The style
     11        is determined and set on every paint() call to the Mac scrollbar theme.
     12
     13        * WebCore.exp.in: adding method to allow changing style
     14        * page/Frame.cpp:
     15        (WebCore::Frame::getDocumentBackgroundColor): moving code from WebFrame for reuse by FrameView
     16        * page/Frame.h:
     17        * page/FrameView.cpp:
     18        (WebCore::FrameView::recommendedScrollbarOverlayStyle): overridden to suggest a style based on CSS background color
     19        * page/FrameView.h:
     20        * platform/ScrollTypes.h: new enum to represent different overlay scrollbar styles
     21        * platform/ScrollableArea.h:
     22        (WebCore::ScrollableArea::recommendedScrollbarOverlayStyle): new virtual function to return a suggested overlay style
     23        * platform/mac/ScrollbarThemeMac.mm:
     24        (WebCore::ScrollbarThemeMac::paint):
     25        * platform/mac/WebCoreSystemInterface.h:
     26        * platform/mac/WebCoreSystemInterface.mm:
     27
    1282011-04-25  Dan Bernstein  <mitz@apple.com>
    229
  • trunk/Source/WebCore/WebCore.exp.in

    r84751 r84769  
    10121012__ZNK3JSC8Bindings10RootObject12globalObjectEv
    10131013__ZNK3WTF6String14createCFStringEv
     1014__ZNK7WebCore5Frame26getDocumentBackgroundColorEv
    10141015__ZNK7WebCore10Credential11persistenceEv
    10151016__ZNK7WebCore10Credential4userEv
     
    14381439_wkScrollbarPainterTrackAlpha
    14391440_wkScrollbarPainterUsesOverlayScrollers
     1441_wkSetScrollbarPainterKnobStyle
    14401442_wkScrollbarThickness
    14411443_wkSetPainterForPainterController
  • trunk/Source/WebCore/page/Frame.cpp

    r84442 r84769  
    501501    return matchLabelsAgainstString(labels, element->getAttribute(idAttr));
    502502}
     503   
     504Color Frame::getDocumentBackgroundColor() const
     505{
     506    // FIXME: This is a basic implementation adopted originally from WebFrame,
     507    // but ultimately is wrong. Body painting propagates up to the document (see
     508    // RenderBox::paintRootBoxDecorations()), so code from that method should be
     509    // adopted here to get the style used to paint the root background.
     510
     511    // Return invalid Color objects if we are not able to obtain the color
     512    // for whatever reason.
     513    if (!m_doc)
     514        return Color();
     515   
     516    Element* rootElementToUse = m_doc->body();
     517    if (!rootElementToUse)
     518        rootElementToUse = m_doc->documentElement();
     519    if (!rootElementToUse)
     520        return Color();
     521   
     522    RenderObject* renderer = rootElementToUse->renderer();
     523    if (!renderer)
     524        return Color();
     525   
     526    return renderer->style()->visitedDependentColor(CSSPropertyBackgroundColor);
     527}
    503528
    504529void Frame::setPrinting(bool printing, const FloatSize& pageSize, float maximumShrinkRatio, AdjustViewSizeOrNot shouldAdjustViewSize)
  • trunk/Source/WebCore/page/Frame.h

    r83081 r84769  
    191191        String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
    192192
     193        Color getDocumentBackgroundColor() const;
     194       
    193195#if PLATFORM(MAC)
    194196        NSString* searchForLabelsBeforeElement(NSArray* labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
  • trunk/Source/WebCore/page/FrameView.cpp

    r84751 r84769  
    307307}
    308308
     309ScrollbarOverlayStyle FrameView::recommendedScrollbarOverlayStyle() const
     310{
     311    Color bgColor = m_frame->getDocumentBackgroundColor();
     312    if (!bgColor.isValid())
     313        return ScrollbarOverlayStyleDefault;
     314   
     315    // Reduce the background color from RGB to a lightness value
     316    // and determine which scrollbar style to use based on a lightness
     317    // heuristic.
     318    double hue, saturation, lightness;
     319    bgColor.getHSL(hue, saturation, lightness);
     320    if (lightness > .5)
     321        return ScrollbarOverlayStyleDefault;
     322   
     323    return ScrollbarOverlayStyleLight;
     324}
     325
    309326void FrameView::clear()
    310327{
  • trunk/Source/WebCore/page/FrameView.h

    r84751 r84769  
    134134    void resetScrollbarsAndClearContentsSize();
    135135    void detachCustomScrollbars();
     136    virtual ScrollbarOverlayStyle recommendedScrollbarOverlayStyle() const;
    136137
    137138    void clear();
  • trunk/Source/WebCore/platform/ScrollTypes.h

    r84751 r84769  
    151151    };
    152152   
     153    enum ScrollbarOverlayStyle {
     154        ScrollbarOverlayStyleDefault,
     155        ScrollbarOverlayStyleDark,
     156        ScrollbarOverlayStyleLight
     157    };
     158   
    153159    typedef unsigned ScrollbarControlPartMask;
    154160
  • trunk/Source/WebCore/platform/ScrollableArea.h

    r84752 r84769  
    7878
    7979    bool hasOverlayScrollbars() const;
     80    virtual ScrollbarOverlayStyle recommendedScrollbarOverlayStyle() const { return ScrollbarOverlayStyleDefault; }
    8081
    8182    ScrollAnimator* scrollAnimator() const { return m_scrollAnimator.get(); }
  • trunk/Source/WebCore/platform/mac/ScrollbarThemeMac.mm

    r84767 r84769  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    430430}
    431431
     432#if USE(WK_SCROLLBAR_PAINTER)
     433static inline wkScrollerKnobStyle toScrollbarPainterKnobStyle(ScrollbarOverlayStyle style)
     434{
     435    switch (style) {
     436    case ScrollbarOverlayStyleDark:
     437        return wkScrollerKnobStyleDark;
     438    case ScrollbarOverlayStyleLight:
     439        return wkScrollerKnobStyleLight;
     440    default:
     441        return wkScrollerKnobStyleDefault;
     442    }
     443}
     444#endif
     445
    432446bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, const IntRect& damageRect)
    433447{
     
    452466            value = 0;
    453467    }
    454 
     468   
    455469    ScrollAnimatorMac* scrollAnimator = static_cast<ScrollAnimatorMac*>(scrollbar->scrollableArea()->scrollAnimator());
    456470    scrollAnimator->setIsDrawingIntoLayer(context->isCALayerContext());
    457471
     472#if USE(WK_SCROLLBAR_PAINTER)
     473    wkSetScrollbarPainterKnobStyle(painterForScrollbar(scrollbar), toScrollbarPainterKnobStyle(scrollbar->scrollableArea()->recommendedScrollbarOverlayStyle()));
     474#endif
     475   
    458476    GraphicsContextStateSaver stateSaver(*context);
    459477    context->clip(damageRect);
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h

    r84751 r84769  
    229229extern void (*wkScrollbarPainterSetOverlayState)(WKScrollbarPainterRef, int overlayScrollerState);
    230230
     231enum {
     232    wkScrollerKnobStyleDefault = 0,
     233    wkScrollerKnobStyleDark = 1,
     234    wkScrollerKnobStyleLight = 2
     235};
     236typedef uint32 wkScrollerKnobStyle;
     237extern void (*wkSetScrollbarPainterKnobStyle)(WKScrollbarPainterRef, wkScrollerKnobStyle);
     238   
    231239extern WKScrollbarPainterControllerRef (*wkMakeScrollbarPainterController)(id painterControllerDelegate);
    232240extern void (*wkSetPainterForPainterController)(WKScrollbarPainterControllerRef, WKScrollbarPainterRef, bool isHorizontal);
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm

    r84751 r84769  
    151151CGRect (*wkScrollbarPainterKnobRect)(WKScrollbarPainterRef);
    152152void (*wkScrollbarPainterSetOverlayState)(WKScrollbarPainterRef, int overlayScrollerState);
     153void (*wkSetScrollbarPainterKnobStyle)(WKScrollbarPainterRef, wkScrollerKnobStyle);
    153154
    154155WKScrollbarPainterControllerRef (*wkMakeScrollbarPainterController)(id painterControllerDelegate);
  • trunk/Source/WebKit/mac/ChangeLog

    r84751 r84769  
     12011-04-25  Jon Lee  <jonlee@apple.com>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Overlay scroller hard to see on pages with dark background (59183)
     6        https://bugs.webkit.org/show_bug.cgi?id=59183
     7        <rdar://problem/8975367>
     8       
     9        * WebCoreSupport/WebSystemInterface.mm:
     10        (InitWebCoreSystemInterface): adding method to allow changing style
     11
    1122011-04-23  Sheriff Bot  <webkit.review.bot@gmail.com>
    213
  • trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm

    r84751 r84769  
    147147    INIT(ScrollbarPainterKnobRect);
    148148    INIT(ScrollbarPainterSetOverlayState);
     149    INIT(SetScrollbarPainterKnobStyle);
    149150    INIT(MakeScrollbarPainterController);
    150151    INIT(MakeScrollbarReplacementPainter);
  • trunk/Source/WebKit2/ChangeLog

    r84757 r84769  
     12011-04-25  Jon Lee  <jonlee@apple.com>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Overlay scroller hard to see on pages with dark background (59183)
     6        https://bugs.webkit.org/show_bug.cgi?id=59183
     7        <rdar://problem/8975367>
     8
     9        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
     10        (InitWebCoreSystemInterface): adding method to allow changing style
     11        * WebProcess/WebPage/WebFrame.cpp:
     12        (WebKit::WebFrame::getDocumentBackgroundColor): refactoring to use common code for retrieving background color
     13
    1142011-04-24  Dan Bernstein  <mitz@apple.com>
    215
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm

    r84751 r84769  
    125125        INIT(ScrollbarPainterKnobRect);
    126126        INIT(ScrollbarPainterSetOverlayState);
     127        INIT(SetScrollbarPainterKnobStyle);
    127128        INIT(MakeScrollbarPainterController);
    128129        INIT(MakeScrollbarReplacementPainter);
  • trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp

    r84058 r84769  
    541541    if (!m_coreFrame)
    542542        return false;
    543     Document* document = m_coreFrame->document();
    544     if (!document)
    545         return false;
    546 
    547     Element* rootElementToUse = document->body();
    548     if (!rootElementToUse)
    549         rootElementToUse = document->documentElement();
    550     if (!rootElementToUse)
    551         return false;
    552 
    553     RenderObject* renderer = rootElementToUse->renderer();
    554     if (!renderer)
    555         return false;
    556     Color color = renderer->style()->visitedDependentColor(CSSPropertyBackgroundColor);
    557     if (!color.isValid())
    558         return false;
    559 
    560     color.getRGBA(*red, *green, *blue, *alpha);
     543    Color bgColor = m_coreFrame->getDocumentBackgroundColor();
     544    if (!bgColor.isValid())
     545        return false;
     546
     547    bgColor.getRGBA(*red, *green, *blue, *alpha);
    561548    return true;
    562549}
Note: See TracChangeset for help on using the changeset viewer.