Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / views / focus / widget_focus_manager.h
blobf87814a3047fe9e5b7465f42047434cea7f02265
1 // Copyright (c) 2011 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 #ifndef UI_VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_
6 #define UI_VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_
8 #include "base/basictypes.h"
9 #include "base/observer_list.h"
10 #include "ui/gfx/native_widget_types.h"
11 #include "ui/views/views_export.h"
13 template <typename T> struct DefaultSingletonTraits;
15 namespace views {
17 // This interface should be implemented by classes that want to be notified when
18 // the native focus is about to change. Listeners implementing this interface
19 // will be invoked for all native focus changes across the entire Chrome
20 // application. FocusChangeListeners are only called for changes within the
21 // children of a single top-level native-view.
22 class WidgetFocusChangeListener {
23 public:
24 virtual void OnNativeFocusChanged(gfx::NativeView focused_now) = 0;
26 protected:
27 virtual ~WidgetFocusChangeListener() {}
30 class VIEWS_EXPORT WidgetFocusManager {
31 public:
32 // Returns the singleton instance.
33 static WidgetFocusManager* GetInstance();
35 // Adds/removes a WidgetFocusChangeListener |listener| to the set of
36 // active listeners.
37 void AddFocusChangeListener(WidgetFocusChangeListener* listener);
38 void RemoveFocusChangeListener(WidgetFocusChangeListener* listener);
40 // Called when native-focus shifts within, or off, a widget. |focused_now| is
41 // null when focus is lost.
42 void OnNativeFocusChanged(gfx::NativeView focused_now);
44 // Enable/Disable notification of registered listeners during calls
45 // to OnNativeFocusChanged. Used to prevent unwanted focus changes from
46 // propagating notifications.
47 void EnableNotifications() { enabled_ = true; }
48 void DisableNotifications() { enabled_ = false; }
50 private:
51 friend struct DefaultSingletonTraits<WidgetFocusManager>;
53 WidgetFocusManager();
54 ~WidgetFocusManager();
56 base::ObserverList<WidgetFocusChangeListener> focus_change_listeners_;
58 bool enabled_;
60 DISALLOW_COPY_AND_ASSIGN(WidgetFocusManager);
63 // A basic helper class that is used to disable native focus change
64 // notifications within a scope.
65 class VIEWS_EXPORT AutoNativeNotificationDisabler {
66 public:
67 AutoNativeNotificationDisabler();
68 ~AutoNativeNotificationDisabler();
70 private:
71 DISALLOW_COPY_AND_ASSIGN(AutoNativeNotificationDisabler);
74 } // namespace views
76 #endif // UI_VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_