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