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

Side by Side Diff: examples/wm_flow/wm/wm.cc

Issue 698543005: Make a pure mojo::View version of the aura::Window FocusController. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: sky comments 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"
17 #include "mojo/services/window_manager/window_manager_app.h" 18 #include "mojo/services/window_manager/window_manager_app.h"
18 #include "mojo/services/window_manager/window_manager_delegate.h" 19 #include "mojo/services/window_manager/window_manager_delegate.h"
19 #include "mojo/views/views_init.h" 20 #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"
23 21
24 namespace examples { 22 namespace examples {
25 23
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
88 class SimpleWM : public mojo::ApplicationDelegate, 24 class SimpleWM : public mojo::ApplicationDelegate,
89 public mojo::ViewManagerDelegate, 25 public mojo::ViewManagerDelegate,
90 public mojo::WindowManagerDelegate, 26 public mojo::WindowManagerDelegate,
91 public mojo::ViewObserver { 27 public mojo::ViewObserver {
92 public: 28 public:
93 SimpleWM() 29 SimpleWM()
94 : shell_(nullptr), 30 : shell_(nullptr),
95 window_manager_app_(new mojo::WindowManagerApp(this, this)), 31 window_manager_app_(new mojo::WindowManagerApp(this, this)),
96 view_manager_(NULL), 32 view_manager_(NULL),
97 root_(NULL), 33 root_(NULL),
(...skipping 23 matching lines...) Expand all
121 mojo::View* root, 57 mojo::View* root,
122 mojo::ServiceProviderImpl* exported_services, 58 mojo::ServiceProviderImpl* exported_services,
123 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override { 59 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override {
124 view_manager_ = view_manager; 60 view_manager_ = view_manager;
125 root_ = root; 61 root_ = root;
126 62
127 window_container_ = mojo::View::Create(view_manager_); 63 window_container_ = mojo::View::Create(view_manager_);
128 window_container_->SetBounds(root_->bounds()); 64 window_container_->SetBounds(root_->bounds());
129 root_->AddChild(window_container_); 65 root_->AddChild(window_container_);
130 66
131 window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(), 67 window_manager_app_->InitFocus(scoped_ptr<mojo::FocusRules>(
132 window_container_)); 68 new mojo::BasicFocusRules(window_manager_app_.get(),
69 window_container_)));
133 } 70 }
134 virtual void OnViewManagerDisconnected( 71 virtual void OnViewManagerDisconnected(
135 mojo::ViewManager* view_manager) override { 72 mojo::ViewManager* view_manager) override {
136 view_manager_ = NULL; 73 view_manager_ = NULL;
137 root_ = NULL; 74 root_ = NULL;
138 } 75 }
139 76
140 // Overridden from mojo::WindowManagerDelegate: 77 // Overridden from mojo::WindowManagerDelegate:
141 virtual void Embed( 78 virtual void Embed(
142 const mojo::String& url, 79 const mojo::String& url,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 113
177 mojo::View* CreateTopLevelWindow(mojo::View** app_view) { 114 mojo::View* CreateTopLevelWindow(mojo::View** app_view) {
178 mojo::View* frame_view = mojo::View::Create(view_manager_); 115 mojo::View* frame_view = mojo::View::Create(view_manager_);
179 mojo::Rect rect; 116 mojo::Rect rect;
180 rect.x = next_window_origin_.x(); 117 rect.x = next_window_origin_.x();
181 rect.y = next_window_origin_.y(); 118 rect.y = next_window_origin_.y();
182 rect.width = rect.height = 400; 119 rect.width = rect.height = 400;
183 frame_view->SetBounds(rect); 120 frame_view->SetBounds(rect);
184 next_window_origin_.Offset(50, 50); 121 next_window_origin_.Offset(50, 50);
185 122
186 aura::client::ActivationClient* client = aura::client::GetActivationClient(
187 window_manager_app_->host()->window());
188 new FrameController( 123 new FrameController(
189 shell_, frame_view, app_view, client, window_manager_app_.get()); 124 shell_, frame_view, app_view, window_manager_app_.get());
190 return frame_view; 125 return frame_view;
191 } 126 }
192 127
193 mojo::Shell* shell_; 128 mojo::Shell* shell_;
194 129
195 scoped_ptr<mojo::ViewsInit> views_init_; 130 scoped_ptr<mojo::ViewsInit> views_init_;
196 131
197 scoped_ptr<mojo::WindowManagerApp> window_manager_app_; 132 scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
198 133
199 mojo::ViewManager* view_manager_; 134 mojo::ViewManager* view_manager_;
200 mojo::View* root_; 135 mojo::View* root_;
201 mojo::View* window_container_; 136 mojo::View* window_container_;
202 137
203 gfx::Point next_window_origin_; 138 gfx::Point next_window_origin_;
204 139
205 DISALLOW_COPY_AND_ASSIGN(SimpleWM); 140 DISALLOW_COPY_AND_ASSIGN(SimpleWM);
206 }; 141 };
207 142
208 } // namespace examples 143 } // namespace examples
209 144
210 MojoResult MojoMain(MojoHandle shell_handle) { 145 MojoResult MojoMain(MojoHandle shell_handle) {
211 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM); 146 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM);
212 return runner.Run(shell_handle); 147 return runner.Run(shell_handle);
213 } 148 }
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