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

Side by Side Diff: ash/wm/caption_buttons/frame_caption_button_container_view.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/caption_buttons/frame_caption_button_container_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <cmath>
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 257 }
256 258
257 void FrameCaptionButtonContainerView::SetButtonIcons( 259 void FrameCaptionButtonContainerView::SetButtonIcons(
258 CaptionButtonIcon minimize_button_icon, 260 CaptionButtonIcon minimize_button_icon,
259 CaptionButtonIcon close_button_icon, 261 CaptionButtonIcon close_button_icon,
260 Animate animate) { 262 Animate animate) {
261 SetButtonIcon(minimize_button_, minimize_button_icon, animate); 263 SetButtonIcon(minimize_button_, minimize_button_icon, animate);
262 SetButtonIcon(close_button_, close_button_icon, animate); 264 SetButtonIcon(close_button_, close_button_icon, animate);
263 } 265 }
264 266
265 const FrameCaptionButton* 267 const FrameCaptionButton* FrameCaptionButtonContainerView::GetButtonClosestTo(
266 FrameCaptionButtonContainerView::PressButtonAt( 268 const gfx::Point& position_in_screen) const {
267 const gfx::Point& position_in_screen, 269 // Since the buttons all have the same size, the closest button is the button
268 const gfx::Insets& pressed_hittest_outer_insets) const { 270 // with the center point closest to |position_in_screen|.
269 DCHECK(switches::UseAlternateFrameCaptionButtonStyle()); 271 // TODO(pkotwicz): Make the caption buttons not overlap.
270 gfx::Point position(position_in_screen); 272 gfx::Point position(position_in_screen);
271 views::View::ConvertPointFromScreen(this, &position); 273 views::View::ConvertPointFromScreen(this, &position);
272 274
273 FrameCaptionButton* buttons[] = { 275 FrameCaptionButton* buttons[] = {
274 close_button_, size_button_, minimize_button_ 276 minimize_button_, size_button_, close_button_
275 }; 277 };
276 FrameCaptionButton* pressed_button = NULL; 278 int min_squared_distance = INT_MAX;
279 FrameCaptionButton* closest_button = NULL;
277 for (size_t i = 0; i < arraysize(buttons); ++i) { 280 for (size_t i = 0; i < arraysize(buttons); ++i) {
278 FrameCaptionButton* button = buttons[i]; 281 FrameCaptionButton* button = buttons[i];
279 if (!button->visible()) 282 if (!button->visible())
280 continue; 283 continue;
281 284
282 if (button->state() == views::Button::STATE_PRESSED) { 285 gfx::Point center_point = button->bounds().CenterPoint();
283 gfx::Rect expanded_bounds = button->bounds(); 286 int squared_distance = static_cast<int>(
284 expanded_bounds.Inset(pressed_hittest_outer_insets); 287 pow(static_cast<double>(position.x() - center_point.x()), 2) +
285 if (expanded_bounds.Contains(position)) { 288 pow(static_cast<double>(position.y() - center_point.y()), 2));
286 pressed_button = button; 289 if (squared_distance < min_squared_distance) {
287 // Do not break in order to give preference to buttons which are 290 min_squared_distance = squared_distance;
288 // closer to |position_in_screen| than the currently pressed button. 291 closest_button = button;
289 // TODO(pkotwicz): Make the caption buttons not overlap.
290 }
291 } else if (ConvertPointToViewAndHitTest(this, button, position)) {
292 pressed_button = button;
293 break;
294 } 292 }
295 } 293 }
294 return closest_button;
295 }
296 296
297 void FrameCaptionButtonContainerView::SetHoveredAndPressedButtons(
298 const FrameCaptionButton* to_hover,
299 const FrameCaptionButton* to_press) {
300 FrameCaptionButton* buttons[] = {
301 minimize_button_, size_button_, close_button_
302 };
297 for (size_t i = 0; i < arraysize(buttons); ++i) { 303 for (size_t i = 0; i < arraysize(buttons); ++i) {
298 buttons[i]->SetState(buttons[i] == pressed_button ? 304 FrameCaptionButton* button = buttons[i];
299 views::Button::STATE_PRESSED : views::Button::STATE_NORMAL); 305 views::Button::ButtonState new_state = views::Button::STATE_NORMAL;
306 if (button == to_hover)
307 new_state = views::Button::STATE_HOVERED;
308 else if (button == to_press)
309 new_state = views::Button::STATE_PRESSED;
310 button->SetState(new_state);
300 } 311 }
301 return pressed_button;
302 } 312 }
303 313
304 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds() 314 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds()
305 : normal_image_id(-1), 315 : normal_image_id(-1),
306 hovered_image_id(-1), 316 hovered_image_id(-1),
307 pressed_image_id(-1) { 317 pressed_image_id(-1) {
308 } 318 }
309 319
310 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds(int normal_id, 320 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds(int normal_id,
311 int hovered_id, 321 int hovered_id,
312 int pressed_id) 322 int pressed_id)
313 : normal_image_id(normal_id), 323 : normal_image_id(normal_id),
314 hovered_image_id(hovered_id), 324 hovered_image_id(hovered_id),
315 pressed_image_id(pressed_id) { 325 pressed_image_id(pressed_id) {
316 } 326 }
317 327
318 FrameCaptionButtonContainerView::ButtonIconIds::~ButtonIconIds() { 328 FrameCaptionButtonContainerView::ButtonIconIds::~ButtonIconIds() {
319 } 329 }
320 330
321 } // namespace ash 331 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/caption_buttons/frame_caption_button_container_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698