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

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

Issue 23471004: Only support left/right maximizing at 50% width when the --ash-enable-alternate-caption-button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch is now friendlier to pending docking changes Created 7 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 78438f02f158f04c256ad55403adfd20f7ed26fc..b47b5f8e718e7ed149c7f01d2c8ec36f486fc110 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);
@@ -156,10 +156,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 +335,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();
@@ -378,10 +374,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 +383,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;
@@ -421,18 +413,10 @@ void FrameMaximizeButton::UpdateSnap(const gfx::Point& location,
bool select_default,
bool is_touch) {
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 +424,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 +432,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 +450,18 @@ 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 snap_sizer.target_bounds();
varkha 2013/08/30 17:13:25 Does it not need to be in screen coordinates? I th
pkotwicz 2013/08/30 21:10:57 Nice catch!
+ }
case SNAP_MAXIMIZE:
return ScreenAsh::ConvertRectToScreen(
window->parent(),
@@ -514,60 +486,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);
varkha 2013/08/30 17:13:25 It would be nice to add UMA metrics to workspace r
pkotwicz 2013/08/30 21:10:57 I think it belongs in a separate CL from this CL a
+ SnapSizer::SnapWindow(widget->GetNativeView(),
+ SnapSizer::LEFT_EDGE,
+ SnapSizer::STEP_NO);
+ break;
varkha 2013/08/30 17:13:25 Would it be simpler and less code duplication if y
pkotwicz 2013/08/30 21:10:57 I think this way is clearer. Note that a different
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:

Powered by Google App Engine
This is Rietveld 408576698