1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_CONTROLLER_H_
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_CONTROLLER_H_
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/basictypes.h"
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/chromeos/ui/focus_ring_layer.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/focus/focus_manager.h"
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/focus/widget_focus_manager.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/widget/widget_observer.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace views {
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class View;
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class Widget;
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace chromeos {
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// FocusRingController manages the focus ring around the focused view. It
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// follows widget focus change and update the focus ring layer when the focused
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// view of the widget changes.
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass FocusRingController : public FocusRingLayerDelegate,
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                            public views::WidgetObserver,
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            public views::WidgetFocusChangeListener,
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            public views::FocusChangeListener {
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  FocusRingController();
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual ~FocusRingController();
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Turns on/off the focus ring.
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SetVisible(bool visible);
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // FocusRingLayerDelegate.
381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnDeviceScaleFactorChanged() OVERRIDE;
391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Sets the focused |widget|.
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SetWidget(views::Widget* widget);
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Updates the focus ring to the focused view of |widget_|. If |widget_| is
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // NULL or has no focused view, removes the focus ring. Otherwise, draws it.
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void UpdateFocusRing();
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // views::WidgetObserver overrides:
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void OnWidgetBoundsChanged(views::Widget* widget,
50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                     const gfx::Rect& new_bounds) OVERRIDE;
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // views::WidgetFocusChangeListener overrides:
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void OnNativeFocusChange(gfx::NativeView focused_before,
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                   gfx::NativeView focused_now) OVERRIDE;
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // views::FocusChangeListener overrides:
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void OnWillChangeFocus(views::View* focused_before,
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                 views::View* focused_now) OVERRIDE;
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void OnDidChangeFocus(views::View* focused_before,
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                views::View* focused_now) OVERRIDE;
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool visible_;
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  views::Widget* widget_;
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<FocusRingLayer> focus_ring_layer_;
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(FocusRingController);
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace chromeos
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif  // CHROME_BROWSER_CHROMEOS_UI_FOCUS_RING_CONTROLLER_H_
73