Chromium Code Reviews| Index: ash/wm/workspace/frame_maximize_button.cc |
| diff --git a/ash/wm/workspace/frame_maximize_button.cc b/ash/wm/workspace/frame_maximize_button.cc |
| index 78438f02f158f04c256ad55403adfd20f7ed26fc..31e860bbc3062d4eab1c5a240fb06679a4c05dbd 100644 |
| --- a/ash/wm/workspace/frame_maximize_button.cc |
| +++ b/ash/wm/workspace/frame_maximize_button.cc |
| @@ -109,7 +109,7 @@ FrameMaximizeButton::~FrameMaximizeButton() { |
| void FrameMaximizeButton::SnapButtonHovered(SnapType type) { |
| // Make sure to only show hover operations when no button is pressed and |
| // a similar snap operation in progress does not get re-applied. |
| - if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_)) |
| + if (is_snap_enabled_) |
| return; |
| // Prime the mouse location with the center of the (local) button. |
| press_location_ = gfx::Point(width() / 2, height() / 2); |
| @@ -141,9 +141,7 @@ void FrameMaximizeButton::SnapButtonHovered(SnapType type) { |
| // We should not come here. |
| NOTREACHED(); |
| } |
| - // Note: There is no hover with touch - we can therefore pass false for touch |
| - // operations. |
| - UpdateSnap(location, true, false); |
| + UpdateSnap(location); |
| } |
| void FrameMaximizeButton::ExecuteSnapAndCloseMenu(SnapType snap_type) { |
| @@ -156,10 +154,7 @@ void FrameMaximizeButton::ExecuteSnapAndCloseMenu(SnapType snap_type) { |
| // Tell our menu to close. |
| maximizer_.reset(); |
| snap_type_ = snap_type; |
| - // Since Snap might destroy |this|, but the snap_sizer needs to be destroyed, |
| - // The ownership of the snap_sizer is taken now. |
| - scoped_ptr<SnapSizer> snap_sizer(snap_sizer_.release()); |
| - Snap(*snap_sizer.get()); |
| + Snap(); |
| } |
| void FrameMaximizeButton::DestroyMaximizeMenu() { |
| @@ -338,7 +333,6 @@ void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { |
| // If the menu did not show up yet, we delay it even a bit more. |
| maximizer_->DelayCreation(); |
| } |
| - snap_sizer_.reset(NULL); |
| InstallEventFilter(); |
| snap_type_ = SNAP_NONE; |
| press_location_ = event.location(); |
| @@ -358,7 +352,7 @@ void FrameMaximizeButton::ProcessUpdateEvent(const ui::LocatedEvent& event) { |
| event.location() - press_location_); |
| } |
| if (exceeded_drag_threshold_) |
| - UpdateSnap(event.location(), false, event.IsGestureEvent()); |
| + UpdateSnap(event.location()); |
| } |
| bool FrameMaximizeButton::ProcessEndEvent(const ui::LocatedEvent& event) { |
| @@ -378,10 +372,7 @@ bool FrameMaximizeButton::ProcessEndEvent(const ui::LocatedEvent& event) { |
| // STATE_NORMAL during a drag. |
| SchedulePaint(); |
| phantom_window_.reset(); |
| - // Since Snap might destroy |this|, but the snap_sizer needs to be destroyed, |
| - // The ownership of the snap_sizer is taken now. |
| - scoped_ptr<SnapSizer> snap_sizer(snap_sizer_.release()); |
| - Snap(*snap_sizer.get()); |
| + Snap(); |
| return true; |
| } |
| @@ -390,7 +381,6 @@ void FrameMaximizeButton::Cancel(bool keep_menu_open) { |
| maximizer_.reset(); |
| UninstallEventFilter(); |
| is_snap_enabled_ = false; |
| - snap_sizer_.reset(); |
| } |
| phantom_window_.reset(); |
| snap_type_ = SNAP_NONE; |
| @@ -414,25 +404,15 @@ void FrameMaximizeButton::UpdateSnapFromEventLocation() { |
| if (exceeded_drag_threshold_) |
| return; |
| exceeded_drag_threshold_ = true; |
| - UpdateSnap(press_location_, false, press_is_gesture_); |
| + UpdateSnap(press_location_); |
| } |
| -void FrameMaximizeButton::UpdateSnap(const gfx::Point& location, |
| - bool select_default, |
| - bool is_touch) { |
| +void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { |
|
pkotwicz
2013/08/30 21:10:57
I removed the now unused extra parameters from Upd
|
| SnapType type = SnapTypeForLocation(location); |
| - if (type == snap_type_) { |
| - if (snap_sizer_) { |
| - snap_sizer_->Update(LocationForSnapSizer(location)); |
| - phantom_window_->Show(ScreenAsh::ConvertRectToScreen( |
| - frame_->GetWidget()->GetNativeView()->parent(), |
| - snap_sizer_->target_bounds())); |
| - } |
| + if (type == snap_type_) |
| return; |
| - } |
| snap_type_ = type; |
| - snap_sizer_.reset(); |
| SchedulePaint(); |
| if (snap_type_ == SNAP_NONE) { |
| @@ -440,19 +420,6 @@ void FrameMaximizeButton::UpdateSnap(const gfx::Point& location, |
| return; |
| } |
| - if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) { |
| - SnapSizer::Edge snap_edge = snap_type_ == SNAP_LEFT ? |
| - SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; |
| - SnapSizer::InputType input_type = |
| - is_touch ? SnapSizer::TOUCH_MAXIMIZE_BUTTON_INPUT : |
| - SnapSizer::OTHER_INPUT; |
| - snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), |
| - LocationForSnapSizer(location), |
| - snap_edge, |
| - input_type)); |
| - if (select_default) |
| - snap_sizer_->SelectDefaultSizeAndDisableResize(); |
| - } |
| if (!phantom_window_) { |
| phantom_window_.reset(new internal::PhantomWindowController( |
| frame_->GetWidget()->GetNativeWindow())); |
| @@ -461,8 +428,7 @@ void FrameMaximizeButton::UpdateSnap(const gfx::Point& location, |
| phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); |
| maximizer_->SetSnapType(snap_type_); |
| } |
| - phantom_window_->Show( |
| - ScreenBoundsForType(snap_type_, *snap_sizer_.get())); |
| + phantom_window_->Show(ScreenBoundsForType(snap_type_)); |
| } |
| SnapType FrameMaximizeButton::SnapTypeForLocation( |
| @@ -480,16 +446,19 @@ SnapType FrameMaximizeButton::SnapTypeForLocation( |
| return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; |
| } |
| -gfx::Rect FrameMaximizeButton::ScreenBoundsForType( |
| - SnapType type, |
| - const SnapSizer& snap_sizer) const { |
| +gfx::Rect FrameMaximizeButton::ScreenBoundsForType(SnapType type) const { |
| aura::Window* window = frame_->GetWidget()->GetNativeWindow(); |
| switch (type) { |
| case SNAP_LEFT: |
| - case SNAP_RIGHT: |
| - return ScreenAsh::ConvertRectToScreen( |
| - frame_->GetWidget()->GetNativeView()->parent(), |
| - snap_sizer.target_bounds()); |
| + case SNAP_RIGHT: { |
| + SnapSizer snap_sizer( |
| + window, |
| + gfx::Point(), |
| + (type == SNAP_LEFT) ? SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE, |
| + SnapSizer::STEP_NO); |
| + return ScreenAsh::ConvertRectToScreen(window->parent(), |
| + snap_sizer.target_bounds()); |
| + } |
| case SNAP_MAXIMIZE: |
| return ScreenAsh::ConvertRectToScreen( |
| window->parent(), |
| @@ -514,60 +483,23 @@ gfx::Rect FrameMaximizeButton::ScreenBoundsForType( |
| return gfx::Rect(); |
| } |
| -gfx::Point FrameMaximizeButton::LocationForSnapSizer( |
| - const gfx::Point& location) const { |
| - gfx::Point result(location); |
| - views::View::ConvertPointToScreen(this, &result); |
| - return result; |
| -} |
| - |
| -void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) { |
| +void FrameMaximizeButton::Snap() { |
| ash::Shell* shell = ash::Shell::GetInstance(); |
| views::Widget* widget = frame_->GetWidget(); |
| switch (snap_type_) { |
| case SNAP_LEFT: |
| + shell->delegate()->RecordUserMetricsAction( |
| + ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT); |
| + SnapSizer::SnapWindow(widget->GetNativeView(), |
| + SnapSizer::LEFT_EDGE, |
| + SnapSizer::STEP_NO); |
| + break; |
| case SNAP_RIGHT: { |
| shell->delegate()->RecordUserMetricsAction( |
| - snap_type_ == SNAP_LEFT ? |
| - ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT : |
| - ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); |
| - // Get the bounds in screen coordinates for restore purposes. |
| - gfx::Rect restore = widget->GetWindowBoundsInScreen(); |
| - if (widget->IsMaximized() || widget->IsFullscreen()) { |
| - aura::Window* window = widget->GetNativeWindow(); |
| - // In case of maximized we have a restore boundary. |
| - DCHECK(ash::GetRestoreBoundsInScreen(window)); |
| - // If it was maximized we need to recover the old restore set. |
| - restore = *ash::GetRestoreBoundsInScreen(window); |
| - |
| - // The auto position manager will kick in when this is the only window. |
| - // To avoid interference with it we tell it temporarily to not change |
| - // the coordinates of this window. |
| - bool is_managed = ash::wm::IsWindowPositionManaged(window); |
| - if (is_managed) |
| - ash::wm::SetWindowPositionManaged(window, false); |
| - |
| - // Set the restore size we want to restore to. |
| - ash::SetRestoreBoundsInScreen(window, |
| - ScreenBoundsForType(snap_type_, |
| - snap_sizer)); |
| - widget->Restore(); |
| - |
| - // After the window is where we want it to be we allow the window to be |
| - // auto managed again. |
| - if (is_managed) |
| - ash::wm::SetWindowPositionManaged(window, true); |
| - } else { |
| - // Others might also have set up a restore rectangle already. If so, |
| - // we should not overwrite the restore rectangle. |
| - bool restore_set = |
| - GetRestoreBoundsInScreen(widget->GetNativeWindow()) != NULL; |
| - widget->SetBounds(ScreenBoundsForType(snap_type_, snap_sizer)); |
| - if (restore_set) |
| - break; |
| - } |
| - // Remember the widow's bounds for restoration. |
| - ash::SetRestoreBoundsInScreen(widget->GetNativeWindow(), restore); |
| + ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); |
| + SnapSizer::SnapWindow(widget->GetNativeView(), |
| + SnapSizer::RIGHT_EDGE, |
| + SnapSizer::STEP_NO); |
| break; |
| } |
| case SNAP_MAXIMIZE: |