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

Side by Side Diff: examples/window_manager/window_manager.cc

Issue 842553002: Rebuild the debug panel in the browser demo with sky. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Add network dependency. Created 5 years, 11 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "examples/keyboard/keyboard.mojom.h" 7 #include "examples/keyboard/keyboard.mojom.h"
8 #include "examples/window_manager/debug_panel.h" 8 #include "examples/window_manager/debug_panel_host.mojom.h"
9 #include "examples/window_manager/window_manager.mojom.h" 9 #include "examples/window_manager/window_manager.mojom.h"
10 #include "mojo/application/application_runner_chromium.h" 10 #include "mojo/application/application_runner_chromium.h"
11 #include "mojo/converters/geometry/geometry_type_converters.h" 11 #include "mojo/converters/geometry/geometry_type_converters.h"
12 #include "mojo/converters/input_events/input_events_type_converters.h" 12 #include "mojo/converters/input_events/input_events_type_converters.h"
13 #include "mojo/public/c/system/main.h" 13 #include "mojo/public/c/system/main.h"
14 #include "mojo/public/cpp/application/application_connection.h" 14 #include "mojo/public/cpp/application/application_connection.h"
15 #include "mojo/public/cpp/application/application_delegate.h" 15 #include "mojo/public/cpp/application/application_delegate.h"
16 #include "mojo/public/cpp/application/application_impl.h" 16 #include "mojo/public/cpp/application/application_impl.h"
17 #include "mojo/public/cpp/application/interface_factory_impl.h" 17 #include "mojo/public/cpp/application/interface_factory_impl.h"
18 #include "mojo/public/cpp/application/service_provider_impl.h" 18 #include "mojo/public/cpp/application/service_provider_impl.h"
19 #include "mojo/services/input_events/public/interfaces/input_events.mojom.h" 19 #include "mojo/services/input_events/public/interfaces/input_events.mojom.h"
20 #include "mojo/services/navigation/public/interfaces/navigation.mojom.h" 20 #include "mojo/services/navigation/public/interfaces/navigation.mojom.h"
21 #include "mojo/services/view_manager/public/cpp/view.h" 21 #include "mojo/services/view_manager/public/cpp/view.h"
22 #include "mojo/services/view_manager/public/cpp/view_manager.h" 22 #include "mojo/services/view_manager/public/cpp/view_manager.h"
23 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h" 23 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h"
24 #include "mojo/services/view_manager/public/cpp/view_observer.h" 24 #include "mojo/services/view_manager/public/cpp/view_observer.h"
25 #include "mojo/views/views_init.h"
26 #include "services/window_manager/basic_focus_rules.h" 25 #include "services/window_manager/basic_focus_rules.h"
27 #include "services/window_manager/view_target.h" 26 #include "services/window_manager/view_target.h"
28 #include "services/window_manager/window_manager_app.h" 27 #include "services/window_manager/window_manager_app.h"
29 #include "services/window_manager/window_manager_delegate.h" 28 #include "services/window_manager/window_manager_delegate.h"
30 #include "ui/events/event.h" 29 #include "ui/events/event.h"
31 #include "ui/events/event_constants.h" 30 #include "ui/events/event_constants.h"
32 #include "ui/gfx/geometry/size_conversions.h" 31 #include "ui/gfx/geometry/size_conversions.h"
32 #include "url/gurl.h"
33 33
34 #if defined CreateWindow 34 #if defined CreateWindow
35 #undef CreateWindow 35 #undef CreateWindow
36 #endif 36 #endif
37 37
38 namespace mojo { 38 namespace mojo {
39 namespace examples { 39 namespace examples {
40 40
41 class WindowManager; 41 class WindowManager;
42 42
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 InterfaceRequest<NavigatorHost> request) override { 246 InterfaceRequest<NavigatorHost> request) override {
247 BindToRequest(new NavigatorHostImpl(window_manager_, view_->id()), 247 BindToRequest(new NavigatorHostImpl(window_manager_, view_->id()),
248 &request); 248 &request);
249 } 249 }
250 250
251 WindowManager* window_manager_; 251 WindowManager* window_manager_;
252 View* view_; 252 View* view_;
253 }; 253 };
254 254
255 class WindowManager : public ApplicationDelegate, 255 class WindowManager : public ApplicationDelegate,
256 public DebugPanel::Delegate, 256 public examples::DebugPanelHost,
257 public ViewManagerDelegate, 257 public ViewManagerDelegate,
258 public window_manager::WindowManagerDelegate, 258 public window_manager::WindowManagerDelegate,
259 public ui::EventHandler { 259 public ui::EventHandler,
260 public mojo::InterfaceFactory<examples::DebugPanelHost> {
260 public: 261 public:
261 WindowManager() 262 WindowManager()
262 : shell_(nullptr), 263 : shell_(nullptr),
263 window_manager_factory_(this), 264 window_manager_factory_(this),
264 launcher_ui_(NULL), 265 launcher_ui_(NULL),
265 view_manager_(NULL), 266 view_manager_(NULL),
266 window_manager_app_(new window_manager::WindowManagerApp(this, this)), 267 window_manager_app_(new window_manager::WindowManagerApp(this, this)),
267 app_(NULL) {} 268 navigation_target_(TARGET_DEFAULT),
269 app_(NULL),
270 binding_(this) {}
268 271
269 virtual ~WindowManager() { 272 virtual ~WindowManager() {
270 // host() may be destroyed by the time we get here. 273 // host() may be destroyed by the time we get here.
271 // TODO: figure out a way to always cleanly remove handler. 274 // TODO: figure out a way to always cleanly remove handler.
272 275
273 // TODO(erg): In the aura version, we removed ourselves from the 276 // TODO(erg): In the aura version, we removed ourselves from the
274 // PreTargetHandler list here. We may need to do something analogous when 277 // PreTargetHandler list here. We may need to do something analogous when
275 // we get event handling without aura working. 278 // we get event handling without aura working.
276 } 279 }
277 280
(...skipping 30 matching lines...) Expand all
308 // See comment in ShowKeyboard() about validating args. 311 // See comment in ShowKeyboard() about validating args.
309 if (keyboard_manager_) 312 if (keyboard_manager_)
310 keyboard_manager_->Hide(view_id); 313 keyboard_manager_->Hide(view_id);
311 } 314 }
312 315
313 void DidNavigateLocally(uint32 source_view_id, const mojo::String& url) { 316 void DidNavigateLocally(uint32 source_view_id, const mojo::String& url) {
314 LOG(ERROR) << "DidNavigateLocally: source_view_id: " << source_view_id 317 LOG(ERROR) << "DidNavigateLocally: source_view_id: " << source_view_id
315 << " url: " << url.To<std::string>(); 318 << " url: " << url.To<std::string>();
316 } 319 }
317 320
318 // Overridden from DebugPanel::Delegate: 321 void RequestNavigate(uint32 source_view_id,
319 virtual void CloseTopWindow() override { 322 Target target,
323 URLRequestPtr request) {
324 OnLaunch(source_view_id, target, request->url);
325 }
326
327 // Overridden from mojo::DebugPanelHost:
328 void CloseTopWindow() override {
320 if (!windows_.empty()) 329 if (!windows_.empty())
321 CloseWindow(windows_.back()->view()->id()); 330 CloseWindow(windows_.back()->view()->id());
322 } 331 }
323 332
324 virtual void RequestNavigate(uint32 source_view_id, 333 void NavigateTo(const String& url) override {
325 Target target, 334 OnLaunch(control_panel_id_, TARGET_NEW_NODE, url);
326 URLRequestPtr request) override { 335 }
327 OnLaunch(source_view_id, target, request->url); 336
337 void SetNavigationTarget(Target t) override {
338 navigation_target_ = t;
339 }
340
341 // mojo::InterfaceFactory<examples::DebugPanelHost> implementation.
342 void Create(
343 mojo::ApplicationConnection* connection,
344 mojo::InterfaceRequest<examples::DebugPanelHost> request) override {
345 binding_.Bind(request.Pass());
328 } 346 }
329 347
330 private: 348 private:
331 typedef std::vector<Window*> WindowVector; 349 typedef std::vector<Window*> WindowVector;
332 350
333 // Overridden from ApplicationDelegate: 351 // Overridden from ApplicationDelegate:
334 virtual void Initialize(ApplicationImpl* app) override { 352 virtual void Initialize(ApplicationImpl* app) override {
335 shell_ = app->shell(); 353 shell_ = app->shell();
336 app_ = app; 354 app_ = app;
337 views_init_.reset(new ViewsInit); 355 // FIXME: Mojo applications don't know their URLs yet:
356 // https://docs.google.com/a/chromium.org/document/d/1AQ2y6ekzvbdaMF5WrUQmne yXJnke-MnYYL4Gz1AKDos
357 url_ = GURL(app->args()[1]);
338 window_manager_app_->Initialize(app); 358 window_manager_app_->Initialize(app);
339 } 359 }
340 360
341 virtual bool ConfigureIncomingConnection( 361 virtual bool ConfigureIncomingConnection(
342 ApplicationConnection* connection) override { 362 ApplicationConnection* connection) override {
343 connection->AddService(&window_manager_factory_); 363 connection->AddService(&window_manager_factory_);
344 window_manager_app_->ConfigureIncomingConnection(connection); 364 window_manager_app_->ConfigureIncomingConnection(connection);
345 return true; 365 return true;
346 } 366 }
347 367
348 // Overridden from ViewManagerDelegate: 368 // Overridden from ViewManagerDelegate:
349 virtual void OnEmbed(View* root, 369 virtual void OnEmbed(View* root,
350 ServiceProviderImpl* exported_services, 370 ServiceProviderImpl* exported_services,
351 scoped_ptr<ServiceProvider> imported_services) override { 371 scoped_ptr<ServiceProvider> imported_services) override {
352 DCHECK(!view_manager_); 372 DCHECK(!view_manager_);
353 view_manager_ = root->view_manager(); 373 view_manager_ = root->view_manager();
354 374
355 View* view = view_manager_->CreateView(); 375 View* view = view_manager_->CreateView();
356 root->AddChild(view); 376 root->AddChild(view);
357 Rect rect; 377 Rect rect;
358 rect.width = root->bounds().width; 378 rect.width = root->bounds().width;
359 rect.height = root->bounds().height; 379 rect.height = root->bounds().height;
360 view->SetBounds(rect); 380 view->SetBounds(rect);
361 view->SetVisible(true); 381 view->SetVisible(true);
362 content_view_id_ = view->id(); 382 content_view_id_ = view->id();
363 383
364 Id launcher_ui_id = CreateLauncherUI(); 384 Id launcher_ui_id = CreateLauncherUI();
365 Id control_panel_id = CreateControlPanel(view); 385 control_panel_id_ = CreateControlPanel(view);
366 386
367 root_layout_manager_.reset( 387 root_layout_manager_.reset(
368 new RootLayoutManager(view_manager_, root, content_view_id_, 388 new RootLayoutManager(view_manager_, root, content_view_id_,
369 launcher_ui_id, control_panel_id)); 389 launcher_ui_id, control_panel_id_));
370 root->AddObserver(root_layout_manager_.get()); 390 root->AddObserver(root_layout_manager_.get());
371 391
372 // TODO(erg): In the aura version, we explicitly added ourselves as a 392 // TODO(erg): In the aura version, we explicitly added ourselves as a
373 // PreTargetHandler to the window() here. We probably have to do something 393 // PreTargetHandler to the window() here. We probably have to do something
374 // analogous here. 394 // analogous here.
375 395
376 window_manager_app_->InitFocus( 396 window_manager_app_->InitFocus(
377 make_scoped_ptr(new window_manager::BasicFocusRules(view))); 397 make_scoped_ptr(new window_manager::BasicFocusRules(view)));
378 } 398 }
379 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { 399 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
(...skipping 16 matching lines...) Expand all
396 static_cast<window_manager::ViewTarget*>(event->target())->view(); 416 static_cast<window_manager::ViewTarget*>(event->target())->view();
397 if (event->type() == ui::ET_MOUSE_PRESSED && 417 if (event->type() == ui::ET_MOUSE_PRESSED &&
398 !IsDescendantOfKeyboard(view)) { 418 !IsDescendantOfKeyboard(view)) {
399 view->SetFocus(); 419 view->SetFocus();
400 } 420 }
401 } 421 }
402 422
403 void OnLaunch(uint32 source_view_id, 423 void OnLaunch(uint32 source_view_id,
404 Target requested_target, 424 Target requested_target,
405 const mojo::String& url) { 425 const mojo::String& url) {
406 Target target = debug_panel_->navigation_target(); 426 Target target = navigation_target_;
407 if (target == TARGET_DEFAULT) { 427 if (target == TARGET_DEFAULT) {
408 if (requested_target != TARGET_DEFAULT) { 428 if (requested_target != TARGET_DEFAULT) {
409 target = requested_target; 429 target = requested_target;
410 } else { 430 } else {
411 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin 431 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin
412 // are different? 432 // are different?
413 target = TARGET_SOURCE_NODE; 433 target = TARGET_SOURCE_NODE;
414 } 434 }
415 } 435 }
416 436
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 501
482 Rect bounds; 502 Rect bounds;
483 bounds.x = root->bounds().width - kControlPanelWidth - kBorderInset; 503 bounds.x = root->bounds().width - kControlPanelWidth - kBorderInset;
484 bounds.y = kBorderInset * 2 + kTextfieldHeight; 504 bounds.y = kBorderInset * 2 + kTextfieldHeight;
485 bounds.width = kControlPanelWidth; 505 bounds.width = kControlPanelWidth;
486 bounds.height = 506 bounds.height =
487 root->bounds().height - kBorderInset * 3 - kTextfieldHeight; 507 root->bounds().height - kBorderInset * 3 - kTextfieldHeight;
488 view->SetBounds(bounds); 508 view->SetBounds(bounds);
489 view->SetVisible(true); 509 view->SetVisible(true);
490 510
491 debug_panel_ = new DebugPanel(this, shell_, view); 511 scoped_ptr<mojo::ServiceProviderImpl> exported_services(
512 new mojo::ServiceProviderImpl());
513 exported_services->AddService(this);
514
515 GURL frame_url = url_.Resolve("/examples/window_manager/debug_panel.sky");
516 debug_panel_ = view->Embed(frame_url.spec(), exported_services.Pass());
517
492 return view->id(); 518 return view->id();
493 } 519 }
494 520
495 WindowVector::iterator GetWindowByViewId(Id view_id) { 521 WindowVector::iterator GetWindowByViewId(Id view_id) {
496 for (std::vector<Window*>::iterator iter = windows_.begin(); 522 for (std::vector<Window*>::iterator iter = windows_.begin();
497 iter != windows_.end(); 523 iter != windows_.end();
498 ++iter) { 524 ++iter) {
499 if ((*iter)->view()->id() == view_id) { 525 if ((*iter)->view()->id() == view_id) {
500 return iter; 526 return iter;
501 } 527 }
502 } 528 }
503 return windows_.end(); 529 return windows_.end();
504 } 530 }
505 531
506 Shell* shell_; 532 Shell* shell_;
507 533
508 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> 534 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager>
509 window_manager_factory_; 535 window_manager_factory_;
510 536
511 scoped_ptr<ViewsInit> views_init_; 537 scoped_ptr<mojo::ServiceProvider> debug_panel_;
512 DebugPanel* debug_panel_;
513 Window* launcher_ui_; 538 Window* launcher_ui_;
514 WindowVector windows_; 539 WindowVector windows_;
515 ViewManager* view_manager_; 540 ViewManager* view_manager_;
516 scoped_ptr<RootLayoutManager> root_layout_manager_; 541 scoped_ptr<RootLayoutManager> root_layout_manager_;
517 542
518 scoped_ptr<window_manager::WindowManagerApp> window_manager_app_; 543 scoped_ptr<window_manager::WindowManagerApp> window_manager_app_;
519 544
520 // Id of the view most content is added to. The keyboard is NOT added here. 545 // Id of the view most content is added to. The keyboard is NOT added here.
521 Id content_view_id_; 546 Id content_view_id_;
522 547
548 // Id of the debug panel.
549 Id control_panel_id_;
550
551 GURL url_;
552 Target navigation_target_;
553
523 scoped_ptr<KeyboardManager> keyboard_manager_; 554 scoped_ptr<KeyboardManager> keyboard_manager_;
524 ApplicationImpl* app_; 555 ApplicationImpl* app_;
525 556
557 mojo::Binding<examples::DebugPanelHost> binding_;
558
526 DISALLOW_COPY_AND_ASSIGN(WindowManager); 559 DISALLOW_COPY_AND_ASSIGN(WindowManager);
527 }; 560 };
528 561
529 void WindowManagerConnection::CloseWindow(Id view_id) { 562 void WindowManagerConnection::CloseWindow(Id view_id) {
530 window_manager_->CloseWindow(view_id); 563 window_manager_->CloseWindow(view_id);
531 } 564 }
532 565
533 void WindowManagerConnection::ShowKeyboard(Id view_id, RectPtr bounds) { 566 void WindowManagerConnection::ShowKeyboard(Id view_id, RectPtr bounds) {
534 window_manager_->ShowKeyboard(view_id, *bounds); 567 window_manager_->ShowKeyboard(view_id, *bounds);
535 } 568 }
(...skipping 10 matching lines...) Expand all
546 window_manager_->RequestNavigate(view_id_, target, request.Pass()); 579 window_manager_->RequestNavigate(view_id_, target, request.Pass());
547 } 580 }
548 581
549 } // namespace examples 582 } // namespace examples
550 } // namespace mojo 583 } // namespace mojo
551 584
552 MojoResult MojoMain(MojoHandle shell_handle) { 585 MojoResult MojoMain(MojoHandle shell_handle) {
553 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); 586 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager);
554 return runner.Run(shell_handle); 587 return runner.Run(shell_handle);
555 } 588 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698