| 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/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 // FrameMaximizeButton --------------------------------------------------------- | 82 // FrameMaximizeButton --------------------------------------------------------- |
| 83 | 83 |
| 84 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, | 84 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, |
| 85 views::NonClientFrameView* frame) | 85 views::NonClientFrameView* frame) |
| 86 : ImageButton(listener), | 86 : ImageButton(listener), |
| 87 frame_(frame), | 87 frame_(frame), |
| 88 is_snap_enabled_(false), | 88 is_snap_enabled_(false), |
| 89 exceeded_drag_threshold_(false), | 89 exceeded_drag_threshold_(false), |
| 90 widget_(NULL), | 90 widget_(NULL), |
| 91 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 (ash::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 (widget_) | 104 if (widget_) |
| 106 OnWindowDestroying(widget_->GetNativeWindow()); | 105 OnWindowDestroying(widget_->GetNativeWindow()); |
| 107 } | 106 } |
| 108 | 107 |
| 109 void FrameMaximizeButton::SnapButtonHovered(SnapType type) { | 108 void FrameMaximizeButton::SnapButtonHovered(SnapType type) { |
| 110 // Make sure to only show hover operations when no button is pressed and | 109 // Make sure to only show hover operations when no button is pressed and |
| 111 // a similar snap operation in progress does not get re-applied. | 110 // a similar snap operation in progress does not get re-applied. |
| 112 if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_)) | 111 if (is_snap_enabled_) |
| 113 return; | 112 return; |
| 114 // Prime the mouse location with the center of the (local) button. | 113 // Prime the mouse location with the center of the (local) button. |
| 115 press_location_ = gfx::Point(width() / 2, height() / 2); | 114 press_location_ = gfx::Point(width() / 2, height() / 2); |
| 116 // Then get an adjusted mouse position to initiate the effect. | 115 // Then get an adjusted mouse position to initiate the effect. |
| 117 gfx::Point location = press_location_; | 116 gfx::Point location = press_location_; |
| 118 switch (type) { | 117 switch (type) { |
| 119 case SNAP_LEFT: | 118 case SNAP_LEFT: |
| 120 location.set_x(location.x() - width()); | 119 location.set_x(location.x() - width()); |
| 121 break; | 120 break; |
| 122 case SNAP_RIGHT: | 121 case SNAP_RIGHT: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 134 break; | 133 break; |
| 135 case SNAP_MAXIMIZE: | 134 case SNAP_MAXIMIZE: |
| 136 break; | 135 break; |
| 137 case SNAP_NONE: | 136 case SNAP_NONE: |
| 138 Cancel(true); | 137 Cancel(true); |
| 139 return; | 138 return; |
| 140 default: | 139 default: |
| 141 // We should not come here. | 140 // We should not come here. |
| 142 NOTREACHED(); | 141 NOTREACHED(); |
| 143 } | 142 } |
| 144 // Note: There is no hover with touch - we can therefore pass false for touch | 143 UpdateSnap(location); |
| 145 // operations. | |
| 146 UpdateSnap(location, true, false); | |
| 147 } | 144 } |
| 148 | 145 |
| 149 void FrameMaximizeButton::ExecuteSnapAndCloseMenu(SnapType snap_type) { | 146 void FrameMaximizeButton::ExecuteSnapAndCloseMenu(SnapType snap_type) { |
| 150 // We can come here with no snap type set in case that the mouse opened the | 147 // We can come here with no snap type set in case that the mouse opened the |
| 151 // maximize button and a touch event "touched" a button. | 148 // maximize button and a touch event "touched" a button. |
| 152 if (snap_type_ == SNAP_NONE) | 149 if (snap_type_ == SNAP_NONE) |
| 153 SnapButtonHovered(snap_type); | 150 SnapButtonHovered(snap_type); |
| 154 | 151 |
| 155 Cancel(true); | 152 Cancel(true); |
| 156 // Tell our menu to close. | 153 // Tell our menu to close. |
| 157 maximizer_.reset(); | 154 maximizer_.reset(); |
| 158 snap_type_ = snap_type; | 155 snap_type_ = snap_type; |
| 159 // Since Snap might destroy |this|, but the snap_sizer needs to be destroyed, | 156 Snap(); |
| 160 // The ownership of the snap_sizer is taken now. | |
| 161 scoped_ptr<SnapSizer> snap_sizer(snap_sizer_.release()); | |
| 162 Snap(*snap_sizer.get()); | |
| 163 } | 157 } |
| 164 | 158 |
| 165 void FrameMaximizeButton::DestroyMaximizeMenu() { | 159 void FrameMaximizeButton::DestroyMaximizeMenu() { |
| 166 Cancel(false); | 160 Cancel(false); |
| 167 } | 161 } |
| 168 | 162 |
| 169 void FrameMaximizeButton::OnWindowBoundsChanged( | 163 void FrameMaximizeButton::OnWindowBoundsChanged( |
| 170 aura::Window* window, | 164 aura::Window* window, |
| 171 const gfx::Rect& old_bounds, | 165 const gfx::Rect& old_bounds, |
| 172 const gfx::Rect& new_bounds) { | 166 const gfx::Rect& new_bounds) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // Prepare the help menu. | 325 // Prepare the help menu. |
| 332 if (!maximizer_) { | 326 if (!maximizer_) { |
| 333 maximizer_.reset(new MaximizeBubbleController( | 327 maximizer_.reset(new MaximizeBubbleController( |
| 334 this, | 328 this, |
| 335 GetMaximizeBubbleFrameState(), | 329 GetMaximizeBubbleFrameState(), |
| 336 bubble_appearance_delay_ms_)); | 330 bubble_appearance_delay_ms_)); |
| 337 } else { | 331 } else { |
| 338 // If the menu did not show up yet, we delay it even a bit more. | 332 // If the menu did not show up yet, we delay it even a bit more. |
| 339 maximizer_->DelayCreation(); | 333 maximizer_->DelayCreation(); |
| 340 } | 334 } |
| 341 snap_sizer_.reset(NULL); | |
| 342 InstallEventFilter(); | 335 InstallEventFilter(); |
| 343 snap_type_ = SNAP_NONE; | 336 snap_type_ = SNAP_NONE; |
| 344 press_location_ = event.location(); | 337 press_location_ = event.location(); |
| 345 press_is_gesture_ = event.IsGestureEvent(); | |
| 346 exceeded_drag_threshold_ = false; | 338 exceeded_drag_threshold_ = false; |
| 347 update_timer_.Start( | 339 update_timer_.Start( |
| 348 FROM_HERE, | 340 FROM_HERE, |
| 349 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), | 341 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), |
| 350 this, | 342 this, |
| 351 &FrameMaximizeButton::UpdateSnapFromEventLocation); | 343 &FrameMaximizeButton::UpdateSnapFromEventLocation); |
| 352 } | 344 } |
| 353 | 345 |
| 354 void FrameMaximizeButton::ProcessUpdateEvent(const ui::LocatedEvent& event) { | 346 void FrameMaximizeButton::ProcessUpdateEvent(const ui::LocatedEvent& event) { |
| 355 DCHECK(is_snap_enabled_); | 347 DCHECK(is_snap_enabled_); |
| 356 if (!exceeded_drag_threshold_) { | 348 if (!exceeded_drag_threshold_) { |
| 357 exceeded_drag_threshold_ = views::View::ExceededDragThreshold( | 349 exceeded_drag_threshold_ = views::View::ExceededDragThreshold( |
| 358 event.location() - press_location_); | 350 event.location() - press_location_); |
| 359 } | 351 } |
| 360 if (exceeded_drag_threshold_) | 352 if (exceeded_drag_threshold_) |
| 361 UpdateSnap(event.location(), false, event.IsGestureEvent()); | 353 UpdateSnap(event.location()); |
| 362 } | 354 } |
| 363 | 355 |
| 364 bool FrameMaximizeButton::ProcessEndEvent(const ui::LocatedEvent& event) { | 356 bool FrameMaximizeButton::ProcessEndEvent(const ui::LocatedEvent& event) { |
| 365 update_timer_.Stop(); | 357 update_timer_.Stop(); |
| 366 UninstallEventFilter(); | 358 UninstallEventFilter(); |
| 367 bool should_snap = is_snap_enabled_; | 359 bool should_snap = is_snap_enabled_; |
| 368 is_snap_enabled_ = false; | 360 is_snap_enabled_ = false; |
| 369 | 361 |
| 370 // Remove our help bubble. | 362 // Remove our help bubble. |
| 371 maximizer_.reset(); | 363 maximizer_.reset(); |
| 372 | 364 |
| 373 if (!should_snap || snap_type_ == SNAP_NONE) | 365 if (!should_snap || snap_type_ == SNAP_NONE) |
| 374 return false; | 366 return false; |
| 375 | 367 |
| 376 SetState(views::CustomButton::STATE_NORMAL); | 368 SetState(views::CustomButton::STATE_NORMAL); |
| 377 // SetState will not call SchedulePaint() if state was already set to | 369 // SetState will not call SchedulePaint() if state was already set to |
| 378 // STATE_NORMAL during a drag. | 370 // STATE_NORMAL during a drag. |
| 379 SchedulePaint(); | 371 SchedulePaint(); |
| 380 phantom_window_.reset(); | 372 phantom_window_.reset(); |
| 381 // Since Snap might destroy |this|, but the snap_sizer needs to be destroyed, | 373 Snap(); |
| 382 // The ownership of the snap_sizer is taken now. | |
| 383 scoped_ptr<SnapSizer> snap_sizer(snap_sizer_.release()); | |
| 384 Snap(*snap_sizer.get()); | |
| 385 return true; | 374 return true; |
| 386 } | 375 } |
| 387 | 376 |
| 388 void FrameMaximizeButton::Cancel(bool keep_menu_open) { | 377 void FrameMaximizeButton::Cancel(bool keep_menu_open) { |
| 389 if (!keep_menu_open) { | 378 if (!keep_menu_open) { |
| 390 maximizer_.reset(); | 379 maximizer_.reset(); |
| 391 UninstallEventFilter(); | 380 UninstallEventFilter(); |
| 392 is_snap_enabled_ = false; | 381 is_snap_enabled_ = false; |
| 393 snap_sizer_.reset(); | |
| 394 } | 382 } |
| 395 phantom_window_.reset(); | 383 phantom_window_.reset(); |
| 396 snap_type_ = SNAP_NONE; | 384 snap_type_ = SNAP_NONE; |
| 397 update_timer_.Stop(); | 385 update_timer_.Stop(); |
| 398 SchedulePaint(); | 386 SchedulePaint(); |
| 399 } | 387 } |
| 400 | 388 |
| 401 void FrameMaximizeButton::InstallEventFilter() { | 389 void FrameMaximizeButton::InstallEventFilter() { |
| 402 if (escape_event_filter_) | 390 if (escape_event_filter_) |
| 403 return; | 391 return; |
| 404 | 392 |
| 405 escape_event_filter_.reset(new EscapeEventFilter(this)); | 393 escape_event_filter_.reset(new EscapeEventFilter(this)); |
| 406 } | 394 } |
| 407 | 395 |
| 408 void FrameMaximizeButton::UninstallEventFilter() { | 396 void FrameMaximizeButton::UninstallEventFilter() { |
| 409 escape_event_filter_.reset(NULL); | 397 escape_event_filter_.reset(NULL); |
| 410 } | 398 } |
| 411 | 399 |
| 412 void FrameMaximizeButton::UpdateSnapFromEventLocation() { | 400 void FrameMaximizeButton::UpdateSnapFromEventLocation() { |
| 413 // If the drag threshold has been exceeded the snap location is up to date. | 401 // If the drag threshold has been exceeded the snap location is up to date. |
| 414 if (exceeded_drag_threshold_) | 402 if (exceeded_drag_threshold_) |
| 415 return; | 403 return; |
| 416 exceeded_drag_threshold_ = true; | 404 exceeded_drag_threshold_ = true; |
| 417 UpdateSnap(press_location_, false, press_is_gesture_); | 405 UpdateSnap(press_location_); |
| 418 } | 406 } |
| 419 | 407 |
| 420 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location, | 408 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { |
| 421 bool select_default, | |
| 422 bool is_touch) { | |
| 423 SnapType type = SnapTypeForLocation(location); | 409 SnapType type = SnapTypeForLocation(location); |
| 424 if (type == snap_type_) { | 410 if (type == snap_type_) |
| 425 if (snap_sizer_) { | |
| 426 snap_sizer_->Update(LocationForSnapSizer(location)); | |
| 427 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( | |
| 428 frame_->GetWidget()->GetNativeView()->parent(), | |
| 429 snap_sizer_->target_bounds())); | |
| 430 } | |
| 431 return; | 411 return; |
| 432 } | |
| 433 | 412 |
| 434 snap_type_ = type; | 413 snap_type_ = type; |
| 435 snap_sizer_.reset(); | |
| 436 SchedulePaint(); | 414 SchedulePaint(); |
| 437 | 415 |
| 438 if (snap_type_ == SNAP_NONE) { | 416 if (snap_type_ == SNAP_NONE) { |
| 439 phantom_window_.reset(); | 417 phantom_window_.reset(); |
| 440 return; | 418 return; |
| 441 } | 419 } |
| 442 | 420 |
| 443 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) { | |
| 444 SnapSizer::Edge snap_edge = snap_type_ == SNAP_LEFT ? | |
| 445 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; | |
| 446 SnapSizer::InputType input_type = | |
| 447 is_touch ? SnapSizer::TOUCH_MAXIMIZE_BUTTON_INPUT : | |
| 448 SnapSizer::OTHER_INPUT; | |
| 449 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), | |
| 450 LocationForSnapSizer(location), | |
| 451 snap_edge, | |
| 452 input_type)); | |
| 453 if (select_default) | |
| 454 snap_sizer_->SelectDefaultSizeAndDisableResize(); | |
| 455 } | |
| 456 if (!phantom_window_) { | 421 if (!phantom_window_) { |
| 457 phantom_window_.reset(new internal::PhantomWindowController( | 422 phantom_window_.reset(new internal::PhantomWindowController( |
| 458 frame_->GetWidget()->GetNativeWindow())); | 423 frame_->GetWidget()->GetNativeWindow())); |
| 459 } | 424 } |
| 460 if (maximizer_) { | 425 if (maximizer_) { |
| 461 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); | 426 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); |
| 462 maximizer_->SetSnapType(snap_type_); | 427 maximizer_->SetSnapType(snap_type_); |
| 463 } | 428 } |
| 464 phantom_window_->Show( | 429 phantom_window_->Show(ScreenBoundsForType(snap_type_)); |
| 465 ScreenBoundsForType(snap_type_, *snap_sizer_.get())); | |
| 466 } | 430 } |
| 467 | 431 |
| 468 SnapType FrameMaximizeButton::SnapTypeForLocation( | 432 SnapType FrameMaximizeButton::SnapTypeForLocation( |
| 469 const gfx::Point& location) const { | 433 const gfx::Point& location) const { |
| 470 MaximizeBubbleFrameState maximize_type = GetMaximizeBubbleFrameState(); | 434 MaximizeBubbleFrameState maximize_type = GetMaximizeBubbleFrameState(); |
| 471 gfx::Vector2d delta(location - press_location_); | 435 gfx::Vector2d delta(location - press_location_); |
| 472 if (!views::View::ExceededDragThreshold(delta)) | 436 if (!views::View::ExceededDragThreshold(delta)) |
| 473 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; | 437 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; |
| 474 if (delta.x() < 0 && delta.y() > delta.x() && delta.y() < -delta.x()) | 438 if (delta.x() < 0 && delta.y() > delta.x() && delta.y() < -delta.x()) |
| 475 return maximize_type == FRAME_STATE_SNAP_LEFT ? SNAP_RESTORE : SNAP_LEFT; | 439 return maximize_type == FRAME_STATE_SNAP_LEFT ? SNAP_RESTORE : SNAP_LEFT; |
| 476 if (delta.x() > 0 && delta.y() > -delta.x() && delta.y() < delta.x()) | 440 if (delta.x() > 0 && delta.y() > -delta.x() && delta.y() < delta.x()) |
| 477 return maximize_type == FRAME_STATE_SNAP_RIGHT ? SNAP_RESTORE : SNAP_RIGHT; | 441 return maximize_type == FRAME_STATE_SNAP_RIGHT ? SNAP_RESTORE : SNAP_RIGHT; |
| 478 if (delta.y() > 0) | 442 if (delta.y() > 0) |
| 479 return SNAP_MINIMIZE; | 443 return SNAP_MINIMIZE; |
| 480 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; | 444 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; |
| 481 } | 445 } |
| 482 | 446 |
| 483 gfx::Rect FrameMaximizeButton::ScreenBoundsForType( | 447 gfx::Rect FrameMaximizeButton::ScreenBoundsForType(SnapType type) const { |
| 484 SnapType type, | |
| 485 const SnapSizer& snap_sizer) const { | |
| 486 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); | 448 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); |
| 487 switch (type) { | 449 switch (type) { |
| 488 case SNAP_LEFT: | 450 case SNAP_LEFT: |
| 489 case SNAP_RIGHT: | 451 case SNAP_RIGHT: { |
| 490 return ScreenAsh::ConvertRectToScreen( | 452 SnapSizer snap_sizer( |
| 491 frame_->GetWidget()->GetNativeView()->parent(), | 453 window, |
| 492 snap_sizer.target_bounds()); | 454 gfx::Point(), |
| 455 (type == SNAP_LEFT) ? SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE, |
| 456 SnapSizer::STEP_NO); |
| 457 return ScreenAsh::ConvertRectToScreen(window->parent(), |
| 458 snap_sizer.target_bounds()); |
| 459 } |
| 493 case SNAP_MAXIMIZE: | 460 case SNAP_MAXIMIZE: |
| 494 return ScreenAsh::ConvertRectToScreen( | 461 return ScreenAsh::ConvertRectToScreen( |
| 495 window->parent(), | 462 window->parent(), |
| 496 ScreenAsh::GetMaximizedWindowBoundsInParent(window)); | 463 ScreenAsh::GetMaximizedWindowBoundsInParent(window)); |
| 497 case SNAP_MINIMIZE: { | 464 case SNAP_MINIMIZE: { |
| 498 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(window); | 465 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(window); |
| 499 if (!rect.IsEmpty()) { | 466 if (!rect.IsEmpty()) { |
| 500 // PhantomWindowController insets slightly, outset it so the phantom | 467 // PhantomWindowController insets slightly, outset it so the phantom |
| 501 // doesn't appear inset. | 468 // doesn't appear inset. |
| 502 rect.Inset(-8, -8); | 469 rect.Inset(-8, -8); |
| 503 } | 470 } |
| 504 return rect; | 471 return rect; |
| 505 } | 472 } |
| 506 case SNAP_RESTORE: { | 473 case SNAP_RESTORE: { |
| 507 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); | 474 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); |
| 508 return restore ? | 475 return restore ? |
| 509 *restore : frame_->GetWidget()->GetWindowBoundsInScreen(); | 476 *restore : frame_->GetWidget()->GetWindowBoundsInScreen(); |
| 510 } | 477 } |
| 511 case SNAP_NONE: | 478 case SNAP_NONE: |
| 512 NOTREACHED(); | 479 NOTREACHED(); |
| 513 } | 480 } |
| 514 return gfx::Rect(); | 481 return gfx::Rect(); |
| 515 } | 482 } |
| 516 | 483 |
| 517 gfx::Point FrameMaximizeButton::LocationForSnapSizer( | 484 void FrameMaximizeButton::Snap() { |
| 518 const gfx::Point& location) const { | |
| 519 gfx::Point result(location); | |
| 520 views::View::ConvertPointToScreen(this, &result); | |
| 521 return result; | |
| 522 } | |
| 523 | |
| 524 void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) { | |
| 525 ash::Shell* shell = ash::Shell::GetInstance(); | 485 ash::Shell* shell = ash::Shell::GetInstance(); |
| 526 views::Widget* widget = frame_->GetWidget(); | 486 views::Widget* widget = frame_->GetWidget(); |
| 527 switch (snap_type_) { | 487 switch (snap_type_) { |
| 528 case SNAP_LEFT: | 488 case SNAP_LEFT: |
| 529 case SNAP_RIGHT: { | |
| 530 shell->delegate()->RecordUserMetricsAction( | 489 shell->delegate()->RecordUserMetricsAction( |
| 531 snap_type_ == SNAP_LEFT ? | 490 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT); |
| 532 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT : | 491 SnapSizer::SnapWindow(widget->GetNativeView(), |
| 533 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); | 492 SnapSizer::LEFT_EDGE, |
| 534 // Get the bounds in screen coordinates for restore purposes. | 493 SnapSizer::STEP_NO); |
| 535 gfx::Rect restore = widget->GetWindowBoundsInScreen(); | |
| 536 if (widget->IsMaximized() || widget->IsFullscreen()) { | |
| 537 aura::Window* window = widget->GetNativeWindow(); | |
| 538 // In case of maximized we have a restore boundary. | |
| 539 DCHECK(ash::GetRestoreBoundsInScreen(window)); | |
| 540 // If it was maximized we need to recover the old restore set. | |
| 541 restore = *ash::GetRestoreBoundsInScreen(window); | |
| 542 | |
| 543 // The auto position manager will kick in when this is the only window. | |
| 544 // To avoid interference with it we tell it temporarily to not change | |
| 545 // the coordinates of this window. | |
| 546 bool is_managed = ash::wm::IsWindowPositionManaged(window); | |
| 547 if (is_managed) | |
| 548 ash::wm::SetWindowPositionManaged(window, false); | |
| 549 | |
| 550 // Set the restore size we want to restore to. | |
| 551 ash::SetRestoreBoundsInScreen(window, | |
| 552 ScreenBoundsForType(snap_type_, | |
| 553 snap_sizer)); | |
| 554 widget->Restore(); | |
| 555 | |
| 556 // After the window is where we want it to be we allow the window to be | |
| 557 // auto managed again. | |
| 558 if (is_managed) | |
| 559 ash::wm::SetWindowPositionManaged(window, true); | |
| 560 } else { | |
| 561 // Others might also have set up a restore rectangle already. If so, | |
| 562 // we should not overwrite the restore rectangle. | |
| 563 bool restore_set = | |
| 564 GetRestoreBoundsInScreen(widget->GetNativeWindow()) != NULL; | |
| 565 widget->SetBounds(ScreenBoundsForType(snap_type_, snap_sizer)); | |
| 566 if (restore_set) | |
| 567 break; | |
| 568 } | |
| 569 // Remember the widow's bounds for restoration. | |
| 570 ash::SetRestoreBoundsInScreen(widget->GetNativeWindow(), restore); | |
| 571 break; | 494 break; |
| 572 } | 495 case SNAP_RIGHT: |
| 496 shell->delegate()->RecordUserMetricsAction( |
| 497 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); |
| 498 SnapSizer::SnapWindow(widget->GetNativeView(), |
| 499 SnapSizer::RIGHT_EDGE, |
| 500 SnapSizer::STEP_NO); |
| 501 break; |
| 573 case SNAP_MAXIMIZE: | 502 case SNAP_MAXIMIZE: |
| 574 widget->Maximize(); | 503 widget->Maximize(); |
| 575 shell->delegate()->RecordUserMetricsAction( | 504 shell->delegate()->RecordUserMetricsAction( |
| 576 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE); | 505 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE); |
| 577 break; | 506 break; |
| 578 case SNAP_MINIMIZE: | 507 case SNAP_MINIMIZE: |
| 579 widget->Minimize(); | 508 widget->Minimize(); |
| 580 shell->delegate()->RecordUserMetricsAction( | 509 shell->delegate()->RecordUserMetricsAction( |
| 581 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE); | 510 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE); |
| 582 break; | 511 break; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 return FRAME_STATE_SNAP_LEFT; | 544 return FRAME_STATE_SNAP_LEFT; |
| 616 if (bounds.right() == screen.right()) | 545 if (bounds.right() == screen.right()) |
| 617 return FRAME_STATE_SNAP_RIGHT; | 546 return FRAME_STATE_SNAP_RIGHT; |
| 618 // If we come here, it is likely caused by the fact that the | 547 // If we come here, it is likely caused by the fact that the |
| 619 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case | 548 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case |
| 620 // we allow all maximize operations (and keep the restore rectangle). | 549 // we allow all maximize operations (and keep the restore rectangle). |
| 621 return FRAME_STATE_NONE; | 550 return FRAME_STATE_NONE; |
| 622 } | 551 } |
| 623 | 552 |
| 624 } // namespace ash | 553 } // namespace ash |
| OLD | NEW |