| OLD | NEW |
| 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 15 matching lines...) Expand all Loading... |
| 40 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); | 41 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); |
| 41 } | 42 } |
| 42 | 43 |
| 43 bool DesktopWindowTreeHostMus::IsDocked() const { | 44 bool DesktopWindowTreeHostMus::IsDocked() const { |
| 44 return window()->GetProperty(aura::client::kShowStateKey) == | 45 return window()->GetProperty(aura::client::kShowStateKey) == |
| 45 ui::SHOW_STATE_DOCKED; | 46 ui::SHOW_STATE_DOCKED; |
| 46 } | 47 } |
| 47 | 48 |
| 48 void DesktopWindowTreeHostMus::Init(aura::Window* content_window, | 49 void DesktopWindowTreeHostMus::Init(aura::Window* content_window, |
| 49 const Widget::InitParams& params) { | 50 const Widget::InitParams& params) { |
| 50 // TODO: handle device scale, http://crbug.com/663524. | |
| 51 if (!params.bounds.IsEmpty()) | 51 if (!params.bounds.IsEmpty()) |
| 52 SetBounds(params.bounds); | 52 SetBounds(gfx::ConvertRectToPixel(GetScaleFactor(), params.bounds)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void DesktopWindowTreeHostMus::OnNativeWidgetCreated( | 55 void DesktopWindowTreeHostMus::OnNativeWidgetCreated( |
| 56 const Widget::InitParams& params) { | 56 const Widget::InitParams& params) { |
| 57 if (params.parent && params.parent->GetHost()) { | 57 if (params.parent && params.parent->GetHost()) { |
| 58 parent_ = static_cast<DesktopWindowTreeHostMus*>(params.parent->GetHost()); | 58 parent_ = static_cast<DesktopWindowTreeHostMus*>(params.parent->GetHost()); |
| 59 parent_->children_.insert(this); | 59 parent_->children_.insert(this); |
| 60 } | 60 } |
| 61 native_widget_delegate_->OnNativeWidgetCreated(true); | 61 native_widget_delegate_->OnNativeWidgetCreated(true); |
| 62 } | 62 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // aura::Window. | 143 // aura::Window. |
| 144 return window()->IsVisible() && | 144 return window()->IsVisible() && |
| 145 (!parent_ || | 145 (!parent_ || |
| 146 static_cast<const internal::NativeWidgetPrivate*>( | 146 static_cast<const internal::NativeWidgetPrivate*>( |
| 147 parent_->desktop_native_widget_aura_) | 147 parent_->desktop_native_widget_aura_) |
| 148 ->IsVisible()); | 148 ->IsVisible()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void DesktopWindowTreeHostMus::SetSize(const gfx::Size& size) { | 151 void DesktopWindowTreeHostMus::SetSize(const gfx::Size& size) { |
| 152 // Use GetBounds() as the origin of window() is always at 0, 0. | 152 // Use GetBounds() as the origin of window() is always at 0, 0. |
| 153 gfx::Rect screen_bounds = GetBounds(); | 153 gfx::Rect screen_bounds_in_pixels = GetBounds(); |
| 154 // TODO: handle device scale, http://crbug.com/663524. Also, |screen_bounds| | 154 screen_bounds_in_pixels.set_size( |
| 155 // is in pixels and should be dip. | 155 gfx::ConvertSizeToPixel(GetScaleFactor(), size)); |
| 156 screen_bounds.set_size(size); | 156 SetBounds(screen_bounds_in_pixels); |
| 157 SetBounds(screen_bounds); | |
| 158 } | 157 } |
| 159 | 158 |
| 160 void DesktopWindowTreeHostMus::StackAbove(aura::Window* window) { | 159 void DesktopWindowTreeHostMus::StackAbove(aura::Window* window) { |
| 161 // TODO: implement window stacking, http://crbug.com/663617. | 160 // TODO: implement window stacking, http://crbug.com/663617. |
| 162 NOTIMPLEMENTED(); | 161 NOTIMPLEMENTED(); |
| 163 } | 162 } |
| 164 | 163 |
| 165 void DesktopWindowTreeHostMus::StackAtTop() { | 164 void DesktopWindowTreeHostMus::StackAtTop() { |
| 166 // TODO: implement window stacking, http://crbug.com/663617. | 165 // TODO: implement window stacking, http://crbug.com/663617. |
| 167 NOTIMPLEMENTED(); | 166 NOTIMPLEMENTED(); |
| 168 } | 167 } |
| 169 | 168 |
| 170 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) { | 169 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) { |
| 171 gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen(); | 170 gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen(); |
| 172 | 171 |
| 173 // If there is a transient parent and it fits |size|, then center over it. | 172 // If there is a transient parent and it fits |size|, then center over it. |
| 174 aura::Window* content_window = desktop_native_widget_aura_->content_window(); | 173 aura::Window* content_window = desktop_native_widget_aura_->content_window(); |
| 175 if (wm::GetTransientParent(content_window)) { | 174 if (wm::GetTransientParent(content_window)) { |
| 176 gfx::Rect transient_parent_bounds = | 175 gfx::Rect transient_parent_bounds = |
| 177 wm::GetTransientParent(content_window)->GetBoundsInScreen(); | 176 wm::GetTransientParent(content_window)->GetBoundsInScreen(); |
| 178 if (transient_parent_bounds.height() >= size.height() && | 177 if (transient_parent_bounds.height() >= size.height() && |
| 179 transient_parent_bounds.width() >= size.width()) { | 178 transient_parent_bounds.width() >= size.width()) { |
| 180 bounds_to_center_in = transient_parent_bounds; | 179 bounds_to_center_in = transient_parent_bounds; |
| 181 } | 180 } |
| 182 } | 181 } |
| 183 | 182 |
| 184 gfx::Rect resulting_bounds(bounds_to_center_in); | 183 gfx::Rect resulting_bounds(bounds_to_center_in); |
| 185 resulting_bounds.ClampToCenteredSize(size); | 184 resulting_bounds.ClampToCenteredSize(size); |
| 186 | 185 SetBounds(gfx::ConvertRectToPixel(GetScaleFactor(), resulting_bounds)); |
| 187 // TODO: handle device scale, http://crbug.com/663524. SetBounds() expects | |
| 188 // pixels. | |
| 189 SetBounds(resulting_bounds); | |
| 190 } | 186 } |
| 191 | 187 |
| 192 void DesktopWindowTreeHostMus::GetWindowPlacement( | 188 void DesktopWindowTreeHostMus::GetWindowPlacement( |
| 193 gfx::Rect* bounds, | 189 gfx::Rect* bounds, |
| 194 ui::WindowShowState* show_state) const { | 190 ui::WindowShowState* show_state) const { |
| 195 // Implementation matches that of NativeWidgetAura. | 191 // Implementation matches that of NativeWidgetAura. |
| 196 *bounds = GetRestoredBounds(); | 192 *bounds = GetRestoredBounds(); |
| 197 *show_state = window()->GetProperty(aura::client::kShowStateKey); | 193 *show_state = window()->GetProperty(aura::client::kShowStateKey); |
| 198 } | 194 } |
| 199 | 195 |
| 200 gfx::Rect DesktopWindowTreeHostMus::GetWindowBoundsInScreen() const { | 196 gfx::Rect DesktopWindowTreeHostMus::GetWindowBoundsInScreen() const { |
| 201 // TODO: convert to dips, http://crbug.com/663524. | 197 return gfx::ConvertRectToDIP(GetScaleFactor(), GetBounds()); |
| 202 return GetBounds(); | |
| 203 } | 198 } |
| 204 | 199 |
| 205 gfx::Rect DesktopWindowTreeHostMus::GetClientAreaBoundsInScreen() const { | 200 gfx::Rect DesktopWindowTreeHostMus::GetClientAreaBoundsInScreen() const { |
| 206 // View-to-screen coordinate system transformations depend on this returning | 201 // View-to-screen coordinate system transformations depend on this returning |
| 207 // the full window bounds, for example View::ConvertPointToScreen(). | 202 // the full window bounds, for example View::ConvertPointToScreen(). |
| 208 return GetWindowBoundsInScreen(); | 203 return GetWindowBoundsInScreen(); |
| 209 } | 204 } |
| 210 | 205 |
| 211 gfx::Rect DesktopWindowTreeHostMus::GetRestoredBounds() const { | 206 gfx::Rect DesktopWindowTreeHostMus::GetRestoredBounds() const { |
| 212 // Restored bounds should only be relevant if the window is minimized, | 207 // Restored bounds should only be relevant if the window is minimized, |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |