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

Side by Side Diff: examples/wm_flow/wm/wm.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 | « examples/wm_flow/wm/frame_controller.cc ('k') | mojo/services/public/cpp/view_manager/BUILD.gn » ('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 <vector> 5 #include <vector>
6 6
7 #include "examples/wm_flow/wm/frame_controller.h" 7 #include "examples/wm_flow/wm/frame_controller.h"
8 #include "mojo/application/application_runner_chromium.h" 8 #include "mojo/application/application_runner_chromium.h"
9 #include "mojo/public/c/system/main.h" 9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_delegate.h" 10 #include "mojo/public/cpp/application/application_delegate.h"
11 #include "mojo/public/cpp/application/application_impl.h" 11 #include "mojo/public/cpp/application/application_impl.h"
12 #include "mojo/public/cpp/application/service_provider_impl.h" 12 #include "mojo/public/cpp/application/service_provider_impl.h"
13 #include "mojo/services/public/cpp/view_manager/view_manager.h" 13 #include "mojo/services/public/cpp/view_manager/view_manager.h"
14 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 14 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
15 #include "mojo/services/public/cpp/view_manager/view_observer.h" 15 #include "mojo/services/public/cpp/view_manager/view_observer.h"
16 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" 16 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
17 #include "mojo/services/window_manager/basic_focus_rules.h"
18 #include "mojo/services/window_manager/window_manager_app.h" 17 #include "mojo/services/window_manager/window_manager_app.h"
19 #include "mojo/services/window_manager/window_manager_delegate.h" 18 #include "mojo/services/window_manager/window_manager_delegate.h"
20 #include "mojo/views/views_init.h" 19 #include "mojo/views/views_init.h"
20 #include "ui/aura/window.h"
21 #include "ui/wm/core/focus_rules.h"
22 #include "ui/wm/public/activation_client.h"
21 23
22 namespace examples { 24 namespace examples {
23 25
26 namespace {
27
28 class WMFocusRules : public wm::FocusRules {
29 public:
30 WMFocusRules(mojo::WindowManagerApp* window_manager_app,
31 mojo::View* window_container)
32 : window_container_(window_container),
33 window_manager_app_(window_manager_app) {}
34 virtual ~WMFocusRules() {}
35
36 private:
37 // Overridden from wm::FocusRules:
38 virtual bool IsToplevelWindow(aura::Window* window) const override {
39 return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
40 window_container_;
41 }
42 virtual bool CanActivateWindow(aura::Window* window) const override {
43 return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
44 window_container_;
45 }
46 virtual bool CanFocusWindow(aura::Window* window) const override {
47 return true;
48 }
49 virtual aura::Window* GetToplevelWindow(aura::Window* window) const override {
50 mojo::View* view = mojo::WindowManagerApp::GetViewForWindow(window);
51 while (view->parent() != window_container_) {
52 view = view->parent();
53 // Unparented hierarchy, there is no "top level" window.
54 if (!view)
55 return NULL;
56 }
57
58 return window_manager_app_->GetWindowForViewId(view->id());
59 }
60 virtual aura::Window* GetActivatableWindow(
61 aura::Window* window) const override {
62 return GetToplevelWindow(window);
63 }
64 virtual aura::Window* GetFocusableWindow(
65 aura::Window* window) const override {
66 return window;
67 }
68 virtual aura::Window* GetNextActivatableWindow(
69 aura::Window* ignore) const override {
70 aura::Window* activatable = GetActivatableWindow(ignore);
71 const aura::Window::Windows& children = activatable->parent()->children();
72 for (aura::Window::Windows::const_reverse_iterator it = children.rbegin();
73 it != children.rend(); ++it) {
74 if (*it != ignore)
75 return *it;
76 }
77 return NULL;
78 }
79
80 mojo::View* window_container_;
81 mojo::WindowManagerApp* window_manager_app_;
82
83 DISALLOW_COPY_AND_ASSIGN(WMFocusRules);
84 };
85
86 } // namespace
87
24 class SimpleWM : public mojo::ApplicationDelegate, 88 class SimpleWM : public mojo::ApplicationDelegate,
25 public mojo::ViewManagerDelegate, 89 public mojo::ViewManagerDelegate,
26 public mojo::WindowManagerDelegate, 90 public mojo::WindowManagerDelegate,
27 public mojo::ViewObserver { 91 public mojo::ViewObserver {
28 public: 92 public:
29 SimpleWM() 93 SimpleWM()
30 : shell_(nullptr), 94 : shell_(nullptr),
31 window_manager_app_(new mojo::WindowManagerApp(this, this)), 95 window_manager_app_(new mojo::WindowManagerApp(this, this)),
32 view_manager_(NULL), 96 view_manager_(NULL),
33 root_(NULL), 97 root_(NULL),
(...skipping 23 matching lines...) Expand all
57 mojo::View* root, 121 mojo::View* root,
58 mojo::ServiceProviderImpl* exported_services, 122 mojo::ServiceProviderImpl* exported_services,
59 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override { 123 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override {
60 view_manager_ = view_manager; 124 view_manager_ = view_manager;
61 root_ = root; 125 root_ = root;
62 126
63 window_container_ = mojo::View::Create(view_manager_); 127 window_container_ = mojo::View::Create(view_manager_);
64 window_container_->SetBounds(root_->bounds()); 128 window_container_->SetBounds(root_->bounds());
65 root_->AddChild(window_container_); 129 root_->AddChild(window_container_);
66 130
67 window_manager_app_->InitFocus(scoped_ptr<mojo::FocusRules>( 131 window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(),
68 new mojo::BasicFocusRules(window_manager_app_.get(), 132 window_container_));
69 window_container_)));
70 } 133 }
71 virtual void OnViewManagerDisconnected( 134 virtual void OnViewManagerDisconnected(
72 mojo::ViewManager* view_manager) override { 135 mojo::ViewManager* view_manager) override {
73 view_manager_ = NULL; 136 view_manager_ = NULL;
74 root_ = NULL; 137 root_ = NULL;
75 } 138 }
76 139
77 // Overridden from mojo::WindowManagerDelegate: 140 // Overridden from mojo::WindowManagerDelegate:
78 virtual void Embed( 141 virtual void Embed(
79 const mojo::String& url, 142 const mojo::String& url,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 176
114 mojo::View* CreateTopLevelWindow(mojo::View** app_view) { 177 mojo::View* CreateTopLevelWindow(mojo::View** app_view) {
115 mojo::View* frame_view = mojo::View::Create(view_manager_); 178 mojo::View* frame_view = mojo::View::Create(view_manager_);
116 mojo::Rect rect; 179 mojo::Rect rect;
117 rect.x = next_window_origin_.x(); 180 rect.x = next_window_origin_.x();
118 rect.y = next_window_origin_.y(); 181 rect.y = next_window_origin_.y();
119 rect.width = rect.height = 400; 182 rect.width = rect.height = 400;
120 frame_view->SetBounds(rect); 183 frame_view->SetBounds(rect);
121 next_window_origin_.Offset(50, 50); 184 next_window_origin_.Offset(50, 50);
122 185
186 aura::client::ActivationClient* client = aura::client::GetActivationClient(
187 window_manager_app_->host()->window());
123 new FrameController( 188 new FrameController(
124 shell_, frame_view, app_view, window_manager_app_.get()); 189 shell_, frame_view, app_view, client, window_manager_app_.get());
125 return frame_view; 190 return frame_view;
126 } 191 }
127 192
128 mojo::Shell* shell_; 193 mojo::Shell* shell_;
129 194
130 scoped_ptr<mojo::ViewsInit> views_init_; 195 scoped_ptr<mojo::ViewsInit> views_init_;
131 196
132 scoped_ptr<mojo::WindowManagerApp> window_manager_app_; 197 scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
133 198
134 mojo::ViewManager* view_manager_; 199 mojo::ViewManager* view_manager_;
135 mojo::View* root_; 200 mojo::View* root_;
136 mojo::View* window_container_; 201 mojo::View* window_container_;
137 202
138 gfx::Point next_window_origin_; 203 gfx::Point next_window_origin_;
139 204
140 DISALLOW_COPY_AND_ASSIGN(SimpleWM); 205 DISALLOW_COPY_AND_ASSIGN(SimpleWM);
141 }; 206 };
142 207
143 } // namespace examples 208 } // namespace examples
144 209
145 MojoResult MojoMain(MojoHandle shell_handle) { 210 MojoResult MojoMain(MojoHandle shell_handle) {
146 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM); 211 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM);
147 return runner.Run(shell_handle); 212 return runner.Run(shell_handle);
148 } 213 }
OLDNEW
« no previous file with comments | « examples/wm_flow/wm/frame_controller.cc ('k') | mojo/services/public/cpp/view_manager/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698