Skip to content

Commit

Permalink
mash: Fix shelf on second display appearing in wrong position
Browse files Browse the repository at this point in the history
NativeWidgetMus::SetBounds() was not correcting for the display origin.

Also fix NativeWidgetMus::GetBoundsInScreen(), which had the same problem.

BUG=645291,644895
TEST=run mash with --multi-display, shelf appears on second display

Review-Url: https://codereview.chromium.org/2328523003
Cr-Commit-Position: refs/heads/master@{#417505}
  • Loading branch information
jamescook authored and Commit bot committed Sep 9, 2016
1 parent 8e62373 commit fa697bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 28 additions & 4 deletions ui/views/mus/native_widget_mus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,22 @@ void NativeWidgetMus::InitModalType(ui::ModalType modal_type) {
}

gfx::Rect NativeWidgetMus::GetWindowBoundsInScreen() const {
return window_ ? window_->GetBoundsInRoot() : gfx::Rect();
if (!window_)
return gfx::Rect();

// Correct for the origin of the display.
const int64_t window_display_id = window_->GetRoot()->display_id();
for (display::Display display :
display::Screen::GetScreen()->GetAllDisplays()) {
if (display.id() == window_display_id) {
gfx::Point display_origin = display.bounds().origin();
gfx::Rect bounds_in_screen = window_->GetBoundsInRoot();
bounds_in_screen.Offset(display_origin.x(), display_origin.y());
return bounds_in_screen;
}
}
// Unknown display, assume primary display at 0,0.
return window_->GetBoundsInRoot();
}

gfx::Rect NativeWidgetMus::GetClientAreaBoundsInScreen() const {
Expand All @@ -934,17 +949,26 @@ std::string NativeWidgetMus::GetWorkspace() const {
return std::string();
}

void NativeWidgetMus::SetBounds(const gfx::Rect& bounds) {
void NativeWidgetMus::SetBounds(const gfx::Rect& bounds_in_screen) {
if (!(window_ && window_tree_host_))
return;

gfx::Size size(bounds.size());
// TODO(jamescook): Needs something like aura::ScreenPositionClient so higher
// level code can move windows between displays. crbug.com/645291
gfx::Point origin(bounds_in_screen.origin());
const gfx::Point display_origin = display::Screen::GetScreen()
->GetDisplayMatching(bounds_in_screen)
.bounds()
.origin();
origin.Offset(-display_origin.x(), -display_origin.y());

gfx::Size size(bounds_in_screen.size());
const gfx::Size min_size = GetMinimumSize();
const gfx::Size max_size = GetMaximumSize();
if (!max_size.IsEmpty())
size.SetToMin(max_size);
size.SetToMax(min_size);
window_->SetBounds(gfx::Rect(bounds.origin(), size));
window_->SetBounds(gfx::Rect(origin, size));
// Observer on |window_tree_host_| expected to synchronously update bounds.
DCHECK(window_->bounds() == window_tree_host_->GetBounds());
}
Expand Down
2 changes: 1 addition & 1 deletion ui/views/mus/native_widget_mus.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class VIEWS_MUS_EXPORT NativeWidgetMus
gfx::Rect GetClientAreaBoundsInScreen() const override;
gfx::Rect GetRestoredBounds() const override;
std::string GetWorkspace() const override;
void SetBounds(const gfx::Rect& bounds) override;
void SetBounds(const gfx::Rect& bounds_in_screen) override;
void SetSize(const gfx::Size& size) override;
void StackAbove(gfx::NativeView native_view) override;
void StackAtTop() override;
Expand Down

0 comments on commit fa697bc

Please sign in to comment.