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

Side by Side Diff: ash/common/wm/window_state.cc

Issue 2778733004: Add WindowPinType property on arua::Window (Closed)
Patch Set: Address review issues. Created 3 years, 8 months 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 | « ash/common/wm/window_state.h ('k') | ash/common/wm_window.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/common/wm/window_state.h" 5 #include "ash/common/wm/window_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/wm/default_state.h" 9 #include "ash/common/wm/default_state.h"
10 #include "ash/common/wm/window_positioning_utils.h" 10 #include "ash/common/wm/window_positioning_utils.h"
11 #include "ash/common/wm/window_state_delegate.h" 11 #include "ash/common/wm/window_state_delegate.h"
12 #include "ash/common/wm/window_state_observer.h" 12 #include "ash/common/wm/window_state_observer.h"
13 #include "ash/common/wm/wm_event.h" 13 #include "ash/common/wm/wm_event.h"
14 #include "ash/common/wm/wm_screen_util.h" 14 #include "ash/common/wm/wm_screen_util.h"
15 #include "ash/common/wm_window.h" 15 #include "ash/common/wm_window.h"
16 #include "ash/public/cpp/window_properties.h"
17 #include "ash/public/interfaces/window_pin_type.mojom.h"
16 #include "base/auto_reset.h" 18 #include "base/auto_reset.h"
19 #include "ui/aura/window.h"
17 20
18 namespace ash { 21 namespace ash {
19 namespace wm { 22 namespace wm {
20 23
21 namespace { 24 namespace {
22 25
23 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { 26 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) {
24 switch (requested_show_state) { 27 switch (requested_show_state) {
25 case ui::SHOW_STATE_DEFAULT: 28 case ui::SHOW_STATE_DEFAULT:
26 case ui::SHOW_STATE_NORMAL: 29 case ui::SHOW_STATE_NORMAL:
27 return WM_EVENT_NORMAL; 30 return WM_EVENT_NORMAL;
28 case ui::SHOW_STATE_MINIMIZED: 31 case ui::SHOW_STATE_MINIMIZED:
29 return WM_EVENT_MINIMIZE; 32 return WM_EVENT_MINIMIZE;
30 case ui::SHOW_STATE_MAXIMIZED: 33 case ui::SHOW_STATE_MAXIMIZED:
31 return WM_EVENT_MAXIMIZE; 34 return WM_EVENT_MAXIMIZE;
32 case ui::SHOW_STATE_FULLSCREEN: 35 case ui::SHOW_STATE_FULLSCREEN:
33 return WM_EVENT_FULLSCREEN; 36 return WM_EVENT_FULLSCREEN;
34 case ui::SHOW_STATE_INACTIVE: 37 case ui::SHOW_STATE_INACTIVE:
35 return WM_EVENT_SHOW_INACTIVE; 38 return WM_EVENT_SHOW_INACTIVE;
36 39
37 case ui::SHOW_STATE_END: 40 case ui::SHOW_STATE_END:
38 NOTREACHED() << "No WMEvent defined for the show state:" 41 NOTREACHED() << "No WMEvent defined for the show state:"
39 << requested_show_state; 42 << requested_show_state;
40 } 43 }
41 return WM_EVENT_NORMAL; 44 return WM_EVENT_NORMAL;
42 } 45 }
43 46
47 WMEventType WMEventTypeFromWindowPinType(ash::mojom::WindowPinType type) {
48 switch (type) {
49 case ash::mojom::WindowPinType::NONE:
50 return WM_EVENT_NORMAL;
51 case ash::mojom::WindowPinType::PINNED:
52 return WM_EVENT_PIN;
53 case ash::mojom::WindowPinType::TRUSTED_PINNED:
54 return WM_EVENT_TRUSTED_PIN;
55 }
56 NOTREACHED() << "No WMEvent defined for the window pin type:" << type;
57 return WM_EVENT_NORMAL;
58 }
59
44 } // namespace 60 } // namespace
45 61
46 WindowState::~WindowState() {} 62 WindowState::~WindowState() {}
47 63
48 bool WindowState::HasDelegate() const { 64 bool WindowState::HasDelegate() const {
49 return !!delegate_; 65 return !!delegate_;
50 } 66 }
51 67
52 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) { 68 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) {
53 DCHECK(!delegate_.get()); 69 DCHECK(!delegate_.get());
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 ClearRestoreBounds(); 295 ClearRestoreBounds();
280 } 296 }
281 297
282 void WindowState::OnWindowShowStateChanged() { 298 void WindowState::OnWindowShowStateChanged() {
283 if (!ignore_property_change_) { 299 if (!ignore_property_change_) {
284 WMEvent event(WMEventTypeFromShowState(GetShowState())); 300 WMEvent event(WMEventTypeFromShowState(GetShowState()));
285 OnWMEvent(&event); 301 OnWMEvent(&event);
286 } 302 }
287 } 303 }
288 304
305 void WindowState::OnWindowPinTypeChanged() {
306 if (!ignore_property_change_) {
307 WMEvent event(WMEventTypeFromWindowPinType(GetPinType()));
308 OnWMEvent(&event);
309 }
310 }
311
289 WindowState::WindowState(WmWindow* window) 312 WindowState::WindowState(WmWindow* window)
290 : window_(window), 313 : window_(window),
291 window_position_managed_(false), 314 window_position_managed_(false),
292 bounds_changed_by_user_(false), 315 bounds_changed_by_user_(false),
293 ignored_by_shelf_(false), 316 ignored_by_shelf_(false),
294 can_consume_system_keys_(false), 317 can_consume_system_keys_(false),
295 unminimize_to_restore_bounds_(false), 318 unminimize_to_restore_bounds_(false),
296 in_immersive_fullscreen_(false), 319 in_immersive_fullscreen_(false),
297 hide_shelf_when_fullscreen_(true), 320 hide_shelf_when_fullscreen_(true),
298 autohide_shelf_when_maximized_or_fullscreen_(false), 321 autohide_shelf_when_maximized_or_fullscreen_(false),
299 minimum_visibility_(false), 322 minimum_visibility_(false),
300 can_be_dragged_(true), 323 can_be_dragged_(true),
301 cached_always_on_top_(false), 324 cached_always_on_top_(false),
302 ignore_property_change_(false), 325 ignore_property_change_(false),
303 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) {} 326 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) {}
304 327
305 bool WindowState::GetAlwaysOnTop() const { 328 bool WindowState::GetAlwaysOnTop() const {
306 return window_->IsAlwaysOnTop(); 329 return window_->IsAlwaysOnTop();
307 } 330 }
308 331
309 ui::WindowShowState WindowState::GetShowState() const { 332 ui::WindowShowState WindowState::GetShowState() const {
310 return window_->GetShowState(); 333 return window_->GetShowState();
311 } 334 }
312 335
336 ash::mojom::WindowPinType WindowState::GetPinType() const {
337 return window_->aura_window()->GetProperty(kWindowPinTypeKey);
338 }
339
313 void WindowState::SetBoundsInScreen(const gfx::Rect& bounds_in_screen) { 340 void WindowState::SetBoundsInScreen(const gfx::Rect& bounds_in_screen) {
314 gfx::Rect bounds_in_parent = 341 gfx::Rect bounds_in_parent =
315 window_->GetParent()->ConvertRectFromScreen(bounds_in_screen); 342 window_->GetParent()->ConvertRectFromScreen(bounds_in_screen);
316 window_->SetBounds(bounds_in_parent); 343 window_->SetBounds(bounds_in_parent);
317 } 344 }
318 345
319 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) { 346 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) {
320 if (is_dragged() || !IsSnapped()) 347 if (is_dragged() || !IsSnapped())
321 return; 348 return;
322 gfx::Rect maximized_bounds = GetMaximizedWindowBoundsInParent(window_); 349 gfx::Rect maximized_bounds = GetMaximizedWindowBoundsInParent(window_);
323 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED) 350 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED)
324 bounds->set_x(maximized_bounds.x()); 351 bounds->set_x(maximized_bounds.x());
325 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED) 352 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED)
326 bounds->set_x(maximized_bounds.right() - bounds->width()); 353 bounds->set_x(maximized_bounds.right() - bounds->width());
327 bounds->set_y(maximized_bounds.y()); 354 bounds->set_y(maximized_bounds.y());
328 bounds->set_height(maximized_bounds.height()); 355 bounds->set_height(maximized_bounds.height());
329 } 356 }
330 357
331 void WindowState::UpdateWindowShowStateFromStateType() { 358 void WindowState::UpdateWindowPropertiesFromStateType() {
332 ui::WindowShowState new_window_state = 359 ui::WindowShowState new_window_state =
333 ToWindowShowState(current_state_->GetType()); 360 ToWindowShowState(current_state_->GetType());
334 if (new_window_state != GetShowState()) { 361 if (new_window_state != GetShowState()) {
335 base::AutoReset<bool> resetter(&ignore_property_change_, true); 362 base::AutoReset<bool> resetter(&ignore_property_change_, true);
336 window_->SetShowState(new_window_state); 363 window_->SetShowState(new_window_state);
337 } 364 }
365
366 // sync up current window show state with PinType property.
367 ash::mojom::WindowPinType pin_type = ash::mojom::WindowPinType::NONE;
368 if (GetStateType() == WINDOW_STATE_TYPE_PINNED)
369 pin_type = ash::mojom::WindowPinType::PINNED;
370 else if (GetStateType() == WINDOW_STATE_TYPE_TRUSTED_PINNED)
371 pin_type = ash::mojom::WindowPinType::TRUSTED_PINNED;
372 if (pin_type != GetPinType()) {
373 base::AutoReset<bool> resetter(&ignore_property_change_, true);
374 window_->aura_window()->SetProperty(kWindowPinTypeKey, pin_type);
375 }
338 } 376 }
339 377
340 void WindowState::NotifyPreStateTypeChange( 378 void WindowState::NotifyPreStateTypeChange(
341 WindowStateType old_window_state_type) { 379 WindowStateType old_window_state_type) {
342 for (auto& observer : observer_list_) 380 for (auto& observer : observer_list_)
343 observer.OnPreWindowStateTypeChange(this, old_window_state_type); 381 observer.OnPreWindowStateTypeChange(this, old_window_state_type);
344 } 382 }
345 383
346 void WindowState::NotifyPostStateTypeChange( 384 void WindowState::NotifyPostStateTypeChange(
347 WindowStateType old_window_state_type) { 385 WindowStateType old_window_state_type) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (!window_->GetTargetVisibility()) { 422 if (!window_->GetTargetVisibility()) {
385 SetBoundsConstrained(new_bounds); 423 SetBoundsConstrained(new_bounds);
386 return; 424 return;
387 } 425 }
388 426
389 window_->SetBoundsDirectCrossFade(new_bounds); 427 window_->SetBoundsDirectCrossFade(new_bounds);
390 } 428 }
391 429
392 } // namespace wm 430 } // namespace wm
393 } // namespace ash 431 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/window_state.h ('k') | ash/common/wm_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698