Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: views/controls/button/text_button.h

Issue 2833013: Tweaks for the merged menu: (Closed)
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « views/accelerator.h ('k') | views/controls/button/text_button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 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"
11 #include "views/border.h" 11 #include "views/border.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // 64 //
65 // TextButton 65 // TextButton
66 // 66 //
67 // A button which displays text and/or and icon that can be changed in 67 // A button which displays text and/or and icon that can be changed in
68 // response to actions. TextButton reserves space for the largest string 68 // response to actions. TextButton reserves space for the largest string
69 // passed to SetText. To reset the cached max size invoke ClearMaxTextSize. 69 // passed to SetText. To reset the cached max size invoke ClearMaxTextSize.
70 // 70 //
71 //////////////////////////////////////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////////////////
72 class TextButton : public CustomButton { 72 class TextButton : public CustomButton {
73 public: 73 public:
74 // Enumeration of how the prefix ('&') character is processed. The default
75 // is |PREFIX_NONE|.
76 enum PrefixType {
77 // No special processing is done.
78 PREFIX_NONE,
79
80 // The character following the prefix character is not rendered specially.
81 PREFIX_HIDE,
82
83 // The character following the prefix character is underlined.
84 PREFIX_SHOW
85 };
86
74 TextButton(ButtonListener* listener, const std::wstring& text); 87 TextButton(ButtonListener* listener, const std::wstring& text);
75 virtual ~TextButton(); 88 virtual ~TextButton();
76 89
77 // Call SetText once per string in your set of possible values at button 90 // Call SetText once per string in your set of possible values at button
78 // creation time, so that it can contain the largest of them and avoid 91 // creation time, so that it can contain the largest of them and avoid
79 // resizing the button when the text changes. 92 // resizing the button when the text changes.
80 virtual void SetText(const std::wstring& text); 93 virtual void SetText(const std::wstring& text);
81 std::wstring text() const { return text_; } 94 std::wstring text() const { return text_; }
82 95
83 enum TextAlignment { 96 enum TextAlignment {
84 ALIGN_LEFT, 97 ALIGN_LEFT,
85 ALIGN_CENTER, 98 ALIGN_CENTER,
86 ALIGN_RIGHT 99 ALIGN_RIGHT
87 }; 100 };
88 101
89 void set_alignment(TextAlignment alignment) { alignment_ = alignment; } 102 void set_alignment(TextAlignment alignment) { alignment_ = alignment; }
90 103
104 void set_prefix_type(PrefixType type) { prefix_type_ = type; }
105
91 // Sets the icon. 106 // Sets the icon.
92 void SetIcon(const SkBitmap& icon); 107 void SetIcon(const SkBitmap& icon);
93 SkBitmap icon() const { return icon_; } 108 SkBitmap icon() const { return icon_; }
94 void SetHoverIcon(const SkBitmap& icon); 109 void SetHoverIcon(const SkBitmap& icon);
95 SkBitmap icon_hover() const { return icon_hover_; } 110 SkBitmap icon_hover() const { return icon_hover_; }
96 111
97 // Meanings are reversed for right-to-left layouts. 112 // Meanings are reversed for right-to-left layouts.
98 enum IconPlacement { 113 enum IconPlacement {
99 ICON_ON_LEFT, 114 ICON_ON_LEFT,
100 ICON_ON_RIGHT 115 ICON_ON_RIGHT
(...skipping 28 matching lines...) Expand all
129 virtual gfx::Size GetMinimumSize(); 144 virtual gfx::Size GetMinimumSize();
130 virtual void SetEnabled(bool enabled); 145 virtual void SetEnabled(bool enabled);
131 146
132 // Text colors. 147 // Text colors.
133 static const SkColor kEnabledColor; 148 static const SkColor kEnabledColor;
134 static const SkColor kHighlightColor; 149 static const SkColor kHighlightColor;
135 static const SkColor kDisabledColor; 150 static const SkColor kDisabledColor;
136 static const SkColor kHoverColor; 151 static const SkColor kHoverColor;
137 152
138 protected: 153 protected:
139 virtual bool OnMousePressed(const MouseEvent& e);
140 virtual void Paint(gfx::Canvas* canvas); 154 virtual void Paint(gfx::Canvas* canvas);
141 155
142 // Called when enabled or disabled state changes, or the colors for those 156 // Called when enabled or disabled state changes, or the colors for those
143 // states change. 157 // states change.
144 virtual void UpdateColor(); 158 virtual void UpdateColor();
145 159
146 private: 160 private:
161 // Updates text_size_ and max_text_size_ from the current text/font. This is
162 // invoked when the font or text changes.
163 void UpdateTextSize();
164
147 // The text string that is displayed in the button. 165 // The text string that is displayed in the button.
148 std::wstring text_; 166 std::wstring text_;
149 167
150 // The size of the text string. 168 // The size of the text string.
151 gfx::Size text_size_; 169 gfx::Size text_size_;
152 170
153 // Track the size of the largest text string seen so far, so that 171 // Track the size of the largest text string seen so far, so that
154 // changing text_ will not resize the button boundary. 172 // changing text_ will not resize the button boundary.
155 gfx::Size max_text_size_; 173 gfx::Size max_text_size_;
156 174
(...skipping 25 matching lines...) Expand all
182 // The width of the button will never be larger than this value. A value <= 0 200 // The width of the button will never be larger than this value. A value <= 0
183 // indicates the width is not constrained. 201 // indicates the width is not constrained.
184 int max_width_; 202 int max_width_;
185 203
186 // This is true if normal state has a border frame; default is false. 204 // This is true if normal state has a border frame; default is false.
187 bool normal_has_border_; 205 bool normal_has_border_;
188 206
189 // Whether or not to show the highlighted (i.e. hot) state. 207 // Whether or not to show the highlighted (i.e. hot) state.
190 bool show_highlighted_; 208 bool show_highlighted_;
191 209
210 PrefixType prefix_type_;
211
192 DISALLOW_COPY_AND_ASSIGN(TextButton); 212 DISALLOW_COPY_AND_ASSIGN(TextButton);
193 }; 213 };
194 214
195 } // namespace views 215 } // namespace views
196 216
197 #endif // VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_ 217 #endif // VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_
OLDNEW
« no previous file with comments | « views/accelerator.h ('k') | views/controls/button/text_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698