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

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: LockToCurrent 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;
(...skipping 26 matching lines...) Expand all
105 83
106 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { 84 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) {
107 has_requested_orientation_lock_ = true; 85 has_requested_orientation_lock_ = true;
108 requested_orientation_lock_ = lock; 86 requested_orientation_lock_ = lock;
109 } 87 }
110 88
111 arc::mojom::OrientationLock requested_orientation_lock() const { 89 arc::mojom::OrientationLock requested_orientation_lock() const {
112 return requested_orientation_lock_; 90 return requested_orientation_lock_;
113 } 91 }
114 92
93 void set_lock_to_current(bool lock) { lock_to_current_ = lock; }
94
95 bool lock_to_current() const { return lock_to_current_; }
96
115 void set_app_window(std::unique_ptr<AppWindow> window) { 97 void set_app_window(std::unique_ptr<AppWindow> window) {
116 app_window_ = std::move(window); 98 app_window_ = std::move(window);
117 } 99 }
118 100
119 AppWindow* app_window() { return app_window_.get(); } 101 AppWindow* app_window() { return app_window_.get(); }
120 102
121 private: 103 private:
122 const arc::ArcAppShelfId app_shelf_id_; 104 const arc::ArcAppShelfId app_shelf_id_;
123 bool has_requested_orientation_lock_ = false; 105 bool has_requested_orientation_lock_ = false;
106
107 // If true, the orientation should be locked to the specific
108 // orientation after the requested_orientation_lock is applied.
109 // This is meaningful only if the orientation is one of ::NONE,
110 // ::PORTRAIT or ::LANDSCAPE.
111 bool lock_to_current_ = false;
124 arc::mojom::OrientationLock requested_orientation_lock_ = 112 arc::mojom::OrientationLock requested_orientation_lock_ =
125 arc::mojom::OrientationLock::NONE; 113 arc::mojom::OrientationLock::NONE;
126 std::unique_ptr<AppWindow> app_window_; 114 std::unique_ptr<AppWindow> app_window_;
127 115
128 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo); 116 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo);
129 }; 117 };
130 118
131 // A ui::BaseWindow for a chromeos launcher to control ARC applications. 119 // A ui::BaseWindow for a chromeos launcher to control ARC applications.
132 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { 120 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
133 public: 121 public:
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 533 }
546 534
547 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( 535 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested(
548 int32_t task_id, 536 int32_t task_id,
549 const arc::mojom::OrientationLock orientation_lock) { 537 const arc::mojom::OrientationLock orientation_lock) {
550 // Don't save to AppInfo in prefs because this is requested in runtime. 538 // Don't save to AppInfo in prefs because this is requested in runtime.
551 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); 539 AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
552 DCHECK(info); 540 DCHECK(info);
553 if (!info) 541 if (!info)
554 return; 542 return;
555 info->set_requested_orientation_lock(orientation_lock); 543
544 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
545 info->set_lock_to_current(true);
546 if (!info->has_requested_orientation_lock()) {
547 info->set_requested_orientation_lock(arc::mojom::OrientationLock::NONE);
548 }
549 } else {
550 info->set_requested_orientation_lock(orientation_lock);
551 info->set_lock_to_current(false);
552 }
556 553
557 if (ash::Shell::Get() 554 if (ash::Shell::Get()
558 ->maximize_mode_controller() 555 ->maximize_mode_controller()
559 ->IsMaximizeModeWindowManagerEnabled()) { 556 ->IsMaximizeModeWindowManagerEnabled()) {
560 AppWindow* app_window = info->app_window(); 557 AppWindow* app_window = info->app_window();
561 if (app_window) 558 if (app_window)
562 SetOrientationLockForAppWindow(app_window); 559 SetOrientationLockForAppWindow(app_window);
563 } 560 }
564 } 561 }
565 562
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 685
689 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( 686 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow(
690 AppWindow* app_window) { 687 AppWindow* app_window) {
691 ash::WmWindow* window = 688 ash::WmWindow* window =
692 ash::WmWindow::Get(app_window->widget()->GetNativeWindow()); 689 ash::WmWindow::Get(app_window->widget()->GetNativeWindow());
693 if (!window) 690 if (!window)
694 return; 691 return;
695 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id()); 692 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id());
696 arc::mojom::OrientationLock orientation_lock; 693 arc::mojom::OrientationLock orientation_lock;
697 694
695 bool lock_to_current_orientation = false;
698 if (info->has_requested_orientation_lock()) { 696 if (info->has_requested_orientation_lock()) {
699 orientation_lock = info->requested_orientation_lock(); 697 orientation_lock = info->requested_orientation_lock();
698 lock_to_current_orientation = info->lock_to_current();
jonross 2017/04/04 21:51:32 for Portrait/Landscape + lock_to_current, those re
700 } else { 699 } else {
701 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(observed_profile_); 700 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(observed_profile_);
702 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = 701 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
703 prefs->GetApp(info->app_shelf_id().app_id()); 702 prefs->GetApp(info->app_shelf_id().app_id());
704 if (!app_info) 703 if (!app_info)
705 return; 704 return;
706 orientation_lock = app_info->orientation_lock; 705 orientation_lock = app_info->orientation_lock;
707 } 706 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
708 707 orientation_lock = arc::mojom::OrientationLock::NONE;
709 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { 708 lock_to_current_orientation = true;
710 // Resolve the orientation when it first resolved. 709 }
711 orientation_lock = GetCurrentOrientation();
712 info->set_requested_orientation_lock(orientation_lock);
713 } 710 }
714 ash::Shell* shell = ash::Shell::GetInstance(); 711 ash::Shell* shell = ash::Shell::GetInstance();
715 shell->screen_orientation_controller()->LockOrientationForWindow( 712 shell->screen_orientation_controller()->LockOrientationForWindow(
716 window, BlinkOrientationLockFromMojom(orientation_lock)); 713 window, BlinkOrientationLockFromMojom(orientation_lock),
714 lock_to_current_orientation);
717 } 715 }
718 716
719 // static 717 // static
720 int ArcAppWindowLauncherController::GetWindowTaskId(aura::Window* window) { 718 int ArcAppWindowLauncherController::GetWindowTaskId(aura::Window* window) {
721 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); 719 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window);
722 if (arc_app_id.empty()) 720 if (arc_app_id.empty())
723 return -1; 721 return -1;
724 722
725 int task_id = -1; 723 int task_id = -1;
726 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) 724 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1)
727 return -1; 725 return -1;
728 726
729 return task_id; 727 return task_id;
730 } 728 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698