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/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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 return blink::WebScreenOrientationLockAny; | 85 return blink::WebScreenOrientationLockAny; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { | 91 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { |
| 92 public: | 92 public: |
| 93 AppWindow(int task_id, | 93 AppWindow(int task_id, |
| 94 const std::string app_id, | 94 const std::string app_id, |
| 95 views::Widget* widget, | |
|
khmel
2016/09/14 23:42:19
Setting widget is legacy code for one of the first
| |
| 95 ArcAppWindowLauncherController* owner) | 96 ArcAppWindowLauncherController* owner) |
| 96 : task_id_(task_id), app_id_(app_id), owner_(owner) {} | 97 : task_id_(task_id), app_id_(app_id), widget_(widget), owner_(owner) {} |
| 97 ~AppWindow() {} | 98 ~AppWindow() {} |
| 98 | 99 |
| 99 void SetController(ArcAppWindowLauncherItemController* controller) { | 100 void SetController(ArcAppWindowLauncherItemController* controller) { |
| 100 DCHECK(!controller_ && controller); | 101 DCHECK(!controller_ && controller); |
| 101 controller_ = controller; | 102 controller_ = controller; |
| 102 } | 103 } |
| 103 | 104 |
| 104 void ResetController() { controller_ = nullptr; } | 105 void ResetController() { controller_ = nullptr; } |
| 105 | 106 |
| 106 void SetFullscreenMode(FullScreenMode mode) { | 107 void SetFullscreenMode(FullScreenMode mode) { |
| 107 DCHECK(mode != FullScreenMode::NOT_DEFINED); | 108 DCHECK(mode != FullScreenMode::NOT_DEFINED); |
| 108 fullscreen_mode_ = mode; | 109 fullscreen_mode_ = mode; |
| 109 } | 110 } |
| 110 | 111 |
| 111 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } | 112 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } |
| 112 | 113 |
| 113 int task_id() const { return task_id_; } | 114 int task_id() const { return task_id_; } |
| 114 | 115 |
| 115 ash::ShelfID shelf_id() const { return shelf_id_; } | 116 ash::ShelfID shelf_id() const { return shelf_id_; } |
| 116 | 117 |
| 117 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } | 118 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } |
| 118 | 119 |
| 119 views::Widget* widget() const { return widget_; } | 120 views::Widget* widget() const { return widget_; } |
| 120 | 121 |
| 121 void set_widget(views::Widget* widget) { widget_ = widget; } | |
| 122 | |
| 123 ArcAppWindowLauncherItemController* controller() { return controller_; } | 122 ArcAppWindowLauncherItemController* controller() { return controller_; } |
| 124 | 123 |
| 125 const std::string app_id() { return app_id_; } | 124 const std::string app_id() { return app_id_; } |
| 126 | 125 |
| 127 // ui::BaseWindow: | 126 // ui::BaseWindow: |
| 128 bool IsActive() const override { | 127 bool IsActive() const override { |
| 129 return widget_ && widget_->IsActive() && | 128 return widget_->IsActive() && owner_->active_task_id_ == task_id_; |
| 130 owner_->active_task_id_ == task_id_; | |
| 131 } | 129 } |
| 132 | 130 |
| 133 bool IsMaximized() const override { | 131 bool IsMaximized() const override { |
| 134 NOTREACHED(); | 132 NOTREACHED(); |
| 135 return false; | 133 return false; |
| 136 } | 134 } |
| 137 | 135 |
| 138 bool IsMinimized() const override { | 136 bool IsMinimized() const override { |
| 139 NOTREACHED(); | 137 NOTREACHED(); |
| 140 return false; | 138 return false; |
| 141 } | 139 } |
| 142 | 140 |
| 143 bool IsFullscreen() const override { | 141 bool IsFullscreen() const override { |
| 144 NOTREACHED(); | 142 NOTREACHED(); |
| 145 return false; | 143 return false; |
| 146 } | 144 } |
| 147 | 145 |
| 148 gfx::NativeWindow GetNativeWindow() const override { | 146 gfx::NativeWindow GetNativeWindow() const override { |
| 149 return widget_ ? widget_->GetNativeWindow() : nullptr; | 147 return widget_->GetNativeWindow(); |
| 150 } | 148 } |
| 151 | 149 |
| 152 gfx::Rect GetRestoredBounds() const override { | 150 gfx::Rect GetRestoredBounds() const override { |
| 153 NOTREACHED(); | 151 NOTREACHED(); |
| 154 return gfx::Rect(); | 152 return gfx::Rect(); |
| 155 } | 153 } |
| 156 | 154 |
| 157 ui::WindowShowState GetRestoredState() const override { | 155 ui::WindowShowState GetRestoredState() const override { |
| 158 NOTREACHED(); | 156 NOTREACHED(); |
| 159 return ui::SHOW_STATE_NORMAL; | 157 return ui::SHOW_STATE_NORMAL; |
| 160 } | 158 } |
| 161 | 159 |
| 162 gfx::Rect GetBounds() const override { | 160 gfx::Rect GetBounds() const override { |
| 163 NOTREACHED(); | 161 NOTREACHED(); |
| 164 return gfx::Rect(); | 162 return gfx::Rect(); |
| 165 } | 163 } |
| 166 | 164 |
| 167 void Show() override { | 165 void Show() override { widget_->Show(); } |
|
khmel
2016/09/14 23:42:19
This is needed to correctly restore from clicking
| |
| 168 // TODO(khmel): support window minimizing. | |
| 169 } | |
| 170 | 166 |
| 171 void ShowInactive() override { NOTREACHED(); } | 167 void ShowInactive() override { NOTREACHED(); } |
| 172 | 168 |
| 173 void Hide() override { NOTREACHED(); } | 169 void Hide() override { NOTREACHED(); } |
| 174 | 170 |
| 175 void Close() override { arc::CloseTask(task_id_); } | 171 void Close() override { arc::CloseTask(task_id_); } |
| 176 | 172 |
| 177 void Activate() override { arc::SetTaskActive(task_id_); } | 173 void Activate() override { widget_->Activate(); } |
|
khmel
2016/09/14 23:42:19
As discussed let use wayland protocol whenever pos
| |
| 178 | 174 |
| 179 void Deactivate() override { NOTREACHED(); } | 175 void Deactivate() override { NOTREACHED(); } |
| 180 | 176 |
| 181 void Maximize() override { NOTREACHED(); } | 177 void Maximize() override { NOTREACHED(); } |
| 182 | 178 |
| 183 void Minimize() override { | 179 void Minimize() override { widget_->Minimize(); } |
| 184 if (widget_) | |
| 185 widget_->Minimize(); | |
| 186 } | |
| 187 | 180 |
| 188 void Restore() override { NOTREACHED(); } | 181 void Restore() override { NOTREACHED(); } |
| 189 | 182 |
| 190 void SetBounds(const gfx::Rect& bounds) override { NOTREACHED(); } | 183 void SetBounds(const gfx::Rect& bounds) override { NOTREACHED(); } |
| 191 | 184 |
| 192 void FlashFrame(bool flash) override { NOTREACHED(); } | 185 void FlashFrame(bool flash) override { NOTREACHED(); } |
| 193 | 186 |
| 194 bool IsAlwaysOnTop() const override { | 187 bool IsAlwaysOnTop() const override { |
| 195 NOTREACHED(); | 188 NOTREACHED(); |
| 196 return false; | 189 return false; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 210 bool has_requested_orientation_lock() const { | 203 bool has_requested_orientation_lock() const { |
| 211 return has_requested_orientation_lock_; | 204 return has_requested_orientation_lock_; |
| 212 } | 205 } |
| 213 | 206 |
| 214 private: | 207 private: |
| 215 int task_id_; | 208 int task_id_; |
| 216 ash::ShelfID shelf_id_ = 0; | 209 ash::ShelfID shelf_id_ = 0; |
| 217 std::string app_id_; | 210 std::string app_id_; |
| 218 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; | 211 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; |
| 219 // Unowned pointers | 212 // Unowned pointers |
| 213 views::Widget* widget_; | |
|
Mr4D (OOO till 08-26)
2016/09/15 14:03:19
could this be then const?
khmel
2016/09/15 15:43:27
Indeed
| |
| 220 ArcAppWindowLauncherController* owner_; | 214 ArcAppWindowLauncherController* owner_; |
| 221 ArcAppWindowLauncherItemController* controller_ = nullptr; | 215 ArcAppWindowLauncherItemController* controller_ = nullptr; |
| 222 // Unowned pointer, represents host Arc window. | 216 // Unowned pointer, represents host Arc window. |
| 223 views::Widget* widget_ = nullptr; | |
| 224 | 217 |
| 225 arc::mojom::OrientationLock requested_orientation_lock_ = | 218 arc::mojom::OrientationLock requested_orientation_lock_ = |
| 226 arc::mojom::OrientationLock::NONE; | 219 arc::mojom::OrientationLock::NONE; |
| 227 bool has_requested_orientation_lock_ = false; | 220 bool has_requested_orientation_lock_ = false; |
| 228 | 221 |
| 229 DISALLOW_COPY_AND_ASSIGN(AppWindow); | 222 DISALLOW_COPY_AND_ASSIGN(AppWindow); |
| 230 }; | 223 }; |
| 231 | 224 |
| 232 ArcAppWindowLauncherController::ArcAppWindowLauncherController( | 225 ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
| 233 ChromeLauncherController* owner, | 226 ChromeLauncherController* owner, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 } | 281 } |
| 289 | 282 |
| 290 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { | 283 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { |
| 291 // Arc windows has type WINDOW_TYPE_NORMAL. | 284 // Arc windows has type WINDOW_TYPE_NORMAL. |
| 292 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) | 285 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) |
| 293 return; | 286 return; |
| 294 observed_windows_.push_back(window); | 287 observed_windows_.push_back(window); |
| 295 window->AddObserver(this); | 288 window->AddObserver(this); |
| 296 } | 289 } |
| 297 | 290 |
| 298 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( | 291 void ArcAppWindowLauncherController::OnWindowVisibilityChanged( |
|
khmel
2016/09/14 23:42:19
Quite tricky case. We used OnWindowVisibilityChang
Mr4D (OOO till 08-26)
2016/09/15 14:03:19
You might want to add a comment here towards that.
khmel
2016/09/15 15:43:27
Done.
| |
| 299 aura::Window* window, | 292 aura::Window* window, |
| 300 bool visible) { | 293 bool visible) { |
| 301 // The application id property should be set at this time. | 294 // The application id property should be set at this time. |
| 302 if (visible && observed_profile_ == owner()->GetProfile()) | 295 if (visible && observed_profile_ == owner()->GetProfile()) |
| 303 AttachControllerToWindowIfNeeded(window); | 296 AttachControllerToWindowIfNeeded(window); |
| 304 } | 297 } |
| 305 | 298 |
| 306 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { | 299 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { |
| 307 auto it = | 300 auto it = |
| 308 std::find(observed_windows_.begin(), observed_windows_.end(), window); | 301 std::find(observed_windows_.begin(), observed_windows_.end(), window); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 if (GetAppWindowForTask(task_id)) | 355 if (GetAppWindowForTask(task_id)) |
| 363 return; | 356 return; |
| 364 | 357 |
| 365 // Create controller if we have task info. | 358 // Create controller if we have task info. |
| 366 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); | 359 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); |
| 367 if (it == task_id_to_shelf_app_id_.end()) | 360 if (it == task_id_to_shelf_app_id_.end()) |
| 368 return; | 361 return; |
| 369 | 362 |
| 370 const std::string& app_id = it->second; | 363 const std::string& app_id = it->second; |
| 371 | 364 |
| 372 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); | 365 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 373 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); | 366 DCHECK(widget); |
| 367 std::unique_ptr<AppWindow> app_window( | |
| 368 new AppWindow(task_id, app_id, widget, this)); | |
| 374 RegisterApp(app_window.get()); | 369 RegisterApp(app_window.get()); |
| 375 DCHECK(app_window->controller()); | 370 DCHECK(app_window->controller()); |
| 376 ash::SetShelfIDForWindow(app_window->shelf_id(), window); | 371 ash::SetShelfIDForWindow(app_window->shelf_id(), window); |
| 377 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( | 372 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( |
| 378 window, | 373 window, |
| 379 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); | 374 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); |
| 380 if (ash::WmShell::Get() | 375 if (ash::WmShell::Get() |
| 381 ->maximize_mode_controller() | 376 ->maximize_mode_controller() |
| 382 ->IsMaximizeModeWindowManagerEnabled()) { | 377 ->IsMaximizeModeWindowManagerEnabled()) { |
| 383 SetOrientationLockForAppWindow(app_window.get()); | 378 SetOrientationLockForAppWindow(app_window.get()); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 630 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 636 // Resolve the orientation when it first resolved. | 631 // Resolve the orientation when it first resolved. |
| 637 orientation_lock = GetCurrentOrientation(); | 632 orientation_lock = GetCurrentOrientation(); |
| 638 app_window->set_requested_orientation_lock(orientation_lock); | 633 app_window->set_requested_orientation_lock(orientation_lock); |
| 639 } | 634 } |
| 640 | 635 |
| 641 ash::Shell* shell = ash::Shell::GetInstance(); | 636 ash::Shell* shell = ash::Shell::GetInstance(); |
| 642 shell->screen_orientation_controller()->LockOrientationForWindow( | 637 shell->screen_orientation_controller()->LockOrientationForWindow( |
| 643 window, BlinkOrientationLockFromMojom(orientation_lock)); | 638 window, BlinkOrientationLockFromMojom(orientation_lock)); |
| 644 } | 639 } |
| OLD | NEW |