| 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 28 matching lines...) Expand all Loading... |
| 39 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 enum class FullScreenMode { | 43 enum class FullScreenMode { |
| 44 NOT_DEFINED, // Fullscreen mode was not defined. | 44 NOT_DEFINED, // Fullscreen mode was not defined. |
| 45 ACTIVE, // Fullscreen is activated for an app. | 45 ACTIVE, // Fullscreen is activated for an app. |
| 46 NON_ACTIVE, // Fullscreen was not activated for an app. | 46 NON_ACTIVE, // Fullscreen was not activated for an app. |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 arc::mojom::OrientationLock GetCurrentOrientation() { | |
| 50 if (!display::Display::HasInternalDisplay()) | |
| 51 return arc::mojom::OrientationLock::NONE; | |
| 52 display::Display internal_display = | |
| 53 ash::Shell::GetInstance()->display_manager()->GetDisplayForId( | |
| 54 display::Display::InternalDisplayId()); | |
| 55 | |
| 56 // ChromeOS currently assumes that the internal panel is always | |
| 57 // landscape (ROTATE_0 == landscape). | |
| 58 switch (internal_display.rotation()) { | |
| 59 case display::Display::ROTATE_0: | |
| 60 return arc::mojom::OrientationLock::LANDSCAPE_PRIMARY; | |
| 61 case display::Display::ROTATE_90: | |
| 62 return arc::mojom::OrientationLock::PORTRAIT_PRIMARY; | |
| 63 case display::Display::ROTATE_180: | |
| 64 return arc::mojom::OrientationLock::LANDSCAPE_SECONDARY; | |
| 65 case display::Display::ROTATE_270: | |
| 66 return arc::mojom::OrientationLock::PORTRAIT_SECONDARY; | |
| 67 } | |
| 68 return arc::mojom::OrientationLock::NONE; | |
| 69 } | |
| 70 | |
| 71 blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom( | 49 blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom( |
| 72 arc::mojom::OrientationLock orientation_lock) { | 50 arc::mojom::OrientationLock orientation_lock) { |
| 73 DCHECK_NE(arc::mojom::OrientationLock::CURRENT, orientation_lock); | 51 DCHECK_NE(arc::mojom::OrientationLock::CURRENT, orientation_lock); |
| 74 switch (orientation_lock) { | 52 switch (orientation_lock) { |
| 75 case arc::mojom::OrientationLock::PORTRAIT: | 53 case arc::mojom::OrientationLock::PORTRAIT: |
| 76 return blink::WebScreenOrientationLockPortrait; | 54 return blink::WebScreenOrientationLockPortrait; |
| 77 case arc::mojom::OrientationLock::LANDSCAPE: | 55 case arc::mojom::OrientationLock::LANDSCAPE: |
| 78 return blink::WebScreenOrientationLockLandscape; | 56 return blink::WebScreenOrientationLockLandscape; |
| 79 case arc::mojom::OrientationLock::PORTRAIT_PRIMARY: | 57 case arc::mojom::OrientationLock::PORTRAIT_PRIMARY: |
| 80 return blink::WebScreenOrientationLockPortraitPrimary; | 58 return blink::WebScreenOrientationLockPortraitPrimary; |
| 81 case arc::mojom::OrientationLock::LANDSCAPE_PRIMARY: | 59 case arc::mojom::OrientationLock::LANDSCAPE_PRIMARY: |
| 82 return blink::WebScreenOrientationLockLandscapePrimary; | 60 return blink::WebScreenOrientationLockLandscapePrimary; |
| 83 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY: | 61 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY: |
| 84 return blink::WebScreenOrientationLockPortraitSecondary; | 62 return blink::WebScreenOrientationLockPortraitSecondary; |
| 85 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY: | 63 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY: |
| 86 return blink::WebScreenOrientationLockLandscapeSecondary; | 64 return blink::WebScreenOrientationLockLandscapeSecondary; |
| 87 default: | 65 default: |
| 88 return blink::WebScreenOrientationLockAny; | 66 return blink::WebScreenOrientationLockAny; |
| 89 } | 67 } |
| 90 } | 68 } |
| 91 | 69 |
| 92 } // namespace | 70 } // namespace |
| 93 | 71 |
| 72 using ash::ScreenOrientationController; |
| 73 |
| 94 // The information about the arc application window which has to be kept | 74 // The information about the arc application window which has to be kept |
| 95 // even when its AppWindow is not present. | 75 // even when its AppWindow is not present. |
| 96 class ArcAppWindowLauncherController::AppWindowInfo { | 76 class ArcAppWindowLauncherController::AppWindowInfo { |
| 97 public: | 77 public: |
| 98 explicit AppWindowInfo(const arc::ArcAppShelfId& app_shelf_id) | 78 explicit AppWindowInfo(const arc::ArcAppShelfId& app_shelf_id) |
| 99 : app_shelf_id_(app_shelf_id) {} | 79 : app_shelf_id_(app_shelf_id) {} |
| 100 ~AppWindowInfo() = default; | 80 ~AppWindowInfo() = default; |
| 101 | 81 |
| 102 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; } | 82 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; } |
| 103 | 83 |
| 104 bool has_requested_orientation_lock() const { | 84 bool has_requested_orientation_lock() const { |
| 105 return has_requested_orientation_lock_; | 85 return has_requested_orientation_lock_; |
| 106 } | 86 } |
| 107 | 87 |
| 108 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { | 88 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { |
| 109 has_requested_orientation_lock_ = true; | 89 has_requested_orientation_lock_ = true; |
| 110 requested_orientation_lock_ = lock; | 90 requested_orientation_lock_ = lock; |
| 111 } | 91 } |
| 112 | 92 |
| 113 arc::mojom::OrientationLock requested_orientation_lock() const { | 93 arc::mojom::OrientationLock requested_orientation_lock() const { |
| 114 return requested_orientation_lock_; | 94 return requested_orientation_lock_; |
| 115 } | 95 } |
| 116 | 96 |
| 97 void set_lock_completion_behavior( |
| 98 ScreenOrientationController::LockCompletionBehavior lock_behavior) { |
| 99 lock_completion_behavior_ = lock_behavior; |
| 100 } |
| 101 |
| 102 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior() |
| 103 const { |
| 104 return lock_completion_behavior_; |
| 105 } |
| 106 |
| 117 void set_app_window(std::unique_ptr<AppWindow> window) { | 107 void set_app_window(std::unique_ptr<AppWindow> window) { |
| 118 app_window_ = std::move(window); | 108 app_window_ = std::move(window); |
| 119 } | 109 } |
| 120 | 110 |
| 121 AppWindow* app_window() { return app_window_.get(); } | 111 AppWindow* app_window() { return app_window_.get(); } |
| 122 | 112 |
| 123 private: | 113 private: |
| 124 const arc::ArcAppShelfId app_shelf_id_; | 114 const arc::ArcAppShelfId app_shelf_id_; |
| 125 bool has_requested_orientation_lock_ = false; | 115 bool has_requested_orientation_lock_ = false; |
| 116 |
| 117 // If true, the orientation should be locked to the specific |
| 118 // orientation after the requested_orientation_lock is applied. |
| 119 // This is meaningful only if the orientation is one of ::NONE, |
| 120 // ::PORTRAIT or ::LANDSCAPE. |
| 121 ScreenOrientationController::LockCompletionBehavior |
| 122 lock_completion_behavior_ = |
| 123 ScreenOrientationController::LockCompletionBehavior::None; |
| 126 arc::mojom::OrientationLock requested_orientation_lock_ = | 124 arc::mojom::OrientationLock requested_orientation_lock_ = |
| 127 arc::mojom::OrientationLock::NONE; | 125 arc::mojom::OrientationLock::NONE; |
| 128 std::unique_ptr<AppWindow> app_window_; | 126 std::unique_ptr<AppWindow> app_window_; |
| 129 | 127 |
| 130 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo); | 128 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo); |
| 131 }; | 129 }; |
| 132 | 130 |
| 133 // A ui::BaseWindow for a chromeos launcher to control ARC applications. | 131 // A ui::BaseWindow for a chromeos launcher to control ARC applications. |
| 134 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { | 132 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { |
| 135 public: | 133 public: |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 546 } |
| 549 | 547 |
| 550 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( | 548 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( |
| 551 int32_t task_id, | 549 int32_t task_id, |
| 552 const arc::mojom::OrientationLock orientation_lock) { | 550 const arc::mojom::OrientationLock orientation_lock) { |
| 553 // Don't save to AppInfo in prefs because this is requested in runtime. | 551 // Don't save to AppInfo in prefs because this is requested in runtime. |
| 554 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); | 552 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 555 DCHECK(info); | 553 DCHECK(info); |
| 556 if (!info) | 554 if (!info) |
| 557 return; | 555 return; |
| 558 info->set_requested_orientation_lock(orientation_lock); | 556 |
| 557 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 558 info->set_lock_completion_behavior( |
| 559 ScreenOrientationController::LockCompletionBehavior::DisableSensor); |
| 560 if (!info->has_requested_orientation_lock()) { |
| 561 info->set_requested_orientation_lock(arc::mojom::OrientationLock::NONE); |
| 562 } |
| 563 } else { |
| 564 info->set_requested_orientation_lock(orientation_lock); |
| 565 info->set_lock_completion_behavior( |
| 566 ScreenOrientationController::LockCompletionBehavior::None); |
| 567 } |
| 559 | 568 |
| 560 if (ash::WmShell::Get() | 569 if (ash::WmShell::Get() |
| 561 ->maximize_mode_controller() | 570 ->maximize_mode_controller() |
| 562 ->IsMaximizeModeWindowManagerEnabled()) { | 571 ->IsMaximizeModeWindowManagerEnabled()) { |
| 563 AppWindow* app_window = info->app_window(); | 572 AppWindow* app_window = info->app_window(); |
| 564 if (app_window) | 573 if (app_window) |
| 565 SetOrientationLockForAppWindow(app_window); | 574 SetOrientationLockForAppWindow(app_window); |
| 566 } | 575 } |
| 567 } | 576 } |
| 568 | 577 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 701 |
| 693 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( | 702 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( |
| 694 AppWindow* app_window) { | 703 AppWindow* app_window) { |
| 695 ash::WmWindow* window = | 704 ash::WmWindow* window = |
| 696 ash::WmLookup::Get()->GetWindowForWidget(app_window->widget()); | 705 ash::WmLookup::Get()->GetWindowForWidget(app_window->widget()); |
| 697 if (!window) | 706 if (!window) |
| 698 return; | 707 return; |
| 699 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id()); | 708 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id()); |
| 700 arc::mojom::OrientationLock orientation_lock; | 709 arc::mojom::OrientationLock orientation_lock; |
| 701 | 710 |
| 711 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior = |
| 712 ScreenOrientationController::LockCompletionBehavior::None; |
| 702 if (info->has_requested_orientation_lock()) { | 713 if (info->has_requested_orientation_lock()) { |
| 703 orientation_lock = info->requested_orientation_lock(); | 714 orientation_lock = info->requested_orientation_lock(); |
| 715 lock_completion_behavior = info->lock_completion_behavior(); |
| 704 } else { | 716 } else { |
| 705 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(observed_profile_); | 717 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(observed_profile_); |
| 706 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | 718 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| 707 prefs->GetApp(info->app_shelf_id().app_id()); | 719 prefs->GetApp(info->app_shelf_id().app_id()); |
| 708 if (!app_info) | 720 if (!app_info) |
| 709 return; | 721 return; |
| 710 orientation_lock = app_info->orientation_lock; | 722 orientation_lock = app_info->orientation_lock; |
| 711 } | 723 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 712 | 724 orientation_lock = arc::mojom::OrientationLock::NONE; |
| 713 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 725 lock_completion_behavior = |
| 714 // Resolve the orientation when it first resolved. | 726 ScreenOrientationController::LockCompletionBehavior::DisableSensor; |
| 715 orientation_lock = GetCurrentOrientation(); | 727 } |
| 716 info->set_requested_orientation_lock(orientation_lock); | |
| 717 } | 728 } |
| 718 ash::Shell* shell = ash::Shell::GetInstance(); | 729 ash::Shell* shell = ash::Shell::GetInstance(); |
| 719 shell->screen_orientation_controller()->LockOrientationForWindow( | 730 shell->screen_orientation_controller()->LockOrientationForWindow( |
| 720 window, BlinkOrientationLockFromMojom(orientation_lock)); | 731 window, BlinkOrientationLockFromMojom(orientation_lock), |
| 732 lock_completion_behavior); |
| 721 } | 733 } |
| 722 | 734 |
| 723 // static | 735 // static |
| 724 int ArcAppWindowLauncherController::GetWindowTaskId(aura::Window* window) { | 736 int ArcAppWindowLauncherController::GetWindowTaskId(aura::Window* window) { |
| 725 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); | 737 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); |
| 726 if (arc_app_id.empty()) | 738 if (arc_app_id.empty()) |
| 727 return -1; | 739 return -1; |
| 728 | 740 |
| 729 int task_id = -1; | 741 int task_id = -1; |
| 730 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) | 742 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
| 731 return -1; | 743 return -1; |
| 732 | 744 |
| 733 return task_id; | 745 return task_id; |
| 734 } | 746 } |
| OLD | NEW |