diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-19 23:08:41 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-19 23:08:41 +0000 |
commit | 42c35a5997f5b11522ee308c19d334146ac6895a (patch) | |
tree | cb46a30551e8eb5112a6c6ba4d9a9284e2dedcfe /views/focus/focus_manager.h | |
parent | a109d02492863aeb537dea09bfb445eb6f5d94c5 (diff) | |
download | chromium_src-42c35a5997f5b11522ee308c19d334146ac6895a.zip chromium_src-42c35a5997f5b11522ee308c19d334146ac6895a.tar.gz chromium_src-42c35a5997f5b11522ee308c19d334146ac6895a.tar.bz2 |
Reverting 18872.
Broke the Windows build.
BUG=None
TEST=None
TBR=ben
Review URL: http://codereview.chromium.org/140023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18873 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/focus/focus_manager.h')
-rw-r--r-- | views/focus/focus_manager.h | 85 |
1 files changed, 67 insertions, 18 deletions
diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h index 8b4c8c9a..fb48188 100644 --- a/views/focus/focus_manager.h +++ b/views/focus/focus_manager.h @@ -20,7 +20,7 @@ // focused views and handle keyboard accelerators. // // There are 2 types of focus: -// - the native focus, which is the focus that an gfx::NativeView has. +// - the native focus, which is the focus that an HWND has. // - the view focus, which is the focus that a views::View has. // // Each native view must register with their Focus Manager so the focus manager @@ -32,9 +32,13 @@ // This is already done for you if you subclass the NativeControl class or if // you use the NativeViewHost class. // -// When creating a top window (derived from views::Widget) that is not a child -// window, it creates and owns a FocusManager to manage the focus for itself and -// all its child windows. +// When creating a top window, if it derives from WidgetWin, the +// |has_own_focus_manager| of the Init method lets you specify whether that +// window should have its own focus manager (so focus traversal stays confined +// in that window). If you are not deriving from WidgetWin or one of its +// derived classes (Window, FramelessWindow, ConstrainedWindow), you must +// create a FocusManager when the window is created (it is automatically deleted +// when the window is destroyed). // // The FocusTraversable interface exposes the methods a class should implement // in order to be able to be focus traversed when tab key is pressed. @@ -73,9 +77,8 @@ namespace views { -class RootView; class View; -class Widget; +class RootView; // The FocusTraversable interface is used by components that want to process // focus traversal events (due to Tab/Shift-Tab key events). @@ -150,10 +153,22 @@ class FocusChangeListener { class FocusManager { public: - explicit FocusManager(Widget* widget); - ~FocusManager(); +#if defined(OS_WIN) + // Creates a FocusManager for the specified window. Top level windows + // must invoked this when created. + // The RootView specified should be the top RootView of the window. + // This also invokes InstallFocusSubclass. + static FocusManager* CreateFocusManager(HWND window, RootView* root_view); +#endif + + static FocusManager* GetFocusManager(gfx::NativeView window); #if defined(OS_WIN) + // Message handlers (for messages received from registered windows). + // Should return true if the message should be forwarded to the window + // original proc function, false otherwise. + bool OnSetFocus(HWND window); + bool OnNCDestroy(HWND window); // OnKeyDown covers WM_KEYDOWN and WM_SYSKEYDOWN. bool OnKeyDown(HWND window, UINT message, @@ -180,10 +195,27 @@ class FocusManager { // the native focus (so we still get keyboard events). void ClearFocus(); + // Clears the HWND that has the focus by focusing the HWND from the top + // RootView (so we still get keyboard events). + // Note that this does not change the currently focused view. + void ClearHWNDFocus(); + +#if defined(OS_WIN) + // Focus the specified |hwnd| without changing the focused view. + void FocusHWND(HWND hwnd); +#endif + // Validates the focused view, clearing it if the window it belongs too is not // attached to the window hierarchy anymore. void ValidateFocusedView(); +#if defined(OS_WIN) + // Returns the view associated with the specified window if any. + // If |look_in_parents| is true, it goes up the window parents until it find + // a view. + static View* GetViewForWindow(HWND window, bool look_in_parents); +#endif + // Stores and restores the focused view. Used when the window becomes // active/inactive. void StoreFocusedView(); @@ -192,6 +224,11 @@ class FocusManager { // Clears the stored focused view. void ClearStoredFocusedView(); + // Returns the FocusManager of the parent window of the window that is the + // root of this FocusManager. This is useful with ConstrainedWindows that have + // their own FocusManager and need to return focus to the browser when closed. + FocusManager* GetParentFocusManager() const; + // Register a keyboard accelerator for the specified target. If multiple // targets are registered for an accelerator, a target registered later has // higher priority. @@ -243,17 +280,22 @@ class FocusManager { // pressed). static bool IsTabTraversalKeyEvent(const KeyEvent& key_event); - // Sets the focus to the specified native view. - virtual void FocusNativeView(gfx::NativeView native_view); + private: +#if defined(OS_WIN) + explicit FocusManager(HWND root, RootView* root_view); - // Clears the native view having the focus. - virtual void ClearNativeFocus(); + // Subclasses the specified window. The subclassed window procedure listens + // for WM_SETFOCUS notification and keeps the FocusManager's focus owner + // property in sync. + // It's not necessary to explicitly invoke Uninstall, it's automatically done + // when the window is destroyed and Uninstall wasn't invoked. + static void InstallFocusSubclass(HWND window, View* view); - // Retrieves the FocusManager associated with the passed native view. - static FocusManager* GetFocusManagerForNativeView( - gfx::NativeView native_view); + // Uninstalls the window subclass installed by InstallFocusSubclass. + static void UninstallFocusSubclass(HWND window); +#endif + ~FocusManager(); - private: // Returns the next focusable view. View* GetNextFocusableView(View* starting_view, bool reverse, bool dont_loop); @@ -265,8 +307,8 @@ class FocusManager { View* starting_view, bool reverse); - // The top-level Widget this FocusManager is associated with. - Widget* widget_; + // The RootView of the window associated with this FocusManager. + RootView* top_root_view_; // The view that currently is focused. View* focused_view_; @@ -275,6 +317,13 @@ class FocusManager { // had focus. int stored_focused_view_storage_id_; + // The window associated with this focus manager. + gfx::NativeView root_; + + // Used to allow setting the focus on an HWND without changing the currently + // focused view. + bool ignore_set_focus_msg_; + // The accelerators and associated targets. typedef std::list<AcceleratorTarget*> AcceleratorTargetList; typedef std::map<Accelerator, AcceleratorTargetList> AcceleratorMap; |