Chromium Code Reviews| 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" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 aura::Env::GetInstance()->RemoveObserver(this); | 39 aura::Env::GetInstance()->RemoveObserver(this); |
| 40 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); | 40 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool DesktopWindowTreeHostMus::IsDocked() const { | 43 bool DesktopWindowTreeHostMus::IsDocked() const { |
| 44 return window()->GetProperty(aura::client::kShowStateKey) == | 44 return window()->GetProperty(aura::client::kShowStateKey) == |
| 45 ui::SHOW_STATE_DOCKED; | 45 ui::SHOW_STATE_DOCKED; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void DesktopWindowTreeHostMus::Init(aura::Window* content_window, | 48 void DesktopWindowTreeHostMus::Init(aura::Window* content_window, |
| 49 const Widget::InitParams& params) {} | 49 const Widget::InitParams& params) { |
| 50 // TODO: handle device scale, http://crbug.com/663524. | |
| 51 if (!params.bounds.IsEmpty()) | |
| 52 SetBounds(params.bounds); | |
| 53 } | |
| 50 | 54 |
| 51 void DesktopWindowTreeHostMus::OnNativeWidgetCreated( | 55 void DesktopWindowTreeHostMus::OnNativeWidgetCreated( |
| 52 const Widget::InitParams& params) { | 56 const Widget::InitParams& params) { |
| 53 if (params.parent && params.parent->GetHost()) { | 57 if (params.parent && params.parent->GetHost()) { |
| 54 parent_ = static_cast<DesktopWindowTreeHostMus*>(params.parent->GetHost()); | 58 parent_ = static_cast<DesktopWindowTreeHostMus*>(params.parent->GetHost()); |
| 55 parent_->children_.insert(this); | 59 parent_->children_.insert(this); |
| 56 } | 60 } |
| 57 native_widget_delegate_->OnNativeWidgetCreated(true); | 61 native_widget_delegate_->OnNativeWidgetCreated(true); |
| 58 } | 62 } |
| 59 | 63 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 } | 107 } |
| 104 | 108 |
| 105 void DesktopWindowTreeHostMus::ShowWindowWithState(ui::WindowShowState state) { | 109 void DesktopWindowTreeHostMus::ShowWindowWithState(ui::WindowShowState state) { |
| 106 if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN || | 110 if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN || |
| 107 state == ui::SHOW_STATE_DOCKED) { | 111 state == ui::SHOW_STATE_DOCKED) { |
| 108 window()->SetProperty(aura::client::kShowStateKey, state); | 112 window()->SetProperty(aura::client::kShowStateKey, state); |
| 109 } | 113 } |
| 110 window()->Show(); | 114 window()->Show(); |
| 111 if (compositor()) | 115 if (compositor()) |
| 112 compositor()->SetVisible(true); | 116 compositor()->SetVisible(true); |
| 113 // TODO: likely needs code to activate, but after content_window_ is shown. | 117 |
| 114 // See NativeWidgetAura::ShowWithWindowState(). | 118 native_widget_delegate_->AsWidget()->SetInitialFocus(state); |
|
msw
2016/11/10 18:27:45
q: Should this check if native_widget_delgate_->Ca
sky
2016/11/10 20:18:11
I'm not exactly sure. That doesn't exist in the de
| |
| 115 } | 119 } |
| 116 | 120 |
| 117 void DesktopWindowTreeHostMus::ShowMaximizedWithBounds( | 121 void DesktopWindowTreeHostMus::ShowMaximizedWithBounds( |
| 118 const gfx::Rect& restored_bounds) { | 122 const gfx::Rect& restored_bounds) { |
| 119 window()->SetProperty(aura::client::kRestoreBoundsKey, | 123 window()->SetProperty(aura::client::kRestoreBoundsKey, |
| 120 new gfx::Rect(restored_bounds)); | 124 new gfx::Rect(restored_bounds)); |
| 121 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); | 125 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); |
| 122 } | 126 } |
| 123 | 127 |
| 124 bool DesktopWindowTreeHostMus::IsVisible() const { | 128 bool DesktopWindowTreeHostMus::IsVisible() const { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 145 // TODO: implement window stacking, http://crbug.com/663617. | 149 // TODO: implement window stacking, http://crbug.com/663617. |
| 146 NOTIMPLEMENTED(); | 150 NOTIMPLEMENTED(); |
| 147 } | 151 } |
| 148 | 152 |
| 149 void DesktopWindowTreeHostMus::StackAtTop() { | 153 void DesktopWindowTreeHostMus::StackAtTop() { |
| 150 // TODO: implement window stacking, http://crbug.com/663617. | 154 // TODO: implement window stacking, http://crbug.com/663617. |
| 151 NOTIMPLEMENTED(); | 155 NOTIMPLEMENTED(); |
| 152 } | 156 } |
| 153 | 157 |
| 154 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) { | 158 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) { |
| 155 NOTIMPLEMENTED(); | 159 gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen(); |
| 160 | |
| 161 // If there is a transient parent and it fits |size|, then center over it. | |
| 162 aura::Window* content_window = desktop_native_widget_aura_->content_window(); | |
| 163 if (wm::GetTransientParent(content_window)) { | |
| 164 gfx::Rect transient_parent_bounds = | |
| 165 wm::GetTransientParent(content_window)->GetBoundsInScreen(); | |
| 166 if (transient_parent_bounds.height() >= size.height() && | |
| 167 transient_parent_bounds.width() >= size.width()) { | |
| 168 bounds_to_center_in = transient_parent_bounds; | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 gfx::Rect resulting_bounds( | |
|
msw
2016/11/10 18:27:45
Use gfx::Rect::ClampToCenteredSize, then skip Adju
sky
2016/11/10 20:18:11
Good call! Done.
| |
| 173 bounds_to_center_in.x() + | |
| 174 (bounds_to_center_in.width() - size.width()) / 2, | |
| 175 bounds_to_center_in.y() + | |
| 176 (bounds_to_center_in.height() - size.height()) / 2, | |
| 177 size.width(), size.height()); | |
| 178 | |
| 179 // Don't size the window bigger than the parent, otherwise the user may not be | |
| 180 // able to close or move it. | |
| 181 resulting_bounds.AdjustToFit(bounds_to_center_in); | |
| 182 | |
| 183 // TODO: handle device scale, http://crbug.com/663524. SetBounds() expects | |
| 184 // pixels. | |
| 185 SetBounds(resulting_bounds); | |
| 156 } | 186 } |
| 157 | 187 |
| 158 void DesktopWindowTreeHostMus::GetWindowPlacement( | 188 void DesktopWindowTreeHostMus::GetWindowPlacement( |
| 159 gfx::Rect* bounds, | 189 gfx::Rect* bounds, |
| 160 ui::WindowShowState* show_state) const { | 190 ui::WindowShowState* show_state) const { |
| 161 // Implementation matches that of NativeWidgetAura. | 191 // Implementation matches that of NativeWidgetAura. |
| 162 *bounds = GetRestoredBounds(); | 192 *bounds = GetRestoredBounds(); |
| 163 *show_state = window()->GetProperty(aura::client::kShowStateKey); | 193 *show_state = window()->GetProperty(aura::client::kShowStateKey); |
| 164 } | 194 } |
| 165 | 195 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 return window()->GetProperty(aura::client::kShowStateKey) == | 284 return window()->GetProperty(aura::client::kShowStateKey) == |
| 255 ui::SHOW_STATE_MAXIMIZED; | 285 ui::SHOW_STATE_MAXIMIZED; |
| 256 } | 286 } |
| 257 | 287 |
| 258 bool DesktopWindowTreeHostMus::IsMinimized() const { | 288 bool DesktopWindowTreeHostMus::IsMinimized() const { |
| 259 return window()->GetProperty(aura::client::kShowStateKey) == | 289 return window()->GetProperty(aura::client::kShowStateKey) == |
| 260 ui::SHOW_STATE_MINIMIZED; | 290 ui::SHOW_STATE_MINIMIZED; |
| 261 } | 291 } |
| 262 | 292 |
| 263 bool DesktopWindowTreeHostMus::HasCapture() const { | 293 bool DesktopWindowTreeHostMus::HasCapture() const { |
| 264 return const_cast<aura::Window*>(window())->HasCapture(); | 294 // Capture state is held by DesktopNativeWidgetAura::content_window_. |
| 295 // DesktopNativeWidgetAura::HasCapture() calls content_window_->HasCapture(), | |
| 296 // and this. That means this function can always return true. | |
| 297 return true; | |
| 265 } | 298 } |
| 266 | 299 |
| 267 void DesktopWindowTreeHostMus::SetAlwaysOnTop(bool always_on_top) { | 300 void DesktopWindowTreeHostMus::SetAlwaysOnTop(bool always_on_top) { |
| 268 window()->SetProperty(aura::client::kAlwaysOnTopKey, always_on_top); | 301 window()->SetProperty(aura::client::kAlwaysOnTopKey, always_on_top); |
| 269 } | 302 } |
| 270 | 303 |
| 271 bool DesktopWindowTreeHostMus::IsAlwaysOnTop() const { | 304 bool DesktopWindowTreeHostMus::IsAlwaysOnTop() const { |
| 272 return window()->GetProperty(aura::client::kAlwaysOnTopKey); | 305 return window()->GetProperty(aura::client::kAlwaysOnTopKey); |
| 273 } | 306 } |
| 274 | 307 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 if (window == this->window()) { | 448 if (window == this->window()) { |
| 416 is_active_ = true; | 449 is_active_ = true; |
| 417 desktop_native_widget_aura_->HandleActivationChanged(true); | 450 desktop_native_widget_aura_->HandleActivationChanged(true); |
| 418 } else if (is_active_) { | 451 } else if (is_active_) { |
| 419 is_active_ = false; | 452 is_active_ = false; |
| 420 desktop_native_widget_aura_->HandleActivationChanged(false); | 453 desktop_native_widget_aura_->HandleActivationChanged(false); |
| 421 } | 454 } |
| 422 } | 455 } |
| 423 | 456 |
| 424 } // namespace views | 457 } // namespace views |
| OLD | NEW |