Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/aura/wm_window_aura.h" | 8 #include "ash/aura/wm_window_aura.h" |
| 9 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 return blink::WebScreenOrientationLockAny; | 86 return blink::WebScreenOrientationLockAny; |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { | 92 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { |
| 93 public: | 93 public: |
| 94 AppWindow(int task_id, | 94 AppWindow(int task_id, |
| 95 const std::string app_id, | 95 const std::string app_id, |
| 96 views::Widget* widget, | |
| 96 ArcAppWindowLauncherController* owner) | 97 ArcAppWindowLauncherController* owner) |
| 97 : task_id_(task_id), app_id_(app_id), owner_(owner) {} | 98 : task_id_(task_id), app_id_(app_id), widget_(widget), owner_(owner) {} |
| 98 ~AppWindow() {} | 99 ~AppWindow() {} |
| 99 | 100 |
| 100 void SetController(ArcAppWindowLauncherItemController* controller) { | 101 void SetController(ArcAppWindowLauncherItemController* controller) { |
| 101 DCHECK(!controller_ && controller); | 102 DCHECK(!controller_ && controller); |
| 102 controller_ = controller; | 103 controller_ = controller; |
| 103 } | 104 } |
| 104 | 105 |
| 105 void ResetController() { controller_ = nullptr; } | 106 void ResetController() { controller_ = nullptr; } |
| 106 | 107 |
| 107 void SetFullscreenMode(FullScreenMode mode) { | 108 void SetFullscreenMode(FullScreenMode mode) { |
| 108 DCHECK(mode != FullScreenMode::NOT_DEFINED); | 109 DCHECK(mode != FullScreenMode::NOT_DEFINED); |
| 109 fullscreen_mode_ = mode; | 110 fullscreen_mode_ = mode; |
| 110 } | 111 } |
| 111 | 112 |
| 112 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } | 113 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } |
| 113 | 114 |
| 114 int task_id() const { return task_id_; } | 115 int task_id() const { return task_id_; } |
| 115 | 116 |
| 116 ash::ShelfID shelf_id() const { return shelf_id_; } | 117 ash::ShelfID shelf_id() const { return shelf_id_; } |
| 117 | 118 |
| 118 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } | 119 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } |
| 119 | 120 |
| 120 views::Widget* widget() const { return widget_; } | 121 views::Widget* widget() const { return widget_; } |
| 121 | 122 |
| 122 void set_widget(views::Widget* widget) { widget_ = widget; } | |
| 123 | |
| 124 ArcAppWindowLauncherItemController* controller() { return controller_; } | 123 ArcAppWindowLauncherItemController* controller() { return controller_; } |
| 125 | 124 |
| 126 const std::string app_id() { return app_id_; } | 125 const std::string app_id() { return app_id_; } |
| 127 | 126 |
| 128 // ui::BaseWindow: | 127 // ui::BaseWindow: |
| 129 bool IsActive() const override { | 128 bool IsActive() const override { |
| 130 return widget_ && widget_->IsActive() && | 129 return widget_->IsActive() && owner_->active_task_id_ == task_id_; |
| 131 owner_->active_task_id_ == task_id_; | |
| 132 } | 130 } |
| 133 | 131 |
| 134 bool IsMaximized() const override { | 132 bool IsMaximized() const override { |
| 135 NOTREACHED(); | 133 NOTREACHED(); |
| 136 return false; | 134 return false; |
| 137 } | 135 } |
| 138 | 136 |
| 139 bool IsMinimized() const override { | 137 bool IsMinimized() const override { |
| 140 NOTREACHED(); | 138 NOTREACHED(); |
| 141 return false; | 139 return false; |
| 142 } | 140 } |
| 143 | 141 |
| 144 bool IsFullscreen() const override { | 142 bool IsFullscreen() const override { |
| 145 NOTREACHED(); | 143 NOTREACHED(); |
| 146 return false; | 144 return false; |
| 147 } | 145 } |
| 148 | 146 |
| 149 gfx::NativeWindow GetNativeWindow() const override { | 147 gfx::NativeWindow GetNativeWindow() const override { |
| 150 return widget_ ? widget_->GetNativeWindow() : nullptr; | 148 return widget_->GetNativeWindow(); |
| 151 } | 149 } |
| 152 | 150 |
| 153 gfx::Rect GetRestoredBounds() const override { | 151 gfx::Rect GetRestoredBounds() const override { |
| 154 NOTREACHED(); | 152 NOTREACHED(); |
| 155 return gfx::Rect(); | 153 return gfx::Rect(); |
| 156 } | 154 } |
| 157 | 155 |
| 158 ui::WindowShowState GetRestoredState() const override { | 156 ui::WindowShowState GetRestoredState() const override { |
| 159 NOTREACHED(); | 157 NOTREACHED(); |
| 160 return ui::SHOW_STATE_NORMAL; | 158 return ui::SHOW_STATE_NORMAL; |
| 161 } | 159 } |
| 162 | 160 |
| 163 gfx::Rect GetBounds() const override { | 161 gfx::Rect GetBounds() const override { |
| 164 NOTREACHED(); | 162 NOTREACHED(); |
| 165 return gfx::Rect(); | 163 return gfx::Rect(); |
| 166 } | 164 } |
| 167 | 165 |
| 168 void Show() override { | 166 void Show() override { widget_->Show(); } |
| 169 // TODO(khmel): support window minimizing. | |
| 170 } | |
| 171 | 167 |
| 172 void ShowInactive() override { NOTREACHED(); } | 168 void ShowInactive() override { NOTREACHED(); } |
| 173 | 169 |
| 174 void Hide() override { NOTREACHED(); } | 170 void Hide() override { NOTREACHED(); } |
| 175 | 171 |
| 176 void Close() override { arc::CloseTask(task_id_); } | 172 void Close() override { arc::CloseTask(task_id_); } |
| 177 | 173 |
| 178 void Activate() override { arc::SetTaskActive(task_id_); } | 174 void Activate() override { widget_->Activate(); } |
| 179 | 175 |
| 180 void Deactivate() override { NOTREACHED(); } | 176 void Deactivate() override { NOTREACHED(); } |
| 181 | 177 |
| 182 void Maximize() override { NOTREACHED(); } | 178 void Maximize() override { NOTREACHED(); } |
| 183 | 179 |
| 184 void Minimize() override { | 180 void Minimize() override { widget_->Minimize(); } |
| 185 if (widget_) | |
| 186 widget_->Minimize(); | |
| 187 } | |
| 188 | 181 |
| 189 void Restore() override { NOTREACHED(); } | 182 void Restore() override { NOTREACHED(); } |
| 190 | 183 |
| 191 void SetBounds(const gfx::Rect& bounds) override { NOTREACHED(); } | 184 void SetBounds(const gfx::Rect& bounds) override { NOTREACHED(); } |
| 192 | 185 |
| 193 void FlashFrame(bool flash) override { NOTREACHED(); } | 186 void FlashFrame(bool flash) override { NOTREACHED(); } |
| 194 | 187 |
| 195 bool IsAlwaysOnTop() const override { | 188 bool IsAlwaysOnTop() const override { |
| 196 NOTREACHED(); | 189 NOTREACHED(); |
| 197 return false; | 190 return false; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 211 bool has_requested_orientation_lock() const { | 204 bool has_requested_orientation_lock() const { |
| 212 return has_requested_orientation_lock_; | 205 return has_requested_orientation_lock_; |
| 213 } | 206 } |
| 214 | 207 |
| 215 private: | 208 private: |
| 216 int task_id_; | 209 int task_id_; |
| 217 ash::ShelfID shelf_id_ = 0; | 210 ash::ShelfID shelf_id_ = 0; |
| 218 std::string app_id_; | 211 std::string app_id_; |
| 219 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; | 212 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; |
| 220 // Unowned pointers | 213 // Unowned pointers |
| 214 views::Widget* const widget_; | |
| 221 ArcAppWindowLauncherController* owner_; | 215 ArcAppWindowLauncherController* owner_; |
| 222 ArcAppWindowLauncherItemController* controller_ = nullptr; | 216 ArcAppWindowLauncherItemController* controller_ = nullptr; |
| 223 // Unowned pointer, represents host Arc window. | 217 // Unowned pointer, represents host Arc window. |
| 224 views::Widget* widget_ = nullptr; | |
| 225 | 218 |
| 226 arc::mojom::OrientationLock requested_orientation_lock_ = | 219 arc::mojom::OrientationLock requested_orientation_lock_ = |
| 227 arc::mojom::OrientationLock::NONE; | 220 arc::mojom::OrientationLock::NONE; |
| 228 bool has_requested_orientation_lock_ = false; | 221 bool has_requested_orientation_lock_ = false; |
| 229 | 222 |
| 230 DISALLOW_COPY_AND_ASSIGN(AppWindow); | 223 DISALLOW_COPY_AND_ASSIGN(AppWindow); |
| 231 }; | 224 }; |
| 232 | 225 |
| 233 ArcAppWindowLauncherController::ArcAppWindowLauncherController( | 226 ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
| 234 ChromeLauncherController* owner, | 227 ChromeLauncherController* owner, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 } | 282 } |
| 290 | 283 |
| 291 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { | 284 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { |
| 292 // Arc windows has type WINDOW_TYPE_NORMAL. | 285 // Arc windows has type WINDOW_TYPE_NORMAL. |
| 293 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) | 286 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) |
| 294 return; | 287 return; |
| 295 observed_windows_.push_back(window); | 288 observed_windows_.push_back(window); |
| 296 window->AddObserver(this); | 289 window->AddObserver(this); |
| 297 } | 290 } |
| 298 | 291 |
| 299 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( | 292 void ArcAppWindowLauncherController::OnWindowVisibilityChanged( |
| 300 aura::Window* window, | 293 aura::Window* window, |
| 301 bool visible) { | 294 bool visible) { |
| 302 // The application id property should be set at this time. | 295 // The application id property should be set at this time. It is important to |
| 296 // have window->IsVisible set to true before attaching to a controller because | |
| 297 // the window is registered in multi-user manager and this manager may | |
| 298 // consider this new window as hidden for current profile. Multi-user manager | |
| 299 // uses OnWindowVisibilityChanging event to update window state. | |
| 303 if (visible && observed_profile_ == owner()->GetProfile()) | 300 if (visible && observed_profile_ == owner()->GetProfile()) |
|
oshima
2016/09/15 17:14:32
It looks to me that observerd_profile_ and owner()
khmel
2016/09/15 17:32:15
Actually not, observerd_profile_ is set on creatio
| |
| 304 AttachControllerToWindowIfNeeded(window); | 301 AttachControllerToWindowIfNeeded(window); |
| 305 } | 302 } |
| 306 | 303 |
| 307 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { | 304 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { |
| 308 auto it = | 305 auto it = |
| 309 std::find(observed_windows_.begin(), observed_windows_.end(), window); | 306 std::find(observed_windows_.begin(), observed_windows_.end(), window); |
| 310 DCHECK(it != observed_windows_.end()); | 307 DCHECK(it != observed_windows_.end()); |
| 311 observed_windows_.erase(it); | 308 observed_windows_.erase(it); |
| 312 window->RemoveObserver(this); | 309 window->RemoveObserver(this); |
|
oshima
2016/09/15 17:14:32
can you also stop observing if the window belongs
khmel
2016/09/15 17:32:15
Will dig into this in next CLs, there are several
| |
| 313 | 310 |
| 314 auto it_app_window = | 311 auto it_app_window = |
| 315 std::find_if(task_id_to_app_window_.begin(), task_id_to_app_window_.end(), | 312 std::find_if(task_id_to_app_window_.begin(), task_id_to_app_window_.end(), |
| 316 [window](const TaskIdToAppWindow::value_type& pair) { | 313 [window](const TaskIdToAppWindow::value_type& pair) { |
| 317 return pair.second->GetNativeWindow() == window; | 314 return pair.second->GetNativeWindow() == window; |
| 318 }); | 315 }); |
| 319 if (it_app_window != task_id_to_app_window_.end()) { | 316 if (it_app_window != task_id_to_app_window_.end()) { |
| 320 // Note, window may be recreated in some cases, so do not close controller | 317 // Note, window may be recreated in some cases, so do not close controller |
| 321 // on window destroying. Controller will be closed onTaskDestroyed event | 318 // on window destroying. Controller will be closed onTaskDestroyed event |
| 322 // which is generated when actual task is destroyed. | 319 // which is generated when actual task is destroyed. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 if (GetAppWindowForTask(task_id)) | 360 if (GetAppWindowForTask(task_id)) |
| 364 return; | 361 return; |
| 365 | 362 |
| 366 // Create controller if we have task info. | 363 // Create controller if we have task info. |
| 367 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); | 364 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); |
| 368 if (it == task_id_to_shelf_app_id_.end()) | 365 if (it == task_id_to_shelf_app_id_.end()) |
| 369 return; | 366 return; |
| 370 | 367 |
| 371 const std::string& app_id = it->second; | 368 const std::string& app_id = it->second; |
| 372 | 369 |
| 373 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); | 370 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 374 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); | 371 DCHECK(widget); |
| 372 std::unique_ptr<AppWindow> app_window( | |
| 373 new AppWindow(task_id, app_id, widget, this)); | |
| 375 RegisterApp(app_window.get()); | 374 RegisterApp(app_window.get()); |
| 376 DCHECK(app_window->controller()); | 375 DCHECK(app_window->controller()); |
| 377 ash::WmWindowAura::Get(window)->SetIntProperty( | 376 ash::WmWindowAura::Get(window)->SetIntProperty( |
| 378 ash::WmWindowProperty::SHELF_ID, app_window->shelf_id()); | 377 ash::WmWindowProperty::SHELF_ID, app_window->shelf_id()); |
| 379 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( | 378 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( |
| 380 window, | 379 window, |
| 381 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); | 380 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); |
| 382 if (ash::WmShell::Get() | 381 if (ash::WmShell::Get() |
| 383 ->maximize_mode_controller() | 382 ->maximize_mode_controller() |
| 384 ->IsMaximizeModeWindowManagerEnabled()) { | 383 ->IsMaximizeModeWindowManagerEnabled()) { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 636 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 638 // Resolve the orientation when it first resolved. | 637 // Resolve the orientation when it first resolved. |
| 639 orientation_lock = GetCurrentOrientation(); | 638 orientation_lock = GetCurrentOrientation(); |
| 640 app_window->set_requested_orientation_lock(orientation_lock); | 639 app_window->set_requested_orientation_lock(orientation_lock); |
| 641 } | 640 } |
| 642 | 641 |
| 643 ash::Shell* shell = ash::Shell::GetInstance(); | 642 ash::Shell* shell = ash::Shell::GetInstance(); |
| 644 shell->screen_orientation_controller()->LockOrientationForWindow( | 643 shell->screen_orientation_controller()->LockOrientationForWindow( |
| 645 window, BlinkOrientationLockFromMojom(orientation_lock)); | 644 window, BlinkOrientationLockFromMojom(orientation_lock)); |
| 646 } | 645 } |
| OLD | NEW |