Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: ui/views/mus/desktop_window_tree_host_mus.cc

Issue 2504793002: Scale bounds in DesktopWindowTreeHostMus and in calls to SetBounds. (Closed)
Patch Set: blimp Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/mus/desktop_window_tree_host_mus.h" 5 #include "ui/views/mus/desktop_window_tree_host_mus.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "ui/aura/client/aura_constants.h" 8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/client/drag_drop_client.h" 9 #include "ui/aura/client/drag_drop_client.h"
10 #include "ui/aura/client/focus_client.h" 10 #include "ui/aura/client/focus_client.h"
11 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
12 #include "ui/aura/mus/window_tree_host_mus.h" 12 #include "ui/aura/mus/window_tree_host_mus.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/display/screen.h" 14 #include "ui/display/screen.h"
15 #include "ui/gfx/geometry/dip_util.h"
15 #include "ui/views/corewm/tooltip_aura.h" 16 #include "ui/views/corewm/tooltip_aura.h"
16 #include "ui/views/mus/mus_client.h" 17 #include "ui/views/mus/mus_client.h"
17 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 18 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
18 #include "ui/views/widget/native_widget_aura.h" 19 #include "ui/views/widget/native_widget_aura.h"
19 #include "ui/views/widget/widget_delegate.h" 20 #include "ui/views/widget/widget_delegate.h"
20 #include "ui/wm/core/window_util.h" 21 #include "ui/wm/core/window_util.h"
21 #include "ui/wm/public/activation_client.h" 22 #include "ui/wm/public/activation_client.h"
22 23
23 namespace views { 24 namespace views {
24 25
(...skipping 17 matching lines...) Expand all
42 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); 43 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this);
43 } 44 }
44 45
45 bool DesktopWindowTreeHostMus::IsDocked() const { 46 bool DesktopWindowTreeHostMus::IsDocked() const {
46 return window()->GetProperty(aura::client::kShowStateKey) == 47 return window()->GetProperty(aura::client::kShowStateKey) ==
47 ui::SHOW_STATE_DOCKED; 48 ui::SHOW_STATE_DOCKED;
48 } 49 }
49 50
50 void DesktopWindowTreeHostMus::Init(aura::Window* content_window, 51 void DesktopWindowTreeHostMus::Init(aura::Window* content_window,
51 const Widget::InitParams& params) { 52 const Widget::InitParams& params) {
52 // TODO: handle device scale, http://crbug.com/663524.
53 if (!params.bounds.IsEmpty()) 53 if (!params.bounds.IsEmpty())
54 SetBounds(params.bounds); 54 SetBounds(gfx::ConvertRectToPixel(GetScaleFactor(), params.bounds));
55 } 55 }
56 56
57 void DesktopWindowTreeHostMus::OnNativeWidgetCreated( 57 void DesktopWindowTreeHostMus::OnNativeWidgetCreated(
58 const Widget::InitParams& params) { 58 const Widget::InitParams& params) {
59 if (params.parent && params.parent->GetHost()) { 59 if (params.parent && params.parent->GetHost()) {
60 parent_ = static_cast<DesktopWindowTreeHostMus*>(params.parent->GetHost()); 60 parent_ = static_cast<DesktopWindowTreeHostMus*>(params.parent->GetHost());
61 parent_->children_.insert(this); 61 parent_->children_.insert(this);
62 } 62 }
63 native_widget_delegate_->OnNativeWidgetCreated(true); 63 native_widget_delegate_->OnNativeWidgetCreated(true);
64 } 64 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // aura::Window. 145 // aura::Window.
146 return window()->IsVisible() && 146 return window()->IsVisible() &&
147 (!parent_ || 147 (!parent_ ||
148 static_cast<const internal::NativeWidgetPrivate*>( 148 static_cast<const internal::NativeWidgetPrivate*>(
149 parent_->desktop_native_widget_aura_) 149 parent_->desktop_native_widget_aura_)
150 ->IsVisible()); 150 ->IsVisible());
151 } 151 }
152 152
153 void DesktopWindowTreeHostMus::SetSize(const gfx::Size& size) { 153 void DesktopWindowTreeHostMus::SetSize(const gfx::Size& size) {
154 // Use GetBounds() as the origin of window() is always at 0, 0. 154 // Use GetBounds() as the origin of window() is always at 0, 0.
155 gfx::Rect screen_bounds = GetBounds(); 155 gfx::Rect screen_bounds_in_pixels = GetBounds();
156 // TODO: handle device scale, http://crbug.com/663524. Also, |screen_bounds| 156 screen_bounds_in_pixels.set_size(
157 // is in pixels and should be dip. 157 gfx::ConvertSizeToPixel(GetScaleFactor(), size));
158 screen_bounds.set_size(size); 158 SetBounds(screen_bounds_in_pixels);
159 SetBounds(screen_bounds);
160 } 159 }
161 160
162 void DesktopWindowTreeHostMus::StackAbove(aura::Window* window) { 161 void DesktopWindowTreeHostMus::StackAbove(aura::Window* window) {
163 // TODO: implement window stacking, http://crbug.com/663617. 162 // TODO: implement window stacking, http://crbug.com/663617.
164 NOTIMPLEMENTED(); 163 NOTIMPLEMENTED();
165 } 164 }
166 165
167 void DesktopWindowTreeHostMus::StackAtTop() { 166 void DesktopWindowTreeHostMus::StackAtTop() {
168 // TODO: implement window stacking, http://crbug.com/663617. 167 // TODO: implement window stacking, http://crbug.com/663617.
169 NOTIMPLEMENTED(); 168 NOTIMPLEMENTED();
170 } 169 }
171 170
172 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) { 171 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) {
173 gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen(); 172 gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen();
174 173
175 // If there is a transient parent and it fits |size|, then center over it. 174 // If there is a transient parent and it fits |size|, then center over it.
176 aura::Window* content_window = desktop_native_widget_aura_->content_window(); 175 aura::Window* content_window = desktop_native_widget_aura_->content_window();
177 if (wm::GetTransientParent(content_window)) { 176 if (wm::GetTransientParent(content_window)) {
178 gfx::Rect transient_parent_bounds = 177 gfx::Rect transient_parent_bounds =
179 wm::GetTransientParent(content_window)->GetBoundsInScreen(); 178 wm::GetTransientParent(content_window)->GetBoundsInScreen();
180 if (transient_parent_bounds.height() >= size.height() && 179 if (transient_parent_bounds.height() >= size.height() &&
181 transient_parent_bounds.width() >= size.width()) { 180 transient_parent_bounds.width() >= size.width()) {
182 bounds_to_center_in = transient_parent_bounds; 181 bounds_to_center_in = transient_parent_bounds;
183 } 182 }
184 } 183 }
185 184
186 gfx::Rect resulting_bounds(bounds_to_center_in); 185 gfx::Rect resulting_bounds(bounds_to_center_in);
187 resulting_bounds.ClampToCenteredSize(size); 186 resulting_bounds.ClampToCenteredSize(size);
188 187 SetBounds(gfx::ConvertRectToPixel(GetScaleFactor(), resulting_bounds));
189 // TODO: handle device scale, http://crbug.com/663524. SetBounds() expects
190 // pixels.
191 SetBounds(resulting_bounds);
192 } 188 }
193 189
194 void DesktopWindowTreeHostMus::GetWindowPlacement( 190 void DesktopWindowTreeHostMus::GetWindowPlacement(
195 gfx::Rect* bounds, 191 gfx::Rect* bounds,
196 ui::WindowShowState* show_state) const { 192 ui::WindowShowState* show_state) const {
197 // Implementation matches that of NativeWidgetAura. 193 // Implementation matches that of NativeWidgetAura.
198 *bounds = GetRestoredBounds(); 194 *bounds = GetRestoredBounds();
199 *show_state = window()->GetProperty(aura::client::kShowStateKey); 195 *show_state = window()->GetProperty(aura::client::kShowStateKey);
200 } 196 }
201 197
202 gfx::Rect DesktopWindowTreeHostMus::GetWindowBoundsInScreen() const { 198 gfx::Rect DesktopWindowTreeHostMus::GetWindowBoundsInScreen() const {
203 // TODO: convert to dips, http://crbug.com/663524. 199 return gfx::ConvertRectToDIP(GetScaleFactor(), GetBounds());
204 return GetBounds();
205 } 200 }
206 201
207 gfx::Rect DesktopWindowTreeHostMus::GetClientAreaBoundsInScreen() const { 202 gfx::Rect DesktopWindowTreeHostMus::GetClientAreaBoundsInScreen() const {
208 // View-to-screen coordinate system transformations depend on this returning 203 // View-to-screen coordinate system transformations depend on this returning
209 // the full window bounds, for example View::ConvertPointToScreen(). 204 // the full window bounds, for example View::ConvertPointToScreen().
210 return GetWindowBoundsInScreen(); 205 return GetWindowBoundsInScreen();
211 } 206 }
212 207
213 gfx::Rect DesktopWindowTreeHostMus::GetRestoredBounds() const { 208 gfx::Rect DesktopWindowTreeHostMus::GetRestoredBounds() const {
214 // Restored bounds should only be relevant if the window is minimized, 209 // Restored bounds should only be relevant if the window is minimized,
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true); 421 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true);
427 } 422 }
428 423
429 void DesktopWindowTreeHostMus::HideImpl() { 424 void DesktopWindowTreeHostMus::HideImpl() {
430 native_widget_delegate_->OnNativeWidgetVisibilityChanging(false); 425 native_widget_delegate_->OnNativeWidgetVisibilityChanging(false);
431 WindowTreeHostMus::HideImpl(); 426 WindowTreeHostMus::HideImpl();
432 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); 427 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false);
433 } 428 }
434 429
435 void DesktopWindowTreeHostMus::SetBounds(const gfx::Rect& bounds_in_pixels) { 430 void DesktopWindowTreeHostMus::SetBounds(const gfx::Rect& bounds_in_pixels) {
436 // TODO: handle conversion to dips, http://crbug.com/663524.
437 gfx::Rect final_bounds_in_pixels = bounds_in_pixels; 431 gfx::Rect final_bounds_in_pixels = bounds_in_pixels;
438 if (GetBounds().size() != bounds_in_pixels.size()) { 432 if (GetBounds().size() != bounds_in_pixels.size()) {
439 gfx::Size size = bounds_in_pixels.size(); 433 gfx::Size size = bounds_in_pixels.size();
440 size.SetToMax(native_widget_delegate_->GetMinimumSize()); 434 size.SetToMax(gfx::ConvertSizeToPixel(
441 const gfx::Size max_size = native_widget_delegate_->GetMaximumSize(); 435 GetScaleFactor(), native_widget_delegate_->GetMinimumSize()));
442 if (!max_size.IsEmpty()) 436 const gfx::Size max_size_in_pixels = gfx::ConvertSizeToPixel(
443 size.SetToMin(max_size); 437 GetScaleFactor(), native_widget_delegate_->GetMaximumSize());
438 if (!max_size_in_pixels.IsEmpty())
439 size.SetToMin(max_size_in_pixels);
444 final_bounds_in_pixels.set_size(size); 440 final_bounds_in_pixels.set_size(size);
445 } 441 }
446 WindowTreeHostMus::SetBounds(final_bounds_in_pixels); 442 WindowTreeHostMus::SetBounds(final_bounds_in_pixels);
447 } 443 }
448 444
449 void DesktopWindowTreeHostMus::OnWindowInitialized(aura::Window* window) {} 445 void DesktopWindowTreeHostMus::OnWindowInitialized(aura::Window* window) {}
450 446
451 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged( 447 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged(
452 aura::client::FocusClient* focus_client, 448 aura::client::FocusClient* focus_client,
453 aura::Window* window) { 449 aura::Window* window) {
454 if (window == this->window()) { 450 if (window == this->window()) {
455 is_active_ = true; 451 is_active_ = true;
456 desktop_native_widget_aura_->HandleActivationChanged(true); 452 desktop_native_widget_aura_->HandleActivationChanged(true);
457 } else if (is_active_) { 453 } else if (is_active_) {
458 is_active_ = false; 454 is_active_ = false;
459 desktop_native_widget_aura_->HandleActivationChanged(false); 455 desktop_native_widget_aura_->HandleActivationChanged(false);
460 } 456 }
461 } 457 }
462 458
459 float DesktopWindowTreeHostMus::GetScaleFactor() const {
460 // TODO(sky): GetDisplayNearestWindow() should take a const aura::Window*.
461 return display::Screen::GetScreen()
462 ->GetDisplayNearestWindow(const_cast<aura::Window*>(window()))
463 .device_scale_factor();
464 }
465
463 } // namespace views 466 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698