Home | History | Annotate | Download | only in core
      1 // Copyright 2014 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_TRANSIENT_WINDOW_MANAGER_H_
      6 #define UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/observer_list.h"
     11 #include "ui/aura/window_observer.h"
     12 #include "ui/wm/wm_export.h"
     13 
     14 namespace wm {
     15 
     16 class TransientWindowObserver;
     17 
     18 // TransientWindowManager manages the set of transient children for a window
     19 // along with the transient parent. Transient children get the following
     20 // behavior:
     21 // . The transient parent destroys any transient children when it is
     22 //   destroyed. This means a transient child is destroyed if either its parent
     23 //   or transient parent is destroyed.
     24 // . If a transient child and its transient parent share the same parent, then
     25 //   transient children are always ordered above the transient parent.
     26 // Transient windows are typically used for popups and menus.
     27 // TODO(sky): when we nuke TransientWindowClient rename this to
     28 // TransientWindowController.
     29 class WM_EXPORT TransientWindowManager : public aura::WindowObserver {
     30  public:
     31   typedef std::vector<aura::Window*> Windows;
     32 
     33   virtual ~TransientWindowManager();
     34 
     35   // Returns the TransientWindowManager for |window|. This never returns NULL.
     36   static TransientWindowManager* Get(aura::Window* window);
     37 
     38   // Returns the TransientWindowManager for |window| only if it already exists.
     39   // WARNING: this may return NULL.
     40   static const TransientWindowManager* Get(const aura::Window* window);
     41 
     42   void AddObserver(TransientWindowObserver* observer);
     43   void RemoveObserver(TransientWindowObserver* observer);
     44 
     45   // Adds or removes a transient child.
     46   void AddTransientChild(aura::Window* child);
     47   void RemoveTransientChild(aura::Window* child);
     48 
     49   const Windows& transient_children() const { return transient_children_; }
     50 
     51   aura::Window* transient_parent() { return transient_parent_; }
     52   const aura::Window* transient_parent() const { return transient_parent_; }
     53 
     54   // Returns true if in the process of stacking |window_| on top of |target|.
     55   // That is, when the stacking order of a window changes
     56   // (OnWindowStackingChanged()) the transients may get restacked as well. This
     57   // function can be used to detect if TransientWindowManager is in the process
     58   // of stacking a transient as the result of window stacking changing.
     59   bool IsStackingTransient(const aura::Window* target) const;
     60 
     61  private:
     62   explicit TransientWindowManager(aura::Window* window);
     63 
     64   // Stacks transient descendants of this window that are its siblings just
     65   // above it.
     66   void RestackTransientDescendants();
     67 
     68   // WindowObserver:
     69   virtual void OnWindowParentChanged(aura::Window* window,
     70                                      aura::Window* parent) OVERRIDE;
     71   virtual void OnWindowVisibilityChanging(aura::Window* window,
     72                                           bool visible) OVERRIDE;
     73   virtual void OnWindowStackingChanged(aura::Window* window) OVERRIDE;
     74   virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
     75 
     76   aura::Window* window_;
     77   aura::Window* transient_parent_;
     78   Windows transient_children_;
     79 
     80   // If non-null we're actively restacking transient as the result of a
     81   // transient ancestor changing.
     82   aura::Window* stacking_target_;
     83 
     84   ObserverList<TransientWindowObserver> observers_;
     85 
     86   DISALLOW_COPY_AND_ASSIGN(TransientWindowManager);
     87 };
     88 
     89 }  // namespace wm
     90 
     91 #endif  // UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_
     92