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 #include "ui/views/controls/single_split_view.h" | 5 #include "ui/views/controls/single_split_view.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "ui/accessibility/ax_view_state.h" | 8 #include "ui/accessibility/ax_view_state.h" |
9 #include "ui/base/cursor/cursor.h" | 9 #include "ui/base/cursor/cursor.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
11 #include "ui/views/background.h" | 11 #include "ui/views/background.h" |
12 #include "ui/views/border.h" | |
12 #include "ui/views/controls/single_split_view_listener.h" | 13 #include "ui/views/controls/single_split_view_listener.h" |
13 #include "ui/views/native_cursor.h" | 14 #include "ui/views/native_cursor.h" |
14 | 15 |
15 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
16 #include "skia/ext/skia_utils_win.h" | 17 #include "skia/ext/skia_utils_win.h" |
17 #endif | 18 #endif |
18 | 19 |
19 namespace views { | 20 namespace views { |
20 | 21 |
21 // static | 22 // static |
(...skipping 16 matching lines...) Expand all Loading... | |
38 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
39 set_background( | 40 set_background( |
40 views::Background::CreateSolidBackground( | 41 views::Background::CreateSolidBackground( |
41 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); | 42 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); |
42 #endif | 43 #endif |
43 } | 44 } |
44 | 45 |
45 void SingleSplitView::Layout() { | 46 void SingleSplitView::Layout() { |
46 gfx::Rect leading_bounds; | 47 gfx::Rect leading_bounds; |
47 gfx::Rect trailing_bounds; | 48 gfx::Rect trailing_bounds; |
48 CalculateChildrenBounds(bounds(), &leading_bounds, &trailing_bounds); | 49 CalculateChildrenBounds(GetContentsBounds(), &leading_bounds, |
50 &trailing_bounds); | |
49 | 51 |
50 if (has_children()) { | 52 if (has_children()) { |
51 if (child_at(0)->visible()) | 53 if (child_at(0)->visible()) |
52 child_at(0)->SetBoundsRect(leading_bounds); | 54 child_at(0)->SetBoundsRect(leading_bounds); |
53 if (child_count() > 1) { | 55 if (child_count() > 1) { |
54 if (child_at(1)->visible()) | 56 if (child_at(1)->visible()) |
55 child_at(1)->SetBoundsRect(trailing_bounds); | 57 child_at(1)->SetBoundsRect(trailing_bounds); |
56 } | 58 } |
57 } | 59 } |
58 | 60 |
(...skipping 21 matching lines...) Expand all Loading... | |
80 height = std::max(height, pref.height()); | 82 height = std::max(height, pref.height()); |
81 } else { | 83 } else { |
82 width = std::max(width, pref.width()); | 84 width = std::max(width, pref.width()); |
83 height += pref.height(); | 85 height += pref.height(); |
84 } | 86 } |
85 } | 87 } |
86 if (is_horizontal_) | 88 if (is_horizontal_) |
87 width += GetDividerSize(); | 89 width += GetDividerSize(); |
88 else | 90 else |
89 height += GetDividerSize(); | 91 height += GetDividerSize(); |
92 width += border()->GetInsets().width(); | |
sky
2016/02/16 16:33:51
border may be null. Use GetInsets().
julienp
2016/02/17 13:46:26
Done.
| |
93 height += border()->GetInsets().height(); | |
90 return gfx::Size(width, height); | 94 return gfx::Size(width, height); |
91 } | 95 } |
92 | 96 |
93 gfx::NativeCursor SingleSplitView::GetCursor(const ui::MouseEvent& event) { | 97 gfx::NativeCursor SingleSplitView::GetCursor(const ui::MouseEvent& event) { |
94 if (!IsPointInDivider(event.location())) | 98 if (!IsPointInDivider(event.location())) |
95 return gfx::kNullCursor; | 99 return gfx::kNullCursor; |
96 return is_horizontal_ ? GetNativeEastWestResizeCursor() | 100 return is_horizontal_ ? GetNativeEastWestResizeCursor() |
97 : GetNativeNorthSouthResizeCursor(); | 101 : GetNativeNorthSouthResizeCursor(); |
98 } | 102 } |
99 | 103 |
(...skipping 17 matching lines...) Expand all Loading... | |
117 } | 121 } |
118 | 122 |
119 int divider_at; | 123 int divider_at; |
120 | 124 |
121 if (!is_trailing_visible) { | 125 if (!is_trailing_visible) { |
122 divider_at = GetPrimaryAxisSize(bounds.width(), bounds.height()); | 126 divider_at = GetPrimaryAxisSize(bounds.width(), bounds.height()); |
123 } else if (!is_leading_visible) { | 127 } else if (!is_leading_visible) { |
124 divider_at = 0; | 128 divider_at = 0; |
125 } else { | 129 } else { |
126 divider_at = | 130 divider_at = |
127 CalculateDividerOffset(divider_offset_, this->bounds(), bounds); | 131 CalculateDividerOffset(divider_offset_, GetContentsBounds(), bounds); |
sky
2016/02/16 16:33:51
GetContentsBounds() -> bounds
julienp
2016/02/17 13:46:26
Done.
| |
128 divider_at = NormalizeDividerOffset(divider_at, bounds); | 132 divider_at = NormalizeDividerOffset(divider_at, bounds); |
129 } | 133 } |
130 | 134 |
131 int divider_size = GetDividerSize(); | 135 int divider_size = GetDividerSize(); |
132 | 136 |
133 if (is_horizontal_) { | 137 if (is_horizontal_) { |
134 *leading_bounds = gfx::Rect(0, 0, divider_at, bounds.height()); | 138 *leading_bounds = |
139 gfx::Rect(bounds.x(), bounds.y(), divider_at, bounds.height()); | |
135 *trailing_bounds = | 140 *trailing_bounds = |
136 gfx::Rect(divider_at + divider_size, 0, | 141 gfx::Rect(divider_at + divider_size + bounds.x(), bounds.y(), |
137 std::max(0, bounds.width() - divider_at - divider_size), | 142 std::max(0, bounds.width() - divider_at - divider_size), |
138 bounds.height()); | 143 bounds.height()); |
139 } else { | 144 } else { |
140 *leading_bounds = gfx::Rect(0, 0, bounds.width(), divider_at); | 145 *leading_bounds = |
141 *trailing_bounds = | 146 gfx::Rect(bounds.x(), bounds.y(), bounds.width(), divider_at); |
142 gfx::Rect(0, divider_at + divider_size, bounds.width(), | 147 *trailing_bounds = gfx::Rect( |
143 std::max(0, bounds.height() - divider_at - divider_size)); | 148 bounds.x(), divider_at + divider_size + bounds.y(), bounds.width(), |
149 std::max(0, bounds.height() - divider_at - divider_size)); | |
144 } | 150 } |
145 } | 151 } |
146 | 152 |
147 void SingleSplitView::SetAccessibleName(const base::string16& name) { | 153 void SingleSplitView::SetAccessibleName(const base::string16& name) { |
148 accessible_name_ = name; | 154 accessible_name_ = name; |
149 } | 155 } |
150 | 156 |
151 bool SingleSplitView::OnMousePressed(const ui::MouseEvent& event) { | 157 bool SingleSplitView::OnMousePressed(const ui::MouseEvent& event) { |
152 if (!IsPointInDivider(event.location())) | 158 if (!IsPointInDivider(event.location())) |
153 return false; | 159 return false; |
154 drag_info_.initial_mouse_offset = GetPrimaryAxisSize(event.x(), event.y()); | 160 drag_info_.initial_mouse_offset = GetPrimaryAxisSize(event.x(), event.y()); |
155 drag_info_.initial_divider_offset = | 161 drag_info_.initial_divider_offset = |
156 NormalizeDividerOffset(divider_offset_, bounds()); | 162 NormalizeDividerOffset(divider_offset_, GetContentsBounds()); |
157 return true; | 163 return true; |
158 } | 164 } |
159 | 165 |
160 bool SingleSplitView::OnMouseDragged(const ui::MouseEvent& event) { | 166 bool SingleSplitView::OnMouseDragged(const ui::MouseEvent& event) { |
161 if (child_count() < 2) | 167 if (child_count() < 2) |
162 return false; | 168 return false; |
163 | 169 |
164 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) - | 170 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) - |
165 drag_info_.initial_mouse_offset; | 171 drag_info_.initial_mouse_offset; |
166 if (is_horizontal_ && base::i18n::IsRTL()) | 172 if (is_horizontal_ && base::i18n::IsRTL()) |
(...skipping 22 matching lines...) Expand all Loading... | |
189 return; | 195 return; |
190 | 196 |
191 if (drag_info_.initial_divider_offset != divider_offset_) { | 197 if (drag_info_.initial_divider_offset != divider_offset_) { |
192 set_divider_offset(drag_info_.initial_divider_offset); | 198 set_divider_offset(drag_info_.initial_divider_offset); |
193 if (!listener_ || listener_->SplitHandleMoved(this)) | 199 if (!listener_ || listener_->SplitHandleMoved(this)) |
194 Layout(); | 200 Layout(); |
195 } | 201 } |
196 } | 202 } |
197 | 203 |
198 void SingleSplitView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 204 void SingleSplitView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
199 divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds, | 205 gfx::Rect previous_content_bounds = previous_bounds; |
200 bounds()); | 206 if (border()) |
207 previous_content_bounds.Inset(border()->GetInsets()); | |
208 divider_offset_ = CalculateDividerOffset( | |
209 divider_offset_, previous_content_bounds, GetContentsBounds()); | |
201 } | 210 } |
202 | 211 |
203 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { | 212 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { |
204 if (resize_disabled_) | 213 if (resize_disabled_) |
205 return false; | 214 return false; |
206 | 215 |
207 if (child_count() < 2) | 216 if (child_count() < 2) |
208 return false; | 217 return false; |
209 | 218 |
210 if (!child_at(0)->visible() || !child_at(1)->visible()) | 219 if (!child_at(0)->visible() || !child_at(1)->visible()) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 const gfx::Rect& bounds) const { | 257 const gfx::Rect& bounds) const { |
249 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height()); | 258 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height()); |
250 if (divider_offset < 0) | 259 if (divider_offset < 0) |
251 // primary_axis_size may < GetDividerSize during initial layout. | 260 // primary_axis_size may < GetDividerSize during initial layout. |
252 return std::max(0, (primary_axis_size - GetDividerSize()) / 2); | 261 return std::max(0, (primary_axis_size - GetDividerSize()) / 2); |
253 return std::min(divider_offset, | 262 return std::min(divider_offset, |
254 std::max(primary_axis_size - GetDividerSize(), 0)); | 263 std::max(primary_axis_size - GetDividerSize(), 0)); |
255 } | 264 } |
256 | 265 |
257 } // namespace views | 266 } // namespace views |
OLD | NEW |