| 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/maximize_bubble_controller.h" | 5 #include "ash/wm/maximize_bubble_controller.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/wm/window_animations.h" | 9 #include "ash/wm/window_animations.h" |
| 10 #include "ash/wm/workspace/frame_maximize_button.h" | 10 #include "ash/wm/workspace/frame_maximize_button.h" |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 494 |
| 495 bool MaximizeBubbleController::Bubble::Contains( | 495 bool MaximizeBubbleController::Bubble::Contains( |
| 496 const gfx::Point& screen_point, | 496 const gfx::Point& screen_point, |
| 497 views::MouseWatcherHost::MouseEventType type) { | 497 views::MouseWatcherHost::MouseEventType type) { |
| 498 if (!owner_ || shutting_down_) | 498 if (!owner_ || shutting_down_) |
| 499 return false; | 499 return false; |
| 500 bool inside_button = | 500 bool inside_button = |
| 501 owner_->frame_maximize_button()->GetBoundsInScreen().Contains( | 501 owner_->frame_maximize_button()->GetBoundsInScreen().Contains( |
| 502 screen_point); | 502 screen_point); |
| 503 if (!owner_->frame_maximize_button()->is_snap_enabled() && inside_button) { | 503 if (!owner_->frame_maximize_button()->is_snap_enabled() && inside_button) { |
| 504 SetSnapType(controller()->is_maximized() ? SNAP_RESTORE : SNAP_MAXIMIZE); | 504 SetSnapType(controller()->maximize_type() == FRAME_STATE_FULL ? |
| 505 SNAP_RESTORE : SNAP_MAXIMIZE); |
| 505 return true; | 506 return true; |
| 506 } | 507 } |
| 507 // Check if either a gesture is taking place (=> bubble stays no matter what | 508 // Check if either a gesture is taking place (=> bubble stays no matter what |
| 508 // the mouse does) or the mouse is over the maximize button or the bubble | 509 // the mouse does) or the mouse is over the maximize button or the bubble |
| 509 // content. | 510 // content. |
| 510 return (owner_->frame_maximize_button()->is_snap_enabled() || | 511 return (owner_->frame_maximize_button()->is_snap_enabled() || |
| 511 inside_button || | 512 inside_button || |
| 512 contents_view_->GetBoundsInScreen().Contains(screen_point)); | 513 contents_view_->GetBoundsInScreen().Contains(screen_point)); |
| 513 } | 514 } |
| 514 | 515 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 MaximizeBubbleController::Bubble* bubble) | 562 MaximizeBubbleController::Bubble* bubble) |
| 562 : bubble_(bubble), | 563 : bubble_(bubble), |
| 563 left_button_(NULL), | 564 left_button_(NULL), |
| 564 minimize_button_(NULL), | 565 minimize_button_(NULL), |
| 565 right_button_(NULL) { | 566 right_button_(NULL) { |
| 566 SetLayoutManager(new views::BoxLayout( | 567 SetLayoutManager(new views::BoxLayout( |
| 567 views::BoxLayout::kHorizontal, 0, 0, kLayoutSpacing)); | 568 views::BoxLayout::kHorizontal, 0, 0, kLayoutSpacing)); |
| 568 set_background( | 569 set_background( |
| 569 views::Background::CreateSolidBackground(kBubbleBackgroundColor)); | 570 views::Background::CreateSolidBackground(kBubbleBackgroundColor)); |
| 570 | 571 |
| 571 left_button_ = new BubbleDialogButton( | 572 if (bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_LEFT) { |
| 572 this, | 573 left_button_ = new BubbleDialogButton( |
| 573 IDR_AURA_WINDOW_POSITION_LEFT, | 574 this, |
| 574 IDR_AURA_WINDOW_POSITION_LEFT_H, | 575 IDR_AURA_WINDOW_POSITION_LEFT_RESTORE, |
| 575 IDR_AURA_WINDOW_POSITION_LEFT_P); | 576 IDR_AURA_WINDOW_POSITION_LEFT_RESTORE_H, |
| 577 IDR_AURA_WINDOW_POSITION_LEFT_RESTORE_P); |
| 578 } else { |
| 579 left_button_ = new BubbleDialogButton( |
| 580 this, |
| 581 IDR_AURA_WINDOW_POSITION_LEFT, |
| 582 IDR_AURA_WINDOW_POSITION_LEFT_H, |
| 583 IDR_AURA_WINDOW_POSITION_LEFT_P); |
| 584 } |
| 576 minimize_button_ = new BubbleDialogButton( | 585 minimize_button_ = new BubbleDialogButton( |
| 577 this, | 586 this, |
| 578 IDR_AURA_WINDOW_POSITION_MIDDLE, | 587 IDR_AURA_WINDOW_POSITION_MIDDLE, |
| 579 IDR_AURA_WINDOW_POSITION_MIDDLE_H, | 588 IDR_AURA_WINDOW_POSITION_MIDDLE_H, |
| 580 IDR_AURA_WINDOW_POSITION_MIDDLE_P); | 589 IDR_AURA_WINDOW_POSITION_MIDDLE_P); |
| 581 right_button_ = new BubbleDialogButton( | 590 if (bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_RIGHT) { |
| 582 this, | 591 right_button_ = new BubbleDialogButton( |
| 583 IDR_AURA_WINDOW_POSITION_RIGHT, | 592 this, |
| 584 IDR_AURA_WINDOW_POSITION_RIGHT_H, | 593 IDR_AURA_WINDOW_POSITION_RIGHT_RESTORE, |
| 585 IDR_AURA_WINDOW_POSITION_RIGHT_P); | 594 IDR_AURA_WINDOW_POSITION_RIGHT_RESTORE_H, |
| 595 IDR_AURA_WINDOW_POSITION_RIGHT_RESTORE_P); |
| 596 } else { |
| 597 right_button_ = new BubbleDialogButton( |
| 598 this, |
| 599 IDR_AURA_WINDOW_POSITION_RIGHT, |
| 600 IDR_AURA_WINDOW_POSITION_RIGHT_H, |
| 601 IDR_AURA_WINDOW_POSITION_RIGHT_P); |
| 602 } |
| 586 } | 603 } |
| 587 | 604 |
| 588 // Overridden from ButtonListener. | 605 // Overridden from ButtonListener. |
| 589 void BubbleContentsButtonRow::ButtonPressed(views::Button* sender, | 606 void BubbleContentsButtonRow::ButtonPressed(views::Button* sender, |
| 590 const ui::Event& event) { | 607 const ui::Event& event) { |
| 591 // While shutting down, the connection to the owner might already be broken. | 608 // While shutting down, the connection to the owner might already be broken. |
| 592 if (!bubble_->controller()) | 609 if (!bubble_->controller()) |
| 593 return; | 610 return; |
| 594 if (sender == left_button_) | 611 if (sender == left_button_) |
| 595 bubble_->controller()->OnButtonClicked(SNAP_LEFT); | 612 bubble_->controller()->OnButtonClicked( |
| 613 bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_LEFT ? |
| 614 SNAP_RESTORE : SNAP_LEFT); |
| 596 else if (sender == minimize_button_) | 615 else if (sender == minimize_button_) |
| 597 bubble_->controller()->OnButtonClicked(SNAP_MINIMIZE); | 616 bubble_->controller()->OnButtonClicked(SNAP_MINIMIZE); |
| 598 else if (sender == right_button_) | 617 else if (sender == right_button_) |
| 599 bubble_->controller()->OnButtonClicked(SNAP_RIGHT); | 618 bubble_->controller()->OnButtonClicked( |
| 619 bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_RIGHT ? |
| 620 SNAP_RESTORE : SNAP_RIGHT); |
| 600 else | 621 else |
| 601 NOTREACHED() << "Unknown button pressed."; | 622 NOTREACHED() << "Unknown button pressed."; |
| 602 } | 623 } |
| 603 | 624 |
| 604 // Called from BubbleDialogButton. | 625 // Called from BubbleDialogButton. |
| 605 void BubbleContentsButtonRow::ButtonHovered(BubbleDialogButton* sender) { | 626 void BubbleContentsButtonRow::ButtonHovered(BubbleDialogButton* sender) { |
| 606 // While shutting down, the connection to the owner might already be broken. | 627 // While shutting down, the connection to the owner might already be broken. |
| 607 if (!bubble_->controller()) | 628 if (!bubble_->controller()) |
| 608 return; | 629 return; |
| 609 if (sender == left_button_) | 630 if (sender == left_button_) |
| 610 bubble_->controller()->OnButtonHover(SNAP_LEFT); | 631 bubble_->controller()->OnButtonHover( |
| 632 bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_LEFT ? |
| 633 SNAP_RESTORE : SNAP_LEFT); |
| 611 else if (sender == minimize_button_) | 634 else if (sender == minimize_button_) |
| 612 bubble_->controller()->OnButtonHover(SNAP_MINIMIZE); | 635 bubble_->controller()->OnButtonHover(SNAP_MINIMIZE); |
| 613 else if (sender == right_button_) | 636 else if (sender == right_button_) |
| 614 bubble_->controller()->OnButtonHover(SNAP_RIGHT); | 637 bubble_->controller()->OnButtonHover( |
| 638 bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_RIGHT ? |
| 639 SNAP_RESTORE : SNAP_RIGHT); |
| 615 else | 640 else |
| 616 bubble_->controller()->OnButtonHover(SNAP_NONE); | 641 bubble_->controller()->OnButtonHover(SNAP_NONE); |
| 617 } | 642 } |
| 618 | 643 |
| 619 views::CustomButton* BubbleContentsButtonRow::GetButtonForUnitTest( | 644 views::CustomButton* BubbleContentsButtonRow::GetButtonForUnitTest( |
| 620 SnapType state) { | 645 SnapType state) { |
| 621 switch (state) { | 646 switch (state) { |
| 622 case SNAP_LEFT: | 647 case SNAP_LEFT: |
| 623 return left_button_; | 648 return left_button_; |
| 624 case SNAP_MINIMIZE: | 649 case SNAP_MINIMIZE: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 689 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 665 int id = 0; | 690 int id = 0; |
| 666 switch (snap_type) { | 691 switch (snap_type) { |
| 667 case SNAP_LEFT: | 692 case SNAP_LEFT: |
| 668 id = IDS_ASH_SNAP_WINDOW_LEFT; | 693 id = IDS_ASH_SNAP_WINDOW_LEFT; |
| 669 break; | 694 break; |
| 670 case SNAP_RIGHT: | 695 case SNAP_RIGHT: |
| 671 id = IDS_ASH_SNAP_WINDOW_RIGHT; | 696 id = IDS_ASH_SNAP_WINDOW_RIGHT; |
| 672 break; | 697 break; |
| 673 case SNAP_MAXIMIZE: | 698 case SNAP_MAXIMIZE: |
| 674 DCHECK(!bubble_->controller()->is_maximized()); | 699 DCHECK_NE(FRAME_STATE_FULL, bubble_->controller()->maximize_type()); |
| 675 id = IDS_ASH_MAXIMIZE_WINDOW; | 700 id = IDS_ASH_MAXIMIZE_WINDOW; |
| 676 break; | 701 break; |
| 677 case SNAP_MINIMIZE: | 702 case SNAP_MINIMIZE: |
| 678 id = IDS_ASH_MINIMIZE_WINDOW; | 703 id = IDS_ASH_MINIMIZE_WINDOW; |
| 679 break; | 704 break; |
| 680 case SNAP_RESTORE: | 705 case SNAP_RESTORE: |
| 681 DCHECK(bubble_->controller()->is_maximized()); | 706 DCHECK_NE(FRAME_STATE_NONE, bubble_->controller()->maximize_type()); |
| 682 id = IDS_ASH_RESTORE_WINDOW; | 707 id = IDS_ASH_RESTORE_WINDOW; |
| 683 break; | 708 break; |
| 684 default: | 709 default: |
| 685 // If nothing is selected, we automatically select the click operation. | 710 // If nothing is selected, we automatically select the click operation. |
| 686 id = bubble_->controller()->is_maximized() ? IDS_ASH_RESTORE_WINDOW : | 711 id = bubble_->controller()->maximize_type() ? IDS_ASH_RESTORE_WINDOW : |
| 687 IDS_ASH_MAXIMIZE_WINDOW; | 712 IDS_ASH_MAXIMIZE_WINDOW; |
| 688 break; | 713 break; |
| 689 } | 714 } |
| 690 label_view_->SetText(rb.GetLocalizedString(id)); | 715 label_view_->SetText(rb.GetLocalizedString(id)); |
| 691 } | 716 } |
| 692 | 717 |
| 693 MaximizeBubbleController::MaximizeBubbleController( | 718 MaximizeBubbleController::MaximizeBubbleController( |
| 694 FrameMaximizeButton* frame_maximize_button, | 719 FrameMaximizeButton* frame_maximize_button, |
| 695 bool is_maximized, | 720 MaximizeBubbleFrameState maximize_type, |
| 696 int appearance_delay_ms) | 721 int appearance_delay_ms) |
| 697 : frame_maximize_button_(frame_maximize_button), | 722 : frame_maximize_button_(frame_maximize_button), |
| 698 bubble_(NULL), | 723 bubble_(NULL), |
| 699 is_maximized_(is_maximized), | 724 maximize_type_(maximize_type), |
| 700 appearance_delay_ms_(appearance_delay_ms) { | 725 appearance_delay_ms_(appearance_delay_ms) { |
| 701 // Create the task which will create the bubble delayed. | 726 // Create the task which will create the bubble delayed. |
| 702 base::OneShotTimer<MaximizeBubbleController>* new_timer = | 727 base::OneShotTimer<MaximizeBubbleController>* new_timer = |
| 703 new base::OneShotTimer<MaximizeBubbleController>(); | 728 new base::OneShotTimer<MaximizeBubbleController>(); |
| 704 // Note: Even if there was no delay time given, we need to have a timer. | 729 // Note: Even if there was no delay time given, we need to have a timer. |
| 705 new_timer->Start( | 730 new_timer->Start( |
| 706 FROM_HERE, | 731 FROM_HERE, |
| 707 base::TimeDelta::FromMilliseconds( | 732 base::TimeDelta::FromMilliseconds( |
| 708 appearance_delay_ms_ ? appearance_delay_ms_ : 10), | 733 appearance_delay_ms_ ? appearance_delay_ms_ : 10), |
| 709 this, | 734 this, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 if (!GetBoundsInScreen().Contains(screen_location)) | 831 if (!GetBoundsInScreen().Contains(screen_location)) |
| 807 button_row_->ButtonHovered(NULL); | 832 button_row_->ButtonHovered(NULL); |
| 808 else | 833 else |
| 809 button_row_->ButtonHovered(this); | 834 button_row_->ButtonHovered(this); |
| 810 | 835 |
| 811 // Pass the event on to the normal handler. | 836 // Pass the event on to the normal handler. |
| 812 return views::ImageButton::OnMouseDragged(event); | 837 return views::ImageButton::OnMouseDragged(event); |
| 813 } | 838 } |
| 814 | 839 |
| 815 } // namespace ash | 840 } // namespace ash |
| OLD | NEW |