view_observer.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
1// Copyright 2014 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 MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_OBSERVER_H_ 6#define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_OBSERVER_H_ 7 8#include <vector> 9 10#include "base/basictypes.h" 11 12#include "mojo/services/public/cpp/view_manager/view.h" 13#include "mojo/services/public/interfaces/input_events/input_events.mojom.h" 14 15namespace gfx { 16class Rect; 17} 18 19namespace mojo { 20 21class View; 22 23// A note on -ing and -ed suffixes: 24// 25// -ing methods are called before changes are applied to the local view model. 26// -ed methods are called after changes are applied to the local view model. 27// 28// If the change originated from another connection to the view manager, it's 29// possible that the change has already been applied to the service-side model 30// prior to being called, so for example in the case of OnViewDestroying(), it's 31// possible the view has already been destroyed on the service side. 32 33class ViewObserver { 34 public: 35 struct TreeChangeParams { 36 TreeChangeParams(); 37 View* target; 38 View* old_parent; 39 View* new_parent; 40 View* receiver; 41 }; 42 43 virtual void OnTreeChanging(const TreeChangeParams& params) {} 44 virtual void OnTreeChanged(const TreeChangeParams& params) {} 45 46 virtual void OnViewReordering(View* view, 47 View* relative_view, 48 OrderDirection direction) {} 49 virtual void OnViewReordered(View* view, 50 View* relative_view, 51 OrderDirection direction) {} 52 53 virtual void OnViewDestroying(View* view) {} 54 virtual void OnViewDestroyed(View* view) {} 55 56 virtual void OnViewBoundsChanging(View* view, 57 const gfx::Rect& old_bounds, 58 const gfx::Rect& new_bounds) {} 59 virtual void OnViewBoundsChanged(View* view, 60 const gfx::Rect& old_bounds, 61 const gfx::Rect& new_bounds) {} 62 63 virtual void OnViewFocusChanged(View* gained_focus, View* lost_focus) {} 64 65 virtual void OnViewInputEvent(View* view, const EventPtr& event) {} 66 67 protected: 68 virtual ~ViewObserver() {} 69}; 70 71} // namespace mojo 72 73#endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_OBSERVER_H_ 74