| 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 void set_color_enabled(SkColor color) { color_enabled_ = color; } | 187 void set_color_enabled(SkColor color) { color_enabled_ = color; } |
| 188 void set_color_disabled(SkColor color) { color_disabled_ = color; } | 188 void set_color_disabled(SkColor color) { color_disabled_ = color; } |
| 189 void set_color_hover(SkColor color) { color_hover_ = color; } | 189 void set_color_hover(SkColor color) { color_hover_ = color; } |
| 190 | 190 |
| 191 bool use_enabled_color_from_theme() const { | 191 bool use_enabled_color_from_theme() const { |
| 192 return use_enabled_color_from_theme_; | 192 return use_enabled_color_from_theme_; |
| 193 } | 193 } |
| 194 | 194 |
| 195 bool use_disabled_color_from_theme() const { | 195 bool use_disabled_color_from_theme() const { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 221 int ComputeCanvasStringFlags() const; | 221 int ComputeCanvasStringFlags() const; |
| 222 | 222 |
| 223 // Calculate the bounds of the content of this button, including any extra | 223 // Calculate the bounds of the content of this button, including any extra |
| 224 // width needed on top of the text width. | 224 // width needed on top of the text width. |
| 225 gfx::Rect GetContentBounds(int extra_width) const; | 225 gfx::Rect GetContentBounds(int extra_width) const; |
| 226 | 226 |
| 227 // The text string that is displayed in the button. | 227 // The text string that is displayed in the button. |
| 228 base::string16 text_; | 228 base::string16 text_; |
| 229 | 229 |
| 230 // The size of the text string. | 230 // The size of the text string. |
| 231 gfx::Size text_size_; | 231 mutable gfx::Size text_size_; |
| 232 | 232 |
| 233 // Track the size of the largest text string seen so far, so that | 233 // Track the size of the largest text string seen so far, so that |
| 234 // changing text_ will not resize the button boundary. | 234 // changing text_ will not resize the button boundary. |
| 235 gfx::Size max_text_size_; | 235 gfx::Size max_text_size_; |
| 236 | 236 |
| 237 // The alignment of the text string within the button. | 237 // The alignment of the text string within the button. |
| 238 TextAlignment alignment_; | 238 TextAlignment alignment_; |
| 239 | 239 |
| 240 // The font list used to paint the text. | 240 // The font list used to paint the text. |
| 241 gfx::FontList font_list_; | 241 gfx::FontList font_list_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // ICON_CENTERED works only when |text_| is empty. | 314 // ICON_CENTERED works only when |text_| is empty. |
| 315 DCHECK((icon_placement != ICON_CENTERED) || text_.empty()); | 315 DCHECK((icon_placement != ICON_CENTERED) || text_.empty()); |
| 316 icon_placement_ = icon_placement; | 316 icon_placement_ = icon_placement; |
| 317 } | 317 } |
| 318 | 318 |
| 319 void set_ignore_minimum_size(bool ignore_minimum_size); | 319 void set_ignore_minimum_size(bool ignore_minimum_size); |
| 320 | 320 |
| 321 void set_full_justification(bool full_justification); | 321 void set_full_justification(bool full_justification); |
| 322 | 322 |
| 323 // Overridden from View: | 323 // Overridden from View: |
| 324 virtual gfx::Size GetPreferredSize() OVERRIDE; | 324 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
| 325 virtual const char* GetClassName() const OVERRIDE; | 325 virtual const char* GetClassName() const OVERRIDE; |
| 326 | 326 |
| 327 // Overridden from TextButtonBase: | 327 // Overridden from TextButtonBase: |
| 328 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE; | 328 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE; |
| 329 | 329 |
| 330 protected: | 330 protected: |
| 331 gfx::ImageSkia icon() const { return icon_; } | 331 gfx::ImageSkia icon() const { return icon_; } |
| 332 | 332 |
| 333 virtual const gfx::ImageSkia& GetImageToPaint() const; | 333 virtual const gfx::ImageSkia& GetImageToPaint() const; |
| 334 | 334 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 365 // True if the icon and the text are aligned along both the left and right | 365 // True if the icon and the text are aligned along both the left and right |
| 366 // margins of the button. | 366 // margins of the button. |
| 367 bool full_justification_; | 367 bool full_justification_; |
| 368 | 368 |
| 369 DISALLOW_COPY_AND_ASSIGN(TextButton); | 369 DISALLOW_COPY_AND_ASSIGN(TextButton); |
| 370 }; | 370 }; |
| 371 | 371 |
| 372 } // namespace views | 372 } // namespace views |
| 373 | 373 |
| 374 #endif // UI_VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ | 374 #endif // UI_VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ |
| OLD | NEW |