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 #include "views/controls/single_split_view.h" | 5 #include "views/controls/single_split_view.h" |
6 | 6 |
7 #if defined(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
8 #include <gdk/gdk.h> | 8 #include <gdk/gdk.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "skia/ext/skia_utils_win.h" | 11 #include "skia/ext/skia_utils_win.h" |
12 #include "ui/base/accessibility/accessible_view_state.h" | 12 #include "ui/base/accessibility/accessible_view_state.h" |
13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
14 #include "views/background.h" | 14 #include "views/background.h" |
| 15 #include "views/controls/single_split_view_listener.h" |
15 | 16 |
16 #if defined(TOOLKIT_USES_GTK) | 17 #if defined(TOOLKIT_USES_GTK) |
17 #include "ui/gfx/gtk_util.h" | 18 #include "ui/gfx/gtk_util.h" |
18 #endif | 19 #endif |
19 | 20 |
20 #if defined(USE_AURA) | 21 #if defined(USE_AURA) |
21 #include "ui/aura/cursor.h" | 22 #include "ui/aura/cursor.h" |
22 #endif | 23 #endif |
23 | 24 |
24 namespace views { | 25 namespace views { |
25 | 26 |
26 // static | 27 // static |
27 const char SingleSplitView::kViewClassName[] = | 28 const char SingleSplitView::kViewClassName[] = |
28 "views/controls/SingleSplitView"; | 29 "views/controls/SingleSplitView"; |
29 | 30 |
30 // Size of the divider in pixels. | 31 // Size of the divider in pixels. |
31 static const int kDividerSize = 4; | 32 static const int kDividerSize = 4; |
32 | 33 |
33 SingleSplitView::SingleSplitView(View* leading, | 34 SingleSplitView::SingleSplitView(View* leading, |
34 View* trailing, | 35 View* trailing, |
35 Orientation orientation, | 36 Orientation orientation, |
36 Observer* observer) | 37 SingleSplitViewListener* listener) |
37 : is_horizontal_(orientation == HORIZONTAL_SPLIT), | 38 : is_horizontal_(orientation == HORIZONTAL_SPLIT), |
38 divider_offset_(-1), | 39 divider_offset_(-1), |
39 resize_leading_on_bounds_change_(true), | 40 resize_leading_on_bounds_change_(true), |
40 observer_(observer) { | 41 listener_(listener) { |
41 AddChildView(leading); | 42 AddChildView(leading); |
42 AddChildView(trailing); | 43 AddChildView(trailing); |
43 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
44 set_background( | 45 set_background( |
45 views::Background::CreateSolidBackground( | 46 views::Background::CreateSolidBackground( |
46 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); | 47 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); |
47 #endif | 48 #endif |
48 } | 49 } |
49 | 50 |
50 void SingleSplitView::Layout() { | 51 void SingleSplitView::Layout() { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // Honor the minimum size when resizing. | 180 // Honor the minimum size when resizing. |
180 gfx::Size min = child_at(0)->GetMinimumSize(); | 181 gfx::Size min = child_at(0)->GetMinimumSize(); |
181 int new_size = std::max(GetPrimaryAxisSize(min.width(), min.height()), | 182 int new_size = std::max(GetPrimaryAxisSize(min.width(), min.height()), |
182 drag_info_.initial_divider_offset + delta_offset); | 183 drag_info_.initial_divider_offset + delta_offset); |
183 | 184 |
184 // And don't let the view get bigger than our width. | 185 // And don't let the view get bigger than our width. |
185 new_size = std::min(GetPrimaryAxisSize() - kDividerSize, new_size); | 186 new_size = std::min(GetPrimaryAxisSize() - kDividerSize, new_size); |
186 | 187 |
187 if (new_size != divider_offset_) { | 188 if (new_size != divider_offset_) { |
188 set_divider_offset(new_size); | 189 set_divider_offset(new_size); |
189 if (!observer_ || observer_->SplitHandleMoved(this)) | 190 if (!listener_ || listener_->SplitHandleMoved(this)) |
190 Layout(); | 191 Layout(); |
191 } | 192 } |
192 return true; | 193 return true; |
193 } | 194 } |
194 | 195 |
195 void SingleSplitView::OnMouseCaptureLost() { | 196 void SingleSplitView::OnMouseCaptureLost() { |
196 if (child_count() < 2) | 197 if (child_count() < 2) |
197 return; | 198 return; |
198 | 199 |
199 if (drag_info_.initial_divider_offset != divider_offset_) { | 200 if (drag_info_.initial_divider_offset != divider_offset_) { |
200 set_divider_offset(drag_info_.initial_divider_offset); | 201 set_divider_offset(drag_info_.initial_divider_offset); |
201 if (!observer_ || observer_->SplitHandleMoved(this)) | 202 if (!listener_ || listener_->SplitHandleMoved(this)) |
202 Layout(); | 203 Layout(); |
203 } | 204 } |
204 } | 205 } |
205 | 206 |
206 void SingleSplitView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 207 void SingleSplitView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
207 divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds, | 208 divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds, |
208 bounds()); | 209 bounds()); |
209 } | 210 } |
210 | 211 |
211 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { | 212 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 const gfx::Rect& bounds) const { | 254 const gfx::Rect& bounds) const { |
254 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height()); | 255 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height()); |
255 if (divider_offset < 0) | 256 if (divider_offset < 0) |
256 // primary_axis_size may < kDividerSize during initial layout. | 257 // primary_axis_size may < kDividerSize during initial layout. |
257 return std::max(0, (primary_axis_size - kDividerSize) / 2); | 258 return std::max(0, (primary_axis_size - kDividerSize) / 2); |
258 return std::min(divider_offset, | 259 return std::min(divider_offset, |
259 std::max(primary_axis_size - kDividerSize, 0)); | 260 std::max(primary_axis_size - kDividerSize, 0)); |
260 } | 261 } |
261 | 262 |
262 } // namespace views | 263 } // namespace views |
OLD | NEW |