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

Unified Diff: ui/views/controls/tree/tree_view.cc

Issue 2411693002: views: add focus ring to TreeView (Closed)
Patch Set: make this Mac-specific 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e6b97a9abe4c69c92897ef12866b6ea3b646dfda 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,13 @@ void TreeView::OnFocus() {
// Notify the InputMethod so that it knows to query the TextInputClient.
if (GetInputMethod())
GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector());
+
+ if (ui::MaterialDesignController::IsSecondaryUiMaterial() &&
+ PlatformStyle::kTreeViewHasFocusRing) {
+ View* focus_ring_view = FindFocusRingView();
+ FocusRing::Install(focus_ring_view);
+ focus_ring_view->SchedulePaint();
+ }
}
void TreeView::OnBlur() {
@@ -639,6 +648,12 @@ void TreeView::OnBlur() {
SchedulePaintForNode(selected_node_);
if (selector_)
selector_->OnViewBlur();
+ if (ui::MaterialDesignController::IsSecondaryUiMaterial() &&
+ PlatformStyle::kTreeViewHasFocusRing) {
+ View* focus_ring_view = FindFocusRingView();
+ FocusRing::Uninstall(focus_ring_view);
+ focus_ring_view->SchedulePaint();
+ }
}
bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) {
@@ -1057,6 +1072,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)
+ return grandparent;
+ return this;
+}
+
// InternalNode ----------------------------------------------------------------
TreeView::InternalNode::InternalNode()
« 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