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

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

Issue 6452011: Rework tree APIs to reflect Google style and more const-correctness.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months 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/scroll_view.cc ('k') | views/controls/single_split_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 21 matching lines...) Expand all
32 AddChildView(leading); 32 AddChildView(leading);
33 AddChildView(trailing); 33 AddChildView(trailing);
34 #if defined(OS_WIN) 34 #if defined(OS_WIN)
35 set_background( 35 set_background(
36 views::Background::CreateSolidBackground( 36 views::Background::CreateSolidBackground(
37 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); 37 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE))));
38 #endif 38 #endif
39 } 39 }
40 40
41 void SingleSplitView::OnBoundsChanged() { 41 void SingleSplitView::OnBoundsChanged() {
42 divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds_, bo unds()); 42 divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds_,
43 bounds());
43 View::OnBoundsChanged(); 44 View::OnBoundsChanged();
44 previous_bounds_ = bounds(); 45 previous_bounds_ = bounds();
45 } 46 }
46 47
47 void SingleSplitView::Layout() { 48 void SingleSplitView::Layout() {
48 gfx::Rect leading_bounds; 49 gfx::Rect leading_bounds;
49 gfx::Rect trailing_bounds; 50 gfx::Rect trailing_bounds;
50 CalculateChildrenBounds(bounds(), &leading_bounds, &trailing_bounds); 51 CalculateChildrenBounds(bounds(), &leading_bounds, &trailing_bounds);
51 52
52 if (GetChildViewCount() > 0) { 53 if (has_children()) {
53 if (GetChildViewAt(0)->IsVisible()) 54 if (GetChildViewAt(0)->IsVisible())
54 GetChildViewAt(0)->SetBoundsRect(leading_bounds); 55 GetChildViewAt(0)->SetBoundsRect(leading_bounds);
55 if (GetChildViewCount() > 1) { 56 if (child_count() > 1) {
56 if (GetChildViewAt(1)->IsVisible()) 57 if (GetChildViewAt(1)->IsVisible())
57 GetChildViewAt(1)->SetBoundsRect(trailing_bounds); 58 GetChildViewAt(1)->SetBoundsRect(trailing_bounds);
58 } 59 }
59 } 60 }
60 61
61 SchedulePaint(); 62 SchedulePaint();
62 63
63 // Invoke super's implementation so that the children are layed out. 64 // Invoke super's implementation so that the children are layed out.
64 View::Layout(); 65 View::Layout();
65 } 66 }
66 67
67 AccessibilityTypes::Role SingleSplitView::GetAccessibleRole() { 68 AccessibilityTypes::Role SingleSplitView::GetAccessibleRole() {
68 return AccessibilityTypes::ROLE_GROUPING; 69 return AccessibilityTypes::ROLE_GROUPING;
69 } 70 }
70 71
71 gfx::Size SingleSplitView::GetPreferredSize() { 72 gfx::Size SingleSplitView::GetPreferredSize() {
72 int width = 0; 73 int width = 0;
73 int height = 0; 74 int height = 0;
74 for (int i = 0; i < 2 && i < GetChildViewCount(); ++i) { 75 for (int i = 0; i < 2 && i < child_count(); ++i) {
75 View* view = GetChildViewAt(i); 76 View* view = GetChildViewAt(i);
76 gfx::Size pref = view->GetPreferredSize(); 77 gfx::Size pref = view->GetPreferredSize();
77 if (is_horizontal_) { 78 if (is_horizontal_) {
78 width += pref.width(); 79 width += pref.width();
79 height = std::max(height, pref.height()); 80 height = std::max(height, pref.height());
80 } else { 81 } else {
81 width = std::max(width, pref.width()); 82 width = std::max(width, pref.width());
82 height += pref.height(); 83 height += pref.height();
83 } 84 }
84 } 85 }
(...skipping 18 matching lines...) Expand all
103 GDK_SB_V_DOUBLE_ARROW); 104 GDK_SB_V_DOUBLE_ARROW);
104 #endif 105 #endif
105 } 106 }
106 return NULL; 107 return NULL;
107 } 108 }
108 109
109 void SingleSplitView::CalculateChildrenBounds( 110 void SingleSplitView::CalculateChildrenBounds(
110 const gfx::Rect& bounds, 111 const gfx::Rect& bounds,
111 gfx::Rect* leading_bounds, 112 gfx::Rect* leading_bounds,
112 gfx::Rect* trailing_bounds) const { 113 gfx::Rect* trailing_bounds) const {
113 bool is_leading_visible = 114 bool is_leading_visible = has_children() && GetChildViewAt(0)->IsVisible();
114 GetChildViewCount() > 0 && GetChildViewAt(0)->IsVisible();
115 bool is_trailing_visible = 115 bool is_trailing_visible =
116 GetChildViewCount() > 1 && GetChildViewAt(1)->IsVisible(); 116 child_count() > 1 && GetChildViewAt(1)->IsVisible();
117 117
118 if (!is_leading_visible && !is_trailing_visible) { 118 if (!is_leading_visible && !is_trailing_visible) {
119 *leading_bounds = gfx::Rect(); 119 *leading_bounds = gfx::Rect();
120 *trailing_bounds = gfx::Rect(); 120 *trailing_bounds = gfx::Rect();
121 return; 121 return;
122 } 122 }
123 123
124 int divider_at; 124 int divider_at;
125 125
126 if (!is_trailing_visible) { 126 if (!is_trailing_visible) {
(...skipping 26 matching lines...) Expand all
153 bool SingleSplitView::OnMousePressed(const MouseEvent& event) { 153 bool SingleSplitView::OnMousePressed(const MouseEvent& event) {
154 if (!IsPointInDivider(event.location())) 154 if (!IsPointInDivider(event.location()))
155 return false; 155 return false;
156 drag_info_.initial_mouse_offset = GetPrimaryAxisSize(event.x(), event.y()); 156 drag_info_.initial_mouse_offset = GetPrimaryAxisSize(event.x(), event.y());
157 drag_info_.initial_divider_offset = 157 drag_info_.initial_divider_offset =
158 NormalizeDividerOffset(divider_offset_, bounds()); 158 NormalizeDividerOffset(divider_offset_, bounds());
159 return true; 159 return true;
160 } 160 }
161 161
162 bool SingleSplitView::OnMouseDragged(const MouseEvent& event) { 162 bool SingleSplitView::OnMouseDragged(const MouseEvent& event) {
163 if (GetChildViewCount() < 2) 163 if (child_count() < 2)
164 return false; 164 return false;
165 165
166 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) - 166 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) -
167 drag_info_.initial_mouse_offset; 167 drag_info_.initial_mouse_offset;
168 if (is_horizontal_ && base::i18n::IsRTL()) 168 if (is_horizontal_ && base::i18n::IsRTL())
169 delta_offset *= -1; 169 delta_offset *= -1;
170 // Honor the minimum size when resizing. 170 // Honor the minimum size when resizing.
171 gfx::Size min = GetChildViewAt(0)->GetMinimumSize(); 171 gfx::Size min = GetChildViewAt(0)->GetMinimumSize();
172 int new_size = std::max(GetPrimaryAxisSize(min.width(), min.height()), 172 int new_size = std::max(GetPrimaryAxisSize(min.width(), min.height()),
173 drag_info_.initial_divider_offset + delta_offset); 173 drag_info_.initial_divider_offset + delta_offset);
174 174
175 // And don't let the view get bigger than our width. 175 // And don't let the view get bigger than our width.
176 new_size = std::min(GetPrimaryAxisSize() - kDividerSize, new_size); 176 new_size = std::min(GetPrimaryAxisSize() - kDividerSize, new_size);
177 177
178 if (new_size != divider_offset_) { 178 if (new_size != divider_offset_) {
179 set_divider_offset(new_size); 179 set_divider_offset(new_size);
180 if (!observer_ || observer_->SplitHandleMoved(this)) 180 if (!observer_ || observer_->SplitHandleMoved(this))
181 Layout(); 181 Layout();
182 } 182 }
183 return true; 183 return true;
184 } 184 }
185 185
186 void SingleSplitView::OnMouseReleased(const MouseEvent& event, bool canceled) { 186 void SingleSplitView::OnMouseReleased(const MouseEvent& event, bool canceled) {
187 if (GetChildViewCount() < 2) 187 if (child_count() < 2)
188 return; 188 return;
189 189
190 if (canceled && drag_info_.initial_divider_offset != divider_offset_) { 190 if (canceled && drag_info_.initial_divider_offset != divider_offset_) {
191 set_divider_offset(drag_info_.initial_divider_offset); 191 set_divider_offset(drag_info_.initial_divider_offset);
192 if (!observer_ || observer_->SplitHandleMoved(this)) 192 if (!observer_ || observer_->SplitHandleMoved(this))
193 Layout(); 193 Layout();
194 } 194 }
195 } 195 }
196 196
197 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { 197 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) {
198 if (GetChildViewCount() < 2) 198 if (child_count() < 2)
199 return false; 199 return false;
200 200
201 if (!GetChildViewAt(0)->IsVisible() || !GetChildViewAt(1)->IsVisible()) 201 if (!GetChildViewAt(0)->IsVisible() || !GetChildViewAt(1)->IsVisible())
202 return false; 202 return false;
203 203
204 int divider_relative_offset; 204 int divider_relative_offset;
205 if (is_horizontal_) { 205 if (is_horizontal_) {
206 divider_relative_offset = 206 divider_relative_offset =
207 p.x() - GetChildViewAt(base::i18n::IsRTL() ? 1 : 0)->width(); 207 p.x() - GetChildViewAt(base::i18n::IsRTL() ? 1 : 0)->width();
208 } else { 208 } else {
(...skipping 29 matching lines...) Expand all
238 int SingleSplitView::NormalizeDividerOffset(int divider_offset, 238 int SingleSplitView::NormalizeDividerOffset(int divider_offset,
239 const gfx::Rect& bounds) const { 239 const gfx::Rect& bounds) const {
240 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height()); 240 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height());
241 if (divider_offset < 0) 241 if (divider_offset < 0)
242 return (primary_axis_size - kDividerSize) / 2; 242 return (primary_axis_size - kDividerSize) / 2;
243 return std::min(divider_offset, 243 return std::min(divider_offset,
244 std::max(primary_axis_size - kDividerSize, 0)); 244 std::max(primary_axis_size - kDividerSize, 0));
245 } 245 }
246 246
247 } // namespace views 247 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/scroll_view.cc ('k') | views/controls/single_split_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698