Changeset 63280 in webkit


Ignore:
Timestamp:
Jul 13, 2010 9:48:05 PM (14 years ago)
Author:
tkent@chromium.org
Message:

[Chromium] Linux implementation of <input type=number> UI
https://bugs.webkit.org/show_bug.cgi?id=41925

Reviewed by Darin Fisher.

WebCore:

  • Move the code for scrollbar steppers from ScrollbarThemeChromiumLinux to PlatformThemeChromiumGtk.
  • Move the code for scrollbar colors from RenderThemeChromiumLinux to PlatformThemeChromiumGtk.
  • WebCore.gypi:
  • platform/chromium/PlatformThemeChromiumGtk.cpp: Added.

(WebCore::PlatformThemeChromiumGtk::setScrollbarColors): Moved from RenderThemeChromiumLinux.
(WebCore::clamp): Moved from ScrollbarThemeChromiumLinux.
(WebCore::PlatformThemeChromiumGtk::saturateAndBrighten): ditto.
(WebCore::PlatformThemeChromiumGtk::outlineColor): ditto.
(WebCore::PlatformThemeChromiumGtk::paintArrowButton): ditto.

  • platform/chromium/PlatformThemeChromiumGtk.h: Added.
  • platform/chromium/ScrollbarThemeChromiumLinux.cpp:

(WebCore::ScrollbarThemeChromiumLinux::paintTrackPiece):
(WebCore::ScrollbarThemeChromiumLinux::paintButton):

Move the main part of the code to PlatformThemeChromiumGtk.

(WebCore::ScrollbarThemeChromiumLinux::paintThumb):

  • rendering/RenderThemeChromiumLinux.cpp:

(WebCore::RenderThemeChromiumLinux::adjustInnerSpinButtonStyle): Added.
(WebCore::RenderThemeChromiumLinux::paintInnerSpinButton): Added.

  • rendering/RenderThemeChromiumLinux.h:

WebKit/chromium:

  • src/WebViewImpl.cpp:

(WebKit::WebViewImpl::setScrollbarColors):

