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

Unified Diff: ui/views/view.h

Issue 2881183003: Add views::View::set_preferred_size, use it in a few places. (Closed)
Patch Set: Created 3 years, 7 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 | « ui/views/controls/image_view.cc ('k') | ui/views/view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view.h
diff --git a/ui/views/view.h b/ui/views/view.h
index d1f69707fda4a74ca022439077464b8205df2fb0..117c1ab5dd03c4adcc897204d9cfa38062b0c68e 100644
--- a/ui/views/view.h
+++ b/ui/views/view.h
@@ -273,8 +273,16 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
virtual int GetBaseline() const;
// Get the size the View would like to be, if enough space were available.
+ // First checks |preferred_size_|, then |layout_manager_|, then
+ // CalculatePreferredSize().
+ // TODO(estade): migrate existing GetPreferredSize() overrides to
+ // CalculatePreferredSize() and make this function non-virtual.
virtual gfx::Size GetPreferredSize() const;
+ // Sets the size that this View will request during layout. The actual size
+ // may differ.
sky 2017/05/15 21:56:16 Please also add a comment that in very rare cases
Evan Stade 2017/05/15 22:04:04 Done.
+ void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; }
+
// Convenience method that sizes this view to its preferred size.
void SizeToPreferredSize();
@@ -1055,6 +1063,10 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// Size and disposition ------------------------------------------------------
+ // Calculates the natural size for the View, to be taken into consideration
+ // when the parent is performing layout.
+ virtual gfx::Size CalculatePreferredSize() const;
+
// Override to be notified when the bounds of the view have changed.
virtual void OnBoundsChanged(const gfx::Rect& previous_bounds);
@@ -1572,6 +1584,8 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// Size and disposition ------------------------------------------------------
+ base::Optional<gfx::Size> preferred_size_;
+
// This View's bounds in the parent coordinate system.
gfx::Rect bounds_;
« no previous file with comments | « ui/views/controls/image_view.cc ('k') | ui/views/view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698