Skip to content

Commit

Permalink
Fix: moveTo resizes window under display device scaling #7113
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Jan 7, 2020
1 parent 245fdcd commit 4339788
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 1 deletion.
12 changes: 11 additions & 1 deletion chrome/browser/extensions/api/tabs/tabs_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ ExtensionFunction::ResponseAction WindowsUpdateFunction::Run() {
else
bounds = browser->window()->GetBounds();
bool set_bounds = false;
bool set_pos_only = false;

bool set_min_size = false;
bool set_max_size = false;
Expand Down Expand Up @@ -916,21 +917,25 @@ ExtensionFunction::ResponseAction WindowsUpdateFunction::Run() {
if (params->update_info.left) {
bounds.set_x(*params->update_info.left);
set_bounds = true;
set_pos_only = true;
}

if (params->update_info.top) {
bounds.set_y(*params->update_info.top);
set_bounds = true;
set_pos_only = true;
}

if (params->update_info.width) {
bounds.set_width(*params->update_info.width);
set_bounds = true;
set_pos_only = false;
}

if (params->update_info.height) {
bounds.set_height(*params->update_info.height);
set_bounds = true;
set_pos_only = false;
}

bool set_client_bounds = false;
Expand Down Expand Up @@ -961,7 +966,12 @@ ExtensionFunction::ResponseAction WindowsUpdateFunction::Run() {
}
// TODO(varkha): Updating bounds during a drag can cause problems and a more
// general solution is needed. See http://crbug.com/251813 .
browser->window()->SetBounds(bounds);
#if defined(OS_WIN)
if (set_pos_only)
browser->window()->SetPosition(bounds.origin());
else
#endif
browser->window()->SetBounds(bounds);
}

if (params->update_info.position &&
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/ui/browser_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ class BrowserWindow : public ui::BaseWindow {
// be called after the TabStripModel has an active tab.
virtual void SetContentsSize(const gfx::Size& size) = 0;

#if defined(OS_WIN)
virtual void SetPosition(const gfx::Point& pos) = 0;
#endif

// Updates the visual state of the specified page action icon if present on
// the window. Returns whether any change occurred.
virtual bool UpdatePageActionIcon(PageActionIconType type) = 0;
Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/ui/views/frame/browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,13 @@ void BrowserView::SetBounds(const gfx::Rect& bounds) {
GetWidget()->SetBounds(bounds);
}

#if defined(OS_WIN)
void BrowserView::SetPosition(const gfx::Point& pos) {
ExitFullscreen();
GetWidget()->SetPosition(pos);
}
#endif

void BrowserView::Close() {
frame_->Close();
}
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ui/views/frame/browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ class BrowserView : public BrowserWindow,
void Hide() override;
bool IsVisible() const override;
void SetBounds(const gfx::Rect& bounds) override;
#if defined(OS_WIN)
void SetPosition(const gfx::Point& pos) override;
#endif
void Close() override;
void Activate() override;
void Deactivate() override;
Expand Down
6 changes: 6 additions & 0 deletions ui/aura/window_tree_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ void WindowTreeHost::UpdateRootWindowSizeInPixels() {
window()->SetBounds(transformed_bounds_in_pixels);
}

#if defined(OS_WIN)
void WindowTreeHost::SetPositionInPixels(const gfx::Point& pos_in_pixels) {

}
#endif

void WindowTreeHost::ConvertDIPToScreenInPixels(gfx::Point* point) const {
ConvertDIPToPixels(point);
gfx::Point location = GetLocationOnScreenInPixels();
Expand Down
3 changes: 3 additions & 0 deletions ui/aura/window_tree_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate,
// depending on the platform. The |local_surface_id| takes effect when (and
// if) the new size is confirmed (potentially asynchronously) by the platform.
virtual void SetBoundsInPixels(const gfx::Rect& bounds_in_pixels) = 0;
#if defined(OS_WIN)
virtual void SetPositionInPixels(const gfx::Point& pos_in_pixels);
#endif
virtual gfx::Rect GetBoundsInPixels() const = 0;

// Sets the OS capture to the root window.
Expand Down
8 changes: 8 additions & 0 deletions ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,14 @@ void DesktopNativeWidgetAura::SetBounds(const gfx::Rect& bounds) {
desktop_window_tree_host_->SetBoundsInDIP(bounds);
}

#if defined(OS_WIN)
void DesktopNativeWidgetAura::SetPosition(const gfx::Point& pos) {
if (!content_window_)
return;
desktop_window_tree_host_->SetPositionInDIP(pos);
}
#endif

void DesktopNativeWidgetAura::SetBoundsConstrained(const gfx::Rect& bounds) {
if (!content_window_)
return;
Expand Down
3 changes: 3 additions & 0 deletions ui/views/widget/desktop_aura/desktop_native_widget_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
gfx::Rect GetRestoredBounds() const override;
std::string GetWorkspace() const override;
void SetBounds(const gfx::Rect& bounds) override;
#if defined(OS_WIN)
void SetPosition(const gfx::Point& pos) override;
#endif
void SetBoundsConstrained(const gfx::Rect& bounds) override;
void SetSize(const gfx::Size& size) override;
void StackAbove(gfx::NativeView native_view) override;
Expand Down
12 changes: 12 additions & 0 deletions ui/views/widget/desktop_aura/desktop_window_tree_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"

#if defined(OS_WIN)
#include "ui/display/win/screen_win.h"
#endif

#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/display/screen.h"
Expand All @@ -18,6 +22,14 @@ void DesktopWindowTreeHost::SetBoundsInDIP(const gfx::Rect& bounds) {
AsWindowTreeHost()->SetBoundsInPixels(bounds_in_pixels);
}

#if defined(OS_WIN)
void DesktopWindowTreeHost::SetPositionInDIP(const gfx::Point& pos) {
const gfx::Point pos_in_pixels =
display::win::ScreenWin::DIPToScreenPoint(pos);
AsWindowTreeHost()->SetPositionInPixels(pos_in_pixels);
}
#endif

std::unique_ptr<aura::client::ScreenPositionClient>
DesktopWindowTreeHost::CreateScreenPositionClient() {
return std::make_unique<DesktopScreenPositionClient>(
Expand Down
4 changes: 4 additions & 0 deletions ui/views/widget/desktop_aura/desktop_window_tree_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ class VIEWS_EXPORT DesktopWindowTreeHost {
// Sets the bounds in screen coordinate DIPs (WindowTreeHost generally
// operates in pixels). This function is implemented in terms of Screen.
virtual void SetBoundsInDIP(const gfx::Rect& bounds);
#if defined(OS_WIN)
virtual void SetPositionInDIP(const gfx::Point& pos);
#endif

};

} // namespace views
Expand Down
4 changes: 4 additions & 0 deletions ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ gfx::Rect DesktopWindowTreeHostWin::GetBoundsInPixels() const {
return without_expansion;
}

void DesktopWindowTreeHostWin::SetPositionInPixels(const gfx::Point& pos) {
message_handler_->SetPosition(pos);
}

void DesktopWindowTreeHostWin::SetBoundsInPixels(const gfx::Rect& bounds) {
// If the window bounds have to be expanded we need to subtract the
// window_expansion_top_left_delta_ from the origin and add the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
void HideImpl() override;
gfx::Rect GetBoundsInPixels() const override;
void SetBoundsInPixels(const gfx::Rect& bounds) override;
void SetPositionInPixels(const gfx::Point& pos) override;
gfx::Point GetLocationOnScreenInPixels() const override;
void SetCapture() override;
void ReleaseCapture() override;
Expand Down
5 changes: 5 additions & 0 deletions ui/views/widget/native_widget_private.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
namespace views {
namespace internal {

#if defined(OS_WIN)
void NativeWidgetPrivate::SetPosition(const gfx::Point& pos) {

}
#endif
// static
gfx::Rect NativeWidgetPrivate::ConstrainBoundsToDisplayWorkArea(
const gfx::Rect& bounds) {
Expand Down
3 changes: 3 additions & 0 deletions ui/views/widget/native_widget_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget {
virtual gfx::Rect GetRestoredBounds() const = 0;
virtual std::string GetWorkspace() const = 0;
virtual void SetBounds(const gfx::Rect& bounds) = 0;
#if defined(OS_WIN)
virtual void SetPosition(const gfx::Point& pos);
#endif
virtual void SetBoundsConstrained(const gfx::Rect& bounds) = 0;
virtual void SetSize(const gfx::Size& size) = 0;
virtual void StackAbove(gfx::NativeView native_view) = 0;
Expand Down
6 changes: 6 additions & 0 deletions ui/views/widget/widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ void Widget::SetBounds(const gfx::Rect& bounds) {
native_widget_->SetBounds(bounds);
}

#if defined(OS_WIN)
void Widget::SetPosition(const gfx::Point& pos) {
native_widget_->SetPosition(pos);
}
#endif

void Widget::SetSize(const gfx::Size& size) {
native_widget_->SetSize(size);
}
Expand Down
3 changes: 3 additions & 0 deletions ui/views/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,

// Sizes and/or places the widget to the specified bounds, size or position.
void SetBounds(const gfx::Rect& bounds);
#if defined(OS_WIN)
void SetPosition(const gfx::Point& position);
#endif
void SetSize(const gfx::Size& size);

// Sizes the window to the specified size and centers it.
Expand Down
5 changes: 5 additions & 0 deletions ui/views/win/hwnd_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3479,6 +3479,11 @@ bool HWNDMessageHandler::HandleMouseInputForCaption(unsigned int message,
return handled;
}

void HWNDMessageHandler::SetPosition(const gfx::Point& pos_in_pixels) {
SetWindowPos(hwnd(), nullptr, pos_in_pixels.x(), pos_in_pixels.y(),
0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
}

void HWNDMessageHandler::SetBoundsInternal(const gfx::Rect& bounds_in_pixels,
bool force_size_changed) {
gfx::Size old_size = GetClientAreaBounds().size();
Expand Down
1 change: 1 addition & 0 deletions ui/views/win/hwnd_message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ class VIEWS_EXPORT HWNDMessageHandler : public gfx::WindowImpl,
// please refer to the SetBounds() function.
void SetBoundsInternal(const gfx::Rect& bounds_in_pixels,
bool force_size_changed);
void SetPosition(const gfx::Point& pos_in_pixels);

// Checks if there is a full screen window on the same monitor as the
// |window| which is becoming active. If yes then we reduce the size of the
Expand Down

0 comments on commit 4339788

Please sign in to comment.