| OLD | NEW |
| 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_LAYOUT_BOX_LAYOUT_H_ | 5 #ifndef UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ |
| 6 #define UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ | 6 #define UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "ui/gfx/insets.h" | 10 #include "ui/gfx/insets.h" |
| 11 #include "ui/views/layout/layout_manager.h" | 11 #include "ui/views/layout/layout_manager.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 class Rect; |
| 14 class Size; | 15 class Size; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace views { | 18 namespace views { |
| 18 | 19 |
| 19 class View; | 20 class View; |
| 20 | 21 |
| 21 // A Layout manager that arranges child views vertically or horizontally in a | 22 // A Layout manager that arranges child views vertically or horizontally in a |
| 22 // side-by-side fashion with spacing around and between the child views. The | 23 // side-by-side fashion with spacing around and between the child views. The |
| 23 // child views are always sized according to their preferred size. If the | 24 // child views are always sized according to their preferred size. If the |
| 24 // host's bounds provide insufficient space, child views will be clamped. | 25 // host's bounds provide insufficient space, child views will be clamped. |
| 25 // Excess space will not be distributed. | 26 // Excess space will not be distributed. |
| 26 class VIEWS_EXPORT BoxLayout : public LayoutManager { | 27 class VIEWS_EXPORT BoxLayout : public LayoutManager { |
| 27 public: | 28 public: |
| 28 enum Orientation { | 29 enum Orientation { |
| 29 kHorizontal, | 30 kHorizontal, |
| 30 kVertical, | 31 kVertical, |
| 31 }; | 32 }; |
| 32 | 33 |
| 34 // This specifies where along the main axis the children should be laid out. |
| 35 // e.g. a horizontal layout of MAIN_AXIS_ALIGNMENT_END will result in the |
| 36 // child views being right-aligned. |
| 37 enum MainAxisAlignment { |
| 38 MAIN_AXIS_ALIGNMENT_START, |
| 39 MAIN_AXIS_ALIGNMENT_CENTER, |
| 40 MAIN_AXIS_ALIGNMENT_END, |
| 41 |
| 42 // This distributes extra space among the child views. This increases the |
| 43 // size of child views along the main axis rather than the space between |
| 44 // them. |
| 45 MAIN_AXIS_ALIGNMENT_FILL, |
| 46 // TODO(calamity): Add MAIN_AXIS_ALIGNMENT_JUSTIFY which spreads blank space |
| 47 // in-between the child views. |
| 48 }; |
| 49 |
| 50 // TODO(calamity): Add CrossAxisAlignment property to allow cross axis |
| 51 // alignment. |
| 52 |
| 33 // Use |inside_border_horizontal_spacing| and | 53 // Use |inside_border_horizontal_spacing| and |
| 34 // |inside_border_vertical_spacing| to add additional space between the child | 54 // |inside_border_vertical_spacing| to add additional space between the child |
| 35 // view area and the host view border. |between_child_spacing| controls the | 55 // view area and the host view border. |between_child_spacing| controls the |
| 36 // space in between child views. | 56 // space in between child views. |
| 37 BoxLayout(Orientation orientation, | 57 BoxLayout(Orientation orientation, |
| 38 int inside_border_horizontal_spacing, | 58 int inside_border_horizontal_spacing, |
| 39 int inside_border_vertical_spacing, | 59 int inside_border_vertical_spacing, |
| 40 int between_child_spacing); | 60 int between_child_spacing); |
| 41 virtual ~BoxLayout(); | 61 virtual ~BoxLayout(); |
| 42 | 62 |
| 43 void set_spread_blank_space(bool spread) { | 63 void set_main_axis_alignment(MainAxisAlignment main_axis_alignment) { |
| 44 spread_blank_space_ = spread; | 64 main_axis_alignment_ = main_axis_alignment; |
| 45 } | 65 } |
| 46 | 66 |
| 47 // Overridden from views::LayoutManager: | 67 // Overridden from views::LayoutManager: |
| 48 virtual void Layout(View* host) OVERRIDE; | 68 virtual void Layout(View* host) OVERRIDE; |
| 49 virtual gfx::Size GetPreferredSize(View* host) OVERRIDE; | 69 virtual gfx::Size GetPreferredSize(View* host) OVERRIDE; |
| 50 virtual int GetPreferredHeightForWidth(View* host, int width) OVERRIDE; | 70 virtual int GetPreferredHeightForWidth(View* host, int width) OVERRIDE; |
| 51 | 71 |
| 52 private: | 72 private: |
| 73 // Returns the size and position along the main axis of |child_area|. |
| 74 int MainAxisSize(const gfx::Rect& child_area) const; |
| 75 int MainAxisPosition(const gfx::Rect& child_area) const; |
| 76 |
| 77 // Sets the size and position along the main axis of |child_area|. |
| 78 void SetMainAxisSize(int size, gfx::Rect* child_area) const; |
| 79 void SetMainAxisPosition(int position, gfx::Rect* child_area) const; |
| 80 |
| 53 // The preferred size for the dialog given the width of the child area. | 81 // The preferred size for the dialog given the width of the child area. |
| 54 gfx::Size GetPreferredSizeForChildWidth(View* host, int child_area_width); | 82 gfx::Size GetPreferredSizeForChildWidth(View* host, int child_area_width); |
| 55 | 83 |
| 56 // The amount of space the layout requires in addition to any space for the | 84 // The amount of space the layout requires in addition to any space for the |
| 57 // child views. | 85 // child views. |
| 58 gfx::Size NonChildSize(View* host); | 86 gfx::Size NonChildSize(View* host); |
| 59 | 87 |
| 60 const Orientation orientation_; | 88 const Orientation orientation_; |
| 61 | 89 |
| 62 // Spacing between child views and host view border. | 90 // Spacing between child views and host view border. |
| 63 gfx::Insets inside_border_insets_; | 91 gfx::Insets inside_border_insets_; |
| 64 | 92 |
| 65 // Spacing to put in between child views. | 93 // Spacing to put in between child views. |
| 66 const int between_child_spacing_; | 94 const int between_child_spacing_; |
| 67 | 95 |
| 68 // Whether the available extra space should be distributed among the child | 96 // The alignment of children in the main axis. This is |
| 69 // views. | 97 // MAIN_AXIS_ALIGNMENT_START by default. |
| 70 bool spread_blank_space_; | 98 MainAxisAlignment main_axis_alignment_; |
| 71 | 99 |
| 72 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); | 100 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); |
| 73 }; | 101 }; |
| 74 | 102 |
| 75 } // namespace views | 103 } // namespace views |
| 76 | 104 |
| 77 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ | 105 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ |
| OLD | NEW |