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

Unified Diff: ui/views/view.h

Issue 2881183003: Add views::View::set_preferred_size, use it in a few places. (Closed)
Patch Set: auto* 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..9f1ca8b509665fda2a4b73d00ff2ffc2fc247acb 100644
--- a/ui/views/view.h
+++ b/ui/views/view.h
@@ -273,8 +273,17 @@ 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. It should rarely be necessary to set this; usually the right
+ // approach is controlling the parent's layout via a LayoutManager.
+ 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 +1064,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 +1585,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