summaryrefslogtreecommitdiffstats
path: root/components/mus/public/cpp/view_observer.h
blob: 2bd541be76323eeec0f5168f980f6ca293070d39 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2014 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 COMPONENTS_MUS_PUBLIC_CPP_VIEW_OBSERVER_H_
#define COMPONENTS_MUS_PUBLIC_CPP_VIEW_OBSERVER_H_

#include <vector>

#include "components/mus/public/cpp/view.h"
#include "ui/mojo/events/input_events.mojom.h"

namespace mus {

class View;

// A note on -ing and -ed suffixes:
//
// -ing methods are called before changes are applied to the local view model.
// -ed methods are called after changes are applied to the local view model.
//
// If the change originated from another connection to the view manager, it's
// possible that the change has already been applied to the service-side model
// prior to being called, so for example in the case of OnViewDestroying(), it's
// possible the view has already been destroyed on the service side.

class ViewObserver {
 public:
  struct TreeChangeParams {
    TreeChangeParams();
    View* target;
    View* old_parent;
    View* new_parent;
    View* receiver;
  };

  virtual void OnTreeChanging(const TreeChangeParams& params) {}
  virtual void OnTreeChanged(const TreeChangeParams& params) {}

  virtual void OnViewReordering(View* view,
                                View* relative_view,
                                mojo::OrderDirection direction) {}
  virtual void OnViewReordered(View* view,
                               View* relative_view,
                               mojo::OrderDirection direction) {}

  virtual void OnViewDestroying(View* view) {}
  virtual void OnViewDestroyed(View* view) {}

  virtual void OnViewBoundsChanging(View* view,
                                    const mojo::Rect& old_bounds,
                                    const mojo::Rect& new_bounds) {}
  virtual void OnViewBoundsChanged(View* view,
                                   const mojo::Rect& old_bounds,
                                   const mojo::Rect& new_bounds) {}

  virtual void OnViewViewportMetricsChanged(
      View* view,
      const mojo::ViewportMetrics& old_metrics,
      const mojo::ViewportMetrics& new_metrics) {}

  virtual void OnViewFocusChanged(View* gained_focus, View* lost_focus) {}

  virtual void OnViewInputEvent(View* view, const mojo::EventPtr& event) {}

  virtual void OnViewVisibilityChanging(View* view) {}
  virtual void OnViewVisibilityChanged(View* view) {}

  // Invoked when this View's shared properties have changed. This can either
  // be caused by SetSharedProperty() being called locally, or by us receiving
  // a mojo message that this property has changed. If this property has been
  // added, |old_data| is null. If this property was removed, |new_data| is
  // null.
  virtual void OnViewSharedPropertyChanged(
      View* view,
      const std::string& name,
      const std::vector<uint8_t>* old_data,
      const std::vector<uint8_t>* new_data) {}

  // Invoked when SetProperty() or ClearProperty() is called on the window.
  // |key| is either a WindowProperty<T>* (SetProperty, ClearProperty). Either
  // way, it can simply be compared for equality with the property
  // constant. |old| is the old property value, which must be cast to the
  // appropriate type before use.
  virtual void OnViewLocalPropertyChanged(View* view,
                                          const void* key,
                                          intptr_t old) {}

  virtual void OnViewEmbeddedAppDisconnected(View* view) {}

  // Sent when the drawn state changes. This is only sent for the root nodes
  // when embedded.
  virtual void OnViewDrawnChanging(View* view) {}
  virtual void OnViewDrawnChanged(View* view) {}

 protected:
  virtual ~ViewObserver() {}
};

}  // namespace mus

#endif  // COMPONENTS_MUS_PUBLIC_CPP_VIEW_OBSERVER_H_