| 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" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 public: | 130 public: |
| 131 virtual ~Delegate() {} | 131 virtual ~Delegate() {} |
| 132 | 132 |
| 133 virtual void ButtonPressed(ControlType type) = 0; | 133 virtual void ButtonPressed(ControlType type) = 0; |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 ControlPanel(Delegate* delegate) : delegate_(delegate), buttons_() {} | 136 ControlPanel(Delegate* delegate) : delegate_(delegate), buttons_() {} |
| 137 | 137 |
| 138 virtual ~ControlPanel() {} | 138 virtual ~ControlPanel() {} |
| 139 | 139 |
| 140 void Initialize(view_manager::Node* node) { | 140 void Initialize(Node* node) { |
| 141 const char* kNames[] = { "Zoom In", "Actual Size", "Zoom Out" }; | 141 const char* kNames[] = { "Zoom In", "Actual Size", "Zoom Out" }; |
| 142 | 142 |
| 143 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; | 143 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
| 144 | 144 |
| 145 widget_delegate->GetContentsView()->SetLayoutManager( | 145 widget_delegate->GetContentsView()->SetLayoutManager( |
| 146 new views::BoxLayout(views::BoxLayout::kHorizontal, 5, 2, 5)); | 146 new views::BoxLayout(views::BoxLayout::kHorizontal, 5, 2, 5)); |
| 147 | 147 |
| 148 widget_delegate->GetContentsView()->set_background( | 148 widget_delegate->GetContentsView()->set_background( |
| 149 views::Background::CreateSolidBackground(SK_ColorLTGRAY)); | 149 views::Background::CreateSolidBackground(SK_ColorLTGRAY)); |
| 150 | 150 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 navigation::NavigationDetailsPtr navigation_details, | 197 navigation::NavigationDetailsPtr navigation_details, |
| 198 navigation::ResponseDetailsPtr response_details) OVERRIDE; | 198 navigation::ResponseDetailsPtr response_details) OVERRIDE; |
| 199 | 199 |
| 200 MediaViewer* viewer_; | 200 MediaViewer* viewer_; |
| 201 | 201 |
| 202 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); | 202 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 class MediaViewer | 205 class MediaViewer |
| 206 : public ApplicationDelegate, | 206 : public ApplicationDelegate, |
| 207 public view_manager::ViewManagerDelegate, | 207 public ViewManagerDelegate, |
| 208 public ControlPanel::Delegate, | 208 public ControlPanel::Delegate, |
| 209 public view_manager::NodeObserver, | 209 public NodeObserver, |
| 210 public InterfaceFactoryWithContext<NavigatorImpl, MediaViewer> { | 210 public InterfaceFactoryWithContext<NavigatorImpl, MediaViewer> { |
| 211 public: | 211 public: |
| 212 MediaViewer() | 212 MediaViewer() |
| 213 : InterfaceFactoryWithContext(this), | 213 : InterfaceFactoryWithContext(this), |
| 214 app_(NULL), | 214 app_(NULL), |
| 215 view_manager_(NULL), | 215 view_manager_(NULL), |
| 216 view_manager_client_factory_(this), | 216 view_manager_client_factory_(this), |
| 217 root_node_(NULL), | 217 root_node_(NULL), |
| 218 control_node_(NULL), | 218 control_node_(NULL), |
| 219 content_node_(NULL), | 219 content_node_(NULL), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 276 } |
| 277 | 277 |
| 278 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 278 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 279 OVERRIDE { | 279 OVERRIDE { |
| 280 connection->AddService(this); | 280 connection->AddService(this); |
| 281 connection->AddService(&view_manager_client_factory_); | 281 connection->AddService(&view_manager_client_factory_); |
| 282 return true; | 282 return true; |
| 283 } | 283 } |
| 284 | 284 |
| 285 void LayoutNodes() { | 285 void LayoutNodes() { |
| 286 view_manager::Node* root = content_node_->parent(); | 286 Node* root = content_node_->parent(); |
| 287 gfx::Rect control_bounds(root->bounds().width(), 28); | 287 gfx::Rect control_bounds(root->bounds().width(), 28); |
| 288 control_node_->SetBounds(control_bounds); | 288 control_node_->SetBounds(control_bounds); |
| 289 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), | 289 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), |
| 290 root->bounds().height() - control_bounds.height()); | 290 root->bounds().height() - control_bounds.height()); |
| 291 content_node_->SetBounds(content_bounds); | 291 content_node_->SetBounds(content_bounds); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // Overridden from view_manager::ViewManagerDelegate: | 294 // Overridden from ViewManagerDelegate: |
| 295 virtual void OnRootAdded(view_manager::ViewManager* view_manager, | 295 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
| 296 view_manager::Node* root) OVERRIDE { | |
| 297 root_node_ = root; | 296 root_node_ = root; |
| 298 view_manager_ = view_manager; | 297 view_manager_ = view_manager; |
| 299 | 298 |
| 300 control_node_ = view_manager::Node::Create(view_manager_); | 299 control_node_ = Node::Create(view_manager_); |
| 301 root_node_->AddChild(control_node_); | 300 root_node_->AddChild(control_node_); |
| 302 | 301 |
| 303 content_node_ = view_manager::Node::Create(view_manager_); | 302 content_node_ = Node::Create(view_manager_); |
| 304 root_node_->AddChild(content_node_); | 303 root_node_->AddChild(content_node_); |
| 305 | 304 |
| 306 control_node_->SetActiveView(view_manager::View::Create(view_manager_)); | 305 control_node_->SetActiveView(View::Create(view_manager_)); |
| 307 control_panel_.Initialize(control_node_); | 306 control_panel_.Initialize(control_node_); |
| 308 | 307 |
| 309 LayoutNodes(); | 308 LayoutNodes(); |
| 310 root_node_->AddObserver(this); | 309 root_node_->AddObserver(this); |
| 311 | 310 |
| 312 if (pending_navigate_request_) { | 311 if (pending_navigate_request_) { |
| 313 scoped_ptr<PendingNavigateRequest> request( | 312 scoped_ptr<PendingNavigateRequest> request( |
| 314 pending_navigate_request_.release()); | 313 pending_navigate_request_.release()); |
| 315 | 314 |
| 316 Navigate(request->node_id, request->navigation_details.Pass(), | 315 Navigate(request->node_id, request->navigation_details.Pass(), |
| 317 request->response_details.Pass()); | 316 request->response_details.Pass()); |
| 318 } | 317 } |
| 319 } | 318 } |
| 320 virtual void OnViewManagerDisconnected( | 319 virtual void OnViewManagerDisconnected( |
| 321 view_manager::ViewManager* view_manager) OVERRIDE { | 320 ViewManager* view_manager) OVERRIDE { |
| 322 DCHECK_EQ(view_manager_, view_manager); | 321 DCHECK_EQ(view_manager_, view_manager); |
| 323 view_manager_ = NULL; | 322 view_manager_ = NULL; |
| 324 base::MessageLoop::current()->Quit(); | 323 base::MessageLoop::current()->Quit(); |
| 325 } | 324 } |
| 326 | 325 |
| 327 // Overridden from ControlPanel::Delegate: | 326 // Overridden from ControlPanel::Delegate: |
| 328 virtual void ButtonPressed(ControlPanel::ControlType type) OVERRIDE { | 327 virtual void ButtonPressed(ControlPanel::ControlType type) OVERRIDE { |
| 329 switch (type) { | 328 switch (type) { |
| 330 case ControlPanel::CONTROL_ZOOM_IN: | 329 case ControlPanel::CONTROL_ZOOM_IN: |
| 331 zoomable_media_->ZoomIn(); | 330 zoomable_media_->ZoomIn(); |
| 332 break; | 331 break; |
| 333 case ControlPanel::CONTROL_ACTUAL_SIZE: | 332 case ControlPanel::CONTROL_ACTUAL_SIZE: |
| 334 zoomable_media_->ZoomToActualSize(); | 333 zoomable_media_->ZoomToActualSize(); |
| 335 break; | 334 break; |
| 336 case ControlPanel::CONTROL_ZOOM_OUT: | 335 case ControlPanel::CONTROL_ZOOM_OUT: |
| 337 zoomable_media_->ZoomOut(); | 336 zoomable_media_->ZoomOut(); |
| 338 break; | 337 break; |
| 339 default: | 338 default: |
| 340 NOTIMPLEMENTED(); | 339 NOTIMPLEMENTED(); |
| 341 } | 340 } |
| 342 } | 341 } |
| 343 | 342 |
| 344 // NodeObserver: | 343 // NodeObserver: |
| 345 virtual void OnNodeBoundsChanged(view_manager::Node* node, | 344 virtual void OnNodeBoundsChanged(Node* node, |
| 346 const gfx::Rect& old_bounds, | 345 const gfx::Rect& old_bounds, |
| 347 const gfx::Rect& new_bounds) OVERRIDE { | 346 const gfx::Rect& new_bounds) OVERRIDE { |
| 348 LayoutNodes(); | 347 LayoutNodes(); |
| 349 } | 348 } |
| 350 virtual void OnNodeDestroyed(view_manager::Node* node) OVERRIDE { | 349 virtual void OnNodeDestroyed(Node* node) OVERRIDE { |
| 351 DCHECK_EQ(node, root_node_); | 350 DCHECK_EQ(node, root_node_); |
| 352 node->RemoveObserver(this); | 351 node->RemoveObserver(this); |
| 353 root_node_ = NULL; | 352 root_node_ = NULL; |
| 354 } | 353 } |
| 355 | 354 |
| 356 std::string GetHandlerForContentType(const std::string& content_type) { | 355 std::string GetHandlerForContentType(const std::string& content_type) { |
| 357 HandlerMap::const_iterator it = handler_map_.find(content_type); | 356 HandlerMap::const_iterator it = handler_map_.find(content_type); |
| 358 return it != handler_map_.end() ? it->second : std::string(); | 357 return it != handler_map_.end() ? it->second : std::string(); |
| 359 } | 358 } |
| 360 | 359 |
| 361 ApplicationImpl* app_; | 360 ApplicationImpl* app_; |
| 362 scoped_ptr<ViewsInit> views_init_; | 361 scoped_ptr<ViewsInit> views_init_; |
| 363 view_manager::ViewManager* view_manager_; | 362 ViewManager* view_manager_; |
| 364 view_manager::ViewManagerClientFactory view_manager_client_factory_; | 363 ViewManagerClientFactory view_manager_client_factory_; |
| 365 view_manager::Node* root_node_; | 364 Node* root_node_; |
| 366 view_manager::Node* control_node_; | 365 Node* control_node_; |
| 367 view_manager::Node* content_node_; | 366 Node* content_node_; |
| 368 ControlPanel control_panel_; | 367 ControlPanel control_panel_; |
| 369 ZoomableMediaPtr zoomable_media_; | 368 ZoomableMediaPtr zoomable_media_; |
| 370 HandlerMap handler_map_; | 369 HandlerMap handler_map_; |
| 371 scoped_ptr<PendingNavigateRequest> pending_navigate_request_; | 370 scoped_ptr<PendingNavigateRequest> pending_navigate_request_; |
| 372 | 371 |
| 373 DISALLOW_COPY_AND_ASSIGN(MediaViewer); | 372 DISALLOW_COPY_AND_ASSIGN(MediaViewer); |
| 374 }; | 373 }; |
| 375 | 374 |
| 376 void NavigatorImpl::Navigate( | 375 void NavigatorImpl::Navigate( |
| 377 uint32_t node_id, | 376 uint32_t node_id, |
| 378 navigation::NavigationDetailsPtr navigation_details, | 377 navigation::NavigationDetailsPtr navigation_details, |
| 379 navigation::ResponseDetailsPtr response_details) { | 378 navigation::ResponseDetailsPtr response_details) { |
| 380 viewer_->Navigate(node_id, navigation_details.Pass(), | 379 viewer_->Navigate(node_id, navigation_details.Pass(), |
| 381 response_details.Pass()); | 380 response_details.Pass()); |
| 382 } | 381 } |
| 383 | 382 |
| 384 } // namespace examples | 383 } // namespace examples |
| 385 | 384 |
| 386 // static | 385 // static |
| 387 ApplicationDelegate* ApplicationDelegate::Create() { | 386 ApplicationDelegate* ApplicationDelegate::Create() { |
| 388 return new examples::MediaViewer; | 387 return new examples::MediaViewer; |
| 389 } | 388 } |
| 390 | 389 |
| 391 } // namespace mojo | 390 } // namespace mojo |
| OLD | NEW |