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 "base/strings/string16.h"
10 #include "ui/aura/aura_export.h"
20 class AURA_EXPORT WindowObserver
{
22 struct HierarchyChangeParams
{
23 enum HierarchyChangePhase
{
28 Window
* target
; // The window that was added or removed.
31 HierarchyChangePhase phase
;
32 Window
* receiver
; // The window receiving the notification.
37 // Called when a window is added or removed. Notifications are sent to the
38 // following hierarchies in this order:
40 // 2. |target|'s child hierarchy.
41 // 3. |target|'s parent hierarchy in its |old_parent|
42 // (only for Changing notifications).
43 // 3. |target|'s parent hierarchy in its |new_parent|.
44 // (only for Changed notifications).
45 // This sequence is performed via the Changing and Changed notifications below
46 // before and after the change is committed.
47 virtual void OnWindowHierarchyChanging(const HierarchyChangeParams
& params
) {}
48 virtual void OnWindowHierarchyChanged(const HierarchyChangeParams
& params
) {}
50 // Invoked when |new_window| has been added as a child of this window.
51 virtual void OnWindowAdded(Window
* new_window
) {}
53 // Invoked prior to removing |window| as a child of this window.
54 virtual void OnWillRemoveWindow(Window
* window
) {}
56 // Invoked when this window's parent window changes. |parent| may be NULL.
57 virtual void OnWindowParentChanged(Window
* window
, Window
* parent
) {}
59 // Invoked when SetProperty(), ClearProperty(), or
60 // NativeWidgetAura::SetNativeWindowProperty() is called on the window.
61 // |key| is either a WindowProperty<T>* (SetProperty, ClearProperty)
62 // or a const char* (SetNativeWindowProperty). Either way, it can simply be
63 // compared for equality with the property constant. |old| is the old property
64 // value, which must be cast to the appropriate type before use.
65 virtual void OnWindowPropertyChanged(Window
* window
,
69 // Invoked when SetVisible() is invoked on a window. |visible| is the
70 // value supplied to SetVisible(). If |visible| is true, window->IsVisible()
71 // may still return false. See description in Window::IsVisible() for details.
72 virtual void OnWindowVisibilityChanging(Window
* window
, bool visible
) {}
73 virtual void OnWindowVisibilityChanged(Window
* window
, bool visible
) {}
75 // Invoked when SetBounds() is invoked on |window|. |old_bounds| and
76 // |new_bounds| are in parent coordinates.
77 virtual void OnWindowBoundsChanged(Window
* window
,
78 const gfx::Rect
& old_bounds
,
79 const gfx::Rect
& new_bounds
) {}
81 // Invoked when SetTransform() is invoked on |window|.
82 virtual void OnWindowTransforming(Window
* window
) {}
83 virtual void OnWindowTransformed(Window
* window
) {}
85 // Invoked when |window|'s position among its siblings in the stacking order
87 virtual void OnWindowStackingChanged(Window
* window
) {}
89 // Invoked when a region of |window| has damage from a new delegated frame.
90 virtual void OnDelegatedFrameDamage(Window
* window
,
91 const gfx::Rect
& damage_rect_in_dip
) {}
93 // Invoked when the Window is being destroyed (i.e. from the start of its
94 // destructor). This is called before the window is removed from its parent.
95 virtual void OnWindowDestroying(Window
* window
) {}
97 // Invoked when the Window has been destroyed (i.e. at the end of
98 // its destructor). This is called after the window is removed from
99 // its parent. Window automatically removes its WindowObservers
100 // before calling this method, so the following code is no op.
102 // void MyWindowObserver::OnWindowDestroyed(aura::Window* window) {
103 // window->RemoveObserver(this);
105 virtual void OnWindowDestroyed(Window
* window
) {}
107 // Called when a Window has been added to a RootWindow.
108 virtual void OnWindowAddedToRootWindow(Window
* window
) {}
110 // Called when a Window is about to be removed from a root Window.
111 // |new_root| contains the new root Window if it is being added to one
113 virtual void OnWindowRemovingFromRootWindow(Window
* window
,
116 // Called when the window title has changed.
117 virtual void OnWindowTitleChanged(Window
* window
) {}
120 virtual ~WindowObserver();
125 // Called when this is added as an observer on |window|.
126 void OnObservingWindow(Window
* window
);
128 // Called when this is removed from the observers on |window|.
129 void OnUnobservingWindow(Window
* window
);
131 // Tracks the number of windows being observed to track down
132 // http://crbug.com/365364.
135 DISALLOW_COPY_AND_ASSIGN(WindowObserver
);
140 #endif // UI_AURA_WINDOW_OBSERVER_H_