Call PlatformThemeChromiumGtk::setScrollbarColors() instead of
RenderThemeChromiumLinux::setScrollbarColors().

Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63278 r63280  
     12010-07-13  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        [Chromium] Linux implementation of <input type=number> UI
     6        https://bugs.webkit.org/show_bug.cgi?id=41925
     7
     8        - Move the code for scrollbar steppers from ScrollbarThemeChromiumLinux
     9          to PlatformThemeChromiumGtk.
     10        - Move the code for scrollbar colors from RenderThemeChromiumLinux
     11          to PlatformThemeChromiumGtk.
     12
     13        * WebCore.gypi:
     14        * platform/chromium/PlatformThemeChromiumGtk.cpp: Added.
     15        (WebCore::PlatformThemeChromiumGtk::setScrollbarColors): Moved from RenderThemeChromiumLinux.
     16        (WebCore::clamp): Moved from ScrollbarThemeChromiumLinux.
     17        (WebCore::PlatformThemeChromiumGtk::saturateAndBrighten): ditto.
     18        (WebCore::PlatformThemeChromiumGtk::outlineColor): ditto.
     19        (WebCore::PlatformThemeChromiumGtk::paintArrowButton): ditto.
     20        * platform/chromium/PlatformThemeChromiumGtk.h: Added.
     21        * platform/chromium/ScrollbarThemeChromiumLinux.cpp:
     22        (WebCore::ScrollbarThemeChromiumLinux::paintTrackPiece):
     23        (WebCore::ScrollbarThemeChromiumLinux::paintButton):
     24         Move the main part of the code to PlatformThemeChromiumGtk.
     25        (WebCore::ScrollbarThemeChromiumLinux::paintThumb):
     26        * rendering/RenderThemeChromiumLinux.cpp:
     27        (WebCore::RenderThemeChromiumLinux::adjustInnerSpinButtonStyle): Added.
     28        (WebCore::RenderThemeChromiumLinux::paintInnerSpinButton): Added.
     29        * rendering/RenderThemeChromiumLinux.h:
     30
    1312010-07-13  Dumitru Daniliuc  <dumi@chromium.org>
    232
  • trunk/WebCore/WebCore.gypi

    r63278 r63280  
    21112111            'platform/chromium/PlatformKeyboardEventChromium.cpp',
    21122112            'platform/chromium/PlatformScreenChromium.cpp',
     2113            'platform/chromium/PlatformThemeChromiumGtk.cpp',
     2114            'platform/chromium/PlatformThemeChromiumGtk.h',
    21132115            'platform/chromium/PlatformWidget.h',
    21142116            'platform/chromium/PopupMenuChromium.cpp',
  • trunk/WebCore/platform/chromium/ScrollbarThemeChromiumLinux.cpp

    r61908 r63280  
    3434#include "PlatformContextSkia.h"
    3535#include "PlatformMouseEvent.h"
    36 #include "RenderTheme.h"
    37 #include "RenderThemeChromiumLinux.h"
     36#include "PlatformThemeChromiumGtk.h"
    3837#include "Scrollbar.h"
    3938#include "TransformationMatrix.h"
     
    7978}
    8079
    81 static SkScalar clamp(SkScalar value, SkScalar min, SkScalar max)
    82 {
    83     return std::min(std::max(value, min), max);
    84 }
    85 
    86 static SkColor saturateAndBrighten(SkScalar* hsv,
    87                                    SkScalar saturateAmount,
    88                                    SkScalar brightenAmount)
    89 {
    90     SkScalar color[3];
    91     color[0] = hsv[0];
    92     color[1] = clamp(hsv[1] + saturateAmount, 0.0, 1.0);
    93     color[2] = clamp(hsv[2] + brightenAmount, 0.0, 1.0);
    94     return SkHSVToColor(color);
    95 }
    96 
    97 static SkColor outlineColor(SkScalar* hsv1, SkScalar* hsv2)
    98 {
    99     // GTK Theme engines have way too much control over the layout of
    100     // the scrollbar. We might be able to more closely approximate its
    101     // look-and-feel, if we sent whole images instead of just colors
    102     // from the browser to the renderer. But even then, some themes
    103     // would just break.
    104     //
    105     // So, instead, we don't even try to 100% replicate the look of
    106     // the native scrollbar. We render our own version, but we make
    107     // sure to pick colors that blend in nicely with the system GTK
    108     // theme. In most cases, we can just sample a couple of pixels
    109     // from the system scrollbar and use those colors to draw our
    110     // scrollbar.
    111     //
    112     // This works fine for the track color and the overall thumb
    113     // color. But it fails spectacularly for the outline color used
    114     // around the thumb piece.  Not all themes have a clearly defined
    115     // outline. For some of them it is partially transparent, and for
    116     // others the thickness is very unpredictable.
    117     //
    118     // So, instead of trying to approximate the system theme, we
    119     // instead try to compute a reasonable looking choice based on the
    120     // known color of the track and the thumb piece. This is difficult
    121     // when trying to deal both with high- and low-contrast themes,
    122     // and both with positive and inverted themes.
    123     //
    124     // The following code has been tested to look OK with all of the
    125     // default GTK themes.
    126     SkScalar minDiff = clamp((hsv1[1] + hsv2[1]) * 1.2, 0.28, 0.5);
    127     SkScalar diff = clamp(fabs(hsv1[2] - hsv2[2]) / 2, minDiff, 0.5);
    128 
    129     if (hsv1[2] + hsv2[2] > 1.0)
    130         diff = -diff;
    131 
    132     return saturateAndBrighten(hsv2, -0.2, diff);
    133 }
    134 
    13580void ScrollbarThemeChromiumLinux::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType)
    13681{
     
    14186    skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height());
    14287    SkScalar trackHSV[3];
    143     SkColorToHSV(RenderThemeChromiumLinux::trackColor(), trackHSV);
    144     paint.setColor(saturateAndBrighten(trackHSV, 0, 0));
     88    SkColorToHSV(PlatformThemeChromiumGtk::trackColor(), trackHSV);
     89    paint.setColor(PlatformThemeChromiumGtk::saturateAndBrighten(trackHSV, 0, 0));
    14590    canvas->drawIRect(skrect, paint);
    14691
    14792    SkScalar thumbHSV[3];
    148     SkColorToHSV(RenderThemeChromiumLinux::thumbInactiveColor(),
     93    SkColorToHSV(PlatformThemeChromiumGtk::thumbInactiveColor(),
    14994                 thumbHSV);
    15095
    151     paint.setColor(outlineColor(trackHSV, thumbHSV));
     96    paint.setColor(PlatformThemeChromiumGtk::outlineColor(trackHSV, thumbHSV));
    15297    drawBox(canvas, rect, paint);
    15398}
     
    155100void ScrollbarThemeChromiumLinux::paintButton(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
    156101{
    157     SkCanvas* const canvas = gc->platformContext()->canvas();
    158     static const int widthMiddle = scrollbarThicknessValue / 2 + 1;
    159     static const int lengthMiddle = buttonLength / 2 + 1;
    160     SkPaint paint;
    161     enum {
    162         North,
    163         East,
    164         South,
    165         West,
    166     } direction;
    167 
     102    PlatformThemeChromiumGtk::ArrowDirection direction;
    168103    if (scrollbar->orientation() == HorizontalScrollbar) {
    169104        if (part == BackButtonStartPart)
    170             direction = West;
     105            direction = PlatformThemeChromiumGtk::West;
    171106        else
    172             direction = East;
     107            direction = PlatformThemeChromiumGtk::East;
    173108    } else {
    174109        if (part == BackButtonStartPart)
    175             direction = North;
     110            direction = PlatformThemeChromiumGtk::North;
    176111        else
    177             direction = South;
     112            direction = PlatformThemeChromiumGtk::South;
    178113    }
    179114
     115    ControlStates states = 0;
    180116    // Determine if the button can be pressed.
    181     bool enabled = false;
    182     if (((direction == West || direction == North) && scrollbar->currentPos())
    183         || (direction == East || direction == South) && scrollbar->currentPos() != scrollbar->maximum())
    184         enabled = true;
    185 
    186     // Calculate button color.
    187     SkScalar trackHSV[3];
    188     SkColorToHSV(RenderThemeChromiumLinux::trackColor(), trackHSV);
    189     SkColor buttonColor = saturateAndBrighten(trackHSV, 0, 0.2);
    190     SkColor backgroundColor = buttonColor;
    191     if (part == scrollbar->pressedPart()) {
    192         SkScalar buttonHSV[3];
    193         SkColorToHSV(buttonColor, buttonHSV);
    194         buttonColor = saturateAndBrighten(buttonHSV, 0, -0.1);
    195     } else if (part == scrollbar->hoveredPart() && enabled) {
    196         SkScalar buttonHSV[3];
    197         SkColorToHSV(buttonColor, buttonHSV);
    198         buttonColor = saturateAndBrighten(buttonHSV, 0, 0.05);
    199     }
    200 
    201     SkIRect skrect;
    202     skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height());
    203     // Paint the background (the area visible behind the rounded corners).
    204     paint.setColor(backgroundColor);
    205     canvas->drawIRect(skrect, paint);
    206 
    207     // Paint the button's outline and fill the middle
    208     SkPath outline;
    209     switch (direction) {
    210     case North:
    211         outline.moveTo(rect.x() + 0.5, rect.y() + rect.height() + 0.5);
    212         outline.rLineTo(0, -(rect.height() - 2));
    213         outline.rLineTo(2, -2);
    214         outline.rLineTo(rect.width() - 5, 0);
    215         outline.rLineTo(2, 2);
    216         outline.rLineTo(0, rect.height() - 2);
    217         break;
    218     case South:
    219         outline.moveTo(rect.x() + 0.5, rect.y() - 0.5);
    220         outline.rLineTo(0, rect.height() - 2);
    221         outline.rLineTo(2, 2);
    222         outline.rLineTo(rect.width() - 5, 0);
    223         outline.rLineTo(2, -2);
    224         outline.rLineTo(0, -(rect.height() - 2));
    225         break;
    226     case East:
    227         outline.moveTo(rect.x() - 0.5, rect.y() + 0.5);
    228         outline.rLineTo(rect.width() - 2, 0);
    229         outline.rLineTo(2, 2);
    230         outline.rLineTo(0, rect.height() - 5);
    231         outline.rLineTo(-2, 2);
    232         outline.rLineTo(-(rect.width() - 2), 0);
    233         break;
    234     case West:
    235         outline.moveTo(rect.x() + rect.width() + 0.5, rect.y() + 0.5);
    236         outline.rLineTo(-(rect.width() - 2), 0);
    237         outline.rLineTo(-2, 2);
    238         outline.rLineTo(0, rect.height() - 5);
    239         outline.rLineTo(2, 2);
    240         outline.rLineTo(rect.width() - 2, 0);
    241         break;
    242     }
    243     outline.close();
    244 
    245     paint.setStyle(SkPaint::kFill_Style);
    246     paint.setColor(buttonColor);
    247     canvas->drawPath(outline, paint);
    248 
    249     paint.setAntiAlias(true);
    250     paint.setStyle(SkPaint::kStroke_Style);
    251     SkScalar thumbHSV[3];
    252     SkColorToHSV(RenderThemeChromiumLinux::thumbInactiveColor(), thumbHSV);
    253     paint.setColor(outlineColor(trackHSV, thumbHSV));
    254     canvas->drawPath(outline, paint);
    255 
    256     // If the button is disabled, the arrow is drawn with the outline color.
    257     if (enabled)
    258         paint.setColor(SK_ColorBLACK);
    259 
    260     paint.setAntiAlias(false);
    261     paint.setStyle(SkPaint::kFill_Style);
    262 
    263     SkPath path;
    264     // The constants in this block of code are hand-tailored to produce good
    265     // looking arrows without anti-aliasing.
    266     switch (direction) {
    267     case North:
    268         path.moveTo(rect.x() + widthMiddle - 4, rect.y() + lengthMiddle + 2);
    269         path.rLineTo(7, 0);
    270         path.rLineTo(-4, -4);
    271         break;
    272     case South:
    273         path.moveTo(rect.x() + widthMiddle - 4, rect.y() + lengthMiddle - 3);
    274         path.rLineTo(7, 0);
    275         path.rLineTo(-4, 4);
    276         break;
    277     case East:
    278         path.moveTo(rect.x() + lengthMiddle - 3, rect.y() + widthMiddle - 4);
    279         path.rLineTo(0, 7);
    280         path.rLineTo(4, -4);
    281         break;
    282     case West:
    283         path.moveTo(rect.x() + lengthMiddle + 1, rect.y() + widthMiddle - 5);
    284         path.rLineTo(0, 9);
    285         path.rLineTo(-4, -4);
    286         break;
    287     }
    288     path.close();
    289 
    290     canvas->drawPath(path, paint);
     117    if (((direction == PlatformThemeChromiumGtk::West || direction == PlatformThemeChromiumGtk::North) && scrollbar->currentPos())
     118        || (direction == PlatformThemeChromiumGtk::East || direction == PlatformThemeChromiumGtk::South) && scrollbar->currentPos() != scrollbar->maximum())
     119        states |= EnabledState;
     120
     121    if (part == scrollbar->pressedPart())
     122        states |= PressedState;
     123    else if (part == scrollbar->hoveredPart() && states & EnabledState)
     124        states |= HoverState;
     125
     126    PlatformThemeChromiumGtk::paintArrowButton(gc, rect, direction, states);
    291127}
    292128
     
    301137    SkScalar thumb[3];
    302138    SkColorToHSV(hovered
    303                  ? RenderThemeChromiumLinux::thumbActiveColor()
    304                  : RenderThemeChromiumLinux::thumbInactiveColor(),
     139                 ? PlatformThemeChromiumGtk::thumbActiveColor()
     140                 : PlatformThemeChromiumGtk::thumbInactiveColor(),
    305141                 thumb);
    306142
    307143    SkPaint paint;
    308     paint.setColor(saturateAndBrighten(thumb, 0, 0.02));
     144    paint.setColor(PlatformThemeChromiumGtk::saturateAndBrighten(thumb, 0, 0.02));
    309145
    310146    SkIRect skrect;
     
    316152    canvas->drawIRect(skrect, paint);
    317153
    318     paint.setColor(saturateAndBrighten(thumb, 0, -0.02));
     154    paint.setColor(PlatformThemeChromiumGtk::saturateAndBrighten(thumb, 0, -0.02));
    319155
    320156    if (vertical)
     
    326162
    327163    SkScalar track[3];
    328     SkColorToHSV(RenderThemeChromiumLinux::trackColor(), track);
    329     paint.setColor(outlineColor(track, thumb));
     164    SkColorToHSV(PlatformThemeChromiumGtk::trackColor(), track);
     165    paint.setColor(PlatformThemeChromiumGtk::outlineColor(track, thumb));
    330166    drawBox(canvas, rect, paint);
    331167
  • trunk/WebCore/rendering/RenderThemeChromiumLinux.cpp

    r61908 r63280  
    2828#include "CSSValueKeywords.h"
    2929#include "Color.h"
     30#include "PlatformThemeChromiumGtk.h"
    3031#include "RenderObject.h"
     32#include "ScrollbarTheme.h"
    3133#include "UserAgentStyleSheets.h"
    3234
    3335namespace WebCore {
    3436
    35 unsigned RenderThemeChromiumLinux::m_thumbInactiveColor = 0xeaeaea;
    36 unsigned RenderThemeChromiumLinux::m_thumbActiveColor = 0xf4f4f4;
    37 unsigned RenderThemeChromiumLinux::m_trackColor = 0xd3d3d3;
    3837unsigned RenderThemeChromiumLinux::m_activeSelectionBackgroundColor =
    3938    0xff1e90ff;
     
    169168}
    170169
    171 void RenderThemeChromiumLinux::setScrollbarColors(
    172     SkColor inactiveColor, SkColor activeColor, SkColor trackColor)
     170void RenderThemeChromiumLinux::adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
    173171{
    174     m_thumbInactiveColor = inactiveColor;
    175     m_thumbActiveColor = activeColor;
    176     m_trackColor = trackColor;
     172    int width = ScrollbarTheme::nativeTheme()->scrollbarThickness();
     173    style->setWidth(Length(width, Fixed));
     174    style->setMinWidth(Length(width, Fixed));
     175}
     176
     177bool RenderThemeChromiumLinux::paintInnerSpinButton(RenderObject* object, const PaintInfo& info, const IntRect& rect)
     178{
     179    ControlStates northStates = controlStatesForRenderer(object);
     180    ControlStates southStates = northStates;
     181    if (northStates & SpinUpState)
     182        southStates &= ~(HoverState | PressedState);
     183    else
     184        northStates &= ~(HoverState | PressedState);
     185
     186    IntRect half = rect;
     187    half.setHeight(rect.height() / 2);
     188    PlatformThemeChromiumGtk::paintArrowButton(info.context, half, PlatformThemeChromiumGtk::North, northStates);
     189
     190    half.setY(rect.y() + rect.height() / 2);
     191    PlatformThemeChromiumGtk::paintArrowButton(info.context, half, PlatformThemeChromiumGtk::South, southStates);
     192    return false;
    177193}
    178194
  • trunk/WebCore/rendering/RenderThemeChromiumLinux.h

    r54280 r63280  
    6060        virtual double caretBlinkIntervalInternal() const;
    6161
     62        virtual void adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
     63        virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&);
     64
    6265        static void setSelectionColors(unsigned activeBackgroundColor,
    6366                                       unsigned activeForegroundColor,
    6467                                       unsigned inactiveBackgroundColor,
    6568                                       unsigned inactiveForegroundColor);
    66 
    67         static void setScrollbarColors(unsigned inactive_color,
    68                                        unsigned active_color,
    69                                        unsigned track_color);
    70         static unsigned thumbInactiveColor() { return m_thumbInactiveColor; }
    71         static unsigned thumbActiveColor() { return m_thumbActiveColor; }
    72         static unsigned trackColor() { return m_trackColor; }
    7369
    7470    private:
     
    8581        static unsigned m_inactiveSelectionBackgroundColor;
    8682        static unsigned m_inactiveSelectionForegroundColor;
    87 
    88         static unsigned m_thumbInactiveColor;
    89         static unsigned m_thumbActiveColor;
    90         static unsigned m_trackColor;
    9183    };
    9284
  • trunk/WebKit/chromium/ChangeLog

    r63258 r63280  
     12010-07-13  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        [Chromium] Linux implementation of <input type=number> UI
     6        https://bugs.webkit.org/show_bug.cgi?id=41925
     7
     8        * src/WebViewImpl.cpp:
     9        (WebKit::WebViewImpl::setScrollbarColors):
     10         Call PlatformThemeChromiumGtk::setScrollbarColors() instead of
     11         RenderThemeChromiumLinux::setScrollbarColors().
     12
    1132010-07-13  Chris Guillory  <chris.guillory@google.com>
    214
  • trunk/WebKit/chromium/src/WebViewImpl.cpp

    r63080 r63280  
    7474#include "PlatformKeyboardEvent.h"
    7575#include "PlatformMouseEvent.h"
     76#include "PlatformThemeChromiumGtk.h"
    7677#include "PlatformWheelEvent.h"
    7778#include "PopupMenuChromium.h"
     
    18531854                                     unsigned trackColor) {
    18541855#if OS(LINUX)
    1855     RenderThemeChromiumLinux::setScrollbarColors(inactiveColor,
     1856    PlatformThemeChromiumGtk::setScrollbarColors(inactiveColor,
    18561857                                                 activeColor,
    18571858                                                 trackColor);
Note: See TracChangeset for help on using the changeset viewer.