Changeset 51827 in webkit


Ignore:
Timestamp:
Dec 7, 2009 6:54:52 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-12-07 Evan Martin <evan@chromium.org>

Reviewed by Eric Seidel.

Chromium: theme scrollbars to match GTK theme.
Add functions to RenderThemeChromiumLinux to change the scrollbar
color.

Since the change is to the Chromium WebKit API layer, testing will
be in Chromium's test shell.
http://bugs.webkit.org/show_bug.cgi?id=32048

Patch from Markus Gutschke <markus@chromium.org>.

  • platform/chromium/ScrollbarThemeChromiumLinux.cpp: (WebCore::saturateAndBrighten): (WebCore::outlineColor): (WebCore::ScrollbarThemeChromiumLinux::paintTrackPiece): (WebCore::ScrollbarThemeChromiumLinux::paintThumb):
  • rendering/RenderThemeChromiumLinux.cpp: (WebCore::RenderThemeChromiumLinux::setScrollbarColors):
  • rendering/RenderThemeChromiumLinux.h: (WebCore::RenderThemeChromiumLinux::thumbInactiveColor): (WebCore::RenderThemeChromiumLinux::thumbActiveColor): (WebCore::RenderThemeChromiumLinux::trackColor):

2009-12-07 Evan Martin <evan@chromium.org>

Reviewed by Eric Seidel.

Chromium: theme scrollbars to match GTK theme.
Add API to set the colors.

Since the change is to the Chromium WebKit API layer, testing will
be in Chromium's test shell.
http://bugs.webkit.org/show_bug.cgi?id=32048

