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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "mojo/examples/media_viewer/media_viewer.mojom.h" | 11 #include "mojo/examples/media_viewer/media_viewer.mojom.h" |
12 #include "mojo/public/cpp/application/application_connection.h" | 12 #include "mojo/public/cpp/application/application_connection.h" |
13 #include "mojo/public/cpp/application/application_delegate.h" | 13 #include "mojo/public/cpp/application/application_delegate.h" |
14 #include "mojo/public/cpp/application/application_impl.h" | 14 #include "mojo/public/cpp/application/application_impl.h" |
| 15 #include "mojo/public/cpp/application/interface_factory_with_context.h" |
15 #include "mojo/public/cpp/bindings/interface_impl.h" | 16 #include "mojo/public/cpp/bindings/interface_impl.h" |
16 #include "mojo/services/public/cpp/view_manager/node.h" | 17 #include "mojo/services/public/cpp/view_manager/node.h" |
17 #include "mojo/services/public/cpp/view_manager/node_observer.h" | 18 #include "mojo/services/public/cpp/view_manager/node_observer.h" |
18 #include "mojo/services/public/cpp/view_manager/view.h" | 19 #include "mojo/services/public/cpp/view_manager/view.h" |
19 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 21 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 22 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
21 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 23 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
22 #include "mojo/views/native_widget_view_manager.h" | 24 #include "mojo/views/native_widget_view_manager.h" |
23 #include "mojo/views/views_init.h" | 25 #include "mojo/views/views_init.h" |
24 #include "skia/ext/platform_canvas.h" | 26 #include "skia/ext/platform_canvas.h" |
25 #include "skia/ext/refptr.h" | 27 #include "skia/ext/refptr.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
27 #include "third_party/skia/include/core/SkCanvas.h" | 29 #include "third_party/skia/include/core/SkCanvas.h" |
28 #include "third_party/skia/include/core/SkColor.h" | 30 #include "third_party/skia/include/core/SkColor.h" |
29 #include "third_party/skia/include/core/SkPaint.h" | 31 #include "third_party/skia/include/core/SkPaint.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 180 } |
179 | 181 |
180 Delegate* delegate_; | 182 Delegate* delegate_; |
181 views::Button* buttons_[CONTROL_COUNT]; | 183 views::Button* buttons_[CONTROL_COUNT]; |
182 | 184 |
183 DISALLOW_COPY_AND_ASSIGN(ControlPanel); | 185 DISALLOW_COPY_AND_ASSIGN(ControlPanel); |
184 }; | 186 }; |
185 | 187 |
186 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { | 188 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { |
187 public: | 189 public: |
188 NavigatorImpl(ApplicationConnection* connection, | 190 explicit NavigatorImpl(MediaViewer* viewer) : viewer_(viewer) {} |
189 MediaViewer* viewer) : viewer_(viewer) {} | |
190 virtual ~NavigatorImpl() {} | 191 virtual ~NavigatorImpl() {} |
191 | 192 |
192 private: | 193 private: |
193 // Overridden from navigation::Navigate: | 194 // Overridden from navigation::Navigate: |
194 virtual void Navigate( | 195 virtual void Navigate( |
195 uint32_t node_id, | 196 uint32_t node_id, |
196 navigation::NavigationDetailsPtr navigation_details, | 197 navigation::NavigationDetailsPtr navigation_details, |
197 navigation::ResponseDetailsPtr response_details) OVERRIDE; | 198 navigation::ResponseDetailsPtr response_details) OVERRIDE; |
198 | 199 |
199 MediaViewer* viewer_; | 200 MediaViewer* viewer_; |
200 | 201 |
201 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); | 202 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); |
202 }; | 203 }; |
203 | 204 |
204 class MediaViewer : public ApplicationDelegate, | 205 class MediaViewer |
205 public view_manager::ViewManagerDelegate, | 206 : public ApplicationDelegate, |
206 public ControlPanel::Delegate, | 207 public view_manager::ViewManagerDelegate, |
207 public view_manager::NodeObserver { | 208 public ControlPanel::Delegate, |
| 209 public view_manager::NodeObserver, |
| 210 public InterfaceFactoryWithContext<NavigatorImpl, MediaViewer> { |
208 public: | 211 public: |
209 MediaViewer() : app_(NULL), | 212 MediaViewer() |
210 view_manager_(NULL), | 213 : InterfaceFactoryWithContext(this), |
211 root_node_(NULL), | 214 app_(NULL), |
212 control_node_(NULL), | 215 view_manager_(NULL), |
213 content_node_(NULL), | 216 view_manager_client_factory_(this), |
214 control_panel_(this) { | 217 root_node_(NULL), |
| 218 control_node_(NULL), |
| 219 content_node_(NULL), |
| 220 control_panel_(this) { |
215 handler_map_["image/png"] = "mojo:mojo_png_viewer"; | 221 handler_map_["image/png"] = "mojo:mojo_png_viewer"; |
216 } | 222 } |
217 | 223 |
218 virtual ~MediaViewer() { | 224 virtual ~MediaViewer() { |
219 if (root_node_) | 225 if (root_node_) |
220 root_node_->RemoveObserver(this); | 226 root_node_->RemoveObserver(this); |
221 } | 227 } |
222 | 228 |
223 void Navigate( | 229 void Navigate( |
224 uint32_t node_id, | 230 uint32_t node_id, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 270 |
265 | 271 |
266 // Overridden from ApplicationDelegate: | 272 // Overridden from ApplicationDelegate: |
267 virtual void Initialize(ApplicationImpl* app) OVERRIDE { | 273 virtual void Initialize(ApplicationImpl* app) OVERRIDE { |
268 app_ = app; | 274 app_ = app; |
269 views_init_.reset(new ViewsInit); | 275 views_init_.reset(new ViewsInit); |
270 } | 276 } |
271 | 277 |
272 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 278 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
273 OVERRIDE { | 279 OVERRIDE { |
274 connection->AddService<NavigatorImpl>(this); | 280 connection->AddService(this); |
275 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); | 281 connection->AddService(&view_manager_client_factory_); |
276 return true; | 282 return true; |
277 } | 283 } |
278 | 284 |
279 void LayoutNodes() { | 285 void LayoutNodes() { |
280 view_manager::Node* root = content_node_->parent(); | 286 view_manager::Node* root = content_node_->parent(); |
281 gfx::Rect control_bounds(root->bounds().width(), 28); | 287 gfx::Rect control_bounds(root->bounds().width(), 28); |
282 control_node_->SetBounds(control_bounds); | 288 control_node_->SetBounds(control_bounds); |
283 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), | 289 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), |
284 root->bounds().height() - control_bounds.height()); | 290 root->bounds().height() - control_bounds.height()); |
285 content_node_->SetBounds(content_bounds); | 291 content_node_->SetBounds(content_bounds); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 354 } |
349 | 355 |
350 std::string GetHandlerForContentType(const std::string& content_type) { | 356 std::string GetHandlerForContentType(const std::string& content_type) { |
351 HandlerMap::const_iterator it = handler_map_.find(content_type); | 357 HandlerMap::const_iterator it = handler_map_.find(content_type); |
352 return it != handler_map_.end() ? it->second : std::string(); | 358 return it != handler_map_.end() ? it->second : std::string(); |
353 } | 359 } |
354 | 360 |
355 ApplicationImpl* app_; | 361 ApplicationImpl* app_; |
356 scoped_ptr<ViewsInit> views_init_; | 362 scoped_ptr<ViewsInit> views_init_; |
357 view_manager::ViewManager* view_manager_; | 363 view_manager::ViewManager* view_manager_; |
| 364 view_manager::ViewManagerClientFactory view_manager_client_factory_; |
358 view_manager::Node* root_node_; | 365 view_manager::Node* root_node_; |
359 view_manager::Node* control_node_; | 366 view_manager::Node* control_node_; |
360 view_manager::Node* content_node_; | 367 view_manager::Node* content_node_; |
361 ControlPanel control_panel_; | 368 ControlPanel control_panel_; |
362 ZoomableMediaPtr zoomable_media_; | 369 ZoomableMediaPtr zoomable_media_; |
363 HandlerMap handler_map_; | 370 HandlerMap handler_map_; |
364 scoped_ptr<PendingNavigateRequest> pending_navigate_request_; | 371 scoped_ptr<PendingNavigateRequest> pending_navigate_request_; |
365 | 372 |
366 DISALLOW_COPY_AND_ASSIGN(MediaViewer); | 373 DISALLOW_COPY_AND_ASSIGN(MediaViewer); |
367 }; | 374 }; |
368 | 375 |
369 void NavigatorImpl::Navigate( | 376 void NavigatorImpl::Navigate( |
370 uint32_t node_id, | 377 uint32_t node_id, |
371 navigation::NavigationDetailsPtr navigation_details, | 378 navigation::NavigationDetailsPtr navigation_details, |
372 navigation::ResponseDetailsPtr response_details) { | 379 navigation::ResponseDetailsPtr response_details) { |
373 viewer_->Navigate(node_id, navigation_details.Pass(), | 380 viewer_->Navigate(node_id, navigation_details.Pass(), |
374 response_details.Pass()); | 381 response_details.Pass()); |
375 } | 382 } |
376 | 383 |
377 } // namespace examples | 384 } // namespace examples |
378 | 385 |
379 // static | 386 // static |
380 ApplicationDelegate* ApplicationDelegate::Create() { | 387 ApplicationDelegate* ApplicationDelegate::Create() { |
381 return new examples::MediaViewer; | 388 return new examples::MediaViewer; |
382 } | 389 } |
383 | 390 |
384 } // namespace mojo | 391 } // namespace mojo |
OLD | NEW |