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

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

Issue 24108003: [Cleanup] Rename WindowSettings to WindowState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase fix Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/window_state.h ('k') | ash/wm/window_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/window_state.h"
6
7 #include "ash/root_window_controller.h"
8 #include "ash/screen_ash.h"
9 #include "ash/shell_window_ids.h"
10 #include "ash/wm/window_properties.h"
11 #include "ash/wm/window_util.h"
12 #include "ui/aura/client/aura_constants.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_delegate.h"
15 #include "ui/gfx/display.h"
16 #include "ui/views/corewm/window_util.h"
17
18 namespace ash {
19 namespace wm {
20
21 // static
22 bool WindowState::IsMaximizedOrFullscreenState(ui::WindowShowState show_state) {
23 return show_state == ui::SHOW_STATE_FULLSCREEN ||
24 show_state == ui::SHOW_STATE_MAXIMIZED;
25 }
26
27 WindowState::WindowState(aura::Window* window)
28 : window_(window),
29 tracked_by_workspace_(true),
30 window_position_managed_(false),
31 bounds_changed_by_user_(false),
32 panel_attached_(true),
33 continue_drag_after_reparent_(false),
34 ignored_by_shelf_(false),
35 always_restores_to_restore_bounds_(false) {
36 }
37
38 WindowState::~WindowState() {
39 }
40
41 ui::WindowShowState WindowState::GetShowState() const {
42 return window_->GetProperty(aura::client::kShowStateKey);
43 }
44
45 bool WindowState::IsMinimized() const {
46 return GetShowState() == ui::SHOW_STATE_MINIMIZED;
47 }
48
49 bool WindowState::IsMaximized() const {
50 return GetShowState() == ui::SHOW_STATE_MAXIMIZED;
51 }
52
53 bool WindowState::IsFullscreen() const {
54 return GetShowState() == ui::SHOW_STATE_FULLSCREEN;
55 }
56
57 bool WindowState::IsMaximizedOrFullscreen() const {
58 return IsMaximizedOrFullscreenState(GetShowState());
59 }
60
61 bool WindowState::IsNormalShowState() const {
62 ui::WindowShowState state = window_->GetProperty(aura::client::kShowStateKey);
63 return state == ui::SHOW_STATE_NORMAL || state == ui::SHOW_STATE_DEFAULT;
64 }
65
66 bool WindowState::IsActive() const {
67 return IsActiveWindow(window_);
68 }
69
70 bool WindowState::CanMaximize() const {
71 return window_->GetProperty(aura::client::kCanMaximizeKey);
72 }
73
74 bool WindowState::CanMinimize() const {
75 internal::RootWindowController* controller =
76 internal::RootWindowController::ForWindow(window_);
77 if (!controller)
78 return false;
79 aura::Window* lockscreen = controller->GetContainer(
80 internal::kShellWindowId_LockScreenContainersContainer);
81 if (lockscreen->Contains(window_))
82 return false;
83
84 return true;
85 }
86
87 bool WindowState::CanResize() const {
88 return window_->GetProperty(aura::client::kCanResizeKey);
89 }
90
91 bool WindowState::CanActivate() const {
92 return views::corewm::CanActivateWindow(window_);
93 }
94
95 bool WindowState::CanSnap() const {
96 if (!CanResize())
97 return false;
98 if (window_->type() == aura::client::WINDOW_TYPE_PANEL)
99 return false;
100 // If a window has a maximum size defined, snapping may make it too big.
101 return window_->delegate() ? window_->delegate()->GetMaximumSize().IsEmpty() :
102 true;
103 }
104
105 bool WindowState::HasRestoreBounds() const {
106 return window_->GetProperty(aura::client::kRestoreBoundsKey) != NULL;
107 }
108
109 void WindowState::Maximize() {
110 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
111 }
112
113 void WindowState::Minimize() {
114 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
115 }
116
117 void WindowState::Unminimize() {
118 window_->SetProperty(
119 aura::client::kShowStateKey,
120 window_->GetProperty(aura::client::kRestoreShowStateKey));
121 window_->ClearProperty(aura::client::kRestoreShowStateKey);
122 }
123
124 void WindowState::Activate() {
125 ActivateWindow(window_);
126 }
127
128 void WindowState::Deactivate() {
129 DeactivateWindow(window_);
130 }
131
132 void WindowState::Restore() {
133 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
134 }
135
136 void WindowState::ToggleMaximized() {
137 if (IsMaximized())
138 Restore();
139 else if (CanMaximize())
140 Maximize();
141 }
142
143 void WindowState::SetBoundsInScreen(
144 const gfx::Rect& bounds_in_screen) {
145 gfx::Rect bounds_in_parent =
146 ScreenAsh::ConvertRectFromScreen(window_->parent(),
147 bounds_in_screen);
148 window_->SetBounds(bounds_in_parent);
149 }
150
151 void WindowState::SaveCurrentBoundsForRestore() {
152 gfx::Rect bounds_in_screen =
153 ScreenAsh::ConvertRectToScreen(window_->parent(),
154 window_->bounds());
155 SetRestoreBoundsInScreen(bounds_in_screen);
156 }
157
158 gfx::Rect WindowState::GetRestoreBoundsInScreen() const {
159 return *window_->GetProperty(aura::client::kRestoreBoundsKey);
160 }
161
162 gfx::Rect WindowState::GetRestoreBoundsInParent() const {
163 return ScreenAsh::ConvertRectFromScreen(window_->parent(),
164 GetRestoreBoundsInScreen());
165 }
166
167 void WindowState::SetRestoreBoundsInScreen(const gfx::Rect& bounds) {
168 window_->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds));
169 }
170
171 void WindowState::SetRestoreBoundsInParent(const gfx::Rect& bounds) {
172 SetRestoreBoundsInScreen(
173 ScreenAsh::ConvertRectToScreen(window_->parent(), bounds));
174 }
175
176 void WindowState::ClearRestoreBounds() {
177 window_->ClearProperty(aura::client::kRestoreBoundsKey);
178 }
179
180 void WindowState::SetPreAutoManageWindowBounds(
181 const gfx::Rect& bounds) {
182 pre_auto_manage_window_bounds_.reset(new gfx::Rect(bounds));
183 }
184
185 void WindowState::AddObserver(Observer* observer) {
186 observer_list_.AddObserver(observer);
187 }
188
189 void WindowState::RemoveObserver(Observer* observer) {
190 observer_list_.RemoveObserver(observer);
191 }
192
193 void WindowState::SetTrackedByWorkspace(bool tracked_by_workspace) {
194 if (tracked_by_workspace_ == tracked_by_workspace)
195 return;
196 bool old = tracked_by_workspace_;
197 tracked_by_workspace_ = tracked_by_workspace;
198 FOR_EACH_OBSERVER(Observer, observer_list_,
199 OnTrackedByWorkspaceChanged(window_, old));
200 }
201
202 WindowState* GetActiveWindowState() {
203 aura::Window* active = GetActiveWindow();
204 return active ? GetWindowState(active) : NULL;
205 }
206
207 WindowState* GetWindowState(aura::Window* window) {
208 if (!window)
209 return NULL;
210 WindowState* settings = window->GetProperty(internal::kWindowStateKey);
211 if(!settings) {
212 settings = new WindowState(window);
213 window->SetProperty(internal::kWindowStateKey, settings);
214 }
215 return settings;
216 }
217
218 const WindowState* GetWindowState(const aura::Window* window) {
219 return GetWindowState(const_cast<aura::Window*>(window));
220 }
221
222 } // namespace wm
223 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_state.h ('k') | ash/wm/window_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698