diff options
-rw-r--r-- | ash/display/display_controller.cc | 2 | ||||
-rw-r--r-- | ash/display/display_controller_unittest.cc | 8 | ||||
-rw-r--r-- | ash/display/display_manager.cc | 75 | ||||
-rw-r--r-- | ash/display/display_manager.h | 23 | ||||
-rw-r--r-- | ash/display/display_manager_unittest.cc | 17 |
5 files changed, 83 insertions, 42 deletions
diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc index 1318f16..16328fc 100644 --- a/ash/display/display_controller.cc +++ b/ash/display/display_controller.cc @@ -449,7 +449,7 @@ void DisplayController::SetPrimaryDisplay( displays.push_back(display_manager->GetDisplayForId(primary_display_id)); displays.push_back(*GetSecondaryDisplay()); GetDisplayManager()->set_force_bounds_changed(true); - GetDisplayManager()->OnNativeDisplaysChanged(displays); + GetDisplayManager()->UpdateDisplays(displays); GetDisplayManager()->set_force_bounds_changed(false); } diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc index 06bf751..56de605 100644 --- a/ash/display/display_controller_unittest.cc +++ b/ash/display/display_controller_unittest.cc @@ -99,15 +99,19 @@ class DisplayControllerShutdownTest : public test::AshTestBase { typedef test::AshTestBase DisplayControllerTest; #if defined(OS_WIN) -// TOD(oshima): Windows creates a window with smaller client area. +// TODO(oshima): Windows creates a window with smaller client area. // Fix this and enable tests. #define MAYBE_SecondaryDisplayLayout DISABLED_SecondaryDisplayLayout #define MAYBE_BoundsUpdated DISABLED_BoundsUpdated #define MAYBE_UpdateDisplayWithHostOrigin DISABLED_UpdateDisplayWithHostOrigin +#define MAYBE_CursorDeviceScaleFactorSwapPrimary \ + DISABLED_CursorDeviceScaleFactorSwapPrimary #define MAYBE_Shutdown DISABLED_Shutdown #else #define MAYBE_SecondaryDisplayLayout SecondaryDisplayLayout #define MAYBE_BoundsUpdated BoundsUpdated +#define MAYBE_CursorDeviceScaleFactorSwapPrimary \ + CursorDeviceScaleFactorSwapPrimary #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin #define MAYBE_Shutdown Shutdown #endif @@ -498,7 +502,7 @@ TEST_F(DisplayControllerTest, SwapPrimaryById) { EXPECT_TRUE(primary_root->Contains(launcher_window)); } -TEST_F(DisplayControllerTest, CursorDeviceScaleFactorSwapPrimary) { +TEST_F(DisplayControllerTest, MAYBE_CursorDeviceScaleFactorSwapPrimary) { DisplayController* display_controller = Shell::GetInstance()->display_controller(); diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index 431a845..cda6ffc 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -144,30 +144,19 @@ const gfx::Display& DisplayManager::FindDisplayContainingPoint( void DisplayManager::SetOverscanInsets(int64 display_id, const gfx::Insets& insets_in_dip) { + display_info_[display_id].overscan_insets_in_dip = insets_in_dip; + + // Copies the |displays_| because UpdateDisplays() compares the passed + // displays and its internal |displays_|. DisplayList displays = displays_; - std::map<int64, gfx::Insets>::const_iterator old_overscan = - overscan_mapping_.find(display_id); - if (old_overscan != overscan_mapping_.end()) { - gfx::Insets old_insets = old_overscan->second; - for (DisplayList::iterator iter = displays.begin(); - iter != displays.end(); ++iter) { - if (iter->id() == display_id) { - // Undo the existing insets before applying the new insets. - gfx::Rect bounds = iter->bounds_in_pixel(); - bounds.Inset(old_insets.Scale(-iter->device_scale_factor())); - iter->SetScaleAndBounds(iter->device_scale_factor(), bounds); - break; - } - } - } - overscan_mapping_[display_id] = insets_in_dip; - OnNativeDisplaysChanged(displays); + UpdateDisplays(displays); } gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { - std::map<int64, gfx::Insets>::const_iterator it = - overscan_mapping_.find(display_id); - return (it != overscan_mapping_.end()) ? it->second : gfx::Insets(); + std::map<int64, DisplayInfo>::const_iterator it = + display_info_.find(display_id); + return (it != display_info_.end()) ? + it->second.overscan_insets_in_dip : gfx::Insets(); } void DisplayManager::OnNativeDisplaysChanged( @@ -211,13 +200,34 @@ void DisplayManager::OnNativeDisplaysChanged( new_displays = updated_displays; } + for (DisplayList::const_iterator iter = new_displays.begin(); + iter != new_displays.end(); ++iter) { + std::map<int64, DisplayInfo>::iterator info = + display_info_.find(iter->id()); + if (info != display_info_.end()) { + info->second.original_bounds_in_pixel = iter->bounds_in_pixel(); + } else { + display_info_[iter->id()].original_bounds_in_pixel = + iter->bounds_in_pixel(); + } + } + + UpdateDisplays(new_displays); + RefreshDisplayNames(); +} + +void DisplayManager::UpdateDisplays( + const std::vector<gfx::Display>& updated_displays) { + DisplayList new_displays = updated_displays; + for (DisplayList::iterator iter = new_displays.begin(); iter != new_displays.end(); ++iter) { - std::map<int64, gfx::Insets>::const_iterator overscan_insets = - overscan_mapping_.find(iter->id()); - if (overscan_insets != overscan_mapping_.end()) { - gfx::Rect bounds = iter->bounds_in_pixel(); - bounds.Inset(overscan_insets->second.Scale(iter->device_scale_factor())); + std::map<int64, DisplayInfo>::const_iterator info = + display_info_.find(iter->id()); + if (info != display_info_.end()) { + gfx::Rect bounds = info->second.original_bounds_in_pixel; + bounds.Inset(info->second.overscan_insets_in_dip.Scale( + iter->device_scale_factor())); iter->SetScaleAndBounds(iter->device_scale_factor(), bounds); } } @@ -281,7 +291,6 @@ void DisplayManager::OnNativeDisplaysChanged( } displays_ = new_displays; - RefreshDisplayNames(); // Temporarily add displays to be removed because display object // being removed are accessed during shutting down the root. @@ -379,10 +388,10 @@ std::string DisplayManager::GetDisplayNameFor( if (!display.is_valid()) return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); - std::map<int64, std::string>::const_iterator iter = - display_names_.find(display.id()); - if (iter != display_names_.end()) - return iter->second; + std::map<int64, DisplayInfo>::const_iterator iter = + display_info_.find(display.id()); + if (iter != display_info_.end()) + return iter->second.name; return base::StringPrintf("Display %d", static_cast<int>(display.id())); } @@ -535,8 +544,6 @@ void DisplayManager::EnsurePointerInDisplays() { } void DisplayManager::RefreshDisplayNames() { - display_names_.clear(); - #if defined(OS_CHROMEOS) if (!base::chromeos::IsRunningOnChromeOS()) return; @@ -555,10 +562,10 @@ void DisplayManager::RefreshDisplayNames() { outputs[i], &manufacturer_id, &serial_number, &name)) { int64 id = gfx::Display::GetID(manufacturer_id, serial_number); if (IsInternalDisplayId(id)) { - display_names_[id] = + display_info_[id].name = l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME); } else { - display_names_[id] = name; + display_info_[id].name = name; } } } diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h index a3c8b12..292da15 100644 --- a/ash/display/display_manager.h +++ b/ash/display/display_manager.h @@ -86,6 +86,9 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver { // contains each display's new infomration. void OnNativeDisplaysChanged(const std::vector<gfx::Display>& displays); + // Updates the internal display data and notifies observers about the changes. + void UpdateDisplays(const std::vector<gfx::Display>& displays); + // Create a root window for given |display|. aura::RootWindow* CreateRootWindowForDisplay(const gfx::Display& display); @@ -127,6 +130,19 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver { typedef std::vector<gfx::Display> DisplayList; + // Metadata for each display. + struct DisplayInfo { + // The cached name of the display. + std::string name; + + // The original bounds_in_pixel for the display. This can be different from + // the current one in case of overscan insets. + gfx::Rect original_bounds_in_pixel; + + // The overscan insets for the display. + gfx::Insets overscan_insets_in_dip; + }; + void Init(); void CycleDisplayImpl(); void ScaleDisplayImpl(); @@ -164,11 +180,8 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver { bool force_bounds_changed_; - // The mapping from the display ID to its overscan insets. - std::map<int64, gfx::Insets> overscan_mapping_; - - // The cached display's name for the display ID. - std::map<int64, std::string> display_names_; + // The mapping from the display ID to its internal data. + std::map<int64, DisplayInfo> display_info_; DISALLOW_COPY_AND_ASSIGN(DisplayManager); }; diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc index 12ed8d20..e7378b6 100644 --- a/ash/display/display_manager_unittest.cc +++ b/ash/display/display_manager_unittest.cc @@ -234,6 +234,15 @@ TEST_F(DisplayManagerTest, MAYBE_OverscanInsetsTest) { EXPECT_EQ("12,514 378x376", display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + // Make sure that SetOverscanInsets() is idempotent. + display_manager()->SetOverscanInsets(display1.id(), gfx::Insets()); + display_manager()->SetOverscanInsets( + display2.id(), gfx::Insets(13, 12, 11, 10)); + EXPECT_EQ("0,0 500x500", + display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); + EXPECT_EQ("12,514 378x376", + display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + display_manager()->SetOverscanInsets( display2.id(), gfx::Insets(10, 11, 12, 13)); EXPECT_EQ("0,0 500x500", @@ -272,6 +281,14 @@ TEST_F(DisplayManagerTest, MAYBE_OverscanInsetsTest) { EXPECT_EQ("10,509 376x380", display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); EXPECT_EQ("188x190", display_manager()->GetDisplayAt(1)->size().ToString()); + + // Make sure switching primary display applies the overscan offset only once. + ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay( + ScreenAsh::GetSecondaryDisplay()); + EXPECT_EQ("0,0 500x500", + ScreenAsh::GetSecondaryDisplay().bounds_in_pixel().ToString()); + EXPECT_EQ("10,509 376x380", gfx::Screen::GetNativeScreen()-> + GetPrimaryDisplay().bounds_in_pixel().ToString()); } TEST_F(DisplayManagerTest, MAYBE_ZeroOverscanInsets) { |