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

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

Issue 2715813002: Change focus indicator for TableView and TreeView. (Closed)
Patch Set: rename Created 3 years, 9 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 | « ui/views/controls/scroll_view.h ('k') | ui/views/controls/table/table_view.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/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/base/material_design/material_design_controller.h"
10 #include "ui/events/event.h" 11 #include "ui/events/event.h"
11 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
12 #include "ui/native_theme/native_theme.h" 13 #include "ui/native_theme/native_theme.h"
13 #include "ui/views/background.h" 14 #include "ui/views/background.h"
14 #include "ui/views/border.h" 15 #include "ui/views/border.h"
15 #include "ui/views/controls/focus_ring.h" 16 #include "ui/views/controls/focus_ring.h"
16 #include "ui/views/style/platform_style.h" 17 #include "ui/views/style/platform_style.h"
17 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
18 19
19 namespace views { 20 namespace views {
20 21
21 const char ScrollView::kViewClassName[] = "ScrollView"; 22 const char ScrollView::kViewClassName[] = "ScrollView";
22 23
23 namespace { 24 namespace {
24 25
25 const base::Feature kToolkitViewsScrollWithLayers { 26 const base::Feature kToolkitViewsScrollWithLayers {
26 "ToolkitViewsScrollWithLayers", 27 "ToolkitViewsScrollWithLayers",
27 #if defined(OS_MACOSX) 28 #if defined(OS_MACOSX)
28 base::FEATURE_ENABLED_BY_DEFAULT 29 base::FEATURE_ENABLED_BY_DEFAULT
29 #else 30 #else
30 base::FEATURE_DISABLED_BY_DEFAULT 31 base::FEATURE_DISABLED_BY_DEFAULT
31 #endif 32 #endif
32 }; 33 };
33 34
34 // Subclass of ScrollView that resets the border when the theme changes. 35 class ScrollCornerView : public View {
35 class ScrollViewWithBorder : public views::ScrollView {
36 public:
37 ScrollViewWithBorder() {}
38
39 // View overrides;
40 void OnNativeThemeChanged(const ui::NativeTheme* theme) override {
41 SetBorder(CreateSolidBorder(
42 1,
43 theme->GetSystemColor(ui::NativeTheme::kColorId_UnfocusedBorderColor)));
44 }
45
46 private:
47 DISALLOW_COPY_AND_ASSIGN(ScrollViewWithBorder);
48 };
49
50 class ScrollCornerView : public views::View {
51 public: 36 public:
52 ScrollCornerView() {} 37 ScrollCornerView() {}
53 38
54 void OnPaint(gfx::Canvas* canvas) override { 39 void OnPaint(gfx::Canvas* canvas) override {
55 ui::NativeTheme::ExtraParams ignored; 40 ui::NativeTheme::ExtraParams ignored;
56 GetNativeTheme()->Paint(canvas->sk_canvas(), 41 GetNativeTheme()->Paint(canvas->sk_canvas(),
57 ui::NativeTheme::kScrollbarCorner, 42 ui::NativeTheme::kScrollbarCorner,
58 ui::NativeTheme::kNormal, 43 ui::NativeTheme::kNormal,
59 GetLocalBounds(), 44 GetLocalBounds(),
60 ignored); 45 ignored);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 ScrollView::~ScrollView() { 174 ScrollView::~ScrollView() {
190 // The scrollbars may not have been added, delete them to ensure they get 175 // The scrollbars may not have been added, delete them to ensure they get
191 // deleted. 176 // deleted.
192 delete horiz_sb_; 177 delete horiz_sb_;
193 delete vert_sb_; 178 delete vert_sb_;
194 delete corner_view_; 179 delete corner_view_;
195 } 180 }
196 181
197 // static 182 // static
198 ScrollView* ScrollView::CreateScrollViewWithBorder() { 183 ScrollView* ScrollView::CreateScrollViewWithBorder() {
199 return new ScrollViewWithBorder(); 184 auto scroll_view = new ScrollView();
185 scroll_view->AddBorder();
186 return scroll_view;
187 }
188
189 // static
190 ScrollView* ScrollView::GetScrollViewForContents(View* contents) {
191 View* grandparent =
192 contents->parent() ? contents->parent()->parent() : nullptr;
193 if (!grandparent || grandparent->GetClassName() != ScrollView::kViewClassName)
194 return nullptr;
195
196 auto scroll_view = static_cast<ScrollView*>(grandparent);
197 DCHECK_EQ(contents, scroll_view->contents());
198 return scroll_view;
200 } 199 }
201 200
202 void ScrollView::SetContents(View* a_view) { 201 void ScrollView::SetContents(View* a_view) {
203 // Protect against clients passing a contents view that has its own Layer. 202 // Protect against clients passing a contents view that has its own Layer.
204 DCHECK(!a_view->layer()); 203 DCHECK(!a_view->layer());
205 if (ScrollsWithLayers()) { 204 if (ScrollsWithLayers()) {
206 if (!a_view->background() && background_color_ != SK_ColorTRANSPARENT) { 205 if (!a_view->background() && background_color_ != SK_ColorTRANSPARENT) {
207 a_view->set_background( 206 a_view->set_background(
208 Background::CreateSolidBackground(background_color_)); 207 Background::CreateSolidBackground(background_color_));
209 } 208 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 261 }
263 262
264 void ScrollView::SetVerticalScrollBar(ScrollBar* vert_sb) { 263 void ScrollView::SetVerticalScrollBar(ScrollBar* vert_sb) {
265 DCHECK(vert_sb); 264 DCHECK(vert_sb);
266 vert_sb->SetVisible(vert_sb_->visible()); 265 vert_sb->SetVisible(vert_sb_->visible());
267 delete vert_sb_; 266 delete vert_sb_;
268 vert_sb->set_controller(this); 267 vert_sb->set_controller(this);
269 vert_sb_ = vert_sb; 268 vert_sb_ = vert_sb;
270 } 269 }
271 270
272 void ScrollView::SetHasFocusRing(bool has_focus_ring) { 271 void ScrollView::SetHasFocusIndicator(bool has_focus_indicator) {
273 if (has_focus_ring == (focus_ring_ != nullptr)) 272 if (has_focus_indicator == draw_focus_indicator_)
274 return; 273 return;
275 if (has_focus_ring) { 274 draw_focus_indicator_ = has_focus_indicator;
276 focus_ring_ = FocusRing::Install(this); 275
276 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
277 DCHECK_EQ(draw_focus_indicator_, !focus_ring_);
278 if (has_focus_indicator) {
279 focus_ring_ = FocusRing::Install(this);
280 } else {
281 FocusRing::Uninstall(this);
282 focus_ring_ = nullptr;
283 }
277 } else { 284 } else {
278 FocusRing::Uninstall(this); 285 UpdateBorder();
279 focus_ring_ = nullptr;
280 } 286 }
281 SchedulePaint(); 287 SchedulePaint();
282 } 288 }
283 289
284 gfx::Size ScrollView::GetPreferredSize() const { 290 gfx::Size ScrollView::GetPreferredSize() const {
285 if (!is_bounded()) 291 if (!is_bounded())
286 return View::GetPreferredSize(); 292 return View::GetPreferredSize();
287 293
288 gfx::Size size = contents_->GetPreferredSize(); 294 gfx::Size size = contents_->GetPreferredSize();
289 size.SetToMax(gfx::Size(size.width(), min_height_)); 295 size.SetToMax(gfx::Size(size.width(), min_height_));
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if (!event->handled() && horiz_sb_->visible()) { 516 if (!event->handled() && horiz_sb_->visible()) {
511 if (horiz_sb_->bounds().Contains(event->location()) || scroll_event) 517 if (horiz_sb_->bounds().Contains(event->location()) || scroll_event)
512 horiz_sb_->OnGestureEvent(event); 518 horiz_sb_->OnGestureEvent(event);
513 } 519 }
514 } 520 }
515 521
516 const char* ScrollView::GetClassName() const { 522 const char* ScrollView::GetClassName() const {
517 return kViewClassName; 523 return kViewClassName;
518 } 524 }
519 525
526 void ScrollView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
527 UpdateBorder();
528 }
529
520 void ScrollView::ScrollToPosition(ScrollBar* source, int position) { 530 void ScrollView::ScrollToPosition(ScrollBar* source, int position) {
521 if (!contents_) 531 if (!contents_)
522 return; 532 return;
523 533
524 gfx::ScrollOffset offset = CurrentOffset(); 534 gfx::ScrollOffset offset = CurrentOffset();
525 if (source == horiz_sb_ && horiz_sb_->visible()) { 535 if (source == horiz_sb_ && horiz_sb_->visible()) {
526 position = AdjustPosition(offset.x(), position, contents_->width(), 536 position = AdjustPosition(offset.x(), position, contents_->width(),
527 contents_viewport_->width()); 537 contents_viewport_->width());
528 if (offset.x() == position) 538 if (offset.x() == position)
529 return; 539 return;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 if (!header_) 739 if (!header_)
730 return; 740 return;
731 741
732 int x_offset = CurrentOffset().x(); 742 int x_offset = CurrentOffset().x();
733 if (header_->x() != -x_offset) { 743 if (header_->x() != -x_offset) {
734 header_->SetX(-x_offset); 744 header_->SetX(-x_offset);
735 header_->SchedulePaintInRect(header_->GetVisibleBounds()); 745 header_->SchedulePaintInRect(header_->GetVisibleBounds());
736 } 746 }
737 } 747 }
738 748
749 void ScrollView::AddBorder() {
750 draw_border_ = true;
751 UpdateBorder();
752 }
753
754 void ScrollView::UpdateBorder() {
755 if (!draw_border_ || !GetWidget())
756 return;
757
758 SetBorder(CreateSolidBorder(
759 1,
760 GetNativeTheme()->GetSystemColor(
761 draw_focus_indicator_
762 ? ui::NativeTheme::kColorId_FocusedBorderColor
763 : ui::NativeTheme::kColorId_UnfocusedBorderColor)));
764 }
765
739 // VariableRowHeightScrollHelper ---------------------------------------------- 766 // VariableRowHeightScrollHelper ----------------------------------------------
740 767
741 VariableRowHeightScrollHelper::VariableRowHeightScrollHelper( 768 VariableRowHeightScrollHelper::VariableRowHeightScrollHelper(
742 Controller* controller) : controller_(controller) { 769 Controller* controller) : controller_(controller) {
743 } 770 }
744 771
745 VariableRowHeightScrollHelper::~VariableRowHeightScrollHelper() { 772 VariableRowHeightScrollHelper::~VariableRowHeightScrollHelper() {
746 } 773 }
747 774
748 int VariableRowHeightScrollHelper::GetPageScrollIncrement( 775 int VariableRowHeightScrollHelper::GetPageScrollIncrement(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 830
804 VariableRowHeightScrollHelper::RowInfo 831 VariableRowHeightScrollHelper::RowInfo
805 FixedRowHeightScrollHelper::GetRowInfo(int y) { 832 FixedRowHeightScrollHelper::GetRowInfo(int y) {
806 if (y < top_margin_) 833 if (y < top_margin_)
807 return RowInfo(0, top_margin_); 834 return RowInfo(0, top_margin_);
808 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, 835 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_,
809 row_height_); 836 row_height_);
810 } 837 }
811 838
812 } // namespace views 839 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/scroll_view.h ('k') | ui/views/controls/table/table_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698