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

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

Issue 2411693002: views: add focus ring to TreeView (Closed)
Patch Set: Only do focus rings in Harmony mode 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
« no previous file with comments | « ui/views/controls/tree/tree_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/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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "ui/accessibility/ax_view_state.h" 12 #include "ui/accessibility/ax_view_state.h"
13 #include "ui/base/ime/input_method.h" 13 #include "ui/base/ime/input_method.h"
14 #include "ui/base/material_design/material_design_controller.h"
14 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/events/event.h" 16 #include "ui/events/event.h"
16 #include "ui/events/keycodes/keyboard_codes.h" 17 #include "ui/events/keycodes/keyboard_codes.h"
17 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/geometry/rect.h" 19 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/rect_conversions.h" 20 #include "ui/gfx/geometry/rect_conversions.h"
20 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
21 #include "ui/gfx/skia_util.h" 22 #include "ui/gfx/skia_util.h"
22 #include "ui/native_theme/native_theme.h" 23 #include "ui/native_theme/native_theme.h"
23 #include "ui/resources/grit/ui_resources.h" 24 #include "ui/resources/grit/ui_resources.h"
25 #include "ui/views/controls/focus_ring.h"
24 #include "ui/views/controls/prefix_selector.h" 26 #include "ui/views/controls/prefix_selector.h"
25 #include "ui/views/controls/scroll_view.h" 27 #include "ui/views/controls/scroll_view.h"
26 #include "ui/views/controls/textfield/textfield.h" 28 #include "ui/views/controls/textfield/textfield.h"
27 #include "ui/views/controls/tree/tree_view_controller.h" 29 #include "ui/views/controls/tree/tree_view_controller.h"
28 #include "ui/views/resources/grit/views_resources.h" 30 #include "ui/views/resources/grit/views_resources.h"
29 #include "ui/views/style/platform_style.h" 31 #include "ui/views/style/platform_style.h"
30 32
31 using ui::TreeModel; 33 using ui::TreeModel;
32 using ui::TreeModelNode; 34 using ui::TreeModelNode;
33 35
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 626
625 void TreeView::OnFocus() { 627 void TreeView::OnFocus() {
626 if (GetInputMethod()) 628 if (GetInputMethod())
627 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector()); 629 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector());
628 View::OnFocus(); 630 View::OnFocus();
629 SchedulePaintForNode(selected_node_); 631 SchedulePaintForNode(selected_node_);
630 632
631 // Notify the InputMethod so that it knows to query the TextInputClient. 633 // Notify the InputMethod so that it knows to query the TextInputClient.
632 if (GetInputMethod()) 634 if (GetInputMethod())
633 GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector()); 635 GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector());
636
637 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
638 View* focus_ring_view = FindFocusRingView();
639 FocusRing::Install(focus_ring_view);
640 focus_ring_view->SchedulePaint();
641 }
634 } 642 }
635 643
636 void TreeView::OnBlur() { 644 void TreeView::OnBlur() {
637 if (GetInputMethod()) 645 if (GetInputMethod())
638 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); 646 GetInputMethod()->DetachTextInputClient(GetPrefixSelector());
639 SchedulePaintForNode(selected_node_); 647 SchedulePaintForNode(selected_node_);
640 if (selector_) 648 if (selector_)
641 selector_->OnViewBlur(); 649 selector_->OnViewBlur();
650 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
651 View* focus_ring_view = FindFocusRingView();
652 FocusRing::Uninstall(focus_ring_view);
653 focus_ring_view->SchedulePaint();
654 }
642 } 655 }
643 656
644 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { 657 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) {
645 CommitEdit(); 658 CommitEdit();
646 RequestFocus(); 659 RequestFocus();
647 660
648 InternalNode* node = GetNodeAtPoint(event.location()); 661 InternalNode* node = GetNodeAtPoint(event.location());
649 if (!node) 662 if (!node)
650 return true; 663 return true;
651 664
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 1063
1051 int arrow_dx = depth * kIndent + kHorizontalInset; 1064 int arrow_dx = depth * kIndent + kHorizontalInset;
1052 gfx::Rect arrow_bounds(bounds().x() + arrow_dx, 1065 gfx::Rect arrow_bounds(bounds().x() + arrow_dx,
1053 row * row_height_ + kVerticalInset, kArrowRegionSize, 1066 row * row_height_ + kVerticalInset, kArrowRegionSize,
1054 row_height_); 1067 row_height_);
1055 if (base::i18n::IsRTL()) 1068 if (base::i18n::IsRTL())
1056 arrow_bounds.set_x(bounds().width() - arrow_dx - kArrowRegionSize); 1069 arrow_bounds.set_x(bounds().width() - arrow_dx - kArrowRegionSize);
1057 return arrow_bounds.Contains(point); 1070 return arrow_bounds.Contains(point);
1058 } 1071 }
1059 1072
1073 View* TreeView::FindFocusRingView() {
1074 // If this View is the grandchild of a ScrollView, use the grandparent
1075 // ScrollView for the focus ring instead of this View so that the focus ring
1076 // won't be scrolled. Otherwise, fall back to using this View. Since
1077 // ScrollViews have a single content view, which they wrap in a
1078 // ScrollView::Viewport, being the grandchild of a ScrollView implies being
1079 // the sole grandchild, which means it's fine to wrap the focus ring around
1080 // the grandparent here.
1081 View* grandparent = parent() ? parent()->parent() : nullptr;
1082 if (grandparent && grandparent->GetClassName() == ScrollView::kViewClassName)
sky 2016/10/11 18:17:15 Did you verify we want this behavior everywhere? O
1083 return grandparent;
1084 return this;
1085 }
1086
1060 // InternalNode ---------------------------------------------------------------- 1087 // InternalNode ----------------------------------------------------------------
1061 1088
1062 TreeView::InternalNode::InternalNode() 1089 TreeView::InternalNode::InternalNode()
1063 : model_node_(NULL), 1090 : model_node_(NULL),
1064 loaded_children_(false), 1091 loaded_children_(false),
1065 is_expanded_(false), 1092 is_expanded_(false),
1066 text_width_(0) { 1093 text_width_(0) {
1067 } 1094 }
1068 1095
1069 TreeView::InternalNode::~InternalNode() { 1096 TreeView::InternalNode::~InternalNode() {
(...skipping 20 matching lines...) Expand all
1090 if (!is_expanded_) 1117 if (!is_expanded_)
1091 return max_width; 1118 return max_width;
1092 for (int i = 0; i < child_count(); ++i) { 1119 for (int i = 0; i < child_count(); ++i) {
1093 max_width = std::max(max_width, 1120 max_width = std::max(max_width,
1094 GetChild(i)->GetMaxWidth(indent, depth + 1)); 1121 GetChild(i)->GetMaxWidth(indent, depth + 1));
1095 } 1122 }
1096 return max_width; 1123 return max_width;
1097 } 1124 }
1098 1125
1099 } // namespace views 1126 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/tree/tree_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698