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

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

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

Powered by Google App Engine
This is Rietveld 408576698