Chromium Code Reviews| 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 #ifndef UI_GFX_NATIVE_THEME_ANDROID_H_ | |
| 6 #define UI_GFX_NATIVE_THEME_ANDROID_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "skia/ext/platform_canvas.h" | |
| 10 | |
| 11 namespace gfx { | |
| 12 class Rect; | |
| 13 class Size; | |
| 14 | |
| 15 // Android theming API. | |
| 16 class NativeThemeAndroid { | |
| 17 public: | |
| 18 // The part to be painted / sized. | |
| 19 enum Part { | |
| 20 SCROLLBAR_DOWN_ARROW, | |
| 21 SCROLLBAR_LEFT_ARROW, | |
| 22 SCROLLBAR_RIGHT_ARROW, | |
| 23 SCROLLBAR_UP_ARROW, | |
| 24 CHECKBOX, | |
| 25 RADIO, | |
| 26 PUSH_BUTTON, | |
| 27 TEXTFIELD, | |
| 28 MENU_LIST, | |
| 29 SLIDER_TRACK, | |
| 30 SLIDER_TNUMB, | |
| 31 INNER_SPIN_BUTTON, | |
| 32 PROGRESS_BAR, | |
| 33 }; | |
| 34 | |
| 35 // The state of the part. | |
| 36 enum State { | |
| 37 kDisabled, | |
|
sky
2011/11/11 00:14:16
This should be ALL_CAPS too.
michaelbai
2011/11/11 00:33:28
Done.
| |
| 38 kHovered, | |
| 39 kNormal, | |
| 40 kPressed, | |
| 41 }; | |
| 42 | |
| 43 struct ButtonExtraParams { | |
| 44 bool checked; | |
| 45 bool indeterminate; // Whether the button state is indeterminate. | |
| 46 bool is_default; // Whether the button is default button. | |
| 47 bool has_border; | |
| 48 SkColor background_color; | |
| 49 }; | |
| 50 | |
| 51 struct TextFieldExtraParams { | |
| 52 bool is_text_area; | |
| 53 bool is_listbox; | |
| 54 SkColor background_color; | |
| 55 }; | |
| 56 | |
| 57 struct MenuListExtraParams { | |
| 58 bool has_border; | |
| 59 bool has_border_radius; | |
| 60 int arrow_x; | |
| 61 int arrow_y; | |
| 62 SkColor background_color; | |
| 63 }; | |
| 64 | |
| 65 struct SliderExtraParams { | |
| 66 bool vertical; | |
| 67 bool in_drag; | |
| 68 }; | |
| 69 | |
| 70 struct InnerSpinButtonExtraParams { | |
| 71 bool spin_up; | |
| 72 bool read_only; | |
| 73 }; | |
| 74 | |
| 75 struct ProgressBarExtraParams { | |
| 76 bool determinate; | |
| 77 int value_rect_x; | |
| 78 int value_rect_y; | |
| 79 int value_rect_width; | |
| 80 int value_rect_height; | |
| 81 }; | |
| 82 | |
| 83 union ExtraParams { | |
| 84 ButtonExtraParams button; | |
| 85 MenuListExtraParams menu_list; | |
| 86 SliderExtraParams slider; | |
| 87 TextFieldExtraParams text_field; | |
| 88 InnerSpinButtonExtraParams inner_spin; | |
| 89 ProgressBarExtraParams progress_bar; | |
| 90 }; | |
| 91 | |
| 92 // Gets our singleton instance. | |
| 93 static NativeThemeAndroid* instance(); | |
| 94 | |
| 95 // Return the size of the part. | |
| 96 gfx::Size GetPartSize(Part part) const; | |
| 97 | |
| 98 // Paint the part to the canvas. | |
| 99 void Paint(SkCanvas* canvas, | |
| 100 Part part, | |
| 101 State state, | |
| 102 const gfx::Rect& rect, | |
| 103 const ExtraParams& extra); | |
| 104 | |
| 105 protected: | |
| 106 NativeThemeAndroid(); | |
| 107 virtual ~NativeThemeAndroid(); | |
| 108 | |
| 109 // Draw the arrow. Used by scrollbar and inner spin button. | |
| 110 virtual void PaintArrowButton(SkCanvas* gc, | |
|
sky
2011/11/11 00:14:16
Same comment on virtual as earlier. If it's not ne
michaelbai
2011/11/11 00:33:28
Done.
| |
| 111 const gfx::Rect& rect, | |
| 112 Part direction, | |
| 113 State state); | |
| 114 | |
| 115 // Draw the checkbox. | |
| 116 virtual void PaintCheckbox(SkCanvas* canvas, | |
| 117 State state, | |
| 118 const gfx::Rect& rect, | |
| 119 const ButtonExtraParams& button); | |
| 120 | |
| 121 // Draw the radio. | |
| 122 virtual void PaintRadio(SkCanvas* canvas, | |
| 123 State state, | |
| 124 const gfx::Rect& rect, | |
| 125 const ButtonExtraParams& button); | |
| 126 | |
| 127 // Draw the push button. | |
| 128 virtual void PaintButton(SkCanvas* canvas, | |
| 129 State state, | |
| 130 const gfx::Rect& rect, | |
| 131 const ButtonExtraParams& button); | |
| 132 | |
| 133 // Draw the text field. | |
| 134 virtual void PaintTextField(SkCanvas* canvas, | |
| 135 State state, | |
| 136 const gfx::Rect& rect, | |
| 137 const TextFieldExtraParams& text); | |
| 138 | |
| 139 // Draw the menu list. | |
| 140 virtual void PaintMenuList(SkCanvas* canvas, | |
| 141 State state, | |
| 142 const gfx::Rect& rect, | |
| 143 const MenuListExtraParams& menu_list); | |
| 144 | |
| 145 // Draw the slider track. | |
| 146 virtual void PaintSliderTrack(SkCanvas* canvas, | |
| 147 State state, | |
| 148 const gfx::Rect& rect, | |
| 149 const SliderExtraParams& slider); | |
| 150 | |
| 151 // Draw the slider thumb. | |
| 152 virtual void PaintSliderThumb(SkCanvas* canvas, | |
| 153 State state, | |
| 154 const gfx::Rect& rect, | |
| 155 const SliderExtraParams& slider); | |
| 156 | |
| 157 // Draw the inner spin button. | |
| 158 virtual void PaintInnerSpinButton( | |
| 159 SkCanvas* canvas, | |
| 160 State state, | |
| 161 const gfx::Rect& rect, | |
| 162 const InnerSpinButtonExtraParams& spin_button); | |
| 163 | |
| 164 // Draw the progress bar. | |
| 165 virtual void PaintProgressBar( | |
| 166 SkCanvas* canvas, | |
| 167 State state, | |
| 168 const gfx::Rect& rect, | |
| 169 const ProgressBarExtraParams& progress_bar); | |
| 170 | |
| 171 private: | |
| 172 // Return true if there is intersection between the |canvas| and the given | |
| 173 // rectangle. | |
| 174 bool IntersectsClipRectInt(SkCanvas* canvas, | |
| 175 int x, | |
| 176 int y, | |
| 177 int w, | |
| 178 int h); | |
| 179 | |
| 180 // Draw the dest rectangle with the given bitmap which might be scaled if its | |
| 181 // size is not same as target rectangle. | |
| 182 void DrawBitmapInt(SkCanvas* canvas, | |
| 183 const SkBitmap& bitmap, | |
| 184 int src_x, | |
| 185 int src_y, | |
| 186 int src_w, | |
| 187 int src_h, | |
| 188 int dest_x, | |
| 189 int dest_y, | |
| 190 int dest_w, | |
| 191 int dest_h); | |
| 192 | |
| 193 // Draw the target rectangle with the |bitmap| accroding the given | |
| 194 // |tile_scale_x| and |tile_scale_y| | |
| 195 void DrawTiledImage(SkCanvas* canvas, | |
| 196 const SkBitmap& bitmap, | |
| 197 int src_x, | |
| 198 int src_y, | |
| 199 double tile_scale_x, | |
| 200 double tile_scale_y, | |
| 201 int dest_x, | |
| 202 int dest_y, | |
| 203 int w, | |
| 204 int h) const; | |
| 205 | |
| 206 // Return a new color which comes from the |hsv| by adjusting saturate and | |
| 207 // brighten according |saturate_amount| and |brighten_amount| | |
| 208 SkColor SaturateAndBrighten(SkScalar* hsv, | |
| 209 SkScalar saturate_amount, | |
| 210 SkScalar brighten_amount) const; | |
| 211 | |
| 212 void DrawVertLine(SkCanvas* canvas, | |
| 213 int x, | |
| 214 int y1, | |
| 215 int y2, | |
| 216 const SkPaint& paint) const; | |
| 217 | |
| 218 void DrawHorizLine(SkCanvas* canvas, | |
| 219 int x1, | |
| 220 int x2, | |
| 221 int y, | |
| 222 const SkPaint& paint) const; | |
| 223 | |
| 224 void DrawBox(SkCanvas* canvas, | |
| 225 const gfx::Rect& rect, | |
| 226 const SkPaint& paint) const; | |
| 227 | |
| 228 // Return the |value| if it is between |min| and |max|, otherwise the |min| | |
| 229 // or |max| is returned dependent on which is mostly near the |value|. | |
| 230 SkScalar Clamp(SkScalar value, SkScalar min, SkScalar max) const; | |
| 231 | |
| 232 // Used to return the color of scrollbar based on the color of thumb and | |
| 233 // track. | |
| 234 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; | |
| 235 | |
| 236 static unsigned int scrollbar_width_; | |
|
sky
2011/11/11 00:14:16
Is there a reason these aren't const too? It doesn
michaelbai
2011/11/11 00:33:28
Done.
| |
| 237 static unsigned int button_length_; | |
| 238 static unsigned int thumb_inactive_color_; | |
| 239 static unsigned int thumb_active_color_; | |
| 240 static unsigned int track_color_; | |
| 241 | |
| 242 DISALLOW_COPY_AND_ASSIGN(NativeThemeAndroid); | |
| 243 }; | |
| 244 | |
| 245 } // namespace gfx | |
| 246 | |
| 247 #endif // UI_GFX_NATIVE_THEME_ANDROID_H_ | |
| OLD | NEW |