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