| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_ | 5 #ifndef VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_ |
| 6 #define VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_ | 6 #define VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "ui/views/focus/widget_focus_manager.h" |
| 10 #include "base/observer_list.h" | 10 // TODO(tfarina): remove this file once all includes have been updated. |
| 11 #include "ui/gfx/native_widget_types.h" | |
| 12 #include "views/views_export.h" | |
| 13 | |
| 14 template <typename T> struct DefaultSingletonTraits; | |
| 15 | |
| 16 namespace views { | |
| 17 | |
| 18 // This interface should be implemented by classes that want to be notified when | |
| 19 // the native focus is about to change. Listeners implementing this interface | |
| 20 // will be invoked for all native focus changes across the entire Chrome | |
| 21 // application. FocusChangeListeners are only called for changes within the | |
| 22 // children of a single top-level native-view. | |
| 23 class WidgetFocusChangeListener { | |
| 24 public: | |
| 25 virtual void OnNativeFocusChange(gfx::NativeView focused_before, | |
| 26 gfx::NativeView focused_now) = 0; | |
| 27 | |
| 28 protected: | |
| 29 virtual ~WidgetFocusChangeListener() {} | |
| 30 }; | |
| 31 | |
| 32 class VIEWS_EXPORT WidgetFocusManager { | |
| 33 public: | |
| 34 // Returns the singleton instance. | |
| 35 static WidgetFocusManager* GetInstance(); | |
| 36 | |
| 37 // Adds/removes a WidgetFocusChangeListener |listener| to the set of | |
| 38 // active listeners. | |
| 39 void AddFocusChangeListener(WidgetFocusChangeListener* listener); | |
| 40 void RemoveFocusChangeListener(WidgetFocusChangeListener* listener); | |
| 41 | |
| 42 // To be called when native-focus shifts from |focused_before| to | |
| 43 // |focused_now|. | |
| 44 // TODO(port) : Invocations to this routine are only implemented for | |
| 45 // the Win32 platform. Calls need to be placed appropriately for | |
| 46 // non-Windows environments. | |
| 47 void OnWidgetFocusEvent(gfx::NativeView focused_before, | |
| 48 gfx::NativeView focused_now); | |
| 49 | |
| 50 // Enable/Disable notification of registered listeners during calls | |
| 51 // to OnWidgetFocusEvent. Used to prevent unwanted focus changes from | |
| 52 // propagating notifications. | |
| 53 void EnableNotifications() { enabled_ = true; } | |
| 54 void DisableNotifications() { enabled_ = false; } | |
| 55 | |
| 56 private: | |
| 57 friend struct DefaultSingletonTraits<WidgetFocusManager>; | |
| 58 | |
| 59 WidgetFocusManager(); | |
| 60 ~WidgetFocusManager(); | |
| 61 | |
| 62 ObserverList<WidgetFocusChangeListener> focus_change_listeners_; | |
| 63 | |
| 64 bool enabled_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(WidgetFocusManager); | |
| 67 }; | |
| 68 | |
| 69 // A basic helper class that is used to disable native focus change | |
| 70 // notifications within a scope. | |
| 71 class VIEWS_EXPORT AutoNativeNotificationDisabler { | |
| 72 public: | |
| 73 AutoNativeNotificationDisabler(); | |
| 74 ~AutoNativeNotificationDisabler(); | |
| 75 | |
| 76 private: | |
| 77 DISALLOW_COPY_AND_ASSIGN(AutoNativeNotificationDisabler); | |
| 78 }; | |
| 79 | |
| 80 } // namespace views | |
| 81 | 11 |
| 82 #endif // VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_ | 12 #endif // VIEWS_FOCUS_WIDGET_FOCUS_MANAGER_H_ |
| OLD | NEW |