Home | History | Annotate | Download | only in native_theme
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef UI_NATIVE_THEME_NATIVE_THEME_BASE_H_
      6 #define UI_NATIVE_THEME_NATIVE_THEME_BASE_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "skia/ext/platform_canvas.h"
     11 #include "ui/native_theme/native_theme.h"
     12 
     13 namespace gfx {
     14 class ImageSkia;
     15 class Rect;
     16 class Size;
     17 }
     18 
     19 namespace ui {
     20 
     21 // Theme support for non-Windows toolkits.
     22 class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme {
     23  public:
     24   // NativeTheme implementation:
     25   virtual gfx::Size GetPartSize(Part part,
     26                                 State state,
     27                                 const ExtraParams& extra) const OVERRIDE;
     28   virtual void Paint(SkCanvas* canvas,
     29                      Part part,
     30                      State state,
     31                      const gfx::Rect& rect,
     32                      const ExtraParams& extra) const OVERRIDE;
     33 
     34  protected:
     35   NativeThemeBase();
     36   virtual ~NativeThemeBase();
     37 
     38   // Draw the arrow. Used by scrollbar and inner spin button.
     39   virtual void PaintArrowButton(
     40       SkCanvas* gc,
     41       const gfx::Rect& rect,
     42       Part direction,
     43       State state) const;
     44   // Paint the scrollbar track. Done before the thumb so that it can contain
     45   // alpha.
     46   virtual void PaintScrollbarTrack(
     47       SkCanvas* canvas,
     48       Part part,
     49       State state,
     50       const ScrollbarTrackExtraParams& extra_params,
     51       const gfx::Rect& rect) const;
     52   // Draw the scrollbar thumb over the track.
     53   virtual void PaintScrollbarThumb(
     54       SkCanvas* canvas,
     55       Part part,
     56       State state,
     57       const gfx::Rect& rect) const;
     58 
     59   virtual void PaintCheckbox(
     60       SkCanvas* canvas,
     61       State state,
     62       const gfx::Rect& rect,
     63       const ButtonExtraParams& button) const;
     64 
     65   virtual void PaintRadio(
     66       SkCanvas* canvas,
     67       State state,
     68       const gfx::Rect& rect,
     69       const ButtonExtraParams& button) const;
     70 
     71   virtual void PaintButton(
     72       SkCanvas* canvas,
     73       State state,
     74       const gfx::Rect& rect,
     75       const ButtonExtraParams& button) const;
     76 
     77   virtual void PaintTextField(
     78       SkCanvas* canvas,
     79       State state,
     80       const gfx::Rect& rect,
     81       const TextFieldExtraParams& text) const;
     82 
     83   virtual void PaintMenuList(
     84       SkCanvas* canvas,
     85       State state,
     86       const gfx::Rect& rect,
     87       const MenuListExtraParams& menu_list) const;
     88 
     89   virtual void PaintMenuPopupBackground(
     90       SkCanvas* canvas,
     91       const gfx::Size& size,
     92       const MenuBackgroundExtraParams& menu_background) const;
     93 
     94   virtual void PaintMenuItemBackground(
     95       SkCanvas* canvas,
     96       State state,
     97       const gfx::Rect& rect,
     98       const MenuListExtraParams& menu_list) const;
     99 
    100   virtual void PaintSliderTrack(
    101       SkCanvas* canvas,
    102       State state,
    103       const gfx::Rect& rect,
    104       const SliderExtraParams& slider) const;
    105 
    106   virtual void PaintSliderThumb(
    107       SkCanvas* canvas,
    108       State state,
    109       const gfx::Rect& rect,
    110       const SliderExtraParams& slider) const;
    111 
    112   virtual void PaintInnerSpinButton(
    113       SkCanvas* canvas,
    114       State state,
    115       const gfx::Rect& rect,
    116       const InnerSpinButtonExtraParams& spin_button) const;
    117 
    118   virtual void PaintProgressBar(
    119       SkCanvas* canvas,
    120       State state,
    121       const gfx::Rect& rect,
    122       const ProgressBarExtraParams& progress_bar) const;
    123 
    124  protected:
    125   void set_scrollbar_button_length(unsigned int length) {
    126     scrollbar_button_length_ = length;
    127   }
    128 
    129   bool IntersectsClipRectInt(SkCanvas* canvas,
    130                              int x, int y, int w, int h) const;
    131 
    132   void DrawImageInt(SkCanvas* canvas, const gfx::ImageSkia& image,
    133                     int src_x, int src_y, int src_w, int src_h,
    134                     int dest_x, int dest_y, int dest_w, int dest_h) const;
    135 
    136   void DrawTiledImage(SkCanvas* canvas,
    137                       const gfx::ImageSkia& image,
    138                       int src_x, int src_y,
    139                       float tile_scale_x, float tile_scale_y,
    140                       int dest_x, int dest_y, int w, int h) const;
    141 
    142   SkColor SaturateAndBrighten(SkScalar* hsv,
    143                               SkScalar saturate_amount,
    144                               SkScalar brighten_amount) const;
    145  private:
    146   void DrawVertLine(SkCanvas* canvas,
    147                     int x,
    148                     int y1,
    149                     int y2,
    150                     const SkPaint& paint) const;
    151   void DrawHorizLine(SkCanvas* canvas,
    152                      int x1,
    153                      int x2,
    154                      int y,
    155                      const SkPaint& paint) const;
    156   void DrawBox(SkCanvas* canvas,
    157                const gfx::Rect& rect,
    158                const SkPaint& paint) const;
    159   SkScalar Clamp(SkScalar value,
    160                  SkScalar min,
    161                  SkScalar max) const;
    162   SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const;
    163 
    164   // Paint the common parts of the checkboxes and radio buttons.
    165   // borderRadius specifies how rounded the corners should be.
    166   SkRect PaintCheckboxRadioCommon(
    167       SkCanvas* canvas,
    168       State state,
    169       const gfx::Rect& rect,
    170       const SkScalar borderRadius) const;
    171 
    172   unsigned int scrollbar_width_;
    173   unsigned int scrollbar_button_length_;
    174 
    175   DISALLOW_COPY_AND_ASSIGN(NativeThemeBase);
    176 };
    177 
    178 }  // namespace ui
    179 
    180 #endif  // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_
    181