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

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

Issue 2490273002: Couple of fixes for DesktopWindowTreeHostMus. (Closed)
Patch Set: feedback 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"
(...skipping 28 matching lines...) Expand all
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
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 if (native_widget_delegate_->CanActivate()) {
119 if (state != ui::SHOW_STATE_INACTIVE)
120 Activate();
121
122 // SetInitialFocus() should be always be called, even for
123 // SHOW_STATE_INACTIVE. If the window has to stay inactive, the method will
124 // do the right thing.
125 // Activate() might fail if the window is non-activatable. In this case, we
126 // should pass SHOW_STATE_INACTIVE to SetInitialFocus() to stop the initial
127 // focused view from getting focused. See crbug.com/515594 for example.
128 native_widget_delegate_->SetInitialFocus(
129 IsActive() ? state : ui::SHOW_STATE_INACTIVE);
130 }
115 } 131 }
116 132
117 void DesktopWindowTreeHostMus::ShowMaximizedWithBounds( 133 void DesktopWindowTreeHostMus::ShowMaximizedWithBounds(
118 const gfx::Rect& restored_bounds) { 134 const gfx::Rect& restored_bounds) {
119 window()->SetProperty(aura::client::kRestoreBoundsKey, 135 window()->SetProperty(aura::client::kRestoreBoundsKey,
120 new gfx::Rect(restored_bounds)); 136 new gfx::Rect(restored_bounds));
121 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); 137 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED);
122 } 138 }
123 139
124 bool DesktopWindowTreeHostMus::IsVisible() const { 140 bool DesktopWindowTreeHostMus::IsVisible() const {
(...skipping 20 matching lines...) Expand all
145 // TODO: implement window stacking, http://crbug.com/663617. 161 // TODO: implement window stacking, http://crbug.com/663617.
146 NOTIMPLEMENTED(); 162 NOTIMPLEMENTED();
147 } 163 }
148 164
149 void DesktopWindowTreeHostMus::StackAtTop() { 165 void DesktopWindowTreeHostMus::StackAtTop() {
150 // TODO: implement window stacking, http://crbug.com/663617. 166 // TODO: implement window stacking, http://crbug.com/663617.
151 NOTIMPLEMENTED(); 167 NOTIMPLEMENTED();
152 } 168 }
153 169
154 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) { 170 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) {
155 NOTIMPLEMENTED(); 171 gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen();
172
173 // 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();
175 if (wm::GetTransientParent(content_window)) {
176 gfx::Rect transient_parent_bounds =
177 wm::GetTransientParent(content_window)->GetBoundsInScreen();
178 if (transient_parent_bounds.height() >= size.height() &&
179 transient_parent_bounds.width() >= size.width()) {
180 bounds_to_center_in = transient_parent_bounds;
181 }
182 }
183
184 gfx::Rect resulting_bounds(bounds_to_center_in);
185 resulting_bounds.ClampToCenteredSize(size);
186
187 // TODO: handle device scale, http://crbug.com/663524. SetBounds() expects
188 // pixels.
189 SetBounds(resulting_bounds);
156 } 190 }
157 191
158 void DesktopWindowTreeHostMus::GetWindowPlacement( 192 void DesktopWindowTreeHostMus::GetWindowPlacement(
159 gfx::Rect* bounds, 193 gfx::Rect* bounds,
160 ui::WindowShowState* show_state) const { 194 ui::WindowShowState* show_state) const {
161 // Implementation matches that of NativeWidgetAura. 195 // Implementation matches that of NativeWidgetAura.
162 *bounds = GetRestoredBounds(); 196 *bounds = GetRestoredBounds();
163 *show_state = window()->GetProperty(aura::client::kShowStateKey); 197 *show_state = window()->GetProperty(aura::client::kShowStateKey);
164 } 198 }
165 199
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return window()->GetProperty(aura::client::kShowStateKey) == 288 return window()->GetProperty(aura::client::kShowStateKey) ==
255 ui::SHOW_STATE_MAXIMIZED; 289 ui::SHOW_STATE_MAXIMIZED;
256 } 290 }
257 291
258 bool DesktopWindowTreeHostMus::IsMinimized() const { 292 bool DesktopWindowTreeHostMus::IsMinimized() const {
259 return window()->GetProperty(aura::client::kShowStateKey) == 293 return window()->GetProperty(aura::client::kShowStateKey) ==
260 ui::SHOW_STATE_MINIMIZED; 294 ui::SHOW_STATE_MINIMIZED;
261 } 295 }
262 296
263 bool DesktopWindowTreeHostMus::HasCapture() const { 297 bool DesktopWindowTreeHostMus::HasCapture() const {
264 return const_cast<aura::Window*>(window())->HasCapture(); 298 // Capture state is held by DesktopNativeWidgetAura::content_window_.
299 // DesktopNativeWidgetAura::HasCapture() calls content_window_->HasCapture(),
300 // and this. That means this function can always return true.
301 return true;
265 } 302 }
266 303
267 void DesktopWindowTreeHostMus::SetAlwaysOnTop(bool always_on_top) { 304 void DesktopWindowTreeHostMus::SetAlwaysOnTop(bool always_on_top) {
268 window()->SetProperty(aura::client::kAlwaysOnTopKey, always_on_top); 305 window()->SetProperty(aura::client::kAlwaysOnTopKey, always_on_top);
269 } 306 }
270 307
271 bool DesktopWindowTreeHostMus::IsAlwaysOnTop() const { 308 bool DesktopWindowTreeHostMus::IsAlwaysOnTop() const {
272 return window()->GetProperty(aura::client::kAlwaysOnTopKey); 309 return window()->GetProperty(aura::client::kAlwaysOnTopKey);
273 } 310 }
274 311
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (window == this->window()) { 452 if (window == this->window()) {
416 is_active_ = true; 453 is_active_ = true;
417 desktop_native_widget_aura_->HandleActivationChanged(true); 454 desktop_native_widget_aura_->HandleActivationChanged(true);
418 } else if (is_active_) { 455 } else if (is_active_) {
419 is_active_ = false; 456 is_active_ = false;
420 desktop_native_widget_aura_->HandleActivationChanged(false); 457 desktop_native_widget_aura_->HandleActivationChanged(false);
421 } 458 }
422 } 459 }
423 460
424 } // namespace views 461 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | ui/views/widget/desktop_aura/desktop_native_widget_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698