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

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

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