Home | History | Annotate | Download | only in ui
      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 "ui/views/focus/focus_manager.h"
     11 #include "ui/views/focus/widget_focus_manager.h"
     12 #include "ui/views/widget/widget_observer.h"
     13 
     14 namespace views {
     15 class View;
     16 class Widget;
     17 }
     18 
     19 namespace chromeos {
     20 
     21 class FocusRingLayer;
     22 
     23 // FocusRingController manages the focus ring around the focused view. It
     24 // follows widget focus change and update the focus ring layer when the focused
     25 // view of the widget changes.
     26 class FocusRingController : 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   // Sets the focused |widget|.
     38   void SetWidget(views::Widget* widget);
     39 
     40   // Updates the focus ring to the focused view of |widget_|. If |widget_| is
     41   // NULL or has no focused view, removes the focus ring. Otherwise, draws it.
     42   void UpdateFocusRing();
     43 
     44   // views::WidgetObserver overrides:
     45   virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
     46   virtual void OnWidgetBoundsChanged(views::Widget* widget,
     47                                      const gfx::Rect& new_bounds) OVERRIDE;
     48 
     49   // views::WidgetFocusChangeListener overrides:
     50   virtual void OnNativeFocusChange(gfx::NativeView focused_before,
     51                                    gfx::NativeView focused_now) OVERRIDE;
     52 
     53   // views::FocusChangeListener overrides:
     54   virtual void OnWillChangeFocus(views::View* focused_before,
     55                                  views::View* focused_now) OVERRIDE;
     56   virtual void OnDidChangeFocus(views::View* focused_before,
     57                                 views::View* focused_now) OVERRIDE;
     58 
     59   bool visible_;
     60 
     61   views::Widget* widget_;
     62   scoped_ptr<FocusRingLayer> focus_ring_layer_;
     63 
     64   DISALLOW_COPY_AND_ASSIGN(FocusRingController);
     65 };
     66 
     67 }  // namespace chromeos
     68 
     69 #endif  // CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_CONTROLLER_H_
     70