• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_VIEWS_WIDGET_WINDOW_REORDERER_H_
6 #define UI_VIEWS_WIDGET_WINDOW_REORDERER_H_
7 
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/aura/window_observer.h"
11 
12 namespace aura {
13 class Window;
14 }
15 
16 namespace views {
17 class View;
18 
19 // Class which reorders the widget's child windows which have an associated view
20 // in the widget's view tree according the z-order of the views in the view
21 // tree. Windows not associated to a view are stacked above windows with an
22 // associated view. The child windows' layers are additionally reordered
23 // according to the z-order of the associated views relative to views with
24 // layers.
25 class WindowReorderer : public aura::WindowObserver {
26  public:
27   WindowReorderer(aura::Window* window, View* root_view);
28   virtual ~WindowReorderer();
29 
30   // Explicitly reorder the children of |window_| (and their layers). This
31   // method should be called when the position of a view with an associated
32   // window changes in the view hierarchy. This method assumes that the
33   // child layers of |window_| which are owned by views are already in the
34   // correct z-order relative to each other and does no reordering if there
35   // are no views with an associated window.
36   void ReorderChildWindows();
37 
38  private:
39   // aura::WindowObserver overrides:
40   virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE;
41   virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE;
42   virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
43 
44   // The window and the root view of the native widget which owns the
45   // WindowReorderer.
46   aura::Window* parent_window_;
47   View* root_view_;
48 
49   // Reorders windows as a result of the kHostViewKey being set on a child of
50   // |parent_window_|.
51   class AssociationObserver;
52   scoped_ptr<AssociationObserver> association_observer_;
53 
54   DISALLOW_COPY_AND_ASSIGN(WindowReorderer);
55 };
56 
57 }  // namespace views
58 
59 #endif  // UI_VIEWS_WIDGET_WINDOW_REORDERER_H_
60