Patch from Markus Gutschke <markus@chromium.org>.

  • public/WebView.h:
  • src/WebViewImpl.cpp: (WebKit::WebViewImpl::setScrollbarColors):
  • src/WebViewImpl.h:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r51825 r51827  
     12009-12-07  Evan Martin  <evan@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Chromium: theme scrollbars to match GTK theme.
     6        Add functions to RenderThemeChromiumLinux to change the scrollbar
     7        color.
     8
     9        Since the change is to the Chromium WebKit API layer, testing will
     10        be in Chromium's test shell.
     11        http://bugs.webkit.org/show_bug.cgi?id=32048
     12
     13        Patch from Markus Gutschke <markus@chromium.org>.
     14
     15        * platform/chromium/ScrollbarThemeChromiumLinux.cpp:
     16        (WebCore::saturateAndBrighten):
     17        (WebCore::outlineColor):
     18        (WebCore::ScrollbarThemeChromiumLinux::paintTrackPiece):
     19        (WebCore::ScrollbarThemeChromiumLinux::paintThumb):
     20        * rendering/RenderThemeChromiumLinux.cpp:
     21        (WebCore::RenderThemeChromiumLinux::setScrollbarColors):
     22        * rendering/RenderThemeChromiumLinux.h:
     23        (WebCore::RenderThemeChromiumLinux::thumbInactiveColor):
     24        (WebCore::RenderThemeChromiumLinux::thumbActiveColor):
     25        (WebCore::RenderThemeChromiumLinux::trackColor):
     26
    1272009-12-08  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
    228
  • trunk/WebCore/platform/chromium/ScrollbarThemeChromiumLinux.cpp

    r49553 r51827  
    3434#include "PlatformContextSkia.h"
    3535#include "PlatformMouseEvent.h"
     36#include "RenderTheme.h"
     37#include "RenderThemeChromiumLinux.h"
    3638#include "Scrollbar.h"
    3739#include "TransformationMatrix.h"
     
    7476}
    7577
     78static SkScalar clamp(SkScalar value, SkScalar min, SkScalar max)
     79{
     80    return std::min(std::max(value, min), max);
     81}
     82
     83static SkColor saturateAndBrighten(SkScalar* hsv,
     84                                   SkScalar saturateAmount,
     85                                   SkScalar brightenAmount)
     86{
     87    SkScalar color[3];
     88    color[0] = hsv[0];
     89    color[1] = clamp(hsv[1] + saturateAmount, 0.0, 1.0);
     90    color[2] = clamp(hsv[2] + brightenAmount, 0.0, 1.0);
     91    return SkHSVToColor(color);
     92}
     93
     94static SkColor outlineColor(SkScalar* hsv1, SkScalar* hsv2)
     95{
     96    // GTK Theme engines have way too much control over the layout of
     97    // the scrollbar. We might be able to more closely approximate its
     98    // look-and-feel, if we sent whole images instead of just colors
     99    // from the browser to the renderer. But even then, some themes
     100    // would just break.
     101    //
     102    // So, instead, we don't even try to 100% replicate the look of
     103    // the native scrollbar. We render our own version, but we make
     104    // sure to pick colors that blend in nicely with the system GTK
     105    // theme. In most cases, we can just sample a couple of pixels
     106    // from the system scrollbar and use those colors to draw our
     107    // scrollbar.
     108    //
     109    // This works fine for the track color and the overall thumb
     110    // color. But it fails spectacularly for the outline color used
     111    // around the thumb piece.  Not all themes have a clearly defined
     112    // outline. For some of them it is partially transparent, and for
     113    // others the thickness is very unpredictable.
     114    //
     115    // So, instead of trying to approximate the system theme, we
     116    // instead try to compute a reasonable looking choice based on the
     117    // known color of the track and the thumb piece. This is difficult
     118    // when trying to deal both with high- and low-contrast themes,
     119    // and both with positive and inverted themes.
     120    //
     121    // The following code has been tested to look OK with all of the
     122    // default GTK themes.
     123    SkScalar minDiff = clamp((hsv1[1] + hsv2[1]) * 1.2, 0.2, 0.5);
     124    SkScalar diff = clamp(fabs(hsv1[2] - hsv2[2]) / 2, minDiff, 0.5);
     125
     126    if (hsv1[2] + hsv2[2] > 1.0)
     127        diff = -diff;
     128
     129    return saturateAndBrighten(hsv2, -0.2, diff);
     130}
     131
    76132IntRect ScrollbarThemeChromium::trackRect(Scrollbar* scrollbar, bool)
    77133{
     
    90146
    91147    skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height());
    92     paint.setARGB(0xff, 0xe3, 0xdd, 0xd8);
    93     canvas->drawIRect(skrect, paint);
    94 
    95     paint.setARGB(0xff, 0xc5, 0xba, 0xb0);
     148    SkScalar track_hsv[3];
     149    SkColorToHSV(RenderThemeChromiumLinux::trackColor(), track_hsv);
     150    paint.setColor(saturateAndBrighten(track_hsv, 0, 0));
     151    canvas->drawIRect(skrect, paint);
     152
     153    SkScalar thumb_hsv[3];
     154    SkColorToHSV(RenderThemeChromiumLinux::thumbInactiveColor(),
     155                 thumb_hsv);
     156
     157    paint.setColor(outlineColor(track_hsv, thumb_hsv));
    96158    drawBox(canvas, rect, paint);
    97159}
     
    110172    SkCanvas* const canvas = gc->platformContext()->canvas();
    111173
     174    SkScalar thumb[3];
     175    SkColorToHSV(hovered
     176                 ? RenderThemeChromiumLinux::thumbActiveColor()
     177                 : RenderThemeChromiumLinux::thumbInactiveColor(),
     178                 thumb);
     179
    112180    SkPaint paint;
    113     if (hovered)
    114         paint.setARGB(0xff, 0xff, 0xff, 0xff);
    115     else
    116         paint.setARGB(0xff, 0xf4, 0xf2, 0xef);
     181    paint.setColor(saturateAndBrighten(thumb, 0, 0.02));
    117182
    118183    SkIRect skrect;
     
    124189    canvas->drawIRect(skrect, paint);
    125190
    126     if (hovered)
    127         paint.setARGB(0xff, 0xf4, 0xf2, 0xef);
    128     else
    129         paint.setARGB(0xff, 0xea, 0xe5, 0xe0);
     191    paint.setColor(saturateAndBrighten(thumb, 0, -0.02));
    130192
    131193    if (vertical)
     
    136198    canvas->drawIRect(skrect, paint);
    137199
    138     paint.setARGB(0xff, 0x9d, 0x96, 0x8e);
     200    SkScalar track[3];
     201    SkColorToHSV(RenderThemeChromiumLinux::trackColor(), track);
     202    paint.setColor(outlineColor(track, thumb));
    139203    drawBox(canvas, rect, paint);
    140204
    141205    if (rect.height() > 10 && rect.width() > 10) {
    142         paint.setARGB(0xff, 0x9d, 0x96, 0x8e);
    143206        const int grippyHalfWidth = 2;
    144207        const int interGrippyOffset = 3;
  • trunk/WebCore/rendering/RenderThemeChromiumLinux.cpp

    r48317 r51827  
    3232
    3333namespace WebCore {
     34
     35unsigned RenderThemeChromiumLinux::m_thumbInactiveColor = 0;
     36unsigned RenderThemeChromiumLinux::m_thumbActiveColor = 0;
     37unsigned RenderThemeChromiumLinux::m_trackColor = 0;
    3438
    3539PassRefPtr<RenderTheme> RenderThemeChromiumLinux::create()
     
    123127}
    124128
     129void RenderThemeChromiumLinux::setScrollbarColors(
     130    SkColor inactiveColor, SkColor activeColor, SkColor trackColor)
     131{
     132    m_thumbInactiveColor = inactiveColor;
     133    m_thumbActiveColor = activeColor;
     134    m_trackColor = trackColor;
     135}
     136
    125137} // namespace WebCore
  • trunk/WebCore/rendering/RenderThemeChromiumLinux.h

    r48317 r51827  
    5555        virtual double caretBlinkIntervalInternal() const;
    5656
     57        static void setScrollbarColors(unsigned inactive_color,
     58                                       unsigned active_color,
     59                                       unsigned track_color);
     60        static unsigned thumbInactiveColor() { return m_thumbInactiveColor; }
     61        static unsigned thumbActiveColor() { return m_thumbActiveColor; }
     62        static unsigned trackColor() { return m_trackColor; }
     63
    5764    private:
    5865        RenderThemeChromiumLinux();
     
    6370
    6471        double m_caretBlinkInterval;
     72
     73        static unsigned m_thumbInactiveColor;
     74        static unsigned m_thumbActiveColor;
     75        static unsigned m_trackColor;
    6576    };
    6677
  • trunk/WebKit/chromium/ChangeLog

    r51818 r51827  
     12009-12-07  Evan Martin  <evan@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Chromium: theme scrollbars to match GTK theme.
     6        Add API to set the colors.
     7
     8        Since the change is to the Chromium WebKit API layer, testing will
     9        be in Chromium's test shell.
     10        http://bugs.webkit.org/show_bug.cgi?id=32048
     11
     12        Patch from Markus Gutschke <markus@chromium.org>.
     13
     14        * public/WebView.h:
     15        * src/WebViewImpl.cpp:
     16        (WebKit::WebViewImpl::setScrollbarColors):
     17        * src/WebViewImpl.h:
     18
    1192009-12-07  Finnur Thorarinsson  <finnur.webkit@gmail.com>
    220
  • trunk/WebKit/chromium/public/WebView.h

    r51719 r51827  
    246246    WEBKIT_API static void resetVisitedLinkState();
    247247
     248    // Scrollbar colors ----------------------------------------------------
     249    virtual void setScrollbarColors(unsigned inactiveColor,
     250                                    unsigned activeColor,
     251                                    unsigned trackColor) = 0;
    248252
    249253protected:
  • trunk/WebKit/chromium/src/WebViewImpl.cpp

    r51818 r51827  
    9898#include "RenderThemeChromiumWin.h"
    9999#else
     100#if PLATFORM(LINUX)
     101#include "RenderThemeChromiumLinux.h"
     102#endif
    100103#include "KeyboardCodesPosix.h"
    101104#include "RenderTheme.h"
     
    16221625}
    16231626
     1627void WebViewImpl::setScrollbarColors(unsigned inactiveColor,
     1628                                     unsigned activeColor,
     1629                                     unsigned trackColor) {
     1630#if PLATFORM(LINUX)
     1631    RenderThemeChromiumLinux::setScrollbarColors(inactiveColor,
     1632                                                 activeColor,
     1633                                                 trackColor);
     1634#endif
     1635}
     1636
    16241637void WebViewImpl::didCommitLoad(bool* isNewNavigation)
    16251638{
  • trunk/WebKit/chromium/src/WebViewImpl.h

    r51719 r51827  
    155155        int defaultSuggestionIndex);
    156156    virtual void hideAutofillPopup();
     157    virtual void setScrollbarColors(unsigned inactiveColor,
     158                                    unsigned activeColor,
     159                                    unsigned trackColor);
    157160
    158161    // WebViewImpl
Note: See TracChangeset for help on using the changeset viewer.