|
1 /* |
|
2 * Copyright (C) 2010 Google Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions are |
|
6 * met: |
|
7 * |
|
8 * * Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * * Redistributions in binary form must reproduce the above |
|
11 * copyright notice, this list of conditions and the following disclaimer |
|
12 * in the documentation and/or other materials provided with the |
|
13 * distribution. |
|
14 * * Neither the name of Google Inc. nor the names of its |
|
15 * contributors may be used to endorse or promote products derived from |
|
16 * this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 */ |
|
30 |
|
31 // WebThemeControlDRT implements the generic rendering of controls |
|
32 // needed by WebThemeEngineDRT. See the comments in that class |
|
33 // header file for why this class is needed and used. |
|
34 // |
|
35 // This class implements a generic set of widgets using Skia. The widgets |
|
36 // are optimized for testability, not a pleasing appearance. |
|
37 // |
|
38 |
|
39 #ifndef WebThemeControlDRT_h |
|
40 #define WebThemeControlDRT_h |
|
41 |
|
42 #include "skia/ext/platform_canvas.h" |
|
43 #include "third_party/skia/include/core/SkColor.h" |
|
44 #include <wtf/Noncopyable.h> |
|
45 |
|
46 // Skia forward declarations |
|
47 struct SkIRect; |
|
48 |
|
49 class WebThemeControlDRT : public Noncopyable { |
|
50 public: |
|
51 // This list of states mostly mirrors the list in WebCore/platform/ThemeTypes.h |
|
52 // but is maintained separately since that isn't public and also to minimize |
|
53 // dependencies. |
|
54 // Note that the WebKit ThemeTypes seem to imply that a control can be |
|
55 // in multiple states simultaneously but WebThemeEngine only allows for |
|
56 // a single state at a time. |
|
57 // |
|
58 // Some definitions for the various states: |
|
59 // Disabled - indicates that a control can't be modified or selected |
|
60 // (corresponds to HTML 'disabled' attribute) |
|
61 // ReadOnly - indicates that a control can't be modified but can be |
|
62 // selected |
|
63 // Normal - the normal state of control on the page when it isn't |
|
64 // focused or otherwise active |
|
65 // Hot - when the mouse is hovering over a part of the control, |
|
66 // all the other parts are considered "hot" |
|
67 // Hover - when the mouse is directly over a control (the CSS |
|
68 // :hover pseudo-class) |
|
69 // Focused - when the control has the keyboard focus |
|
70 // Pressed - when the control is being triggered (by a mousedown or |
|
71 // a key event). |
|
72 // Indeterminate - when set to indeterminate (only for progress bar) |
|
73 enum State { |
|
74 UnknownState = 0, |
|
75 DisabledState, |
|
76 ReadOnlyState, |
|
77 NormalState, |
|
78 HotState, |
|
79 HoverState, |
|
80 FocusedState, |
|
81 PressedState, |
|
82 IndeterminateState |
|
83 }; |
|
84 |
|
85 // This list of types mostly mirrors the list in |
|
86 // WebCore/platform/ThemeTypes.h but is maintained |
|
87 // separately since that isn't public and also to minimize dependencies. |
|
88 // |
|
89 // Note that what the user might think of as a single control can be |
|
90 // made up of multiple parts. For example, a single scroll bar contains |
|
91 // six clickable parts - two arrows, the "thumb" indicating the current |
|
92 // position on the bar, the other two parts of the bar (before and after |
|
93 // the thumb) and the "gripper" on the thumb itself. |
|
94 // |
|
95 enum Type { |
|
96 UnknownType = 0, |
|
97 TextFieldType, |
|
98 PushButtonType, |
|
99 UncheckedBoxType, |
|
100 CheckedBoxType, |
|
101 IndeterminateCheckboxType, |
|
102 UncheckedRadioType, |
|
103 CheckedRadioType, |
|
104 HorizontalScrollTrackBackType, |
|
105 HorizontalScrollTrackForwardType, |
|
106 HorizontalScrollThumbType, |
|
107 HorizontalScrollGripType, |
|
108 VerticalScrollTrackBackType, |
|
109 VerticalScrollTrackForwardType, |
|
110 VerticalScrollThumbType, |
|
111 VerticalScrollGripType, |
|
112 LeftArrowType, |
|
113 RightArrowType, |
|
114 UpArrowType, |
|
115 DownArrowType, |
|
116 HorizontalSliderTrackType, |
|
117 HorizontalSliderThumbType, |
|
118 DropDownButtonType, |
|
119 ProgressBarType |
|
120 }; |
|
121 |
|
122 // canvas is the canvas to draw onto, and rect gives the size of the |
|
123 // control. ctype and cstate specify the type and state of the control. |
|
124 WebThemeControlDRT(skia::PlatformCanvas* canvas, |
|
125 const SkIRect& rect, |
|
126 Type ctype, |
|
127 State cstate); |
|
128 ~WebThemeControlDRT(); |
|
129 |
|
130 // Draws the control. |
|
131 void draw(); |
|
132 |
|
133 // Use this for TextField controls instead, because the logic |
|
134 // for drawing them is dependent on what WebKit tells us to do. |
|
135 // If drawEdges is true, draw an edge around the control. If |
|
136 // fillContentArea is true, fill the content area with the given color. |
|
137 void drawTextField(bool drawEdges, bool fillContentArea, SkColor color); |
|
138 |
|
139 // Use this for drawing ProgressBar controls instead, since we |
|
140 // need to know the rect to fill inside the bar. |
|
141 void drawProgressBar(const SkIRect& fillRect); |
|
142 |
|
143 private: |
|
144 // Draws a box of size specified by irect, filled with the given color. |
|
145 // The box will have a border drawn in the default edge color. |
|
146 void box(const SkIRect& irect, SkColor color); |
|
147 |
|
148 |
|
149 // Draws a triangle of size specified by the three pairs of coordinates, |
|
150 // filled with the given color. The box will have an edge drawn in the |
|
151 // default edge color. |
|
152 void triangle(int x0, int y0, int x1, int y1, int x2, int y2, SkColor color); |
|
153 |
|
154 // Draws a rectangle the size of the control with rounded corners, filled |
|
155 // with the specified color (and with a border in the default edge color). |
|
156 void roundRect(SkColor color); |
|
157 |
|
158 // Draws an oval the size of the control, filled with the specified color |
|
159 // and with a border in the default edge color. |
|
160 void oval(SkColor color); |
|
161 |
|
162 // Draws a circle centered in the control with the specified radius, |
|
163 // filled with the specified color, and with a border draw in the |
|
164 // default edge color. |
|
165 void circle(SkScalar radius, SkColor color); |
|
166 |
|
167 // Draws a box the size of the control, filled with the outerColor and |
|
168 // with a border in the default edge color, and then draws another box |
|
169 // indented on all four sides by the specified amounts, filled with the |
|
170 // inner color and with a border in the default edge color. |
|
171 void nestedBoxes(int indentLeft, |
|
172 int indentTop, |
|
173 int indentRight, |
|
174 int indentBottom, |
|
175 SkColor outerColor, |
|
176 SkColor innerColor); |
|
177 |
|
178 // Draws a line between the two points in the given color. |
|
179 void line(int x0, int y0, int x1, int y1, SkColor color); |
|
180 |
|
181 // Draws a distinctive mark on the control for each state, so that the |
|
182 // state of the control can be determined without needing to know which |
|
183 // color is which. |
|
184 void markState(); |
|
185 |
|
186 skia::PlatformCanvas* m_canvas; |
|
187 const SkIRect m_irect; |
|
188 const Type m_type; |
|
189 const State m_state; |
|
190 const SkColor m_edgeColor; |
|
191 const SkColor m_bgColor; |
|
192 const SkColor m_fgColor; |
|
193 |
|
194 // The following are convenience accessors for m_irect. |
|
195 const int m_left; |
|
196 const int m_right; |
|
197 const int m_top; |
|
198 const int m_bottom; |
|
199 const int m_width; |
|
200 const int m_height; |
|
201 }; |
|
202 |
|
203 #endif // WebThemeControlDRT_h |