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