| OLD | NEW |
| 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/wm/caption_buttons/frame_maximize_button.h" | 5 #include "ash/wm/caption_buttons/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/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_delegate.h" | 11 #include "ash/shell_delegate.h" |
| 12 #include "ash/touch/touch_uma.h" | 12 #include "ash/touch/touch_uma.h" |
| 13 #include "ash/wm/caption_buttons/maximize_bubble_controller.h" | 13 #include "ash/wm/caption_buttons/maximize_bubble_controller.h" |
| 14 #include "ash/wm/property_util.h" | |
| 15 #include "ash/wm/window_animations.h" | 14 #include "ash/wm/window_animations.h" |
| 16 #include "ash/wm/window_settings.h" | 15 #include "ash/wm/window_state.h" |
| 17 #include "ash/wm/workspace/phantom_window_controller.h" | 16 #include "ash/wm/workspace/phantom_window_controller.h" |
| 18 #include "ash/wm/workspace/snap_sizer.h" | 17 #include "ash/wm/workspace/snap_sizer.h" |
| 19 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
| 20 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
| 21 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 22 #include "ui/base/events/event.h" | 21 #include "ui/base/events/event.h" |
| 23 #include "ui/base/events/event_handler.h" | 22 #include "ui/base/events/event_handler.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 frame_(frame), | 86 frame_(frame), |
| 88 observing_frame_(false), | 87 observing_frame_(false), |
| 89 is_snap_enabled_(false), | 88 is_snap_enabled_(false), |
| 90 exceeded_drag_threshold_(false), | 89 exceeded_drag_threshold_(false), |
| 91 press_is_gesture_(false), | 90 press_is_gesture_(false), |
| 92 snap_type_(SNAP_NONE), | 91 snap_type_(SNAP_NONE), |
| 93 bubble_appearance_delay_ms_(kBubbleAppearanceDelayMS) { | 92 bubble_appearance_delay_ms_(kBubbleAppearanceDelayMS) { |
| 94 // TODO(sky): nuke this. It's temporary while we don't have good images. | 93 // TODO(sky): nuke this. It's temporary while we don't have good images. |
| 95 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); | 94 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); |
| 96 | 95 |
| 97 if (ash::Shell::IsForcedMaximizeMode()) | 96 if (Shell::IsForcedMaximizeMode()) |
| 98 views::View::SetVisible(false); | 97 views::View::SetVisible(false); |
| 99 } | 98 } |
| 100 | 99 |
| 101 FrameMaximizeButton::~FrameMaximizeButton() { | 100 FrameMaximizeButton::~FrameMaximizeButton() { |
| 102 // Before the window gets destroyed, the maximizer dialog needs to be shut | 101 // Before the window gets destroyed, the maximizer dialog needs to be shut |
| 103 // down since it would otherwise call into a deleted object. | 102 // down since it would otherwise call into a deleted object. |
| 104 maximizer_.reset(); | 103 maximizer_.reset(); |
| 105 if (observing_frame_) | 104 if (observing_frame_) |
| 106 OnWindowDestroying(frame_->GetNativeWindow()); | 105 OnWindowDestroying(frame_->GetNativeWindow()); |
| 107 } | 106 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 event->SetHandled(); | 308 event->SetHandled(); |
| 310 return; | 309 return; |
| 311 } | 310 } |
| 312 } | 311 } |
| 313 | 312 |
| 314 ImageButton::OnGestureEvent(event); | 313 ImageButton::OnGestureEvent(event); |
| 315 } | 314 } |
| 316 | 315 |
| 317 void FrameMaximizeButton::SetVisible(bool visible) { | 316 void FrameMaximizeButton::SetVisible(bool visible) { |
| 318 // In the enforced maximized mode we do not allow to be made visible. | 317 // In the enforced maximized mode we do not allow to be made visible. |
| 319 if (ash::Shell::IsForcedMaximizeMode()) | 318 if (Shell::IsForcedMaximizeMode()) |
| 320 return; | 319 return; |
| 321 | 320 |
| 322 views::View::SetVisible(visible); | 321 views::View::SetVisible(visible); |
| 323 } | 322 } |
| 324 | 323 |
| 325 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { | 324 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { |
| 326 DCHECK(is_snap_enabled_); | 325 DCHECK(is_snap_enabled_); |
| 327 // Prepare the help menu. | 326 // Prepare the help menu. |
| 328 if (!maximizer_) { | 327 if (!maximizer_) { |
| 329 maximizer_.reset(new MaximizeBubbleController( | 328 maximizer_.reset(new MaximizeBubbleController( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 case SNAP_MINIMIZE: { | 491 case SNAP_MINIMIZE: { |
| 493 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(window); | 492 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(window); |
| 494 if (!rect.IsEmpty()) { | 493 if (!rect.IsEmpty()) { |
| 495 // PhantomWindowController insets slightly, outset it so the phantom | 494 // PhantomWindowController insets slightly, outset it so the phantom |
| 496 // doesn't appear inset. | 495 // doesn't appear inset. |
| 497 rect.Inset(-8, -8); | 496 rect.Inset(-8, -8); |
| 498 } | 497 } |
| 499 return rect; | 498 return rect; |
| 500 } | 499 } |
| 501 case SNAP_RESTORE: { | 500 case SNAP_RESTORE: { |
| 502 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); | 501 wm::WindowState* window_state = wm::GetWindowState(window); |
| 503 return restore ? *restore : frame_->GetWindowBoundsInScreen(); | 502 return window_state->HasRestoreBounds() ? |
| 503 window_state->GetRestoreBoundsInScreen() : |
| 504 frame_->GetWindowBoundsInScreen(); |
| 504 } | 505 } |
| 505 case SNAP_NONE: | 506 case SNAP_NONE: |
| 506 NOTREACHED(); | 507 NOTREACHED(); |
| 507 } | 508 } |
| 508 return gfx::Rect(); | 509 return gfx::Rect(); |
| 509 } | 510 } |
| 510 | 511 |
| 511 gfx::Point FrameMaximizeButton::LocationForSnapSizer( | 512 gfx::Point FrameMaximizeButton::LocationForSnapSizer( |
| 512 const gfx::Point& location) const { | 513 const gfx::Point& location) const { |
| 513 gfx::Point result(location); | 514 gfx::Point result(location); |
| 514 views::View::ConvertPointToScreen(this, &result); | 515 views::View::ConvertPointToScreen(this, &result); |
| 515 return result; | 516 return result; |
| 516 } | 517 } |
| 517 | 518 |
| 518 void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) { | 519 void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) { |
| 519 ash::Shell* shell = ash::Shell::GetInstance(); | 520 Shell* shell = Shell::GetInstance(); |
| 521 |
| 520 switch (snap_type_) { | 522 switch (snap_type_) { |
| 521 case SNAP_LEFT: | 523 case SNAP_LEFT: |
| 522 case SNAP_RIGHT: { | 524 case SNAP_RIGHT: { |
| 523 shell->delegate()->RecordUserMetricsAction( | 525 shell->delegate()->RecordUserMetricsAction( |
| 524 snap_type_ == SNAP_LEFT ? | 526 snap_type_ == SNAP_LEFT ? |
| 525 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT : | 527 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT : |
| 526 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); | 528 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); |
| 529 wm::WindowState* window_state = wm::GetWindowState( |
| 530 frame_->GetNativeWindow()); |
| 527 // Get the bounds in screen coordinates for restore purposes. | 531 // Get the bounds in screen coordinates for restore purposes. |
| 528 gfx::Rect restore = frame_->GetWindowBoundsInScreen(); | 532 gfx::Rect restore = frame_->GetWindowBoundsInScreen(); |
| 529 if (frame_->IsMaximized() || frame_->IsFullscreen()) { | 533 if (frame_->IsMaximized() || frame_->IsFullscreen()) { |
| 530 aura::Window* window = frame_->GetNativeWindow(); | |
| 531 // In case of maximized we have a restore boundary. | 534 // In case of maximized we have a restore boundary. |
| 532 DCHECK(ash::GetRestoreBoundsInScreen(window)); | 535 DCHECK(window_state->HasRestoreBounds()); |
| 533 // If it was maximized we need to recover the old restore set. | 536 // If it was maximized we need to recover the old restore set. |
| 534 restore = *ash::GetRestoreBoundsInScreen(window); | 537 restore = window_state->GetRestoreBoundsInScreen(); |
| 535 | 538 |
| 536 // The auto position manager will kick in when this is the only window. | 539 // The auto position manager will kick in when this is the only window. |
| 537 // To avoid interference with it we tell it temporarily to not change | 540 // To avoid interference with it we tell it temporarily to not change |
| 538 // the coordinates of this window. | 541 // the coordinates of this window. |
| 539 wm::WindowSettings* settings = wm::GetWindowSettings(window); | 542 bool was_managed = window_state->window_position_managed(); |
| 540 bool was_managed = settings->window_position_managed(); | 543 window_state->set_window_position_managed(false); |
| 541 settings->set_window_position_managed(false); | |
| 542 | 544 |
| 543 // Set the restore size we want to restore to. | 545 // Set the restore size we want to restore to. |
| 544 ash::SetRestoreBoundsInScreen(window, | 546 window_state->SetRestoreBoundsInScreen( |
| 545 ScreenBoundsForType(snap_type_, | 547 ScreenBoundsForType(snap_type_, snap_sizer)); |
| 546 snap_sizer)); | |
| 547 frame_->Restore(); | 548 frame_->Restore(); |
| 548 | 549 |
| 549 // After the window is where we want it to be we allow the window to be | 550 // After the window is where we want it to be we allow the window to be |
| 550 // auto managed again. | 551 // auto managed again. |
| 551 settings->set_window_position_managed(was_managed); | 552 window_state->set_window_position_managed(was_managed); |
| 552 } else { | 553 } else { |
| 553 // Others might also have set up a restore rectangle already. If so, | 554 // Others might also have set up a restore rectangle already. If so, |
| 554 // we should not overwrite the restore rectangle. | 555 // we should not overwrite the restore rectangle. |
| 555 bool restore_set = | 556 bool restore_set = window_state->HasRestoreBounds(); |
| 556 GetRestoreBoundsInScreen(frame_->GetNativeWindow()) != NULL; | |
| 557 frame_->SetBounds(ScreenBoundsForType(snap_type_, snap_sizer)); | 557 frame_->SetBounds(ScreenBoundsForType(snap_type_, snap_sizer)); |
| 558 if (restore_set) | 558 if (restore_set) |
| 559 break; | 559 break; |
| 560 } | 560 } |
| 561 // Remember the widow's bounds for restoration. | 561 // Remember the widow's bounds for restoration. |
| 562 ash::SetRestoreBoundsInScreen(frame_->GetNativeWindow(), restore); | 562 window_state->SetRestoreBoundsInScreen(restore); |
| 563 break; | 563 break; |
| 564 } | 564 } |
| 565 case SNAP_MAXIMIZE: | 565 case SNAP_MAXIMIZE: |
| 566 frame_->Maximize(); | 566 frame_->Maximize(); |
| 567 shell->delegate()->RecordUserMetricsAction( | 567 shell->delegate()->RecordUserMetricsAction( |
| 568 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE); | 568 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE); |
| 569 break; | 569 break; |
| 570 case SNAP_MINIMIZE: | 570 case SNAP_MINIMIZE: |
| 571 frame_->Minimize(); | 571 frame_->Minimize(); |
| 572 shell->delegate()->RecordUserMetricsAction( | 572 shell->delegate()->RecordUserMetricsAction( |
| 573 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE); | 573 UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE); |
| 574 break; | 574 break; |
| 575 case SNAP_RESTORE: | 575 case SNAP_RESTORE: |
| 576 frame_->Restore(); | 576 frame_->Restore(); |
| 577 shell->delegate()->RecordUserMetricsAction( | 577 shell->delegate()->RecordUserMetricsAction( |
| 578 ash::UMA_WINDOW_MAXIMIZE_BUTTON_RESTORE); | 578 UMA_WINDOW_MAXIMIZE_BUTTON_RESTORE); |
| 579 break; | 579 break; |
| 580 case SNAP_NONE: | 580 case SNAP_NONE: |
| 581 NOTREACHED(); | 581 NOTREACHED(); |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 | 584 |
| 585 MaximizeBubbleFrameState | 585 MaximizeBubbleFrameState |
| 586 FrameMaximizeButton::GetMaximizeBubbleFrameState() const { | 586 FrameMaximizeButton::GetMaximizeBubbleFrameState() const { |
| 587 wm::WindowState* window_state = |
| 588 wm::GetWindowState(frame_->GetNativeWindow()); |
| 587 // When there are no restore bounds, we are in normal mode. | 589 // When there are no restore bounds, we are in normal mode. |
| 588 if (!ash::GetRestoreBoundsInScreen(frame_->GetNativeWindow())) | 590 if (!window_state->HasRestoreBounds()) |
| 589 return FRAME_STATE_NONE; | 591 return FRAME_STATE_NONE; |
| 590 // The normal maximized test can be used. | 592 // The normal maximized test can be used. |
| 591 if (frame_->IsMaximized()) | 593 if (frame_->IsMaximized()) |
| 592 return FRAME_STATE_FULL; | 594 return FRAME_STATE_FULL; |
| 593 // For Left/right maximize we need to check the dimensions. | 595 // For Left/right maximize we need to check the dimensions. |
| 594 gfx::Rect bounds = frame_->GetWindowBoundsInScreen(); | 596 gfx::Rect bounds = frame_->GetWindowBoundsInScreen(); |
| 595 gfx::Rect screen = Shell::GetScreen()->GetDisplayNearestWindow( | 597 gfx::Rect screen = Shell::GetScreen()->GetDisplayNearestWindow( |
| 596 frame_->GetNativeView()).work_area(); | 598 frame_->GetNativeView()).work_area(); |
| 597 if (bounds.width() < (screen.width() * kMinSnapSizePercent) / 100) | 599 if (bounds.width() < (screen.width() * kMinSnapSizePercent) / 100) |
| 598 return FRAME_STATE_NONE; | 600 return FRAME_STATE_NONE; |
| 599 // We might still have a horizontally filled window at this point which we | 601 // We might still have a horizontally filled window at this point which we |
| 600 // treat as no special state. | 602 // treat as no special state. |
| 601 if (bounds.y() != screen.y() || bounds.height() != screen.height()) | 603 if (bounds.y() != screen.y() || bounds.height() != screen.height()) |
| 602 return FRAME_STATE_NONE; | 604 return FRAME_STATE_NONE; |
| 603 | 605 |
| 604 // We have to be in a maximize mode at this point. | 606 // We have to be in a maximize mode at this point. |
| 605 if (bounds.x() == screen.x()) | 607 if (bounds.x() == screen.x()) |
| 606 return FRAME_STATE_SNAP_LEFT; | 608 return FRAME_STATE_SNAP_LEFT; |
| 607 if (bounds.right() == screen.right()) | 609 if (bounds.right() == screen.right()) |
| 608 return FRAME_STATE_SNAP_RIGHT; | 610 return FRAME_STATE_SNAP_RIGHT; |
| 609 // If we come here, it is likely caused by the fact that the | 611 // If we come here, it is likely caused by the fact that the |
| 610 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case | 612 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case |
| 611 // we allow all maximize operations (and keep the restore rectangle). | 613 // we allow all maximize operations (and keep the restore rectangle). |
| 612 return FRAME_STATE_NONE; | 614 return FRAME_STATE_NONE; |
| 613 } | 615 } |
| 614 | 616 |
| 615 } // namespace ash | 617 } // namespace ash |
| OLD | NEW |