| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 // TestShellWebTheme::Control implements the generic rendering of controls | |
| 6 // needed by TestShellWebTheme::Engine. See the comments in that class | |
| 7 // header file for why this class is needed and used. | |
| 8 // | |
| 9 // This class implements a generic set of widgets using Skia. The widgets | |
| 10 // are optimized for testability, not a pleasing appearance. | |
| 11 // | |
| 12 | |
| 13 #ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBTHEMECONTROL_H_ | |
| 14 #define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBTHEMECONTROL_H_ | |
| 15 | |
| 16 #include "base/basictypes.h" | |
| 17 #include "third_party/skia/include/core/SkColor.h" | |
| 18 #include "third_party/skia/include/core/SkRect.h" | |
| 19 | |
| 20 class SkCanvas; | |
| 21 | |
| 22 namespace TestShellWebTheme { | |
| 23 | |
| 24 class Control { | |
| 25 public: | |
| 26 // This list of states mostly mirrors the list in | |
| 27 // third_party/WebKit/WebCore/platform/ThemeTypes.h but is maintained | |
| 28 // separately since that isn't public and also to minimize dependencies. | |
| 29 // Note that the WebKit ThemeTypes seem to imply that a control can be | |
| 30 // in multiple states simultaneously but WebThemeEngine only allows for | |
| 31 // a single state at a time. | |
| 32 // | |
| 33 // Some definitions for the various states: | |
| 34 // Disabled - indicates that a control can't be modified or selected | |
| 35 // (corresponds to HTML 'disabled' attribute) | |
| 36 // ReadOnly - indicates that a control can't be modified but can be | |
| 37 // selected | |
| 38 // Normal - the normal state of control on the page when it isn't | |
| 39 // focused or otherwise active | |
| 40 // Hot - when the mouse is hovering over a part of the control, | |
| 41 // all the other parts are considered "hot" | |
| 42 // Hover - when the mouse is directly over a control (the CSS | |
| 43 // :hover pseudo-class) | |
| 44 // Focused - when the control has the keyboard focus | |
| 45 // Pressed - when the control is being triggered (by a mousedown or | |
| 46 // a key event). | |
| 47 // Indeterminate - when set to indeterminate (only for progress bar) | |
| 48 enum State { | |
| 49 kUnknown_State = 0, | |
| 50 kDisabled_State, | |
| 51 kReadOnly_State, | |
| 52 kNormal_State, | |
| 53 kHot_State, | |
| 54 kHover_State, | |
| 55 kFocused_State, | |
| 56 kPressed_State, | |
| 57 kIndeterminate_State | |
| 58 }; | |
| 59 | |
| 60 // This list of types mostly mirrors the list in | |
| 61 // third_party/WebKit/WebCore/platform/ThemeTypes.h but is maintained | |
| 62 // separately since that isn't public and also to minimize dependencies. | |
| 63 // | |
| 64 // Note that what the user might think of as a single control can be | |
| 65 // made up of multiple parts. For example, a single scroll bar contains | |
| 66 // six clickable parts - two arrows, the "thumb" indicating the current | |
| 67 // position on the bar, the other two parts of the bar (before and after | |
| 68 // the thumb) and the "gripper" on the thumb itself. | |
| 69 // | |
| 70 enum Type { | |
| 71 kUnknown_Type = 0, | |
| 72 kTextField_Type, | |
| 73 kPushButton_Type, | |
| 74 kUncheckedBox_Type, | |
| 75 kCheckedBox_Type, | |
| 76 kIndeterminateCheckBox_Type, | |
| 77 kUncheckedRadio_Type, | |
| 78 kCheckedRadio_Type, | |
| 79 kHorizontalScrollTrackBack_Type, | |
| 80 kHorizontalScrollTrackForward_Type, | |
| 81 kHorizontalScrollThumb_Type, | |
| 82 kHorizontalScrollGrip_Type, | |
| 83 kVerticalScrollTrackBack_Type, | |
| 84 kVerticalScrollTrackForward_Type, | |
| 85 kVerticalScrollThumb_Type, | |
| 86 kVerticalScrollGrip_Type, | |
| 87 kLeftArrow_Type, | |
| 88 kRightArrow_Type, | |
| 89 kUpArrow_Type, | |
| 90 kDownArrow_Type, | |
| 91 kHorizontalSliderTrack_Type, | |
| 92 kHorizontalSliderThumb_Type, | |
| 93 kDropDownButton_Type, | |
| 94 kProgressBar_Type | |
| 95 }; | |
| 96 | |
| 97 // canvas is the canvas to draw onto, and rect gives the size of the | |
| 98 // control. ctype and cstate specify the type and state of the control. | |
| 99 Control(SkCanvas* canvas, const SkIRect& rect, | |
| 100 Type ctype, State cstate); | |
| 101 ~Control(); | |
| 102 | |
| 103 // Draws the control. | |
| 104 void draw(); | |
| 105 | |
| 106 // Use this for TextField controls instead, because the logic | |
| 107 // for drawing them is dependent on what WebKit tells us to do. | |
| 108 // If draw_edges is true, draw an edge around the control. If | |
| 109 // fill_content_area is true, fill the content area with the given color. | |
| 110 void drawTextField(bool draw_edges, bool fill_content_area, SkColor color); | |
| 111 | |
| 112 // Use this for drawing ProgressBar controls instead, since we | |
| 113 // need to know the rect to fill inside the bar. | |
| 114 void drawProgressBar(const SkIRect& fill_rect); | |
| 115 | |
| 116 private: | |
| 117 // Draws a box of size specified by irect, filled with the given color. | |
| 118 // The box will have a border drawn in the default edge color. | |
| 119 void box(const SkIRect& irect, SkColor color); | |
| 120 | |
| 121 | |
| 122 // Draws a triangle of size specified by the three pairs of coordinates, | |
| 123 // filled with the given color. The box will have an edge drawn in the | |
| 124 // default edge color. | |
| 125 void triangle(int x0, int y0, int x1, int y1, int x2, int y2, | |
| 126 SkColor color); | |
| 127 | |
| 128 // Draws a rectangle the size of the control with rounded corners, filled | |
| 129 // with the specified color (and with a border in the default edge color). | |
| 130 void roundRect(SkColor color); | |
| 131 | |
| 132 // Draws an oval the size of the control, filled with the specified color | |
| 133 // and with a border in the default edge color. | |
| 134 void oval(SkColor color); | |
| 135 | |
| 136 // Draws a circle centered in the control with the specified radius, | |
| 137 // filled with the specified color, and with a border draw in the | |
| 138 // default edge color. | |
| 139 void circle(SkScalar radius, SkColor color); | |
| 140 | |
| 141 // Draws a box the size of the control, filled with the outer_color and | |
| 142 // with a border in the default edge color, and then draws another box | |
| 143 // indented on all four sides by the specified amounts, filled with the | |
| 144 // inner color and with a border in the default edge color. | |
| 145 void nested_boxes(int indent_left, int indent_top, | |
| 146 int indent_right, int indent_bottom, | |
| 147 SkColor outer_color, SkColor inner_color); | |
| 148 | |
| 149 // Draws a line between the two points in the given color. | |
| 150 void line(int x0, int y0, int x1, int y1, SkColor color); | |
| 151 | |
| 152 // Draws a distinctive mark on the control for each state, so that the | |
| 153 // state of the control can be determined without needing to know which | |
| 154 // color is which. | |
| 155 void markState(); | |
| 156 | |
| 157 SkCanvas* canvas_; | |
| 158 const SkIRect irect_; | |
| 159 const Type type_; | |
| 160 const State state_; | |
| 161 const SkColor edge_color_; | |
| 162 const SkColor bg_color_; | |
| 163 const SkColor fg_color_; | |
| 164 | |
| 165 // The following are convenience accessors for irect_. | |
| 166 const int left_; | |
| 167 const int right_; | |
| 168 const int top_; | |
| 169 const int bottom_; | |
| 170 const int width_; | |
| 171 const int height_; | |
| 172 | |
| 173 DISALLOW_COPY_AND_ASSIGN(Control); | |
| 174 }; | |
| 175 | |
| 176 } // namespace TestShellWebTheme | |
| 177 | |
| 178 #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBTHEMECONTROL_H_ | |
| OLD | NEW |