Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: mojo/examples/media_viewer/media_viewer.cc

Issue 383123006: Preliminary interactive layout of window manager's demo_launcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resize KeyboardManager, sync Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bindings/interface_impl.h" 15 #include "mojo/public/cpp/bindings/interface_impl.h"
16 #include "mojo/services/public/cpp/view_manager/node.h" 16 #include "mojo/services/public/cpp/view_manager/node.h"
17 #include "mojo/services/public/cpp/view_manager/node_observer.h"
17 #include "mojo/services/public/cpp/view_manager/view.h" 18 #include "mojo/services/public/cpp/view_manager/view.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager.h" 19 #include "mojo/services/public/cpp/view_manager/view_manager.h"
19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
20 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" 21 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
21 #include "mojo/views/native_widget_view_manager.h" 22 #include "mojo/views/native_widget_view_manager.h"
22 #include "mojo/views/views_init.h" 23 #include "mojo/views/views_init.h"
23 #include "skia/ext/platform_canvas.h" 24 #include "skia/ext/platform_canvas.h"
24 #include "skia/ext/refptr.h" 25 #include "skia/ext/refptr.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "third_party/skia/include/core/SkCanvas.h" 27 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 navigation::NavigationDetailsPtr navigation_details, 196 navigation::NavigationDetailsPtr navigation_details,
196 navigation::ResponseDetailsPtr response_details) OVERRIDE; 197 navigation::ResponseDetailsPtr response_details) OVERRIDE;
197 198
198 MediaViewer* viewer_; 199 MediaViewer* viewer_;
199 200
200 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); 201 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
201 }; 202 };
202 203
203 class MediaViewer : public ApplicationDelegate, 204 class MediaViewer : public ApplicationDelegate,
204 public view_manager::ViewManagerDelegate, 205 public view_manager::ViewManagerDelegate,
205 public ControlPanel::Delegate { 206 public ControlPanel::Delegate,
207 public view_manager::NodeObserver {
206 public: 208 public:
207 MediaViewer() : app_(NULL), 209 MediaViewer() : app_(NULL),
208 view_manager_(NULL), 210 view_manager_(NULL),
209 control_node_(NULL), 211 control_node_(NULL),
210 content_node_(NULL), 212 content_node_(NULL),
211 control_panel_(this) { 213 control_panel_(this) {
212 handler_map_["image/png"] = "mojo:mojo_png_viewer"; 214 handler_map_["image/png"] = "mojo:mojo_png_viewer";
213 } 215 }
214 216
215 virtual ~MediaViewer() {} 217 virtual ~MediaViewer() {}
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 views_init_.reset(new ViewsInit); 265 views_init_.reset(new ViewsInit);
264 } 266 }
265 267
266 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 268 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
267 OVERRIDE { 269 OVERRIDE {
268 connection->AddService<NavigatorImpl>(this); 270 connection->AddService<NavigatorImpl>(this);
269 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); 271 view_manager::ViewManager::ConfigureIncomingConnection(connection, this);
270 return true; 272 return true;
271 } 273 }
272 274
275 void LayoutNodes() {
276 view_manager::Node* root = content_node_->parent();
277 gfx::Rect control_bounds(root->bounds().width(), 28);
278 control_node_->SetBounds(control_bounds);
279 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(),
280 root->bounds().height() - control_bounds.height());
281 content_node_->SetBounds(content_bounds);
282 }
283
273 // Overridden from view_manager::ViewManagerDelegate: 284 // Overridden from view_manager::ViewManagerDelegate:
274 virtual void OnRootAdded(view_manager::ViewManager* view_manager, 285 virtual void OnRootAdded(view_manager::ViewManager* view_manager,
275 view_manager::Node* root) OVERRIDE { 286 view_manager::Node* root) OVERRIDE {
276 view_manager_ = view_manager; 287 view_manager_ = view_manager;
277 288
278 control_node_ = view_manager::Node::Create(view_manager_); 289 control_node_ = view_manager::Node::Create(view_manager_);
279 root->AddChild(control_node_); 290 root->AddChild(control_node_);
280 gfx::Rect control_bounds(root->bounds().width(), 28);
281 control_node_->SetBounds(control_bounds);
282 control_node_->SetActiveView(view_manager::View::Create(view_manager_));
283
284 control_panel_.Initialize(control_node_);
285 291
286 content_node_ = view_manager::Node::Create(view_manager_); 292 content_node_ = view_manager::Node::Create(view_manager_);
287 root->AddChild(content_node_); 293 root->AddChild(content_node_);
288 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), 294
289 root->bounds().height() - control_bounds.height()); 295 control_node_->SetActiveView(view_manager::View::Create(view_manager_));
290 content_node_->SetBounds(content_bounds); 296 control_panel_.Initialize(control_node_);
297
298 LayoutNodes();
299 root->AddObserver(this);
sky 2014/07/14 19:15:28 You need to remove the observer when done.
hansmuller 2014/07/14 22:16:42 Done.
291 300
292 if (pending_navigate_request_) { 301 if (pending_navigate_request_) {
293 scoped_ptr<PendingNavigateRequest> request( 302 scoped_ptr<PendingNavigateRequest> request(
294 pending_navigate_request_.release()); 303 pending_navigate_request_.release());
295 304
296 Navigate(request->node_id, request->navigation_details.Pass(), 305 Navigate(request->node_id, request->navigation_details.Pass(),
297 request->response_details.Pass()); 306 request->response_details.Pass());
298 } 307 }
299 } 308 }
300 virtual void OnViewManagerDisconnected( 309 virtual void OnViewManagerDisconnected(
(...skipping 13 matching lines...) Expand all
314 zoomable_media_->ZoomToActualSize(); 323 zoomable_media_->ZoomToActualSize();
315 break; 324 break;
316 case ControlPanel::CONTROL_ZOOM_OUT: 325 case ControlPanel::CONTROL_ZOOM_OUT:
317 zoomable_media_->ZoomOut(); 326 zoomable_media_->ZoomOut();
318 break; 327 break;
319 default: 328 default:
320 NOTIMPLEMENTED(); 329 NOTIMPLEMENTED();
321 } 330 }
322 } 331 }
323 332
333 // Overridden from view_manager::NodeObserver
334 virtual void OnNodeBoundsChanged(view_manager::Node* node,
335 const gfx::Rect&,
336 const gfx::Rect&) OVERRIDE {
337 LayoutNodes();
338 }
339
324 std::string GetHandlerForContentType(const std::string& content_type) { 340 std::string GetHandlerForContentType(const std::string& content_type) {
325 HandlerMap::const_iterator it = handler_map_.find(content_type); 341 HandlerMap::const_iterator it = handler_map_.find(content_type);
326 return it != handler_map_.end() ? it->second : std::string(); 342 return it != handler_map_.end() ? it->second : std::string();
327 } 343 }
328 344
329 ApplicationImpl* app_; 345 ApplicationImpl* app_;
330 scoped_ptr<ViewsInit> views_init_; 346 scoped_ptr<ViewsInit> views_init_;
331 view_manager::ViewManager* view_manager_; 347 view_manager::ViewManager* view_manager_;
332 view_manager::Node* control_node_; 348 view_manager::Node* control_node_;
333 view_manager::Node* content_node_; 349 view_manager::Node* content_node_;
(...skipping 14 matching lines...) Expand all
348 } 364 }
349 365
350 } // namespace examples 366 } // namespace examples
351 367
352 // static 368 // static
353 ApplicationDelegate* ApplicationDelegate::Create() { 369 ApplicationDelegate* ApplicationDelegate::Create() {
354 return new examples::MediaViewer; 370 return new examples::MediaViewer;
355 } 371 }
356 372
357 } // namespace mojo 373 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698