diff options
28 files changed, 204 insertions, 148 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index 6ef3ac6..5141766 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -851,6 +851,7 @@ bool AcceleratorController::CanPerformAction( return CanHandlePositionCenter(); #if defined(OS_CHROMEOS) case DEBUG_ADD_REMOVE_DISPLAY: + case DEBUG_TOGGLE_UNIFIED_DESKTOP: return debug::DebugAcceleratorsEnabled(); case DISABLE_CAPS_LOCK: return CanHandleDisableCapsLock(previous_accelerator); @@ -1107,6 +1108,9 @@ void AcceleratorController::PerformAction(AcceleratorAction action, case DEBUG_ADD_REMOVE_DISPLAY: debug::PerformDebugActionIfEnabled(action); break; + case DEBUG_TOGGLE_UNIFIED_DESKTOP: + debug::PerformDebugActionIfEnabled(action); + break; case DISABLE_CAPS_LOCK: HandleDisableCapsLock(); break; diff --git a/ash/accelerators/accelerator_table.cc b/ash/accelerators/accelerator_table.cc index f3a0a49..3f02fcc 100644 --- a/ash/accelerators/accelerator_table.cc +++ b/ash/accelerators/accelerator_table.cc @@ -179,50 +179,58 @@ const size_t kAcceleratorDataLength = arraysize(kAcceleratorData); const AcceleratorData kDebugAcceleratorData[] = { #if defined(OS_CHROMEOS) - // Extra shortcut for debug build to control magnifier on linux desktop. - { true, ui::VKEY_BRIGHTNESS_DOWN, ui::EF_CONTROL_DOWN, - MAGNIFY_SCREEN_ZOOM_OUT}, - { true, ui::VKEY_BRIGHTNESS_UP, ui::EF_CONTROL_DOWN, MAGNIFY_SCREEN_ZOOM_IN}, - // Extra shortcuts to lock the screen on linux desktop. - { true, ui::VKEY_L, ui::EF_ALT_DOWN, LOCK_SCREEN }, - { true, ui::VKEY_POWER, ui::EF_SHIFT_DOWN, LOCK_PRESSED }, - { false, ui::VKEY_POWER, ui::EF_SHIFT_DOWN, LOCK_RELEASED }, - { true, ui::VKEY_D, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, - DEBUG_ADD_REMOVE_DISPLAY }, - { true, ui::VKEY_M, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, - TOGGLE_MIRROR_MODE }, - { true, ui::VKEY_W, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, TOGGLE_WIFI }, - // Extra shortcut for display swapping as alt-f4 is taken on linux desktop. - { true, ui::VKEY_S, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, - SWAP_PRIMARY_DISPLAY }, + // Extra shortcut for debug build to control magnifier on linux desktop. + {true, ui::VKEY_BRIGHTNESS_DOWN, ui::EF_CONTROL_DOWN, + MAGNIFY_SCREEN_ZOOM_OUT}, + {true, ui::VKEY_BRIGHTNESS_UP, ui::EF_CONTROL_DOWN, MAGNIFY_SCREEN_ZOOM_IN}, + // Extra shortcuts to lock the screen on linux desktop. + {true, ui::VKEY_L, ui::EF_ALT_DOWN, LOCK_SCREEN}, + {true, ui::VKEY_POWER, ui::EF_SHIFT_DOWN, LOCK_PRESSED}, + {false, ui::VKEY_POWER, ui::EF_SHIFT_DOWN, LOCK_RELEASED}, + {true, ui::VKEY_D, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, + DEBUG_ADD_REMOVE_DISPLAY}, + {true, ui::VKEY_J, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, + DEBUG_TOGGLE_UNIFIED_DESKTOP}, + {true, ui::VKEY_M, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, + TOGGLE_MIRROR_MODE}, + {true, ui::VKEY_W, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, TOGGLE_WIFI}, + // Extra shortcut for display swapping as alt-f4 is taken on linux desktop. + {true, ui::VKEY_S, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, + SWAP_PRIMARY_DISPLAY}, #endif - // Extra shortcut to rotate/scale up/down the screen on linux desktop. - { true, ui::VKEY_R, - ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, ROTATE_SCREEN }, - // For testing on systems where Alt-Tab is already mapped. - { true, ui::VKEY_W, ui::EF_ALT_DOWN, CYCLE_FORWARD_MRU }, - { true, ui::VKEY_F11, ui::EF_CONTROL_DOWN, - DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN }, - { true, ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, - CYCLE_BACKWARD_MRU }, - { true, ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, - DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE }, - { true, ui::VKEY_F, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, - TOGGLE_FULLSCREEN }, - { true, ui::VKEY_L, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, - DEBUG_PRINT_LAYER_HIERARCHY }, - { true, ui::VKEY_V, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, - DEBUG_PRINT_VIEW_HIERARCHY }, - { true, ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, - DEBUG_PRINT_WINDOW_HIERARCHY }, - { true, ui::VKEY_S, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, - DEBUG_TOGGLE_DEVICE_SCALE_FACTOR }, - { true, ui::VKEY_B, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, - DEBUG_TOGGLE_SHOW_DEBUG_BORDERS }, - { true, ui::VKEY_F, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, - DEBUG_TOGGLE_SHOW_FPS_COUNTER }, - { true, ui::VKEY_P, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, - DEBUG_TOGGLE_SHOW_PAINT_RECTS }, + // Extra shortcut to rotate/scale up/down the screen on linux desktop. + {true, ui::VKEY_R, + ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, ROTATE_SCREEN}, + // For testing on systems where Alt-Tab is already mapped. + {true, ui::VKEY_W, ui::EF_ALT_DOWN, CYCLE_FORWARD_MRU}, + {true, ui::VKEY_F11, ui::EF_CONTROL_DOWN, + DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN}, + {true, ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, CYCLE_BACKWARD_MRU}, + {true, ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, + DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE}, + {true, ui::VKEY_F, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, + TOGGLE_FULLSCREEN}, + {true, ui::VKEY_L, + ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, + DEBUG_PRINT_LAYER_HIERARCHY}, + {true, ui::VKEY_V, + ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, + DEBUG_PRINT_VIEW_HIERARCHY}, + {true, ui::VKEY_W, + ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, + DEBUG_PRINT_WINDOW_HIERARCHY}, + {true, ui::VKEY_S, + ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, + DEBUG_TOGGLE_DEVICE_SCALE_FACTOR}, + {true, ui::VKEY_B, + ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, + DEBUG_TOGGLE_SHOW_DEBUG_BORDERS}, + {true, ui::VKEY_F, + ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, + DEBUG_TOGGLE_SHOW_FPS_COUNTER}, + {true, ui::VKEY_P, + ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, + DEBUG_TOGGLE_SHOW_PAINT_RECTS}, }; const size_t kDebugAcceleratorDataLength = arraysize(kDebugAcceleratorData); diff --git a/ash/accelerators/accelerator_table.h b/ash/accelerators/accelerator_table.h index 86ec318..089e240 100644 --- a/ash/accelerators/accelerator_table.h +++ b/ash/accelerators/accelerator_table.h @@ -112,6 +112,7 @@ enum AcceleratorAction { BRIGHTNESS_DOWN, BRIGHTNESS_UP, DEBUG_ADD_REMOVE_DISPLAY, + DEBUG_TOGGLE_UNIFIED_DESKTOP, DISABLE_CAPS_LOCK, DISABLE_GPU_WATCHDOG, KEYBOARD_BRIGHTNESS_DOWN, diff --git a/ash/accelerators/debug_commands.cc b/ash/accelerators/debug_commands.cc index 5ce0c7c..fe4589d 100644 --- a/ash/accelerators/debug_commands.cc +++ b/ash/accelerators/debug_commands.cc @@ -148,6 +148,10 @@ void PerformDebugActionIfEnabled(AcceleratorAction action) { case DEBUG_ADD_REMOVE_DISPLAY: Shell::GetInstance()->display_manager()->AddRemoveDisplay(); break; + case DEBUG_TOGGLE_UNIFIED_DESKTOP: + Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled( + !Shell::GetInstance()->display_manager()->unified_desktop_enabled()); + break; #endif case DEBUG_PRINT_LAYER_HIERARCHY: HandlePrintLayerHierarchy(); diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index 14e79cb..fdbe279 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -136,11 +136,6 @@ bool ConstrainPointerToRoot() { kAshConstrainPointerToRoot); } -bool UnifiedDesktopEnabled() { - return base::CommandLine::ForCurrentProcess()->HasSwitch( - kAshEnableUnifiedDesktop); -} - #endif } // namespace switches diff --git a/ash/ash_switches.h b/ash/ash_switches.h index 0b5e030..ed8f878 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -51,8 +51,6 @@ ASH_EXPORT extern const char kForceAshToDesktop[]; #if defined(OS_CHROMEOS) // True if the pointer (cursor) position should be kept inside root windows. ASH_EXPORT bool ConstrainPointerToRoot(); - -ASH_EXPORT bool UnifiedDesktopEnabled(); #endif } // namespace switches diff --git a/ash/display/display_layout.cc b/ash/display/display_layout.cc index 2cf54a6..9816f21 100644 --- a/ash/display/display_layout.cc +++ b/ash/display/display_layout.cc @@ -5,7 +5,9 @@ #include "ash/display/display_layout.h" #include "ash/ash_switches.h" +#include "ash/display/display_manager.h" #include "ash/display/display_pref_util.h" +#include "ash/shell.h" #include "base/json/json_value_converter.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" @@ -72,7 +74,7 @@ DisplayLayout::DisplayLayout() offset(0), mirrored(false), #if defined(OS_CHROMEOS) - default_unified(switches::UnifiedDesktopEnabled()), + default_unified(true), #else default_unified(false), #endif @@ -84,7 +86,7 @@ DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset) offset(offset), mirrored(false), #if defined(OS_CHROMEOS) - default_unified(switches::UnifiedDesktopEnabled()), + default_unified(true), #else default_unified(false), #endif @@ -146,9 +148,13 @@ bool DisplayLayout::ConvertToValue(const DisplayLayout& layout, std::string DisplayLayout::ToString() const { const std::string position_str = GetStringFromPosition(position); + bool unified = + default_unified && + Shell::GetInstance()->display_manager()->unified_desktop_enabled(); + return base::StringPrintf("%s, %d%s%s", position_str.c_str(), offset, mirrored ? ", mirrored" : "", - default_unified ? ", unified" : ""); + unified ? ", unified" : ""); } // static diff --git a/ash/display/display_layout.h b/ash/display/display_layout.h index df966b2..e5623f4 100644 --- a/ash/display/display_layout.h +++ b/ash/display/display_layout.h @@ -66,6 +66,7 @@ struct ASH_EXPORT DisplayLayout { int64 primary_id; // Returns string representation of the layout for debugging/testing. + // This includes "unified" only if the unified desktop feature is enabled. std::string ToString() const; }; diff --git a/ash/display/display_layout_store.cc b/ash/display/display_layout_store.cc index 2f5dc2b..c002e04 100644 --- a/ash/display/display_layout_store.cc +++ b/ash/display/display_layout_store.cc @@ -51,11 +51,6 @@ void DisplayLayoutStore::RegisterLayoutForDisplayIdPair( const DisplayLayout& layout) { auto key = CreateDisplayIdPair(id1, id2); paired_layouts_[key] = layout; -#if defined(OS_CHROMEOS) - // Force disabling unified desktop if the flag is not set. - if (!switches::UnifiedDesktopEnabled()) - paired_layouts_[key].default_unified = false; -#endif } DisplayLayout DisplayLayoutStore::GetRegisteredDisplayLayout( diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index 88987f0..dba2e0a 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -51,8 +51,6 @@ #include "base/win/windows_version.h" #endif -#include "base/debug/stack_trace.h" - namespace ash { typedef std::vector<gfx::Display> DisplayList; typedef std::vector<DisplayInfo> DisplayInfoList; @@ -69,13 +67,13 @@ const int kMinimumOverlapForInvalidOffset = 100; struct DisplaySortFunctor { bool operator()(const gfx::Display& a, const gfx::Display& b) { - return a.id() < b.id(); + return CompareDisplayIds(a.id(), b.id()); } }; struct DisplayInfoSortFunctor { bool operator()(const DisplayInfo& a, const DisplayInfo& b) { - return a.id() < b.id(); + return CompareDisplayIds(a.id(), b.id()); } }; @@ -137,13 +135,16 @@ DisplayManager::DisplayManager() force_bounds_changed_(false), change_display_upon_host_resize_(false), multi_display_mode_(EXTENDED), - default_multi_display_mode_(EXTENDED), + current_default_multi_display_mode_(EXTENDED), mirroring_display_id_(gfx::Display::kInvalidDisplayID), registered_internal_display_rotation_lock_(false), registered_internal_display_rotation_(gfx::Display::ROTATE_0), + unified_desktop_enabled_(false), weak_ptr_factory_(this) { #if defined(OS_CHROMEOS) change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); + unified_desktop_enabled_ = base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kAshEnableUnifiedDesktop); #endif gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, screen_.get()); gfx::Screen* current_native = @@ -621,19 +622,14 @@ void DisplayManager::OnNativeDisplaysChanged( } #if defined(OS_CHROMEOS) - if (new_display_info_list.size() > 1) { - std::sort(new_display_info_list.begin(), new_display_info_list.end(), - DisplayInfoSortFunctor()); + if (!base::SysInfo::IsRunningOnChromeOS() && + new_display_info_list.size() > 1) { DisplayIdPair pair = CreateDisplayIdPair(new_display_info_list[0].id(), new_display_info_list[1].id()); DisplayLayout layout = layout_store_->GetRegisteredDisplayLayout(pair); - default_multi_display_mode_ = - (layout.default_unified && switches::UnifiedDesktopEnabled()) - ? UNIFIED - : EXTENDED; // Mirror mode is set by DisplayConfigurator on the device. // Emulate it when running on linux desktop. - if (!base::SysInfo::IsRunningOnChromeOS() && layout.mirrored) + if (layout.mirrored) SetMultiDisplayMode(MIRRORING); } #endif @@ -664,8 +660,17 @@ void DisplayManager::UpdateDisplays( new_display_info_list.end(), DisplayInfoSortFunctor()); + if (new_display_info_list.size() > 1) { + DisplayIdPair pair = CreateDisplayIdPair(new_display_info_list[0].id(), + new_display_info_list[1].id()); + DisplayLayout layout = layout_store_->GetRegisteredDisplayLayout(pair); + current_default_multi_display_mode_ = + (layout.default_unified && unified_desktop_enabled_) ? UNIFIED + : EXTENDED; + } + if (multi_display_mode_ != MIRRORING) - multi_display_mode_ = default_multi_display_mode_; + multi_display_mode_ = current_default_multi_display_mode_; CreateSoftwareMirroringDisplayInfo(&new_display_info_list); @@ -871,6 +876,11 @@ bool DisplayManager::IsInMirrorMode() const { return mirroring_display_id_ != gfx::Display::kInvalidDisplayID; } +void DisplayManager::SetUnifiedDesktopEnabled(bool enable) { + unified_desktop_enabled_ = enable; + ReconfigureDisplays(); +} + bool DisplayManager::IsInUnifiedMode() const { return multi_display_mode_ == UNIFIED && !software_mirroring_display_list_.empty(); @@ -925,7 +935,8 @@ void DisplayManager::SetMirrorMode(bool mirror) { Shell::GetInstance()->display_configurator()->SetDisplayMode(new_state); return; } - multi_display_mode_ = mirror ? MIRRORING : default_multi_display_mode_; + multi_display_mode_ = + mirror ? MIRRORING : current_default_multi_display_mode_; ReconfigureDisplays(); if (Shell::GetInstance()->display_configurator_animation()) { Shell::GetInstance()->display_configurator_animation()-> @@ -975,7 +986,8 @@ void DisplayManager::ToggleDisplayScaleFactor() { #if defined(OS_CHROMEOS) void DisplayManager::SetSoftwareMirroring(bool enabled) { - SetMultiDisplayMode(enabled ? MIRRORING : default_multi_display_mode_); + SetMultiDisplayMode(enabled ? MIRRORING + : current_default_multi_display_mode_); } bool DisplayManager::SoftwareMirroringEnabled() const { @@ -983,17 +995,20 @@ bool DisplayManager::SoftwareMirroringEnabled() const { } #endif +void DisplayManager::SetDefaultMultiDisplayModeForCurrentDisplays( + MultiDisplayMode mode) { + DCHECK_NE(MIRRORING, mode); + DisplayIdPair pair = GetCurrentDisplayIdPair(); + layout_store_->UpdateMultiDisplayState(pair, IsInMirrorMode(), + mode == UNIFIED); +} + void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { multi_display_mode_ = mode; mirroring_display_id_ = gfx::Display::kInvalidDisplayID; software_mirroring_display_list_.clear(); } -void DisplayManager::SetDefaultMultiDisplayMode(MultiDisplayMode mode) { - DCHECK_NE(mode, MIRRORING); - default_multi_display_mode_ = mode; -} - void DisplayManager::ReconfigureDisplays() { DisplayInfoList display_info_list; for (DisplayList::const_iterator iter = active_display_list_.begin(); diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h index 481310b..fa5cccf 100644 --- a/ash/display/display_manager.h +++ b/ash/display/display_manager.h @@ -250,6 +250,12 @@ class ASH_EXPORT DisplayManager const DisplayList& software_mirroring_display_list() const { return software_mirroring_display_list_; } + + // Sets/gets if the unified desktop feature is enabled. + void SetUnifiedDesktopEnabled(bool enabled); + bool unified_desktop_enabled() const { return unified_desktop_enabled_; } + + // Returns true if it's in unified desktop mode. bool IsInUnifiedMode() const; // Returns the display used for software mirrroring. Returns invalid @@ -282,15 +288,15 @@ class ASH_EXPORT DisplayManager bool SoftwareMirroringEnabled() const override; #endif - // Sets/gets multi display mode. - void SetMultiDisplayMode(MultiDisplayMode mode); - // Sets/gets default multi display mode. - void SetDefaultMultiDisplayMode(MultiDisplayMode mode); - MultiDisplayMode default_multi_display_mode() const { - return default_multi_display_mode_; + void SetDefaultMultiDisplayModeForCurrentDisplays(MultiDisplayMode mode); + MultiDisplayMode current_default_multi_display_mode() const { + return current_default_multi_display_mode_; } + // Sets multi display mode. + void SetMultiDisplayMode(MultiDisplayMode mode); + // Reconfigure display configuration using the same // physical display. TODO(oshima): Refactor and move this // impl to |SetDefaultMultiDisplayMode|. @@ -421,7 +427,7 @@ private: bool change_display_upon_host_resize_; MultiDisplayMode multi_display_mode_; - MultiDisplayMode default_multi_display_mode_; + MultiDisplayMode current_default_multi_display_mode_; int64 mirroring_display_id_; DisplayList software_mirroring_display_list_; @@ -432,6 +438,8 @@ private: // User preference for the rotation of the internal display. gfx::Display::Rotation registered_internal_display_rotation_; + bool unified_desktop_enabled_; + base::WeakPtrFactory<DisplayManager> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(DisplayManager); diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc index e3c05e4..822452e 100644 --- a/ash/display/display_manager_unittest.cc +++ b/ash/display/display_manager_unittest.cc @@ -658,7 +658,7 @@ TEST_F(DisplayManagerTest, DisplayAddRemoveAtTheSameTime) { DisplayInfo secondary_info = display_manager()->GetDisplayInfo(secondary_id); // An id which is different from primary and secondary. - const int64 third_id = primary_id + secondary_id; + const int64 third_id = secondary_id + 1; DisplayInfo third_info = CreateDisplayInfo(third_id, gfx::Rect(0, 0, 600, 600)); @@ -1120,13 +1120,11 @@ TEST_F(DisplayManagerTest, Use125DSFForUIScaling) { TEST_F(DisplayManagerTest, ResolutionChangeInUnifiedMode) { if (!SupportsMultipleDisplays()) return; - - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); - // Don't check root window destruction in unified mode. Shell::GetPrimaryRootWindow()->RemoveObserver(this); DisplayManager* display_manager = Shell::GetInstance()->display_manager(); + display_manager->SetUnifiedDesktopEnabled(true); UpdateDisplay("200x200, 400x400"); @@ -1520,13 +1518,15 @@ TEST_F(DisplayManagerTest, MAYBE_UpdateDisplayWithHostOrigin) { TEST_F(DisplayManagerTest, UnifiedDesktopBasic) { if (!SupportsMultipleDisplays()) return; - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); // Don't check root window destruction in unified mode. Shell::GetPrimaryRootWindow()->RemoveObserver(this); UpdateDisplay("400x500,300x200"); + // Enable after extended mode. + display_manager()->SetUnifiedDesktopEnabled(true); + // Defaults to the unified desktop. gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE); @@ -1562,19 +1562,35 @@ TEST_F(DisplayManagerTest, UnifiedDesktopBasic) { } // Switch back to extended desktop. - display_manager()->SetDefaultMultiDisplayMode(DisplayManager::EXTENDED); - display_manager()->ReconfigureDisplays(); + display_manager()->SetUnifiedDesktopEnabled(false); EXPECT_EQ("500x300", screen->GetPrimaryDisplay().size().ToString()); EXPECT_EQ("400x500", ScreenUtil::GetSecondaryDisplay().size().ToString()); } +TEST_F(DisplayManagerTest, UnifiedDesktopEnabledWithExtended) { + if (!SupportsMultipleDisplays()) + return; + // Don't check root window destruction in unified mode. + Shell::GetPrimaryRootWindow()->RemoveObserver(this); + + UpdateDisplay("400x500,300x200"); + DisplayIdPair pair = display_manager()->GetCurrentDisplayIdPair(); + DisplayLayout layout = + display_manager()->layout_store()->GetRegisteredDisplayLayout(pair); + layout.default_unified = false; + display_manager()->layout_store()->RegisterLayoutForDisplayIdPair( + pair.first, pair.second, layout); + display_manager()->SetUnifiedDesktopEnabled(true); + EXPECT_FALSE(display_manager()->IsInUnifiedMode()); +} + TEST_F(DisplayManagerTest, UnifiedDesktopWith2xDSF) { if (!SupportsMultipleDisplays()) return; // Don't check root window destruction in unified mode. Shell::GetPrimaryRootWindow()->RemoveObserver(this); - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); + display_manager()->SetUnifiedDesktopEnabled(true); gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE); @@ -1690,7 +1706,7 @@ TEST_F(DisplayManagerTest, ConfigureUnifiedTwice) { TEST_F(DisplayManagerTest, NoRotateUnifiedDesktop) { if (!SupportsMultipleDisplays()) return; - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); + display_manager()->SetUnifiedDesktopEnabled(true); // Don't check root window destruction in unified mode. Shell::GetPrimaryRootWindow()->RemoveObserver(this); @@ -1717,7 +1733,7 @@ TEST_F(DisplayManagerTest, NoRotateUnifiedDesktop) { TEST_F(DisplayManagerTest, UnifiedWithDockWindows) { if (!SupportsMultipleDisplays()) return; - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); + display_manager()->SetUnifiedDesktopEnabled(true); // Don't check root window destruction in unified mode. Shell::GetPrimaryRootWindow()->RemoveObserver(this); diff --git a/ash/display/display_util.cc b/ash/display/display_util.cc index 5219dad..291b9a3 100644 --- a/ash/display/display_util.cc +++ b/ash/display/display_util.cc @@ -339,15 +339,19 @@ int FindDisplayIndexContainingPoint(const std::vector<gfx::Display>& displays, } DisplayIdPair CreateDisplayIdPair(int64 id1, int64 id2) { + return CompareDisplayIds(id1, id2) ? std::make_pair(id1, id2) + : std::make_pair(id2, id1); +} + +bool CompareDisplayIds(int64 id1, int64 id2) { DCHECK_NE(id1, id2); // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID // in edid_parser.cc. int index_1 = id1 & 0xFF; int index_2 = id2 & 0xFF; - if (gfx::Display::IsInternalDisplayId(id2) || index_2 < index_1) - return std::make_pair(id2, id1); - else - return std::make_pair(id1, id2); + DCHECK_NE(index_1, index_2) << id1 << " and " << id2; + return gfx::Display::IsInternalDisplayId(id1) || + (index_1 < index_2 && !gfx::Display::IsInternalDisplayId(id2)); } } // namespace ash diff --git a/ash/display/display_util.h b/ash/display/display_util.h index dd0784b..0e4dadf 100644 --- a/ash/display/display_util.h +++ b/ash/display/display_util.h @@ -87,11 +87,15 @@ ASH_EXPORT int FindDisplayIndexContainingPoint( const std::vector<gfx::Display>& displays, const gfx::Point& point_in_screen); -// Creates the DisplayIdPair where ids are sorted in the following manner. -// 1) ID for internal display comes first. -// 2) If none of the ids are internal, sorted by the output index. +// Creates the DisplayIdPair where ids are sorted using |CompareDisplayIds| +// below. ASH_EXPORT DisplayIdPair CreateDisplayIdPair(int64 id1, int64 id2); +// Returns true if one of following conditinos is met. +// 1) id1 is internal. +// 2) output index of id1 < output index of id2 and id2 isn't internal. +ASH_EXPORT bool CompareDisplayIds(int64 id1, int64 id2); + } // namespace ash #endif // ASH_DISPLAY_DISPLAY_UTIL_H_ diff --git a/ash/display/display_util_unittest.cc b/ash/display/display_util_unittest.cc index 1bd3d8c..1dcd0c7 100644 --- a/ash/display/display_util_unittest.cc +++ b/ash/display/display_util_unittest.cc @@ -98,11 +98,27 @@ TEST_F(DisplayUtilTest, CreateDisplayIdPair) { pair = CreateDisplayIdPair(10, 100); EXPECT_EQ(10, pair.first); EXPECT_EQ(100, pair.second); + { + test::ScopedSetInternalDisplayId set_internal(100); + pair = CreateDisplayIdPair(10, 100); + EXPECT_EQ(100, pair.first); + EXPECT_EQ(10, pair.second); - test::ScopedSetInternalDisplayId set_internal(100); - pair = CreateDisplayIdPair(10, 100); - EXPECT_EQ(100, pair.first); - EXPECT_EQ(10, pair.second); + pair = CreateDisplayIdPair(100, 10); + EXPECT_EQ(100, pair.first); + EXPECT_EQ(10, pair.second); + } + + { + test::ScopedSetInternalDisplayId set_internal(10); + pair = CreateDisplayIdPair(10, 100); + EXPECT_EQ(10, pair.first); + EXPECT_EQ(100, pair.second); + + pair = CreateDisplayIdPair(100, 10); + EXPECT_EQ(10, pair.first); + EXPECT_EQ(100, pair.second); + } } } // namespace diff --git a/ash/display/unified_mouse_warp_controller_unittest.cc b/ash/display/unified_mouse_warp_controller_unittest.cc index 599d6ee..e176141 100644 --- a/ash/display/unified_mouse_warp_controller_unittest.cc +++ b/ash/display/unified_mouse_warp_controller_unittest.cc @@ -4,6 +4,7 @@ #include "ash/display/unified_mouse_warp_controller.h" +#include "ash/display/display_manager.h" #include "ash/display/mouse_cursor_event_filter.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" @@ -22,7 +23,7 @@ class UnifiedMouseWarpControllerTest : public test::AshTestBase { void SetUp() override { test::AshTestBase::SetUp(); - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); + Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true); } protected: diff --git a/ash/display/window_tree_host_manager.cc b/ash/display/window_tree_host_manager.cc index f1e6aaf..77bec60 100644 --- a/ash/display/window_tree_host_manager.cc +++ b/ash/display/window_tree_host_manager.cc @@ -841,13 +841,11 @@ void WindowTreeHostManager::PostDisplayConfigurationChange() { DisplayLayoutStore* layout_store = display_manager->layout_store(); if (display_manager->num_connected_displays() > 1) { DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); + DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); layout_store->UpdateMultiDisplayState( - pair, display_manager->IsInMirrorMode(), - display_manager->default_multi_display_mode() == - DisplayManager::UNIFIED); + pair, display_manager->IsInMirrorMode(), layout.default_unified); if (Shell::GetScreen()->GetNumDisplays() > 1) { - DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); int64 primary_id = layout.primary_id; SetPrimaryDisplayId(primary_id == gfx::Display::kInvalidDisplayID ? pair.first diff --git a/ash/magnifier/magnification_controller_unittest.cc b/ash/magnifier/magnification_controller_unittest.cc index 01a1e84..fcd7381 100644 --- a/ash/magnifier/magnification_controller_unittest.cc +++ b/ash/magnifier/magnification_controller_unittest.cc @@ -4,9 +4,9 @@ #include "ash/magnifier/magnification_controller.h" +#include "ash/display/display_manager.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" -#include "ash/test/display_manager_test_api.h" #include "base/strings/stringprintf.h" #include "ui/aura/env.h" #include "ui/aura/test/aura_test_utils.h" @@ -670,7 +670,7 @@ TEST_F(MagnificationControllerTest, CenterTextCaretInViewport) { TEST_F(MagnificationControllerTest, EnableMagnifierInUnifiedDesktop) { if (!SupportsMultipleDisplays()) return; - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); + Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true); EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc index 1953fed..97fd09e 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -173,8 +173,9 @@ void ReparentAllWindows(aura::Window* src, aura::Window* dst) { kContainerIdsToMove + arraysize(kContainerIdsToMove)); // Check the default_multi_display_mode because this is also necessary // in trasition between mirror <-> unified mode. - if (Shell::GetInstance()->display_manager()->default_multi_display_mode() == - DisplayManager::UNIFIED) { + if (Shell::GetInstance() + ->display_manager() + ->current_default_multi_display_mode() == DisplayManager::UNIFIED) { for (int id : kExtraContainerIdsToMoveInUnifiedMode) container_ids.push_back(id); } diff --git a/ash/root_window_controller_unittest.cc b/ash/root_window_controller_unittest.cc index 88e254f..923fdce 100644 --- a/ash/root_window_controller_unittest.cc +++ b/ash/root_window_controller_unittest.cc @@ -293,7 +293,7 @@ TEST_F(RootWindowControllerTest, MoveWindows_Modal) { TEST_F(RootWindowControllerTest, MoveWindows_LockWindowsInUnified) { if (!SupportsMultipleDisplays()) return; - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); + Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true); UpdateDisplay("500x500"); const int kLockScreenWindowId = 1000; diff --git a/ash/screen_util_unittest.cc b/ash/screen_util_unittest.cc index 7fc9ae6..f8d7f33 100644 --- a/ash/screen_util_unittest.cc +++ b/ash/screen_util_unittest.cc @@ -117,11 +117,9 @@ TEST_F(ScreenUtilTest, ConvertRect) { TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { if (!SupportsMultipleDisplays()) return; - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED); - display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED); + + display_manager->SetUnifiedDesktopEnabled(true); views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc index d447b06..7558b0c 100644 --- a/ash/shelf/shelf_layout_manager_unittest.cc +++ b/ash/shelf/shelf_layout_manager_unittest.cc @@ -2349,7 +2349,7 @@ TEST_F(ShelfLayoutManagerTest, ShutdownHandlesWindowActivation) { TEST_F(ShelfLayoutManagerTest, ShelfLayoutInUnifiedDesktop) { if (!SupportsMultipleDisplays()) return; - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); + Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true); UpdateDisplay("500x500, 500x500"); diff --git a/ash/system/chromeos/tray_display_unittest.cc b/ash/system/chromeos/tray_display_unittest.cc index f6c205f..0a23260 100644 --- a/ash/system/chromeos/tray_display_unittest.cc +++ b/ash/system/chromeos/tray_display_unittest.cc @@ -315,9 +315,7 @@ TEST_F(TrayDisplayTest, InternalDisplayResized) { CheckAccessibleName(); // Unified mode - test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); - display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED); - display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED); + display_manager->SetUnifiedDesktopEnabled(true); UpdateDisplay("300x200,400x500"); // Update the cache variables as the primary root window changed. GetTray()->ShowDefaultView(BUBBLE_USE_EXISTING); diff --git a/ash/system/web_notification/ash_popup_alignment_delegate_unittest.cc b/ash/system/web_notification/ash_popup_alignment_delegate_unittest.cc index 6601dca..f487c75 100644 --- a/ash/system/web_notification/ash_popup_alignment_delegate_unittest.cc +++ b/ash/system/web_notification/ash_popup_alignment_delegate_unittest.cc @@ -276,8 +276,7 @@ TEST_F(AshPopupAlignmentDelegateTest, Unified) { if (!SupportsMultipleDisplays()) return; DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED); - display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED); + display_manager->SetUnifiedDesktopEnabled(true); // Reset the delegate as the primary display's shelf will be destroyed during // transition. diff --git a/ash/test/display_manager_test_api.cc b/ash/test/display_manager_test_api.cc index 434c7a9..73fb2d8 100644 --- a/ash/test/display_manager_test_api.cc +++ b/ash/test/display_manager_test_api.cc @@ -95,18 +95,6 @@ bool DisplayManagerTestApi::TestIfMouseWarpsAt( } } -// static -void DisplayManagerTestApi::EnableUnifiedDesktopForTest() { -#if defined(OS_CHROMEOS) - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kAshEnableUnifiedDesktop); - Shell::GetInstance() - ->display_manager() - ->layout_store() - ->SetDefaultDisplayLayout(DisplayLayout()); -#endif -} - DisplayManagerTestApi::DisplayManagerTestApi() : display_manager_(Shell::GetInstance()->display_manager()) {} diff --git a/ash/test/display_manager_test_api.h b/ash/test/display_manager_test_api.h index b73e65d8..4bb070d 100644 --- a/ash/test/display_manager_test_api.h +++ b/ash/test/display_manager_test_api.h @@ -34,8 +34,6 @@ class DisplayManagerTestApi { static bool TestIfMouseWarpsAt(ui::test::EventGenerator& event_generator, const gfx::Point& point_in_screen); - static void EnableUnifiedDesktopForTest(); - DisplayManagerTestApi(); virtual ~DisplayManagerTestApi(); diff --git a/chrome/browser/chromeos/display/display_preferences_unittest.cc b/chrome/browser/chromeos/display/display_preferences_unittest.cc index eb065ad..07c0514 100644 --- a/chrome/browser/chromeos/display/display_preferences_unittest.cc +++ b/chrome/browser/chromeos/display/display_preferences_unittest.cc @@ -876,11 +876,11 @@ TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { } TEST_F(DisplayPreferencesTest, SaveUnifiedMode) { - ash::test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); LoggedInAsUser(); ash::DisplayManager* display_manager = ash::Shell::GetInstance()->display_manager(); + display_manager->SetUnifiedDesktopEnabled(true); UpdateDisplay("200x200,100x100"); ash::DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); @@ -928,7 +928,8 @@ TEST_F(DisplayPreferencesTest, SaveUnifiedMode) { EXPECT_FALSE(stored_layout.mirrored); // Exit unified mode. - display_manager->SetDefaultMultiDisplayMode(ash::DisplayManager::EXTENDED); + display_manager->SetDefaultMultiDisplayModeForCurrentDisplays( + ash::DisplayManager::EXTENDED); display_manager->ReconfigureDisplays(); ASSERT_TRUE( secondary_displays->GetDictionary(ToPairString(pair), &new_value)); @@ -953,7 +954,7 @@ TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { EXPECT_FALSE(display_manager->IsInUnifiedMode()); // Restored to unified. - ash::test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); + display_manager->SetUnifiedDesktopEnabled(true); StoreDisplayBoolPropertyForPair(pair, "default_unified", true); LoadDisplayPreferences(false); UpdateDisplay("100x100,200x200"); diff --git a/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc index 4859235..4fc8e39 100644 --- a/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc @@ -6,7 +6,6 @@ #include <string> -#include "ash/ash_switches.h" #include "ash/display/display_configurator_animation.h" #include "ash/display/display_manager.h" #include "ash/display/resolution_notification_controller.h" @@ -331,7 +330,7 @@ void DisplayOptionsHandler::SendDisplayInfo( void DisplayOptionsHandler::UpdateDisplaySettingsEnabled() { bool enabled = GetDisplayManager()->num_connected_displays() <= 2; - bool show_unified_desktop = ash::switches::UnifiedDesktopEnabled(); + bool show_unified_desktop = GetDisplayManager()->unified_desktop_enabled(); web_ui()->CallJavascriptFunction( "options.BrowserOptions.enableDisplaySettings", @@ -488,10 +487,10 @@ void DisplayOptionsHandler::HandleSetColorProfile(const base::ListValue* args) { void DisplayOptionsHandler::HandleSetUnifiedDesktopEnabled( const base::ListValue* args) { - DCHECK(ash::switches::UnifiedDesktopEnabled()); + DCHECK(GetDisplayManager()->unified_desktop_enabled()); bool enable = false; if (args->GetBoolean(0, &enable)) { - GetDisplayManager()->SetDefaultMultiDisplayMode( + GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( enable ? DisplayManager::UNIFIED : DisplayManager::EXTENDED); GetDisplayManager()->ReconfigureDisplays(); } |