diff options
author | oshima <oshima@chromium.org> | 2015-11-03 18:16:36 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-04 02:17:25 +0000 |
commit | c0c9eb78b45bc6ff392cc30d7b4cbe005de60c85 (patch) | |
tree | c08529d6753ae3598f60a7559bbd8efdc87c8948 /ash | |
parent | 61526c47df0ebc90e87daa429c134c9a825ca1a1 (diff) | |
download | chromium_src-c0c9eb78b45bc6ff392cc30d7b4cbe005de60c85.zip chromium_src-c0c9eb78b45bc6ff392cc30d7b4cbe005de60c85.tar.gz chromium_src-c0c9eb78b45bc6ff392cc30d7b4cbe005de60c85.tar.bz2 |
Return ShelfDisplayBoundsI in root coordinates
Most use case is in root coordinates, and GetDisplayNearestWindow can return wrong value during transition.
I also disabled a few tests on Windows as the window may not be resized on Win Ash. (besides, win_ash will be gone soon)
BUG=547280
TEST=WindowTreeHostTest.ReplacePrimary
Review URL: https://codereview.chromium.org/1419373004
Cr-Commit-Position: refs/heads/master@{#357730}
Diffstat (limited to 'ash')
-rw-r--r-- | ash/display/window_tree_host_manager_unittest.cc | 64 | ||||
-rw-r--r-- | ash/screen_util.cc | 6 | ||||
-rw-r--r-- | ash/screen_util.h | 2 | ||||
-rw-r--r-- | ash/screen_util_unittest.cc | 20 | ||||
-rw-r--r-- | ash/shelf/shelf_layout_manager.cc | 5 | ||||
-rw-r--r-- | ash/system/web_notification/ash_popup_alignment_delegate_unittest.cc | 3 | ||||
-rw-r--r-- | ash/wm/app_list_controller.cc | 3 | ||||
-rw-r--r-- | ash/wm/lock_layout_manager_unittest.cc | 6 | ||||
-rw-r--r-- | ash/wm/lock_window_state.cc | 2 |
9 files changed, 92 insertions, 19 deletions
diff --git a/ash/display/window_tree_host_manager_unittest.cc b/ash/display/window_tree_host_manager_unittest.cc index 99d6950..5ea2343 100644 --- a/ash/display/window_tree_host_manager_unittest.cc +++ b/ash/display/window_tree_host_manager_unittest.cc @@ -24,6 +24,7 @@ #include "ui/aura/client/focus_change_observer.h" #include "ui/aura/client/focus_client.h" #include "ui/aura/env.h" +#include "ui/aura/window_observer.h" #include "ui/aura/window_tracker.h" #include "ui/aura/window_tree_host.h" #include "ui/events/event_handler.h" @@ -1293,6 +1294,69 @@ TEST_F(WindowTreeHostManagerTest, ReplaceSwappedPrimary) { EXPECT_EQ(20, Shell::GetScreen()->GetPrimaryDisplay().id()); } +namespace { + +class RootWindowTestObserver : public aura::WindowObserver { + public: + RootWindowTestObserver() {} + ~RootWindowTestObserver() override {} + + void OnWindowBoundsChanged(aura::Window* window, + const gfx::Rect& old_bounds, + const gfx::Rect& new_bounds) override { + shelf_display_bounds_ = ScreenUtil::GetShelfDisplayBoundsInRoot(window); + } + + const gfx::Rect& shelf_display_bounds() const { + return shelf_display_bounds_; + } + + private: + gfx::Rect shelf_display_bounds_; + + DISALLOW_COPY_AND_ASSIGN(RootWindowTestObserver); +}; + +} // names + +// Make sure that GetShelfDisplayBoundsInRoot returns the correct bounds +// when primary display gets replaced in a following scenario. +// 1) Two displays connected: a) b) +// 2) both are disconnected and new one with the same size as b) is connected +// in one configuration event. +// See crbug.com/547280. +TEST_F(WindowTreeHostManagerTest, ReplacePrimary) { + if (!SupportsMultipleDisplays()) + return; + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); + + DisplayInfo first_display_info = + CreateDisplayInfo(10, 0, gfx::Display::ROTATE_0); + first_display_info.SetBounds(gfx::Rect(0, 0, 400, 400)); + const DisplayInfo second_display_info = + CreateDisplayInfo(11, 500, gfx::Display::ROTATE_0); + + std::vector<DisplayInfo> display_info_list; + // Extended + display_info_list.push_back(first_display_info); + display_info_list.push_back(second_display_info); + display_manager->OnNativeDisplaysChanged(display_info_list); + aura::Window* primary_root = Shell::GetAllRootWindows()[0]; + + int64 new_display_id = 20; + RootWindowTestObserver test_observer; + primary_root->AddObserver(&test_observer); + + display_info_list.clear(); + const DisplayInfo new_first_display_info = + CreateDisplayInfo(new_display_id, 0, gfx::Display::ROTATE_0); + + display_info_list.push_back(new_first_display_info); + display_manager->OnNativeDisplaysChanged(display_info_list); + EXPECT_EQ("0,0 500x500", test_observer.shelf_display_bounds().ToString()); + primary_root->RemoveObserver(&test_observer); +} + TEST_F(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange) { if (!SupportsMultipleDisplays()) return; diff --git a/ash/screen_util.cc b/ash/screen_util.cc index d0e4121..02d90e2 100644 --- a/ash/screen_util.cc +++ b/ash/screen_util.cc @@ -52,7 +52,7 @@ gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) { Shell::GetScreen()->GetDisplayNearestWindow(window).work_area()); } -gfx::Rect ScreenUtil::GetShelfDisplayBoundsInScreen(aura::Window* window) { +gfx::Rect ScreenUtil::GetShelfDisplayBoundsInRoot(aura::Window* window) { DisplayManager* display_manager = Shell::GetInstance()->display_manager(); if (display_manager->IsInUnifiedMode()) { // In unified desktop mode, there is only one shelf in the 1st display. @@ -65,9 +65,7 @@ gfx::Rect ScreenUtil::GetShelfDisplayBoundsInScreen(aura::Window* window) { size.Scale(scale, scale); return gfx::Rect(gfx::ToCeiledSize(size)); } else { - return gfx::Screen::GetScreenFor(window) - ->GetDisplayNearestWindow(window) - .bounds(); + return window->GetRootWindow()->bounds(); } } diff --git a/ash/screen_util.h b/ash/screen_util.h index 971215e..79c0358 100644 --- a/ash/screen_util.h +++ b/ash/screen_util.h @@ -44,7 +44,7 @@ class ASH_EXPORT ScreenUtil { // general use, we should consider always using physical display in // window layout instead of root window, and keep the logical // display only in display management code. - static gfx::Rect GetShelfDisplayBoundsInScreen(aura::Window* window); + static gfx::Rect GetShelfDisplayBoundsInRoot(aura::Window* window); // TODO(oshima): Move following two to wm/coordinate_conversion.h // Converts |rect| from |window|'s coordinates to the virtual screen diff --git a/ash/screen_util_unittest.cc b/ash/screen_util_unittest.cc index f8d7f33..6adae38 100644 --- a/ash/screen_util_unittest.cc +++ b/ash/screen_util_unittest.cc @@ -125,24 +125,28 @@ TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); UpdateDisplay("500x400"); - EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen( - widget->GetNativeWindow()).ToString()); + EXPECT_EQ("0,0 500x400", + ScreenUtil::GetShelfDisplayBoundsInRoot(widget->GetNativeWindow()) + .ToString()); UpdateDisplay("500x400,600x400"); - EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen( - widget->GetNativeWindow()).ToString()); + EXPECT_EQ("0,0 500x400", + ScreenUtil::GetShelfDisplayBoundsInRoot(widget->GetNativeWindow()) + .ToString()); // Move to the 2nd physical display. Shelf's display still should be // the first. widget->SetBounds(gfx::Rect(800, 0, 100, 100)); ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); - EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen( - widget->GetNativeWindow()).ToString()); + EXPECT_EQ("0,0 500x400", + ScreenUtil::GetShelfDisplayBoundsInRoot(widget->GetNativeWindow()) + .ToString()); UpdateDisplay("600x500"); - EXPECT_EQ("0,0 600x500", ScreenUtil::GetShelfDisplayBoundsInScreen( - widget->GetNativeWindow()).ToString()); + EXPECT_EQ("0,0 600x500", + ScreenUtil::GetShelfDisplayBoundsInRoot(widget->GetNativeWindow()) + .ToString()); } } // namespace test diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc index 7f90844..5e1aab0 100644 --- a/ash/shelf/shelf_layout_manager.cc +++ b/ash/shelf/shelf_layout_manager.cc @@ -749,10 +749,7 @@ void ShelfLayoutManager::CalculateTargetBounds( const State& state, TargetBounds* target_bounds) { gfx::Rect available_bounds = - ScreenUtil::GetShelfDisplayBoundsInScreen(root_window_); - available_bounds = - ScreenUtil::ConvertRectFromScreen(root_window_, available_bounds); - + ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); gfx::Rect status_size( shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); int shelf_width = 0, shelf_height = 0; 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 f487c75..ad4358d 100644 --- a/ash/system/web_notification/ash_popup_alignment_delegate_unittest.cc +++ b/ash/system/web_notification/ash_popup_alignment_delegate_unittest.cc @@ -136,6 +136,9 @@ TEST_F(AshPopupAlignmentDelegateTest, ShelfAlignment) { } TEST_F(AshPopupAlignmentDelegateTest, LockScreen) { + if (!SupportsHostWindowResize()) + return; + const gfx::Rect toast_size(0, 0, 10, 10); Shell::GetInstance()->SetShelfAlignment( diff --git a/ash/wm/app_list_controller.cc b/ash/wm/app_list_controller.cc index e4fdb79..67a50c3 100644 --- a/ash/wm/app_list_controller.cc +++ b/ash/wm/app_list_controller.cc @@ -125,7 +125,8 @@ gfx::Vector2d GetAnchorPositionOffsetToShelf( gfx::Point GetCenterOfDisplayForView(const views::View* view, int minimum_height) { aura::Window* window = view->GetWidget()->GetNativeView(); - gfx::Rect bounds = ScreenUtil::GetShelfDisplayBoundsInScreen(window); + gfx::Rect bounds = ScreenUtil::GetShelfDisplayBoundsInRoot(window); + bounds = ScreenUtil::ConvertRectToScreen(window->GetRootWindow(), bounds); // If the virtual keyboard is active, subtract it from the display bounds, so // that the app list is centered in the non-keyboard area of the display. diff --git a/ash/wm/lock_layout_manager_unittest.cc b/ash/wm/lock_layout_manager_unittest.cc index 3f5ab9f..944124c 100644 --- a/ash/wm/lock_layout_manager_unittest.cc +++ b/ash/wm/lock_layout_manager_unittest.cc @@ -129,6 +129,9 @@ TEST_F(LockLayoutManagerTest, NorwmalWindowBoundsArePreserved) { } TEST_F(LockLayoutManagerTest, MaximizedFullscreenWindowBoundsAreEqualToScreen) { + if (!SupportsHostWindowResize()) + return; + gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); views::Widget::InitParams widget_params( @@ -178,6 +181,9 @@ TEST_F(LockLayoutManagerTest, MaximizedFullscreenWindowBoundsAreEqualToScreen) { } TEST_F(LockLayoutManagerTest, KeyboardBounds) { + if (!SupportsHostWindowResize()) + return; + gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); gfx::Rect screen_bounds = primary_display.bounds(); diff --git a/ash/wm/lock_window_state.cc b/ash/wm/lock_window_state.cc index d153fb2..6230dd1 100644 --- a/ash/wm/lock_window_state.cc +++ b/ash/wm/lock_window_state.cc @@ -190,7 +190,7 @@ void LockWindowState::UpdateBounds(wm::WindowState* window_state) { keyboard_bounds = keyboard_controller->current_keyboard_bounds(); } gfx::Rect bounds = - ScreenUtil::GetShelfDisplayBoundsInScreen(window_state->window()); + ScreenUtil::GetShelfDisplayBoundsInRoot(window_state->window()); bounds.set_height(bounds.height() - keyboard_bounds.height()); |