Index: ash/wm/caption_buttons/frame_caption_button_container_view.cc |
diff --git a/ash/wm/caption_buttons/frame_caption_button_container_view.cc b/ash/wm/caption_buttons/frame_caption_button_container_view.cc |
index 1ac3a2625ae9248fcf0b0d05e24ac3c88122a063..38fa2658902aae9787f3634c7c3fc16ad6a7bdc3 100644 |
--- a/ash/wm/caption_buttons/frame_caption_button_container_view.cc |
+++ b/ash/wm/caption_buttons/frame_caption_button_container_view.cc |
@@ -4,6 +4,8 @@ |
#include "ash/wm/caption_buttons/frame_caption_button_container_view.h" |
+#include <math.h> |
James Cook
2014/02/19 00:31:27
optional nit: I think we prefer <cmath>, though we
|
+ |
#include "ash/ash_switches.h" |
#include "ash/metrics/user_metrics_recorder.h" |
#include "ash/shell.h" |
@@ -234,43 +236,49 @@ void FrameCaptionButtonContainerView::SetButtonIcons( |
close_button_->SetIcon(close_button_icon, fcb_animate); |
} |
-const FrameCaptionButton* |
-FrameCaptionButtonContainerView::PressButtonAt( |
- const gfx::Point& position_in_screen, |
- const gfx::Insets& pressed_hittest_outer_insets) const { |
- DCHECK(switches::UseAlternateFrameCaptionButtonStyle()); |
- gfx::Point position(position_in_screen); |
+const FrameCaptionButton* FrameCaptionButtonContainerView::GetButtonClosestTo( |
+ const gfx::Point& position_in_screen) const { |
+ // Since the buttons all have the same size, the closest button is the button |
+ // with the center point closest to |position_in_screen|. |
+ // TODO(pkotwicz): Make the caption buttons not overlap. |
views::View::ConvertPointFromScreen(this, &position); |
FrameCaptionButton* buttons[] = { |
- close_button_, size_button_, minimize_button_ |
+ minimize_button_, size_button_, close_button_ |
}; |
- FrameCaptionButton* pressed_button = NULL; |
+ int min_squared_distance = INT_MAX; |
+ FrameCaptionButton* closest_button = NULL; |
for (size_t i = 0; i < arraysize(buttons); ++i) { |
FrameCaptionButton* button = buttons[i]; |
if (!button->visible()) |
continue; |
- if (button->state() == views::Button::STATE_PRESSED) { |
- gfx::Rect expanded_bounds = button->bounds(); |
- expanded_bounds.Inset(pressed_hittest_outer_insets); |
- if (expanded_bounds.Contains(position)) { |
- pressed_button = button; |
- // Do not break in order to give preference to buttons which are |
- // closer to |position_in_screen| than the currently pressed button. |
- // TODO(pkotwicz): Make the caption buttons not overlap. |
- } |
- } else if (ConvertPointToViewAndHitTest(this, button, position)) { |
- pressed_button = button; |
- break; |
+ gfx::Point center_point = button->bounds().CenterPoint(); |
+ int squared_distance = pow((position.x() - center_point.x()), 2) + |
+ pow((position.y() - center_point.y()), 2); |
+ if (squared_distance < min_squared_distance) { |
+ min_squared_distance = squared_distance; |
+ closest_button = button; |
} |
} |
+ return closest_button; |
+} |
+void FrameCaptionButtonContainerView::SetHoveredAndPressedButtons( |
+ const FrameCaptionButton* to_hover, |
+ const FrameCaptionButton* to_press) { |
+ FrameCaptionButton* buttons[] = { |
+ minimize_button_, size_button_, close_button_ |
+ }; |
for (size_t i = 0; i < arraysize(buttons); ++i) { |
- buttons[i]->SetState(buttons[i] == pressed_button ? |
- views::Button::STATE_PRESSED : views::Button::STATE_NORMAL); |
+ FrameCaptionButton* button = buttons[i]; |
+ views::Button::ButtonState new_state = views::Button::STATE_NORMAL; |
+ if (button == to_hover) |
+ new_state = views::Button::STATE_HOVERED; |
+ else if (button == to_press) |
+ new_state = views::Button::STATE_PRESSED; |
+ button->SetState(new_state); |
} |
- return pressed_button; |
} |
} // namespace ash |