| 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(OS_LINUX) | 7 #if defined(OS_LINUX) |
| 8 #include <gdk/gdk.h> | 8 #include <gdk/gdk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); | 42 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); |
| 43 #endif | 43 #endif |
| 44 } | 44 } |
| 45 | 45 |
| 46 void SingleSplitView::Layout() { | 46 void SingleSplitView::Layout() { |
| 47 gfx::Rect leading_bounds; | 47 gfx::Rect leading_bounds; |
| 48 gfx::Rect trailing_bounds; | 48 gfx::Rect trailing_bounds; |
| 49 CalculateChildrenBounds(bounds(), &leading_bounds, &trailing_bounds); | 49 CalculateChildrenBounds(bounds(), &leading_bounds, &trailing_bounds); |
| 50 | 50 |
| 51 if (has_children()) { | 51 if (has_children()) { |
| 52 if (GetChildViewAt(0)->IsVisible()) | 52 if (child_at(0)->IsVisible()) |
| 53 GetChildViewAt(0)->SetBoundsRect(leading_bounds); | 53 child_at(0)->SetBoundsRect(leading_bounds); |
| 54 if (child_count() > 1) { | 54 if (child_count() > 1) { |
| 55 if (GetChildViewAt(1)->IsVisible()) | 55 if (child_at(1)->IsVisible()) |
| 56 GetChildViewAt(1)->SetBoundsRect(trailing_bounds); | 56 child_at(1)->SetBoundsRect(trailing_bounds); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 SchedulePaint(); | 60 SchedulePaint(); |
| 61 | 61 |
| 62 // Invoke super's implementation so that the children are layed out. | 62 // Invoke super's implementation so that the children are layed out. |
| 63 View::Layout(); | 63 View::Layout(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 std::string SingleSplitView::GetClassName() const { | 66 std::string SingleSplitView::GetClassName() const { |
| 67 return kViewClassName; | 67 return kViewClassName; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void SingleSplitView::GetAccessibleState(ui::AccessibleViewState* state) { | 70 void SingleSplitView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 71 state->role = ui::AccessibilityTypes::ROLE_GROUPING; | 71 state->role = ui::AccessibilityTypes::ROLE_GROUPING; |
| 72 state->name = accessible_name_; | 72 state->name = accessible_name_; |
| 73 } | 73 } |
| 74 | 74 |
| 75 gfx::Size SingleSplitView::GetPreferredSize() { | 75 gfx::Size SingleSplitView::GetPreferredSize() { |
| 76 int width = 0; | 76 int width = 0; |
| 77 int height = 0; | 77 int height = 0; |
| 78 for (int i = 0; i < 2 && i < child_count(); ++i) { | 78 for (int i = 0; i < 2 && i < child_count(); ++i) { |
| 79 View* view = GetChildViewAt(i); | 79 View* view = child_at(i); |
| 80 gfx::Size pref = view->GetPreferredSize(); | 80 gfx::Size pref = view->GetPreferredSize(); |
| 81 if (is_horizontal_) { | 81 if (is_horizontal_) { |
| 82 width += pref.width(); | 82 width += pref.width(); |
| 83 height = std::max(height, pref.height()); | 83 height = std::max(height, pref.height()); |
| 84 } else { | 84 } else { |
| 85 width = std::max(width, pref.width()); | 85 width = std::max(width, pref.width()); |
| 86 height += pref.height(); | 86 height += pref.height(); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 if (is_horizontal_) | 89 if (is_horizontal_) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 103 #elif defined(OS_LINUX) | 103 #elif defined(OS_LINUX) |
| 104 return gfx::GetCursor(is_horizontal_ ? GDK_SB_H_DOUBLE_ARROW : | 104 return gfx::GetCursor(is_horizontal_ ? GDK_SB_H_DOUBLE_ARROW : |
| 105 GDK_SB_V_DOUBLE_ARROW); | 105 GDK_SB_V_DOUBLE_ARROW); |
| 106 #endif | 106 #endif |
| 107 } | 107 } |
| 108 | 108 |
| 109 void SingleSplitView::CalculateChildrenBounds( | 109 void SingleSplitView::CalculateChildrenBounds( |
| 110 const gfx::Rect& bounds, | 110 const gfx::Rect& bounds, |
| 111 gfx::Rect* leading_bounds, | 111 gfx::Rect* leading_bounds, |
| 112 gfx::Rect* trailing_bounds) const { | 112 gfx::Rect* trailing_bounds) const { |
| 113 bool is_leading_visible = has_children() && GetChildViewAt(0)->IsVisible(); | 113 bool is_leading_visible = has_children() && child_at(0)->IsVisible(); |
| 114 bool is_trailing_visible = | 114 bool is_trailing_visible = child_count() > 1 && child_at(1)->IsVisible(); |
| 115 child_count() > 1 && GetChildViewAt(1)->IsVisible(); | |
| 116 | 115 |
| 117 if (!is_leading_visible && !is_trailing_visible) { | 116 if (!is_leading_visible && !is_trailing_visible) { |
| 118 *leading_bounds = gfx::Rect(); | 117 *leading_bounds = gfx::Rect(); |
| 119 *trailing_bounds = gfx::Rect(); | 118 *trailing_bounds = gfx::Rect(); |
| 120 return; | 119 return; |
| 121 } | 120 } |
| 122 | 121 |
| 123 int divider_at; | 122 int divider_at; |
| 124 | 123 |
| 125 if (!is_trailing_visible) { | 124 if (!is_trailing_visible) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 163 |
| 165 bool SingleSplitView::OnMouseDragged(const MouseEvent& event) { | 164 bool SingleSplitView::OnMouseDragged(const MouseEvent& event) { |
| 166 if (child_count() < 2) | 165 if (child_count() < 2) |
| 167 return false; | 166 return false; |
| 168 | 167 |
| 169 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) - | 168 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) - |
| 170 drag_info_.initial_mouse_offset; | 169 drag_info_.initial_mouse_offset; |
| 171 if (is_horizontal_ && base::i18n::IsRTL()) | 170 if (is_horizontal_ && base::i18n::IsRTL()) |
| 172 delta_offset *= -1; | 171 delta_offset *= -1; |
| 173 // Honor the minimum size when resizing. | 172 // Honor the minimum size when resizing. |
| 174 gfx::Size min = GetChildViewAt(0)->GetMinimumSize(); | 173 gfx::Size min = child_at(0)->GetMinimumSize(); |
| 175 int new_size = std::max(GetPrimaryAxisSize(min.width(), min.height()), | 174 int new_size = std::max(GetPrimaryAxisSize(min.width(), min.height()), |
| 176 drag_info_.initial_divider_offset + delta_offset); | 175 drag_info_.initial_divider_offset + delta_offset); |
| 177 | 176 |
| 178 // And don't let the view get bigger than our width. | 177 // And don't let the view get bigger than our width. |
| 179 new_size = std::min(GetPrimaryAxisSize() - kDividerSize, new_size); | 178 new_size = std::min(GetPrimaryAxisSize() - kDividerSize, new_size); |
| 180 | 179 |
| 181 if (new_size != divider_offset_) { | 180 if (new_size != divider_offset_) { |
| 182 set_divider_offset(new_size); | 181 set_divider_offset(new_size); |
| 183 if (!observer_ || observer_->SplitHandleMoved(this)) | 182 if (!observer_ || observer_->SplitHandleMoved(this)) |
| 184 Layout(); | 183 Layout(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 199 | 198 |
| 200 void SingleSplitView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 199 void SingleSplitView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 201 divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds, | 200 divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds, |
| 202 bounds()); | 201 bounds()); |
| 203 } | 202 } |
| 204 | 203 |
| 205 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { | 204 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { |
| 206 if (child_count() < 2) | 205 if (child_count() < 2) |
| 207 return false; | 206 return false; |
| 208 | 207 |
| 209 if (!GetChildViewAt(0)->IsVisible() || !GetChildViewAt(1)->IsVisible()) | 208 if (!child_at(0)->IsVisible() || !child_at(1)->IsVisible()) |
| 210 return false; | 209 return false; |
| 211 | 210 |
| 212 int divider_relative_offset; | 211 int divider_relative_offset; |
| 213 if (is_horizontal_) { | 212 if (is_horizontal_) { |
| 214 divider_relative_offset = | 213 divider_relative_offset = |
| 215 p.x() - GetChildViewAt(base::i18n::IsRTL() ? 1 : 0)->width(); | 214 p.x() - child_at(base::i18n::IsRTL() ? 1 : 0)->width(); |
| 216 } else { | 215 } else { |
| 217 divider_relative_offset = p.y() - GetChildViewAt(0)->height(); | 216 divider_relative_offset = p.y() - child_at(0)->height(); |
| 218 } | 217 } |
| 219 return (divider_relative_offset >= 0 && | 218 return (divider_relative_offset >= 0 && |
| 220 divider_relative_offset < kDividerSize); | 219 divider_relative_offset < kDividerSize); |
| 221 } | 220 } |
| 222 | 221 |
| 223 int SingleSplitView::CalculateDividerOffset( | 222 int SingleSplitView::CalculateDividerOffset( |
| 224 int divider_offset, | 223 int divider_offset, |
| 225 const gfx::Rect& previous_bounds, | 224 const gfx::Rect& previous_bounds, |
| 226 const gfx::Rect& new_bounds) const { | 225 const gfx::Rect& new_bounds) const { |
| 227 if (resize_leading_on_bounds_change_ && divider_offset != -1) { | 226 if (resize_leading_on_bounds_change_ && divider_offset != -1) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 246 int SingleSplitView::NormalizeDividerOffset(int divider_offset, | 245 int SingleSplitView::NormalizeDividerOffset(int divider_offset, |
| 247 const gfx::Rect& bounds) const { | 246 const gfx::Rect& bounds) const { |
| 248 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height()); | 247 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height()); |
| 249 if (divider_offset < 0) | 248 if (divider_offset < 0) |
| 250 return (primary_axis_size - kDividerSize) / 2; | 249 return (primary_axis_size - kDividerSize) / 2; |
| 251 return std::min(divider_offset, | 250 return std::min(divider_offset, |
| 252 std::max(primary_axis_size - kDividerSize, 0)); | 251 std::max(primary_axis_size - kDividerSize, 0)); |
| 253 } | 252 } |
| 254 | 253 |
| 255 } // namespace views | 254 } // namespace views |
| OLD | NEW |