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_; |