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

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
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"
16 #include "base/auto_reset.h" 17 #include "base/auto_reset.h"
17 18
18 namespace ash { 19 namespace ash {
19 namespace wm { 20 namespace wm {
20 21
21 namespace { 22 namespace {
22 23
23 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { 24 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) {
24 switch (requested_show_state) { 25 switch (requested_show_state) {
25 case ui::SHOW_STATE_DEFAULT: 26 case ui::SHOW_STATE_DEFAULT:
26 case ui::SHOW_STATE_NORMAL: 27 case ui::SHOW_STATE_NORMAL:
27 return WM_EVENT_NORMAL; 28 return WM_EVENT_NORMAL;
28 case ui::SHOW_STATE_MINIMIZED: 29 case ui::SHOW_STATE_MINIMIZED:
29 return WM_EVENT_MINIMIZE; 30 return WM_EVENT_MINIMIZE;
30 case ui::SHOW_STATE_MAXIMIZED: 31 case ui::SHOW_STATE_MAXIMIZED:
31 return WM_EVENT_MAXIMIZE; 32 return WM_EVENT_MAXIMIZE;
32 case ui::SHOW_STATE_FULLSCREEN: 33 case ui::SHOW_STATE_FULLSCREEN:
33 return WM_EVENT_FULLSCREEN; 34 return WM_EVENT_FULLSCREEN;
34 case ui::SHOW_STATE_INACTIVE: 35 case ui::SHOW_STATE_INACTIVE:
35 return WM_EVENT_SHOW_INACTIVE; 36 return WM_EVENT_SHOW_INACTIVE;
36 37
37 case ui::SHOW_STATE_END: 38 case ui::SHOW_STATE_END:
38 NOTREACHED() << "No WMEvent defined for the show state:" 39 NOTREACHED() << "No WMEvent defined for the show state:"
39 << requested_show_state; 40 << requested_show_state;
40 } 41 }
41 return WM_EVENT_NORMAL; 42 return WM_EVENT_NORMAL;
42 } 43 }
43 44
45 WMEventType WMEventTypeFromWindowPinType(WindowPinType type) {
46 switch (type) {
47 case WindowPinType::NONE:
48 return WM_EVENT_NORMAL;
49 case WindowPinType::PINNED:
50 return WM_EVENT_PIN;
51 case WindowPinType::TRUSTED_PINNED:
52 return WM_EVENT_TRUSTED_PIN;
53 }
54 return WM_EVENT_NORMAL;
55 }
56
44 } // namespace 57 } // namespace
45 58
46 WindowState::~WindowState() {} 59 WindowState::~WindowState() {}
47 60
48 bool WindowState::HasDelegate() const { 61 bool WindowState::HasDelegate() const {
49 return !!delegate_; 62 return !!delegate_;
50 } 63 }
51 64
52 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) { 65 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) {
53 DCHECK(!delegate_.get()); 66 DCHECK(!delegate_.get());
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 ClearRestoreBounds(); 292 ClearRestoreBounds();
280 } 293 }
281 294
282 void WindowState::OnWindowShowStateChanged() { 295 void WindowState::OnWindowShowStateChanged() {
283 if (!ignore_property_change_) { 296 if (!ignore_property_change_) {
284 WMEvent event(WMEventTypeFromShowState(GetShowState())); 297 WMEvent event(WMEventTypeFromShowState(GetShowState()));
285 OnWMEvent(&event); 298 OnWMEvent(&event);
286 } 299 }
287 } 300 }
288 301
302 void WindowState::OnWindowPinTypeChanged() {
303 if (!ignore_property_change_) {
304 WMEvent event(WMEventTypeFromWindowPinType(window_->GetPinType()));
305 OnWMEvent(&event);
306 }
307 }
308
289 WindowState::WindowState(WmWindow* window) 309 WindowState::WindowState(WmWindow* window)
290 : window_(window), 310 : window_(window),
291 window_position_managed_(false), 311 window_position_managed_(false),
292 bounds_changed_by_user_(false), 312 bounds_changed_by_user_(false),
293 ignored_by_shelf_(false), 313 ignored_by_shelf_(false),
294 can_consume_system_keys_(false), 314 can_consume_system_keys_(false),
295 unminimize_to_restore_bounds_(false), 315 unminimize_to_restore_bounds_(false),
296 in_immersive_fullscreen_(false), 316 in_immersive_fullscreen_(false),
297 hide_shelf_when_fullscreen_(true), 317 hide_shelf_when_fullscreen_(true),
298 autohide_shelf_when_maximized_or_fullscreen_(false), 318 autohide_shelf_when_maximized_or_fullscreen_(false),
(...skipping 22 matching lines...) Expand all
321 return; 341 return;
322 gfx::Rect maximized_bounds = GetMaximizedWindowBoundsInParent(window_); 342 gfx::Rect maximized_bounds = GetMaximizedWindowBoundsInParent(window_);
323 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED) 343 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED)
324 bounds->set_x(maximized_bounds.x()); 344 bounds->set_x(maximized_bounds.x());
325 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED) 345 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED)
326 bounds->set_x(maximized_bounds.right() - bounds->width()); 346 bounds->set_x(maximized_bounds.right() - bounds->width());
327 bounds->set_y(maximized_bounds.y()); 347 bounds->set_y(maximized_bounds.y());
328 bounds->set_height(maximized_bounds.height()); 348 bounds->set_height(maximized_bounds.height());
329 } 349 }
330 350
331 void WindowState::UpdateWindowShowStateFromStateType() { 351 void WindowState::UpdateWindowPropertiesFromStateType() {
332 ui::WindowShowState new_window_state = 352 ui::WindowShowState new_window_state =
333 ToWindowShowState(current_state_->GetType()); 353 ToWindowShowState(current_state_->GetType());
334 if (new_window_state != GetShowState()) { 354 if (new_window_state != GetShowState()) {
335 base::AutoReset<bool> resetter(&ignore_property_change_, true); 355 base::AutoReset<bool> resetter(&ignore_property_change_, true);
336 window_->SetShowState(new_window_state); 356 window_->SetShowState(new_window_state);
337 } 357 }
358
359 // sync up current window show state with PinType property.
360 WindowPinType pin_type = WindowPinType::NONE;
361 if (GetStateType() == WINDOW_STATE_TYPE_PINNED)
362 pin_type = WindowPinType::PINNED;
363 else if (GetStateType() == WINDOW_STATE_TYPE_TRUSTED_PINNED)
364 pin_type = WindowPinType::TRUSTED_PINNED;
365 if (pin_type != window_->GetPinType()) {
366 base::AutoReset<bool> resetter(&ignore_property_change_, true);
367 window_->SetPinType(pin_type);
368 }
338 } 369 }
339 370
340 void WindowState::NotifyPreStateTypeChange( 371 void WindowState::NotifyPreStateTypeChange(
341 WindowStateType old_window_state_type) { 372 WindowStateType old_window_state_type) {
342 for (auto& observer : observer_list_) 373 for (auto& observer : observer_list_)
343 observer.OnPreWindowStateTypeChange(this, old_window_state_type); 374 observer.OnPreWindowStateTypeChange(this, old_window_state_type);
344 } 375 }
345 376
346 void WindowState::NotifyPostStateTypeChange( 377 void WindowState::NotifyPostStateTypeChange(
347 WindowStateType old_window_state_type) { 378 WindowStateType old_window_state_type) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (!window_->GetTargetVisibility()) { 415 if (!window_->GetTargetVisibility()) {
385 SetBoundsConstrained(new_bounds); 416 SetBoundsConstrained(new_bounds);
386 return; 417 return;
387 } 418 }
388 419
389 window_->SetBoundsDirectCrossFade(new_bounds); 420 window_->SetBoundsDirectCrossFade(new_bounds);
390 } 421 }
391 422
392 } // namespace wm 423 } // namespace wm
393 } // namespace ash 424 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/window_state.h ('k') | ash/common/wm_window.h » ('j') | ash/common/wm_window.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698