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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/ui/focus_ring_controller.h"
7 #include "ash/wm/window_util.h"
8 #include "chrome/browser/chromeos/ui/focus_ring_layer.h"
9 #include "ui/views/widget/widget.h"
13 FocusRingController::FocusRingController()
18 FocusRingController::~FocusRingController() {
22 void FocusRingController::SetVisible(bool visible
) {
23 if (visible_
== visible
)
29 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this);
30 aura::Window
* active_window
= ash::wm::GetActiveWindow();
32 SetWidget(views::Widget::GetWidgetForNativeWindow(active_window
));
34 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this);
39 void FocusRingController::UpdateFocusRing() {
40 views::View
* focused_view
= NULL
;
41 if (widget_
&& widget_
->GetFocusManager())
42 focused_view
= widget_
->GetFocusManager()->GetFocusedView();
44 // No focus ring if no focused view or the focused view covers the whole
45 // widget content area (such as RenderWidgetHostWidgetAura).
47 focused_view
->ConvertRectToWidget(focused_view
->bounds()) ==
48 widget_
->GetContentsView()->bounds()) {
49 focus_ring_layer_
.reset();
53 if (!focus_ring_layer_
)
54 focus_ring_layer_
.reset(new FocusRingLayer
);
56 focus_ring_layer_
->SetForView(focused_view
);
59 void FocusRingController::SetWidget(views::Widget
* widget
) {
61 widget_
->RemoveObserver(this);
62 if (widget_
->GetFocusManager())
63 widget_
->GetFocusManager()->RemoveFocusChangeListener(this);
69 widget_
->AddObserver(this);
70 if (widget_
->GetFocusManager())
71 widget_
->GetFocusManager()->AddFocusChangeListener(this);
77 void FocusRingController::OnWidgetDestroying(views::Widget
* widget
) {
78 DCHECK_EQ(widget_
, widget
);
82 void FocusRingController::OnWidgetBoundsChanged(views::Widget
* widget
,
83 const gfx::Rect
& new_bounds
) {
84 DCHECK_EQ(widget_
, widget
);
88 void FocusRingController::OnNativeFocusChange(gfx::NativeView focused_before
,
89 gfx::NativeView focused_now
) {
90 views::Widget
* widget
=
91 focused_now
? views::Widget::GetWidgetForNativeWindow(focused_now
) : NULL
;
95 void FocusRingController::OnWillChangeFocus(views::View
* focused_before
,
96 views::View
* focused_now
) {
99 void FocusRingController::OnDidChangeFocus(views::View
* focused_before
,
100 views::View
* focused_now
) {
101 DCHECK_EQ(focused_now
, widget_
->GetFocusManager()->GetFocusedView());
105 } // namespace chromeos