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

Side by Side Diff: ash/wm/workspace/frame_maximize_button.cc

Issue 10883069: Added restore functionality for maximize full/left/right (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
OLDNEW
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/maximize_bubble_controller.h" 11 #include "ash/wm/maximize_bubble_controller.h"
12 #include "ash/wm/workspace/phantom_window_controller.h" 12 #include "ash/wm/workspace/phantom_window_controller.h"
13 #include "ash/wm/workspace/snap_sizer.h" 13 #include "ash/wm/workspace/snap_sizer.h"
14 #include "ash/wm/workspace/workspace_event_filter.h"
14 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
15 #include "grit/ui_resources.h" 16 #include "grit/ui_resources.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/event.h" 19 #include "ui/base/event.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
22 #include "ui/gfx/screen.h" 23 #include "ui/gfx/screen.h"
23 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 void FrameMaximizeButton::OnMouseEntered(const ui::MouseEvent& event) { 206 void FrameMaximizeButton::OnMouseEntered(const ui::MouseEvent& event) {
206 ImageButton::OnMouseEntered(event); 207 ImageButton::OnMouseEntered(event);
207 if (!maximizer_.get()) { 208 if (!maximizer_.get()) {
208 DCHECK(GetWidget()); 209 DCHECK(GetWidget());
209 if (!window_) { 210 if (!window_) {
210 window_ = frame_->GetWidget()->GetNativeWindow(); 211 window_ = frame_->GetWidget()->GetNativeWindow();
211 window_->AddObserver(this); 212 window_->AddObserver(this);
212 } 213 }
213 maximizer_.reset(new MaximizeBubbleController( 214 maximizer_.reset(new MaximizeBubbleController(
214 this, 215 this,
215 frame_->GetWidget()->IsMaximized(), 216 GetMaximizeType(),
216 bubble_appearance_delay_ms_)); 217 bubble_appearance_delay_ms_));
217 } 218 }
218 } 219 }
219 220
220 void FrameMaximizeButton::OnMouseExited(const ui::MouseEvent& event) { 221 void FrameMaximizeButton::OnMouseExited(const ui::MouseEvent& event) {
221 ImageButton::OnMouseExited(event); 222 ImageButton::OnMouseExited(event);
222 // Remove the bubble menu when the button is not pressed and the mouse is not 223 // Remove the bubble menu when the button is not pressed and the mouse is not
223 // within the bubble. 224 // within the bubble.
224 if (!is_snap_enabled_ && maximizer_.get()) { 225 if (!is_snap_enabled_ && maximizer_.get()) {
225 if (maximizer_->GetBubbleWindow()) { 226 if (maximizer_->GetBubbleWindow()) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 298
298 return ImageButton::OnGestureEvent(event); 299 return ImageButton::OnGestureEvent(event);
299 } 300 }
300 301
301 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { 302 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) {
302 DCHECK(is_snap_enabled_); 303 DCHECK(is_snap_enabled_);
303 // Prepare the help menu. 304 // Prepare the help menu.
304 if (!maximizer_.get()) { 305 if (!maximizer_.get()) {
305 maximizer_.reset(new MaximizeBubbleController( 306 maximizer_.reset(new MaximizeBubbleController(
306 this, 307 this,
307 frame_->GetWidget()->IsMaximized(), 308 GetMaximizeType(),
308 bubble_appearance_delay_ms_)); 309 bubble_appearance_delay_ms_));
309 } else { 310 } else {
310 // If the menu did not show up yet, we delay it even a bit more. 311 // If the menu did not show up yet, we delay it even a bit more.
311 maximizer_->DelayCreation(); 312 maximizer_->DelayCreation();
312 } 313 }
313 snap_sizer_.reset(NULL); 314 snap_sizer_.reset(NULL);
314 InstallEventFilter(); 315 InstallEventFilter();
315 snap_type_ = SNAP_NONE; 316 snap_type_ = SNAP_NONE;
316 press_location_ = event.location(); 317 press_location_ = event.location();
317 exceeded_drag_threshold_ = false; 318 exceeded_drag_threshold_ = false;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 } 426 }
426 if (maximizer_.get()) { 427 if (maximizer_.get()) {
427 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); 428 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow());
428 maximizer_->SetSnapType(snap_type_); 429 maximizer_->SetSnapType(snap_type_);
429 } 430 }
430 phantom_window_->Show(ScreenBoundsForType(snap_type_, *snap_sizer_.get())); 431 phantom_window_->Show(ScreenBoundsForType(snap_type_, *snap_sizer_.get()));
431 } 432 }
432 433
433 SnapType FrameMaximizeButton::SnapTypeForLocation( 434 SnapType FrameMaximizeButton::SnapTypeForLocation(
434 const gfx::Point& location) const { 435 const gfx::Point& location) const {
436 MaximizeType maximize_type = GetMaximizeType();
435 int delta_x = location.x() - press_location_.x(); 437 int delta_x = location.x() - press_location_.x();
436 int delta_y = location.y() - press_location_.y(); 438 int delta_y = location.y() - press_location_.y();
437 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) 439 if (!views::View::ExceededDragThreshold(delta_x, delta_y))
438 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; 440 return maximize_type != MAXIMIZE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE;
439 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) 441 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x)
440 return SNAP_LEFT; 442 return maximize_type == MAXIMIZE_LEFT ? SNAP_RESTORE : SNAP_LEFT;
441 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) 443 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x)
442 return SNAP_RIGHT; 444 return maximize_type == MAXIMIZE_RIGHT ? SNAP_RESTORE : SNAP_RIGHT;
443 else if (delta_y > 0) 445 else if (delta_y > 0)
444 return SNAP_MINIMIZE; 446 return SNAP_MINIMIZE;
445 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; 447 return maximize_type != MAXIMIZE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE;
446 } 448 }
447 449
448 gfx::Rect FrameMaximizeButton::ScreenBoundsForType( 450 gfx::Rect FrameMaximizeButton::ScreenBoundsForType(
449 SnapType type, 451 SnapType type,
450 const SnapSizer& snap_sizer) const { 452 const SnapSizer& snap_sizer) const {
451 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); 453 aura::Window* window = frame_->GetWidget()->GetNativeWindow();
452 switch (type) { 454 switch (type) {
453 case SNAP_LEFT: 455 case SNAP_LEFT:
454 case SNAP_RIGHT: 456 case SNAP_RIGHT:
455 return ScreenAsh::ConvertRectToScreen( 457 return ScreenAsh::ConvertRectToScreen(
(...skipping 26 matching lines...) Expand all
482 } 484 }
483 485
484 gfx::Point FrameMaximizeButton::LocationForSnapSizer( 486 gfx::Point FrameMaximizeButton::LocationForSnapSizer(
485 const gfx::Point& location) const { 487 const gfx::Point& location) const {
486 gfx::Point result(location); 488 gfx::Point result(location);
487 views::View::ConvertPointToScreen(this, &result); 489 views::View::ConvertPointToScreen(this, &result);
488 return result; 490 return result;
489 } 491 }
490 492
491 void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) { 493 void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) {
494 views::Widget* widget = frame_->GetWidget();
492 switch (snap_type_) { 495 switch (snap_type_) {
493 case SNAP_LEFT: 496 case SNAP_LEFT:
494 case SNAP_RIGHT: 497 case SNAP_RIGHT: {
495 if (frame_->GetWidget()->IsMaximized()) { 498 // Get the window coordinates on the screen for restore purposes.
sky 2012/08/28 15:38:36 spacing is off here.
Mr4D (OOO till 08-26) 2012/08/28 19:40:53 Done. But here is a question: This whole paragraph
496 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), 499 gfx::Rect restore = widget->GetNativeWindow()->bounds();
497 ScreenBoundsForType(snap_type_, 500 if (widget->IsMaximized()) {
498 snap_sizer)); 501 // If it was maximized we need to recover the old restore set.
499 frame_->GetWidget()->Restore(); 502 restore = *ash::GetRestoreBoundsInScreen(widget->GetNativeWindow());
500 } else { 503 // Set the restore size we want to restore to.
501 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_, 504 ash::SetRestoreBoundsInScreen(widget->GetNativeWindow(),
502 snap_sizer)); 505 ScreenBoundsForType(snap_type_,
506 snap_sizer));
507 widget->Restore();
508 } else {
509 widget->SetBounds(ScreenBoundsForType(snap_type_, snap_sizer));
510 }
511 // Remember the widow's bounds for restoration.
512 ash::SetRestoreBoundsInScreen(widget->GetNativeWindow(), restore);
503 } 513 }
504 break; 514 break;
505 case SNAP_MAXIMIZE: 515 case SNAP_MAXIMIZE:
506 frame_->GetWidget()->Maximize(); 516 ToggleMaximizedState(widget->GetNativeWindow());
507 break; 517 break;
508 case SNAP_MINIMIZE: 518 case SNAP_MINIMIZE:
509 frame_->GetWidget()->Minimize(); 519 widget->Minimize();
510 break; 520 break;
511 case SNAP_RESTORE: 521 case SNAP_RESTORE:
512 frame_->GetWidget()->Restore(); 522 widget->Restore();
513 break; 523 break;
514 case SNAP_NONE: 524 case SNAP_NONE:
515 NOTREACHED(); 525 NOTREACHED();
516 } 526 }
517 } 527 }
518 528
529 MaximizeType FrameMaximizeButton::GetMaximizeType() const {
530 // When there are no restore bounds, we are in normal mode.
531 if (!ash::GetRestoreBoundsInScreen(
532 frame_->GetWidget()->GetNativeWindow()))
533 return MAXIMIZE_NONE;
534 // The normal maximized test can be used.
535 if (frame_->GetWidget()->IsMaximized())
536 return MAXIMIZE_FULL;
537 // For Left/right maximize we need to check the dimensions.
538 gfx::Rect bounds = frame_->GetWidget()->GetNativeWindow()->bounds();
539 gfx::Rect screen = gfx::Screen::GetDisplayMatching(bounds).work_area();
540 // We have to be in a maximize mode at this point.
541 DCHECK(bounds.y() == screen.y());
542 DCHECK(bounds.height() >= screen.height());
543 if (bounds.x() == screen.x())
544 return MAXIMIZE_LEFT;
545 if (bounds.right() == screen.right())
546 return MAXIMIZE_RIGHT;
547 NOTREACHED();
548 return MAXIMIZE_NONE;
549 }
550
519 } // namespace ash 551 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698