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

Side by Side Diff: views/controls/single_split_view.h

Issue 8687031: views: Move the remaining files to ui/views/controls/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « views/controls/separator.cc ('k') | views/controls/single_split_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_
6 #define VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_
7 #pragma once
8
9 #include "base/gtest_prod_util.h"
10 #include "views/view.h"
11
12 namespace views {
13
14 class SingleSplitViewListener;
15
16 // SingleSplitView lays out two views next to each other, either horizontally
17 // or vertically. A splitter exists between the two views that the user can
18 // drag around to resize the views.
19 // SingleSplitViewListener's SplitHandleMoved notification helps to monitor user
20 // initiated layout changes.
21 class VIEWS_EXPORT SingleSplitView : public View {
22 public:
23 enum Orientation {
24 HORIZONTAL_SPLIT,
25 VERTICAL_SPLIT
26 };
27
28 static const char kViewClassName[];
29
30 SingleSplitView(View* leading,
31 View* trailing,
32 Orientation orientation,
33 SingleSplitViewListener* listener);
34
35 virtual void Layout() OVERRIDE;
36 virtual std::string GetClassName() const OVERRIDE;
37
38 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
39
40 // SingleSplitView's preferred size is the sum of the preferred widths
41 // and the max of the heights.
42 virtual gfx::Size GetPreferredSize() OVERRIDE;
43
44 // Overriden to return a resize cursor when over the divider.
45 virtual gfx::NativeCursor GetCursor(const MouseEvent& event) OVERRIDE;
46
47 Orientation orientation() const {
48 return is_horizontal_ ? HORIZONTAL_SPLIT : VERTICAL_SPLIT;
49 }
50
51 void set_divider_offset(int divider_offset) {
52 divider_offset_ = divider_offset;
53 }
54 int divider_offset() const { return divider_offset_; }
55
56 // Sets whether the leading component is resized when the split views size
57 // changes. The default is true. A value of false results in the trailing
58 // component resizing on a bounds change.
59 void set_resize_leading_on_bounds_change(bool resize) {
60 resize_leading_on_bounds_change_ = resize;
61 }
62
63 // Calculates ideal leading and trailing view bounds according to the given
64 // split view |bounds|, current divider offset and children visiblity.
65 // Does not change children view bounds.
66 void CalculateChildrenBounds(const gfx::Rect& bounds,
67 gfx::Rect* leading_bounds,
68 gfx::Rect* trailing_bounds) const;
69
70 void SetAccessibleName(const string16& name);
71
72 protected:
73 // View overrides.
74 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
75 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
76 virtual void OnMouseCaptureLost() OVERRIDE;
77 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
78
79 private:
80 // This test calls OnMouse* functions.
81 FRIEND_TEST_ALL_PREFIXES(SingleSplitViewTest, MouseDrag);
82
83 // Returns true if |x| or |y| is over the divider.
84 bool IsPointInDivider(const gfx::Point& p);
85
86 // Calculates the new |divider_offset| based on the changes of split view
87 // bounds.
88 int CalculateDividerOffset(int divider_offset,
89 const gfx::Rect& previous_bounds,
90 const gfx::Rect& new_bounds) const;
91
92 // Returns divider offset within primary axis size range for given split
93 // view |bounds|.
94 int NormalizeDividerOffset(int divider_offset, const gfx::Rect& bounds) const;
95
96 // Returns width in case of horizontal split and height otherwise.
97 int GetPrimaryAxisSize() const {
98 return GetPrimaryAxisSize(width(), height());
99 }
100
101 int GetPrimaryAxisSize(int h, int v) const {
102 return is_horizontal_ ? h : v;
103 }
104
105 // Used to track drag info.
106 struct DragInfo {
107 // The initial coordinate of the mouse when the user started the drag.
108 int initial_mouse_offset;
109 // The initial position of the divider when the user started the drag.
110 int initial_divider_offset;
111 };
112
113 DragInfo drag_info_;
114
115 // Orientation of the split view.
116 bool is_horizontal_;
117
118 // Position of the divider.
119 int divider_offset_;
120
121 bool resize_leading_on_bounds_change_;
122
123 // Listener to notify about user initiated handle movements. Not owned.
124 SingleSplitViewListener* listener_;
125
126 // The accessible name of this view.
127 string16 accessible_name_;
128
129 DISALLOW_COPY_AND_ASSIGN(SingleSplitView);
130 };
131
132 } // namespace views
133
134 #endif // VIEWS_CONTROLS_SINGLE_SPLIT_VIEW_H_
OLDNEW
« no previous file with comments | « views/controls/separator.cc ('k') | views/controls/single_split_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698