summaryrefslogtreecommitdiffstats
path: root/gfx/native_theme_linux.h
blob: 62a84e989cecc953baed6820fce7cdc72415d102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GFX_NATIVE_THEME_LINUX_H_
#define GFX_NATIVE_THEME_LINUX_H_

#include "base/basictypes.h"
#include "skia/ext/platform_canvas.h"

namespace skia {
class PlatformCanvas;
}

namespace gfx {
class Rect;
class Size;

// Linux theming API.
class NativeThemeLinux {
 public:
  // Gets our singleton instance.
  static NativeThemeLinux* instance();

  // The part to be painted / sized.
  enum Part {
    kScrollbarDownArrow,
    kScrollbarLeftArrow,
    kScrollbarRightArrow,
    kScrollbarUpArrow,
    kScrollbarHorizontalThumb,
    kScrollbarVerticalThumb,
    kScrollbarHorizontalTrack,
    kScrollbarVerticalTrack
  };

  // The state of the part.
  enum State {
    kDisabled,
    kHover,
    kNormal,
    kPressed,
  };

  // Extra data needed to draw scrollbar track correctly.
  struct ScrollbarTrackExtraParams {
    int track_x;
    int track_y;
    int track_width;
    int track_height;
  };

  union ExtraParams {
    ScrollbarTrackExtraParams scrollbar_track;
  };

  // Return the size of the part.
  virtual gfx::Size GetSize(Part part) const;
  // Paint the part to the canvas.
  virtual void Paint(skia::PlatformCanvas* canvas,
                     Part part,
                     State state,
                     const gfx::Rect& rect,
                     const ExtraParams& extra);
  // Supports theme specific colors.
  void SetScrollbarColors(unsigned inactive_color,
                          unsigned active_color,
                          unsigned track_color) const;

 protected:
  NativeThemeLinux();
  virtual ~NativeThemeLinux();

  // Draw the arrow.
  virtual void PaintArrowButton(
      skia::PlatformCanvas* gc,
      const gfx::Rect& rect,
      Part direction,
      State state);
  // Paint the track. Done before the thumb so that it can contain alpha.
  virtual void PaintTrack(skia::PlatformCanvas* canvas,
                  Part part,
                  State state,
                  const ScrollbarTrackExtraParams& extra_params,
                  const gfx::Rect& rect);
  // Draw the thumb over the track.
  virtual void PaintThumb(skia::PlatformCanvas* canvas,
                  Part part,
                  State state,
                  const gfx::Rect& rect);

 private:
  void DrawVertLine(SkCanvas* canvas,
                    int x,
                    int y1,
                    int y2,
                    const SkPaint& paint) const;
  void DrawHorizLine(SkCanvas* canvas,
                     int x1,
                     int x2,
                     int y,
                     const SkPaint& paint) const;
  void DrawBox(SkCanvas* canvas,
               const gfx::Rect& rect,
               const SkPaint& paint) const;
  SkScalar Clamp(SkScalar value,
                 SkScalar min,
                 SkScalar max) const;
  SkColor SaturateAndBrighten(SkScalar* hsv,
                              SkScalar saturate_amount,
                              SkScalar brighten_amount) const;
  SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const;

  static unsigned int scrollbar_width_;
  static unsigned int button_length_;
  static unsigned int thumb_inactive_color_;
  static unsigned int thumb_active_color_;
  static unsigned int track_color_;

  DISALLOW_COPY_AND_ASSIGN(NativeThemeLinux);
};

}  // namespace gfx

#endif  // GFX_NATIVE_THEME_LINUX_H_