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 WindowObserver(); 35 36 // Called when a window is added or removed. Notifications are sent to the 37 // following hierarchies in this order: 38 // 1. |target|. 39 // 2. |target|'s child hierarchy. 40 // 3. |target|'s parent hierarchy in its |old_parent| 41 // (only for Changing notifications). 42 // 3. |target|'s parent hierarchy in its |new_parent|. 43 // (only for Changed notifications). 44 // This sequence is performed via the Changing and Changed notifications below 45 // before and after the change is committed. OnWindowHierarchyChanging(const HierarchyChangeParams & params)46 virtual void OnWindowHierarchyChanging(const HierarchyChangeParams& params) {} OnWindowHierarchyChanged(const HierarchyChangeParams & params)47 virtual void OnWindowHierarchyChanged(const HierarchyChangeParams& params) {} 48 49 // Invoked when |new_window| has been added as a child of this window. OnWindowAdded(Window * new_window)50 virtual void OnWindowAdded(Window* new_window) {} 51 52 // Invoked prior to removing |window| as a child of this window. OnWillRemoveWindow(Window * window)53 virtual void OnWillRemoveWindow(Window* window) {} 54 55 // Invoked when this window's parent window changes. |parent| may be NULL. OnWindowParentChanged(Window * window,Window * parent)56 virtual void OnWindowParentChanged(Window* window, Window* parent) {} 57 58 // Invoked when SetProperty(), ClearProperty(), or 59 // NativeWidgetAura::SetNativeWindowProperty() is called on the window. 60 // |key| is either a WindowProperty<T>* (SetProperty, ClearProperty) 61 // or a const char* (SetNativeWindowProperty). Either way, it can simply be 62 // compared for equality with the property constant. |old| is the old property 63 // value, which must be cast to the appropriate type before use. OnWindowPropertyChanged(Window * window,const void * key,intptr_t old)64 virtual void OnWindowPropertyChanged(Window* window, 65 const void* key, 66 intptr_t old) {} 67 68 // Invoked when SetVisible() is invoked on a window. |visible| is the 69 // value supplied to SetVisible(). If |visible| is true, window->IsVisible() 70 // may still return false. See description in Window::IsVisible() for details. OnWindowVisibilityChanging(Window * window,bool visible)71 virtual void OnWindowVisibilityChanging(Window* window, bool visible) {} OnWindowVisibilityChanged(Window * window,bool visible)72 virtual void OnWindowVisibilityChanged(Window* window, bool visible) {} 73 74 // Invoked when SetBounds() is invoked on |window|. |old_bounds| and 75 // |new_bounds| are in parent coordinates. OnWindowBoundsChanged(Window * window,const gfx::Rect & old_bounds,const gfx::Rect & new_bounds)76 virtual void OnWindowBoundsChanged(Window* window, 77 const gfx::Rect& old_bounds, 78 const gfx::Rect& new_bounds) {} 79 80 // Invoked when SetTransform() is invoked on |window|. OnWindowTransforming(Window * window)81 virtual void OnWindowTransforming(Window* window) {} OnWindowTransformed(Window * window)82 virtual void OnWindowTransformed(Window* window) {} 83 84 // Invoked when |window|'s position among its siblings in the stacking order 85 // has changed. OnWindowStackingChanged(Window * window)86 virtual void OnWindowStackingChanged(Window* window) {} 87 88 // Invoked when a region of |window| is scheduled to be redrawn. OnWindowPaintScheduled(Window * window,const gfx::Rect & region)89 virtual void OnWindowPaintScheduled(Window* window, 90 const gfx::Rect& region) {} 91 92 // Invoked when the Window is being destroyed (i.e. from the start of its 93 // destructor). This is called before the window is removed from its parent. OnWindowDestroying(Window * window)94 virtual void OnWindowDestroying(Window* window) {} 95 96 // Invoked when the Window has been destroyed (i.e. at the end of 97 // its destructor). This is called after the window is removed from 98 // its parent. Window automatically removes its WindowObservers 99 // before calling this method, so the following code is no op. 100 // 101 // void MyWindowObserver::OnWindowDestroyed(aura::Window* window) { 102 // window->RemoveObserver(this); 103 // } OnWindowDestroyed(Window * window)104 virtual void OnWindowDestroyed(Window* window) {} 105 106 // Called when a Window has been added to a RootWindow. OnWindowAddedToRootWindow(Window * window)107 virtual void OnWindowAddedToRootWindow(Window* window) {} 108 109 // Called when a Window is about to be removed from a root Window. 110 // |new_root| contains the new root Window if it is being added to one 111 // atomically. OnWindowRemovingFromRootWindow(Window * window,Window * new_root)112 virtual void OnWindowRemovingFromRootWindow(Window* window, 113 Window* new_root) {} 114 115 protected: 116 virtual ~WindowObserver(); 117 118 private: 119 friend class Window; 120 121 // Called when this is added as an observer on |window|. 122 void OnObservingWindow(Window* window); 123 124 // Called when this is removed from the observers on |window|. 125 void OnUnobservingWindow(Window* window); 126 127 // Tracks the number of windows being observed to track down 128 // http://crbug.com/365364. 129 int observing_; 130 131 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 132 }; 133 134 } // namespace aura 135 136 #endif // UI_AURA_WINDOW_OBSERVER_H_ 137