Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" | 5 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" |
| 6 | 6 |
| 7 #include <math.h> | |
|
James Cook
2014/02/19 00:31:27
optional nit: I think we prefer <cmath>, though we
| |
| 8 | |
| 7 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 8 #include "ash/metrics/user_metrics_recorder.h" | 10 #include "ash/metrics/user_metrics_recorder.h" |
| 9 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 10 #include "ash/wm/caption_buttons/alternate_frame_size_button.h" | 12 #include "ash/wm/caption_buttons/alternate_frame_size_button.h" |
| 11 #include "ash/wm/caption_buttons/frame_caption_button.h" | 13 #include "ash/wm/caption_buttons/frame_caption_button.h" |
| 12 #include "ash/wm/caption_buttons/frame_maximize_button.h" | 14 #include "ash/wm/caption_buttons/frame_maximize_button.h" |
| 13 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
| 14 #include "grit/ui_strings.h" // Accessibility names | 16 #include "grit/ui_strings.h" // Accessibility names |
| 15 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 void FrameCaptionButtonContainerView::SetButtonIcons( | 229 void FrameCaptionButtonContainerView::SetButtonIcons( |
| 228 CaptionButtonIcon minimize_button_icon, | 230 CaptionButtonIcon minimize_button_icon, |
| 229 CaptionButtonIcon close_button_icon, | 231 CaptionButtonIcon close_button_icon, |
| 230 Animate animate) { | 232 Animate animate) { |
| 231 FrameCaptionButton::Animate fcb_animate = (animate == ANIMATE_YES) ? | 233 FrameCaptionButton::Animate fcb_animate = (animate == ANIMATE_YES) ? |
| 232 FrameCaptionButton::ANIMATE_YES : FrameCaptionButton::ANIMATE_NO; | 234 FrameCaptionButton::ANIMATE_YES : FrameCaptionButton::ANIMATE_NO; |
| 233 minimize_button_->SetIcon(minimize_button_icon, fcb_animate); | 235 minimize_button_->SetIcon(minimize_button_icon, fcb_animate); |
| 234 close_button_->SetIcon(close_button_icon, fcb_animate); | 236 close_button_->SetIcon(close_button_icon, fcb_animate); |
| 235 } | 237 } |
| 236 | 238 |
| 237 const FrameCaptionButton* | 239 const FrameCaptionButton* FrameCaptionButtonContainerView::GetButtonClosestTo( |
| 238 FrameCaptionButtonContainerView::PressButtonAt( | 240 const gfx::Point& position_in_screen) const { |
| 239 const gfx::Point& position_in_screen, | 241 // Since the buttons all have the same size, the closest button is the button |
| 240 const gfx::Insets& pressed_hittest_outer_insets) const { | 242 // with the center point closest to |position_in_screen|. |
| 241 DCHECK(switches::UseAlternateFrameCaptionButtonStyle()); | 243 // TODO(pkotwicz): Make the caption buttons not overlap. |
| 242 gfx::Point position(position_in_screen); | |
| 243 views::View::ConvertPointFromScreen(this, &position); | 244 views::View::ConvertPointFromScreen(this, &position); |
| 244 | 245 |
| 245 FrameCaptionButton* buttons[] = { | 246 FrameCaptionButton* buttons[] = { |
| 246 close_button_, size_button_, minimize_button_ | 247 minimize_button_, size_button_, close_button_ |
| 247 }; | 248 }; |
| 248 FrameCaptionButton* pressed_button = NULL; | 249 int min_squared_distance = INT_MAX; |
| 250 FrameCaptionButton* closest_button = NULL; | |
| 249 for (size_t i = 0; i < arraysize(buttons); ++i) { | 251 for (size_t i = 0; i < arraysize(buttons); ++i) { |
| 250 FrameCaptionButton* button = buttons[i]; | 252 FrameCaptionButton* button = buttons[i]; |
| 251 if (!button->visible()) | 253 if (!button->visible()) |
| 252 continue; | 254 continue; |
| 253 | 255 |
| 254 if (button->state() == views::Button::STATE_PRESSED) { | 256 gfx::Point center_point = button->bounds().CenterPoint(); |
| 255 gfx::Rect expanded_bounds = button->bounds(); | 257 int squared_distance = pow((position.x() - center_point.x()), 2) + |
| 256 expanded_bounds.Inset(pressed_hittest_outer_insets); | 258 pow((position.y() - center_point.y()), 2); |
| 257 if (expanded_bounds.Contains(position)) { | 259 if (squared_distance < min_squared_distance) { |
| 258 pressed_button = button; | 260 min_squared_distance = squared_distance; |
| 259 // Do not break in order to give preference to buttons which are | 261 closest_button = button; |
| 260 // closer to |position_in_screen| than the currently pressed button. | |
| 261 // TODO(pkotwicz): Make the caption buttons not overlap. | |
| 262 } | |
| 263 } else if (ConvertPointToViewAndHitTest(this, button, position)) { | |
| 264 pressed_button = button; | |
| 265 break; | |
| 266 } | 262 } |
| 267 } | 263 } |
| 264 return closest_button; | |
| 265 } | |
| 268 | 266 |
| 267 void FrameCaptionButtonContainerView::SetHoveredAndPressedButtons( | |
| 268 const FrameCaptionButton* to_hover, | |
| 269 const FrameCaptionButton* to_press) { | |
| 270 FrameCaptionButton* buttons[] = { | |
| 271 minimize_button_, size_button_, close_button_ | |
| 272 }; | |
| 269 for (size_t i = 0; i < arraysize(buttons); ++i) { | 273 for (size_t i = 0; i < arraysize(buttons); ++i) { |
| 270 buttons[i]->SetState(buttons[i] == pressed_button ? | 274 FrameCaptionButton* button = buttons[i]; |
| 271 views::Button::STATE_PRESSED : views::Button::STATE_NORMAL); | 275 views::Button::ButtonState new_state = views::Button::STATE_NORMAL; |
| 276 if (button == to_hover) | |
| 277 new_state = views::Button::STATE_HOVERED; | |
| 278 else if (button == to_press) | |
| 279 new_state = views::Button::STATE_PRESSED; | |
| 280 button->SetState(new_state); | |
| 272 } | 281 } |
| 273 return pressed_button; | |
| 274 } | 282 } |
| 275 | 283 |
| 276 } // namespace ash | 284 } // namespace ash |
| OLD | NEW |