Index: ui/views/layout/box_layout.h |
diff --git a/ui/views/layout/box_layout.h b/ui/views/layout/box_layout.h |
index 9a87984d51f77cec0caa488860fa6dc1986f9e28..62672d02532e9b4e4700f70f1c1a66778845c07b 100644 |
--- a/ui/views/layout/box_layout.h |
+++ b/ui/views/layout/box_layout.h |
@@ -105,6 +105,31 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager { |
int GetPreferredHeightForWidth(const View* host, int width) const override; |
private: |
+ // This struct is used internally to "wrap" a child view in order to obviate |
+ // the need for the main layout logic to be aware of the per-view margins. |
+ // Since each view is a rectangle of a certain size, this wrapper, coupled |
+ // with any margins set will increase the apparent size of the view. All |
+ // necessary view size/position methods required for the layout logic add or |
+ // subtract the margins where appropriate to ensure the actual visible size |
+ // of the view doesn't include the margins. |
+ struct ViewWrapper { |
+ ViewWrapper(); |
+ ViewWrapper(View* view); |
+ ViewWrapper(const ViewWrapper& wrapper) = delete; |
+ ~ViewWrapper(); |
+ int GetHeightForWidth(int width) const; |
+ gfx::Size GetPreferredSize() const; |
+ void SetBoundsRect(const gfx::Rect& bounds); |
+ View* view() const { return view_; } |
+ bool visible() const; |
+ |
+ private: |
+ View* view_; |
+ gfx::Insets margins_; |
+ }; |
+ |
+ using FlexMap = std::map<const View*, int>; |
+ |
// Returns the flex for the specified |view|. |
int GetFlexForView(const View* view) const; |
@@ -126,10 +151,10 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager { |
// Returns the main axis size for the given view. |child_area_width| is needed |
// to calculate the height of the view when the orientation is vertical. |
- int MainAxisSizeForView(const View* view, int child_area_width) const; |
+ int MainAxisSizeForView(const ViewWrapper& view, int child_area_width) const; |
// Returns the cross axis size for the given view. |
- int CrossAxisSizeForView(const View* view) const; |
+ int CrossAxisSizeForView(const ViewWrapper& view) const; |
// The preferred size for the dialog given the width of the child area. |
gfx::Size GetPreferredSizeForChildWidth(const View* host, |
@@ -156,7 +181,7 @@ class VIEWS_EXPORT BoxLayout : public LayoutManager { |
CrossAxisAlignment cross_axis_alignment_; |
// A map of views to their flex weights. |
- std::map<const View*, int> flex_map_; |
+ FlexMap flex_map_; |
// The flex weight for views if none is set. Defaults to 0. |
int default_flex_; |