summaryrefslogtreecommitdiffstats
path: root/ui/v2/public/view_observer.h
blob: 9fcceb08c59e96fa9c76843c373103ae2bb55bad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_V2_PUBLIC_VIEW_OBSERVER_H_
#define UI_V2_PUBLIC_VIEW_OBSERVER_H_

#include "ui/v2/public/v2_export.h"

namespace gfx {
class Rect;
}

namespace v2 {

class View;

// Observe View disposition changes. -ing methods are called before the change
// is committed, -ed methods are called after.
class V2_EXPORT ViewObserver {
 public:
  // Whether a notification is being sent before or after some property has
  // changed.
  enum DispositionChangePhase {
    DISPOSITION_CHANGING,
    DISPOSITION_CHANGED
  };

  // Tree.
  struct TreeChangeParams {
    TreeChangeParams();
    View* target;
    View* old_parent;
    View* new_parent;
    View* receiver;
    DispositionChangePhase phase;
  };

  // Called when a node is added or removed. Notifications are sent to the
  // following hierarchies in this order:
  // 1. |target|.
  // 2. |target|'s child hierarchy.
  // 3. |target|'s parent hierarchy in its |old_parent|
  //        (only for Changing notifications).
  // 3. |target|'s parent hierarchy in its |new_parent|.
  //        (only for Changed notifications).
  // This sequence is performed via the OnTreeChange notification below before
  // and after the change is committed.
  virtual void OnViewTreeChange(const TreeChangeParams& params) {}

  // TODO(beng): stacking change notification?

  // Disposition.

  virtual void OnViewDestroying() {}
  virtual void OnViewDestroyed() {}

  virtual void OnViewBoundsChanged(const gfx::Rect& old_bounds,
                                   const gfx::Rect& new_bounds) {}

  virtual void OnViewVisibilityChanging() {}
  virtual void OnViewVisibilityChanged() {}

 protected:
  virtual ~ViewObserver() {}
};

}  // namespace v2

#endif  // UI_V2_PUBLIC_VIEW_OBSERVER_H_