OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "mojo/examples/window_manager/window_manager.mojom.h" | 9 #include "mojo/examples/window_manager/window_manager.mojom.h" |
10 #include "mojo/public/cpp/application/application.h" | 10 #include "mojo/public/cpp/application/application.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // Overridden from ViewManagerDelegate: | 81 // Overridden from ViewManagerDelegate: |
82 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { | 82 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
83 View* view = View::Create(view_manager); | 83 View* view = View::Create(view_manager); |
84 view->AddObserver(this); | 84 view->AddObserver(this); |
85 root->SetActiveView(view); | 85 root->SetActiveView(view); |
86 root->AddObserver(this); | 86 root->AddObserver(this); |
87 | 87 |
88 roots_[root->id()] = root; | 88 roots_[root->id()] = root; |
89 ProcessPendingNodeColor(root->id()); | 89 ProcessPendingNodeColor(root->id()); |
90 } | 90 } |
91 virtual void OnRootRemoved(ViewManager* view_manager, Node* root) OVERRIDE { | |
92 roots_.erase(root->id()); | |
93 | |
94 std::map<Node*, View*>::const_iterator it = views_to_reap_.find(root); | |
95 if (it != views_to_reap_.end()) | |
96 it->second->Destroy(); | |
97 } | |
98 | 91 |
99 // Overridden from ViewObserver: | 92 // Overridden from ViewObserver: |
100 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { | 93 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { |
101 if (event->action == ui::ET_MOUSE_RELEASED) | 94 if (event->action == ui::ET_MOUSE_RELEASED) |
102 window_manager_->CloseWindow(view->node()->id()); | 95 window_manager_->CloseWindow(view->node()->id()); |
103 } | 96 } |
104 | 97 |
105 // Overridden from NodeObserver: | 98 // Overridden from NodeObserver: |
106 virtual void OnNodeActiveViewChange( | 99 virtual void OnNodeActiveViewChange( |
107 Node* node, | 100 Node* node, |
108 View* old_view, | 101 View* old_view, |
109 View* new_view, | 102 View* new_view, |
110 NodeObserver::DispositionChangePhase phase) OVERRIDE { | 103 NodeObserver::DispositionChangePhase phase) OVERRIDE { |
111 if (new_view == 0) | 104 if (new_view == 0) |
112 views_to_reap_[node] = old_view; | 105 views_to_reap_[node] = old_view; |
113 } | 106 } |
| 107 virtual void OnNodeDestroy( |
| 108 Node* node, |
| 109 NodeObserver::DispositionChangePhase phase) OVERRIDE { |
| 110 if (phase != NodeObserver::DISPOSITION_CHANGED) |
| 111 return; |
| 112 DCHECK(roots_.find(node->id()) != roots_.end()); |
| 113 roots_.erase(node->id()); |
| 114 std::map<Node*, View*>::const_iterator it = views_to_reap_.find(node); |
| 115 if (it != views_to_reap_.end()) |
| 116 it->second->Destroy(); |
| 117 } |
114 | 118 |
115 void ProcessPendingNodeColor(uint32 node_id) { | 119 void ProcessPendingNodeColor(uint32 node_id) { |
116 RootMap::iterator root = roots_.find(node_id); | 120 RootMap::iterator root = roots_.find(node_id); |
117 if (root == roots_.end()) | 121 if (root == roots_.end()) |
118 return; | 122 return; |
119 | 123 |
120 PendingNodeColors::iterator color = pending_node_colors_.find(node_id); | 124 PendingNodeColors::iterator color = pending_node_colors_.find(node_id); |
121 if (color == pending_node_colors_.end()) | 125 if (color == pending_node_colors_.end()) |
122 return; | 126 return; |
123 | 127 |
124 root->second->active_view()->SetColor(color->second); | 128 root->second->active_view()->SetColor(color->second); |
125 pending_node_colors_.erase(color); | 129 pending_node_colors_.erase(color); |
126 } | 130 } |
127 | 131 |
128 | |
129 view_manager::ViewManager* view_manager_; | 132 view_manager::ViewManager* view_manager_; |
130 IWindowManagerPtr window_manager_; | 133 IWindowManagerPtr window_manager_; |
131 std::map<Node*, View*> views_to_reap_; | 134 std::map<Node*, View*> views_to_reap_; |
132 | 135 |
133 typedef std::map<uint32, Node*> RootMap; | 136 typedef std::map<view_manager::Id, Node*> RootMap; |
134 RootMap roots_; | 137 RootMap roots_; |
135 | 138 |
136 // We can receive navigations for nodes we don't have yet. | 139 // We can receive navigations for nodes we don't have yet. |
137 typedef std::map<uint32, SkColor> PendingNodeColors; | 140 typedef std::map<uint32, SkColor> PendingNodeColors; |
138 PendingNodeColors pending_node_colors_; | 141 PendingNodeColors pending_node_colors_; |
139 | 142 |
140 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp); | 143 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp); |
141 }; | 144 }; |
142 | 145 |
143 } // namespace examples | 146 } // namespace examples |
144 | 147 |
145 // static | 148 // static |
146 Application* Application::Create() { | 149 Application* Application::Create() { |
147 return new examples::EmbeddedApp; | 150 return new examples::EmbeddedApp; |
148 } | 151 } |
149 | 152 |
150 } // namespace mojo | 153 } // namespace mojo |
OLD | NEW |