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_H_ 6 #define UI_NATIVE_THEME_NATIVE_THEME_H_ 7 8 #include "third_party/skia/include/core/SkColor.h" 9 #include "ui/gfx/native_widget_types.h" 10 #include "ui/native_theme/native_theme_export.h" 11 12 class SkCanvas; 13 14 namespace gfx { 15 class Rect; 16 class Size; 17 } 18 19 namespace ui { 20 21 // This class supports drawing UI controls (like buttons, text fields, lists, 22 // comboboxes, etc) that look like the native UI controls of the underlying 23 // platform, such as Windows or Linux. It also supplies default colors for 24 // dialog box backgrounds, etc., which are obtained from the system theme where 25 // possible. 26 // 27 // The supported control types are listed in the Part enum. These parts can be 28 // in any state given by the State enum, where the actual definition of the 29 // state is part-specific. The supported colors are listed in the ColorId enum. 30 // 31 // Some parts require more information than simply the state in order to be 32 // drawn correctly, and this information is given to the Paint() method via the 33 // ExtraParams union. Each part that requires more information has its own 34 // field in the union. 35 // 36 // NativeTheme also supports getting the default size of a given part with 37 // the GetPartSize() method. 38 class NATIVE_THEME_EXPORT NativeTheme { 39 public: 40 // The part to be painted / sized. 41 enum Part { 42 kCheckbox, 43 kInnerSpinButton, 44 kMenuList, 45 kMenuCheck, 46 kMenuCheckBackground, 47 kMenuPopupArrow, 48 kMenuPopupBackground, 49 kMenuPopupGutter, 50 kMenuPopupSeparator, 51 kMenuItemBackground, 52 kProgressBar, 53 kPushButton, 54 kRadio, 55 56 // The order of the arrow enums is important, do not change without also 57 // changing the code in platform implementations. 58 kScrollbarDownArrow, 59 kScrollbarLeftArrow, 60 kScrollbarRightArrow, 61 kScrollbarUpArrow, 62 63 kScrollbarHorizontalThumb, 64 kScrollbarVerticalThumb, 65 kScrollbarHorizontalTrack, 66 kScrollbarVerticalTrack, 67 kScrollbarHorizontalGripper, 68 kScrollbarVerticalGripper, 69 kSliderTrack, 70 kSliderThumb, 71 kTabPanelBackground, 72 kTextField, 73 kTrackbarThumb, 74 kTrackbarTrack, 75 kWindowResizeGripper, 76 kMaxPart, 77 }; 78 79 // The state of the part. 80 enum State { 81 kDisabled, 82 kHovered, 83 kNormal, 84 kPressed, 85 kMaxState, 86 }; 87 88 // Each structure below holds extra information needed when painting a given 89 // part. 90 91 struct ButtonExtraParams { 92 bool checked; 93 bool indeterminate; // Whether the button state is indeterminate. 94 bool is_default; // Whether the button is default button. 95 bool is_focused; 96 bool has_border; 97 int classic_state; // Used on Windows when uxtheme is not available. 98 SkColor background_color; 99 }; 100 101 struct InnerSpinButtonExtraParams { 102 bool spin_up; 103 bool read_only; 104 int classic_state; // Used on Windows when uxtheme is not available. 105 }; 106 107 struct MenuArrowExtraParams { 108 bool pointing_right; 109 // Used for the disabled state to indicate if the item is both disabled and 110 // selected. 111 bool is_selected; 112 }; 113 114 struct MenuCheckExtraParams { 115 bool is_radio; 116 // Used for the disabled state to indicate if the item is both disabled and 117 // selected. 118 bool is_selected; 119 }; 120 121 struct MenuItemExtraParams { 122 bool is_selected; 123 }; 124 125 struct MenuListExtraParams { 126 bool has_border; 127 bool has_border_radius; 128 int arrow_x; 129 int arrow_y; 130 SkColor background_color; 131 int classic_state; // Used on Windows when uxtheme is not available. 132 }; 133 134 struct MenuSeparatorExtraParams { 135 bool has_gutter; 136 }; 137 138 struct MenuBackgroundExtraParams { 139 int corner_radius; 140 }; 141 142 struct ProgressBarExtraParams { 143 double animated_seconds; 144 bool determinate; 145 int value_rect_x; 146 int value_rect_y; 147 int value_rect_width; 148 int value_rect_height; 149 }; 150 151 struct ScrollbarArrowExtraParams { 152 bool is_hovering; 153 }; 154 155 struct ScrollbarTrackExtraParams { 156 bool is_upper; 157 int track_x; 158 int track_y; 159 int track_width; 160 int track_height; 161 int classic_state; // Used on Windows when uxtheme is not available. 162 }; 163 164 struct ScrollbarThumbExtraParams { 165 bool is_hovering; 166 }; 167 168 struct SliderExtraParams { 169 bool vertical; 170 bool in_drag; 171 }; 172 173 struct TextFieldExtraParams { 174 bool is_text_area; 175 bool is_listbox; 176 SkColor background_color; 177 bool is_read_only; 178 bool is_focused; 179 bool fill_content_area; 180 bool draw_edges; 181 int classic_state; // Used on Windows when uxtheme is not available. 182 }; 183 184 struct TrackbarExtraParams { 185 bool vertical; 186 int classic_state; // Used on Windows when uxtheme is not available. 187 }; 188 189 union ExtraParams { 190 ButtonExtraParams button; 191 InnerSpinButtonExtraParams inner_spin; 192 MenuArrowExtraParams menu_arrow; 193 MenuCheckExtraParams menu_check; 194 MenuItemExtraParams menu_item; 195 MenuListExtraParams menu_list; 196 MenuSeparatorExtraParams menu_separator; 197 MenuBackgroundExtraParams menu_background; 198 ProgressBarExtraParams progress_bar; 199 ScrollbarArrowExtraParams scrollbar_arrow; 200 ScrollbarTrackExtraParams scrollbar_track; 201 ScrollbarThumbExtraParams scrollbar_thumb; 202 SliderExtraParams slider; 203 TextFieldExtraParams text_field; 204 TrackbarExtraParams trackbar; 205 }; 206 207 // Return the size of the part. 208 virtual gfx::Size GetPartSize(Part part, 209 State state, 210 const ExtraParams& extra) const = 0; 211 212 // Paint the part to the canvas. 213 virtual void Paint(SkCanvas* canvas, 214 Part part, 215 State state, 216 const gfx::Rect& rect, 217 const ExtraParams& extra) const = 0; 218 219 // Supports theme specific colors. 220 void SetScrollbarColors(unsigned inactive_color, 221 unsigned active_color, 222 unsigned track_color); 223 224 // Colors for GetSystemColor(). 225 enum ColorId { 226 // Windows 227 kColorId_WindowBackground, 228 // Dialogs 229 kColorId_DialogBackground, 230 // FocusableBorder 231 kColorId_FocusedBorderColor, 232 kColorId_UnfocusedBorderColor, 233 // Button 234 kColorId_ButtonBackgroundColor, 235 kColorId_ButtonEnabledColor, 236 kColorId_ButtonDisabledColor, 237 kColorId_ButtonHighlightColor, 238 kColorId_ButtonHoverColor, 239 // MenuItem 240 kColorId_EnabledMenuItemForegroundColor, 241 kColorId_DisabledMenuItemForegroundColor, 242 kColorId_SelectedMenuItemForegroundColor, 243 kColorId_FocusedMenuItemBackgroundColor, 244 kColorId_HoverMenuItemBackgroundColor, 245 kColorId_MenuSeparatorColor, 246 kColorId_MenuBackgroundColor, 247 kColorId_MenuBorderColor, 248 // MenuButton - buttons in wrench menu 249 kColorId_EnabledMenuButtonBorderColor, 250 kColorId_FocusedMenuButtonBorderColor, 251 kColorId_HoverMenuButtonBorderColor, 252 // Label 253 kColorId_LabelEnabledColor, 254 kColorId_LabelDisabledColor, 255 kColorId_LabelBackgroundColor, 256 // Textfield 257 kColorId_TextfieldDefaultColor, 258 kColorId_TextfieldDefaultBackground, 259 kColorId_TextfieldReadOnlyColor, 260 kColorId_TextfieldReadOnlyBackground, 261 kColorId_TextfieldSelectionColor, 262 kColorId_TextfieldSelectionBackgroundFocused, 263 // Tree 264 kColorId_TreeBackground, 265 kColorId_TreeText, 266 kColorId_TreeSelectedText, 267 kColorId_TreeSelectedTextUnfocused, 268 kColorId_TreeSelectionBackgroundFocused, 269 kColorId_TreeSelectionBackgroundUnfocused, 270 kColorId_TreeArrow, 271 // Table 272 kColorId_TableBackground, 273 kColorId_TableText, 274 kColorId_TableSelectedText, 275 kColorId_TableSelectedTextUnfocused, 276 kColorId_TableSelectionBackgroundFocused, 277 kColorId_TableSelectionBackgroundUnfocused, 278 kColorId_TableGroupingIndicatorColor, 279 // TODO(benrg): move other hardcoded colors here. 280 }; 281 282 // Return a color from the system theme. 283 virtual SkColor GetSystemColor(ColorId color_id) const = 0; 284 285 // Returns a shared instance of the native theme. 286 // The returned object should not be deleted by the caller. This function 287 // is not thread safe and should only be called from the UI thread. 288 // Each port of NativeTheme should provide its own implementation of this 289 // function, returning the port's subclass. 290 static NativeTheme* instance(); 291 292 protected: 293 NativeTheme(); 294 virtual ~NativeTheme(); 295 296 unsigned int thumb_inactive_color_; 297 unsigned int thumb_active_color_; 298 unsigned int track_color_; 299 300 DISALLOW_COPY_AND_ASSIGN(NativeTheme); 301 }; 302 303 } // namespace ui 304 305 #endif // UI_NATIVE_THEME_NATIVE_THEME_H_ 306