• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_AURA_WINDOW_OBSERVER_H_
6 #define UI_AURA_WINDOW_OBSERVER_H_
7 
8 #include "base/basictypes.h"
9 #include "ui/aura/aura_export.h"
10 
11 namespace gfx {
12 class Rect;
13 }  // namespace gfx
14 
15 namespace aura {
16 
17 class Window;
18 
19 class AURA_EXPORT WindowObserver {
20  public:
21   struct HierarchyChangeParams {
22     enum HierarchyChangePhase {
23       HIERARCHY_CHANGING,
24       HIERARCHY_CHANGED
25     };
26 
27     Window* target;     // The window that was added or removed.
28     Window* new_parent;
29     Window* old_parent;
30     HierarchyChangePhase phase;
31     Window* receiver;   // The window receiving the notification.
32   };
33 
34   // Called when a window is added or removed. Notifications are sent to the
35   // following hierarchies in this order:
36   // 1. |target|.
37   // 2. |target|'s child hierarchy.
38   // 3. |target|'s parent hierarchy in its |old_parent|
39   //        (only for Changing notifications).
40   // 3. |target|'s parent hierarchy in its |new_parent|.
41   //        (only for Changed notifications).
42   // This sequence is performed via the Changing and Changed notifications below
43   // before and after the change is committed.
OnWindowHierarchyChanging(const HierarchyChangeParams & params)44   virtual void OnWindowHierarchyChanging(const HierarchyChangeParams& params) {}
OnWindowHierarchyChanged(const HierarchyChangeParams & params)45   virtual void OnWindowHierarchyChanged(const HierarchyChangeParams& params) {}
46 
47   // Invoked when |new_window| has been added as a child of this window.
OnWindowAdded(Window * new_window)48   virtual void OnWindowAdded(Window* new_window) {}
49 
50   // Invoked prior to removing |window| as a child of this window.
OnWillRemoveWindow(Window * window)51   virtual void OnWillRemoveWindow(Window* window) {}
52 
53   // Invoked when this window's parent window changes.  |parent| may be NULL.
OnWindowParentChanged(Window * window,Window * parent)54   virtual void OnWindowParentChanged(Window* window, Window* parent) {}
55 
56   // Invoked when SetProperty(), ClearProperty(), or
57   // NativeWidgetAura::SetNativeWindowProperty() is called on the window.
58   // |key| is either a WindowProperty<T>* (SetProperty, ClearProperty)
59   // or a const char* (SetNativeWindowProperty). Either way, it can simply be
60   // compared for equality with the property constant. |old| is the old property
61   // value, which must be cast to the appropriate type before use.
OnWindowPropertyChanged(Window * window,const void * key,intptr_t old)62   virtual void OnWindowPropertyChanged(Window* window,
63                                        const void* key,
64                                        intptr_t old) {}
65 
66   // Invoked when SetVisible() is invoked on a window. |visible| is the
67   // value supplied to SetVisible(). If |visible| is true, window->IsVisible()
68   // may still return false. See description in Window::IsVisible() for details.
OnWindowVisibilityChanging(Window * window,bool visible)69   virtual void OnWindowVisibilityChanging(Window* window, bool visible) {}
OnWindowVisibilityChanged(Window * window,bool visible)70   virtual void OnWindowVisibilityChanged(Window* window, bool visible) {}
71 
72   // Invoked when SetBounds() is invoked on |window|. |old_bounds| and
73   // |new_bounds| are in parent coordinates.
OnWindowBoundsChanged(Window * window,const gfx::Rect & old_bounds,const gfx::Rect & new_bounds)74   virtual void OnWindowBoundsChanged(Window* window,
75                                      const gfx::Rect& old_bounds,
76                                      const gfx::Rect& new_bounds) {}
77 
78   // Invoked when |window|'s position among its siblings in the stacking order
79   // has changed.
OnWindowStackingChanged(Window * window)80   virtual void OnWindowStackingChanged(Window* window) {}
81 
82   // Invoked when a region of |window| is scheduled to be redrawn.
OnWindowPaintScheduled(Window * window,const gfx::Rect & region)83   virtual void OnWindowPaintScheduled(Window* window,
84                                       const gfx::Rect& region) {}
85 
86   // Invoked when the Window is being destroyed (i.e. from the start of its
87   // destructor). This is called before the window is removed from its parent.
OnWindowDestroying(Window * window)88   virtual void OnWindowDestroying(Window* window) {}
89 
90   // Invoked when the Window has been destroyed (i.e. at the end of
91   // its destructor). This is called after the window is removed from
92   // its parent.  Window automatically removes its WindowObservers
93   // before calling this method, so the following code is no op.
94   //
95   // void MyWindowObserver::OnWindowDestroyed(aura::Window* window) {
96   //    window->RemoveObserver(this);
97   // }
OnWindowDestroyed(Window * window)98   virtual void OnWindowDestroyed(Window* window) {}
99 
100   // Called when a Window has been added to a RootWindow.
OnWindowAddedToRootWindow(Window * window)101   virtual void OnWindowAddedToRootWindow(Window* window) {}
102 
103   // Called when a Window is about to be removed from a RootWindow.
OnWindowRemovingFromRootWindow(Window * window)104   virtual void OnWindowRemovingFromRootWindow(Window* window) {}
105 
106   // Called when a transient child is added to |window|.
OnAddTransientChild(Window * window,Window * transient)107   virtual void OnAddTransientChild(Window* window, Window* transient) {}
108 
109   // Called when a transient child is removed from |window|.
OnRemoveTransientChild(Window * window,Window * transient)110   virtual void OnRemoveTransientChild(Window* window, Window* transient) {}
111 
112  protected:
~WindowObserver()113   virtual ~WindowObserver() {}
114 };
115 
116 }  // namespace aura
117 
118 #endif  // UI_AURA_WINDOW_OBSERVER_H_
119