1 // Copyright (c) 2012 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_COREWM_FOCUS_RULES_H_
6 #define UI_VIEWS_COREWM_FOCUS_RULES_H_
8 #include "ui/views/views_export.h"
17 // Implemented by an object that establishes the rules about what can be
18 // focused or activated.
19 class VIEWS_EXPORT FocusRules {
21 virtual ~FocusRules() {}
23 // Returns true if |window| is a toplevel window. Whether or not a window
24 // is considered toplevel is determined by a similar set of rules that
25 // govern activation and focus. Not all toplevel windows are activatable,
26 // call CanActivateWindow() to determine if a window can be activated.
27 virtual bool IsToplevelWindow(aura::Window* window) const = 0;
28 // Returns true if |window| can be activated or focused.
29 virtual bool CanActivateWindow(aura::Window* window) const = 0;
30 // For CanFocusWindow(), NULL is supported, because NULL is a valid focusable
31 // window (in the case of clearing focus).
32 virtual bool CanFocusWindow(aura::Window* window) const = 0;
34 // Returns the toplevel window containing |window|. Not all toplevel windows
35 // are activatable, call GetActivatableWindow() instead to return the
36 // activatable window, which might be in a different hierarchy.
37 // Will return NULL if |window| is not contained by a window considered to be
39 virtual aura::Window* GetToplevelWindow(aura::Window* window) const = 0;
40 // Returns the activatable or focusable window given an attempt to activate or
41 // focus |window|. Some possible scenarios (not intended to be exhaustive):
42 // - |window| is a child of a non-focusable window and so focus must be set
43 // according to rules defined by the delegate, e.g. to a parent.
44 // - |window| is an activatable window that is the transient parent of a modal
45 // window, so attempts to activate |window| should result in the modal
46 // transient being activated instead.
47 // These methods may return NULL if they are unable to find an activatable
48 // or focusable window given |window|.
49 virtual aura::Window* GetActivatableWindow(aura::Window* window) const = 0;
50 virtual aura::Window* GetFocusableWindow(aura::Window* window) const = 0;
52 // Returns the next window to activate in the event that |ignore| is no longer
53 // activatable. This function is called when something is happening to
54 // |ignore| that means it can no longer have focus or activation, including
55 // but not limited to:
56 // - it or its parent hierarchy is being hidden, or removed from the
58 // - it is being destroyed.
59 // - it is being explicitly deactivated.
60 // |ignore| cannot be NULL.
61 virtual aura::Window* GetNextActivatableWindow(
62 aura::Window* ignore) const = 0;
68 #endif // UI_VIEWS_COREWM_FOCUS_RULES_H_