| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 17 matching lines...) Expand all Loading... |
| 28 views::Background::CreateSolidBackground( | 28 views::Background::CreateSolidBackground( |
| 29 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); | 29 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void SingleSplitView::Layout() { | 32 void SingleSplitView::Layout() { |
| 33 if (GetChildViewCount() != 2) | 33 if (GetChildViewCount() != 2) |
| 34 return; | 34 return; |
| 35 | 35 |
| 36 View* leading = GetChildViewAt(0); | 36 View* leading = GetChildViewAt(0); |
| 37 View* trailing = GetChildViewAt(1); | 37 View* trailing = GetChildViewAt(1); |
| 38 if (divider_offset_ < 0) | |
| 39 divider_offset_ = (GetPrimaryAxisSize() - kDividerSize) / 2; | |
| 40 else | |
| 41 divider_offset_ = std::min(divider_offset_, | |
| 42 GetPrimaryAxisSize() - kDividerSize); | |
| 43 | 38 |
| 44 if (is_horizontal_) { | 39 if (!leading->IsVisible() && !trailing->IsVisible()) |
| 45 leading->SetBounds(0, 0, divider_offset_, height()); | 40 return; |
| 46 trailing->SetBounds(divider_offset_ + kDividerSize, 0, | 41 |
| 47 width() - divider_offset_ - kDividerSize, height()); | 42 if (!trailing->IsVisible()) { |
| 43 leading->SetBounds(0, 0, width(), height()); |
| 44 } else if (!leading->IsVisible()) { |
| 45 trailing->SetBounds(0, 0, width(), height()); |
| 48 } else { | 46 } else { |
| 49 leading->SetBounds(0, 0, width(), divider_offset_); | 47 if (divider_offset_ < 0) |
| 50 trailing->SetBounds(0, divider_offset_ + kDividerSize, | 48 divider_offset_ = (GetPrimaryAxisSize() - kDividerSize) / 2; |
| 51 width(), height() - divider_offset_ - kDividerSize); | 49 else |
| 50 divider_offset_ = std::min(divider_offset_, |
| 51 GetPrimaryAxisSize() - kDividerSize); |
| 52 |
| 53 if (is_horizontal_) { |
| 54 leading->SetBounds(0, 0, divider_offset_, height()); |
| 55 trailing->SetBounds(divider_offset_ + kDividerSize, 0, |
| 56 width() - divider_offset_ - kDividerSize, height()); |
| 57 } else { |
| 58 leading->SetBounds(0, 0, width(), divider_offset_); |
| 59 trailing->SetBounds(0, divider_offset_ + kDividerSize, |
| 60 width(), height() - divider_offset_ - kDividerSize); |
| 61 } |
| 52 } | 62 } |
| 53 | 63 |
| 54 SchedulePaint(); | 64 SchedulePaint(); |
| 55 | 65 |
| 56 // Invoke super's implementation so that the children are layed out. | 66 // Invoke super's implementation so that the children are layed out. |
| 57 View::Layout(); | 67 View::Layout(); |
| 58 } | 68 } |
| 59 | 69 |
| 60 gfx::Size SingleSplitView::GetPreferredSize() { | 70 gfx::Size SingleSplitView::GetPreferredSize() { |
| 61 int width = 0; | 71 int width = 0; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (canceled && drag_info_.initial_divider_offset != divider_offset_) { | 142 if (canceled && drag_info_.initial_divider_offset != divider_offset_) { |
| 133 set_divider_offset(drag_info_.initial_divider_offset); | 143 set_divider_offset(drag_info_.initial_divider_offset); |
| 134 Layout(); | 144 Layout(); |
| 135 } | 145 } |
| 136 } | 146 } |
| 137 | 147 |
| 138 bool SingleSplitView::IsPointInDivider(int x, int y) { | 148 bool SingleSplitView::IsPointInDivider(int x, int y) { |
| 139 if (GetChildViewCount() < 2) | 149 if (GetChildViewCount() < 2) |
| 140 return false; | 150 return false; |
| 141 | 151 |
| 152 if (!GetChildViewAt(0)->IsVisible() || !GetChildViewAt(1)->IsVisible()) |
| 153 return false; |
| 154 |
| 142 int divider_relative_offset; | 155 int divider_relative_offset; |
| 143 if (is_horizontal_) { | 156 if (is_horizontal_) { |
| 144 divider_relative_offset = | 157 divider_relative_offset = |
| 145 x - GetChildViewAt(UILayoutIsRightToLeft() ? 1 : 0)->width(); | 158 x - GetChildViewAt(UILayoutIsRightToLeft() ? 1 : 0)->width(); |
| 146 } else { | 159 } else { |
| 147 divider_relative_offset = y - GetChildViewAt(0)->height(); | 160 divider_relative_offset = y - GetChildViewAt(0)->height(); |
| 148 } | 161 } |
| 149 return (divider_relative_offset >= 0 && | 162 return (divider_relative_offset >= 0 && |
| 150 divider_relative_offset < kDividerSize); | 163 divider_relative_offset < kDividerSize); |
| 151 } | 164 } |
| 152 | 165 |
| 153 } // namespace views | 166 } // namespace views |
| OLD | NEW |