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

Side by Side Diff: chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc

Issue 2356213003: [Merge-M54] arc: Support Arc window showing/hiding on a user's profile switch. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" 4 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
5 5
6 #include <string> 6 #include <string>
7 7
8 #include "ash/common/shelf/shelf_delegate.h" 8 #include "ash/common/shelf/shelf_delegate.h"
9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
10 #include "ash/common/wm/window_state.h" 10 #include "ash/common/wm/window_state.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 return task_id; 98 return task_id;
99 } 99 }
100 100
101 } // namespace 101 } // namespace
102 102
103 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { 103 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
104 public: 104 public:
105 AppWindow(int task_id, 105 AppWindow(int task_id,
106 const std::string app_id, 106 const std::string app_id,
107 views::Widget* widget,
107 ArcAppWindowLauncherController* owner) 108 ArcAppWindowLauncherController* owner)
108 : task_id_(task_id), app_id_(app_id), owner_(owner) {} 109 : task_id_(task_id), app_id_(app_id), widget_(widget), owner_(owner) {}
109 ~AppWindow() {} 110 ~AppWindow() {}
110 111
111 void SetController(ArcAppWindowLauncherItemController* controller) { 112 void SetController(ArcAppWindowLauncherItemController* controller) {
112 DCHECK(!controller_ && controller); 113 DCHECK(!controller_ && controller);
113 controller_ = controller; 114 controller_ = controller;
114 } 115 }
115 116
116 void ResetController() { controller_ = nullptr; } 117 void ResetController() { controller_ = nullptr; }
117 118
118 void SetFullscreenMode(FullScreenMode mode) { 119 void SetFullscreenMode(FullScreenMode mode) {
119 DCHECK(mode != FullScreenMode::NOT_DEFINED); 120 DCHECK(mode != FullScreenMode::NOT_DEFINED);
120 fullscreen_mode_ = mode; 121 fullscreen_mode_ = mode;
121 } 122 }
122 123
123 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } 124 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; }
124 125
125 int task_id() const { return task_id_; } 126 int task_id() const { return task_id_; }
126 127
127 ash::ShelfID shelf_id() const { return shelf_id_; } 128 ash::ShelfID shelf_id() const { return shelf_id_; }
128 129
129 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } 130 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; }
130 131
131 views::Widget* widget() const { return widget_; } 132 views::Widget* widget() const { return widget_; }
132 133
133 void set_widget(views::Widget* widget) { widget_ = widget; }
134
135 ArcAppWindowLauncherItemController* controller() { return controller_; } 134 ArcAppWindowLauncherItemController* controller() { return controller_; }
136 135
137 const std::string app_id() { return app_id_; } 136 const std::string app_id() { return app_id_; }
138 137
139 // ui::BaseWindow: 138 // ui::BaseWindow:
140 bool IsActive() const override { 139 bool IsActive() const override {
141 return widget_ && widget_->IsActive() && 140 return widget_->IsActive() && owner_->active_task_id_ == task_id_;
142 owner_->active_task_id_ == task_id_;
143 } 141 }
144 142
145 bool IsMaximized() const override { 143 bool IsMaximized() const override {
146 NOTREACHED(); 144 NOTREACHED();
147 return false; 145 return false;
148 } 146 }
149 147
150 bool IsMinimized() const override { 148 bool IsMinimized() const override {
151 NOTREACHED(); 149 NOTREACHED();
152 return false; 150 return false;
153 } 151 }
154 152
155 bool IsFullscreen() const override { 153 bool IsFullscreen() const override {
156 NOTREACHED(); 154 NOTREACHED();
157 return false; 155 return false;
158 } 156 }
159 157
160 gfx::NativeWindow GetNativeWindow() const override { 158 gfx::NativeWindow GetNativeWindow() const override {
161 return widget_ ? widget_->GetNativeWindow() : nullptr; 159 return widget_->GetNativeWindow();
162 } 160 }
163 161
164 gfx::Rect GetRestoredBounds() const override { 162 gfx::Rect GetRestoredBounds() const override {
165 NOTREACHED(); 163 NOTREACHED();
166 return gfx::Rect(); 164 return gfx::Rect();
167 } 165 }
168 166
169 ui::WindowShowState GetRestoredState() const override { 167 ui::WindowShowState GetRestoredState() const override {
170 NOTREACHED(); 168 NOTREACHED();
171 return ui::SHOW_STATE_NORMAL; 169 return ui::SHOW_STATE_NORMAL;
172 } 170 }
173 171
174 gfx::Rect GetBounds() const override { 172 gfx::Rect GetBounds() const override {
175 NOTREACHED(); 173 NOTREACHED();
176 return gfx::Rect(); 174 return gfx::Rect();
177 } 175 }
178 176
179 void Show() override { 177 void Show() override { widget_->Show(); }
180 // TODO(khmel): support window minimizing.
181 }
182 178
183 void ShowInactive() override { NOTREACHED(); } 179 void ShowInactive() override { NOTREACHED(); }
184 180
185 void Hide() override { NOTREACHED(); } 181 void Hide() override { NOTREACHED(); }
186 182
187 void Close() override { arc::CloseTask(task_id_); } 183 void Close() override { arc::CloseTask(task_id_); }
188 184
189 void Activate() override { arc::SetTaskActive(task_id_); } 185 void Activate() override { widget_->Activate(); }
190 186
191 void Deactivate() override { NOTREACHED(); } 187 void Deactivate() override { NOTREACHED(); }
192 188
193 void Maximize() override { NOTREACHED(); } 189 void Maximize() override { NOTREACHED(); }
194 190
195 void Minimize() override { 191 void Minimize() override { widget_->Minimize(); }
196 if (widget_)
197 widget_->Minimize();
198 }
199 192
200 void Restore() override { NOTREACHED(); } 193 void Restore() override { NOTREACHED(); }
201 194
202 void SetBounds(const gfx::Rect& bounds) override { NOTREACHED(); } 195 void SetBounds(const gfx::Rect& bounds) override { NOTREACHED(); }
203 196
204 void FlashFrame(bool flash) override { NOTREACHED(); } 197 void FlashFrame(bool flash) override { NOTREACHED(); }
205 198
206 bool IsAlwaysOnTop() const override { 199 bool IsAlwaysOnTop() const override {
207 NOTREACHED(); 200 NOTREACHED();
208 return false; 201 return false;
(...skipping 13 matching lines...) Expand all
222 bool has_requested_orientation_lock() const { 215 bool has_requested_orientation_lock() const {
223 return has_requested_orientation_lock_; 216 return has_requested_orientation_lock_;
224 } 217 }
225 218
226 private: 219 private:
227 int task_id_; 220 int task_id_;
228 ash::ShelfID shelf_id_ = 0; 221 ash::ShelfID shelf_id_ = 0;
229 std::string app_id_; 222 std::string app_id_;
230 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; 223 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED;
231 // Unowned pointers 224 // Unowned pointers
225 views::Widget* const widget_;
232 ArcAppWindowLauncherController* owner_; 226 ArcAppWindowLauncherController* owner_;
233 ArcAppWindowLauncherItemController* controller_ = nullptr; 227 ArcAppWindowLauncherItemController* controller_ = nullptr;
234 // Unowned pointer, represents host Arc window. 228 // Unowned pointer, represents host Arc window.
235 views::Widget* widget_ = nullptr;
236 229
237 arc::mojom::OrientationLock requested_orientation_lock_ = 230 arc::mojom::OrientationLock requested_orientation_lock_ =
238 arc::mojom::OrientationLock::NONE; 231 arc::mojom::OrientationLock::NONE;
239 bool has_requested_orientation_lock_ = false; 232 bool has_requested_orientation_lock_ = false;
240 233
241 DISALLOW_COPY_AND_ASSIGN(AppWindow); 234 DISALLOW_COPY_AND_ASSIGN(AppWindow);
242 }; 235 };
243 236
244 ArcAppWindowLauncherController::ArcAppWindowLauncherController( 237 ArcAppWindowLauncherController::ArcAppWindowLauncherController(
245 ChromeLauncherController* owner, 238 ChromeLauncherController* owner,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 293 }
301 294
302 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { 295 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) {
303 // Arc windows has type WINDOW_TYPE_NORMAL. 296 // Arc windows has type WINDOW_TYPE_NORMAL.
304 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) 297 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL)
305 return; 298 return;
306 observed_windows_.push_back(window); 299 observed_windows_.push_back(window);
307 window->AddObserver(this); 300 window->AddObserver(this);
308 } 301 }
309 302
310 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( 303 void ArcAppWindowLauncherController::OnWindowVisibilityChanged(
311 aura::Window* window, 304 aura::Window* window,
312 bool visible) { 305 bool visible) {
313 // Attach window to multi-user manager now to let it manage visibility state 306 // Attach window to multi-user manager now to let it manage visibility state
314 // of the Arc window correctly. 307 // of the Arc window correctly.
315 if (GetWindowTaskId(window) > 0) { 308 if (GetWindowTaskId(window) > 0) {
316 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( 309 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner(
317 window, 310 window,
318 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); 311 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
319 } 312 }
320 313
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 if (GetAppWindowForTask(task_id)) 372 if (GetAppWindowForTask(task_id))
380 return; 373 return;
381 374
382 // Create controller if we have task info. 375 // Create controller if we have task info.
383 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); 376 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id);
384 if (it == task_id_to_shelf_app_id_.end()) 377 if (it == task_id_to_shelf_app_id_.end())
385 return; 378 return;
386 379
387 const std::string& app_id = it->second; 380 const std::string& app_id = it->second;
388 381
389 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); 382 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
390 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); 383 DCHECK(widget);
384 std::unique_ptr<AppWindow> app_window(
385 new AppWindow(task_id, app_id, widget, this));
391 RegisterApp(app_window.get()); 386 RegisterApp(app_window.get());
392 DCHECK(app_window->controller()); 387 DCHECK(app_window->controller());
393 ash::SetShelfIDForWindow(app_window->shelf_id(), window); 388 ash::SetShelfIDForWindow(app_window->shelf_id(), window);
394 if (ash::WmShell::Get() 389 if (ash::WmShell::Get()
395 ->maximize_mode_controller() 390 ->maximize_mode_controller()
396 ->IsMaximizeModeWindowManagerEnabled()) { 391 ->IsMaximizeModeWindowManagerEnabled()) {
397 SetOrientationLockForAppWindow(app_window.get()); 392 SetOrientationLockForAppWindow(app_window.get());
398 } 393 }
399 task_id_to_app_window_[task_id] = std::move(app_window); 394 task_id_to_app_window_[task_id] = std::move(app_window);
400 } 395 }
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { 644 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
650 // Resolve the orientation when it first resolved. 645 // Resolve the orientation when it first resolved.
651 orientation_lock = GetCurrentOrientation(); 646 orientation_lock = GetCurrentOrientation();
652 app_window->set_requested_orientation_lock(orientation_lock); 647 app_window->set_requested_orientation_lock(orientation_lock);
653 } 648 }
654 649
655 ash::Shell* shell = ash::Shell::GetInstance(); 650 ash::Shell* shell = ash::Shell::GetInstance();
656 shell->screen_orientation_controller()->LockOrientationForWindow( 651 shell->screen_orientation_controller()->LockOrientationForWindow(
657 window, BlinkOrientationLockFromMojom(orientation_lock)); 652 window, BlinkOrientationLockFromMojom(orientation_lock));
658 } 653 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698