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. 4 5#ifndef CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_CONTROLLER_H_ 6#define CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_CONTROLLER_H_ 7 8#include "base/basictypes.h" 9#include "base/memory/scoped_ptr.h" 10#include "chrome/browser/chromeos/ui/focus_ring_layer.h" 11#include "ui/views/focus/focus_manager.h" 12#include "ui/views/focus/widget_focus_manager.h" 13#include "ui/views/widget/widget_observer.h" 14 15namespace views { 16class View; 17class Widget; 18} 19 20namespace chromeos { 21 22// FocusRingController manages the focus ring around the focused view. It 23// follows widget focus change and update the focus ring layer when the focused 24// view of the widget changes. 25class FocusRingController : public FocusRingLayerDelegate, 26 public views::WidgetObserver, 27 public views::WidgetFocusChangeListener, 28 public views::FocusChangeListener { 29 public: 30 FocusRingController(); 31 virtual ~FocusRingController(); 32 33 // Turns on/off the focus ring. 34 void SetVisible(bool visible); 35 36 private: 37 // FocusRingLayerDelegate. 38 virtual void OnDeviceScaleFactorChanged() OVERRIDE; 39 40 // Sets the focused |widget|. 41 void SetWidget(views::Widget* widget); 42 43 // Updates the focus ring to the focused view of |widget_|. If |widget_| is 44 // NULL or has no focused view, removes the focus ring. Otherwise, draws it. 45 void UpdateFocusRing(); 46 47 // views::WidgetObserver overrides: 48 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 49 virtual void OnWidgetBoundsChanged(views::Widget* widget, 50 const gfx::Rect& new_bounds) OVERRIDE; 51 52 // views::WidgetFocusChangeListener overrides: 53 virtual void OnNativeFocusChange(gfx::NativeView focused_before, 54 gfx::NativeView focused_now) OVERRIDE; 55 56 // views::FocusChangeListener overrides: 57 virtual void OnWillChangeFocus(views::View* focused_before, 58 views::View* focused_now) OVERRIDE; 59 virtual void OnDidChangeFocus(views::View* focused_before, 60 views::View* focused_now) OVERRIDE; 61 62 bool visible_; 63 64 views::Widget* widget_; 65 scoped_ptr<FocusRingLayer> focus_ring_layer_; 66 67 DISALLOW_COPY_AND_ASSIGN(FocusRingController); 68}; 69 70} // namespace chromeos 71 72#endif // CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_CONTROLLER_H_ 73