| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ | 5 #ifndef VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ |
| 6 #define VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ | 6 #define VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ |
| 7 | 7 |
| 8 #include "gfx/font.h" | 8 #include "gfx/font.h" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
| 10 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 ALIGN_CENTER, | 98 ALIGN_CENTER, |
| 99 ALIGN_RIGHT | 99 ALIGN_RIGHT |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 void set_alignment(TextAlignment alignment) { alignment_ = alignment; } | 102 void set_alignment(TextAlignment alignment) { alignment_ = alignment; } |
| 103 | 103 |
| 104 void set_prefix_type(PrefixType type) { prefix_type_ = type; } | 104 void set_prefix_type(PrefixType type) { prefix_type_ = type; } |
| 105 | 105 |
| 106 // Sets the icon. | 106 // Sets the icon. |
| 107 void SetIcon(const SkBitmap& icon); | 107 void SetIcon(const SkBitmap& icon); |
| 108 SkBitmap icon() const { return icon_; } | |
| 109 void SetHoverIcon(const SkBitmap& icon); | 108 void SetHoverIcon(const SkBitmap& icon); |
| 110 SkBitmap icon_hover() const { return icon_hover_; } | 109 void SetPushedIcon(const SkBitmap& icon); |
| 110 |
| 111 bool HasIcon() const { return !icon_.empty(); } |
| 111 | 112 |
| 112 // Meanings are reversed for right-to-left layouts. | 113 // Meanings are reversed for right-to-left layouts. |
| 113 enum IconPlacement { | 114 enum IconPlacement { |
| 114 ICON_ON_LEFT, | 115 ICON_ON_LEFT, |
| 115 ICON_ON_RIGHT | 116 ICON_ON_RIGHT |
| 116 }; | 117 }; |
| 117 | 118 |
| 118 IconPlacement icon_placement() { return icon_placement_; } | 119 IconPlacement icon_placement() { return icon_placement_; } |
| 119 void set_icon_placement(IconPlacement icon_placement) { | 120 void set_icon_placement(IconPlacement icon_placement) { |
| 120 icon_placement_ = icon_placement; | 121 icon_placement_ = icon_placement; |
| 121 } | 122 } |
| 122 | 123 |
| 123 // TextButton remembers the maximum display size of the text passed to | 124 // TextButton remembers the maximum display size of the text passed to |
| 124 // SetText. This method resets the cached maximum display size to the | 125 // SetText. This method resets the cached maximum display size to the |
| 125 // current size. | 126 // current size. |
| 126 void ClearMaxTextSize(); | 127 void ClearMaxTextSize(); |
| 127 | 128 |
| 128 void set_max_width(int max_width) { max_width_ = max_width; } | 129 void set_max_width(int max_width) { max_width_ = max_width; } |
| 129 void SetFont(const gfx::Font& font); | 130 void SetFont(const gfx::Font& font); |
| 130 void SetEnabledColor(SkColor color); | 131 void SetEnabledColor(SkColor color); |
| 131 void SetDisabledColor(SkColor color); | 132 void SetDisabledColor(SkColor color); |
| 132 void SetHighlightColor(SkColor color); | 133 void SetHighlightColor(SkColor color); |
| 133 void SetHoverColor(SkColor color); | 134 void SetHoverColor(SkColor color); |
| 134 void SetNormalHasBorder(bool normal_has_border); | 135 void SetNormalHasBorder(bool normal_has_border); |
| 135 // Sets whether or not to show the highlighed (i.e. hot) state. Default true. | 136 // Sets whether or not to show the hot and pushed states for the button icon |
| 136 void SetShowHighlighted(bool show_highlighted); | 137 // (if present) in addition to the normal state. Defaults to true. |
| 138 void SetShowMultipleIconStates(bool show_multiple_icon_states); |
| 137 | 139 |
| 138 // Paint the button into the specified canvas. If |for_drag| is true, the | 140 // Paint the button into the specified canvas. If |for_drag| is true, the |
| 139 // function paints a drag image representation into the canvas. | 141 // function paints a drag image representation into the canvas. |
| 140 virtual void Paint(gfx::Canvas* canvas, bool for_drag); | 142 virtual void Paint(gfx::Canvas* canvas, bool for_drag); |
| 141 | 143 |
| 142 // Overridden from View: | 144 // Overridden from View: |
| 143 virtual gfx::Size GetPreferredSize(); | 145 virtual gfx::Size GetPreferredSize(); |
| 144 virtual gfx::Size GetMinimumSize(); | 146 virtual gfx::Size GetMinimumSize(); |
| 145 virtual void SetEnabled(bool enabled); | 147 virtual void SetEnabled(bool enabled); |
| 146 | 148 |
| 147 // Text colors. | 149 // Text colors. |
| 148 static const SkColor kEnabledColor; | 150 static const SkColor kEnabledColor; |
| 149 static const SkColor kHighlightColor; | 151 static const SkColor kHighlightColor; |
| 150 static const SkColor kDisabledColor; | 152 static const SkColor kDisabledColor; |
| 151 static const SkColor kHoverColor; | 153 static const SkColor kHoverColor; |
| 152 | 154 |
| 153 protected: | 155 protected: |
| 156 SkBitmap icon() const { return icon_; } |
| 157 |
| 154 virtual void Paint(gfx::Canvas* canvas); | 158 virtual void Paint(gfx::Canvas* canvas); |
| 155 | 159 |
| 156 // Called when enabled or disabled state changes, or the colors for those | 160 // Called when enabled or disabled state changes, or the colors for those |
| 157 // states change. | 161 // states change. |
| 158 virtual void UpdateColor(); | 162 virtual void UpdateColor(); |
| 159 | 163 |
| 160 private: | 164 private: |
| 161 // Updates text_size_ and max_text_size_ from the current text/font. This is | 165 // Updates text_size_ and max_text_size_ from the current text/font. This is |
| 162 // invoked when the font or text changes. | 166 // invoked when the font or text changes. |
| 163 void UpdateTextSize(); | 167 void UpdateTextSize(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 190 SkColor color_highlight_; | 194 SkColor color_highlight_; |
| 191 SkColor color_hover_; | 195 SkColor color_hover_; |
| 192 | 196 |
| 193 // An icon displayed with the text. | 197 // An icon displayed with the text. |
| 194 SkBitmap icon_; | 198 SkBitmap icon_; |
| 195 | 199 |
| 196 // An optional different version of the icon for hover state. | 200 // An optional different version of the icon for hover state. |
| 197 SkBitmap icon_hover_; | 201 SkBitmap icon_hover_; |
| 198 bool has_hover_icon_; | 202 bool has_hover_icon_; |
| 199 | 203 |
| 204 // An optional different version of the icon for pushed state. |
| 205 SkBitmap icon_pushed_; |
| 206 bool has_pushed_icon_; |
| 207 |
| 200 // The width of the button will never be larger than this value. A value <= 0 | 208 // The width of the button will never be larger than this value. A value <= 0 |
| 201 // indicates the width is not constrained. | 209 // indicates the width is not constrained. |
| 202 int max_width_; | 210 int max_width_; |
| 203 | 211 |
| 204 // This is true if normal state has a border frame; default is false. | 212 // This is true if normal state has a border frame; default is false. |
| 205 bool normal_has_border_; | 213 bool normal_has_border_; |
| 206 | 214 |
| 207 // Whether or not to show the highlighted (i.e. hot) state. | 215 // Whether or not to show the hot and pushed icon states. |
| 208 bool show_highlighted_; | 216 bool show_multiple_icon_states_; |
| 209 | 217 |
| 210 PrefixType prefix_type_; | 218 PrefixType prefix_type_; |
| 211 | 219 |
| 212 DISALLOW_COPY_AND_ASSIGN(TextButton); | 220 DISALLOW_COPY_AND_ASSIGN(TextButton); |
| 213 }; | 221 }; |
| 214 | 222 |
| 215 } // namespace views | 223 } // namespace views |
| 216 | 224 |
| 217 #endif // VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ | 225 #endif // VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ |
| OLD | NEW |