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

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

Issue 12013004: alternate ntp: unpinned bookmark bar in ntp (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | « ui/views/controls/single_split_view.h ('k') | no next file » | 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 "skia/ext/skia_utils_win.h" 7 #include "skia/ext/skia_utils_win.h"
8 #include "ui/base/accessibility/accessible_view_state.h" 8 #include "ui/base/accessibility/accessible_view_state.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/views/background.h" 10 #include "ui/views/background.h"
(...skipping 12 matching lines...) Expand all
23 // Size of the divider in pixels. 23 // Size of the divider in pixels.
24 static const int kDividerSize = 4; 24 static const int kDividerSize = 4;
25 25
26 SingleSplitView::SingleSplitView(View* leading, 26 SingleSplitView::SingleSplitView(View* leading,
27 View* trailing, 27 View* trailing,
28 Orientation orientation, 28 Orientation orientation,
29 SingleSplitViewListener* listener) 29 SingleSplitViewListener* listener)
30 : is_horizontal_(orientation == HORIZONTAL_SPLIT), 30 : is_horizontal_(orientation == HORIZONTAL_SPLIT),
31 divider_offset_(-1), 31 divider_offset_(-1),
32 resize_leading_on_bounds_change_(true), 32 resize_leading_on_bounds_change_(true),
33 listener_(listener), 33 listener_(listener) {
34 leading_bottom_offset_(0) {
35 AddChildView(leading); 34 AddChildView(leading);
36 AddChildView(trailing); 35 AddChildView(trailing);
37 #if defined(OS_WIN) 36 #if defined(OS_WIN)
38 set_background( 37 set_background(
39 views::Background::CreateSolidBackground( 38 views::Background::CreateSolidBackground(
40 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)))); 39 skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE))));
41 #endif 40 #endif
42 } 41 }
43 42
44 void SingleSplitView::Layout() { 43 void SingleSplitView::Layout() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 int divider_size = 131 int divider_size =
133 !is_leading_visible || !is_trailing_visible ? 0 : kDividerSize; 132 !is_leading_visible || !is_trailing_visible ? 0 : kDividerSize;
134 133
135 if (is_horizontal_) { 134 if (is_horizontal_) {
136 *leading_bounds = gfx::Rect(0, 0, divider_at, bounds.height()); 135 *leading_bounds = gfx::Rect(0, 0, divider_at, bounds.height());
137 *trailing_bounds = 136 *trailing_bounds =
138 gfx::Rect(divider_at + divider_size, 0, 137 gfx::Rect(divider_at + divider_size, 0,
139 std::max(0, bounds.width() - divider_at - divider_size), 138 std::max(0, bounds.width() - divider_at - divider_size),
140 bounds.height()); 139 bounds.height());
141 } else { 140 } else {
142 *leading_bounds = gfx::Rect( 141 *leading_bounds = gfx::Rect(0, 0, bounds.width(), divider_at);
143 0, 0, bounds.width(), divider_at - leading_bottom_offset_);
144 *trailing_bounds = 142 *trailing_bounds =
145 gfx::Rect(0, divider_at + divider_size, bounds.width(), 143 gfx::Rect(0, divider_at + divider_size, bounds.width(),
146 std::max(0, bounds.height() - divider_at - divider_size)); 144 std::max(0, bounds.height() - divider_at - divider_size));
147 } 145 }
148 } 146 }
149 147
150 void SingleSplitView::SetAccessibleName(const string16& name) { 148 void SingleSplitView::SetAccessibleName(const string16& name) {
151 accessible_name_ = name; 149 accessible_name_ = name;
152 } 150 }
153 151
154 void SingleSplitView::SetLeadingBottomOffset(int offset) {
155 if (leading_bottom_offset_ == offset)
156 return;
157 leading_bottom_offset_ = offset;
158 InvalidateLayout();
159 }
160
161 bool SingleSplitView::OnMousePressed(const ui::MouseEvent& event) { 152 bool SingleSplitView::OnMousePressed(const ui::MouseEvent& event) {
162 if (!IsPointInDivider(event.location())) 153 if (!IsPointInDivider(event.location()))
163 return false; 154 return false;
164 drag_info_.initial_mouse_offset = GetPrimaryAxisSize(event.x(), event.y()); 155 drag_info_.initial_mouse_offset = GetPrimaryAxisSize(event.x(), event.y());
165 drag_info_.initial_divider_offset = 156 drag_info_.initial_divider_offset =
166 NormalizeDividerOffset(divider_offset_, bounds()); 157 NormalizeDividerOffset(divider_offset_, bounds());
167 return true; 158 return true;
168 } 159 }
169 160
170 bool SingleSplitView::OnMouseDragged(const ui::MouseEvent& event) { 161 bool SingleSplitView::OnMouseDragged(const ui::MouseEvent& event) {
171 if (child_count() < 2) 162 if (child_count() < 2)
172 return false; 163 return false;
173 164
174 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) - 165 int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) -
175 drag_info_.initial_mouse_offset; 166 drag_info_.initial_mouse_offset;
176 if (is_horizontal_ && base::i18n::IsRTL()) 167 if (is_horizontal_ && base::i18n::IsRTL())
177 delta_offset *= -1; 168 delta_offset *= -1;
178 // Honor the minimum size when resizing. 169 // Honor the minimum size when resizing.
179 gfx::Size min = child_at(0)->GetMinimumSize(); 170 gfx::Size min = child_at(0)->GetMinimumSize();
180 int new_size = std::max(GetPrimaryAxisSize(min.width(), 171 int new_size = std::max(GetPrimaryAxisSize(min.width(), min.height()),
181 min.height() + leading_bottom_offset_),
182 drag_info_.initial_divider_offset + delta_offset); 172 drag_info_.initial_divider_offset + delta_offset);
183 173
184 // And don't let the view get bigger than our width. 174 // And don't let the view get bigger than our width.
185 new_size = std::min(GetPrimaryAxisSize() - kDividerSize, new_size); 175 new_size = std::min(GetPrimaryAxisSize() - kDividerSize, new_size);
186 176
187 if (new_size != divider_offset_) { 177 if (new_size != divider_offset_) {
188 set_divider_offset(new_size); 178 set_divider_offset(new_size);
189 if (!listener_ || listener_->SplitHandleMoved(this)) 179 if (!listener_ || listener_->SplitHandleMoved(this))
190 Layout(); 180 Layout();
191 } 181 }
(...skipping 21 matching lines...) Expand all
213 return false; 203 return false;
214 204
215 if (!child_at(0)->visible() || !child_at(1)->visible()) 205 if (!child_at(0)->visible() || !child_at(1)->visible())
216 return false; 206 return false;
217 207
218 int divider_relative_offset; 208 int divider_relative_offset;
219 if (is_horizontal_) { 209 if (is_horizontal_) {
220 divider_relative_offset = 210 divider_relative_offset =
221 p.x() - child_at(base::i18n::IsRTL() ? 1 : 0)->width(); 211 p.x() - child_at(base::i18n::IsRTL() ? 1 : 0)->width();
222 } else { 212 } else {
223 divider_relative_offset = 213 divider_relative_offset = p.y() - child_at(0)->height();
224 p.y() - (child_at(0)->height() + leading_bottom_offset_);
225 } 214 }
226 return (divider_relative_offset >= 0 && 215 return (divider_relative_offset >= 0 &&
227 divider_relative_offset < kDividerSize); 216 divider_relative_offset < kDividerSize);
228 } 217 }
229 218
230 int SingleSplitView::CalculateDividerOffset( 219 int SingleSplitView::CalculateDividerOffset(
231 int divider_offset, 220 int divider_offset,
232 const gfx::Rect& previous_bounds, 221 const gfx::Rect& previous_bounds,
233 const gfx::Rect& new_bounds) const { 222 const gfx::Rect& new_bounds) const {
234 if (resize_leading_on_bounds_change_ && divider_offset != -1) { 223 if (resize_leading_on_bounds_change_ && divider_offset != -1) {
(...skipping 19 matching lines...) Expand all
254 const gfx::Rect& bounds) const { 243 const gfx::Rect& bounds) const {
255 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height()); 244 int primary_axis_size = GetPrimaryAxisSize(bounds.width(), bounds.height());
256 if (divider_offset < 0) 245 if (divider_offset < 0)
257 // primary_axis_size may < kDividerSize during initial layout. 246 // primary_axis_size may < kDividerSize during initial layout.
258 return std::max(0, (primary_axis_size - kDividerSize) / 2); 247 return std::max(0, (primary_axis_size - kDividerSize) / 2);
259 return std::min(divider_offset, 248 return std::min(divider_offset,
260 std::max(primary_axis_size - kDividerSize, 0)); 249 std::max(primary_axis_size - kDividerSize, 0));
261 } 250 }
262 251
263 } // namespace views 252 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/single_split_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698