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

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: sadrul@'s comment Created 4 years 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);
sky 2016/11/21 22:27:25 This code is hard to read because it isn't clear w
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true); 419 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true);
425 } 420 }
426 421
427 void DesktopWindowTreeHostMus::HideImpl() { 422 void DesktopWindowTreeHostMus::HideImpl() {
428 native_widget_delegate_->OnNativeWidgetVisibilityChanging(false); 423 native_widget_delegate_->OnNativeWidgetVisibilityChanging(false);
429 WindowTreeHostMus::HideImpl(); 424 WindowTreeHostMus::HideImpl();
430 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); 425 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false);
431 } 426 }
432 427
433 void DesktopWindowTreeHostMus::SetBounds(const gfx::Rect& bounds_in_pixels) { 428 void DesktopWindowTreeHostMus::SetBounds(const gfx::Rect& bounds_in_pixels) {
434 // TODO: handle conversion to dips, http://crbug.com/663524.
435 gfx::Rect final_bounds_in_pixels = bounds_in_pixels; 429 gfx::Rect final_bounds_in_pixels = bounds_in_pixels;
436 if (GetBounds().size() != bounds_in_pixels.size()) { 430 if (GetBounds().size() != bounds_in_pixels.size()) {
437 gfx::Size size = bounds_in_pixels.size(); 431 gfx::Size size = bounds_in_pixels.size();
438 size.SetToMax(native_widget_delegate_->GetMinimumSize()); 432 size.SetToMax(gfx::ConvertSizeToPixel(
439 const gfx::Size max_size = native_widget_delegate_->GetMaximumSize(); 433 GetScaleFactor(), native_widget_delegate_->GetMinimumSize()));
440 if (!max_size.IsEmpty()) 434 const gfx::Size max_size_in_pixels = gfx::ConvertSizeToPixel(
441 size.SetToMin(max_size); 435 GetScaleFactor(), native_widget_delegate_->GetMaximumSize());
436 if (!max_size_in_pixels.IsEmpty())
437 size.SetToMin(max_size_in_pixels);
442 final_bounds_in_pixels.set_size(size); 438 final_bounds_in_pixels.set_size(size);
443 } 439 }
444 WindowTreeHostMus::SetBounds(final_bounds_in_pixels); 440 WindowTreeHostMus::SetBounds(final_bounds_in_pixels);
445 } 441 }
446 442
447 void DesktopWindowTreeHostMus::OnWindowInitialized(aura::Window* window) {} 443 void DesktopWindowTreeHostMus::OnWindowInitialized(aura::Window* window) {}
448 444
449 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged( 445 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged(
450 aura::client::FocusClient* focus_client, 446 aura::client::FocusClient* focus_client,
451 aura::Window* window) { 447 aura::Window* window) {
452 if (window == this->window()) { 448 if (window == this->window()) {
453 is_active_ = true; 449 is_active_ = true;
454 desktop_native_widget_aura_->HandleActivationChanged(true); 450 desktop_native_widget_aura_->HandleActivationChanged(true);
455 } else if (is_active_) { 451 } else if (is_active_) {
456 is_active_ = false; 452 is_active_ = false;
457 desktop_native_widget_aura_->HandleActivationChanged(false); 453 desktop_native_widget_aura_->HandleActivationChanged(false);
458 } 454 }
459 } 455 }
460 456
457 float DesktopWindowTreeHostMus::GetScaleFactor() const {
458 // TODO(sky): GetDisplayNearestWindow() should take a const aura::Window*.
459 return display::Screen::GetScreen()
460 ->GetDisplayNearestWindow(const_cast<aura::Window*>(window()))
461 .device_scale_factor();
462 }
463
461 } // namespace views 464 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698