OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/workspace/frame_maximize_button.h" | 5 #include "ash/wm/workspace/frame_maximize_button.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/property_util.h" | 10 #include "ash/wm/property_util.h" |
| 11 #include "ash/wm/window_maximize.h" |
11 #include "ash/wm/workspace/phantom_window_controller.h" | 12 #include "ash/wm/workspace/phantom_window_controller.h" |
12 #include "ash/wm/workspace/snap_sizer.h" | 13 #include "ash/wm/workspace/snap_sizer.h" |
13 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
14 #include "grit/ui_resources.h" | 15 #include "grit/ui_resources.h" |
15 #include "ui/aura/event.h" | 16 #include "ui/aura/event.h" |
16 #include "ui/aura/event_filter.h" | 17 #include "ui/aura/event_filter.h" |
17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 99 } |
99 | 100 |
100 // FrameMaximizeButton --------------------------------------------------------- | 101 // FrameMaximizeButton --------------------------------------------------------- |
101 | 102 |
102 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, | 103 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, |
103 views::NonClientFrameView* frame) | 104 views::NonClientFrameView* frame) |
104 : ImageButton(listener), | 105 : ImageButton(listener), |
105 frame_(frame), | 106 frame_(frame), |
106 is_snap_enabled_(false), | 107 is_snap_enabled_(false), |
107 exceeded_drag_threshold_(false), | 108 exceeded_drag_threshold_(false), |
108 snap_type_(SNAP_NONE) { | 109 snap_type_(SNAP_NONE), |
| 110 maximizer_(NULL) { |
109 // TODO(sky): nuke this. It's temporary while we don't have good images. | 111 // TODO(sky): nuke this. It's temporary while we don't have good images. |
110 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); | 112 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); |
111 SetTooltipText(l10n_util::GetStringUTF16(IDS_FRAME_MAXIMIZE_BUTTON_TOOLTIP)); | |
112 } | 113 } |
113 | 114 |
114 FrameMaximizeButton::~FrameMaximizeButton() { | 115 FrameMaximizeButton::~FrameMaximizeButton() { |
115 } | 116 } |
116 | 117 |
117 bool FrameMaximizeButton::OnMousePressed(const views::MouseEvent& event) { | 118 bool FrameMaximizeButton::OnMousePressed(const views::MouseEvent& event) { |
118 is_snap_enabled_ = event.IsLeftMouseButton(); | 119 is_snap_enabled_ = event.IsLeftMouseButton(); |
119 if (is_snap_enabled_) | 120 if (is_snap_enabled_) |
120 ProcessStartEvent(event); | 121 ProcessStartEvent(event); |
121 ImageButton::OnMousePressed(event); | 122 ImageButton::OnMousePressed(event); |
122 return true; | 123 return true; |
123 } | 124 } |
124 | 125 |
125 void FrameMaximizeButton::OnMouseEntered(const views::MouseEvent& event) { | 126 void FrameMaximizeButton::OnMouseEntered(const views::MouseEvent& event) { |
126 ImageButton::OnMouseEntered(event); | 127 ImageButton::OnMouseEntered(event); |
| 128 if (!maximizer_.get()) |
| 129 maximizer_.reset(new MaximizeBubble(this, |
| 130 frame_->GetWidget()->IsMaximized())); |
127 } | 131 } |
128 | 132 |
129 void FrameMaximizeButton::OnMouseExited(const views::MouseEvent& event) { | 133 void FrameMaximizeButton::OnMouseExited(const views::MouseEvent& event) { |
130 ImageButton::OnMouseExited(event); | 134 ImageButton::OnMouseExited(event); |
| 135 // Remove the bubble menu when the button is not pressed and the mouse is not |
| 136 // within the bubble. |
| 137 if (!is_snap_enabled_ && maximizer_.get() && maximizer_->GetMenuWindow()) { |
| 138 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); |
| 139 if (!maximizer_->GetMenuWindow()->bounds().Contains(screen_location)) |
| 140 maximizer_.reset(NULL); |
| 141 } |
131 } | 142 } |
132 | 143 |
133 bool FrameMaximizeButton::OnMouseDragged(const views::MouseEvent& event) { | 144 bool FrameMaximizeButton::OnMouseDragged(const views::MouseEvent& event) { |
134 if (is_snap_enabled_) | 145 if (is_snap_enabled_) |
135 ProcessUpdateEvent(event); | 146 ProcessUpdateEvent(event); |
136 return ImageButton::OnMouseDragged(event); | 147 return ImageButton::OnMouseDragged(event); |
137 } | 148 } |
138 | 149 |
139 void FrameMaximizeButton::OnMouseReleased(const views::MouseEvent& event) { | 150 void FrameMaximizeButton::OnMouseReleased(const views::MouseEvent& event) { |
140 if (!ProcessEndEvent(event)) | 151 if (!ProcessEndEvent(event)) |
141 ImageButton::OnMouseReleased(event); | 152 ImageButton::OnMouseReleased(event); |
| 153 maximizer_.reset(NULL); |
142 } | 154 } |
143 | 155 |
144 void FrameMaximizeButton::OnMouseCaptureLost() { | 156 void FrameMaximizeButton::OnMouseCaptureLost() { |
145 Cancel(); | 157 Cancel(); |
146 ImageButton::OnMouseCaptureLost(); | 158 ImageButton::OnMouseCaptureLost(); |
| 159 if (!is_snap_enabled_) |
| 160 maximizer_.reset(NULL); |
147 } | 161 } |
148 | 162 |
149 ui::GestureStatus FrameMaximizeButton::OnGestureEvent( | 163 ui::GestureStatus FrameMaximizeButton::OnGestureEvent( |
150 const views::GestureEvent& event) { | 164 const views::GestureEvent& event) { |
151 if (event.type() == ui::ET_GESTURE_TAP_DOWN) { | 165 if (event.type() == ui::ET_GESTURE_TAP_DOWN) { |
152 is_snap_enabled_ = true; | 166 is_snap_enabled_ = true; |
153 ProcessStartEvent(event); | 167 ProcessStartEvent(event); |
154 return ui::GESTURE_STATUS_CONSUMED; | 168 return ui::GESTURE_STATUS_CONSUMED; |
155 } | 169 } |
156 | 170 |
(...skipping 20 matching lines...) Expand all Loading... |
177 } | 191 } |
178 } | 192 } |
179 | 193 |
180 return ImageButton::OnGestureEvent(event); | 194 return ImageButton::OnGestureEvent(event); |
181 } | 195 } |
182 | 196 |
183 gfx::ImageSkia FrameMaximizeButton::GetImageToPaint() { | 197 gfx::ImageSkia FrameMaximizeButton::GetImageToPaint() { |
184 if (is_snap_enabled_) { | 198 if (is_snap_enabled_) { |
185 int id = 0; | 199 int id = 0; |
186 if (frame_->GetWidget()->IsMaximized()) { | 200 if (frame_->GetWidget()->IsMaximized()) { |
187 switch (snap_type_) { | 201 // TODO(SKUHNE): Remove old bitmaps as soon as the final artwork comes in: |
188 case SNAP_LEFT: | 202 // IDR_AURA_WINDOW_MAXIMIZED_SNAP_LEFT_P |
189 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_LEFT_P; | 203 // IDR_AURA_WINDOW_MAXIMIZED_SNAP_RIGHT_P |
190 break; | 204 // IDR_AURA_WINDOW_MAXIMIZED_SNAP_MINIMIZE_P |
191 case SNAP_RIGHT: | 205 // IDR_AURA_WINDOW_SNAP_LEFT_P |
192 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_RIGHT_P; | 206 // IDR_AURA_WINDOW_SNAP_RIGHT_P |
193 break; | 207 // IDR_AURA_WINDOW_SNAP_MINIMIZE_P |
194 case SNAP_MAXIMIZE: | 208 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_P; |
195 case SNAP_RESTORE: | 209 } else |
196 case SNAP_NONE: | 210 id = IDR_AURA_WINDOW_SNAP_P; |
197 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_P; | |
198 break; | |
199 case SNAP_MINIMIZE: | |
200 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_MINIMIZE_P; | |
201 break; | |
202 default: | |
203 NOTREACHED(); | |
204 } | |
205 } else { | |
206 switch (snap_type_) { | |
207 case SNAP_LEFT: | |
208 id = IDR_AURA_WINDOW_SNAP_LEFT_P; | |
209 break; | |
210 case SNAP_RIGHT: | |
211 id = IDR_AURA_WINDOW_SNAP_RIGHT_P; | |
212 break; | |
213 case SNAP_MAXIMIZE: | |
214 case SNAP_RESTORE: | |
215 case SNAP_NONE: | |
216 id = IDR_AURA_WINDOW_SNAP_P; | |
217 break; | |
218 case SNAP_MINIMIZE: | |
219 id = IDR_AURA_WINDOW_SNAP_MINIMIZE_P; | |
220 break; | |
221 default: | |
222 NOTREACHED(); | |
223 } | |
224 } | |
225 return *ResourceBundle::GetSharedInstance().GetImageNamed(id).ToImageSkia(); | 211 return *ResourceBundle::GetSharedInstance().GetImageNamed(id).ToImageSkia(); |
226 } | 212 } |
227 // Hot and pressed states handled by regular ImageButton. | 213 // Hot and pressed states handled by regular ImageButton. |
228 return ImageButton::GetImageToPaint(); | 214 return ImageButton::GetImageToPaint(); |
229 } | 215 } |
230 | 216 |
231 void FrameMaximizeButton::ProcessStartEvent(const views::LocatedEvent& event) { | 217 void FrameMaximizeButton::ProcessStartEvent(const views::LocatedEvent& event) { |
232 DCHECK(is_snap_enabled_); | 218 DCHECK(is_snap_enabled_); |
| 219 // Prepare the help / helo menu. |
| 220 if (!maximizer_.get()) { |
| 221 maximizer_.reset(new MaximizeBubble(this, |
| 222 frame_->GetWidget()->IsMaximized())); |
| 223 } else { |
| 224 // If the menu did not show up yet, we delay it even a bit more. |
| 225 maximizer_->DelayCreation(); |
| 226 } |
233 snap_sizer_.reset(NULL); | 227 snap_sizer_.reset(NULL); |
234 InstallEventFilter(); | 228 InstallEventFilter(); |
235 snap_type_ = SNAP_NONE; | 229 snap_type_ = SNAP_NONE; |
236 press_location_ = event.location(); | 230 press_location_ = event.location(); |
237 exceeded_drag_threshold_ = false; | 231 exceeded_drag_threshold_ = false; |
238 update_timer_.Start( | 232 update_timer_.Start( |
239 FROM_HERE, | 233 FROM_HERE, |
240 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), | 234 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), |
241 this, | 235 this, |
242 &FrameMaximizeButton::UpdateSnapFromEventLocation); | 236 &FrameMaximizeButton::UpdateSnapFromEventLocation); |
243 } | 237 } |
244 | 238 |
245 void FrameMaximizeButton::ProcessUpdateEvent(const views::LocatedEvent& event) { | 239 void FrameMaximizeButton::ProcessUpdateEvent(const views::LocatedEvent& event) { |
246 DCHECK(is_snap_enabled_); | 240 DCHECK(is_snap_enabled_); |
247 int delta_x = event.x() - press_location_.x(); | 241 int delta_x = event.x() - press_location_.x(); |
248 int delta_y = event.y() - press_location_.y(); | 242 int delta_y = event.y() - press_location_.y(); |
249 if (!exceeded_drag_threshold_) { | 243 if (!exceeded_drag_threshold_) { |
250 exceeded_drag_threshold_ = | 244 exceeded_drag_threshold_ = |
251 views::View::ExceededDragThreshold(delta_x, delta_y); | 245 views::View::ExceededDragThreshold(delta_x, delta_y); |
252 } | 246 } |
253 if (exceeded_drag_threshold_) | 247 if (exceeded_drag_threshold_) |
254 UpdateSnap(event.location()); | 248 UpdateSnap(event.location()); |
| 249 |
| 250 // Update the halo menu. |
| 251 if (maximizer_.get() && maximizer_->IsRadialMenu()) { |
| 252 gfx::Point pt = event.location(); |
| 253 views::View::ConvertPointToScreen(this, &pt); |
| 254 FrameMaximizeButton::SnapType type; |
| 255 maximizer_->SnapTypeForLocation(pt, type); |
| 256 } |
255 } | 257 } |
256 | 258 |
257 bool FrameMaximizeButton::ProcessEndEvent(const views::LocatedEvent& event) { | 259 bool FrameMaximizeButton::ProcessEndEvent(const views::LocatedEvent& event) { |
258 update_timer_.Stop(); | 260 update_timer_.Stop(); |
259 UninstallEventFilter(); | 261 UninstallEventFilter(); |
260 bool should_snap = is_snap_enabled_; | 262 bool should_snap = is_snap_enabled_; |
261 is_snap_enabled_ = false; | 263 is_snap_enabled_ = false; |
262 | 264 |
| 265 // Remove our help / halo menu if the mouse cursor is not still over it. |
| 266 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); |
| 267 if (!GetBoundsInScreen().Contains(screen_location)) |
| 268 maximizer_.reset(); |
| 269 |
263 if (!should_snap || snap_type_ == SNAP_NONE) | 270 if (!should_snap || snap_type_ == SNAP_NONE) |
264 return false; | 271 return false; |
265 | 272 |
266 SetState(BS_NORMAL); | 273 SetState(BS_NORMAL); |
267 // SetState will not call SchedulePaint() if state was already set to | 274 // SetState will not call SchedulePaint() if state was already set to |
268 // BS_NORMAL during a drag. | 275 // BS_NORMAL during a drag. |
269 SchedulePaint(); | 276 SchedulePaint(); |
270 phantom_window_.reset(); | 277 phantom_window_.reset(); |
271 Snap(); | 278 Snap(); |
272 return true; | 279 return true; |
273 } | 280 } |
274 | 281 |
275 void FrameMaximizeButton::Cancel() { | 282 void FrameMaximizeButton::Cancel() { |
276 UninstallEventFilter(); | 283 UninstallEventFilter(); |
277 is_snap_enabled_ = false; | 284 is_snap_enabled_ = false; |
278 phantom_window_.reset(); | 285 phantom_window_.reset(); |
279 snap_sizer_.reset(); | 286 snap_sizer_.reset(); |
| 287 snap_type_ = SNAP_NONE; |
280 update_timer_.Stop(); | 288 update_timer_.Stop(); |
281 SchedulePaint(); | 289 SchedulePaint(); |
282 } | 290 } |
283 | 291 |
284 void FrameMaximizeButton::InstallEventFilter() { | 292 void FrameMaximizeButton::InstallEventFilter() { |
285 if (escape_event_filter_.get()) | 293 if (escape_event_filter_.get()) |
286 return; | 294 return; |
287 | 295 |
288 escape_event_filter_.reset(new EscapeEventFilter(this)); | 296 escape_event_filter_.reset(new EscapeEventFilter(this)); |
289 } | 297 } |
290 | 298 |
291 void FrameMaximizeButton::UninstallEventFilter() { | 299 void FrameMaximizeButton::UninstallEventFilter() { |
292 escape_event_filter_.reset(NULL); | 300 escape_event_filter_.reset(NULL); |
293 } | 301 } |
294 | 302 |
295 void FrameMaximizeButton::UpdateSnapFromEventLocation() { | 303 void FrameMaximizeButton::UpdateSnapFromEventLocation() { |
296 // If the drag threshold has been exceeded the snap location is up to date. | 304 // If the drag threshold has been exceeded the snap location is up to date. |
297 if (exceeded_drag_threshold_) | 305 if (exceeded_drag_threshold_) |
298 return; | 306 return; |
299 exceeded_drag_threshold_ = true; | 307 exceeded_drag_threshold_ = true; |
300 UpdateSnap(press_location_); | 308 UpdateSnap(press_location_); |
301 } | 309 } |
302 | 310 |
| 311 void FrameMaximizeButton::SnapButtonHovered(SnapType type) { |
| 312 // Make sure to only show hover operations when no button is pressed and |
| 313 // a similar snap operation in progress does not get re-applied. |
| 314 if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_.get())) |
| 315 return; |
| 316 // Prime the mouse location with the center of the (local) button. |
| 317 press_location_ = gfx::Point(width() / 2, height() / 2); |
| 318 // Then get an adjusted mouse position to initiate the effect. |
| 319 gfx::Point location = press_location_; |
| 320 switch (type) { |
| 321 case SNAP_LEFT: |
| 322 location.set_x(location.x() - width()); |
| 323 break; |
| 324 case SNAP_RIGHT: |
| 325 location.set_x(location.x() + width()); |
| 326 break; |
| 327 case SNAP_MINIMIZE: |
| 328 location.set_y(location.y() + height()); |
| 329 break; |
| 330 case SNAP_MAXIMIZE: |
| 331 case SNAP_RESTORE: |
| 332 break; |
| 333 case SNAP_NONE: |
| 334 snap_type_ = type; |
| 335 snap_sizer_.reset(); |
| 336 SchedulePaint(); |
| 337 phantom_window_.reset(); |
| 338 return; |
| 339 default: |
| 340 // We should not come here. |
| 341 DCHECK(false); |
| 342 return; |
| 343 } |
| 344 UpdateSnap(location); |
| 345 } |
| 346 |
303 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { | 347 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { |
304 SnapType type = SnapTypeForLocation(location); | 348 SnapType type = SnapTypeForLocation(location); |
305 if (type == snap_type_) { | 349 if (type == snap_type_) { |
306 if (snap_sizer_.get()) { | 350 if (snap_sizer_.get()) { |
307 snap_sizer_->Update(LocationForSnapSizer(location)); | 351 snap_sizer_->Update(LocationForSnapSizer(location)); |
308 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( | 352 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( |
309 frame_->GetWidget()->GetNativeView()->parent(), | 353 frame_->GetWidget()->GetNativeView()->parent(), |
310 snap_sizer_->target_bounds())); | 354 snap_sizer_->target_bounds())); |
311 } | 355 } |
312 return; | 356 return; |
(...skipping 13 matching lines...) Expand all Loading... |
326 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; | 370 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; |
327 int grid_size = Shell::GetInstance()->GetGridSize(); | 371 int grid_size = Shell::GetInstance()->GetGridSize(); |
328 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), | 372 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), |
329 LocationForSnapSizer(location), | 373 LocationForSnapSizer(location), |
330 snap_edge, grid_size)); | 374 snap_edge, grid_size)); |
331 } | 375 } |
332 if (!phantom_window_.get()) { | 376 if (!phantom_window_.get()) { |
333 phantom_window_.reset(new internal::PhantomWindowController( | 377 phantom_window_.reset(new internal::PhantomWindowController( |
334 frame_->GetWidget()->GetNativeWindow())); | 378 frame_->GetWidget()->GetNativeWindow())); |
335 } | 379 } |
| 380 if (maximizer_.get()) |
| 381 phantom_window_->set_phantom_below_window(maximizer_->GetMenuWindow()); |
| 382 |
336 phantom_window_->Show(ScreenBoundsForType(snap_type_)); | 383 phantom_window_->Show(ScreenBoundsForType(snap_type_)); |
| 384 |
| 385 if (maximizer_.get()) |
| 386 maximizer_->SetMenuState(snap_type_); |
337 } | 387 } |
338 | 388 |
339 FrameMaximizeButton::SnapType FrameMaximizeButton::SnapTypeForLocation( | 389 FrameMaximizeButton::SnapType FrameMaximizeButton::SnapTypeForLocation( |
340 const gfx::Point& location) const { | 390 const gfx::Point& location) const { |
| 391 if (maximizer_.get() && maximizer_->IsRadialMenu()) { |
| 392 FrameMaximizeButton::SnapType code; |
| 393 gfx::Point pt = location; |
| 394 views::View::ConvertPointToScreen(this, &pt); |
| 395 maximizer_->SnapTypeForLocation(pt, code); |
| 396 if (code != SNAP_NONE) |
| 397 return code; |
| 398 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; |
| 399 } |
341 int delta_x = location.x() - press_location_.x(); | 400 int delta_x = location.x() - press_location_.x(); |
342 int delta_y = location.y() - press_location_.y(); | 401 int delta_y = location.y() - press_location_.y(); |
343 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) | 402 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) |
344 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; | 403 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; |
345 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) | 404 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) |
346 return SNAP_LEFT; | 405 return SNAP_LEFT; |
347 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) | 406 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) |
348 return SNAP_RIGHT; | 407 return SNAP_RIGHT; |
349 else if (delta_y > 0) | 408 else if (delta_y > 0) |
350 return SNAP_MINIMIZE; | 409 return SNAP_MINIMIZE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return gfx::Rect(); | 444 return gfx::Rect(); |
386 } | 445 } |
387 | 446 |
388 gfx::Point FrameMaximizeButton::LocationForSnapSizer( | 447 gfx::Point FrameMaximizeButton::LocationForSnapSizer( |
389 const gfx::Point& location) const { | 448 const gfx::Point& location) const { |
390 gfx::Point result(location); | 449 gfx::Point result(location); |
391 views::View::ConvertPointToScreen(this, &result); | 450 views::View::ConvertPointToScreen(this, &result); |
392 return result; | 451 return result; |
393 } | 452 } |
394 | 453 |
| 454 void FrameMaximizeButton::SnapButtonClicked(SnapType snap_type) { |
| 455 snap_type_ = snap_type; |
| 456 Snap(); |
| 457 // Remove any pending snap previews. |
| 458 SnapButtonHovered(SNAP_NONE); |
| 459 } |
| 460 |
395 void FrameMaximizeButton::Snap() { | 461 void FrameMaximizeButton::Snap() { |
396 switch (snap_type_) { | 462 switch (snap_type_) { |
397 case SNAP_LEFT: | 463 case SNAP_LEFT: |
398 case SNAP_RIGHT: | 464 case SNAP_RIGHT: |
399 if (frame_->GetWidget()->IsMaximized()) { | 465 if (frame_->GetWidget()->IsMaximized()) { |
400 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), | 466 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), |
401 ScreenBoundsForType(snap_type_)); | 467 ScreenBoundsForType(snap_type_)); |
402 frame_->GetWidget()->Restore(); | 468 frame_->GetWidget()->Restore(); |
403 } else { | 469 } else { |
404 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_)); | 470 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_)); |
405 } | 471 } |
406 break; | 472 break; |
407 case SNAP_MAXIMIZE: | 473 case SNAP_MAXIMIZE: |
408 frame_->GetWidget()->Maximize(); | 474 frame_->GetWidget()->Maximize(); |
409 break; | 475 break; |
410 case SNAP_MINIMIZE: | 476 case SNAP_MINIMIZE: |
411 frame_->GetWidget()->Minimize(); | 477 frame_->GetWidget()->Minimize(); |
412 break; | 478 break; |
413 case SNAP_RESTORE: | 479 case SNAP_RESTORE: |
414 frame_->GetWidget()->Restore(); | 480 frame_->GetWidget()->Restore(); |
415 break; | 481 break; |
416 case SNAP_NONE: | 482 case SNAP_NONE: |
417 NOTREACHED(); | 483 NOTREACHED(); |
418 } | 484 } |
419 } | 485 } |
420 | 486 |
| 487 void FrameMaximizeButton::DestroyMaximizeMenu() { |
| 488 if (maximizer_.get()) |
| 489 maximizer_.reset(); |
| 490 } |
| 491 |
421 } // namespace ash | 492 } // namespace ash |
OLD | NEW |