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

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

Issue 718573002: Revert "Remove aura and make a pure mojo::View version of the aura::Window FocusController." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | examples/wm_flow/wm/frame_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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/public/cpp/view_manager/view.h" 19 #include "mojo/services/public/cpp/view_manager/view.h"
20 #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_delegate.h" 21 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
22 #include "mojo/services/public/cpp/view_manager/view_observer.h" 22 #include "mojo/services/public/cpp/view_manager/view_observer.h"
23 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" 23 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" 24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
25 #include "mojo/services/window_manager/basic_focus_rules.h"
26 #include "mojo/services/window_manager/view_target.h"
27 #include "mojo/services/window_manager/window_manager_app.h" 25 #include "mojo/services/window_manager/window_manager_app.h"
28 #include "mojo/services/window_manager/window_manager_delegate.h" 26 #include "mojo/services/window_manager/window_manager_delegate.h"
29 #include "mojo/views/views_init.h" 27 #include "mojo/views/views_init.h"
28 #include "ui/aura/window.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 "ui/wm/core/focus_rules.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
43 namespace { 43 namespace {
44 44
45 const int kBorderInset = 25; 45 const int kBorderInset = 25;
46 const int kControlPanelWidth = 200; 46 const int kControlPanelWidth = 200;
47 const int kTextfieldHeight = 25; 47 const int kTextfieldHeight = 25;
48 48
49 class WMFocusRules : public wm::FocusRules {
50 public:
51 WMFocusRules(mojo::WindowManagerApp* window_manager_app,
52 mojo::View* window_container)
53 : window_container_(window_container),
54 window_manager_app_(window_manager_app) {}
55 virtual ~WMFocusRules() {}
56
57 private:
58 // Overridden from wm::FocusRules:
59 virtual bool IsToplevelWindow(aura::Window* window) const override {
60 return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
61 window_container_;
62 }
63 virtual bool CanActivateWindow(aura::Window* window) const override {
64 return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
65 window_container_;
66 }
67 virtual bool CanFocusWindow(aura::Window* window) const override {
68 return true;
69 }
70 virtual aura::Window* GetToplevelWindow(aura::Window* window) const override {
71 mojo::View* view = mojo::WindowManagerApp::GetViewForWindow(window);
72 while (view->parent() != window_container_) {
73 view = view->parent();
74 // Unparented hierarchy, there is no "top level" window.
75 if (!view)
76 return NULL;
77 }
78
79 return window_manager_app_->GetWindowForViewId(view->id());
80 }
81 virtual aura::Window* GetActivatableWindow(
82 aura::Window* window) const override {
83 return GetToplevelWindow(window);
84 }
85 virtual aura::Window* GetFocusableWindow(
86 aura::Window* window) const override {
87 return window;
88 }
89 virtual aura::Window* GetNextActivatableWindow(
90 aura::Window* ignore) const override {
91 aura::Window* activatable = GetActivatableWindow(ignore);
92 const aura::Window::Windows& children = activatable->parent()->children();
93 for (aura::Window::Windows::const_reverse_iterator it = children.rbegin();
94 it != children.rend(); ++it) {
95 if (*it != ignore)
96 return *it;
97 }
98 return NULL;
99 }
100
101 mojo::View* window_container_;
102 mojo::WindowManagerApp* window_manager_app_;
103
104 DISALLOW_COPY_AND_ASSIGN(WMFocusRules);
105 };
106
49 } // namespace 107 } // namespace
50 108
51 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { 109 class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
52 public: 110 public:
53 explicit WindowManagerConnection(WindowManager* window_manager) 111 explicit WindowManagerConnection(WindowManager* window_manager)
54 : window_manager_(window_manager) {} 112 : window_manager_(window_manager) {}
55 virtual ~WindowManagerConnection() {} 113 virtual ~WindowManagerConnection() {}
56 114
57 private: 115 private:
58 // Overridden from IWindowManager: 116 // Overridden from IWindowManager:
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 : shell_(nullptr), 321 : shell_(nullptr),
264 window_manager_factory_(this), 322 window_manager_factory_(this),
265 launcher_ui_(NULL), 323 launcher_ui_(NULL),
266 view_manager_(NULL), 324 view_manager_(NULL),
267 window_manager_app_(new WindowManagerApp(this, this)), 325 window_manager_app_(new WindowManagerApp(this, this)),
268 app_(NULL) {} 326 app_(NULL) {}
269 327
270 virtual ~WindowManager() { 328 virtual ~WindowManager() {
271 // host() may be destroyed by the time we get here. 329 // host() may be destroyed by the time we get here.
272 // TODO: figure out a way to always cleanly remove handler. 330 // TODO: figure out a way to always cleanly remove handler.
273 331 if (window_manager_app_->host())
274 // TODO(erg): In the aura version, we removed ourselves from the 332 window_manager_app_->host()->window()->RemovePreTargetHandler(this);
275 // PreTargetHandler list here. We may need to do something analogous when
276 // we get event handling without aura working.
277 } 333 }
278 334
279 void CloseWindow(Id view_id) { 335 void CloseWindow(Id view_id) {
280 WindowVector::iterator iter = GetWindowByViewId(view_id); 336 WindowVector::iterator iter = GetWindowByViewId(view_id);
281 DCHECK(iter != windows_.end()); 337 DCHECK(iter != windows_.end());
282 Window* window = *iter; 338 Window* window = *iter;
283 windows_.erase(iter); 339 windows_.erase(iter);
284 window->view()->Destroy(); 340 window->view()->Destroy();
285 } 341 }
286 342
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 Id launcher_ui_id = CreateLauncherUI(); 421 Id launcher_ui_id = CreateLauncherUI();
366 Id control_panel_id = CreateControlPanel(view); 422 Id control_panel_id = CreateControlPanel(view);
367 423
368 root_layout_manager_.reset( 424 root_layout_manager_.reset(
369 new RootLayoutManager(view_manager, root, 425 new RootLayoutManager(view_manager, root,
370 content_view_id_, 426 content_view_id_,
371 launcher_ui_id, 427 launcher_ui_id,
372 control_panel_id)); 428 control_panel_id));
373 root->AddObserver(root_layout_manager_.get()); 429 root->AddObserver(root_layout_manager_.get());
374 430
375 // TODO(erg): In the aura version, we explicitly added ourselves as a 431 window_manager_app_->host()->window()->AddPreTargetHandler(this);
376 // PreTargetHandler to the window() here. We probably have to do something
377 // analogous here.
378 432
379 window_manager_app_->InitFocus(scoped_ptr<mojo::FocusRules>( 433 window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(),
380 new mojo::BasicFocusRules(window_manager_app_.get(), 434 view));
381 view)));
382 } 435 }
383 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { 436 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
384 DCHECK_EQ(view_manager_, view_manager); 437 DCHECK_EQ(view_manager_, view_manager);
385 view_manager_ = NULL; 438 view_manager_ = NULL;
386 base::MessageLoop::current()->Quit(); 439 base::MessageLoop::current()->Quit();
387 } 440 }
388 441
389 // Overridden from WindowManagerDelegate: 442 // Overridden from WindowManagerDelegate:
390 virtual void Embed( 443 virtual void Embed(
391 const String& url, 444 const String& url,
392 InterfaceRequest<ServiceProvider> service_provider) override { 445 InterfaceRequest<ServiceProvider> service_provider) override {
393 const Id kInvalidSourceViewId = 0; 446 const Id kInvalidSourceViewId = 0;
394 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); 447 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url);
395 } 448 }
396 449
397 // Overridden from ui::EventHandler: 450 // Overridden from ui::EventHandler:
398 virtual void OnEvent(ui::Event* event) override { 451 virtual void OnEvent(ui::Event* event) override {
399 View* view = WindowManagerApp::GetViewForViewTarget( 452 View* view = WindowManagerApp::GetViewForWindow(
400 static_cast<ViewTarget*>(event->target())); 453 static_cast<aura::Window*>(event->target()));
401 if (event->type() == ui::ET_MOUSE_PRESSED && 454 if (event->type() == ui::ET_MOUSE_PRESSED &&
402 !IsDescendantOfKeyboard(view)) { 455 !IsDescendantOfKeyboard(view)) {
403 view->SetFocus(); 456 view->SetFocus();
404 } 457 }
405 } 458 }
406 459
407 void OnLaunch(uint32 source_view_id, 460 void OnLaunch(uint32 source_view_id,
408 Target requested_target, 461 Target requested_target,
409 const mojo::String& url) { 462 const mojo::String& url) {
410 Target target = debug_panel_->navigation_target(); 463 Target target = debug_panel_->navigation_target();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 window_manager_->RequestNavigate(view_id_, target, request.Pass()); 601 window_manager_->RequestNavigate(view_id_, target, request.Pass());
549 } 602 }
550 603
551 } // namespace examples 604 } // namespace examples
552 } // namespace mojo 605 } // namespace mojo
553 606
554 MojoResult MojoMain(MojoHandle shell_handle) { 607 MojoResult MojoMain(MojoHandle shell_handle) {
555 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); 608 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager);
556 return runner.Run(shell_handle); 609 return runner.Run(shell_handle);
557 } 610 }
OLDNEW
« no previous file with comments | « no previous file | examples/wm_flow/wm/frame_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698