Home | History | Annotate | Download | only in aura
      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.
     44   virtual void OnWindowHierarchyChanging(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.
     48   virtual void OnWindowAdded(Window* new_window) {}
     49 
     50   // Invoked prior to removing |window| as a child of this window.
     51   virtual void OnWillRemoveWindow(Window* window) {}
     52 
     53   // Invoked when this window's parent window changes.  |parent| may be NULL.
     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.
     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.
     69   virtual void OnWindowVisibilityChanging(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.
     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.
     80   virtual void OnWindowStackingChanged(Window* window) {}
     81 
     82   // Invoked when a region of |window| is scheduled to be redrawn.
     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.
     88   virtual void OnWindowDestroying(Window* window) {}
     89 
     90   // Invoked when the Window has been destroyed (i.e. at the end of its
     91   // destructor). This is called after the window is removed from its parent.
     92   virtual void OnWindowDestroyed(Window* window) {}
     93 
     94   // Called when a Window has been added to a RootWindow.
     95   virtual void OnWindowAddedToRootWindow(Window* window) {}
     96 
     97   // Called when a Window is about to be removed from a RootWindow.
     98   virtual void OnWindowRemovingFromRootWindow(Window* window) {}
     99 
    100   // Called when a transient child is added to |window|.
    101   virtual void OnAddTransientChild(Window* window, Window* transient) {}
    102 
    103   // Called when a transient child is removed from |window|.
    104   virtual void OnRemoveTransientChild(Window* window, Window* transient) {}
    105 
    106  protected:
    107   virtual ~WindowObserver() {}
    108 };
    109 
    110 }  // namespace aura
    111 
    112 #endif  // UI_AURA_WINDOW_OBSERVER_H_
    113