summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima <oshima@chromium.org>2015-07-27 14:16:01 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-27 21:17:19 +0000
commit81d33285d0e1dd675048c5648b8f552d9655ee51 (patch)
treeee20964bc2b8382a865016ff88d078d255210ea4
parent7db270d16be6f08f9cb2b71508204c770bdbc3c6 (diff)
downloadchromium_src-81d33285d0e1dd675048c5648b8f552d9655ee51.zip
chromium_src-81d33285d0e1dd675048c5648b8f552d9655ee51.tar.gz
chromium_src-81d33285d0e1dd675048c5648b8f552d9655ee51.tar.bz2
[Cleanup]: Made SetDisplayUIScale private
I'll consolidate this and SetDisplayUIMode in next CL. other cleanups: * Moved GetDisplayModeForResolution/GetDisplayModeForNextUIScale out from DisplayManager as utility function, as they do not depend on DisplayManager. * Removed argument from DisplayManagerTestApi. It's always Shell::GetInstance()->display_manager(). BUG=None TBR=asargent@chromium.org Review URL: https://codereview.chromium.org/1254733002 Cr-Commit-Position: refs/heads/master@{#340564}
-rw-r--r--ash/accelerators/accelerator_controller.cc12
-rw-r--r--ash/accelerators/accelerator_controller_unittest.cc3
-rw-r--r--ash/content/display/screen_orientation_controller_chromeos_unittest.cc21
-rw-r--r--ash/desktop_background/desktop_background_controller_unittest.cc5
-rw-r--r--ash/display/display_controller_unittest.cc24
-rw-r--r--ash/display/display_manager.cc88
-rw-r--r--ash/display/display_manager.h13
-rw-r--r--ash/display/display_manager_unittest.cc137
-rw-r--r--ash/display/display_util.cc72
-rw-r--r--ash/display/display_util.h18
-rw-r--r--ash/display/mirror_window_controller_unittest.cc9
-rw-r--r--ash/display/root_window_transformers_unittest.cc7
-rw-r--r--ash/test/ash_test_base.cc5
-rw-r--r--ash/test/ash_test_helper.cc3
-rw-r--r--ash/test/display_manager_test_api.cc22
-rw-r--r--ash/test/display_manager_test_api.h24
-rw-r--r--ash/touch/touch_observer_hud_unittest.cc4
-rw-r--r--ash/wm/ash_native_cursor_manager_unittest.cc8
-rw-r--r--ash/wm/maximize_mode/maximize_mode_controller_unittest.cc3
-rw-r--r--ash/wm/system_gesture_event_filter_unittest.cc3
-rw-r--r--chrome/browser/chromeos/display/display_preferences_unittest.cc24
-rw-r--r--chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc4
-rw-r--r--chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc5
-rw-r--r--chrome/browser/extensions/display_info_provider_chromeos_unittest.cc3
-rw-r--r--chrome/browser/ui/ash/system_tray_delegate_chromeos_browsertest_chromeos.cc6
25 files changed, 269 insertions, 254 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index bee96b2..2884ec1 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -300,7 +300,7 @@ void HandleScaleReset() {
base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Reset"));
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
int64 display_id = display_manager->GetDisplayIdForUIScaling();
- display_manager->SetDisplayUIScale(display_id, 1.0f);
+ SetDisplayUIScale(display_id, 1.0f);
}
bool CanHandleScaleUI() {
@@ -311,15 +311,15 @@ void HandleScaleUI(bool up) {
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
int64 display_id = display_manager->GetDisplayIdForUIScaling();
- if (up) {
+ if (up)
base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Up"));
- } else {
+ else
base::RecordAction(UserMetricsAction("Accel_Scale_Ui_Down"));
- }
const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id);
- float next_scale = GetNextUIScale(display_info, up);
- display_manager->SetDisplayUIScale(display_id, next_scale);
+ DisplayMode mode;
+ if (GetDisplayModeForNextUIScale(display_info, up, &mode))
+ display_manager->SetDisplayMode(display_id, mode);
}
void HandleShowKeyboardOverlay() {
diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc
index 1af6f7f..100e5ef 100644
--- a/ash/accelerators/accelerator_controller_unittest.cc
+++ b/ash/accelerators/accelerator_controller_unittest.cc
@@ -223,8 +223,7 @@ class AcceleratorControllerTest : public test::AshTestBase {
protected:
void EnableInternalDisplay() {
- test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()).
- SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
}
static AcceleratorController* GetController();
diff --git a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc
index 84bbb5d..57a7485 100644
--- a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc
+++ b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc
@@ -419,8 +419,7 @@ TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) {
static_cast<test::TestSystemTrayDelegate*>(
Shell::GetInstance()->system_tray_delegate());
tray_delegate->set_should_show_display_notification(true);
- test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
- .SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
message_center::MessageCenter* message_center =
message_center::MessageCenter::Get();
@@ -470,8 +469,7 @@ TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) {
// Tests that if a user has set a display rotation that it is restored upon
// exiting maximize mode.
TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) {
- test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
- .SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
SetInternalDisplayRotation(gfx::Display::ROTATE_90);
EnableMaximizeMode(true);
@@ -597,8 +595,7 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) {
// ready, that ScreenOrientationController still begins listening to events,
// which require an internal display to be acted upon.
TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) {
- test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
- .SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
int64 internal_display_id = gfx::Display::InternalDisplayId();
gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID);
@@ -626,8 +623,6 @@ TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplay) {
const int64 kExternalDisplayId = 10;
const gfx::Display::Rotation kNewRotation = gfx::Display::ROTATE_180;
- DisplayManager* display_manager = Shell::GetInstance()->display_manager();
-
const DisplayInfo internal_display_info =
CreateDisplayInfo(kInternalDisplayId, gfx::Rect(0, 0, 500, 500));
const DisplayInfo external_display_info =
@@ -643,13 +638,11 @@ TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplay) {
// The DisplayInfo list with two active displays needs to be added first so
// that the DisplayManager can track the |internal_display_info| as inactive
// instead of non-existent.
- ash::Shell::GetInstance()->display_manager()->UpdateDisplays(
- display_info_list_two_active);
- ash::Shell::GetInstance()->display_manager()->UpdateDisplays(
- display_info_list_one_active);
+ DisplayManager* display_manager = Shell::GetInstance()->display_manager();
+ display_manager->UpdateDisplays(display_info_list_two_active);
+ display_manager->UpdateDisplays(display_info_list_one_active);
- test::DisplayManagerTestApi(display_manager)
- .SetInternalDisplayId(kInternalDisplayId);
+ test::ScopedSetInternalDisplayId set_internal(kInternalDisplayId);
ASSERT_NE(kNewRotation, display_manager->GetDisplayInfo(kInternalDisplayId)
.GetActiveRotation());
diff --git a/ash/desktop_background/desktop_background_controller_unittest.cc b/ash/desktop_background/desktop_background_controller_unittest.cc
index ecd1c3a..b51fca1 100644
--- a/ash/desktop_background/desktop_background_controller_unittest.cc
+++ b/ash/desktop_background/desktop_background_controller_unittest.cc
@@ -13,7 +13,6 @@
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
-#include "ash/test/display_manager_test_api.h"
#include "ash/test/test_user_wallpaper_delegate.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/sequenced_worker_pool.h"
@@ -284,9 +283,7 @@ TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) {
if (!SupportsMultipleDisplays())
return;
- test::DisplayManagerTestApi display_manager_test_api(
- Shell::GetInstance()->display_manager());
- display_manager_test_api.UpdateDisplay("320x200");
+ UpdateDisplay("320x200");
gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc
index 6b04077..9e72799 100644
--- a/ash/display/display_controller_unittest.cc
+++ b/ash/display/display_controller_unittest.cc
@@ -8,6 +8,7 @@
#include "ash/display/display_info.h"
#include "ash/display/display_layout_store.h"
#include "ash/display/display_manager.h"
+#include "ash/display/display_util.h"
#include "ash/screen_util.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_widget.h"
@@ -567,8 +568,7 @@ TEST_F(DisplayControllerTest, MirrorToDockedWithFullscreen) {
display_info_list.push_back(external_display_info);
display_manager->OnNativeDisplaysChanged(display_info_list);
const int64 internal_display_id =
- test::DisplayManagerTestApi(display_manager).
- SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
EXPECT_EQ(1, internal_display_id);
EXPECT_EQ(2U, display_manager->num_connected_displays());
EXPECT_EQ(1U, display_manager->GetNumDisplays());
@@ -676,22 +676,21 @@ TEST_F(DisplayControllerTest, BoundsUpdated) {
// UI scale is eanbled only on internal display.
int64 secondary_id = GetSecondaryDisplay().id();
- test::DisplayManagerTestApi(display_manager)
- .SetInternalDisplayId(secondary_id);
+ test::ScopedSetInternalDisplayId set_internal(secondary_id);
- display_manager->SetDisplayUIScale(secondary_id, 1.125f);
+ SetDisplayUIScale(secondary_id, 1.125f);
EXPECT_EQ(1, observer.CountAndReset());
EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
- display_manager->SetDisplayUIScale(secondary_id, 1.125f);
+ SetDisplayUIScale(secondary_id, 1.125f);
EXPECT_EQ(0, observer.CountAndReset());
EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
- display_manager->SetDisplayUIScale(primary_id, 1.125f);
+ SetDisplayUIScale(primary_id, 1.125f);
EXPECT_EQ(0, observer.CountAndReset());
EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
- display_manager->SetDisplayUIScale(primary_id, 1.125f);
+ SetDisplayUIScale(primary_id, 1.125f);
EXPECT_EQ(0, observer.CountAndReset());
EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
@@ -1086,10 +1085,8 @@ TEST_F(DisplayControllerTest, ScaleRootWindow) {
UpdateDisplay("600x400*2@1.5,500x300");
- DisplayManager* display_manager = Shell::GetInstance()->display_manager();
gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
- test::DisplayManagerTestApi(display_manager)
- .SetInternalDisplayId(display1.id());
+ test::ScopedSetInternalDisplayId set_internal(display1.id());
gfx::Display display2 = ScreenUtil::GetSecondaryDisplay();
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
@@ -1103,7 +1100,7 @@ TEST_F(DisplayControllerTest, ScaleRootWindow) {
generator.MoveMouseToInHost(599, 200);
EXPECT_EQ("449,150", event_handler.GetLocationAndReset());
- display_manager->SetDisplayUIScale(display1.id(), 1.25f);
+ SetDisplayUIScale(display1.id(), 1.25f);
display1 = Shell::GetScreen()->GetPrimaryDisplay();
display2 = ScreenUtil::GetSecondaryDisplay();
EXPECT_EQ("0,0 375x250", display1.bounds().ToString());
@@ -1228,8 +1225,7 @@ TEST_F(DisplayControllerTest, DockToSingle) {
display_info_list.push_back(external_display_info);
display_manager->OnNativeDisplaysChanged(display_info_list);
const int64 internal_display_id =
- test::DisplayManagerTestApi(display_manager).
- SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
EXPECT_EQ(internal_id, internal_display_id);
EXPECT_EQ(2U, display_manager->GetNumDisplays());
diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc
index 00f2102..ed78316 100644
--- a/ash/display/display_manager.cc
+++ b/ash/display/display_manager.cc
@@ -354,64 +354,15 @@ void DisplayManager::SetDisplayRotation(int64 display_id,
}
}
-bool DisplayManager::SetDisplayUIScale(int64 display_id,
- float ui_scale) {
- if (GetDisplayIdForUIScaling() != display_id)
- return false;
-
- bool found = false;
- // TODO(mukai): merge this implementation into SetDisplayMode().
- DisplayInfoList display_info_list;
- for (const auto& display : active_display_list_) {
- DisplayInfo info = GetDisplayInfo(display.id());
- if (info.id() == display_id) {
- found = true;
- if (info.configured_ui_scale() == ui_scale)
- return true;
- if (!HasDisplayModeForUIScale(info, ui_scale))
- return false;
- info.set_configured_ui_scale(ui_scale);
- }
- display_info_list.push_back(info);
- }
- if (found) {
- AddMirrorDisplayInfoIfAny(&display_info_list);
- UpdateDisplays(display_info_list);
- return true;
- }
- return false;
-}
-
-void DisplayManager::SetDisplayResolution(int64 display_id,
- const gfx::Size& resolution) {
- DCHECK(!gfx::Display::IsInternalDisplayId(display_id));
- if (gfx::Display::IsInternalDisplayId(display_id))
- return;
- const DisplayInfo& display_info = GetDisplayInfo(display_id);
- const std::vector<DisplayMode>& modes = display_info.display_modes();
- DCHECK_NE(0u, modes.size());
- DisplayMode target_mode;
- target_mode.size = resolution;
- std::vector<DisplayMode>::const_iterator iter =
- std::find_if(modes.begin(), modes.end(), DisplayModeMatcher(target_mode));
- if (iter == modes.end()) {
- LOG(WARNING) << "Unsupported resolution was requested:"
- << resolution.ToString();
- return;
- }
- display_modes_[display_id] = *iter;
-#if defined(OS_CHROMEOS)
- if (base::SysInfo::IsRunningOnChromeOS())
- Shell::GetInstance()->display_configurator()->OnConfigurationChanged();
-#endif
-}
-
bool DisplayManager::SetDisplayMode(int64 display_id,
const DisplayMode& display_mode) {
- if (GetDisplayIdForUIScaling() == display_id) {
- SetDisplayUIScale(display_id, display_mode.ui_scale);
+ if (GetDisplayIdForUIScaling() == display_id)
+ return SetDisplayUIScale(display_id, display_mode.ui_scale);
+
+ // UI scaling should not be applied to non internal display.
+ DCHECK_EQ(1.0f, display_mode.ui_scale);
+ if (display_mode.ui_scale != 1.0f)
return false;
- }
DisplayInfoList display_info_list;
bool display_property_changed = false;
@@ -1122,6 +1073,33 @@ void DisplayManager::UpdateInternalDisplayModeListForTest() {
SetInternalDisplayModeList(info);
}
+// TODO(oshima|mukai): Merge this logic into SetDisplayMode.
+bool DisplayManager::SetDisplayUIScale(int64 display_id, float ui_scale) {
+ if (GetDisplayIdForUIScaling() != display_id)
+ return false;
+
+ bool found = false;
+ DisplayInfoList display_info_list;
+ for (const auto& display : active_display_list_) {
+ DisplayInfo info = GetDisplayInfo(display.id());
+ if (info.id() == display_id) {
+ found = true;
+ if (info.configured_ui_scale() == ui_scale)
+ return true;
+ if (!HasDisplayModeForUIScale(info, ui_scale))
+ return false;
+ info.set_configured_ui_scale(ui_scale);
+ }
+ display_info_list.push_back(info);
+ }
+ if (found) {
+ AddMirrorDisplayInfoIfAny(&display_info_list);
+ UpdateDisplays(display_info_list);
+ return true;
+ }
+ return false;
+}
+
void DisplayManager::CreateSoftwareMirroringDisplayInfo(
DisplayInfoList* display_info_list) {
// Use the internal display or 1st as the mirror source, then scale
diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h
index ccd606a..4983f58 100644
--- a/ash/display/display_manager.h
+++ b/ash/display/display_manager.h
@@ -163,15 +163,6 @@ class ASH_EXPORT DisplayManager
gfx::Display::Rotation rotation,
gfx::Display::RotationSource source);
- // Sets the display's ui scale. Returns true if it's successful, or
- // false otherwise. TODO(mukai): remove this and merge into
- // SetDisplayMode.
- bool SetDisplayUIScale(int64 display_id, float ui_scale);
-
- // Sets the display's resolution.
- // TODO(mukai): remove this and merge into SetDisplayMode.
- void SetDisplayResolution(int64 display_id, const gfx::Size& resolution);
-
// Sets the external display's configuration, including resolution change,
// ui-scale change, and device scale factor change. Returns true if it changes
// the display resolution so that the caller needs to show a notification in
@@ -351,6 +342,10 @@ private:
void set_change_display_upon_host_resize(bool value) {
change_display_upon_host_resize_ = value;
}
+ // Sets the display's ui scale. Returns true if it's successful, or
+ // false otherwise. TODO(mukai): remove this and merge into
+ // SetDisplayMode.
+ bool SetDisplayUIScale(int64 display_id, float ui_scale);
// Creates software mirroring display related information. The display
// used to mirror the content is removed from the |display_info_list|.
diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc
index e20469e..a7ec228 100644
--- a/ash/display/display_manager_unittest.cc
+++ b/ash/display/display_manager_unittest.cc
@@ -480,8 +480,7 @@ DisplayInfo CreateDisplayInfo(int64 id, const gfx::Rect& bounds) {
TEST_F(DisplayManagerTest, TestNativeDisplaysChanged) {
const int64 internal_display_id =
- test::DisplayManagerTestApi(display_manager()).
- SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
const int external_id = 10;
const int mirror_id = 11;
const int64 invalid_id = gfx::Display::kInvalidDisplayID;
@@ -708,8 +707,7 @@ TEST_F(DisplayManagerTest, NativeDisplaysChangedAfterPrimaryChange) {
return;
const int64 internal_display_id =
- test::DisplayManagerTestApi(display_manager()).
- SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
const DisplayInfo native_display_info =
CreateDisplayInfo(internal_display_id, gfx::Rect(0, 0, 500, 500));
const DisplayInfo secondary_display_info =
@@ -765,14 +763,14 @@ TEST_F(DisplayManagerTest, DontRememberBestResolution) {
display_manager()->GetActiveModeForDisplayId(display_id)));
// Unsupported resolution.
- display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 4000));
+ test::SetDisplayResolution(display_id, gfx::Size(800, 4000));
EXPECT_FALSE(
display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
EXPECT_TRUE(expected_mode.IsEquivalent(
display_manager()->GetActiveModeForDisplayId(display_id)));
// Supported resolution.
- display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 300));
+ test::SetDisplayResolution(display_id, gfx::Size(800, 300));
EXPECT_TRUE(
display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
EXPECT_EQ("800x300", mode.size.ToString());
@@ -783,7 +781,7 @@ TEST_F(DisplayManagerTest, DontRememberBestResolution) {
display_manager()->GetActiveModeForDisplayId(display_id)));
// Best resolution.
- display_manager()->SetDisplayResolution(display_id, gfx::Size(1000, 500));
+ test::SetDisplayResolution(display_id, gfx::Size(1000, 500));
EXPECT_TRUE(
display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
EXPECT_EQ("1000x500", mode.size.ToString());
@@ -813,7 +811,7 @@ TEST_F(DisplayManagerTest, ResolutionFallback) {
display_info_list.push_back(native_display_info);
display_manager()->OnNativeDisplaysChanged(display_info_list);
{
- display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 300));
+ test::SetDisplayResolution(display_id, gfx::Size(800, 300));
DisplayInfo new_native_display_info =
CreateDisplayInfo(display_id, gfx::Rect(0, 0, 400, 500));
copy = display_modes;
@@ -831,7 +829,7 @@ TEST_F(DisplayManagerTest, ResolutionFallback) {
}
{
// Best resolution should find itself on the resolutions list.
- display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 300));
+ test::SetDisplayResolution(display_id, gfx::Size(800, 300));
DisplayInfo new_native_display_info =
CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500));
std::vector<DisplayMode> copy = display_modes;
@@ -909,8 +907,7 @@ TEST_F(DisplayManagerTest, Rotate) {
// set rotations should be applied.
UpdateDisplay("200x200, 200x200");
const int64 internal_display_id =
- test::DisplayManagerTestApi(display_manager())
- .SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
display_manager()->SetDisplayRotation(internal_display_id,
gfx::Display::ROTATE_90,
@@ -946,79 +943,78 @@ TEST_F(DisplayManagerTest, UIScale) {
UpdateDisplay("1280x800");
int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id();
- display_manager()->SetDisplayUIScale(display_id, 1.125f);
+ SetDisplayUIScale(display_id, 1.125f);
EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.8f);
+ SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.75f);
+ SetDisplayUIScale(display_id, 0.75f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.625f);
+ SetDisplayUIScale(display_id, 0.625f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- test::DisplayManagerTestApi(display_manager())
- .SetInternalDisplayId(display_id);
+ test::ScopedSetInternalDisplayId set_internal(display_id);
- display_manager()->SetDisplayUIScale(display_id, 1.5f);
+ SetDisplayUIScale(display_id, 1.5f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 1.25f);
+ SetDisplayUIScale(display_id, 1.25f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 1.125f);
+ SetDisplayUIScale(display_id, 1.125f);
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.8f);
+ SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.75f);
+ SetDisplayUIScale(display_id, 0.75f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.625f);
+ SetDisplayUIScale(display_id, 0.625f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.6f);
+ SetDisplayUIScale(display_id, 0.6f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.5f);
+ SetDisplayUIScale(display_id, 0.5f);
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());
UpdateDisplay("1366x768");
- display_manager()->SetDisplayUIScale(display_id, 1.5f);
+ SetDisplayUIScale(display_id, 1.5f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 1.25f);
+ SetDisplayUIScale(display_id, 1.25f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 1.125f);
+ SetDisplayUIScale(display_id, 1.125f);
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.8f);
+ SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.75f);
+ SetDisplayUIScale(display_id, 0.75f);
EXPECT_EQ(0.75f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.6f);
+ SetDisplayUIScale(display_id, 0.6f);
EXPECT_EQ(0.6f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.625f);
+ SetDisplayUIScale(display_id, 0.625f);
EXPECT_EQ(0.6f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.5f);
+ SetDisplayUIScale(display_id, 0.5f);
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());
UpdateDisplay("1280x850*2");
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 1.5f);
+ SetDisplayUIScale(display_id, 1.5f);
EXPECT_EQ(1.5f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 1.25f);
+ SetDisplayUIScale(display_id, 1.25f);
EXPECT_EQ(1.25f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 1.125f);
+ SetDisplayUIScale(display_id, 1.125f);
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 1.0f);
+ SetDisplayUIScale(display_id, 1.0f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(2.0f, display.device_scale_factor());
EXPECT_EQ("640x425", display.bounds().size().ToString());
- display_manager()->SetDisplayUIScale(display_id, 0.8f);
+ SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.75f);
+ SetDisplayUIScale(display_id, 0.75f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.625f);
+ SetDisplayUIScale(display_id, 0.625f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.6f);
+ SetDisplayUIScale(display_id, 0.6f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 0.5f);
+ SetDisplayUIScale(display_id, 0.5f);
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());
- display_manager()->SetDisplayUIScale(display_id, 2.0f);
+ SetDisplayUIScale(display_id, 2.0f);
EXPECT_EQ(2.0f, GetDisplayInfoAt(0).configured_ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale());
display = Shell::GetScreen()->GetPrimaryDisplay();
@@ -1028,7 +1024,7 @@ TEST_F(DisplayManagerTest, UIScale) {
// 1.25 ui scaling on 1.25 DSF device should use 1.0 DSF
// on screen.
UpdateDisplay("1280x850*1.25");
- display_manager()->SetDisplayUIScale(display_id, 1.25f);
+ SetDisplayUIScale(display_id, 1.25f);
EXPECT_EQ(1.25f, GetDisplayInfoAt(0).configured_ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale());
display = Shell::GetScreen()->GetPrimaryDisplay();
@@ -1055,58 +1051,40 @@ TEST_F(DisplayManagerTest, UIScaleWithDisplayMode) {
EXPECT_TRUE(expected_mode.IsEquivalent(
display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 1.125f);
- EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
- EXPECT_TRUE(expected_mode.IsEquivalent(
- display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 0.8f);
- EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- EXPECT_TRUE(expected_mode.IsEquivalent(
- display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 0.75f);
- EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- EXPECT_TRUE(expected_mode.IsEquivalent(
- display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 0.625f);
- EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
- EXPECT_TRUE(expected_mode.IsEquivalent(
- display_manager()->GetActiveModeForDisplayId(display_id)));
-
- test::DisplayManagerTestApi(display_manager())
- .SetInternalDisplayId(display_id);
+ test::ScopedSetInternalDisplayId set_internal(display_id);
- display_manager()->SetDisplayUIScale(display_id, 1.5f);
+ SetDisplayUIScale(display_id, 1.5f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
EXPECT_TRUE(expected_mode.IsEquivalent(
display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 1.25f);
+ SetDisplayUIScale(display_id, 1.25f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
EXPECT_TRUE(expected_mode.IsEquivalent(
display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 1.125f);
+ SetDisplayUIScale(display_id, 1.125f);
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
expected_mode.ui_scale = 1.125f;
EXPECT_TRUE(expected_mode.IsEquivalent(
display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 0.8f);
+ SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
expected_mode.ui_scale = 0.8f;
EXPECT_TRUE(expected_mode.IsEquivalent(
display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 0.75f);
+ SetDisplayUIScale(display_id, 0.75f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
EXPECT_TRUE(expected_mode.IsEquivalent(
display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 0.625f);
+ SetDisplayUIScale(display_id, 0.625f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
expected_mode.ui_scale = 0.625f;
EXPECT_TRUE(expected_mode.IsEquivalent(
display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 0.6f);
+ SetDisplayUIScale(display_id, 0.6f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
EXPECT_TRUE(expected_mode.IsEquivalent(
display_manager()->GetActiveModeForDisplayId(display_id)));
- display_manager()->SetDisplayUIScale(display_id, 0.5f);
+ SetDisplayUIScale(display_id, 0.5f);
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());
expected_mode.ui_scale = 0.5f;
EXPECT_TRUE(expected_mode.IsEquivalent(
@@ -1115,24 +1093,23 @@ TEST_F(DisplayManagerTest, UIScaleWithDisplayMode) {
TEST_F(DisplayManagerTest, Use125DSFForUIScaling) {
int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id();
- test::DisplayManagerTestApi(display_manager())
- .SetInternalDisplayId(display_id);
+ test::ScopedSetInternalDisplayId set_internal(display_id);
UpdateDisplay("1920x1080*1.25");
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale());
- display_manager()->SetDisplayUIScale(display_id, 0.8f);
+ SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(1.25f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale());
EXPECT_EQ("1536x864", GetDisplayForId(display_id).size().ToString());
- display_manager()->SetDisplayUIScale(display_id, 0.5f);
+ SetDisplayUIScale(display_id, 0.5f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).GetEffectiveUIScale());
EXPECT_EQ("960x540", GetDisplayForId(display_id).size().ToString());
- display_manager()->SetDisplayUIScale(display_id, 1.25f);
+ SetDisplayUIScale(display_id, 1.25f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
EXPECT_EQ(1.25f, GetDisplayInfoAt(0).GetEffectiveUIScale());
EXPECT_EQ("2400x1350", GetDisplayForId(display_id).size().ToString());
@@ -1159,7 +1136,7 @@ TEST_F(DisplayManagerTest, UIScaleInUnifiedMode) {
EXPECT_EQ(1.0f, active_mode.ui_scale);
EXPECT_EQ("800x400", active_mode.size.ToString());
- EXPECT_TRUE(display_manager->SetDisplayUIScale(unified_id, 0.5f));
+ EXPECT_TRUE(SetDisplayUIScale(unified_id, 0.5f));
EXPECT_EQ("400x200",
Shell::GetScreen()->GetPrimaryDisplay().size().ToString());
active_mode = display_manager->GetActiveModeForDisplayId(unified_id);
@@ -1738,8 +1715,7 @@ TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf200Internal) {
EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
- Shell::GetInstance()->display_manager()->SetDisplayUIScale(
- Shell::GetScreen()->GetPrimaryDisplay().id(), 2.0f);
+ SetDisplayUIScale(Shell::GetScreen()->GetPrimaryDisplay().id(), 2.0f);
ASSERT_DOUBLE_EQ(
1.0f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
@@ -1779,8 +1755,7 @@ TEST_F(DisplayManagerFontTest,
EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
- Shell::GetInstance()->display_manager()->SetDisplayUIScale(
- Shell::GetScreen()->GetPrimaryDisplay().id(), 0.8f);
+ SetDisplayUIScale(Shell::GetScreen()->GetPrimaryDisplay().id(), 0.8f);
ASSERT_DOUBLE_EQ(
1.25f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
diff --git a/ash/display/display_util.cc b/ash/display/display_util.cc
index 12373e8..d017d7d 100644
--- a/ash/display/display_util.cc
+++ b/ash/display/display_util.cc
@@ -12,6 +12,7 @@
#include "ash/shell.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h"
+#include "ui/gfx/display.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/wm/core/coordinate_conversion.h"
@@ -77,6 +78,20 @@ void ConvertPointFromScreenToNative(aura::WindowTreeHost* host,
host->ConvertPointToNativeScreen(point);
}
+bool GetDisplayModeForUIScale(const DisplayInfo& info,
+ float ui_scale,
+ DisplayMode* out) {
+ const std::vector<DisplayMode>& modes = info.display_modes();
+ auto iter = std::find_if(modes.begin(), modes.end(),
+ [ui_scale](const DisplayMode& mode) {
+ return mode.ui_scale == ui_scale;
+ });
+ if (iter == modes.end())
+ return false;
+ *out = *iter;
+ return true;
+}
+
} // namespace
std::vector<DisplayMode> CreateInternalDisplayModeList(
@@ -110,21 +125,64 @@ std::vector<DisplayMode> CreateUnifiedDisplayModeList(
return display_mode_list;
}
-// static
-float GetNextUIScale(const DisplayInfo& info, bool up) {
+bool GetDisplayModeForResolution(const DisplayInfo& info,
+ const gfx::Size& resolution,
+ DisplayMode* out) {
+ // TODO(oshima): Replace this with IsInternalDisplayId once
+ // the unified desktop mode is convered to not to use UI scaling.
+ if (Shell::GetInstance()->display_manager()->GetDisplayIdForUIScaling() ==
+ info.id())
+ return false;
+
+ const std::vector<DisplayMode>& modes = info.display_modes();
+ DCHECK_NE(0u, modes.size());
+ DisplayMode target_mode;
+ target_mode.size = resolution;
+ std::vector<DisplayMode>::const_iterator iter = std::find_if(
+ modes.begin(), modes.end(), [resolution](const DisplayMode& mode) {
+ return mode.size == resolution;
+ });
+ if (iter == modes.end()) {
+ LOG(WARNING) << "Unsupported resolution was requested:"
+ << resolution.ToString();
+ return false;
+ }
+ *out = *iter;
+ return true;
+}
+
+bool GetDisplayModeForNextUIScale(const DisplayInfo& info,
+ bool up,
+ DisplayMode* out) {
+ // TODO(oshima): Replace this with IsInternalDisplayId once
+ // the unified desktop mode is convered to not to use UI scaling.
+ if (Shell::GetInstance()->display_manager()->GetDisplayIdForUIScaling() !=
+ info.id())
+ return false;
ScaleComparator comparator(info.configured_ui_scale());
const std::vector<DisplayMode>& modes = info.display_modes();
for (auto iter = modes.begin(); iter != modes.end(); ++iter) {
if (comparator(*iter)) {
if (up && (iter + 1) != modes.end())
- return (iter + 1)->ui_scale;
+ *out = *(iter + 1);
if (!up && iter != modes.begin())
- return (iter - 1)->ui_scale;
- return info.configured_ui_scale();
+ *out = *(iter - 1);
+ else
+ *out = *iter;
+ return true;
}
}
- // Fallback to 1.0f if the |scale| wasn't in the list.
- return 1.0f;
+ NOTREACHED();
+ return false;
+}
+
+bool SetDisplayUIScale(int64 id, float ui_scale) {
+ DisplayManager* display_manager = Shell::GetInstance()->display_manager();
+ const DisplayInfo& info = display_manager->GetDisplayInfo(id);
+ DisplayMode mode;
+ if (!GetDisplayModeForUIScale(info, ui_scale, &mode))
+ return false;
+ return display_manager->SetDisplayMode(id, mode);
}
bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale) {
diff --git a/ash/display/display_util.h b/ash/display/display_util.h
index 6b74fbc..57085dd 100644
--- a/ash/display/display_util.h
+++ b/ash/display/display_util.h
@@ -15,6 +15,7 @@ namespace gfx {
class Display;
class Point;
class Rect;
+class Size;
}
namespace ash {
@@ -33,8 +34,21 @@ ASH_EXPORT std::vector<DisplayMode> CreateUnifiedDisplayModeList(
const DisplayMode& native_mode,
const std::set<float>& scales);
-// Returns next valid UI scale.
-float GetNextUIScale(const DisplayInfo& info, bool up);
+// Gets the display mode for |resolution|. Returns false if no display
+// mode matches the resolution, or the display is an internal display.
+ASH_EXPORT bool GetDisplayModeForResolution(const DisplayInfo& info,
+ const gfx::Size& resolution,
+ DisplayMode* out);
+
+// Gets the display mode for the next valid UI scale. Returns false
+// if the display is not an internal display.
+ASH_EXPORT bool GetDisplayModeForNextUIScale(const DisplayInfo& info,
+ bool up,
+ DisplayMode* out);
+
+// Sets the UI scale for the |display_id|. Returns false if the
+// display_id is not an internal display.
+ASH_EXPORT bool SetDisplayUIScale(int64 display_id, float scale);
// Tests if the |info| has display mode that matches |ui_scale|.
bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale);
diff --git a/ash/display/mirror_window_controller_unittest.cc b/ash/display/mirror_window_controller_unittest.cc
index fab0bba..644d2ed 100644
--- a/ash/display/mirror_window_controller_unittest.cc
+++ b/ash/display/mirror_window_controller_unittest.cc
@@ -218,13 +218,11 @@ TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorMoveOnEnter) {
aura::Env* env = aura::Env::GetInstance();
Shell* shell = Shell::GetInstance();
DisplayController* display_controller = shell->display_controller();
- DisplayManager* display_manager = shell->display_manager();
UpdateDisplay("400x400*2/r,400x400");
int64 primary_display_id = display_controller->GetPrimaryDisplayId();
int64 secondary_display_id = ScreenUtil::GetSecondaryDisplay().id();
- test::DisplayManagerTestApi(display_manager)
- .SetInternalDisplayId(primary_display_id);
+ test::ScopedSetInternalDisplayId set_internal(primary_display_id);
// Chrome uses the internal display as the source display for software mirror
// mode. Move the cursor to the external display.
@@ -236,7 +234,7 @@ TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorMoveOnEnter) {
EXPECT_EQ(1.0f, cursor_test_api.GetCurrentCursor().device_scale_factor());
EXPECT_EQ(gfx::Display::ROTATE_0, cursor_test_api.GetCurrentCursorRotation());
- display_manager->SetMultiDisplayMode(DisplayManager::MIRRORING);
+ shell->display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING);
UpdateDisplay("400x400*2/r,400x400");
// Entering mirror mode should have centered the cursor on the primary display
@@ -278,8 +276,7 @@ TEST_F(MirrorWindowControllerTest, MAYBE_DockMode) {
display_info_list.push_back(external_display_info);
display_manager->OnNativeDisplaysChanged(display_info_list);
const int64 internal_display_id =
- test::DisplayManagerTestApi(display_manager).
- SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
EXPECT_EQ(internal_id, internal_display_id);
EXPECT_EQ(1U, display_manager->GetNumDisplays());
diff --git a/ash/display/root_window_transformers_unittest.cc b/ash/display/root_window_transformers_unittest.cc
index 39e8c64..9aae4f3 100644
--- a/ash/display/root_window_transformers_unittest.cc
+++ b/ash/display/root_window_transformers_unittest.cc
@@ -6,6 +6,7 @@
#include "ash/display/display_info.h"
#include "ash/display/display_manager.h"
+#include "ash/display/display_util.h"
#include "ash/host/root_window_transformer.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/screen_util.h"
@@ -243,8 +244,7 @@ TEST_F(RootWindowTransformersTest, ScaleAndMagnify) {
UpdateDisplay("600x400*2@1.5,500x300");
gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
- test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
- .SetInternalDisplayId(display1.id());
+ test::ScopedSetInternalDisplayId set_internal(display1.id());
gfx::Display display2 = ScreenUtil::GetSecondaryDisplay();
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
MagnificationController* magnifier =
@@ -263,8 +263,7 @@ TEST_F(RootWindowTransformersTest, ScaleAndMagnify) {
EXPECT_EQ("299,150", event_handler.GetLocationAndReset());
magnifier->SetEnabled(false);
- DisplayManager* display_manager = Shell::GetInstance()->display_manager();
- display_manager->SetDisplayUIScale(display1.id(), 1.25);
+ SetDisplayUIScale(display1.id(), 1.25f);
display1 = Shell::GetScreen()->GetPrimaryDisplay();
display2 = ScreenUtil::GetSecondaryDisplay();
magnifier->SetEnabled(true);
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc
index b4ccd36..f483044 100644
--- a/ash/test/ash_test_base.cc
+++ b/ash/test/ash_test_base.cc
@@ -224,10 +224,7 @@ bool AshTestBase::SupportsHostWindowResize() {
}
void AshTestBase::UpdateDisplay(const std::string& display_specs) {
- DisplayManager* display_manager = Shell::GetInstance()->display_manager();
- DisplayManagerTestApi display_manager_test_api(display_manager);
- display_manager_test_api.UpdateDisplay(display_specs);
- display_manager->RunPendingTasksForTest();
+ DisplayManagerTestApi().UpdateDisplay(display_specs);
}
aura::Window* AshTestBase::CurrentContext() {
diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc
index 60b8f3e..60a3a31 100644
--- a/ash/test/ash_test_helper.cc
+++ b/ash/test/ash_test_helper.cc
@@ -102,8 +102,7 @@ void AshTestHelper::SetUp(bool start_session) {
GetTestSessionStateDelegate()->SetHasActiveUser(true);
}
- test::DisplayManagerTestApi(shell->display_manager()).
- DisableChangeDisplayUponHostResize();
+ test::DisplayManagerTestApi().DisableChangeDisplayUponHostResize();
ShellTestApi(shell).DisableDisplayConfiguratorAnimation();
test_screenshot_delegate_ = new TestScreenshotDelegate();
diff --git a/ash/test/display_manager_test_api.cc b/ash/test/display_manager_test_api.cc
index 6df43b2..434c7a9 100644
--- a/ash/test/display_manager_test_api.cc
+++ b/ash/test/display_manager_test_api.cc
@@ -107,8 +107,8 @@ void DisplayManagerTestApi::EnableUnifiedDesktopForTest() {
#endif
}
-DisplayManagerTestApi::DisplayManagerTestApi(DisplayManager* display_manager)
- : display_manager_(display_manager) {}
+DisplayManagerTestApi::DisplayManagerTestApi()
+ : display_manager_(Shell::GetInstance()->display_manager()) {}
DisplayManagerTestApi::~DisplayManagerTestApi() {}
@@ -145,6 +145,7 @@ void DisplayManagerTestApi::UpdateDisplay(
display_manager_->OnNativeDisplaysChanged(display_info_list);
display_manager_->UpdateInternalDisplayModeListForTest();
+ display_manager_->RunPendingTasksForTest();
}
int64 DisplayManagerTestApi::SetFirstDisplayAsInternalDisplay() {
@@ -177,5 +178,22 @@ ScopedDisable125DSFForUIScaling::~ScopedDisable125DSFForUIScaling() {
DisplayInfo::SetUse125DSFForUIScalingForTest(true);
}
+ScopedSetInternalDisplayId::ScopedSetInternalDisplayId(int64 id) {
+ DisplayManagerTestApi().SetInternalDisplayId(id);
+}
+
+ScopedSetInternalDisplayId::~ScopedSetInternalDisplayId() {
+ gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID);
+}
+
+bool SetDisplayResolution(int64 display_id, const gfx::Size& resolution) {
+ DisplayManager* display_manager = Shell::GetInstance()->display_manager();
+ const DisplayInfo& info = display_manager->GetDisplayInfo(display_id);
+ DisplayMode mode;
+ if (!GetDisplayModeForResolution(info, resolution, &mode))
+ return false;
+ return display_manager->SetDisplayMode(display_id, mode);
+}
+
} // namespace test
} // namespace ash
diff --git a/ash/test/display_manager_test_api.h b/ash/test/display_manager_test_api.h
index 9088b04..b73e65d8 100644
--- a/ash/test/display_manager_test_api.h
+++ b/ash/test/display_manager_test_api.h
@@ -13,6 +13,7 @@
namespace gfx {
class Point;
+class Size;
}
namespace ui {
@@ -35,7 +36,7 @@ class DisplayManagerTestApi {
static void EnableUnifiedDesktopForTest();
- explicit DisplayManagerTestApi(DisplayManager* display_manager);
+ DisplayManagerTestApi();
virtual ~DisplayManagerTestApi();
// Update the display configuration as given in |display_specs|. The format of
@@ -48,10 +49,6 @@ class DisplayManagerTestApi {
// the internal display.
int64 SetFirstDisplayAsInternalDisplay();
- // Sets the display id for internal display and
- // update the display mode list if necessary.
- void SetInternalDisplayId(int64 id);
-
// Don't update the display when the root window's size was changed.
void DisableChangeDisplayUponHostResize();
@@ -61,6 +58,11 @@ class DisplayManagerTestApi {
const std::vector<ui::ColorCalibrationProfile>& profiles);
private:
+ friend class ScopedSetInternalDisplayId;
+ // Sets the display id for internal display and
+ // update the display mode list if necessary.
+ void SetInternalDisplayId(int64 id);
+
DisplayManager* display_manager_; // not owned
DISALLOW_COPY_AND_ASSIGN(DisplayManagerTestApi);
@@ -75,6 +77,18 @@ class ScopedDisable125DSFForUIScaling {
DISALLOW_COPY_AND_ASSIGN(ScopedDisable125DSFForUIScaling);
};
+class ScopedSetInternalDisplayId {
+ public:
+ ScopedSetInternalDisplayId(int64 id);
+ ~ScopedSetInternalDisplayId();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScopedSetInternalDisplayId);
+};
+
+// Sets the display mode that matches the |resolution| for |display_id|.
+bool SetDisplayResolution(int64 display_id, const gfx::Size& resolution);
+
} // namespace test
} // namespace ash
diff --git a/ash/touch/touch_observer_hud_unittest.cc b/ash/touch/touch_observer_hud_unittest.cc
index c68b841..7a3cf22 100644
--- a/ash/touch/touch_observer_hud_unittest.cc
+++ b/ash/touch/touch_observer_hud_unittest.cc
@@ -31,8 +31,8 @@ class TouchHudTestBase : public test::AshTestBase {
// Initialize display infos. They should be initialized after Ash
// environment is set up, i.e., after test::AshTestBase::SetUp().
- internal_display_id_ = test::DisplayManagerTestApi(GetDisplayManager()).
- SetFirstDisplayAsInternalDisplay();
+ internal_display_id_ =
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
external_display_id_ = 10;
mirrored_display_id_ = 11;
diff --git a/ash/wm/ash_native_cursor_manager_unittest.cc b/ash/wm/ash_native_cursor_manager_unittest.cc
index f29b924..abb22c9 100644
--- a/ash/wm/ash_native_cursor_manager_unittest.cc
+++ b/ash/wm/ash_native_cursor_manager_unittest.cc
@@ -6,6 +6,7 @@
#include "ash/display/display_info.h"
#include "ash/display/display_manager.h"
+#include "ash/display/display_util.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/cursor_manager_test_api.h"
@@ -163,21 +164,20 @@ TEST_F(AshNativeCursorManagerTest, UIScaleShouldNotChangeCursor) {
::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
CursorManagerTestApi test_api(cursor_manager);
- DisplayManager* display_manager = Shell::GetInstance()->display_manager();
- display_manager->SetDisplayUIScale(display_id, 0.5f);
+ SetDisplayUIScale(display_id, 0.5f);
EXPECT_EQ(1.0f,
Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
- display_manager->SetDisplayUIScale(display_id, 1.0f);
+ SetDisplayUIScale(display_id, 1.0f);
// 2x display should keep using 2x cursor regardless of the UI scale.
UpdateDisplay("800x800*2");
EXPECT_EQ(2.0f,
Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
- display_manager->SetDisplayUIScale(display_id, 2.0f);
+ SetDisplayUIScale(display_id, 2.0f);
EXPECT_EQ(1.0f,
Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
diff --git a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
index 6153984..0bc8634 100644
--- a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
+++ b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
@@ -75,8 +75,7 @@ class MaximizeModeControllerTest : public test::AshTestBase {
// Set the first display to be the internal display for the accelerometer
// screen rotation tests.
- test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()).
- SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
}
void TearDown() override {
diff --git a/ash/wm/system_gesture_event_filter_unittest.cc b/ash/wm/system_gesture_event_filter_unittest.cc
index 99d845c..0cbb027 100644
--- a/ash/wm/system_gesture_event_filter_unittest.cc
+++ b/ash/wm/system_gesture_event_filter_unittest.cc
@@ -148,8 +148,7 @@ class SystemGestureEventFilterTest : public AshTestBase {
test::AshTestBase::SetUp();
// Enable brightness key.
- test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()).
- SetFirstDisplayAsInternalDisplay();
+ test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
}
private:
diff --git a/chrome/browser/chromeos/display/display_preferences_unittest.cc b/chrome/browser/chromeos/display/display_preferences_unittest.cc
index 22e80a1..e818139 100644
--- a/chrome/browser/chromeos/display/display_preferences_unittest.cc
+++ b/chrome/browser/chromeos/display/display_preferences_unittest.cc
@@ -11,6 +11,7 @@
#include "ash/display/display_controller.h"
#include "ash/display/display_layout_store.h"
#include "ash/display/display_manager.h"
+#include "ash/display/display_util.h"
#include "ash/display/resolution_notification_controller.h"
#include "ash/screen_util.h"
#include "ash/shell.h"
@@ -244,8 +245,7 @@ TEST_F(DisplayPreferencesTest, BasicStores) {
UpdateDisplay("200x200*2, 400x300#400x400|300x200*1.25");
int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id();
- ash::test::DisplayManagerTestApi test_api(display_manager);
- test_api.SetInternalDisplayId(id1);
+ ash::test::ScopedSetInternalDisplayId set_internal(id1);
int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id();
int64 dummy_id = id2 + 1;
ASSERT_NE(id1, dummy_id);
@@ -255,7 +255,7 @@ TEST_F(DisplayPreferencesTest, BasicStores) {
profiles.push_back(ui::COLOR_PROFILE_MOVIE);
profiles.push_back(ui::COLOR_PROFILE_READING);
// Allows only |id1|.
- test_api.SetAvailableColorProfiles(id1, profiles);
+ ash::test::DisplayManagerTestApi().SetAvailableColorProfiles(id1, profiles);
display_manager->SetColorCalibrationProfile(id1, ui::COLOR_PROFILE_DYNAMIC);
display_manager->SetColorCalibrationProfile(id2, ui::COLOR_PROFILE_DYNAMIC);
@@ -271,8 +271,8 @@ TEST_F(DisplayPreferencesTest, BasicStores) {
display_controller->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13));
display_manager->SetDisplayRotation(id1, gfx::Display::ROTATE_90,
gfx::Display::ROTATION_SOURCE_USER);
- EXPECT_TRUE(display_manager->SetDisplayUIScale(id1, 1.25f));
- EXPECT_FALSE(display_manager->SetDisplayUIScale(id2, 1.25f));
+ EXPECT_TRUE(ash::SetDisplayUIScale(id1, 1.25f));
+ EXPECT_FALSE(ash::SetDisplayUIScale(id2, 1.25f));
const base::DictionaryValue* displays =
local_state()->GetDictionary(prefs::kSecondaryDisplays);
@@ -572,8 +572,7 @@ TEST_F(DisplayPreferencesTest, RestoreColorProfiles) {
profiles.push_back(ui::COLOR_PROFILE_DYNAMIC);
profiles.push_back(ui::COLOR_PROFILE_MOVIE);
profiles.push_back(ui::COLOR_PROFILE_READING);
- ash::test::DisplayManagerTestApi test_api(display_manager);
- test_api.SetAvailableColorProfiles(id1, profiles);
+ ash::test::DisplayManagerTestApi().SetAvailableColorProfiles(id1, profiles);
LoadDisplayPreferences(false);
EXPECT_EQ(ui::COLOR_PROFILE_DYNAMIC,
@@ -583,19 +582,18 @@ TEST_F(DisplayPreferencesTest, RestoreColorProfiles) {
TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) {
ash::DisplayController* display_controller =
ash::Shell::GetInstance()->display_controller();
- ash::DisplayManager* display_manager =
- ash::Shell::GetInstance()->display_manager();
UpdateDisplay("200x200*2,200x200");
LoggedInAsGuest();
int64 id1 = ash::Shell::GetScreen()->GetPrimaryDisplay().id();
- ash::test::DisplayManagerTestApi(display_manager)
- .SetInternalDisplayId(id1);
+ ash::test::ScopedSetInternalDisplayId set_internal(id1);
int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id();
ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10);
SetCurrentDisplayLayout(layout);
- display_manager->SetDisplayUIScale(id1, 1.25f);
+ ash::DisplayManager* display_manager =
+ ash::Shell::GetInstance()->display_manager();
+ ash::SetDisplayUIScale(id1, 1.25f);
display_controller->SetPrimaryDisplayId(id2);
int64 new_primary = ash::Shell::GetScreen()->GetPrimaryDisplay().id();
display_controller->SetOverscanInsets(
@@ -910,7 +908,7 @@ TEST_F(DisplayPreferencesTest, SaveUnifiedMode) {
int ui_scale = 0;
EXPECT_FALSE(new_value->GetInteger("ui-scale", &ui_scale));
- display_manager->SetDisplayUIScale(unified_id, 0.5f);
+ ash::SetDisplayUIScale(unified_id, 0.5f);
EXPECT_EQ(
"200x100",
gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().size().ToString());
diff --git a/chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc b/chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc
index 8656175..448d058 100644
--- a/chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc
+++ b/chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc
@@ -87,9 +87,7 @@ class WallpaperManagerBrowserTest : public InProcessBrowserTest {
// Update the display configuration as given in |display_specs|. See
// ash::test::DisplayManagerTestApi::UpdateDisplay for more details.
void UpdateDisplay(const std::string& display_specs) {
- ash::test::DisplayManagerTestApi display_manager_test_api(
- ash::Shell::GetInstance()->display_manager());
- display_manager_test_api.UpdateDisplay(display_specs);
+ ash::test::DisplayManagerTestApi().UpdateDisplay(display_specs);
}
void WaitAsyncWallpaperLoadStarted() {
diff --git a/chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc b/chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc
index 2cc37d5..8072b95 100644
--- a/chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc
+++ b/chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc
@@ -48,10 +48,7 @@ class ForceMaximizeOnFirstRunTest : public LoginPolicyTestBase,
ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100;
// Set resolution to 1466x300.
const std::string resolution = base::IntToString(width) + "x300";
- ash::DisplayManager* const display_manager =
- ash::Shell::GetInstance()->display_manager();
- ash::test::DisplayManagerTestApi display_manager_test_api(display_manager);
- display_manager_test_api.UpdateDisplay(resolution);
+ ash::test::DisplayManagerTestApi().UpdateDisplay(resolution);
}
const Browser* OpenNewBrowserWindow() {
diff --git a/chrome/browser/extensions/display_info_provider_chromeos_unittest.cc b/chrome/browser/extensions/display_info_provider_chromeos_unittest.cc
index 4429bfa..36f861f 100644
--- a/chrome/browser/extensions/display_info_provider_chromeos_unittest.cc
+++ b/chrome/browser/extensions/display_info_provider_chromeos_unittest.cc
@@ -944,8 +944,7 @@ TEST_F(DisplayInfoProviderChromeosTest, SetOverscan) {
TEST_F(DisplayInfoProviderChromeosTest, SetOverscanForInternal) {
UpdateDisplay("1200x600,600x1000*2");
const int64 internal_display_id =
- ash::test::DisplayManagerTestApi(GetDisplayManager())
- .SetFirstDisplayAsInternalDisplay();
+ ash::test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
api::system_display::DisplayProperties info;
info.overscan.reset(new api::system_display::Insets);
diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos_browsertest_chromeos.cc b/chrome/browser/ui/ash/system_tray_delegate_chromeos_browsertest_chromeos.cc
index ebafe38..0bb1fcd 100644
--- a/chrome/browser/ui/ash/system_tray_delegate_chromeos_browsertest_chromeos.cc
+++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos_browsertest_chromeos.cc
@@ -64,11 +64,7 @@ class DisplayNotificationsTest : public InProcessBrowserTest {
void SetUp() override { InProcessBrowserTest::SetUp(); }
void UpdateDisplay(const std::string& display_specs) {
- ash::DisplayManager* display_manager =
- ash::Shell::GetInstance()->display_manager();
- ash::test::DisplayManagerTestApi display_manager_test_api(display_manager);
- display_manager_test_api.UpdateDisplay(display_specs);
- display_manager->RunPendingTasksForTest();
+ ash::test::DisplayManagerTestApi().UpdateDisplay(display_specs);
}
message_center::NotificationList::Notifications GetVisibleNotifications()