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

Side by Side Diff: ash/frame/caption_buttons/frame_caption_button_container_view.cc

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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/frame/caption_buttons/frame_caption_button_container_view.h" 5 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <map> 8 #include <map>
9 9
10 #include "ash/common/ash_switches.h" 10 #include "ash/common/ash_switches.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // Duration of |maximize_mode_animation_| showing. 56 // Duration of |maximize_mode_animation_| showing.
57 // Slide minimize button 500 57 // Slide minimize button 500
58 // |-------------------------------------------------| 58 // |-------------------------------------------------|
59 // Delay 100 Show size button 250 59 // Delay 100 Show size button 250
60 // |---------|-----------------------| 60 // |---------|-----------------------|
61 const int kShowAnimationDurationMs = kPositionAnimationDurationMs; 61 const int kShowAnimationDurationMs = kPositionAnimationDurationMs;
62 62
63 // Value of |maximize_mode_animation_| showing to begin animating alpha of 63 // Value of |maximize_mode_animation_| showing to begin animating alpha of
64 // |size_button_|. 64 // |size_button_|.
65 float SizeButtonShowStartValue() { 65 float SizeButtonShowStartValue() {
66 return static_cast<float>(kShowAnimationAlphaDelayMs) 66 return static_cast<float>(kShowAnimationAlphaDelayMs) /
67 / kShowAnimationDurationMs; 67 kShowAnimationDurationMs;
68 } 68 }
69 69
70 // Amount of |maximize_mode_animation_| showing to animate the alpha of 70 // Amount of |maximize_mode_animation_| showing to animate the alpha of
71 // |size_button_|. 71 // |size_button_|.
72 float SizeButtonShowDuration() { 72 float SizeButtonShowDuration() {
73 return static_cast<float>(kAlphaAnimationDurationMs) 73 return static_cast<float>(kAlphaAnimationDurationMs) /
74 / kShowAnimationDurationMs; 74 kShowAnimationDurationMs;
75 } 75 }
76 76
77 // Amount of |maximize_mode_animation_| hiding to animate the alpha of 77 // Amount of |maximize_mode_animation_| hiding to animate the alpha of
78 // |size_button_|. 78 // |size_button_|.
79 float SizeButtonHideDuration() { 79 float SizeButtonHideDuration() {
80 return static_cast<float>(kAlphaAnimationDurationMs) 80 return static_cast<float>(kAlphaAnimationDurationMs) /
81 / kHideAnimationDurationMs; 81 kHideAnimationDurationMs;
82 } 82 }
83 83
84 // Value of |maximize_mode_animation_| hiding to begin animating the position of 84 // Value of |maximize_mode_animation_| hiding to begin animating the position of
85 // |minimize_button_|. 85 // |minimize_button_|.
86 float HidePositionStartValue() { 86 float HidePositionStartValue() {
87 return 1.0f - static_cast<float>(kHidePositionDelayMs) 87 return 1.0f -
88 / kHideAnimationDurationMs; 88 static_cast<float>(kHidePositionDelayMs) / kHideAnimationDurationMs;
89 } 89 }
90 90
91 // Converts |point| from |src| to |dst| and hittests against |dst|. 91 // Converts |point| from |src| to |dst| and hittests against |dst|.
92 bool ConvertPointToViewAndHitTest(const views::View* src, 92 bool ConvertPointToViewAndHitTest(const views::View* src,
93 const views::View* dst, 93 const views::View* dst,
94 const gfx::Point& point) { 94 const gfx::Point& point) {
95 gfx::Point converted(point); 95 gfx::Point converted(point);
96 views::View::ConvertPointToTarget(src, dst, &converted); 96 views::View::ConvertPointToTarget(src, dst, &converted);
97 return dst->HitTestPoint(converted); 97 return dst->HitTestPoint(converted);
98 } 98 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); 136 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE));
137 size_button_->SetVisible(size_button_visibility); 137 size_button_->SetVisible(size_button_visibility);
138 AddChildView(size_button_); 138 AddChildView(size_button_);
139 139
140 close_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_CLOSE); 140 close_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_CLOSE);
141 close_button_->SetAccessibleName( 141 close_button_->SetAccessibleName(
142 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); 142 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
143 AddChildView(close_button_); 143 AddChildView(close_button_);
144 } 144 }
145 145
146 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() { 146 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() {}
147 }
148 147
149 void FrameCaptionButtonContainerView::TestApi::EndAnimations() { 148 void FrameCaptionButtonContainerView::TestApi::EndAnimations() {
150 container_view_->maximize_mode_animation_->End(); 149 container_view_->maximize_mode_animation_->End();
151 } 150 }
152 151
153 void FrameCaptionButtonContainerView::SetButtonImage( 152 void FrameCaptionButtonContainerView::SetButtonImage(
154 CaptionButtonIcon icon, 153 CaptionButtonIcon icon,
155 gfx::VectorIconId icon_image_id) { 154 gfx::VectorIconId icon_image_id) {
156 button_icon_id_map_[icon] = icon_image_id; 155 button_icon_id_map_[icon] = icon_image_id;
157 156
158 FrameCaptionButton* buttons[] = { 157 FrameCaptionButton* buttons[] = {minimize_button_, size_button_,
159 minimize_button_, size_button_, close_button_ 158 close_button_};
160 };
161 for (size_t i = 0; i < arraysize(buttons); ++i) { 159 for (size_t i = 0; i < arraysize(buttons); ++i) {
162 if (buttons[i]->icon() == icon) 160 if (buttons[i]->icon() == icon)
163 buttons[i]->SetImage(icon, FrameCaptionButton::ANIMATE_NO, icon_image_id); 161 buttons[i]->SetImage(icon, FrameCaptionButton::ANIMATE_NO, icon_image_id);
164 } 162 }
165 } 163 }
166 164
167 void FrameCaptionButtonContainerView::SetPaintAsActive(bool paint_as_active) { 165 void FrameCaptionButtonContainerView::SetPaintAsActive(bool paint_as_active) {
168 minimize_button_->set_paint_as_active(paint_as_active); 166 minimize_button_->set_paint_as_active(paint_as_active);
169 size_button_->set_paint_as_active(paint_as_active); 167 size_button_->set_paint_as_active(paint_as_active);
170 close_button_->set_paint_as_active(paint_as_active); 168 close_button_->set_paint_as_active(paint_as_active);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 PreferredSizeChanged(); 252 PreferredSizeChanged();
255 } 253 }
256 } 254 }
257 255
258 void FrameCaptionButtonContainerView::AnimationProgressed( 256 void FrameCaptionButtonContainerView::AnimationProgressed(
259 const gfx::Animation* animation) { 257 const gfx::Animation* animation) {
260 double current_value = animation->GetCurrentValue(); 258 double current_value = animation->GetCurrentValue();
261 int size_alpha = 0; 259 int size_alpha = 0;
262 int minimize_x = 0; 260 int minimize_x = 0;
263 if (maximize_mode_animation_->IsShowing()) { 261 if (maximize_mode_animation_->IsShowing()) {
264 double scaled_value = CapAnimationValue( 262 double scaled_value =
265 (current_value - SizeButtonShowStartValue()) 263 CapAnimationValue((current_value - SizeButtonShowStartValue()) /
266 / SizeButtonShowDuration()); 264 SizeButtonShowDuration());
267 double tweened_value_alpha = 265 double tweened_value_alpha =
268 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT,scaled_value); 266 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value);
269 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 0, 255); 267 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 0, 255);
270 268
271 double tweened_value_slide = 269 double tweened_value_slide =
272 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, current_value); 270 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, current_value);
273 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_slide, 271 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_slide,
274 size_button_->x(), 0); 272 size_button_->x(), 0);
275 } else { 273 } else {
276 double scaled_value_alpha = CapAnimationValue( 274 double scaled_value_alpha =
277 (1.0f - current_value) / SizeButtonHideDuration()); 275 CapAnimationValue((1.0f - current_value) / SizeButtonHideDuration());
278 double tweened_value_alpha = 276 double tweened_value_alpha =
279 gfx::Tween::CalculateValue(gfx::Tween::EASE_IN, scaled_value_alpha); 277 gfx::Tween::CalculateValue(gfx::Tween::EASE_IN, scaled_value_alpha);
280 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 255, 0); 278 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 255, 0);
281 279
282 double scaled_value_position = CapAnimationValue( 280 double scaled_value_position = CapAnimationValue(
283 (HidePositionStartValue() - current_value) 281 (HidePositionStartValue() - current_value) / HidePositionStartValue());
284 / HidePositionStartValue());
285 double tweened_value_position = 282 double tweened_value_position =
286 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value_position); 283 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value_position);
287 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_position, 0, 284 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_position, 0,
288 size_button_->x()); 285 size_button_->x());
289 } 286 }
290 size_button_->SetAlpha(size_alpha); 287 size_button_->SetAlpha(size_alpha);
291 minimize_button_->SetX(minimize_x); 288 minimize_button_->SetX(minimize_x);
292 } 289 }
293 290
294 void FrameCaptionButtonContainerView::SetButtonIcon(FrameCaptionButton* button, 291 void FrameCaptionButtonContainerView::SetButtonIcon(FrameCaptionButton* button,
295 CaptionButtonIcon icon, 292 CaptionButtonIcon icon,
296 Animate animate) { 293 Animate animate) {
297 // The early return is dependant on |animate| because callers use 294 // The early return is dependant on |animate| because callers use
298 // SetButtonIcon() with ANIMATE_NO to progress |button|'s crossfade animation 295 // SetButtonIcon() with ANIMATE_NO to progress |button|'s crossfade animation
299 // to the end. 296 // to the end.
300 if (button->icon() == icon && 297 if (button->icon() == icon &&
301 (animate == ANIMATE_YES || !button->IsAnimatingImageSwap())) { 298 (animate == ANIMATE_YES || !button->IsAnimatingImageSwap())) {
302 return; 299 return;
303 } 300 }
304 301
305 FrameCaptionButton::Animate fcb_animate = (animate == ANIMATE_YES) ? 302 FrameCaptionButton::Animate fcb_animate =
306 FrameCaptionButton::ANIMATE_YES : FrameCaptionButton::ANIMATE_NO; 303 (animate == ANIMATE_YES) ? FrameCaptionButton::ANIMATE_YES
304 : FrameCaptionButton::ANIMATE_NO;
307 auto it = button_icon_id_map_.find(icon); 305 auto it = button_icon_id_map_.find(icon);
308 if (it != button_icon_id_map_.end()) 306 if (it != button_icon_id_map_.end())
309 button->SetImage(icon, fcb_animate, it->second); 307 button->SetImage(icon, fcb_animate, it->second);
310 } 308 }
311 309
312 bool FrameCaptionButtonContainerView::ShouldSizeButtonBeVisible() const { 310 bool FrameCaptionButtonContainerView::ShouldSizeButtonBeVisible() const {
313 return !Shell::GetInstance()->maximize_mode_controller()-> 311 return !Shell::GetInstance()
314 IsMaximizeModeWindowManagerEnabled() && 312 ->maximize_mode_controller()
315 frame_->widget_delegate()->CanMaximize(); 313 ->IsMaximizeModeWindowManagerEnabled() &&
314 frame_->widget_delegate()->CanMaximize();
316 } 315 }
317 316
318 void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender, 317 void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender,
319 const ui::Event& event) { 318 const ui::Event& event) {
320 // Abort any animations of the button icons. 319 // Abort any animations of the button icons.
321 SetButtonsToNormal(ANIMATE_NO); 320 SetButtonsToNormal(ANIMATE_NO);
322 321
323 UserMetricsAction action = UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE; 322 UserMetricsAction action = UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE;
324 if (sender == minimize_button_) { 323 if (sender == minimize_button_) {
325 frame_->Minimize(); 324 frame_->Minimize();
(...skipping 21 matching lines...) Expand all
347 } 346 }
348 WmShell::Get()->RecordUserMetricsAction(action); 347 WmShell::Get()->RecordUserMetricsAction(action);
349 } 348 }
350 349
351 bool FrameCaptionButtonContainerView::IsMinimizeButtonVisible() const { 350 bool FrameCaptionButtonContainerView::IsMinimizeButtonVisible() const {
352 return minimize_button_->visible(); 351 return minimize_button_->visible();
353 } 352 }
354 353
355 void FrameCaptionButtonContainerView::SetButtonsToNormal(Animate animate) { 354 void FrameCaptionButtonContainerView::SetButtonsToNormal(Animate animate) {
356 SetButtonIcons(CAPTION_BUTTON_ICON_MINIMIZE, CAPTION_BUTTON_ICON_CLOSE, 355 SetButtonIcons(CAPTION_BUTTON_ICON_MINIMIZE, CAPTION_BUTTON_ICON_CLOSE,
357 animate); 356 animate);
358 minimize_button_->SetState(views::Button::STATE_NORMAL); 357 minimize_button_->SetState(views::Button::STATE_NORMAL);
359 size_button_->SetState(views::Button::STATE_NORMAL); 358 size_button_->SetState(views::Button::STATE_NORMAL);
360 close_button_->SetState(views::Button::STATE_NORMAL); 359 close_button_->SetState(views::Button::STATE_NORMAL);
361 } 360 }
362 361
363 void FrameCaptionButtonContainerView::SetButtonIcons( 362 void FrameCaptionButtonContainerView::SetButtonIcons(
364 CaptionButtonIcon minimize_button_icon, 363 CaptionButtonIcon minimize_button_icon,
365 CaptionButtonIcon close_button_icon, 364 CaptionButtonIcon close_button_icon,
366 Animate animate) { 365 Animate animate) {
367 SetButtonIcon(minimize_button_, minimize_button_icon, animate); 366 SetButtonIcon(minimize_button_, minimize_button_icon, animate);
368 SetButtonIcon(close_button_, close_button_icon, animate); 367 SetButtonIcon(close_button_, close_button_icon, animate);
369 } 368 }
370 369
371 const FrameCaptionButton* FrameCaptionButtonContainerView::GetButtonClosestTo( 370 const FrameCaptionButton* FrameCaptionButtonContainerView::GetButtonClosestTo(
372 const gfx::Point& position_in_screen) const { 371 const gfx::Point& position_in_screen) const {
373 // Since the buttons all have the same size, the closest button is the button 372 // Since the buttons all have the same size, the closest button is the button
374 // with the center point closest to |position_in_screen|. 373 // with the center point closest to |position_in_screen|.
375 // TODO(pkotwicz): Make the caption buttons not overlap. 374 // TODO(pkotwicz): Make the caption buttons not overlap.
376 gfx::Point position(position_in_screen); 375 gfx::Point position(position_in_screen);
377 views::View::ConvertPointFromScreen(this, &position); 376 views::View::ConvertPointFromScreen(this, &position);
378 377
379 FrameCaptionButton* buttons[] = { 378 FrameCaptionButton* buttons[] = {minimize_button_, size_button_,
380 minimize_button_, size_button_, close_button_ 379 close_button_};
381 };
382 int min_squared_distance = INT_MAX; 380 int min_squared_distance = INT_MAX;
383 FrameCaptionButton* closest_button = NULL; 381 FrameCaptionButton* closest_button = NULL;
384 for (size_t i = 0; i < arraysize(buttons); ++i) { 382 for (size_t i = 0; i < arraysize(buttons); ++i) {
385 FrameCaptionButton* button = buttons[i]; 383 FrameCaptionButton* button = buttons[i];
386 if (!button->visible()) 384 if (!button->visible())
387 continue; 385 continue;
388 386
389 gfx::Point center_point = button->GetLocalBounds().CenterPoint(); 387 gfx::Point center_point = button->GetLocalBounds().CenterPoint();
390 views::View::ConvertPointToTarget(button, this, &center_point); 388 views::View::ConvertPointToTarget(button, this, &center_point);
391 int squared_distance = static_cast<int>( 389 int squared_distance = static_cast<int>(
392 pow(static_cast<double>(position.x() - center_point.x()), 2) + 390 pow(static_cast<double>(position.x() - center_point.x()), 2) +
393 pow(static_cast<double>(position.y() - center_point.y()), 2)); 391 pow(static_cast<double>(position.y() - center_point.y()), 2));
394 if (squared_distance < min_squared_distance) { 392 if (squared_distance < min_squared_distance) {
395 min_squared_distance = squared_distance; 393 min_squared_distance = squared_distance;
396 closest_button = button; 394 closest_button = button;
397 } 395 }
398 } 396 }
399 return closest_button; 397 return closest_button;
400 } 398 }
401 399
402 void FrameCaptionButtonContainerView::SetHoveredAndPressedButtons( 400 void FrameCaptionButtonContainerView::SetHoveredAndPressedButtons(
403 const FrameCaptionButton* to_hover, 401 const FrameCaptionButton* to_hover,
404 const FrameCaptionButton* to_press) { 402 const FrameCaptionButton* to_press) {
405 FrameCaptionButton* buttons[] = { 403 FrameCaptionButton* buttons[] = {minimize_button_, size_button_,
406 minimize_button_, size_button_, close_button_ 404 close_button_};
407 };
408 for (size_t i = 0; i < arraysize(buttons); ++i) { 405 for (size_t i = 0; i < arraysize(buttons); ++i) {
409 FrameCaptionButton* button = buttons[i]; 406 FrameCaptionButton* button = buttons[i];
410 views::Button::ButtonState new_state = views::Button::STATE_NORMAL; 407 views::Button::ButtonState new_state = views::Button::STATE_NORMAL;
411 if (button == to_hover) 408 if (button == to_hover)
412 new_state = views::Button::STATE_HOVERED; 409 new_state = views::Button::STATE_HOVERED;
413 else if (button == to_press) 410 else if (button == to_press)
414 new_state = views::Button::STATE_PRESSED; 411 new_state = views::Button::STATE_PRESSED;
415 button->SetState(new_state); 412 button->SetState(new_state);
416 } 413 }
417 } 414 }
418 415
419 } // namespace ash 416 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698