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

Side by Side Diff: chrome/browser/chromeos/ui/focus_ring_controller.cc

Issue 537893003: Move view logic from FocusRingLayer to FocusRingController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@focus_ring_0_force_on
Patch Set: Created 6 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/chromeos/ui/focus_ring_controller.h" 5 #include "chrome/browser/chromeos/ui/focus_ring_controller.h"
6 6
7 #include "ash/system/tray/actionable_view.h"
8 #include "ash/system/tray/tray_background_view.h"
9 #include "ash/system/tray/tray_popup_header_button.h"
7 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
8 #include "chrome/browser/chromeos/ui/focus_ring_layer.h" 11 #include "chrome/browser/chromeos/ui/focus_ring_layer.h"
12 #include "ui/aura/window.h"
13 #include "ui/views/controls/button/label_button.h"
14 #include "ui/views/view.h"
9 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
10 16
11 namespace chromeos { 17 namespace chromeos {
12 18
13 FocusRingController::FocusRingController() 19 FocusRingController::FocusRingController()
14 : visible_(false), 20 : visible_(false),
15 widget_(NULL) { 21 widget_(NULL) {
16 } 22 }
17 23
18 FocusRingController::~FocusRingController() { 24 FocusRingController::~FocusRingController() {
(...skipping 11 matching lines...) Expand all
30 aura::Window* active_window = ash::wm::GetActiveWindow(); 36 aura::Window* active_window = ash::wm::GetActiveWindow();
31 if (active_window) 37 if (active_window)
32 SetWidget(views::Widget::GetWidgetForNativeWindow(active_window)); 38 SetWidget(views::Widget::GetWidgetForNativeWindow(active_window));
33 } else { 39 } else {
34 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); 40 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this);
35 SetWidget(NULL); 41 SetWidget(NULL);
36 } 42 }
37 } 43 }
38 44
39 void FocusRingController::UpdateFocusRing() { 45 void FocusRingController::UpdateFocusRing() {
40 views::View* focused_view = NULL; 46 views::View* view = NULL;
41 if (widget_ && widget_->GetFocusManager()) 47 if (widget_ && widget_->GetFocusManager())
42 focused_view = widget_->GetFocusManager()->GetFocusedView(); 48 view = widget_->GetFocusManager()->GetFocusedView();
43 49
44 // No focus ring if no focused view or the focused view covers the whole 50 // No focus ring if no focused view or the focused view covers the whole
45 // widget content area (such as RenderWidgetHostWidgetAura). 51 // widget content area (such as RenderWidgetHostWidgetAura).
46 if (!focused_view || 52 if (!view ||
47 focused_view->ConvertRectToWidget(focused_view->bounds()) == 53 view->ConvertRectToWidget(view->bounds()) ==
48 widget_->GetContentsView()->bounds()) { 54 widget_->GetContentsView()->bounds()) {
49 focus_ring_layer_.reset(); 55 focus_ring_layer_.reset();
50 return; 56 return;
51 } 57 }
52 58
59 gfx::Rect view_bounds = view->GetContentsBounds();
60
61 // Workarounds that attempts to pick a better bounds.
62 if (view->GetClassName() == views::LabelButton::kViewClassName) {
63 view_bounds = view->GetLocalBounds();
64 view_bounds.Inset(2, 2, 2, 2);
65 }
66
67 // Workarounds for system tray items that have customized focus borders. The
68 // insets here must be consistent with the ones used by those classes.
69 if (view->GetClassName() == ash::ActionableView::kViewClassName) {
70 view_bounds = view->GetLocalBounds();
71 view_bounds.Inset(1, 1, 3, 3);
72 } else if (view->GetClassName() == ash::TrayBackgroundView::kViewClassName) {
73 view_bounds.Inset(1, 1, 3, 3);
74 } else if (view->GetClassName() ==
75 ash::TrayPopupHeaderButton::kViewClassName) {
76 view_bounds = view->GetLocalBounds();
77 view_bounds.Inset(2, 1, 2, 2);
78 }
79
80 // Convert view bounds to widget/window coordinates.
81 view_bounds = view->ConvertRectToWidget(view_bounds);
82
83 // Translate window coordinates to root window coordinates.
84 DCHECK(view->GetWidget());
85 aura::Window* window = view->GetWidget()->GetNativeWindow();
86 aura::Window* root_window = window->GetRootWindow();
87 gfx::Point origin = view_bounds.origin();
88 aura::Window::ConvertPointToTarget(window, root_window, &origin);
89 gfx::Rect layer_bounds = view_bounds;
xiyuan 2014/09/10 23:03:16 |layer_bounds| seems not used.
dmazzoni 2014/09/11 18:31:50 Done.
90 view_bounds.set_origin(origin);
91
92 // Update the focus ring layer.
53 if (!focus_ring_layer_) 93 if (!focus_ring_layer_)
54 focus_ring_layer_.reset(new FocusRingLayer); 94 focus_ring_layer_.reset(new FocusRingLayer(this));
95 focus_ring_layer_->Set(root_window, view_bounds);
96 }
55 97
56 focus_ring_layer_->SetForView(focused_view); 98 void FocusRingController::OnDeviceScaleFactorChanged() {
99 UpdateFocusRing();
57 } 100 }
58 101
59 void FocusRingController::SetWidget(views::Widget* widget) { 102 void FocusRingController::SetWidget(views::Widget* widget) {
60 if (widget_) { 103 if (widget_) {
61 widget_->RemoveObserver(this); 104 widget_->RemoveObserver(this);
62 if (widget_->GetFocusManager()) 105 if (widget_->GetFocusManager())
63 widget_->GetFocusManager()->RemoveFocusChangeListener(this); 106 widget_->GetFocusManager()->RemoveFocusChangeListener(this);
64 } 107 }
65 108
66 widget_ = widget; 109 widget_ = widget;
(...skipping 29 matching lines...) Expand all
96 views::View* focused_now) { 139 views::View* focused_now) {
97 } 140 }
98 141
99 void FocusRingController::OnDidChangeFocus(views::View* focused_before, 142 void FocusRingController::OnDidChangeFocus(views::View* focused_before,
100 views::View* focused_now) { 143 views::View* focused_now) {
101 DCHECK_EQ(focused_now, widget_->GetFocusManager()->GetFocusedView()); 144 DCHECK_EQ(focused_now, widget_->GetFocusManager()->GetFocusedView());
102 UpdateFocusRing(); 145 UpdateFocusRing();
103 } 146 }
104 147
105 } // namespace chromeos 148 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698