Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / ui / views / focus / widget_focus_manager.h
blob6d2036c6cffeb27a0e8430551479609cdda13031
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 OnNativeFocusChange(gfx::NativeView focused_before,
25 gfx::NativeView focused_now) = 0;
27 protected:
28 virtual ~WidgetFocusChangeListener() {}
31 class VIEWS_EXPORT WidgetFocusManager {
32 public:
33 // Returns the singleton instance.
34 static WidgetFocusManager* GetInstance();
36 // Adds/removes a WidgetFocusChangeListener |listener| to the set of
37 // active listeners.
38 void AddFocusChangeListener(WidgetFocusChangeListener* listener);
39 void RemoveFocusChangeListener(WidgetFocusChangeListener* listener);
41 // To be called when native-focus shifts from |focused_before| to
42 // |focused_now|.
43 // TODO(port) : Invocations to this routine are only implemented for
44 // the Win32 platform. Calls need to be placed appropriately for
45 // non-Windows environments.
46 void OnWidgetFocusEvent(gfx::NativeView focused_before,
47 gfx::NativeView focused_now);
49 // Enable/Disable notification of registered listeners during calls
50 // to OnWidgetFocusEvent. Used to prevent unwanted focus changes from
51 // propagating notifications.
52 void EnableNotifications() { enabled_ = true; }
53 void DisableNotifications() { enabled_ = false; }
55 private:
56 friend struct DefaultSingletonTraits<WidgetFocusManager>;
58 WidgetFocusManager();
59 ~WidgetFocusManager();
61 ObserverList<WidgetFocusChangeListener> focus_change_listeners_;
63 bool enabled_;
65 DISALLOW_COPY_AND_ASSIGN(WidgetFocusManager);
68 // A basic helper class that is used to disable native focus change
69 // notifications within a scope.
70 class VIEWS_EXPORT AutoNativeNotificationDisabler {
71 public:
72 AutoNativeNotificationDisabler();
73 ~AutoNativeNotificationDisabler();
75 private:
76 DISALLOW_COPY_AND_ASSIGN(AutoNativeNotificationDisabler);
79 } // namespace views
81 #endif // UI_VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_