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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/controls/button/label_button.cc » ('j') | ui/views/controls/button/label_button.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/button/label_button.h
diff --git a/ui/views/controls/button/label_button.h b/ui/views/controls/button/label_button.h
index 4c569ff0f5b6346d61dd51bad499727400fe39d8..4c99d749788c9091ea7e5522f62679f33344f767 100644
--- a/ui/views/controls/button/label_button.h
+++ b/ui/views/controls/button/label_button.h
@@ -69,8 +69,14 @@ class VIEWS_EXPORT LabelButton : public CustomButton,
void SetDirectionalityMode(gfx::DirectionalityMode mode);
// Call set_min_size(gfx::Size()) to clear the monotonically increasing size.
- void set_min_size(const gfx::Size& min_size) { min_size_ = min_size; }
- void set_max_size(const gfx::Size& max_size) { max_size_ = max_size; }
+ void set_min_size(const gfx::Size& min_size) {
+ min_size_ = min_size;
+ ResetCachedSize();
+ }
+ void set_max_size(const gfx::Size& max_size) {
+ max_size_ = max_size;
+ ResetCachedSize();
+ }
// Get or set the option to handle the return key; false by default.
bool is_default() const { return is_default_; }
@@ -146,6 +152,9 @@ class VIEWS_EXPORT LabelButton : public CustomButton,
virtual ui::NativeTheme::State GetForegroundThemeState(
ui::NativeTheme::ExtraParams* params) const OVERRIDE;
+ // Resets |button_size_| and marks |button_size_valid_| as false.
+ void ResetCachedSize();
+
// The image and label shown in the button.
ImageView* image_;
Label* label_;
@@ -166,6 +175,10 @@ class VIEWS_EXPORT LabelButton : public CustomButton,
// |max_size_| may be set to clamp the preferred size.
gfx::Size max_size_;
+ // Cache the last computed preferred size.
+ mutable gfx::Size button_size_;
+ mutable bool button_size_valid_;
+
// Flag indicating default handling of the return key via an accelerator.
// Whether or not the button appears or behaves as the default button in its
// current context;
« 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