| 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/maximize_bubble_controller.h" | 10 #include "ash/wm/maximize_bubble_controller.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 exceeded_drag_threshold_ = false; | 330 exceeded_drag_threshold_ = false; |
| 331 update_timer_.Start( | 331 update_timer_.Start( |
| 332 FROM_HERE, | 332 FROM_HERE, |
| 333 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), | 333 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), |
| 334 this, | 334 this, |
| 335 &FrameMaximizeButton::UpdateSnapFromEventLocation); | 335 &FrameMaximizeButton::UpdateSnapFromEventLocation); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void FrameMaximizeButton::ProcessUpdateEvent(const ui::LocatedEvent& event) { | 338 void FrameMaximizeButton::ProcessUpdateEvent(const ui::LocatedEvent& event) { |
| 339 DCHECK(is_snap_enabled_); | 339 DCHECK(is_snap_enabled_); |
| 340 int delta_x = event.x() - press_location_.x(); | |
| 341 int delta_y = event.y() - press_location_.y(); | |
| 342 if (!exceeded_drag_threshold_) { | 340 if (!exceeded_drag_threshold_) { |
| 343 exceeded_drag_threshold_ = | 341 exceeded_drag_threshold_ = views::View::ExceededDragThreshold( |
| 344 views::View::ExceededDragThreshold(delta_x, delta_y); | 342 event.location() - press_location_); |
| 345 } | 343 } |
| 346 if (exceeded_drag_threshold_) | 344 if (exceeded_drag_threshold_) |
| 347 UpdateSnap(event.location(), false); | 345 UpdateSnap(event.location(), false); |
| 348 } | 346 } |
| 349 | 347 |
| 350 bool FrameMaximizeButton::ProcessEndEvent(const ui::LocatedEvent& event) { | 348 bool FrameMaximizeButton::ProcessEndEvent(const ui::LocatedEvent& event) { |
| 351 update_timer_.Stop(); | 349 update_timer_.Stop(); |
| 352 UninstallEventFilter(); | 350 UninstallEventFilter(); |
| 353 bool should_snap = is_snap_enabled_; | 351 bool should_snap = is_snap_enabled_; |
| 354 is_snap_enabled_ = false; | 352 is_snap_enabled_ = false; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); | 440 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); |
| 443 maximizer_->SetSnapType(snap_type_); | 441 maximizer_->SetSnapType(snap_type_); |
| 444 } | 442 } |
| 445 phantom_window_->Show( | 443 phantom_window_->Show( |
| 446 ScreenBoundsForType(snap_type_, *snap_sizer_.get()), NULL); | 444 ScreenBoundsForType(snap_type_, *snap_sizer_.get()), NULL); |
| 447 } | 445 } |
| 448 | 446 |
| 449 SnapType FrameMaximizeButton::SnapTypeForLocation( | 447 SnapType FrameMaximizeButton::SnapTypeForLocation( |
| 450 const gfx::Point& location) const { | 448 const gfx::Point& location) const { |
| 451 MaximizeBubbleFrameState maximize_type = GetMaximizeBubbleFrameState(); | 449 MaximizeBubbleFrameState maximize_type = GetMaximizeBubbleFrameState(); |
| 452 int delta_x = location.x() - press_location_.x(); | 450 gfx::Vector2d delta(location - press_location_); |
| 453 int delta_y = location.y() - press_location_.y(); | 451 if (!views::View::ExceededDragThreshold(delta)) |
| 454 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) | |
| 455 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; | 452 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; |
| 456 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) | 453 if (delta.x() < 0 && delta.y() > delta.x() && delta.y() < -delta.x()) |
| 457 return maximize_type == FRAME_STATE_SNAP_LEFT ? SNAP_RESTORE : SNAP_LEFT; | 454 return maximize_type == FRAME_STATE_SNAP_LEFT ? SNAP_RESTORE : SNAP_LEFT; |
| 458 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) | 455 if (delta.x() > 0 && delta.y() > -delta.x() && delta.y() < delta.x()) |
| 459 return maximize_type == FRAME_STATE_SNAP_RIGHT ? SNAP_RESTORE : SNAP_RIGHT; | 456 return maximize_type == FRAME_STATE_SNAP_RIGHT ? SNAP_RESTORE : SNAP_RIGHT; |
| 460 else if (delta_y > 0) | 457 if (delta.y() > 0) |
| 461 return SNAP_MINIMIZE; | 458 return SNAP_MINIMIZE; |
| 462 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; | 459 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; |
| 463 } | 460 } |
| 464 | 461 |
| 465 gfx::Rect FrameMaximizeButton::ScreenBoundsForType( | 462 gfx::Rect FrameMaximizeButton::ScreenBoundsForType( |
| 466 SnapType type, | 463 SnapType type, |
| 467 const SnapSizer& snap_sizer) const { | 464 const SnapSizer& snap_sizer) const { |
| 468 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); | 465 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); |
| 469 switch (type) { | 466 switch (type) { |
| 470 case SNAP_LEFT: | 467 case SNAP_LEFT: |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 return FRAME_STATE_SNAP_LEFT; | 574 return FRAME_STATE_SNAP_LEFT; |
| 578 if (bounds.right() == screen.right()) | 575 if (bounds.right() == screen.right()) |
| 579 return FRAME_STATE_SNAP_RIGHT; | 576 return FRAME_STATE_SNAP_RIGHT; |
| 580 // If we come here, it is likely caused by the fact that the | 577 // If we come here, it is likely caused by the fact that the |
| 581 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case | 578 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case |
| 582 // we allow all maximize operations (and keep the restore rectangle). | 579 // we allow all maximize operations (and keep the restore rectangle). |
| 583 return FRAME_STATE_NONE; | 580 return FRAME_STATE_NONE; |
| 584 } | 581 } |
| 585 | 582 |
| 586 } // namespace ash | 583 } // namespace ash |
| OLD | NEW |