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

Side by Side Diff: ui/views/controls/tree/tree_view.cc

Issue 2715813002: Change focus indicator for TableView and TreeView. (Closed)
Patch Set: rename Created 3 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 | « ui/views/controls/tree/tree_view.h ('k') | ui/views/style/platform_style.h » ('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/tree/tree_view.h" 5 #include "ui/views/controls/tree/tree_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 void TreeView::OnFocus() { 631 void TreeView::OnFocus() {
632 if (GetInputMethod()) 632 if (GetInputMethod())
633 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector()); 633 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector());
634 View::OnFocus(); 634 View::OnFocus();
635 SchedulePaintForNode(selected_node_); 635 SchedulePaintForNode(selected_node_);
636 636
637 // Notify the InputMethod so that it knows to query the TextInputClient. 637 // Notify the InputMethod so that it knows to query the TextInputClient.
638 if (GetInputMethod()) 638 if (GetInputMethod())
639 GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector()); 639 GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector());
640 640
641 SetHasFocusRing(true); 641 SetHasFocusIndicator(true);
642 } 642 }
643 643
644 void TreeView::OnBlur() { 644 void TreeView::OnBlur() {
645 if (GetInputMethod()) 645 if (GetInputMethod())
646 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); 646 GetInputMethod()->DetachTextInputClient(GetPrefixSelector());
647 SchedulePaintForNode(selected_node_); 647 SchedulePaintForNode(selected_node_);
648 if (selector_) 648 if (selector_)
649 selector_->OnViewBlur(); 649 selector_->OnViewBlur();
650 SetHasFocusRing(false); 650 SetHasFocusIndicator(false);
651 } 651 }
652 652
653 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { 653 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) {
654 CommitEdit(); 654 CommitEdit();
655 RequestFocus(); 655 RequestFocus();
656 656
657 InternalNode* node = GetNodeAtPoint(event.location()); 657 InternalNode* node = GetNodeAtPoint(event.location());
658 if (!node) 658 if (!node)
659 return true; 659 return true;
660 660
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 return; 800 return;
801 801
802 gfx::Rect text_bounds(GetTextBoundsForNode(node)); 802 gfx::Rect text_bounds(GetTextBoundsForNode(node));
803 if (base::i18n::IsRTL()) 803 if (base::i18n::IsRTL())
804 text_bounds.set_x(bounds.x()); 804 text_bounds.set_x(bounds.x());
805 805
806 // Paint the background on the selected row. 806 // Paint the background on the selected row.
807 if (!PlatformStyle::kTreeViewSelectionPaintsEntireRow && 807 if (!PlatformStyle::kTreeViewSelectionPaintsEntireRow &&
808 node == selected_node_) { 808 node == selected_node_) {
809 canvas->FillRect(text_bounds, selected_row_bg_color); 809 canvas->FillRect(text_bounds, selected_row_bg_color);
810 if (HasFocus())
811 canvas->DrawFocusRect(text_bounds);
812 } 810 }
813 811
814 // Paint the text. 812 // Paint the text.
815 const ui::NativeTheme::ColorId color_id = 813 const ui::NativeTheme::ColorId color_id =
816 text_color_id(HasFocus(), node == selected_node_); 814 text_color_id(HasFocus(), node == selected_node_);
817 const gfx::Rect internal_bounds( 815 const gfx::Rect internal_bounds(
818 text_bounds.x() + kTextHorizontalPadding, 816 text_bounds.x() + kTextHorizontalPadding,
819 text_bounds.y() + kTextVerticalPadding, 817 text_bounds.y() + kTextVerticalPadding,
820 text_bounds.width() - kTextHorizontalPadding * 2, 818 text_bounds.width() - kTextHorizontalPadding * 2,
821 text_bounds.height() - kTextVerticalPadding * 2); 819 text_bounds.height() - kTextVerticalPadding * 2);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 1048
1051 int arrow_dx = depth * kIndent + kHorizontalInset; 1049 int arrow_dx = depth * kIndent + kHorizontalInset;
1052 gfx::Rect arrow_bounds(bounds().x() + arrow_dx, 1050 gfx::Rect arrow_bounds(bounds().x() + arrow_dx,
1053 row * row_height_ + kVerticalInset, kArrowRegionSize, 1051 row * row_height_ + kVerticalInset, kArrowRegionSize,
1054 row_height_); 1052 row_height_);
1055 if (base::i18n::IsRTL()) 1053 if (base::i18n::IsRTL())
1056 arrow_bounds.set_x(bounds().width() - arrow_dx - kArrowRegionSize); 1054 arrow_bounds.set_x(bounds().width() - arrow_dx - kArrowRegionSize);
1057 return arrow_bounds.Contains(point); 1055 return arrow_bounds.Contains(point);
1058 } 1056 }
1059 1057
1060 void TreeView::SetHasFocusRing(bool shows) { 1058 void TreeView::SetHasFocusIndicator(bool shows) {
1061 if (!ui::MaterialDesignController::IsSecondaryUiMaterial() ||
1062 !PlatformStyle::kTreeViewHasFocusRing) {
1063 return;
1064 }
1065 // If this View is the grandchild of a ScrollView, use the grandparent 1059 // If this View is the grandchild of a ScrollView, use the grandparent
1066 // ScrollView for the focus ring instead of this View so that the focus ring 1060 // ScrollView for the focus ring instead of this View so that the focus ring
1067 // won't be scrolled. Since ScrollViews have a single content view, which they 1061 // won't be scrolled.
1068 // wrap in a ScrollView::Viewport, being the grandchild of a ScrollView 1062 ScrollView* scroll_view = ScrollView::GetScrollViewForContents(this);
1069 // implies being the sole grandchild, which means it's fine to wrap the focus 1063 if (scroll_view)
1070 // ring around the grandparent here. 1064 scroll_view->SetHasFocusIndicator(shows);
1071 View* grandparent = parent() ? parent()->parent() : nullptr;
1072 if (grandparent && grandparent->GetClassName() == ScrollView::kViewClassName)
1073 static_cast<ScrollView*>(grandparent)->SetHasFocusRing(shows);
1074 } 1065 }
1075 1066
1076 // InternalNode ---------------------------------------------------------------- 1067 // InternalNode ----------------------------------------------------------------
1077 1068
1078 TreeView::InternalNode::InternalNode() 1069 TreeView::InternalNode::InternalNode()
1079 : model_node_(NULL), 1070 : model_node_(NULL),
1080 loaded_children_(false), 1071 loaded_children_(false),
1081 is_expanded_(false), 1072 is_expanded_(false),
1082 text_width_(0) { 1073 text_width_(0) {
1083 } 1074 }
(...skipping 22 matching lines...) Expand all
1106 if (!is_expanded_) 1097 if (!is_expanded_)
1107 return max_width; 1098 return max_width;
1108 for (int i = 0; i < child_count(); ++i) { 1099 for (int i = 0; i < child_count(); ++i) {
1109 max_width = std::max(max_width, 1100 max_width = std::max(max_width,
1110 GetChild(i)->GetMaxWidth(indent, depth + 1)); 1101 GetChild(i)->GetMaxWidth(indent, depth + 1));
1111 } 1102 }
1112 return max_width; 1103 return max_width;
1113 } 1104 }
1114 1105
1115 } // namespace views 1106 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/tree/tree_view.h ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698