| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_ | 5 #ifndef VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_ |
| 6 #define VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_ | 6 #define VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "views/view.h" | 10 #include "views/view.h" |
| 11 | 11 |
| 12 namespace views { | 12 namespace views { |
| 13 | 13 |
| 14 class SingleSplitViewListener; |
| 15 |
| 14 // SingleSplitView lays out two views next to each other, either horizontally | 16 // SingleSplitView lays out two views next to each other, either horizontally |
| 15 // or vertically. A splitter exists between the two views that the user can | 17 // or vertically. A splitter exists between the two views that the user can |
| 16 // drag around to resize the views. | 18 // drag around to resize the views. |
| 17 // Observer's SplitHandleMoved notification helps to monitor user initiated | 19 // SingleSplitViewListener's SplitHandleMoved notification helps to monitor user |
| 18 // layout changes. | 20 // initiated layout changes. |
| 19 class VIEWS_EXPORT SingleSplitView : public View { | 21 class VIEWS_EXPORT SingleSplitView : public View { |
| 20 public: | 22 public: |
| 21 enum Orientation { | 23 enum Orientation { |
| 22 HORIZONTAL_SPLIT, | 24 HORIZONTAL_SPLIT, |
| 23 VERTICAL_SPLIT | 25 VERTICAL_SPLIT |
| 24 }; | 26 }; |
| 25 | 27 |
| 26 // Internal class name | |
| 27 static const char kViewClassName[]; | 28 static const char kViewClassName[]; |
| 28 | 29 |
| 29 class Observer { | |
| 30 public: | |
| 31 // Invoked when split handle is moved by the user. |source|'s divider_offset | |
| 32 // is already set to the new value, but Layout has not happened yet. | |
| 33 // Returns false if the layout has been handled by the observer, returns | |
| 34 // true if |source| should do it by itself. | |
| 35 virtual bool SplitHandleMoved(SingleSplitView* source) = 0; | |
| 36 protected: | |
| 37 virtual ~Observer() {} | |
| 38 }; | |
| 39 | |
| 40 SingleSplitView(View* leading, | 30 SingleSplitView(View* leading, |
| 41 View* trailing, | 31 View* trailing, |
| 42 Orientation orientation, | 32 Orientation orientation, |
| 43 Observer* observer); | 33 SingleSplitViewListener* listener); |
| 44 | 34 |
| 45 virtual void Layout() OVERRIDE; | 35 virtual void Layout() OVERRIDE; |
| 46 virtual std::string GetClassName() const OVERRIDE; | 36 virtual std::string GetClassName() const OVERRIDE; |
| 47 | 37 |
| 48 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 38 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 49 | 39 |
| 50 // SingleSplitView's preferred size is the sum of the preferred widths | 40 // SingleSplitView's preferred size is the sum of the preferred widths |
| 51 // and the max of the heights. | 41 // and the max of the heights. |
| 52 virtual gfx::Size GetPreferredSize() OVERRIDE; | 42 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 53 | 43 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 78 |
| 89 private: | 79 private: |
| 90 // This test calls OnMouse* functions. | 80 // This test calls OnMouse* functions. |
| 91 FRIEND_TEST_ALL_PREFIXES(SingleSplitViewTest, MouseDrag); | 81 FRIEND_TEST_ALL_PREFIXES(SingleSplitViewTest, MouseDrag); |
| 92 | 82 |
| 93 // Returns true if |x| or |y| is over the divider. | 83 // Returns true if |x| or |y| is over the divider. |
| 94 bool IsPointInDivider(const gfx::Point& p); | 84 bool IsPointInDivider(const gfx::Point& p); |
| 95 | 85 |
| 96 // Calculates the new |divider_offset| based on the changes of split view | 86 // Calculates the new |divider_offset| based on the changes of split view |
| 97 // bounds. | 87 // bounds. |
| 98 int CalculateDividerOffset( | 88 int CalculateDividerOffset(int divider_offset, |
| 99 int divider_offset, | 89 const gfx::Rect& previous_bounds, |
| 100 const gfx::Rect& previous_bounds, | 90 const gfx::Rect& new_bounds) const; |
| 101 const gfx::Rect& new_bounds) const; | |
| 102 | 91 |
| 103 // Returns divider offset within primary axis size range for given split | 92 // Returns divider offset within primary axis size range for given split |
| 104 // view |bounds|. | 93 // view |bounds|. |
| 105 int NormalizeDividerOffset(int divider_offset, const gfx::Rect& bounds) const; | 94 int NormalizeDividerOffset(int divider_offset, const gfx::Rect& bounds) const; |
| 106 | 95 |
| 107 // Returns width in case of horizontal split and height otherwise. | 96 // Returns width in case of horizontal split and height otherwise. |
| 108 int GetPrimaryAxisSize() const { | 97 int GetPrimaryAxisSize() const { |
| 109 return GetPrimaryAxisSize(width(), height()); | 98 return GetPrimaryAxisSize(width(), height()); |
| 110 } | 99 } |
| 111 | 100 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 124 DragInfo drag_info_; | 113 DragInfo drag_info_; |
| 125 | 114 |
| 126 // Orientation of the split view. | 115 // Orientation of the split view. |
| 127 bool is_horizontal_; | 116 bool is_horizontal_; |
| 128 | 117 |
| 129 // Position of the divider. | 118 // Position of the divider. |
| 130 int divider_offset_; | 119 int divider_offset_; |
| 131 | 120 |
| 132 bool resize_leading_on_bounds_change_; | 121 bool resize_leading_on_bounds_change_; |
| 133 | 122 |
| 134 // Observer to notify about user initiated handle movements. Not own by us. | 123 // Listener to notify about user initiated handle movements. Not owned. |
| 135 Observer* observer_; | 124 SingleSplitViewListener* listener_; |
| 136 | 125 |
| 137 // The accessible name of this view. | 126 // The accessible name of this view. |
| 138 string16 accessible_name_; | 127 string16 accessible_name_; |
| 139 | 128 |
| 140 DISALLOW_COPY_AND_ASSIGN(SingleSplitView); | 129 DISALLOW_COPY_AND_ASSIGN(SingleSplitView); |
| 141 }; | 130 }; |
| 142 | 131 |
| 143 } // namespace views | 132 } // namespace views |
| 144 | 133 |
| 145 #endif // VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_ | 134 #endif // VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_ |
| OLD | NEW |