| OLD | NEW |
| 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 Loading... |
| 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 SetHasFocusRing(true); |
| 634 } | 638 } |
| 635 | 639 |
| 636 void TreeView::OnBlur() { | 640 void TreeView::OnBlur() { |
| 637 if (GetInputMethod()) | 641 if (GetInputMethod()) |
| 638 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); | 642 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); |
| 639 SchedulePaintForNode(selected_node_); | 643 SchedulePaintForNode(selected_node_); |
| 640 if (selector_) | 644 if (selector_) |
| 641 selector_->OnViewBlur(); | 645 selector_->OnViewBlur(); |
| 646 SetHasFocusRing(false); |
| 642 } | 647 } |
| 643 | 648 |
| 644 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { | 649 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { |
| 645 CommitEdit(); | 650 CommitEdit(); |
| 646 RequestFocus(); | 651 RequestFocus(); |
| 647 | 652 |
| 648 InternalNode* node = GetNodeAtPoint(event.location()); | 653 InternalNode* node = GetNodeAtPoint(event.location()); |
| 649 if (!node) | 654 if (!node) |
| 650 return true; | 655 return true; |
| 651 | 656 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 | 1055 |
| 1051 int arrow_dx = depth * kIndent + kHorizontalInset; | 1056 int arrow_dx = depth * kIndent + kHorizontalInset; |
| 1052 gfx::Rect arrow_bounds(bounds().x() + arrow_dx, | 1057 gfx::Rect arrow_bounds(bounds().x() + arrow_dx, |
| 1053 row * row_height_ + kVerticalInset, kArrowRegionSize, | 1058 row * row_height_ + kVerticalInset, kArrowRegionSize, |
| 1054 row_height_); | 1059 row_height_); |
| 1055 if (base::i18n::IsRTL()) | 1060 if (base::i18n::IsRTL()) |
| 1056 arrow_bounds.set_x(bounds().width() - arrow_dx - kArrowRegionSize); | 1061 arrow_bounds.set_x(bounds().width() - arrow_dx - kArrowRegionSize); |
| 1057 return arrow_bounds.Contains(point); | 1062 return arrow_bounds.Contains(point); |
| 1058 } | 1063 } |
| 1059 | 1064 |
| 1065 void TreeView::SetHasFocusRing(bool shows) { |
| 1066 if (!ui::MaterialDesignController::IsSecondaryUiMaterial() || |
| 1067 !PlatformStyle::kTreeViewHasFocusRing) { |
| 1068 return; |
| 1069 } |
| 1070 // If this View is the grandchild of a ScrollView, use the grandparent |
| 1071 // ScrollView for the focus ring instead of this View so that the focus ring |
| 1072 // won't be scrolled. Since ScrollViews have a single content view, which they |
| 1073 // wrap in a ScrollView::Viewport, being the grandchild of a ScrollView |
| 1074 // implies being the sole grandchild, which means it's fine to wrap the focus |
| 1075 // ring around the grandparent here. |
| 1076 View* grandparent = parent() ? parent()->parent() : nullptr; |
| 1077 if (grandparent && grandparent->GetClassName() == ScrollView::kViewClassName) |
| 1078 static_cast<ScrollView*>(grandparent)->SetHasFocusRing(shows); |
| 1079 } |
| 1080 |
| 1060 // InternalNode ---------------------------------------------------------------- | 1081 // InternalNode ---------------------------------------------------------------- |
| 1061 | 1082 |
| 1062 TreeView::InternalNode::InternalNode() | 1083 TreeView::InternalNode::InternalNode() |
| 1063 : model_node_(NULL), | 1084 : model_node_(NULL), |
| 1064 loaded_children_(false), | 1085 loaded_children_(false), |
| 1065 is_expanded_(false), | 1086 is_expanded_(false), |
| 1066 text_width_(0) { | 1087 text_width_(0) { |
| 1067 } | 1088 } |
| 1068 | 1089 |
| 1069 TreeView::InternalNode::~InternalNode() { | 1090 TreeView::InternalNode::~InternalNode() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1090 if (!is_expanded_) | 1111 if (!is_expanded_) |
| 1091 return max_width; | 1112 return max_width; |
| 1092 for (int i = 0; i < child_count(); ++i) { | 1113 for (int i = 0; i < child_count(); ++i) { |
| 1093 max_width = std::max(max_width, | 1114 max_width = std::max(max_width, |
| 1094 GetChild(i)->GetMaxWidth(indent, depth + 1)); | 1115 GetChild(i)->GetMaxWidth(indent, depth + 1)); |
| 1095 } | 1116 } |
| 1096 return max_width; | 1117 return max_width; |
| 1097 } | 1118 } |
| 1098 | 1119 |
| 1099 } // namespace views | 1120 } // namespace views |
| OLD | NEW |