diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 614cf33dae234..8b82837d49623 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -581,10 +581,6 @@ void RenderWidgetHostViewAura::Hide() { #endif } -aura::Window* RenderWidgetHostViewAura::GetToplevelWindow() { - return window_->GetToplevelWindow(); -} - void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { // For a SetSize operation, we don't care what coordinate system the origin // of the window is in, it's only important to make sure that the origin @@ -593,12 +589,21 @@ void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { } void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { - display::Display display = - popup_parent_host_view_ - ? display::Screen::GetScreen()->GetDisplayNearestWindow( - popup_parent_host_view_->window_) - : display::Screen::GetScreen()->GetDisplayMatching(rect); - GetToplevelWindow()->SetBoundsInScreen(rect, display); + gfx::Point relative_origin(rect.origin()); + + // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but + // Window::SetBounds() takes parent coordinates, so do the conversion here. + aura::Window* root = window_->GetRootWindow(); + if (root) { + aura::client::ScreenPositionClient* screen_position_client = + aura::client::GetScreenPositionClient(root); + if (screen_position_client) { + screen_position_client->ConvertPointFromScreen(window_->parent(), + &relative_origin); + } + } + + InternalSetBounds(gfx::Rect(relative_origin, rect.size())); } gfx::Vector2dF RenderWidgetHostViewAura::GetLastScrollOffset() const { diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h index dbf3024f8b635..6b880fadd3200 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.h +++ b/content/browser/renderer_host/render_widget_host_view_aura.h @@ -332,9 +332,6 @@ class CONTENT_EXPORT RenderWidgetHostViewAura return delegated_frame_host_.get(); } - // Returns the top level window that is hosting the renderwidget. - virtual aura::Window* GetToplevelWindow(); - private: friend class DelegatedFrameHostClientAura; friend class InputMethodAuraTestBase; diff --git a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc index 7652b2e168ea8..22bf032db242f 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc @@ -430,10 +430,6 @@ class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { return event_handler()->pointer_state(); } - // In this unit test, |window_| is directly added to the root and is - // toplevel. - aura::Window* GetToplevelWindow() override { return window(); } - gfx::Size last_frame_size_; std::unique_ptr last_copy_request_; FakeWindowEventDispatcher* dispatcher_; @@ -521,20 +517,6 @@ const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) { return reinterpret_cast(data); } -class MockRenderWidgetHostViewAura : public RenderWidgetHostViewAura { - public: - MockRenderWidgetHostViewAura(RenderWidgetHost* host, bool is_guest_view_hack) - : RenderWidgetHostViewAura(host, is_guest_view_hack) {} - - ~MockRenderWidgetHostViewAura() override {} - - protected: - aura::Window* GetToplevelWindow() override { return window(); } - - private: - DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostViewAura); -}; - } // namespace class RenderWidgetHostViewAuraTest : public testing::Test { @@ -560,8 +542,6 @@ class RenderWidgetHostViewAuraTest : public testing::Test { ImageTransportFactory::GetInstance()->GetContextFactory(), ImageTransportFactory::GetInstance()->GetContextFactoryPrivate()); new wm::DefaultActivationClient(aura_test_helper_->root_window()); - aura::client::SetScreenPositionClient(aura_test_helper_->root_window(), - &screen_position_client_); browser_context_.reset(new TestBrowserContext); process_host_ = new MockRenderProcessHost(browser_context_.get()); @@ -575,7 +555,7 @@ class RenderWidgetHostViewAuraTest : public testing::Test { process_host_, routing_id, false); delegates_.back()->set_widget_host(parent_host_); parent_view_ = - new MockRenderWidgetHostViewAura(parent_host_, is_guest_view_hack_); + new RenderWidgetHostViewAura(parent_host_, is_guest_view_hack_); parent_view_->InitAsChild(nullptr); aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), aura_test_helper_->root_window(), @@ -733,7 +713,6 @@ class RenderWidgetHostViewAuraTest : public testing::Test { std::unique_ptr aura_test_helper_; std::unique_ptr browser_context_; std::vector> delegates_; - wm::DefaultScreenPositionClient screen_position_client_; MockRenderProcessHost* process_host_; // Tests should set these to nullptr if they've already triggered their @@ -1023,9 +1002,11 @@ TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) { // Checks that a popup is positioned correctly relative to its parent using // screen coordinates. TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) { + wm::DefaultScreenPositionClient screen_position_client; aura::Window* window = parent_view_->GetNativeView(); aura::Window* root = window->GetRootWindow(); + aura::client::SetScreenPositionClient(root, &screen_position_client); parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600)); gfx::Rect bounds_in_screen = parent_view_->GetViewBounds(); @@ -4219,7 +4200,7 @@ class RenderWidgetHostViewAuraWithViewHarnessTest // the RWHVA as the view. delete contents()->GetRenderViewHost()->GetWidget()->GetView(); // This instance is destroyed in the TearDown method below. - view_ = new MockRenderWidgetHostViewAura( + view_ = new RenderWidgetHostViewAura( contents()->GetRenderViewHost()->GetWidget(), false); } diff --git a/ui/aura/window.cc b/ui/aura/window.cc index 83a532b052437..e12dd7dbe7954 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -313,11 +313,8 @@ void Window::SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen, if (root) { aura::client::ScreenPositionClient* screen_position_client = aura::client::GetScreenPositionClient(root); - if (screen_position_client) { - screen_position_client->SetBounds(this, new_bounds_in_screen, - dst_display); - return; - } + screen_position_client->SetBounds(this, new_bounds_in_screen, dst_display); + return; } SetBounds(new_bounds_in_screen); } diff --git a/ui/views/widget/desktop_aura/desktop_native_widget_aura_unittest.cc b/ui/views/widget/desktop_aura/desktop_native_widget_aura_unittest.cc index e6c2041353592..d2f0e65e321ad 100644 --- a/ui/views/widget/desktop_aura/desktop_native_widget_aura_unittest.cc +++ b/ui/views/widget/desktop_aura/desktop_native_widget_aura_unittest.cc @@ -614,25 +614,6 @@ TEST_F(WidgetTest, WindowMouseModalityTest) { top_level_widget.CloseNow(); } -TEST_F(WidgetTest, SetScreenBoundsOnNativeWindow) { - Widget widget; - Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); - params.native_widget = - CreatePlatformDesktopNativeWidgetImpl(params, &widget, nullptr); - params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.bounds = gfx::Rect(10, 10, 100, 100); - widget.Init(params); - widget.Show(); - aura::Window* window = widget.GetNativeWindow(); - display::Screen* screen = display::Screen::GetScreen(); - - const gfx::Rect new_screen_bounds(50, 50, 150, 150); - window->SetBoundsInScreen(new_screen_bounds, - screen->GetPrimaryDisplay()); - EXPECT_EQ(new_screen_bounds, widget.GetWindowBoundsInScreen()); - widget.CloseNow(); -} - #if defined(OS_WIN) // Tests whether we can activate the top level widget when a modal dialog is // active. diff --git a/ui/views/widget/desktop_aura/desktop_screen_position_client.cc b/ui/views/widget/desktop_aura/desktop_screen_position_client.cc index b6ed6e571a2fa..6096b4e10797d 100644 --- a/ui/views/widget/desktop_aura/desktop_screen_position_client.cc +++ b/ui/views/widget/desktop_aura/desktop_screen_position_client.cc @@ -38,17 +38,10 @@ void DesktopScreenPositionClient::SetBounds(aura::Window* window, // TODO(jam): Use the 3rd parameter, |display|. aura::Window* root = window->GetRootWindow(); + // This method assumes that |window| does not have an associated + // DesktopNativeWidgetAura. internal::NativeWidgetPrivate* desktop_native_widget = DesktopNativeWidgetAura::ForWindow(root); - // The screen bounds request to the content_window_ should be interpreted as - // a widget bounds change. - if (desktop_native_widget && - desktop_native_widget->GetNativeView() == window) { - desktop_native_widget->GetWidget()->SetBounds(bounds); - return; - } - // The following logic assumes that |window| does not have an associated - // DesktopNativeWidgetAura. DCHECK(!desktop_native_widget || desktop_native_widget->GetNativeView() != window);