Chromium Code Reviews| 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" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 void FrameMaximizeButton::OnMouseEntered(const ui::MouseEvent& event) { | 205 void FrameMaximizeButton::OnMouseEntered(const ui::MouseEvent& event) { |
| 206 ImageButton::OnMouseEntered(event); | 206 ImageButton::OnMouseEntered(event); |
| 207 if (!maximizer_.get()) { | 207 if (!maximizer_.get()) { |
| 208 DCHECK(GetWidget()); | 208 DCHECK(GetWidget()); |
| 209 if (!window_) { | 209 if (!window_) { |
| 210 window_ = frame_->GetWidget()->GetNativeWindow(); | 210 window_ = frame_->GetWidget()->GetNativeWindow(); |
| 211 window_->AddObserver(this); | 211 window_->AddObserver(this); |
| 212 } | 212 } |
| 213 maximizer_.reset(new MaximizeBubbleController( | 213 maximizer_.reset(new MaximizeBubbleController( |
| 214 this, | 214 this, |
| 215 frame_->GetWidget()->IsMaximized(), | 215 GetMaximizeType(), |
| 216 bubble_appearance_delay_ms_)); | 216 bubble_appearance_delay_ms_)); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 void FrameMaximizeButton::OnMouseExited(const ui::MouseEvent& event) { | 220 void FrameMaximizeButton::OnMouseExited(const ui::MouseEvent& event) { |
| 221 ImageButton::OnMouseExited(event); | 221 ImageButton::OnMouseExited(event); |
| 222 // Remove the bubble menu when the button is not pressed and the mouse is not | 222 // Remove the bubble menu when the button is not pressed and the mouse is not |
| 223 // within the bubble. | 223 // within the bubble. |
| 224 if (!is_snap_enabled_ && maximizer_.get()) { | 224 if (!is_snap_enabled_ && maximizer_.get()) { |
| 225 if (maximizer_->GetBubbleWindow()) { | 225 if (maximizer_->GetBubbleWindow()) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE || | 291 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE || |
| 292 event.type() == ui::ET_GESTURE_SCROLL_BEGIN) { | 292 event.type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
| 293 ProcessUpdateEvent(event); | 293 ProcessUpdateEvent(event); |
| 294 return ui::GESTURE_STATUS_CONSUMED; | 294 return ui::GESTURE_STATUS_CONSUMED; |
| 295 } | 295 } |
| 296 } | 296 } |
| 297 | 297 |
| 298 return ImageButton::OnGestureEvent(event); | 298 return ImageButton::OnGestureEvent(event); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void FrameMaximizeButton::ToggleMaximize() { | |
| 302 if (frame_->GetWidget()->IsMaximized()) | |
| 303 frame_->GetWidget()->Restore(); | |
| 304 else | |
| 305 Maximize(); | |
| 306 } | |
| 307 | |
| 301 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { | 308 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { |
| 302 DCHECK(is_snap_enabled_); | 309 DCHECK(is_snap_enabled_); |
| 303 // Prepare the help menu. | 310 // Prepare the help menu. |
| 304 if (!maximizer_.get()) { | 311 if (!maximizer_.get()) { |
| 305 maximizer_.reset(new MaximizeBubbleController( | 312 maximizer_.reset(new MaximizeBubbleController( |
| 306 this, | 313 this, |
| 307 frame_->GetWidget()->IsMaximized(), | 314 GetMaximizeType(), |
| 308 bubble_appearance_delay_ms_)); | 315 bubble_appearance_delay_ms_)); |
| 309 } else { | 316 } else { |
| 310 // If the menu did not show up yet, we delay it even a bit more. | 317 // If the menu did not show up yet, we delay it even a bit more. |
| 311 maximizer_->DelayCreation(); | 318 maximizer_->DelayCreation(); |
| 312 } | 319 } |
| 313 snap_sizer_.reset(NULL); | 320 snap_sizer_.reset(NULL); |
| 314 InstallEventFilter(); | 321 InstallEventFilter(); |
| 315 snap_type_ = SNAP_NONE; | 322 snap_type_ = SNAP_NONE; |
| 316 press_location_ = event.location(); | 323 press_location_ = event.location(); |
| 317 exceeded_drag_threshold_ = false; | 324 exceeded_drag_threshold_ = false; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 } | 432 } |
| 426 if (maximizer_.get()) { | 433 if (maximizer_.get()) { |
| 427 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); | 434 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); |
| 428 maximizer_->SetSnapType(snap_type_); | 435 maximizer_->SetSnapType(snap_type_); |
| 429 } | 436 } |
| 430 phantom_window_->Show(ScreenBoundsForType(snap_type_, *snap_sizer_.get())); | 437 phantom_window_->Show(ScreenBoundsForType(snap_type_, *snap_sizer_.get())); |
| 431 } | 438 } |
| 432 | 439 |
| 433 SnapType FrameMaximizeButton::SnapTypeForLocation( | 440 SnapType FrameMaximizeButton::SnapTypeForLocation( |
| 434 const gfx::Point& location) const { | 441 const gfx::Point& location) const { |
| 442 MaximizeType maximize_type = GetMaximizeType(); | |
| 435 int delta_x = location.x() - press_location_.x(); | 443 int delta_x = location.x() - press_location_.x(); |
| 436 int delta_y = location.y() - press_location_.y(); | 444 int delta_y = location.y() - press_location_.y(); |
| 437 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) | 445 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) |
| 438 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; | 446 return maximize_type != MAXIMIZE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; |
| 439 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) | 447 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) |
| 440 return SNAP_LEFT; | 448 return maximize_type == MAXIMIZE_LEFT ? SNAP_RESTORE : SNAP_LEFT; |
| 441 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) | 449 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) |
| 442 return SNAP_RIGHT; | 450 return maximize_type == MAXIMIZE_RIGHT ? SNAP_RESTORE : SNAP_RIGHT; |
| 443 else if (delta_y > 0) | 451 else if (delta_y > 0) |
| 444 return SNAP_MINIMIZE; | 452 return SNAP_MINIMIZE; |
| 445 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; | 453 return maximize_type != MAXIMIZE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; |
| 446 } | 454 } |
| 447 | 455 |
| 448 gfx::Rect FrameMaximizeButton::ScreenBoundsForType( | 456 gfx::Rect FrameMaximizeButton::ScreenBoundsForType( |
| 449 SnapType type, | 457 SnapType type, |
| 450 const SnapSizer& snap_sizer) const { | 458 const SnapSizer& snap_sizer) const { |
| 451 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); | 459 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); |
| 452 switch (type) { | 460 switch (type) { |
| 453 case SNAP_LEFT: | 461 case SNAP_LEFT: |
| 454 case SNAP_RIGHT: | 462 case SNAP_RIGHT: |
| 455 return ScreenAsh::ConvertRectToScreen( | 463 return ScreenAsh::ConvertRectToScreen( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 482 } | 490 } |
| 483 | 491 |
| 484 gfx::Point FrameMaximizeButton::LocationForSnapSizer( | 492 gfx::Point FrameMaximizeButton::LocationForSnapSizer( |
| 485 const gfx::Point& location) const { | 493 const gfx::Point& location) const { |
| 486 gfx::Point result(location); | 494 gfx::Point result(location); |
| 487 views::View::ConvertPointToScreen(this, &result); | 495 views::View::ConvertPointToScreen(this, &result); |
| 488 return result; | 496 return result; |
| 489 } | 497 } |
| 490 | 498 |
| 491 void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) { | 499 void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) { |
| 500 views::Widget* widget = frame_->GetWidget(); | |
| 492 switch (snap_type_) { | 501 switch (snap_type_) { |
| 493 case SNAP_LEFT: | 502 case SNAP_LEFT: |
| 494 case SNAP_RIGHT: | 503 case SNAP_RIGHT: { |
| 495 if (frame_->GetWidget()->IsMaximized()) { | 504 // Get the window coordinates on the screen for restore purposes. |
| 505 gfx::Rect restore = frame_->GetWidget()->GetNativeWindow()->bounds(); | |
| 506 if (frame_->GetWidget()->IsMaximized()) { | |
| 507 // If it was maximized we need to recover the old restore set. | |
| 508 restore = *ash::GetRestoreBoundsInScreen( | |
| 509 frame_->GetWidget()->GetNativeWindow()); | |
| 510 // Set the restore size we want to restore to. | |
| 511 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), | |
| 512 ScreenBoundsForType(snap_type_, | |
| 513 snap_sizer)); | |
| 514 frame_->GetWidget()->Restore(); | |
| 515 } else { | |
| 516 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_, | |
| 517 snap_sizer)); | |
| 518 } | |
| 519 // Remember the widow's bounds for restoration. | |
| 496 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), | 520 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), |
| 497 ScreenBoundsForType(snap_type_, | 521 restore); |
| 498 snap_sizer)); | |
| 499 frame_->GetWidget()->Restore(); | |
| 500 } else { | |
| 501 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_, | |
| 502 snap_sizer)); | |
| 503 } | 522 } |
| 504 break; | 523 break; |
| 505 case SNAP_MAXIMIZE: | 524 case SNAP_MAXIMIZE: |
| 506 frame_->GetWidget()->Maximize(); | 525 Maximize(); |
| 507 break; | 526 break; |
| 508 case SNAP_MINIMIZE: | 527 case SNAP_MINIMIZE: |
| 509 frame_->GetWidget()->Minimize(); | 528 widget->Minimize(); |
| 510 break; | 529 break; |
| 511 case SNAP_RESTORE: | 530 case SNAP_RESTORE: |
| 512 frame_->GetWidget()->Restore(); | 531 widget->Restore(); |
| 513 break; | 532 break; |
| 514 case SNAP_NONE: | 533 case SNAP_NONE: |
| 515 NOTREACHED(); | 534 NOTREACHED(); |
| 516 } | 535 } |
| 517 } | 536 } |
| 518 | 537 |
| 538 MaximizeType FrameMaximizeButton::GetMaximizeType() const { | |
| 539 // When there are no restore bounds, we are in normal mode. | |
| 540 if (!ash::GetRestoreBoundsInScreen( | |
| 541 frame_->GetWidget()->GetNativeWindow())) | |
| 542 return MAXIMIZE_NONE; | |
| 543 // The normal maximized test can be used. | |
| 544 if (frame_->GetWidget()->IsMaximized()) | |
| 545 return MAXIMIZE_FULL; | |
| 546 // For Left/right maximize we need to check the dimensions. | |
| 547 gfx::Rect bounds = frame_->GetWidget()->GetNativeWindow()->bounds(); | |
| 548 gfx::Rect screen = gfx::Screen::GetDisplayMatching(bounds).work_area(); | |
| 549 // We have to be in a maximize mode at this point. | |
| 550 DCHECK(!bounds.y()); | |
|
sky
2012/08/27 22:18:16
Why does the x/y need to be 0 here? Might it diffe
Mr4D (OOO till 08-26)
2012/08/28 01:30:25
Very good point! Changed!
| |
| 551 DCHECK(bounds.height() >= screen.height()); | |
| 552 if (!bounds.x()) | |
| 553 return MAXIMIZE_LEFT; | |
| 554 if (bounds.right() == screen.right()) | |
| 555 return MAXIMIZE_RIGHT; | |
| 556 NOTREACHED(); | |
| 557 return MAXIMIZE_NONE; | |
| 558 } | |
| 559 | |
| 560 void FrameMaximizeButton::Maximize() { | |
| 561 views::Widget* widget = frame_->GetWidget(); | |
| 562 MaximizeType maximize_type = GetMaximizeType(); | |
| 563 if (maximize_type == MAXIMIZE_LEFT || maximize_type == MAXIMIZE_RIGHT) { | |
| 564 aura::Window* window = widget->GetNativeWindow(); | |
| 565 gfx::Rect restore = *ash::GetRestoreBoundsInScreen(window); | |
| 566 widget->Maximize(); | |
| 567 ash::SetRestoreBoundsInScreen(window, restore); | |
| 568 } else { | |
| 569 widget->Maximize(); | |
| 570 } | |
| 571 // Note: |This| might be destroyed at this time. | |
| 572 } | |
| 573 | |
| 519 } // namespace ash | 574 } // namespace ash |
| OLD | NEW |