| 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/common/ash_switches.h" | 8 #include "ash/common/ash_switches.h" |
| 9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 9 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
| 11 #include "ash/common/wm_window.h" |
| 10 #include "ash/display/display_configuration_controller.h" | 12 #include "ash/display/display_configuration_controller.h" |
| 11 #include "ash/display/display_util.h" | 13 #include "ash/display/display_util.h" |
| 12 #include "ash/display/mirror_window_controller.h" | 14 #include "ash/display/mirror_window_controller.h" |
| 15 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 13 #include "ash/display/window_tree_host_manager.h" | 16 #include "ash/display/window_tree_host_manager.h" |
| 14 #include "ash/screen_util.h" | 17 #include "ash/screen_util.h" |
| 18 #include "ash/shared/app_types.h" |
| 15 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 16 #include "ash/strings/grit/ash_strings.h" | 20 #include "ash/strings/grit/ash_strings.h" |
| 17 #include "ash/test/ash_test_base.h" | 21 #include "ash/test/ash_test_base.h" |
| 18 #include "ash/test/mirror_window_test_api.h" | 22 #include "ash/test/mirror_window_test_api.h" |
| 19 #include "ash/wm/window_state_aura.h" | 23 #include "ash/wm/window_state_aura.h" |
| 24 #include "ash/wm/window_util.h" |
| 20 #include "base/command_line.h" | 25 #include "base/command_line.h" |
| 21 #include "base/format_macros.h" | 26 #include "base/format_macros.h" |
| 22 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 24 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 30 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 31 #include "chromeos/accelerometer/accelerometer_types.h" |
| 25 #include "ui/aura/client/aura_constants.h" | 32 #include "ui/aura/client/aura_constants.h" |
| 26 #include "ui/aura/env.h" | 33 #include "ui/aura/env.h" |
| 27 #include "ui/aura/window_observer.h" | 34 #include "ui/aura/window_observer.h" |
| 28 #include "ui/aura/window_tree_host.h" | 35 #include "ui/aura/window_tree_host.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/display/display.h" | 37 #include "ui/display/display.h" |
| 31 #include "ui/display/display_layout_builder.h" | 38 #include "ui/display/display_layout_builder.h" |
| 32 #include "ui/display/display_observer.h" | 39 #include "ui/display/display_observer.h" |
| 33 #include "ui/display/display_switches.h" | 40 #include "ui/display/display_switches.h" |
| 34 #include "ui/display/manager/display_layout_store.h" | 41 #include "ui/display/manager/display_layout_store.h" |
| (...skipping 2885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2920 display::DisplayLayoutStore* layout_store = display_manager()->layout_store(); | 2927 display::DisplayLayoutStore* layout_store = display_manager()->layout_store(); |
| 2921 display::DisplayIdList list = display::test::CreateDisplayIdList2(id1, id2); | 2928 display::DisplayIdList list = display::test::CreateDisplayIdList2(id1, id2); |
| 2922 layout_store->RegisterLayoutForDisplayIdList(list, std::move(old_layout)); | 2929 layout_store->RegisterLayoutForDisplayIdList(list, std::move(old_layout)); |
| 2923 const display::DisplayLayout& stored = | 2930 const display::DisplayLayout& stored = |
| 2924 layout_store->GetRegisteredDisplayLayout(list); | 2931 layout_store->GetRegisteredDisplayLayout(list); |
| 2925 | 2932 |
| 2926 EXPECT_EQ(id1, stored.placement_list[0].parent_display_id); | 2933 EXPECT_EQ(id1, stored.placement_list[0].parent_display_id); |
| 2927 EXPECT_EQ(id2, stored.placement_list[0].display_id); | 2934 EXPECT_EQ(id2, stored.placement_list[0].display_id); |
| 2928 } | 2935 } |
| 2929 | 2936 |
| 2937 TEST_F(DisplayManagerTest, SaveRestoreUserRotationLock) { |
| 2938 Shell* shell = Shell::Get(); |
| 2939 display::DisplayManager* display_manager = shell->display_manager(); |
| 2940 display::test::DisplayManagerTestApi test_api(display_manager); |
| 2941 test_api.SetFirstDisplayAsInternalDisplay(); |
| 2942 ScreenOrientationController* orientation_controller = |
| 2943 shell->screen_orientation_controller(); |
| 2944 |
| 2945 // Set up windows with portrait,lanscape and any. |
| 2946 aura::Window* window_a = CreateTestWindowInShellWithId(0); |
| 2947 { |
| 2948 WmWindow* wm_window_a = WmWindow::Get(window_a); |
| 2949 wm_window_a->SetAppType(static_cast<int>(AppType::CHROME_APP)); |
| 2950 orientation_controller->LockOrientationForWindow( |
| 2951 wm_window_a, blink::WebScreenOrientationLockAny); |
| 2952 } |
| 2953 aura::Window* window_p = CreateTestWindowInShellWithId(0); |
| 2954 { |
| 2955 WmWindow* wm_window_p = WmWindow::Get(window_p); |
| 2956 wm_window_p->SetAppType(static_cast<int>(AppType::CHROME_APP)); |
| 2957 orientation_controller->LockOrientationForWindow( |
| 2958 wm_window_p, blink::WebScreenOrientationLockPortrait); |
| 2959 } |
| 2960 aura::Window* window_l = CreateTestWindowInShellWithId(0); |
| 2961 { |
| 2962 WmWindow* wm_window_l = WmWindow::Get(window_l); |
| 2963 wm_window_l->SetAppType(static_cast<int>(AppType::CHROME_APP)); |
| 2964 orientation_controller->LockOrientationForWindow( |
| 2965 wm_window_l, blink::WebScreenOrientationLockLandscape); |
| 2966 } |
| 2967 |
| 2968 DisplayConfigurationController* configuration_controller = |
| 2969 shell->display_configuration_controller(); |
| 2970 display::Screen* screen = display::Screen::GetScreen(); |
| 2971 |
| 2972 // Rotate to portrait in clamshell. |
| 2973 configuration_controller->SetDisplayRotation( |
| 2974 screen->GetPrimaryDisplay().id(), display::Display::ROTATE_90, |
| 2975 display::Display::ROTATION_SOURCE_USER); |
| 2976 EXPECT_EQ(display::Display::ROTATE_90, |
| 2977 screen->GetPrimaryDisplay().rotation()); |
| 2978 EXPECT_FALSE(display_manager->registered_internal_display_rotation_lock()); |
| 2979 |
| 2980 // Just enabling will not save the lock. |
| 2981 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 2982 true); |
| 2983 |
| 2984 EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation()); |
| 2985 EXPECT_FALSE(display_manager->registered_internal_display_rotation_lock()); |
| 2986 |
| 2987 // Enable lock at 0. |
| 2988 orientation_controller->ToggleUserRotationLock(); |
| 2989 |
| 2990 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock()); |
| 2991 EXPECT_EQ(display::Display::ROTATE_0, |
| 2992 display_manager->registered_internal_display_rotation()); |
| 2993 |
| 2994 // Application can overwwrite the locked orientation. |
| 2995 wm::ActivateWindow(window_p); |
| 2996 EXPECT_EQ(display::Display::ROTATE_90, |
| 2997 screen->GetPrimaryDisplay().rotation()); |
| 2998 EXPECT_EQ(display::Display::ROTATE_0, |
| 2999 display_manager->registered_internal_display_rotation()); |
| 3000 |
| 3001 // Any will rotate to the locked rotation. |
| 3002 wm::ActivateWindow(window_a); |
| 3003 EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation()); |
| 3004 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock()); |
| 3005 EXPECT_EQ(display::Display::ROTATE_0, |
| 3006 display_manager->registered_internal_display_rotation()); |
| 3007 |
| 3008 wm::ActivateWindow(window_l); |
| 3009 EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation()); |
| 3010 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock()); |
| 3011 EXPECT_EQ(display::Display::ROTATE_0, |
| 3012 display_manager->registered_internal_display_rotation()); |
| 3013 |
| 3014 // Exit tablet mode reset to clamshell's rotation, which is 90. |
| 3015 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 3016 false); |
| 3017 EXPECT_EQ(display::Display::ROTATE_90, |
| 3018 screen->GetPrimaryDisplay().rotation()); |
| 3019 // Activate Any. |
| 3020 wm::ActivateWindow(window_a); |
| 3021 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 3022 true); |
| 3023 // Entering with active ANY will lock again to landscape. |
| 3024 EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation()); |
| 3025 |
| 3026 wm::ActivateWindow(window_p); |
| 3027 EXPECT_EQ(display::Display::ROTATE_90, |
| 3028 screen->GetPrimaryDisplay().rotation()); |
| 3029 orientation_controller->ToggleUserRotationLock(); |
| 3030 orientation_controller->ToggleUserRotationLock(); |
| 3031 |
| 3032 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock()); |
| 3033 EXPECT_EQ(display::Display::ROTATE_90, |
| 3034 display_manager->registered_internal_display_rotation()); |
| 3035 |
| 3036 wm::ActivateWindow(window_l); |
| 3037 EXPECT_EQ(display::Display::ROTATE_0, screen->GetPrimaryDisplay().rotation()); |
| 3038 EXPECT_EQ(display::Display::ROTATE_90, |
| 3039 display_manager->registered_internal_display_rotation()); |
| 3040 |
| 3041 // ANY will rotate to locked ortation. |
| 3042 wm::ActivateWindow(window_a); |
| 3043 EXPECT_EQ(display::Display::ROTATE_90, |
| 3044 screen->GetPrimaryDisplay().rotation()); |
| 3045 } |
| 3046 |
| 3047 TEST_F(DisplayManagerTest, UserRotationLockReverse) { |
| 3048 Shell* shell = Shell::Get(); |
| 3049 display::DisplayManager* display_manager = shell->display_manager(); |
| 3050 display::test::DisplayManagerTestApi test_api(display_manager); |
| 3051 test_api.SetFirstDisplayAsInternalDisplay(); |
| 3052 ScreenOrientationController* orientation_controller = |
| 3053 shell->screen_orientation_controller(); |
| 3054 |
| 3055 // Set up windows with portrait,lanscape and any. |
| 3056 aura::Window* window = CreateTestWindowInShellWithId(0); |
| 3057 WmWindow* wm_window = WmWindow::Get(window); |
| 3058 wm_window->SetAppType(static_cast<int>(AppType::CHROME_APP)); |
| 3059 display::Screen* screen = display::Screen::GetScreen(); |
| 3060 |
| 3061 // Just enabling will not save the lock. |
| 3062 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 3063 true); |
| 3064 |
| 3065 orientation_controller->LockOrientationForWindow( |
| 3066 wm_window, blink::WebScreenOrientationLockPortrait); |
| 3067 EXPECT_EQ(display::Display::ROTATE_90, |
| 3068 screen->GetPrimaryDisplay().rotation()); |
| 3069 |
| 3070 const float kMeanGravity = -9.8066f; |
| 3071 |
| 3072 scoped_refptr<chromeos::AccelerometerUpdate> reverse_portrait( |
| 3073 new chromeos::AccelerometerUpdate()); |
| 3074 reverse_portrait->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, kMeanGravity, |
| 3075 0.f, 0.f); |
| 3076 orientation_controller->OnAccelerometerUpdated(reverse_portrait); |
| 3077 |
| 3078 EXPECT_EQ(display::Display::ROTATE_270, |
| 3079 screen->GetPrimaryDisplay().rotation()); |
| 3080 |
| 3081 scoped_refptr<chromeos::AccelerometerUpdate> portrait( |
| 3082 new chromeos::AccelerometerUpdate()); |
| 3083 portrait->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.f, 0.f); |
| 3084 orientation_controller->OnAccelerometerUpdated(portrait); |
| 3085 EXPECT_EQ(display::Display::ROTATE_90, |
| 3086 screen->GetPrimaryDisplay().rotation()); |
| 3087 |
| 3088 // Enable lock at 90. |
| 3089 orientation_controller->ToggleUserRotationLock(); |
| 3090 EXPECT_TRUE(display_manager->registered_internal_display_rotation_lock()); |
| 3091 EXPECT_EQ(display::Display::ROTATE_90, |
| 3092 display_manager->registered_internal_display_rotation()); |
| 3093 |
| 3094 orientation_controller->OnAccelerometerUpdated(reverse_portrait); |
| 3095 |
| 3096 EXPECT_EQ(display::Display::ROTATE_90, |
| 3097 screen->GetPrimaryDisplay().rotation()); |
| 3098 } |
| 3099 |
| 2930 } // namespace ash | 3100 } // namespace ash |
| OLD | NEW |