OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ | 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ |
6 #define UI_VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ | 6 #define UI_VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 void SetFocusPainter(scoped_ptr<Painter> focus_painter); | 155 void SetFocusPainter(scoped_ptr<Painter> focus_painter); |
156 Painter* focus_painter() { return focus_painter_.get(); } | 156 Painter* focus_painter() { return focus_painter_.get(); } |
157 | 157 |
158 // Paint the button into the specified canvas. If |mode| is |PB_FOR_DRAG|, the | 158 // Paint the button into the specified canvas. If |mode| is |PB_FOR_DRAG|, the |
159 // function paints a drag image representation into the canvas. | 159 // function paints a drag image representation into the canvas. |
160 enum PaintButtonMode { PB_NORMAL, PB_FOR_DRAG }; | 160 enum PaintButtonMode { PB_NORMAL, PB_FOR_DRAG }; |
161 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode); | 161 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode); |
162 | 162 |
163 // Overridden from View: | 163 // Overridden from View: |
164 virtual gfx::Size GetPreferredSize() OVERRIDE; | 164 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
165 virtual gfx::Size GetMinimumSize() OVERRIDE; | 165 virtual gfx::Size GetMinimumSize() const OVERRIDE; |
166 virtual int GetHeightForWidth(int w) OVERRIDE; | 166 virtual int GetHeightForWidth(int w) const OVERRIDE; |
167 virtual void OnEnabledChanged() OVERRIDE; | 167 virtual void OnEnabledChanged() OVERRIDE; |
168 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 168 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
169 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | 169 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |
170 virtual const char* GetClassName() const OVERRIDE; | 170 virtual const char* GetClassName() const OVERRIDE; |
171 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; | 171 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; |
172 | 172 |
173 protected: | 173 protected: |
174 TextButtonBase(ButtonListener* listener, const base::string16& text); | 174 TextButtonBase(ButtonListener* listener, const base::string16& text); |
175 | 175 |
176 // Called when enabled or disabled state changes, or the colors for those | 176 // Called when enabled or disabled state changes, or the colors for those |
177 // states change. | 177 // states change. |
178 virtual void UpdateColor(); | 178 virtual void UpdateColor(); |
179 | 179 |
180 // Updates text_size_ and max_text_size_ from the current text/font. This is | 180 // Updates text_size_ and max_text_size_ from the current text/font. This is |
181 // invoked when the font list or text changes. | 181 // invoked when the font list or text changes. |
182 void UpdateTextSize(); | 182 void UpdateTextSize(); |
183 | 183 |
184 // Calculate the size of the text size without setting any of the members. | 184 // Calculate the size of the text size without setting any of the members. |
185 void CalculateTextSize(gfx::Size* text_size, int max_width); | 185 void CalculateTextSize(gfx::Size* text_size, int max_width) const; |
186 | 186 |
187 // Paint the button's text into the specified canvas. If |mode| is | 187 // Paint the button's text into the specified canvas. If |mode| is |
188 // |PB_FOR_DRAG|, the function paints a drag image representation. Derived | 188 // |PB_FOR_DRAG|, the function paints a drag image representation. Derived |
189 // can override this function to change only the text rendering. | 189 // can override this function to change only the text rendering. |
190 virtual void OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode); | 190 virtual void OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode); |
191 | 191 |
192 void set_color_enabled(SkColor color) { color_enabled_ = color; } | 192 void set_color_enabled(SkColor color) { color_enabled_ = color; } |
193 void set_color_disabled(SkColor color) { color_disabled_ = color; } | 193 void set_color_disabled(SkColor color) { color_disabled_ = color; } |
194 void set_color_hover(SkColor color) { color_hover_ = color; } | 194 void set_color_hover(SkColor color) { color_hover_ = color; } |
195 | 195 |
(...skipping 30 matching lines...) Expand all Loading... |
226 int ComputeCanvasStringFlags() const; | 226 int ComputeCanvasStringFlags() const; |
227 | 227 |
228 // Calculate the bounds of the content of this button, including any extra | 228 // Calculate the bounds of the content of this button, including any extra |
229 // width needed on top of the text width. | 229 // width needed on top of the text width. |
230 gfx::Rect GetContentBounds(int extra_width) const; | 230 gfx::Rect GetContentBounds(int extra_width) const; |
231 | 231 |
232 // The text string that is displayed in the button. | 232 // The text string that is displayed in the button. |
233 base::string16 text_; | 233 base::string16 text_; |
234 | 234 |
235 // The size of the text string. | 235 // The size of the text string. |
236 gfx::Size text_size_; | 236 mutable gfx::Size text_size_; |
237 | 237 |
238 // Track the size of the largest text string seen so far, so that | 238 // Track the size of the largest text string seen so far, so that |
239 // changing text_ will not resize the button boundary. | 239 // changing text_ will not resize the button boundary. |
240 gfx::Size max_text_size_; | 240 gfx::Size max_text_size_; |
241 | 241 |
242 // The alignment of the text string within the button. | 242 // The alignment of the text string within the button. |
243 TextAlignment alignment_; | 243 TextAlignment alignment_; |
244 | 244 |
245 // The font list used to paint the text. | 245 // The font list used to paint the text. |
246 gfx::FontList font_list_; | 246 gfx::FontList font_list_; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 // ICON_CENTERED works only when |text_| is empty. | 319 // ICON_CENTERED works only when |text_| is empty. |
320 DCHECK((icon_placement != ICON_CENTERED) || text_.empty()); | 320 DCHECK((icon_placement != ICON_CENTERED) || text_.empty()); |
321 icon_placement_ = icon_placement; | 321 icon_placement_ = icon_placement; |
322 } | 322 } |
323 | 323 |
324 void set_ignore_minimum_size(bool ignore_minimum_size); | 324 void set_ignore_minimum_size(bool ignore_minimum_size); |
325 | 325 |
326 void set_full_justification(bool full_justification); | 326 void set_full_justification(bool full_justification); |
327 | 327 |
328 // Overridden from View: | 328 // Overridden from View: |
329 virtual gfx::Size GetPreferredSize() OVERRIDE; | 329 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
330 virtual const char* GetClassName() const OVERRIDE; | 330 virtual const char* GetClassName() const OVERRIDE; |
331 | 331 |
332 // Overridden from TextButtonBase: | 332 // Overridden from TextButtonBase: |
333 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE; | 333 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE; |
334 | 334 |
335 protected: | 335 protected: |
336 // Paint the button's icon into the specified canvas. If |mode| is | 336 // Paint the button's icon into the specified canvas. If |mode| is |
337 // |PB_FOR_DRAG|, the function paints a drag image representation. Derived | 337 // |PB_FOR_DRAG|, the function paints a drag image representation. Derived |
338 // can override this function to change only the icon rendering. | 338 // can override this function to change only the icon rendering. |
339 virtual void OnPaintIcon(gfx::Canvas* canvas, PaintButtonMode mode); | 339 virtual void OnPaintIcon(gfx::Canvas* canvas, PaintButtonMode mode); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 // True if the icon and the text are aligned along both the left and right | 375 // True if the icon and the text are aligned along both the left and right |
376 // margins of the button. | 376 // margins of the button. |
377 bool full_justification_; | 377 bool full_justification_; |
378 | 378 |
379 DISALLOW_COPY_AND_ASSIGN(TextButton); | 379 DISALLOW_COPY_AND_ASSIGN(TextButton); |
380 }; | 380 }; |
381 | 381 |
382 } // namespace views | 382 } // namespace views |
383 | 383 |
384 #endif // UI_VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ | 384 #endif // UI_VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ |
OLD | NEW |