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

Unified Diff: ash/wm/caption_buttons/alternate_frame_size_button.cc

Issue 168943006: Keep the size button pressed when the user hovers the snap left or snap right button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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/caption_buttons/alternate_frame_size_button.cc
diff --git a/ash/wm/caption_buttons/alternate_frame_size_button.cc b/ash/wm/caption_buttons/alternate_frame_size_button.cc
index 33e62004d91ab137695aad014bb2e8b82b9b3025..cffed8c439ba01d84cb24413b9bbcc6b9e676040 100644
--- a/ash/wm/caption_buttons/alternate_frame_size_button.cc
+++ b/ash/wm/caption_buttons/alternate_frame_size_button.cc
@@ -21,10 +21,22 @@ namespace {
// right.
const int kSetButtonsToSnapModeDelayMs = 150;
-// The amount that a user can overshoot the snap left / snap right button and
-// keep the snap left / snap right button pressed.
-const int kPressedHitBoundsExpandX = 200;
-const int kPressedHitBoundsExpandY = 50;
+// The amount that a user can overshoot one of the caption buttons while in
+// "snap mode" and keep the button hovered/pressed.
+const int kMaxOvershootX = 200;
+const int kMaxOvershootY = 50;
+
+// Returns true if a mouse drag while in "snap mode" at |location_in_screen|
+// would hover/press |button| or keep it hovered/pressed.
+bool HitTestButton(const ash::FrameCaptionButton* button,
+ const gfx::Point& location_in_screen) {
+ gfx::Rect expanded_bounds_in_screen = button->GetBoundsInScreen();
+ if (button->state() == views::Button::STATE_HOVERED ||
+ button->state() == views::Button::STATE_PRESSED) {
+ expanded_bounds_in_screen.Inset(-kMaxOvershootX, -kMaxOvershootY);
+ }
+ return expanded_bounds_in_screen.Contains(location_in_screen);
+}
} // namespace
@@ -59,8 +71,12 @@ bool AlternateFrameSizeButton::OnMousePressed(const ui::MouseEvent& event) {
}
bool AlternateFrameSizeButton::OnMouseDragged(const ui::MouseEvent& event) {
- UpdatePressedButton(event);
- FrameCaptionButton::OnMouseDragged(event);
+ UpdateSnapType(event);
+ // By default a FrameCaptionButton reverts to STATE_NORMAL once the mouse
+ // leaves its bounds. Skip FrameCaptionButton's handling when
+ // |in_snap_mode_| == true because we want different behavior.
+ if (!in_snap_mode_)
+ FrameCaptionButton::OnMouseDragged(event);
return true;
}
@@ -74,6 +90,12 @@ void AlternateFrameSizeButton::OnMouseCaptureLost() {
FrameCaptionButton::OnMouseCaptureLost();
}
+void AlternateFrameSizeButton::OnMouseMoved(const ui::MouseEvent& event) {
+ // Ignore any synthetic mouse moves during a drag.
+ if (!in_snap_mode_)
+ FrameCaptionButton::OnMouseMoved(event);
+}
+
void AlternateFrameSizeButton::OnGestureEvent(ui::GestureEvent* event) {
if (event->details().touch_points() > 1) {
SetButtonsToNormalMode(AlternateFrameSizeButtonDelegate::ANIMATE_YES);
@@ -89,7 +111,7 @@ void AlternateFrameSizeButton::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
- UpdatePressedButton(*event);
+ UpdateSnapType(*event);
event->SetHandled();
return;
}
@@ -134,8 +156,7 @@ void AlternateFrameSizeButton::SetButtonsToSnapMode() {
AlternateFrameSizeButtonDelegate::ANIMATE_YES);
}
-void AlternateFrameSizeButton::UpdatePressedButton(
- const ui::LocatedEvent& event) {
+void AlternateFrameSizeButton::UpdateSnapType(const ui::LocatedEvent& event) {
if (!in_snap_mode_) {
// Set the buttons adjacent to the size button to snap left and right early
// if the user drags past the drag threshold.
@@ -153,16 +174,16 @@ void AlternateFrameSizeButton::UpdatePressedButton(
gfx::Point event_location_in_screen(event.location());
views::View::ConvertPointToScreen(this, &event_location_in_screen);
+ const FrameCaptionButton* to_hover =
+ GetButtonToHover(event_location_in_screen);
+ bool press_size_button =
+ to_hover || HitTestButton(this, event_location_in_screen);
+ delegate_->SetHoveredAndPressedButtons(
+ to_hover, press_size_button ? this : NULL);
- gfx::Insets pressed_button_hittest_insets(-kPressedHitBoundsExpandY,
- -kPressedHitBoundsExpandX,
- -kPressedHitBoundsExpandY,
- -kPressedHitBoundsExpandX);
- const FrameCaptionButton* pressed_button = delegate_->PressButtonAt(
- event_location_in_screen, pressed_button_hittest_insets);
snap_type_ = SNAP_NONE;
- if (pressed_button) {
- switch (pressed_button->icon()) {
+ if (to_hover) {
+ switch (to_hover->icon()) {
case CAPTION_BUTTON_ICON_LEFT_SNAPPED:
snap_type_ = SNAP_LEFT;
break;
@@ -170,8 +191,6 @@ void AlternateFrameSizeButton::UpdatePressedButton(
snap_type_ = SNAP_RIGHT;
break;
case CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE:
- // snap_type_ = SNAP_NONE
- break;
case CAPTION_BUTTON_ICON_MINIMIZE:
case CAPTION_BUTTON_ICON_CLOSE:
case CAPTION_BUTTON_ICON_COUNT:
@@ -200,10 +219,22 @@ void AlternateFrameSizeButton::UpdatePressedButton(
}
}
+const FrameCaptionButton* AlternateFrameSizeButton::GetButtonToHover(
+ const gfx::Point& event_location_in_screen) const {
+ const FrameCaptionButton* closest_button = delegate_->GetButtonClosestTo(
+ event_location_in_screen);
+ if ((closest_button->icon() == CAPTION_BUTTON_ICON_LEFT_SNAPPED ||
+ closest_button->icon() == CAPTION_BUTTON_ICON_RIGHT_SNAPPED) &&
+ HitTestButton(closest_button, event_location_in_screen)) {
+ return closest_button;
+ }
+ return NULL;
+}
+
bool AlternateFrameSizeButton::CommitSnap(const ui::LocatedEvent& event) {
// The position of |event| may be different than the position of the previous
// event.
- UpdatePressedButton(event);
+ UpdateSnapType(event);
if (in_snap_mode_ &&
(snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) {
« no previous file with comments | « ash/wm/caption_buttons/alternate_frame_size_button.h ('k') | ash/wm/caption_buttons/alternate_frame_size_button_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698