Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3350)

Unified Diff: ash/wm/workspace/frame_maximize_button.cc

Issue 10883069: Added restore functionality for maximize full/left/right (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 8f8f7e8ff2ebd70d2bc6bc90a2a7479edd74ee43..5f79bc79644a5787e438f1fcc73bf2381a3017d9 100644
--- a/ash/wm/workspace/frame_maximize_button.cc
+++ b/ash/wm/workspace/frame_maximize_button.cc
@@ -212,7 +212,7 @@ void FrameMaximizeButton::OnMouseEntered(const ui::MouseEvent& event) {
}
maximizer_.reset(new MaximizeBubbleController(
this,
- frame_->GetWidget()->IsMaximized(),
+ GetMaximizeType(),
bubble_appearance_delay_ms_));
}
}
@@ -298,13 +298,20 @@ ui::GestureStatus FrameMaximizeButton::OnGestureEvent(
return ImageButton::OnGestureEvent(event);
}
+void FrameMaximizeButton::ToggleMaximize() {
+ if (frame_->GetWidget()->IsMaximized())
+ frame_->GetWidget()->Restore();
+ else
+ Maximize();
+}
+
void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) {
DCHECK(is_snap_enabled_);
// Prepare the help menu.
if (!maximizer_.get()) {
maximizer_.reset(new MaximizeBubbleController(
this,
- frame_->GetWidget()->IsMaximized(),
+ GetMaximizeType(),
bubble_appearance_delay_ms_));
} else {
// If the menu did not show up yet, we delay it even a bit more.
@@ -432,17 +439,18 @@ void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) {
SnapType FrameMaximizeButton::SnapTypeForLocation(
const gfx::Point& location) const {
+ MaximizeType maximize_type = GetMaximizeType();
int delta_x = location.x() - press_location_.x();
int delta_y = location.y() - press_location_.y();
if (!views::View::ExceededDragThreshold(delta_x, delta_y))
- return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE;
+ return maximize_type != MAXIMIZE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE;
else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x)
- return SNAP_LEFT;
+ return maximize_type == MAXIMIZE_LEFT ? SNAP_RESTORE : SNAP_LEFT;
else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x)
- return SNAP_RIGHT;
+ return maximize_type == MAXIMIZE_RIGHT ? SNAP_RESTORE : SNAP_RIGHT;
else if (delta_y > 0)
return SNAP_MINIMIZE;
- return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE;
+ return maximize_type != MAXIMIZE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE;
}
gfx::Rect FrameMaximizeButton::ScreenBoundsForType(
@@ -489,31 +497,78 @@ gfx::Point FrameMaximizeButton::LocationForSnapSizer(
}
void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) {
+ views::Widget* widget = frame_->GetWidget();
switch (snap_type_) {
case SNAP_LEFT:
- case SNAP_RIGHT:
- if (frame_->GetWidget()->IsMaximized()) {
+ case SNAP_RIGHT: {
+ // Get the window coordinates on the screen for restore purposes.
+ gfx::Rect restore = frame_->GetWidget()->GetNativeWindow()->bounds();
+ if (frame_->GetWidget()->IsMaximized()) {
+ // If it was maximized we need to recover the old restore set.
+ restore = *ash::GetRestoreBoundsInScreen(
+ frame_->GetWidget()->GetNativeWindow());
+ // Set the restore size we want to restore to.
+ ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(),
+ ScreenBoundsForType(snap_type_,
+ snap_sizer));
+ frame_->GetWidget()->Restore();
+ } else {
+ frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_,
+ snap_sizer));
+ }
+ // Remember the widow's bounds for restoration.
ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(),
- ScreenBoundsForType(snap_type_,
- snap_sizer));
- frame_->GetWidget()->Restore();
- } else {
- frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_,
- snap_sizer));
+ restore);
}
break;
case SNAP_MAXIMIZE:
- frame_->GetWidget()->Maximize();
+ Maximize();
break;
case SNAP_MINIMIZE:
- frame_->GetWidget()->Minimize();
+ widget->Minimize();
break;
case SNAP_RESTORE:
- frame_->GetWidget()->Restore();
+ widget->Restore();
break;
case SNAP_NONE:
NOTREACHED();
}
}
+MaximizeType FrameMaximizeButton::GetMaximizeType() const {
+ // When there are no restore bounds, we are in normal mode.
+ if (!ash::GetRestoreBoundsInScreen(
+ frame_->GetWidget()->GetNativeWindow()))
+ return MAXIMIZE_NONE;
+ // The normal maximized test can be used.
+ if (frame_->GetWidget()->IsMaximized())
+ return MAXIMIZE_FULL;
+ // For Left/right maximize we need to check the dimensions.
+ gfx::Rect bounds = frame_->GetWidget()->GetNativeWindow()->bounds();
+ gfx::Rect screen = gfx::Screen::GetDisplayMatching(bounds).work_area();
+ // We have to be in a maximize mode at this point.
+ 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!
+ DCHECK(bounds.height() >= screen.height());
+ if (!bounds.x())
+ return MAXIMIZE_LEFT;
+ if (bounds.right() == screen.right())
+ return MAXIMIZE_RIGHT;
+ NOTREACHED();
+ return MAXIMIZE_NONE;
+}
+
+void FrameMaximizeButton::Maximize() {
+ views::Widget* widget = frame_->GetWidget();
+ MaximizeType maximize_type = GetMaximizeType();
+ if (maximize_type == MAXIMIZE_LEFT || maximize_type == MAXIMIZE_RIGHT) {
+ aura::Window* window = widget->GetNativeWindow();
+ gfx::Rect restore = *ash::GetRestoreBoundsInScreen(window);
+ widget->Maximize();
+ ash::SetRestoreBoundsInScreen(window, restore);
+ } else {
+ widget->Maximize();
+ }
+ // Note: |This| might be destroyed at this time.
+}
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698