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

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

Issue 2411693002: views: add focus ring to TreeView (Closed)
Patch Set: move FocusRing support into ScrollView Created 4 years, 2 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
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/scroll_view.h" 5 #include "ui/views/controls/scroll_view.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "ui/events/event.h" 10 #include "ui/events/event.h"
11 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 #include "ui/native_theme/native_theme.h" 12 #include "ui/native_theme/native_theme.h"
13 #include "ui/views/background.h" 13 #include "ui/views/background.h"
14 #include "ui/views/border.h" 14 #include "ui/views/border.h"
15 #include "ui/views/controls/focus_ring.h"
15 #include "ui/views/style/platform_style.h" 16 #include "ui/views/style/platform_style.h"
16 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
17 18
18 namespace views { 19 namespace views {
19 20
20 const char ScrollView::kViewClassName[] = "ScrollView"; 21 const char ScrollView::kViewClassName[] = "ScrollView";
21 22
22 namespace { 23 namespace {
23 24
24 const base::Feature kToolkitViewsScrollWithLayers { 25 const base::Feature kToolkitViewsScrollWithLayers {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 265 }
265 266
266 void ScrollView::SetVerticalScrollBar(ScrollBar* vert_sb) { 267 void ScrollView::SetVerticalScrollBar(ScrollBar* vert_sb) {
267 DCHECK(vert_sb); 268 DCHECK(vert_sb);
268 vert_sb->SetVisible(vert_sb_->visible()); 269 vert_sb->SetVisible(vert_sb_->visible());
269 delete vert_sb_; 270 delete vert_sb_;
270 vert_sb->set_controller(this); 271 vert_sb->set_controller(this);
271 vert_sb_ = vert_sb; 272 vert_sb_ = vert_sb;
272 } 273 }
273 274
275 void ScrollView::SetHasFocusRing(bool has_focus_ring) {
276 if (has_focus_ring == bool(focus_ring_))
sky 2016/10/12 23:58:01 Why not just focus_ring_?
Elly Fong-Jones 2016/10/13 11:14:56 It doesn't compile: ../../ui/views/controls/scrol
sky 2016/10/13 17:39:45 My mistake.
277 return;
278 if (has_focus_ring) {
279 focus_ring_ = new FocusRing;
280 AddChildView(focus_ring_);
281 focus_ring_->Layout();
282 } else {
283 delete focus_ring_;
284 focus_ring_ = nullptr;
285 }
286 }
287
274 gfx::Size ScrollView::GetPreferredSize() const { 288 gfx::Size ScrollView::GetPreferredSize() const {
275 if (!is_bounded()) 289 if (!is_bounded())
276 return View::GetPreferredSize(); 290 return View::GetPreferredSize();
277 291
278 gfx::Size size = contents()->GetPreferredSize(); 292 gfx::Size size = contents()->GetPreferredSize();
279 size.SetToMax(gfx::Size(size.width(), min_height_)); 293 size.SetToMax(gfx::Size(size.width(), min_height_));
280 size.SetToMin(gfx::Size(size.width(), max_height_)); 294 size.SetToMin(gfx::Size(size.width(), max_height_));
281 gfx::Insets insets = GetInsets(); 295 gfx::Insets insets = GetInsets();
282 size.Enlarge(insets.width(), insets.height()); 296 size.Enlarge(insets.width(), insets.height());
283 return size; 297 return size;
284 } 298 }
285 299
286 int ScrollView::GetHeightForWidth(int width) const { 300 int ScrollView::GetHeightForWidth(int width) const {
287 if (!is_bounded()) 301 if (!is_bounded())
288 return View::GetHeightForWidth(width); 302 return View::GetHeightForWidth(width);
289 303
290 gfx::Insets insets = GetInsets(); 304 gfx::Insets insets = GetInsets();
291 width = std::max(0, width - insets.width()); 305 width = std::max(0, width - insets.width());
292 int height = contents()->GetHeightForWidth(width) + insets.height(); 306 int height = contents()->GetHeightForWidth(width) + insets.height();
293 return std::min(std::max(height, min_height_), max_height_); 307 return std::min(std::max(height, min_height_), max_height_);
294 } 308 }
295 309
296 void ScrollView::Layout() { 310 void ScrollView::Layout() {
311 if (focus_ring_)
312 focus_ring_->Layout();
313
297 gfx::Rect available_rect = GetContentsBounds(); 314 gfx::Rect available_rect = GetContentsBounds();
298 if (is_bounded()) { 315 if (is_bounded()) {
299 int content_width = available_rect.width(); 316 int content_width = available_rect.width();
300 int content_height = contents()->GetHeightForWidth(content_width); 317 int content_height = contents()->GetHeightForWidth(content_width);
301 if (content_height > height()) { 318 if (content_height > height()) {
302 content_width = std::max(content_width - GetScrollBarWidth(), 0); 319 content_width = std::max(content_width - GetScrollBarWidth(), 0);
303 content_height = contents()->GetHeightForWidth(content_width); 320 content_height = contents()->GetHeightForWidth(content_width);
304 } 321 }
305 if (contents()->bounds().size() != gfx::Size(content_width, content_height)) 322 if (contents()->bounds().size() != gfx::Size(content_width, content_height))
306 contents()->SetBounds(0, 0, content_width, content_height); 323 contents()->SetBounds(0, 0, content_width, content_height);
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 783
767 VariableRowHeightScrollHelper::RowInfo 784 VariableRowHeightScrollHelper::RowInfo
768 FixedRowHeightScrollHelper::GetRowInfo(int y) { 785 FixedRowHeightScrollHelper::GetRowInfo(int y) {
769 if (y < top_margin_) 786 if (y < top_margin_)
770 return RowInfo(0, top_margin_); 787 return RowInfo(0, top_margin_);
771 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, 788 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_,
772 row_height_); 789 row_height_);
773 } 790 }
774 791
775 } // namespace views 792 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698