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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/image_view.cc ('k') | ui/views/view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_VIEW_H_ 5 #ifndef UI_VIEWS_VIEW_H_
6 #define UI_VIEWS_VIEW_H_ 6 #define UI_VIEWS_VIEW_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 gfx::Rect GetVisibleBounds() const; 266 gfx::Rect GetVisibleBounds() const;
267 267
268 // Return the bounds of the View in screen coordinate system. 268 // Return the bounds of the View in screen coordinate system.
269 gfx::Rect GetBoundsInScreen() const; 269 gfx::Rect GetBoundsInScreen() const;
270 270
271 // Returns the baseline of this view, or -1 if this view has no baseline. The 271 // Returns the baseline of this view, or -1 if this view has no baseline. The
272 // return value is relative to the preferred height. 272 // return value is relative to the preferred height.
273 virtual int GetBaseline() const; 273 virtual int GetBaseline() const;
274 274
275 // Get the size the View would like to be, if enough space were available. 275 // Get the size the View would like to be, if enough space were available.
276 // First checks |preferred_size_|, then |layout_manager_|, then
277 // CalculatePreferredSize().
278 // TODO(estade): migrate existing GetPreferredSize() overrides to
279 // CalculatePreferredSize() and make this function non-virtual.
276 virtual gfx::Size GetPreferredSize() const; 280 virtual gfx::Size GetPreferredSize() const;
277 281
282 // Sets the size that this View will request during layout. The actual size
283 // 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.
284 void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; }
285
278 // Convenience method that sizes this view to its preferred size. 286 // Convenience method that sizes this view to its preferred size.
279 void SizeToPreferredSize(); 287 void SizeToPreferredSize();
280 288
281 // Gets the minimum size of the view. View's implementation invokes 289 // Gets the minimum size of the view. View's implementation invokes
282 // GetPreferredSize. 290 // GetPreferredSize.
283 virtual gfx::Size GetMinimumSize() const; 291 virtual gfx::Size GetMinimumSize() const;
284 292
285 // Gets the maximum size of the view. Currently only used for sizing shell 293 // Gets the maximum size of the view. Currently only used for sizing shell
286 // windows. 294 // windows.
287 virtual gfx::Size GetMaximumSize() const; 295 virtual gfx::Size GetMaximumSize() const;
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 1056
1049 // Whether the press may generate a drag. 1057 // Whether the press may generate a drag.
1050 bool possible_drag; 1058 bool possible_drag;
1051 1059
1052 // Coordinates of the mouse press. 1060 // Coordinates of the mouse press.
1053 gfx::Point start_pt; 1061 gfx::Point start_pt;
1054 }; 1062 };
1055 1063
1056 // Size and disposition ------------------------------------------------------ 1064 // Size and disposition ------------------------------------------------------
1057 1065
1066 // Calculates the natural size for the View, to be taken into consideration
1067 // when the parent is performing layout.
1068 virtual gfx::Size CalculatePreferredSize() const;
1069
1058 // Override to be notified when the bounds of the view have changed. 1070 // Override to be notified when the bounds of the view have changed.
1059 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds); 1071 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds);
1060 1072
1061 // Called when the preferred size of a child view changed. This gives the 1073 // Called when the preferred size of a child view changed. This gives the
1062 // parent an opportunity to do a fresh layout if that makes sense. 1074 // parent an opportunity to do a fresh layout if that makes sense.
1063 virtual void ChildPreferredSizeChanged(View* child) {} 1075 virtual void ChildPreferredSizeChanged(View* child) {}
1064 1076
1065 // Called when the visibility of a child view changed. This gives the parent 1077 // Called when the visibility of a child view changed. This gives the parent
1066 // an opportunity to do a fresh layout if that makes sense. 1078 // an opportunity to do a fresh layout if that makes sense.
1067 virtual void ChildVisibilityChanged(View* child) {} 1079 virtual void ChildVisibilityChanged(View* child) {}
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 #if DCHECK_IS_ON() 1577 #if DCHECK_IS_ON()
1566 // True while iterating over |children_|. Used to detect and DCHECK when 1578 // True while iterating over |children_|. Used to detect and DCHECK when
1567 // |children_| is mutated during iteration. 1579 // |children_| is mutated during iteration.
1568 mutable bool iterating_; 1580 mutable bool iterating_;
1569 #endif 1581 #endif
1570 1582
1571 bool can_process_events_within_subtree_; 1583 bool can_process_events_within_subtree_;
1572 1584
1573 // Size and disposition ------------------------------------------------------ 1585 // Size and disposition ------------------------------------------------------
1574 1586
1587 base::Optional<gfx::Size> preferred_size_;
1588
1575 // This View's bounds in the parent coordinate system. 1589 // This View's bounds in the parent coordinate system.
1576 gfx::Rect bounds_; 1590 gfx::Rect bounds_;
1577 1591
1578 // Whether this view is visible. 1592 // Whether this view is visible.
1579 bool visible_; 1593 bool visible_;
1580 1594
1581 // Whether this view is enabled. 1595 // Whether this view is enabled.
1582 bool enabled_; 1596 bool enabled_;
1583 1597
1584 // When this flag is on, a View receives a mouse-enter and mouse-leave event 1598 // When this flag is on, a View receives a mouse-enter and mouse-leave event
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 // Observers ------------------------------------------------------------- 1707 // Observers -------------------------------------------------------------
1694 1708
1695 base::ObserverList<ViewObserver> observers_; 1709 base::ObserverList<ViewObserver> observers_;
1696 1710
1697 DISALLOW_COPY_AND_ASSIGN(View); 1711 DISALLOW_COPY_AND_ASSIGN(View);
1698 }; 1712 };
1699 1713
1700 } // namespace views 1714 } // namespace views
1701 1715
1702 #endif // UI_VIEWS_VIEW_H_ 1716 #endif // UI_VIEWS_VIEW_H_
OLDNEW
« 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