Chromium Code Reviews| Index: ui/views/controls/tree/tree_view.cc |
| diff --git a/ui/views/controls/tree/tree_view.cc b/ui/views/controls/tree/tree_view.cc |
| index a87875e7870ddb7af5c099fcd3f9a917d7d549a1..42a34bf4ab09608e4cb5c22578199d3a0d7c447b 100644 |
| --- a/ui/views/controls/tree/tree_view.cc |
| +++ b/ui/views/controls/tree/tree_view.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/message_loop/message_loop.h" |
| #include "ui/accessibility/ax_view_state.h" |
| #include "ui/base/ime/input_method.h" |
| +#include "ui/base/material_design/material_design_controller.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/events/event.h" |
| #include "ui/events/keycodes/keyboard_codes.h" |
| @@ -21,6 +22,7 @@ |
| #include "ui/gfx/skia_util.h" |
| #include "ui/native_theme/native_theme.h" |
| #include "ui/resources/grit/ui_resources.h" |
| +#include "ui/views/controls/focus_ring.h" |
| #include "ui/views/controls/prefix_selector.h" |
| #include "ui/views/controls/scroll_view.h" |
| #include "ui/views/controls/textfield/textfield.h" |
| @@ -631,6 +633,12 @@ void TreeView::OnFocus() { |
| // Notify the InputMethod so that it knows to query the TextInputClient. |
| if (GetInputMethod()) |
| GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector()); |
| + |
| + if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| + View* focus_ring_view = FindFocusRingView(); |
| + FocusRing::Install(focus_ring_view); |
| + focus_ring_view->SchedulePaint(); |
| + } |
| } |
| void TreeView::OnBlur() { |
| @@ -639,6 +647,11 @@ void TreeView::OnBlur() { |
| SchedulePaintForNode(selected_node_); |
| if (selector_) |
| selector_->OnViewBlur(); |
| + if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| + View* focus_ring_view = FindFocusRingView(); |
| + FocusRing::Uninstall(focus_ring_view); |
| + focus_ring_view->SchedulePaint(); |
| + } |
| } |
| bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { |
| @@ -1057,6 +1070,20 @@ bool TreeView::IsPointInExpandControl(InternalNode* node, |
| return arrow_bounds.Contains(point); |
| } |
| +View* TreeView::FindFocusRingView() { |
| + // If this View is the grandchild of a ScrollView, use the grandparent |
| + // ScrollView for the focus ring instead of this View so that the focus ring |
| + // won't be scrolled. Otherwise, fall back to using this View. Since |
| + // ScrollViews have a single content view, which they wrap in a |
| + // ScrollView::Viewport, being the grandchild of a ScrollView implies being |
| + // the sole grandchild, which means it's fine to wrap the focus ring around |
| + // the grandparent here. |
| + View* grandparent = parent() ? parent()->parent() : nullptr; |
| + if (grandparent && grandparent->GetClassName() == ScrollView::kViewClassName) |
|
sky
2016/10/11 18:17:15
Did you verify we want this behavior everywhere? O
|
| + return grandparent; |
| + return this; |
| +} |
| + |
| // InternalNode ---------------------------------------------------------------- |
| TreeView::InternalNode::InternalNode() |