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.
5 #ifndef UI_AURA_WINDOW_OBSERVER_H_
6 #define UI_AURA_WINDOW_OBSERVER_H_
8 #include "base/basictypes.h"
9 #include "ui/aura/aura_export.h"
19 class AURA_EXPORT WindowObserver
{
21 struct HierarchyChangeParams
{
22 enum HierarchyChangePhase
{
27 Window
* target
; // The window that was added or removed.
30 HierarchyChangePhase phase
;
31 Window
* receiver
; // The window receiving the notification.
34 // Called when a window is added or removed. Notifications are sent to the
35 // following hierarchies in this order:
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.
44 virtual void OnWindowHierarchyChanging(const HierarchyChangeParams
& params
) {}
45 virtual void OnWindowHierarchyChanged(const HierarchyChangeParams
& params
) {}
47 // Invoked when |new_window| has been added as a child of this window.
48 virtual void OnWindowAdded(Window
* new_window
) {}
50 // Invoked prior to removing |window| as a child of this window.
51 virtual void OnWillRemoveWindow(Window
* window
) {}
53 // Invoked when this window's parent window changes. |parent| may be NULL.
54 virtual void OnWindowParentChanged(Window
* window
, Window
* parent
) {}
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.
62 virtual void OnWindowPropertyChanged(Window
* window
,
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.
69 virtual void OnWindowVisibilityChanging(Window
* window
, bool visible
) {}
70 virtual void OnWindowVisibilityChanged(Window
* window
, bool visible
) {}
72 // Invoked when SetBounds() is invoked on |window|. |old_bounds| and
73 // |new_bounds| are in parent coordinates.
74 virtual void OnWindowBoundsChanged(Window
* window
,
75 const gfx::Rect
& old_bounds
,
76 const gfx::Rect
& new_bounds
) {}
78 // Invoked when |window|'s position among its siblings in the stacking order
80 virtual void OnWindowStackingChanged(Window
* window
) {}
82 // Invoked when a region of |window| is scheduled to be redrawn.
83 virtual void OnWindowPaintScheduled(Window
* window
,
84 const gfx::Rect
& region
) {}
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.
88 virtual void OnWindowDestroying(Window
* window
) {}
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.
95 // void MyWindowObserver::OnWindowDestroyed(aura::Window* window) {
96 // window->RemoveObserver(this);
98 virtual void OnWindowDestroyed(Window
* window
) {}
100 // Called when a Window has been added to a RootWindow.
101 virtual void OnWindowAddedToRootWindow(Window
* window
) {}
103 // Called when a Window is about to be removed from a RootWindow.
104 virtual void OnWindowRemovingFromRootWindow(Window
* window
) {}
107 virtual ~WindowObserver() {}
112 #endif // UI_AURA_WINDOW_OBSERVER_H_