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 15 namespace gfx { 16 class Rect; 17 } 18 19 namespace mojo { 20 21 class 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 33 class ViewObserver { 34 public: 35 struct TreeChangeParams { 36 TreeChangeParams(); 37 View* target; 38 View* old_parent; 39 View* new_parent; 40 View* receiver; 41 }; 42 OnTreeChanging(const TreeChangeParams & params)43 virtual void OnTreeChanging(const TreeChangeParams& params) {} OnTreeChanged(const TreeChangeParams & params)44 virtual void OnTreeChanged(const TreeChangeParams& params) {} 45 OnViewReordering(View * view,View * relative_view,OrderDirection direction)46 virtual void OnViewReordering(View* view, 47 View* relative_view, 48 OrderDirection direction) {} OnViewReordered(View * view,View * relative_view,OrderDirection direction)49 virtual void OnViewReordered(View* view, 50 View* relative_view, 51 OrderDirection direction) {} 52 OnViewDestroying(View * view)53 virtual void OnViewDestroying(View* view) {} OnViewDestroyed(View * view)54 virtual void OnViewDestroyed(View* view) {} 55 OnViewBoundsChanging(View * view,const gfx::Rect & old_bounds,const gfx::Rect & new_bounds)56 virtual void OnViewBoundsChanging(View* view, 57 const gfx::Rect& old_bounds, 58 const gfx::Rect& new_bounds) {} OnViewBoundsChanged(View * view,const gfx::Rect & old_bounds,const gfx::Rect & new_bounds)59 virtual void OnViewBoundsChanged(View* view, 60 const gfx::Rect& old_bounds, 61 const gfx::Rect& new_bounds) {} 62 OnViewFocusChanged(View * gained_focus,View * lost_focus)63 virtual void OnViewFocusChanged(View* gained_focus, View* lost_focus) {} 64 OnViewInputEvent(View * view,const EventPtr & event)65 virtual void OnViewInputEvent(View* view, const EventPtr& event) {} 66 67 protected: ~ViewObserver()68 virtual ~ViewObserver() {} 69 }; 70 71 } // namespace mojo 72 73 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_OBSERVER_H_ 74