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

Side by Side Diff: ash/wm/lock_window_state.cc

Issue 2901663003: chromeos: converts WindowState to aura::Window (Closed)
Patch Set: feedback Created 3 years, 7 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/wm/lock_window_state.h ('k') | ash/wm/maximize_mode/maximize_mode_window_state.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/wm/lock_window_state.h" 5 #include "ash/wm/lock_window_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/screen_util.h" 9 #include "ash/screen_util.h"
10 #include "ash/wm/lock_layout_manager.h" 10 #include "ash/wm/lock_layout_manager.h"
11 #include "ash/wm/window_animation_types.h" 11 #include "ash/wm/window_animation_types.h"
12 #include "ash/wm/window_state.h" 12 #include "ash/wm/window_state.h"
13 #include "ash/wm/window_state_delegate.h" 13 #include "ash/wm/window_state_delegate.h"
14 #include "ash/wm/window_state_util.h" 14 #include "ash/wm/window_state_util.h"
15 #include "ash/wm/wm_event.h" 15 #include "ash/wm/wm_event.h"
16 #include "ash/wm_window.h"
17 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "ui/aura/window.h"
18 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/keyboard/keyboard_controller.h" 19 #include "ui/keyboard/keyboard_controller.h"
20 #include "ui/keyboard/keyboard_util.h" 20 #include "ui/keyboard/keyboard_util.h"
21 21
22 namespace ash { 22 namespace ash {
23 23
24 LockWindowState::LockWindowState(WmWindow* window) 24 LockWindowState::LockWindowState(aura::Window* window)
25 : current_state_type_(window->GetWindowState()->GetStateType()) {} 25 : current_state_type_(wm::GetWindowState(window)->GetStateType()) {}
26 26
27 LockWindowState::~LockWindowState() {} 27 LockWindowState::~LockWindowState() {}
28 28
29 void LockWindowState::OnWMEvent(wm::WindowState* window_state, 29 void LockWindowState::OnWMEvent(wm::WindowState* window_state,
30 const wm::WMEvent* event) { 30 const wm::WMEvent* event) {
31 switch (event->type()) { 31 switch (event->type()) {
32 case wm::WM_EVENT_TOGGLE_FULLSCREEN: 32 case wm::WM_EVENT_TOGGLE_FULLSCREEN:
33 ToggleFullScreen(window_state, window_state->delegate()); 33 ToggleFullScreen(window_state, window_state->delegate());
34 break; 34 break;
35 case wm::WM_EVENT_FULLSCREEN: 35 case wm::WM_EVENT_FULLSCREEN:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && 96 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
97 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && 97 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
98 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { 98 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
99 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state)); 99 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state));
100 } 100 }
101 } 101 }
102 102
103 void LockWindowState::DetachState(wm::WindowState* window_state) {} 103 void LockWindowState::DetachState(wm::WindowState* window_state) {}
104 104
105 // static 105 // static
106 wm::WindowState* LockWindowState::SetLockWindowState(WmWindow* window) { 106 wm::WindowState* LockWindowState::SetLockWindowState(aura::Window* window) {
107 std::unique_ptr<wm::WindowState::State> lock_state = 107 std::unique_ptr<wm::WindowState::State> lock_state =
108 base::MakeUnique<LockWindowState>(window); 108 base::MakeUnique<LockWindowState>(window);
109 wm::WindowState* window_state = wm::GetWindowState(window);
109 std::unique_ptr<wm::WindowState::State> old_state( 110 std::unique_ptr<wm::WindowState::State> old_state(
110 window->GetWindowState()->SetStateObject(std::move(lock_state))); 111 window_state->SetStateObject(std::move(lock_state)));
111 return window->GetWindowState(); 112 return window_state;
112 } 113 }
113 114
114 void LockWindowState::UpdateWindow(wm::WindowState* window_state, 115 void LockWindowState::UpdateWindow(wm::WindowState* window_state,
115 wm::WindowStateType target_state) { 116 wm::WindowStateType target_state) {
116 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || 117 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED ||
117 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || 118 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED ||
118 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && 119 (target_state == wm::WINDOW_STATE_TYPE_NORMAL &&
119 !window_state->CanMaximize()) || 120 !window_state->CanMaximize()) ||
120 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); 121 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN);
121 122
122 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { 123 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) {
123 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED) 124 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED)
124 return; 125 return;
125 126
126 current_state_type_ = target_state; 127 current_state_type_ = target_state;
127 window_state->window()->SetVisibilityAnimationType( 128 ::wm::SetWindowVisibilityAnimationType(
128 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); 129 window_state->window(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
129 window_state->window()->Hide(); 130 window_state->window()->Hide();
130 if (window_state->IsActive()) 131 if (window_state->IsActive())
131 window_state->Deactivate(); 132 window_state->Deactivate();
132 return; 133 return;
133 } 134 }
134 135
135 if (current_state_type_ == target_state) { 136 if (current_state_type_ == target_state) {
136 // If the state type did not change, update it accordingly. 137 // If the state type did not change, update it accordingly.
137 UpdateBounds(window_state); 138 UpdateBounds(window_state);
138 return; 139 return;
139 } 140 }
140 141
141 const wm::WindowStateType old_state_type = current_state_type_; 142 const wm::WindowStateType old_state_type = current_state_type_;
142 current_state_type_ = target_state; 143 current_state_type_ = target_state;
143 window_state->UpdateWindowPropertiesFromStateType(); 144 window_state->UpdateWindowPropertiesFromStateType();
144 window_state->NotifyPreStateTypeChange(old_state_type); 145 window_state->NotifyPreStateTypeChange(old_state_type);
145 UpdateBounds(window_state); 146 UpdateBounds(window_state);
146 window_state->NotifyPostStateTypeChange(old_state_type); 147 window_state->NotifyPostStateTypeChange(old_state_type);
147 148
148 if ((window_state->window()->GetTargetVisibility() || 149 if ((window_state->window()->TargetVisibility() ||
149 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && 150 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) &&
150 !window_state->window()->GetLayer()->visible()) { 151 !window_state->window()->layer()->visible()) {
151 // The layer may be hidden if the window was previously minimized. Make 152 // The layer may be hidden if the window was previously minimized. Make
152 // sure it's visible. 153 // sure it's visible.
153 window_state->window()->Show(); 154 window_state->window()->Show();
154 } 155 }
155 } 156 }
156 157
157 wm::WindowStateType LockWindowState::GetMaximizedOrCenteredWindowType( 158 wm::WindowStateType LockWindowState::GetMaximizedOrCenteredWindowType(
158 wm::WindowState* window_state) { 159 wm::WindowState* window_state) {
159 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED 160 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED
160 : wm::WINDOW_STATE_TYPE_NORMAL; 161 : wm::WINDOW_STATE_TYPE_NORMAL;
161 } 162 }
162 163
163 void LockWindowState::UpdateBounds(wm::WindowState* window_state) { 164 void LockWindowState::UpdateBounds(wm::WindowState* window_state) {
164 if (!window_state->IsMaximized() && !window_state->IsFullscreen()) 165 if (!window_state->IsMaximized() && !window_state->IsFullscreen())
165 return; 166 return;
166 167
167 keyboard::KeyboardController* keyboard_controller = 168 keyboard::KeyboardController* keyboard_controller =
168 keyboard::KeyboardController::GetInstance(); 169 keyboard::KeyboardController::GetInstance();
169 gfx::Rect keyboard_bounds; 170 gfx::Rect keyboard_bounds;
170 171
171 if (keyboard_controller && !keyboard::IsKeyboardOverscrollEnabled() && 172 if (keyboard_controller && !keyboard::IsKeyboardOverscrollEnabled() &&
172 keyboard_controller->keyboard_visible()) { 173 keyboard_controller->keyboard_visible()) {
173 keyboard_bounds = keyboard_controller->current_keyboard_bounds(); 174 keyboard_bounds = keyboard_controller->current_keyboard_bounds();
174 } 175 }
175 gfx::Rect bounds = ScreenUtil::GetDisplayBoundsWithShelf( 176 gfx::Rect bounds =
176 window_state->window()->aura_window()); 177 ScreenUtil::GetDisplayBoundsWithShelf(window_state->window());
177 bounds.set_height(bounds.height() - keyboard_bounds.height()); 178 bounds.set_height(bounds.height() - keyboard_bounds.height());
178 179
179 VLOG(1) << "Updating window bounds to: " << bounds.ToString(); 180 VLOG(1) << "Updating window bounds to: " << bounds.ToString();
180 window_state->SetBoundsDirect(bounds); 181 window_state->SetBoundsDirect(bounds);
181 } 182 }
182 183
183 } // namespace ash 184 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/lock_window_state.h ('k') | ash/wm/maximize_mode/maximize_mode_window_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698