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_VIEW_MANAGER_NODE_H_ 6 #define MOJO_SERVICES_VIEW_MANAGER_NODE_H_ 7 8 #include <vector> 9 10 #include "base/logging.h" 11 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" 12 #include "mojo/services/view_manager/ids.h" 13 #include "mojo/services/view_manager/view_manager_export.h" 14 #include "ui/aura/window.h" 15 #include "ui/aura/window_delegate.h" 16 #include "ui/aura/window_observer.h" 17 18 namespace mojo { 19 namespace view_manager { 20 namespace service { 21 22 class NodeDelegate; 23 class View; 24 25 // Represents a node in the graph. Delegate is informed of interesting events. 26 class MOJO_VIEW_MANAGER_EXPORT Node 27 : public aura::WindowObserver, 28 public aura::WindowDelegate { 29 public: 30 Node(NodeDelegate* delegate, const NodeId& id); 31 virtual ~Node(); 32 33 void set_view_id(const ViewId& view_id) { view_id_ = view_id; } 34 const ViewId& view_id() const { return view_id_; } 35 36 const NodeId& id() const { return id_; } 37 38 void Add(Node* child); 39 void Remove(Node* child); 40 41 void Reorder(Node* child, Node* relative, OrderDirection direction); 42 43 aura::Window* window() { return &window_; } 44 45 const gfx::Rect& bounds() const { return window_.bounds(); } 46 47 const Node* GetParent() const; 48 Node* GetParent() { 49 return const_cast<Node*>(const_cast<const Node*>(this)->GetParent()); 50 } 51 52 const Node* GetRoot() const; 53 Node* GetRoot() { 54 return const_cast<Node*>(const_cast<const Node*>(this)->GetRoot()); 55 } 56 57 std::vector<const Node*> GetChildren() const; 58 std::vector<Node*> GetChildren(); 59 60 bool Contains(const Node* node) const; 61 62 // Sets the view associated with this node. Node does not own its View. 63 void SetView(View* view); 64 View* view() { return view_; } 65 const View* view() const { return view_; } 66 67 private: 68 // WindowObserver overrides: 69 virtual void OnWindowHierarchyChanged( 70 const aura::WindowObserver::HierarchyChangeParams& params) OVERRIDE; 71 72 // WindowDelegate overrides: 73 virtual gfx::Size GetMinimumSize() const OVERRIDE; 74 virtual gfx::Size GetMaximumSize() const OVERRIDE; 75 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, 76 const gfx::Rect& new_bounds) OVERRIDE; 77 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE; 78 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE; 79 virtual bool ShouldDescendIntoChildForEventHandling( 80 aura::Window* child, 81 const gfx::Point& location) OVERRIDE; 82 virtual bool CanFocus() OVERRIDE; 83 virtual void OnCaptureLost() OVERRIDE; 84 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 85 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; 86 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; 87 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; 88 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE; 89 virtual bool HasHitTestMask() const OVERRIDE; 90 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE; 91 92 // ui::EventHandler overrides: 93 virtual void OnEvent(ui::Event* event) OVERRIDE; 94 95 NodeDelegate* delegate_; 96 const NodeId id_; 97 98 // Weak pointer to view associated with this node. 99 View* view_; 100 101 ViewId view_id_; 102 103 aura::Window window_; 104 105 DISALLOW_COPY_AND_ASSIGN(Node); 106 }; 107 108 } // namespace service 109 } // namespace view_manager 110 } // namespace mojo 111 112 #endif // MOJO_SERVICES_VIEW_MANAGER_NODE_H_ 113