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

Side by Side Diff: ui/views/controls/button/label_button.h

Issue 371633002: LabelButton: cache the last computed preferred size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix whitespace Created 6 years, 5 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
OLDNEW
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_LABEL_BUTTON_H_ 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_
6 #define UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ 6 #define UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "third_party/skia/include/core/SkColor.h" 10 #include "third_party/skia/include/core/SkColor.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 // Get or set the horizontal alignment used for the button; reversed in RTL. 63 // Get or set the horizontal alignment used for the button; reversed in RTL.
64 // The optional image will lead the text, unless the button is right-aligned. 64 // The optional image will lead the text, unless the button is right-aligned.
65 gfx::HorizontalAlignment GetHorizontalAlignment() const; 65 gfx::HorizontalAlignment GetHorizontalAlignment() const;
66 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); 66 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment);
67 67
68 // Set the directionality mode used for the button text. 68 // Set the directionality mode used for the button text.
69 void SetDirectionalityMode(gfx::DirectionalityMode mode); 69 void SetDirectionalityMode(gfx::DirectionalityMode mode);
70 70
71 // Call set_min_size(gfx::Size()) to clear the monotonically increasing size. 71 // Call set_min_size(gfx::Size()) to clear the monotonically increasing size.
72 void set_min_size(const gfx::Size& min_size) { min_size_ = min_size; } 72 void set_min_size(const gfx::Size& min_size) {
73 void set_max_size(const gfx::Size& max_size) { max_size_ = max_size; } 73 min_size_ = min_size;
74 ResetCachedSize();
75 }
76 void set_max_size(const gfx::Size& max_size) {
77 max_size_ = max_size;
78 ResetCachedSize();
79 }
74 80
75 // Get or set the option to handle the return key; false by default. 81 // Get or set the option to handle the return key; false by default.
76 bool is_default() const { return is_default_; } 82 bool is_default() const { return is_default_; }
77 void SetIsDefault(bool is_default); 83 void SetIsDefault(bool is_default);
78 84
79 // Get or set the button's overall style; the default is |STYLE_TEXTBUTTON|. 85 // Get or set the button's overall style; the default is |STYLE_TEXTBUTTON|.
80 ButtonStyle style() const { return style_; } 86 ButtonStyle style() const { return style_; }
81 void SetStyle(ButtonStyle style); 87 void SetStyle(ButtonStyle style);
82 88
83 void SetFocusPainter(scoped_ptr<Painter> focus_painter); 89 void SetFocusPainter(scoped_ptr<Painter> focus_painter);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // NativeThemeDelegate: 145 // NativeThemeDelegate:
140 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; 146 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE;
141 virtual ui::NativeTheme::State GetThemeState( 147 virtual ui::NativeTheme::State GetThemeState(
142 ui::NativeTheme::ExtraParams* params) const OVERRIDE; 148 ui::NativeTheme::ExtraParams* params) const OVERRIDE;
143 virtual const gfx::Animation* GetThemeAnimation() const OVERRIDE; 149 virtual const gfx::Animation* GetThemeAnimation() const OVERRIDE;
144 virtual ui::NativeTheme::State GetBackgroundThemeState( 150 virtual ui::NativeTheme::State GetBackgroundThemeState(
145 ui::NativeTheme::ExtraParams* params) const OVERRIDE; 151 ui::NativeTheme::ExtraParams* params) const OVERRIDE;
146 virtual ui::NativeTheme::State GetForegroundThemeState( 152 virtual ui::NativeTheme::State GetForegroundThemeState(
147 ui::NativeTheme::ExtraParams* params) const OVERRIDE; 153 ui::NativeTheme::ExtraParams* params) const OVERRIDE;
148 154
155 // Resets |button_size_| and marks |button_size_valid_| as false.
156 void ResetCachedSize();
157
149 // The image and label shown in the button. 158 // The image and label shown in the button.
150 ImageView* image_; 159 ImageView* image_;
151 Label* label_; 160 Label* label_;
152 161
153 // The cached font lists in the normal and bold style. 162 // The cached font lists in the normal and bold style.
154 gfx::FontList cached_normal_font_list_; 163 gfx::FontList cached_normal_font_list_;
155 gfx::FontList cached_bold_font_list_; 164 gfx::FontList cached_bold_font_list_;
156 165
157 // The images and colors for each button state. 166 // The images and colors for each button state.
158 gfx::ImageSkia button_state_images_[STATE_COUNT]; 167 gfx::ImageSkia button_state_images_[STATE_COUNT];
159 SkColor button_state_colors_[STATE_COUNT]; 168 SkColor button_state_colors_[STATE_COUNT];
160 169
161 // Used to track whether SetTextColor() has been invoked. 170 // Used to track whether SetTextColor() has been invoked.
162 bool explicitly_set_colors_[STATE_COUNT]; 171 bool explicitly_set_colors_[STATE_COUNT];
163 172
164 // |min_size_| increases monotonically with the preferred size. 173 // |min_size_| increases monotonically with the preferred size.
165 mutable gfx::Size min_size_; 174 mutable gfx::Size min_size_;
166 // |max_size_| may be set to clamp the preferred size. 175 // |max_size_| may be set to clamp the preferred size.
167 gfx::Size max_size_; 176 gfx::Size max_size_;
168 177
178 // Cache the last computed preferred size.
179 mutable gfx::Size button_size_;
180 mutable bool button_size_valid_;
181
169 // Flag indicating default handling of the return key via an accelerator. 182 // Flag indicating default handling of the return key via an accelerator.
170 // Whether or not the button appears or behaves as the default button in its 183 // Whether or not the button appears or behaves as the default button in its
171 // current context; 184 // current context;
172 bool is_default_; 185 bool is_default_;
173 186
174 // The button's overall style. 187 // The button's overall style.
175 ButtonStyle style_; 188 ButtonStyle style_;
176 189
177 // True if current border was set by UpdateThemedBorder. Defaults to true. 190 // True if current border was set by UpdateThemedBorder. Defaults to true.
178 bool border_is_themed_border_; 191 bool border_is_themed_border_;
179 192
180 scoped_ptr<Painter> focus_painter_; 193 scoped_ptr<Painter> focus_painter_;
181 194
182 DISALLOW_COPY_AND_ASSIGN(LabelButton); 195 DISALLOW_COPY_AND_ASSIGN(LabelButton);
183 }; 196 };
184 197
185 } // namespace views 198 } // namespace views
186 199
187 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ 200 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/button/label_button.cc » ('j') | ui/views/controls/button/label_button.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698