| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 4 |
| 5 #include "ui/display/manager/display_manager.h" | 5 #include "ui/display/manager/display_manager.h" |
| 6 | 6 |
| 7 #include "ash/accelerators/accelerator_commands_aura.h" | 7 #include "ash/accelerators/accelerator_commands_aura.h" |
| 8 #include "ash/ash_switches.h" | 8 #include "ash/ash_switches.h" |
| 9 #include "ash/display/display_configuration_controller.h" | 9 #include "ash/display/display_configuration_controller.h" |
| 10 #include "ash/display/display_util.h" | 10 #include "ash/display/display_util.h" |
| 11 #include "ash/display/mirror_window_controller.h" | 11 #include "ash/display/mirror_window_controller.h" |
| 12 #include "ash/display/screen_orientation_controller_chromeos.h" | 12 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 13 #include "ash/display/window_tree_host_manager.h" | 13 #include "ash/display/window_tree_host_manager.h" |
| 14 #include "ash/screen_util.h" | 14 #include "ash/screen_util.h" |
| 15 #include "ash/shared/app_types.h" | 15 #include "ash/shared/app_types.h" |
| 16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "ash/strings/grit/ash_strings.h" | 17 #include "ash/strings/grit/ash_strings.h" |
| 18 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
| 19 #include "ash/test/mirror_window_test_api.h" | 19 #include "ash/test/mirror_window_test_api.h" |
| 20 #include "ash/test/screen_orientation_controller_test_api.h" | 20 #include "ash/test/screen_orientation_controller_test_api.h" |
| 21 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 21 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 22 #include "ash/wm/window_state.h" | 22 #include "ash/wm/window_state.h" |
| 23 #include "ash/wm/window_util.h" | 23 #include "ash/wm/window_util.h" |
| 24 #include "ash/wm_window.h" | |
| 25 #include "base/command_line.h" | 24 #include "base/command_line.h" |
| 26 #include "base/format_macros.h" | 25 #include "base/format_macros.h" |
| 27 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 28 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
| 29 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 30 #include "chromeos/accelerometer/accelerometer_reader.h" | 29 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 31 #include "chromeos/accelerometer/accelerometer_types.h" | 30 #include "chromeos/accelerometer/accelerometer_types.h" |
| 32 #include "ui/aura/client/aura_constants.h" | 31 #include "ui/aura/client/aura_constants.h" |
| 33 #include "ui/aura/env.h" | 32 #include "ui/aura/env.h" |
| 34 #include "ui/aura/window_observer.h" | 33 #include "ui/aura/window_observer.h" |
| (...skipping 2949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2984 .SetFirstDisplayAsInternalDisplay(); | 2983 .SetFirstDisplayAsInternalDisplay(); |
| 2985 ScreenOrientationController* orientation_controller = | 2984 ScreenOrientationController* orientation_controller = |
| 2986 shell->screen_orientation_controller(); | 2985 shell->screen_orientation_controller(); |
| 2987 test::ScreenOrientationControllerTestApi test_api(orientation_controller); | 2986 test::ScreenOrientationControllerTestApi test_api(orientation_controller); |
| 2988 TestObserver test_observer; | 2987 TestObserver test_observer; |
| 2989 orientation_controller->AddObserver(&test_observer); | 2988 orientation_controller->AddObserver(&test_observer); |
| 2990 | 2989 |
| 2991 // Set up windows with portrait,lanscape and any. | 2990 // Set up windows with portrait,lanscape and any. |
| 2992 aura::Window* window_a = CreateTestWindowInShellWithId(0); | 2991 aura::Window* window_a = CreateTestWindowInShellWithId(0); |
| 2993 { | 2992 { |
| 2994 WmWindow* wm_window_a = WmWindow::Get(window_a); | 2993 window_a->SetProperty(aura::client::kAppType, |
| 2995 wm_window_a->SetAppType(static_cast<int>(AppType::CHROME_APP)); | 2994 static_cast<int>(AppType::CHROME_APP)); |
| 2996 orientation_controller->LockOrientationForWindow( | 2995 orientation_controller->LockOrientationForWindow( |
| 2997 wm_window_a, blink::kWebScreenOrientationLockAny, | 2996 window_a, blink::kWebScreenOrientationLockAny, |
| 2998 ScreenOrientationController::LockCompletionBehavior::None); | 2997 ScreenOrientationController::LockCompletionBehavior::None); |
| 2999 } | 2998 } |
| 3000 aura::Window* window_p = CreateTestWindowInShellWithId(0); | 2999 aura::Window* window_p = CreateTestWindowInShellWithId(0); |
| 3001 { | 3000 { |
| 3002 WmWindow* wm_window_p = WmWindow::Get(window_p); | 3001 window_p->SetProperty(aura::client::kAppType, |
| 3003 wm_window_p->SetAppType(static_cast<int>(AppType::CHROME_APP)); | 3002 static_cast<int>(AppType::CHROME_APP)); |
| 3004 orientation_controller->LockOrientationForWindow( | 3003 orientation_controller->LockOrientationForWindow( |
| 3005 wm_window_p, blink::kWebScreenOrientationLockPortrait, | 3004 window_p, blink::kWebScreenOrientationLockPortrait, |
| 3006 ScreenOrientationController::LockCompletionBehavior::None); | 3005 ScreenOrientationController::LockCompletionBehavior::None); |
| 3007 } | 3006 } |
| 3008 aura::Window* window_l = CreateTestWindowInShellWithId(0); | 3007 aura::Window* window_l = CreateTestWindowInShellWithId(0); |
| 3009 { | 3008 { |
| 3010 WmWindow* wm_window_l = WmWindow::Get(window_l); | 3009 window_l->SetProperty(aura::client::kAppType, |
| 3011 wm_window_l->SetAppType(static_cast<int>(AppType::CHROME_APP)); | 3010 static_cast<int>(AppType::CHROME_APP)); |
| 3012 orientation_controller->LockOrientationForWindow( | 3011 orientation_controller->LockOrientationForWindow( |
| 3013 wm_window_l, blink::kWebScreenOrientationLockLandscape, | 3012 window_l, blink::kWebScreenOrientationLockLandscape, |
| 3014 ScreenOrientationController::LockCompletionBehavior::None); | 3013 ScreenOrientationController::LockCompletionBehavior::None); |
| 3015 } | 3014 } |
| 3016 | 3015 |
| 3017 DisplayConfigurationController* configuration_controller = | 3016 DisplayConfigurationController* configuration_controller = |
| 3018 shell->display_configuration_controller(); | 3017 shell->display_configuration_controller(); |
| 3019 display::Screen* screen = display::Screen::GetScreen(); | 3018 display::Screen* screen = display::Screen::GetScreen(); |
| 3020 | 3019 |
| 3021 // Rotate to portrait in clamshell. | 3020 // Rotate to portrait in clamshell. |
| 3022 configuration_controller->SetDisplayRotation( | 3021 configuration_controller->SetDisplayRotation( |
| 3023 screen->GetPrimaryDisplay().id(), display::Display::ROTATE_90, | 3022 screen->GetPrimaryDisplay().id(), display::Display::ROTATE_90, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3112 TEST_F(DisplayManagerOrientationTest, UserRotationLockReverse) { | 3111 TEST_F(DisplayManagerOrientationTest, UserRotationLockReverse) { |
| 3113 Shell* shell = Shell::Get(); | 3112 Shell* shell = Shell::Get(); |
| 3114 display::DisplayManager* display_manager = shell->display_manager(); | 3113 display::DisplayManager* display_manager = shell->display_manager(); |
| 3115 display::test::DisplayManagerTestApi test_api(display_manager); | 3114 display::test::DisplayManagerTestApi test_api(display_manager); |
| 3116 test_api.SetFirstDisplayAsInternalDisplay(); | 3115 test_api.SetFirstDisplayAsInternalDisplay(); |
| 3117 ScreenOrientationController* orientation_controller = | 3116 ScreenOrientationController* orientation_controller = |
| 3118 shell->screen_orientation_controller(); | 3117 shell->screen_orientation_controller(); |
| 3119 | 3118 |
| 3120 // Set up windows with portrait,lanscape and any. | 3119 // Set up windows with portrait,lanscape and any. |
| 3121 aura::Window* window = CreateTestWindowInShellWithId(0); | 3120 aura::Window* window = CreateTestWindowInShellWithId(0); |
| 3122 WmWindow* wm_window = WmWindow::Get(window); | 3121 window->SetProperty(aura::client::kAppType, |
| 3123 wm_window->SetAppType(static_cast<int>(AppType::CHROME_APP)); | 3122 static_cast<int>(AppType::CHROME_APP)); |
| 3124 display::Screen* screen = display::Screen::GetScreen(); | 3123 display::Screen* screen = display::Screen::GetScreen(); |
| 3125 | 3124 |
| 3126 // Just enabling will not save the lock. | 3125 // Just enabling will not save the lock. |
| 3127 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 3126 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 3128 true); | 3127 true); |
| 3129 | 3128 |
| 3130 orientation_controller->LockOrientationForWindow( | 3129 orientation_controller->LockOrientationForWindow( |
| 3131 wm_window, blink::kWebScreenOrientationLockPortrait, | 3130 window, blink::kWebScreenOrientationLockPortrait, |
| 3132 ScreenOrientationController::LockCompletionBehavior::None); | 3131 ScreenOrientationController::LockCompletionBehavior::None); |
| 3133 EXPECT_EQ(display::Display::ROTATE_90, | 3132 EXPECT_EQ(display::Display::ROTATE_90, |
| 3134 screen->GetPrimaryDisplay().rotation()); | 3133 screen->GetPrimaryDisplay().rotation()); |
| 3135 | 3134 |
| 3136 orientation_controller->OnAccelerometerUpdated(portrait_secondary); | 3135 orientation_controller->OnAccelerometerUpdated(portrait_secondary); |
| 3137 | 3136 |
| 3138 EXPECT_EQ(display::Display::ROTATE_270, | 3137 EXPECT_EQ(display::Display::ROTATE_270, |
| 3139 screen->GetPrimaryDisplay().rotation()); | 3138 screen->GetPrimaryDisplay().rotation()); |
| 3140 | 3139 |
| 3141 orientation_controller->OnAccelerometerUpdated(portrait_primary); | 3140 orientation_controller->OnAccelerometerUpdated(portrait_primary); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3158 Shell* shell = Shell::Get(); | 3157 Shell* shell = Shell::Get(); |
| 3159 display::DisplayManager* display_manager = shell->display_manager(); | 3158 display::DisplayManager* display_manager = shell->display_manager(); |
| 3160 display::test::DisplayManagerTestApi(display_manager) | 3159 display::test::DisplayManagerTestApi(display_manager) |
| 3161 .SetFirstDisplayAsInternalDisplay(); | 3160 .SetFirstDisplayAsInternalDisplay(); |
| 3162 ScreenOrientationController* orientation_controller = | 3161 ScreenOrientationController* orientation_controller = |
| 3163 shell->screen_orientation_controller(); | 3162 shell->screen_orientation_controller(); |
| 3164 test::ScreenOrientationControllerTestApi test_api(orientation_controller); | 3163 test::ScreenOrientationControllerTestApi test_api(orientation_controller); |
| 3165 | 3164 |
| 3166 aura::Window* window_a = CreateTestWindowInShellWithId(0); | 3165 aura::Window* window_a = CreateTestWindowInShellWithId(0); |
| 3167 { | 3166 { |
| 3168 WmWindow* wm_window_a = WmWindow::Get(window_a); | 3167 window_a->SetProperty(aura::client::kAppType, |
| 3169 wm_window_a->SetAppType(static_cast<int>(AppType::CHROME_APP)); | 3168 static_cast<int>(AppType::CHROME_APP)); |
| 3170 orientation_controller->LockOrientationForWindow( | 3169 orientation_controller->LockOrientationForWindow( |
| 3171 wm_window_a, blink::kWebScreenOrientationLockAny, | 3170 window_a, blink::kWebScreenOrientationLockAny, |
| 3172 ScreenOrientationController::LockCompletionBehavior::None); | 3171 ScreenOrientationController::LockCompletionBehavior::None); |
| 3173 } | 3172 } |
| 3174 wm::ActivateWindow(window_a); | 3173 wm::ActivateWindow(window_a); |
| 3175 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 3174 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 3176 true); | 3175 true); |
| 3177 | 3176 |
| 3178 orientation_controller->OnAccelerometerUpdated(portrait_primary); | 3177 orientation_controller->OnAccelerometerUpdated(portrait_primary); |
| 3179 | 3178 |
| 3180 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitPrimary, | 3179 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitPrimary, |
| 3181 test_api.GetCurrentOrientation()); | 3180 test_api.GetCurrentOrientation()); |
| 3182 | 3181 |
| 3183 orientation_controller->OnAccelerometerUpdated(portrait_secondary); | 3182 orientation_controller->OnAccelerometerUpdated(portrait_secondary); |
| 3184 | 3183 |
| 3185 aura::Window* window_ps = CreateTestWindowInShellWithId(1); | 3184 aura::Window* window_ps = CreateTestWindowInShellWithId(1); |
| 3186 { | 3185 { |
| 3187 WmWindow* wm_window_ps = WmWindow::Get(window_ps); | 3186 window_ps->SetProperty(aura::client::kAppType, |
| 3188 wm_window_ps->SetAppType(static_cast<int>(AppType::CHROME_APP)); | 3187 static_cast<int>(AppType::CHROME_APP)); |
| 3189 orientation_controller->LockOrientationForWindow( | 3188 orientation_controller->LockOrientationForWindow( |
| 3190 wm_window_ps, blink::kWebScreenOrientationLockPortrait, | 3189 window_ps, blink::kWebScreenOrientationLockPortrait, |
| 3191 ScreenOrientationController::LockCompletionBehavior::DisableSensor); | 3190 ScreenOrientationController::LockCompletionBehavior::DisableSensor); |
| 3192 wm::ActivateWindow(window_ps); | 3191 wm::ActivateWindow(window_ps); |
| 3193 } | 3192 } |
| 3194 | 3193 |
| 3195 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitSecondary, | 3194 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitSecondary, |
| 3196 test_api.GetCurrentOrientation()); | 3195 test_api.GetCurrentOrientation()); |
| 3197 | 3196 |
| 3198 // The orientation should stay portrait secondary. | 3197 // The orientation should stay portrait secondary. |
| 3199 orientation_controller->OnAccelerometerUpdated(portrait_primary); | 3198 orientation_controller->OnAccelerometerUpdated(portrait_primary); |
| 3200 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitSecondary, | 3199 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitSecondary, |
| 3201 test_api.GetCurrentOrientation()); | 3200 test_api.GetCurrentOrientation()); |
| 3202 | 3201 |
| 3203 wm::ActivateWindow(window_a); | 3202 wm::ActivateWindow(window_a); |
| 3204 orientation_controller->OnAccelerometerUpdated(portrait_primary); | 3203 orientation_controller->OnAccelerometerUpdated(portrait_primary); |
| 3205 | 3204 |
| 3206 // Swtching to |window_a| enables rotation. | 3205 // Swtching to |window_a| enables rotation. |
| 3207 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitPrimary, | 3206 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitPrimary, |
| 3208 test_api.GetCurrentOrientation()); | 3207 test_api.GetCurrentOrientation()); |
| 3209 | 3208 |
| 3210 // The orientation has alraedy been locked to secondary once, so | 3209 // The orientation has alraedy been locked to secondary once, so |
| 3211 // it should swtich back to the portrait secondary. | 3210 // it should swtich back to the portrait secondary. |
| 3212 wm::ActivateWindow(window_ps); | 3211 wm::ActivateWindow(window_ps); |
| 3213 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitSecondary, | 3212 EXPECT_EQ(blink::kWebScreenOrientationLockPortraitSecondary, |
| 3214 test_api.GetCurrentOrientation()); | 3213 test_api.GetCurrentOrientation()); |
| 3215 } | 3214 } |
| 3216 | 3215 |
| 3217 } // namespace ash | 3216 } // namespace ash |
| OLD | NEW |