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

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

Issue 1702473002: Make SingleSplitView take borders into account. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adapted unittest Created 4 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
« no previous file with comments | « no previous file | ui/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) 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
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
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 += GetInsets().width();
93 height += 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 16 matching lines...) Expand all
116 return; 120 return;
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 = CalculateDividerOffset(divider_offset_, bounds, bounds);
127 CalculateDividerOffset(divider_offset_, this->bounds(), bounds);
128 divider_at = NormalizeDividerOffset(divider_at, bounds); 131 divider_at = NormalizeDividerOffset(divider_at, bounds);
129 } 132 }
130 133
131 int divider_size = GetDividerSize(); 134 int divider_size = GetDividerSize();
132 135
133 if (is_horizontal_) { 136 if (is_horizontal_) {
134 *leading_bounds = gfx::Rect(0, 0, divider_at, bounds.height()); 137 *leading_bounds =
138 gfx::Rect(bounds.x(), bounds.y(), divider_at, bounds.height());
135 *trailing_bounds = 139 *trailing_bounds =
136 gfx::Rect(divider_at + divider_size, 0, 140 gfx::Rect(divider_at + divider_size + bounds.x(), bounds.y(),
137 std::max(0, bounds.width() - divider_at - divider_size), 141 std::max(0, bounds.width() - divider_at - divider_size),
138 bounds.height()); 142 bounds.height());
139 } else { 143 } else {
140 *leading_bounds = gfx::Rect(0, 0, bounds.width(), divider_at); 144 *leading_bounds =
141 *trailing_bounds = 145 gfx::Rect(bounds.x(), bounds.y(), bounds.width(), divider_at);
142 gfx::Rect(0, divider_at + divider_size, bounds.width(), 146 *trailing_bounds = gfx::Rect(
143 std::max(0, bounds.height() - divider_at - divider_size)); 147 bounds.x(), divider_at + divider_size + bounds.y(), bounds.width(),
148 std::max(0, bounds.height() - divider_at - divider_size));
144 } 149 }
145 } 150 }
146 151
147 void SingleSplitView::SetAccessibleName(const base::string16& name) { 152 void SingleSplitView::SetAccessibleName(const base::string16& name) {
148 accessible_name_ = name; 153 accessible_name_ = name;
149 } 154 }
150 155
151 bool SingleSplitView::OnMousePressed(const ui::MouseEvent& event) { 156 bool SingleSplitView::OnMousePressed(const ui::MouseEvent& event) {
152 if (!IsPointInDivider(event.location())) 157 if (!IsPointInDivider(event.location()))
153 return false; 158 return false;
154 drag_info_.initial_mouse_offset = GetPrimaryAxisSize(event.x(), event.y()); 159 drag_info_.initial_mouse_offset = GetPrimaryAxisSize(event.x(), event.y());
155 drag_info_.initial_divider_offset = 160 drag_info_.initial_divider_offset =
156 NormalizeDividerOffset(divider_offset_, bounds()); 161 NormalizeDividerOffset(divider_offset_, GetContentsBounds());
157 return true; 162 return true;
158 } 163 }
159 164
160 bool SingleSplitView::OnMouseDragged(const ui::MouseEvent& event) { 165 bool SingleSplitView::OnMouseDragged(const ui::MouseEvent& event) {
161 if (child_count() < 2) 166 if (child_count() < 2)
162 return false; 167 return false;
163 168
164 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) - 169 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) -
165 drag_info_.initial_mouse_offset; 170 drag_info_.initial_mouse_offset;
166 if (is_horizontal_ && base::i18n::IsRTL()) 171 if (is_horizontal_ && base::i18n::IsRTL())
(...skipping 22 matching lines...) Expand all
189 return; 194 return;
190 195
191 if (drag_info_.initial_divider_offset != divider_offset_) { 196 if (drag_info_.initial_divider_offset != divider_offset_) {
192 set_divider_offset(drag_info_.initial_divider_offset); 197 set_divider_offset(drag_info_.initial_divider_offset);
193 if (!listener_ || listener_->SplitHandleMoved(this)) 198 if (!listener_ || listener_->SplitHandleMoved(this))
194 Layout(); 199 Layout();
195 } 200 }
196 } 201 }
197 202
198 void SingleSplitView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 203 void SingleSplitView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
199 divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds, 204 gfx::Rect previous_content_bounds = previous_bounds;
200 bounds()); 205 previous_content_bounds.Inset(GetInsets());
206 divider_offset_ = CalculateDividerOffset(
207 divider_offset_, previous_content_bounds, GetContentsBounds());
201 } 208 }
202 209
203 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { 210 bool SingleSplitView::IsPointInDivider(const gfx::Point& p) {
204 if (resize_disabled_) 211 if (resize_disabled_)
205 return false; 212 return false;
206 213
207 if (child_count() < 2) 214 if (child_count() < 2)
208 return false; 215 return false;
209 216
210 if (!child_at(0)->visible() || !child_at(1)->visible()) 217 if (!child_at(0)->visible() || !child_at(1)->visible())
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 const gfx::Rect& bounds) const { 255 const gfx::Rect& bounds) const {
249 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height()); 256 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height());
250 if (divider_offset < 0) 257 if (divider_offset < 0)
251 // primary_axis_size may < GetDividerSize during initial layout. 258 // primary_axis_size may < GetDividerSize during initial layout.
252 return std::max(0, (primary_axis_size - GetDividerSize()) / 2); 259 return std::max(0, (primary_axis_size - GetDividerSize()) / 2);
253 return std::min(divider_offset, 260 return std::min(divider_offset,
254 std::max(primary_axis_size - GetDividerSize(), 0)); 261 std::max(primary_axis_size - GetDividerSize(), 0));
255 } 262 }
256 263
257 } // namespace views 264 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/single_split_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698