OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/view.h" | 9 #include "views/view.h" |
10 | 10 |
11 namespace views { | 11 namespace views { |
12 | 12 |
13 // SingleSplitView lays out two views horizontally. A splitter exists between | 13 // SingleSplitView lays out two views next to each other, either horizontally |
14 // the two views that the user can drag around to resize the views. | 14 // or vertically. A splitter exists between the two views that the user can |
15 // drag around to resize the views. It does not change these views bounds | |
16 // though, the actual resize is a resonsibility of the entity resizing | |
17 // the SingleSplitView itself. Observer's SplitHandleMoved notification helps | |
18 // to handle user initiated layout changes. | |
sky
2011/01/06 17:55:02
The Observer should be optional, a NULL observer m
Aleksey Shlyapnikov
2011/01/07 19:07:23
Done.
| |
15 class SingleSplitView : public views::View { | 19 class SingleSplitView : public views::View { |
16 public: | 20 public: |
17 enum Orientation { | 21 enum Orientation { |
18 HORIZONTAL_SPLIT, | 22 HORIZONTAL_SPLIT, |
19 VERTICAL_SPLIT | 23 VERTICAL_SPLIT |
20 }; | 24 }; |
21 | 25 |
22 SingleSplitView(View* leading, View* trailing, Orientation orientation); | 26 class Observer { |
27 public: | |
28 // Invoked when split handle is moved by the user. | |
sky
2011/01/06 17:55:02
This should return a boolean indicating if Layout
Aleksey Shlyapnikov
2011/01/07 19:07:23
In the updated version SingleSplitView does layout
| |
29 virtual void SplitHandleMoved(SingleSplitView* source) = 0; | |
30 protected: | |
31 virtual ~Observer() {} | |
32 }; | |
33 | |
34 SingleSplitView(View* leading, View* trailing, Orientation orientation, | |
35 Observer* observer); | |
23 | 36 |
24 virtual void DidChangeBounds(const gfx::Rect& previous, | 37 virtual void DidChangeBounds(const gfx::Rect& previous, |
25 const gfx::Rect& current); | 38 const gfx::Rect& current); |
26 | 39 |
27 virtual void Layout(); | 40 virtual void Layout(); |
28 | 41 |
29 virtual AccessibilityTypes::Role GetAccessibleRole(); | 42 virtual AccessibilityTypes::Role GetAccessibleRole(); |
30 | 43 |
31 // SingleSplitView's preferred size is the sum of the preferred widths | 44 // SingleSplitView's preferred size is the sum of the preferred widths |
32 // and the max of the heights. | 45 // and the max of the heights. |
33 virtual gfx::Size GetPreferredSize(); | 46 virtual gfx::Size GetPreferredSize(); |
34 | 47 |
35 // Overriden to return a resize cursor when over the divider. | 48 // Overriden to return a resize cursor when over the divider. |
36 virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type, | 49 virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type, |
37 const gfx::Point& p); | 50 const gfx::Point& p); |
38 | 51 |
39 void set_divider_offset(int divider_offset) { | 52 void set_divider_offset(int divider_offset) { |
40 divider_offset_ = divider_offset; | 53 divider_offset_ = divider_offset; |
41 } | 54 } |
42 int divider_offset() { return divider_offset_; } | 55 int divider_offset() { return divider_offset_; } |
43 | 56 |
44 // Sets whether the leading component is resized when the split views size | 57 // Sets whether the leading component is resized when the split views size |
45 // changes. The default is true. A value of false results in the trailing | 58 // changes. The default is true. A value of false results in the trailing |
46 // component resizing on a bounds change. | 59 // component resizing on a bounds change. |
47 void set_resize_leading_on_bounds_change(bool resize) { | 60 void set_resize_leading_on_bounds_change(bool resize) { |
48 resize_leading_on_bounds_change_ = resize; | 61 resize_leading_on_bounds_change_ = resize; |
49 } | 62 } |
50 | 63 |
64 const gfx::Rect& leading_view_rect() const { return leading_view_rect_; } | |
65 const gfx::Rect& trailing_view_rect() const { return trailing_view_rect_; } | |
66 | |
67 // Resizes leading and trailing views to the current leading_view_rect_ and | |
68 // trailing_view_rect_ bounds, accordingly. | |
69 void ResizeViews(); | |
70 | |
51 protected: | 71 protected: |
52 virtual bool OnMousePressed(const MouseEvent& event); | 72 virtual bool OnMousePressed(const MouseEvent& event); |
53 virtual bool OnMouseDragged(const MouseEvent& event); | 73 virtual bool OnMouseDragged(const MouseEvent& event); |
54 virtual void OnMouseReleased(const MouseEvent& event, bool canceled); | 74 virtual void OnMouseReleased(const MouseEvent& event, bool canceled); |
55 | 75 |
56 private: | 76 private: |
57 // Returns true if |x| or |y| is over the divider. | 77 // Returns true if |x| or |y| is over the divider. |
58 bool IsPointInDivider(const gfx::Point& p); | 78 bool IsPointInDivider(const gfx::Point& p); |
59 | 79 |
60 // Returns width in case of horizontal split and height otherwise. | 80 // Returns width in case of horizontal split and height otherwise. |
(...skipping 16 matching lines...) Expand all Loading... | |
77 DragInfo drag_info_; | 97 DragInfo drag_info_; |
78 | 98 |
79 // Orientation of the split view. | 99 // Orientation of the split view. |
80 bool is_horizontal_; | 100 bool is_horizontal_; |
81 | 101 |
82 // Position of the divider. | 102 // Position of the divider. |
83 int divider_offset_; | 103 int divider_offset_; |
84 | 104 |
85 bool resize_leading_on_bounds_change_; | 105 bool resize_leading_on_bounds_change_; |
86 | 106 |
107 // Observer to notify about user initiated handle movements. Not own by us. | |
108 Observer* observer_; | |
109 // Leading and trailing views bounds calcualted based on the current | |
sky
2011/01/06 17:55:02
Newline between 108 and 109.
sky
2011/01/06 17:55:02
calcualted - > calculated
Aleksey Shlyapnikov
2011/01/07 19:07:23
Done.
Aleksey Shlyapnikov
2011/01/07 19:07:23
Done.
| |
110 // |divider_offset_|. Not necessarily equal to the actual views bounds, | |
111 // ResizeViews() brings them in sync. | |
112 gfx::Rect leading_view_rect_; | |
113 gfx::Rect trailing_view_rect_; | |
114 | |
87 DISALLOW_COPY_AND_ASSIGN(SingleSplitView); | 115 DISALLOW_COPY_AND_ASSIGN(SingleSplitView); |
88 }; | 116 }; |
89 | 117 |
90 } // namespace views | 118 } // namespace views |
91 | 119 |
92 #endif // VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_ | 120 #endif // VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_ |
OLD | NEW |