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

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: SetBounds + rebase 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
« no previous file with comments | « ui/views/mus/desktop_window_tree_host_mus.h ('k') | ui/views/mus/window_tree_host_mus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base/hit_test.h" 14 #include "ui/base/hit_test.h"
15 #include "ui/display/screen.h" 15 #include "ui/display/screen.h"
16 #include "ui/gfx/geometry/dip_util.h"
16 #include "ui/views/corewm/tooltip_aura.h" 17 #include "ui/views/corewm/tooltip_aura.h"
17 #include "ui/views/mus/mus_client.h" 18 #include "ui/views/mus/mus_client.h"
18 #include "ui/views/mus/window_manager_frame_values.h" 19 #include "ui/views/mus/window_manager_frame_values.h"
19 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 20 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
20 #include "ui/views/widget/native_widget_aura.h" 21 #include "ui/views/widget/native_widget_aura.h"
21 #include "ui/views/widget/widget_delegate.h" 22 #include "ui/views/widget/widget_delegate.h"
22 #include "ui/wm/core/window_util.h" 23 #include "ui/wm/core/window_util.h"
23 #include "ui/wm/public/activation_client.h" 24 #include "ui/wm/public/activation_client.h"
24 25
25 namespace views { 26 namespace views {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 157 }
157 158
158 gfx::Path mask_path; 159 gfx::Path mask_path;
159 native_widget_delegate_->GetHitTestMask(&mask_path); 160 native_widget_delegate_->GetHitTestMask(&mask_path);
160 // TODO(jamescook): Use the full path for the mask. 161 // TODO(jamescook): Use the full path for the mask.
161 gfx::Rect mask_rect = 162 gfx::Rect mask_rect =
162 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 163 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
163 SetHitTestMask(mask_rect); 164 SetHitTestMask(mask_rect);
164 } 165 }
165 166
167 float DesktopWindowTreeHostMus::GetScaleFactor() const {
168 // TODO(sky): GetDisplayNearestWindow() should take a const aura::Window*.
169 return display::Screen::GetScreen()
170 ->GetDisplayNearestWindow(const_cast<aura::Window*>(window()))
171 .device_scale_factor();
172 }
173
174 void DesktopWindowTreeHostMus::SetBoundsInDips(
175 const gfx::Rect& bounds_in_dips) {
176 SetBounds(gfx::ConvertRectToPixel(GetScaleFactor(), bounds_in_dips));
177 }
178
166 void DesktopWindowTreeHostMus::Init(aura::Window* content_window, 179 void DesktopWindowTreeHostMus::Init(aura::Window* content_window,
167 const Widget::InitParams& params) { 180 const Widget::InitParams& params) {
168 // TODO: handle device scale, http://crbug.com/663524.
169 if (!params.bounds.IsEmpty()) 181 if (!params.bounds.IsEmpty())
170 SetBounds(params.bounds); 182 SetBoundsInDips(params.bounds);
171 } 183 }
172 184
173 void DesktopWindowTreeHostMus::OnNativeWidgetCreated( 185 void DesktopWindowTreeHostMus::OnNativeWidgetCreated(
174 const Widget::InitParams& params) { 186 const Widget::InitParams& params) {
175 if (params.parent && params.parent->GetHost()) { 187 if (params.parent && params.parent->GetHost()) {
176 parent_ = static_cast<DesktopWindowTreeHostMus*>(params.parent->GetHost()); 188 parent_ = static_cast<DesktopWindowTreeHostMus*>(params.parent->GetHost());
177 parent_->children_.insert(this); 189 parent_->children_.insert(this);
178 } 190 }
179 native_widget_delegate_->OnNativeWidgetCreated(true); 191 native_widget_delegate_->OnNativeWidgetCreated(true);
180 } 192 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // aura::Window. 273 // aura::Window.
262 return window()->IsVisible() && 274 return window()->IsVisible() &&
263 (!parent_ || 275 (!parent_ ||
264 static_cast<const internal::NativeWidgetPrivate*>( 276 static_cast<const internal::NativeWidgetPrivate*>(
265 parent_->desktop_native_widget_aura_) 277 parent_->desktop_native_widget_aura_)
266 ->IsVisible()); 278 ->IsVisible());
267 } 279 }
268 280
269 void DesktopWindowTreeHostMus::SetSize(const gfx::Size& size) { 281 void DesktopWindowTreeHostMus::SetSize(const gfx::Size& size) {
270 // Use GetBounds() as the origin of window() is always at 0, 0. 282 // Use GetBounds() as the origin of window() is always at 0, 0.
271 gfx::Rect screen_bounds = GetBounds(); 283 gfx::Rect screen_bounds =
272 // TODO: handle device scale, http://crbug.com/663524. Also, |screen_bounds| 284 gfx::ConvertRectToDIP(GetScaleFactor(), GetBounds());
273 // is in pixels and should be dip.
274 screen_bounds.set_size(size); 285 screen_bounds.set_size(size);
275 SetBounds(screen_bounds); 286 SetBoundsInDips(screen_bounds);
276 } 287 }
277 288
278 void DesktopWindowTreeHostMus::StackAbove(aura::Window* window) { 289 void DesktopWindowTreeHostMus::StackAbove(aura::Window* window) {
279 // TODO: implement window stacking, http://crbug.com/663617. 290 // TODO: implement window stacking, http://crbug.com/663617.
280 NOTIMPLEMENTED(); 291 NOTIMPLEMENTED();
281 } 292 }
282 293
283 void DesktopWindowTreeHostMus::StackAtTop() { 294 void DesktopWindowTreeHostMus::StackAtTop() {
284 // TODO: implement window stacking, http://crbug.com/663617. 295 // TODO: implement window stacking, http://crbug.com/663617.
285 NOTIMPLEMENTED(); 296 NOTIMPLEMENTED();
286 } 297 }
287 298
288 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) { 299 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) {
289 gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen(); 300 gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen();
290 301
291 // If there is a transient parent and it fits |size|, then center over it. 302 // If there is a transient parent and it fits |size|, then center over it.
292 aura::Window* content_window = desktop_native_widget_aura_->content_window(); 303 aura::Window* content_window = desktop_native_widget_aura_->content_window();
293 if (wm::GetTransientParent(content_window)) { 304 if (wm::GetTransientParent(content_window)) {
294 gfx::Rect transient_parent_bounds = 305 gfx::Rect transient_parent_bounds =
295 wm::GetTransientParent(content_window)->GetBoundsInScreen(); 306 wm::GetTransientParent(content_window)->GetBoundsInScreen();
296 if (transient_parent_bounds.height() >= size.height() && 307 if (transient_parent_bounds.height() >= size.height() &&
297 transient_parent_bounds.width() >= size.width()) { 308 transient_parent_bounds.width() >= size.width()) {
298 bounds_to_center_in = transient_parent_bounds; 309 bounds_to_center_in = transient_parent_bounds;
299 } 310 }
300 } 311 }
301 312
302 gfx::Rect resulting_bounds(bounds_to_center_in); 313 gfx::Rect resulting_bounds(bounds_to_center_in);
303 resulting_bounds.ClampToCenteredSize(size); 314 resulting_bounds.ClampToCenteredSize(size);
304 315 SetBoundsInDips(resulting_bounds);
305 // TODO: handle device scale, http://crbug.com/663524. SetBounds() expects
306 // pixels.
307 SetBounds(resulting_bounds);
308 } 316 }
309 317
310 void DesktopWindowTreeHostMus::GetWindowPlacement( 318 void DesktopWindowTreeHostMus::GetWindowPlacement(
311 gfx::Rect* bounds, 319 gfx::Rect* bounds,
312 ui::WindowShowState* show_state) const { 320 ui::WindowShowState* show_state) const {
313 // Implementation matches that of NativeWidgetAura. 321 // Implementation matches that of NativeWidgetAura.
314 *bounds = GetRestoredBounds(); 322 *bounds = GetRestoredBounds();
315 *show_state = window()->GetProperty(aura::client::kShowStateKey); 323 *show_state = window()->GetProperty(aura::client::kShowStateKey);
316 } 324 }
317 325
318 gfx::Rect DesktopWindowTreeHostMus::GetWindowBoundsInScreen() const { 326 gfx::Rect DesktopWindowTreeHostMus::GetWindowBoundsInScreen() const {
319 // TODO: convert to dips, http://crbug.com/663524. 327 return gfx::ConvertRectToDIP(GetScaleFactor(), GetBounds());
320 return GetBounds();
321 } 328 }
322 329
323 gfx::Rect DesktopWindowTreeHostMus::GetClientAreaBoundsInScreen() const { 330 gfx::Rect DesktopWindowTreeHostMus::GetClientAreaBoundsInScreen() const {
324 // View-to-screen coordinate system transformations depend on this returning 331 // View-to-screen coordinate system transformations depend on this returning
325 // the full window bounds, for example View::ConvertPointToScreen(). 332 // the full window bounds, for example View::ConvertPointToScreen().
326 return GetWindowBoundsInScreen(); 333 return GetWindowBoundsInScreen();
327 } 334 }
328 335
329 gfx::Rect DesktopWindowTreeHostMus::GetRestoredBounds() const { 336 gfx::Rect DesktopWindowTreeHostMus::GetRestoredBounds() const {
330 // Restored bounds should only be relevant if the window is minimized, 337 // Restored bounds should only be relevant if the window is minimized,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true); 563 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true);
557 } 564 }
558 565
559 void DesktopWindowTreeHostMus::HideImpl() { 566 void DesktopWindowTreeHostMus::HideImpl() {
560 native_widget_delegate_->OnNativeWidgetVisibilityChanging(false); 567 native_widget_delegate_->OnNativeWidgetVisibilityChanging(false);
561 WindowTreeHostMus::HideImpl(); 568 WindowTreeHostMus::HideImpl();
562 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); 569 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false);
563 } 570 }
564 571
565 void DesktopWindowTreeHostMus::SetBounds(const gfx::Rect& bounds_in_pixels) { 572 void DesktopWindowTreeHostMus::SetBounds(const gfx::Rect& bounds_in_pixels) {
566 // TODO: handle conversion to dips, http://crbug.com/663524.
567 gfx::Rect final_bounds_in_pixels = bounds_in_pixels; 573 gfx::Rect final_bounds_in_pixels = bounds_in_pixels;
568 if (GetBounds().size() != bounds_in_pixels.size()) { 574 if (GetBounds().size() != bounds_in_pixels.size()) {
569 gfx::Size size = bounds_in_pixels.size(); 575 gfx::Size size = bounds_in_pixels.size();
570 size.SetToMax(native_widget_delegate_->GetMinimumSize()); 576 size.SetToMax(gfx::ConvertSizeToPixel(
571 const gfx::Size max_size = native_widget_delegate_->GetMaximumSize(); 577 GetScaleFactor(), native_widget_delegate_->GetMinimumSize()));
572 if (!max_size.IsEmpty()) 578 const gfx::Size max_size_in_pixels = gfx::ConvertSizeToPixel(
573 size.SetToMin(max_size); 579 GetScaleFactor(), native_widget_delegate_->GetMaximumSize());
580 if (!max_size_in_pixels.IsEmpty())
581 size.SetToMin(max_size_in_pixels);
574 final_bounds_in_pixels.set_size(size); 582 final_bounds_in_pixels.set_size(size);
575 } 583 }
576 WindowTreeHostMus::SetBounds(final_bounds_in_pixels); 584 WindowTreeHostMus::SetBounds(final_bounds_in_pixels);
577 } 585 }
578 586
579 void DesktopWindowTreeHostMus::OnWindowInitialized(aura::Window* window) {} 587 void DesktopWindowTreeHostMus::OnWindowInitialized(aura::Window* window) {}
580 588
581 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged( 589 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged(
582 aura::client::FocusClient* focus_client, 590 aura::client::FocusClient* focus_client,
583 aura::Window* window) { 591 aura::Window* window) {
584 if (window == this->window()) { 592 if (window == this->window()) {
585 is_active_ = true; 593 is_active_ = true;
586 desktop_native_widget_aura_->HandleActivationChanged(true); 594 desktop_native_widget_aura_->HandleActivationChanged(true);
587 } else if (is_active_) { 595 } else if (is_active_) {
588 is_active_ = false; 596 is_active_ = false;
589 desktop_native_widget_aura_->HandleActivationChanged(false); 597 desktop_native_widget_aura_->HandleActivationChanged(false);
590 } 598 }
591 } 599 }
592 600
593 } // namespace views 601 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/desktop_window_tree_host_mus.h ('k') | ui/views/mus/window_tree_host_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698