15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <vector>
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/observer_list.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/aura/window_observer.h"
120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "ui/wm/wm_export.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace wm {
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TransientWindowObserver;
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// TransientWindowManager manages the set of transient children for a window
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// along with the transient parent. Transient children get the following
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// behavior:
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// . The transient parent destroys any transient children when it is
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//   destroyed. This means a transient child is destroyed if either its parent
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//   or transient parent is destroyed.
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// . If a transient child and its transient parent share the same parent, then
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//   transient children are always ordered above the transient parent.
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Transient windows are typically used for popups and menus.
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// TODO(sky): when we nuke TransientWindowClient rename this to
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// TransientWindowController.
290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass WM_EXPORT TransientWindowManager : public aura::WindowObserver {
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef std::vector<aura::Window*> Windows;
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~TransientWindowManager();
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns the TransientWindowManager for |window|. This never returns NULL.
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static TransientWindowManager* Get(aura::Window* window);
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns the TransientWindowManager for |window| only if it already exists.
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // WARNING: this may return NULL.
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const TransientWindowManager* Get(const aura::Window* window);
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void AddObserver(TransientWindowObserver* observer);
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void RemoveObserver(TransientWindowObserver* observer);
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Adds or removes a transient child.
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void AddTransientChild(aura::Window* child);
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void RemoveTransientChild(aura::Window* child);
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const Windows& transient_children() const { return transient_children_; }
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* transient_parent() { return transient_parent_; }
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const aura::Window* transient_parent() const { return transient_parent_; }
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
54a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Returns true if in the process of stacking |window_| on top of |target|.
55a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // That is, when the stacking order of a window changes
56a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // (OnWindowStackingChanged()) the transients may get restacked as well. This
57a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // function can be used to detect if TransientWindowManager is in the process
58a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // of stacking a transient as the result of window stacking changing.
59a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  bool IsStackingTransient(const aura::Window* target) const;
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit TransientWindowManager(aura::Window* window);
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
64a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Stacks transient descendants of this window that are its siblings just
65a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // above it.
66a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  void RestackTransientDescendants();
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // WindowObserver:
69a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  virtual void OnWindowParentChanged(aura::Window* window,
70a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                     aura::Window* parent) OVERRIDE;
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnWindowVisibilityChanging(aura::Window* window,
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          bool visible) OVERRIDE;
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnWindowStackingChanged(aura::Window* window) OVERRIDE;
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* window_;
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* transient_parent_;
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Windows transient_children_;
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // If non-null we're actively restacking transient as the result of a
81a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // transient ancestor changing.
82a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  aura::Window* stacking_target_;
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ObserverList<TransientWindowObserver> observers_;
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TransientWindowManager);
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace wm
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // UI_WM_CORE_TRANSIENT_WINDOW_MANAGER_H_
92