summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell/test_shell_webthemecontrol.h
blob: bb439afe04b7dac79ba5a0909841e401fe81802c (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (c) 2009 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.

// TestShellWebTheme::Control implements the generic rendering of controls
// needed by TestShellWebTheme::Engine. See the comments in that class
// header file for why this class is needed and used.
//
// This class implements a generic set of widgets using Skia. The widgets
// are optimized for testability, not a pleasing appearance.
//

#ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBTHEMECONTROL_H_
#define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBTHEMECONTROL_H_

#include "base/basictypes.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkRect.h"

namespace TestShellWebTheme {

class Control {
 public:
  // This list of states mostly mirrors the list in
  // third_party/WebKit/WebCore/platform/ThemeTypes.h but is maintained
  // separately since that isn't public and also to minimize dependencies.
  // Note that the WebKit ThemeTypes seem to imply that a control can be
  // in multiple states simultaneously but WebThemeEngine only allows for
  // a single state at a time.
  //
  // Some definitions for the various states:
  //   Disabled - indicates that a control can't be modified or selected
  //              (corresponds to HTML 'disabled' attribute)
  //   ReadOnly - indicates that a control can't be modified but can be
  //              selected
  //   Normal   - the normal state of control on the page when it isn't
  //              focused or otherwise active
  //   Hot      - when the mouse is hovering over a part of the control,
  //              all the other parts are considered "hot"
  //   Hover    - when the mouse is directly over a control (the CSS
  //               :hover pseudo-class)
  //   Focused  - when the control has the keyboard focus
  //   Pressed  - when the control is being triggered (by a mousedown or
  //              a key event).
  enum State {
    kUnknown_State = 0,
    kDisabled_State,
    kReadOnly_State,
    kNormal_State,
    kHot_State,
    kHover_State,
    kFocused_State,
    kPressed_State
  };

  // This list of types mostly mirrors the list in
  // third_party/WebKit/WebCore/platform/ThemeTypes.h but is maintained
  // separately since that isn't public and also to minimize dependencies.
  //
  // Note that what the user might think of as a single control can be
  // made up of multiple parts. For example, a single scroll bar contains
  // six clickable parts - two arrows, the "thumb" indicating the current
  // position on the bar, the other two parts of the bar (before and after
  // the thumb) and the "gripper" on the thumb itself.
  //
  enum Type {
    kUnknown_Type = 0,
    kTextField_Type,
    kPushButton_Type,
    kUncheckedBox_Type,
    kCheckedBox_Type,
    kUncheckedRadio_Type,
    kCheckedRadio_Type,
    kHorizontalScrollTrackBack_Type,
    kHorizontalScrollTrackForward_Type,
    kHorizontalScrollThumb_Type,
    kHorizontalScrollGrip_Type,
    kVerticalScrollTrackBack_Type,
    kVerticalScrollTrackForward_Type,
    kVerticalScrollThumb_Type,
    kVerticalScrollGrip_Type,
    kLeftArrow_Type,
    kRightArrow_Type,
    kUpArrow_Type,
    kDownArrow_Type,
    kHorizontalSliderTrack_Type,
    kHorizontalSliderThumb_Type,
    kDropDownButton_Type
  };

  // canvas is the canvas to draw onto, and rect gives the size of the
  // control. ctype and cstate specify the type and state of the control.
  Control(skia::PlatformCanvas *canvas, const SkIRect &rect,
          Type ctype, State cstate);
  ~Control();

  // Draws the control.
  void draw();

  // Use this for TextField controls instead, because the logic
  // for drawing them is dependent on what WebKit tells us to do.
  // If draw_edges is true, draw an edge around the control. If
  // fill_content_area is true, fill the content area with the given color.
  void drawTextField(bool draw_edges, bool fill_content_area, SkColor color);

 private:
  // Draws a box of size specified by irect, filled with the given color.
  // The box will have a border drawn in the default edge color.
  void box(const SkIRect &irect, SkColor color);


  // Draws a triangle of size specified by the three pairs of coordinates,
  // filled with the given color. The box will have an edge drawn in the
  // default edge color.
  void triangle(int x0, int y0, int x1, int y1, int x2, int y2,
                SkColor color);

  // Draws a rectangle the size of the control with rounded corners, filled
  // with the specified color (and with a border in the default edge color).
  void roundRect(SkColor color);

  // Draws an oval the size of the control, filled with the specified color
  // and with a border in the default edge color.
  void oval(SkColor color);

  // Draws a circle centered in the control with the specified radius,
  // filled with the specified color, and with a border draw in the
  // default edge color.
  void circle(SkScalar radius, SkColor color);

  // Draws a box the size of the control, filled with the outer_color and
  // with a border in the default edge color, and then draws another box
  // indented on all four sides by the specified amounts, filled with the
  // inner color and with a border in the default edge color.
  void nested_boxes(int indent_left, int indent_top,
                    int indent_right, int indent_bottom,
                    SkColor outer_color, SkColor inner_color);

  // Draws a line between the two points in the given color.
  void line(int x0, int y0, int x1, int y1, SkColor color);

  // Draws a distinctive mark on the control for each state, so that the
  // state of the control can be determined without needing to know which
  // color is which.
  void markState();

  skia::PlatformCanvas* canvas_;
  const SkIRect irect_;
  const Type type_;
  const State state_;
  const SkColor edge_color_;
  const SkColor bg_color_;
  const SkColor fg_color_;

  // The following are convenience accessors for irect_.
  const int left_;
  const int right_;
  const int top_;
  const int bottom_;
  const int width_;
  const int height_;

  DISALLOW_COPY_AND_ASSIGN(Control);
};

}  // namespace TestShellWebTheme

#endif  // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBTHEMECONTROL_H_