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/common/wm/overview/window_selector_item.h" | 5 #include "ash/common/wm/overview/window_selector_item.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "ui/wm/core/shadow.h" | 49 #include "ui/wm/core/shadow.h" |
50 #include "ui/wm/core/window_util.h" | 50 #include "ui/wm/core/window_util.h" |
51 | 51 |
52 namespace ash { | 52 namespace ash { |
53 | 53 |
54 namespace { | 54 namespace { |
55 | 55 |
56 // In the conceptual overview table, the window margin is the space reserved | 56 // In the conceptual overview table, the window margin is the space reserved |
57 // around the window within the cell. This margin does not overlap so the | 57 // around the window within the cell. This margin does not overlap so the |
58 // closest distance between adjacent windows will be twice this amount. | 58 // closest distance between adjacent windows will be twice this amount. |
59 static const int kWindowMargin = 30; | 59 static const int kWindowMargin = 5; |
60 static const int kWindowMarginMD = 5; | |
61 | 60 |
62 // Cover the transformed window including the gaps between the windows with a | 61 // Cover the transformed window including the gaps between the windows with a |
63 // transparent shield to block the input events from reaching the transformed | 62 // transparent shield to block the input events from reaching the transformed |
64 // window while in overview. | 63 // window while in overview. |
65 static const int kWindowSelectorMargin = kWindowMarginMD * 2; | 64 static const int kWindowSelectorMargin = kWindowMargin * 2; |
66 | 65 |
67 // Foreground label color. | 66 // Foreground label color. |
68 static const SkColor kLabelColor = SK_ColorWHITE; | 67 static const SkColor kLabelColor = SK_ColorWHITE; |
69 | 68 |
70 // TODO(tdanderson): Move this to a central location. | 69 // TODO(tdanderson): Move this to a central location. |
71 static const SkColor kCloseButtonColor = SK_ColorWHITE; | 70 static const SkColor kCloseButtonColor = SK_ColorWHITE; |
72 | 71 |
73 // Label background color used with Material Design once in overview mode. | 72 // Label background color once in overview mode. |
74 static const SkColor kLabelBackgroundColor = SkColorSetARGB(25, 255, 255, 255); | 73 static const SkColor kLabelBackgroundColor = SkColorSetARGB(25, 255, 255, 255); |
75 | 74 |
76 // Label background color used with Material Design when exiting overview mode. | 75 // Label background color when exiting overview mode. |
77 static const SkColor kLabelExitColor = SkColorSetARGB(255, 90, 90, 90); | 76 static const SkColor kLabelExitColor = SkColorSetARGB(255, 90, 90, 90); |
78 | 77 |
79 // Corner radius for the selection tiles used with Material Design. | 78 // Corner radius for the selection tiles. |
80 static int kLabelBackgroundRadius = 2; | 79 static int kLabelBackgroundRadius = 2; |
81 | 80 |
82 // Label shadow color. | |
83 static const SkColor kLabelShadow = SkColorSetARGB(176, 0, 0, 0); | |
84 | |
85 // Vertical padding for the label, on top of it. | 81 // Vertical padding for the label, on top of it. |
86 static const int kVerticalLabelPadding = 20; | 82 static const int kVerticalLabelPadding = 20; |
87 | 83 |
88 // Horizontal padding for the label, on both sides. Used with Material Design. | 84 // Horizontal padding for the label, on both sides. |
89 static const int kHorizontalLabelPaddingMD = 8; | 85 static const int kHorizontalLabelPadding = 8; |
90 | 86 |
91 // Solid shadow length from the label | 87 // Height of an item header. |
92 static const int kVerticalShadowOffset = 1; | |
93 | |
94 // Amount of blur applied to the label shadow | |
95 static const int kShadowBlur = 10; | |
96 | |
97 // Height of an item header in Material Design. | |
98 static const int kHeaderHeight = 32; | 88 static const int kHeaderHeight = 32; |
99 | 89 |
100 // Opacity for dimmed items. | 90 // Opacity for dimmed items. |
101 static const float kDimmedItemOpacity = 0.5f; | 91 static const float kDimmedItemOpacity = 0.5f; |
102 | 92 |
103 // Opacity for fading out during closing a window. | 93 // Opacity for fading out during closing a window. |
104 static const float kClosingItemOpacity = 0.8f; | 94 static const float kClosingItemOpacity = 0.8f; |
105 | 95 |
106 // Opacity for the item header. | 96 // Opacity for the item header. |
107 static const float kHeaderOpacity = | 97 static const float kHeaderOpacity = |
(...skipping 27 matching lines...) Expand all Loading... |
135 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, | 125 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, |
136 window); | 126 window); |
137 window->SetOpacity(1.0f); | 127 window->SetOpacity(1.0f); |
138 } | 128 } |
139 | 129 |
140 } // namespace | 130 } // namespace |
141 | 131 |
142 WindowSelectorItem::OverviewCloseButton::OverviewCloseButton( | 132 WindowSelectorItem::OverviewCloseButton::OverviewCloseButton( |
143 views::ButtonListener* listener) | 133 views::ButtonListener* listener) |
144 : views::ImageButton(listener) { | 134 : views::ImageButton(listener) { |
145 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 135 icon_image_ = gfx::CreateVectorIcon(gfx::VectorIconId::WINDOW_CONTROL_CLOSE, |
146 icon_image_ = gfx::CreateVectorIcon(gfx::VectorIconId::WINDOW_CONTROL_CLOSE, | 136 kCloseButtonColor); |
147 kCloseButtonColor); | 137 SetImage(views::CustomButton::STATE_NORMAL, &icon_image_); |
148 SetImage(views::CustomButton::STATE_NORMAL, &icon_image_); | 138 SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
149 SetImage(views::CustomButton::STATE_HOVERED, &icon_image_); | 139 views::ImageButton::ALIGN_MIDDLE); |
150 SetImage(views::CustomButton::STATE_PRESSED, &icon_image_); | 140 SetMinimumImageSize(gfx::Size(kHeaderHeight, kHeaderHeight)); |
151 SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
152 views::ImageButton::ALIGN_MIDDLE); | |
153 SetMinimumImageSize(gfx::Size(kHeaderHeight, kHeaderHeight)); | |
154 } else { | |
155 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
156 SetImage(views::CustomButton::STATE_NORMAL, | |
157 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE)); | |
158 SetImage(views::CustomButton::STATE_HOVERED, | |
159 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_H)); | |
160 SetImage(views::CustomButton::STATE_PRESSED, | |
161 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_P)); | |
162 } | |
163 } | 141 } |
164 | 142 |
165 WindowSelectorItem::OverviewCloseButton::~OverviewCloseButton() {} | 143 WindowSelectorItem::OverviewCloseButton::~OverviewCloseButton() {} |
166 | 144 |
167 // A View having rounded top corners and a specified background color which is | 145 // A View having rounded top corners and a specified background color which is |
168 // only painted within the bounds defined by the rounded corners. | 146 // only painted within the bounds defined by the rounded corners. |
169 // This class coordinates the transitions of the overview mode header when | 147 // This class coordinates the transitions of the overview mode header when |
170 // entering the overview mode. Those animations are: | 148 // entering the overview mode. Those animations are: |
171 // - Opacity animation. The header is initially same color as the original | 149 // - Opacity animation. The header is initially same color as the original |
172 // window's header. It starts as transparent and is faded in. When the full | 150 // window's header. It starts as transparent and is faded in. When the full |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 int corner_radius_; | 309 int corner_radius_; |
332 SkColor initial_color_; | 310 SkColor initial_color_; |
333 SkColor target_color_; | 311 SkColor target_color_; |
334 int current_value_; | 312 int current_value_; |
335 ui::Layer* layer_; | 313 ui::Layer* layer_; |
336 std::unique_ptr<gfx::SlideAnimation> animation_; | 314 std::unique_ptr<gfx::SlideAnimation> animation_; |
337 | 315 |
338 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); | 316 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); |
339 }; | 317 }; |
340 | 318 |
341 bool WindowSelectorItem::use_mask_ = false; | |
342 bool WindowSelectorItem::use_shape_ = false; | |
343 | |
344 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( | 319 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( |
345 views::ButtonListener* listener, | 320 views::ButtonListener* listener, |
346 const base::string16& text) | 321 const base::string16& text) |
347 : LabelButton(listener, text) {} | 322 : LabelButton(listener, text) {} |
348 | 323 |
349 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} | 324 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} |
350 | 325 |
351 void WindowSelectorItem::OverviewLabelButton::SetBackgroundColorHint( | 326 void WindowSelectorItem::OverviewLabelButton::SetBackgroundColorHint( |
352 SkColor color) { | 327 SkColor color) { |
353 // Tell the label what color it will be drawn onto. It will use whether the | 328 // Tell the label what color it will be drawn onto. It will use whether the |
354 // background color is opaque or transparent to decide whether to use subpixel | 329 // background color is opaque or transparent to decide whether to use subpixel |
355 // rendering. Does not actually set the label's background color. | 330 // rendering. Does not actually set the label's background color. |
356 label()->SetBackgroundColor(color); | 331 label()->SetBackgroundColor(color); |
357 } | 332 } |
358 | 333 |
359 gfx::Rect WindowSelectorItem::OverviewLabelButton::GetChildAreaBounds() { | 334 gfx::Rect WindowSelectorItem::OverviewLabelButton::GetChildAreaBounds() { |
360 gfx::Rect bounds = GetLocalBounds(); | 335 gfx::Rect bounds = GetLocalBounds(); |
361 bounds.Inset(padding_); | 336 bounds.Inset(padding_ + gfx::Insets(0, kHorizontalLabelPadding)); |
362 if (ash::MaterialDesignController::IsOverviewMaterial()) | |
363 bounds.Inset(kHorizontalLabelPaddingMD, 0, kHorizontalLabelPaddingMD, 0); | |
364 return bounds; | 337 return bounds; |
365 } | 338 } |
366 | 339 |
367 // Container View that has an item label and a close button as children. | 340 // Container View that has an item label and a close button as children. |
368 class WindowSelectorItem::CaptionContainerView : public views::View { | 341 class WindowSelectorItem::CaptionContainerView : public views::View { |
369 public: | 342 public: |
370 CaptionContainerView(WindowSelectorItem::OverviewLabelButton* label, | 343 CaptionContainerView(WindowSelectorItem::OverviewLabelButton* label, |
371 views::ImageButton* close_button, | 344 views::ImageButton* close_button, |
372 WindowSelectorItem::RoundedContainerView* background) | 345 WindowSelectorItem::RoundedContainerView* background) |
373 : label_(label), close_button_(close_button), background_(background) { | 346 : label_(label), close_button_(close_button), background_(background) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 root_window_(window->GetRootWindow()), | 388 root_window_(window->GetRootWindow()), |
416 transform_window_(window), | 389 transform_window_(window), |
417 in_bounds_update_(false), | 390 in_bounds_update_(false), |
418 selected_(false), | 391 selected_(false), |
419 caption_container_view_(nullptr), | 392 caption_container_view_(nullptr), |
420 window_label_button_view_(nullptr), | 393 window_label_button_view_(nullptr), |
421 close_button_(new OverviewCloseButton(this)), | 394 close_button_(new OverviewCloseButton(this)), |
422 window_selector_(window_selector), | 395 window_selector_(window_selector), |
423 background_view_(nullptr) { | 396 background_view_(nullptr) { |
424 CreateWindowLabel(window->GetTitle()); | 397 CreateWindowLabel(window->GetTitle()); |
425 if (!ash::MaterialDesignController::IsOverviewMaterial()) { | |
426 views::Widget::InitParams params; | |
427 params.type = views::Widget::InitParams::TYPE_POPUP; | |
428 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
429 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
430 params.name = "OverviewModeCloseButton"; | |
431 close_button_widget_.reset(new views::Widget); | |
432 close_button_widget_->set_focus_on_creation(false); | |
433 window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( | |
434 close_button_widget_.get(), kShellWindowId_StatusContainer, ¶ms); | |
435 close_button_widget_->Init(params); | |
436 close_button_->SetVisible(false); | |
437 close_button_widget_->SetContentsView(close_button_); | |
438 close_button_widget_->SetSize(close_button_->GetPreferredSize()); | |
439 close_button_widget_->Show(); | |
440 | |
441 gfx::Rect close_button_rect(close_button_->GetPreferredSize()); | |
442 // Align the center of the button with position (0, 0) so that the | |
443 // translate transform does not need to take the button dimensions into | |
444 // account. | |
445 close_button_rect.set_x(-close_button_rect.width() / 2); | |
446 close_button_rect.set_y(-close_button_rect.height() / 2); | |
447 WmLookup::Get() | |
448 ->GetWindowForWidget(close_button_widget_.get()) | |
449 ->SetBounds(close_button_rect); | |
450 } | |
451 GetWindow()->AddObserver(this); | 398 GetWindow()->AddObserver(this); |
452 } | 399 } |
453 | 400 |
454 WindowSelectorItem::~WindowSelectorItem() { | 401 WindowSelectorItem::~WindowSelectorItem() { |
455 GetWindow()->RemoveObserver(this); | 402 GetWindow()->RemoveObserver(this); |
456 } | 403 } |
457 | 404 |
458 WmWindow* WindowSelectorItem::GetWindow() { | 405 WmWindow* WindowSelectorItem::GetWindow() { |
459 return transform_window_.window(); | 406 return transform_window_.window(); |
460 } | 407 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } | 452 } |
506 | 453 |
507 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds, | 454 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds, |
508 OverviewAnimationType animation_type) { | 455 OverviewAnimationType animation_type) { |
509 if (in_bounds_update_) | 456 if (in_bounds_update_) |
510 return; | 457 return; |
511 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); | 458 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); |
512 target_bounds_ = target_bounds; | 459 target_bounds_ = target_bounds; |
513 | 460 |
514 gfx::Rect inset_bounds(target_bounds); | 461 gfx::Rect inset_bounds(target_bounds); |
515 if (ash::MaterialDesignController::IsOverviewMaterial()) | 462 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
516 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); | |
517 else | |
518 inset_bounds.Inset(kWindowMargin, kWindowMargin); | |
519 SetItemBounds(inset_bounds, animation_type); | 463 SetItemBounds(inset_bounds, animation_type); |
520 | 464 |
521 // SetItemBounds is called before UpdateHeaderLayout so the header can | 465 // SetItemBounds is called before UpdateHeaderLayout so the header can |
522 // properly use the updated windows bounds. | 466 // properly use the updated windows bounds. |
523 UpdateHeaderLayout(HeaderFadeInMode::UPDATE, animation_type); | 467 UpdateHeaderLayout(HeaderFadeInMode::UPDATE, animation_type); |
524 if (!ash::MaterialDesignController::IsOverviewMaterial()) | |
525 UpdateWindowLabel(target_bounds, animation_type); | |
526 } | 468 } |
527 | 469 |
528 void WindowSelectorItem::SetSelected(bool selected) { | 470 void WindowSelectorItem::SetSelected(bool selected) { |
529 if (!ash::MaterialDesignController::IsOverviewMaterial()) | |
530 return; | |
531 selected_ = selected; | 471 selected_ = selected; |
532 background_view_->AnimateBackgroundOpacity(selected ? 0.f : kHeaderOpacity); | 472 background_view_->AnimateBackgroundOpacity(selected ? 0.f : kHeaderOpacity); |
533 | 473 |
534 if (shadow_) { | 474 if (shadow_) { |
535 ui::ScopedLayerAnimationSettings animation_settings_shadow( | 475 ui::ScopedLayerAnimationSettings animation_settings_shadow( |
536 shadow_->shadow_layer()->GetAnimator()); | 476 shadow_->shadow_layer()->GetAnimator()); |
537 animation_settings_shadow.SetTransitionDuration( | 477 animation_settings_shadow.SetTransitionDuration( |
538 base::TimeDelta::FromMilliseconds(kSelectorFadeInMilliseconds)); | 478 base::TimeDelta::FromMilliseconds(kSelectorFadeInMilliseconds)); |
539 animation_settings_shadow.SetTweenType( | 479 animation_settings_shadow.SetTweenType( |
540 selected ? gfx::Tween::FAST_OUT_LINEAR_IN | 480 selected ? gfx::Tween::FAST_OUT_LINEAR_IN |
541 : gfx::Tween::LINEAR_OUT_SLOW_IN); | 481 : gfx::Tween::LINEAR_OUT_SLOW_IN); |
542 animation_settings_shadow.SetPreemptionStrategy( | 482 animation_settings_shadow.SetPreemptionStrategy( |
543 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 483 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
544 shadow_->shadow_layer()->SetOpacity(selected ? 0.0f : 1.0f); | 484 shadow_->shadow_layer()->SetOpacity(selected ? 0.0f : 1.0f); |
545 } | 485 } |
546 } | 486 } |
547 | 487 |
548 void WindowSelectorItem::RecomputeWindowTransforms() { | |
549 if (in_bounds_update_ || target_bounds_.IsEmpty()) | |
550 return; | |
551 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); | |
552 gfx::Rect inset_bounds(target_bounds_); | |
553 if (ash::MaterialDesignController::IsOverviewMaterial()) | |
554 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); | |
555 else | |
556 inset_bounds.Inset(kWindowMargin, kWindowMargin); | |
557 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE); | |
558 UpdateHeaderLayout(HeaderFadeInMode::UPDATE, | |
559 OverviewAnimationType::OVERVIEW_ANIMATION_NONE); | |
560 } | |
561 | |
562 void WindowSelectorItem::SendAccessibleSelectionEvent() { | 488 void WindowSelectorItem::SendAccessibleSelectionEvent() { |
563 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, | 489 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, |
564 true); | 490 true); |
565 } | 491 } |
566 | 492 |
567 void WindowSelectorItem::CloseWindow() { | 493 void WindowSelectorItem::CloseWindow() { |
568 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 494 gfx::Rect inset_bounds(target_bounds_); |
569 gfx::Rect inset_bounds(target_bounds_); | 495 inset_bounds.Inset(target_bounds_.width() * kPreCloseScale, |
570 inset_bounds.Inset(target_bounds_.width() * kPreCloseScale, | 496 target_bounds_.height() * kPreCloseScale); |
571 target_bounds_.height() * kPreCloseScale); | 497 OverviewAnimationType animation_type = |
572 OverviewAnimationType animation_type = | 498 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM; |
573 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM; | 499 // Scale down both the window and label. |
574 // Scale down both the window and label. | 500 SetBounds(inset_bounds, animation_type); |
575 SetBounds(inset_bounds, animation_type); | 501 // First animate opacity to an intermediate value concurrently with the |
576 // First animate opacity to an intermediate value concurrently with the | 502 // scaling animation. |
577 // scaling animation. | 503 AnimateOpacity(kClosingItemOpacity, animation_type); |
578 AnimateOpacity(kClosingItemOpacity, animation_type); | |
579 | 504 |
580 // Fade out the window and the label, effectively hiding them. | 505 // Fade out the window and the label, effectively hiding them. |
581 AnimateOpacity( | 506 AnimateOpacity(0.0, |
582 0.0, OverviewAnimationType::OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM); | 507 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM); |
583 } | |
584 transform_window_.Close(); | 508 transform_window_.Close(); |
585 } | 509 } |
586 | 510 |
587 void WindowSelectorItem::HideHeaderAndSetShape(int radius) { | 511 void WindowSelectorItem::HideHeaderAndSetShape(int radius) { |
588 transform_window_.HideHeaderAndSetShape(use_mask_, use_shape_, radius); | 512 transform_window_.HideHeaderAndSetShape(radius); |
589 } | 513 } |
590 | 514 |
591 void WindowSelectorItem::SetDimmed(bool dimmed) { | 515 void WindowSelectorItem::SetDimmed(bool dimmed) { |
592 dimmed_ = dimmed; | 516 dimmed_ = dimmed; |
593 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); | 517 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); |
594 } | 518 } |
595 | 519 |
596 void WindowSelectorItem::ButtonPressed(views::Button* sender, | 520 void WindowSelectorItem::ButtonPressed(views::Button* sender, |
597 const ui::Event& event) { | 521 const ui::Event& event) { |
598 if (sender == close_button_) { | 522 if (sender == close_button_) { |
(...skipping 11 matching lines...) Expand all Loading... |
610 } | 534 } |
611 | 535 |
612 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { | 536 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { |
613 // TODO(flackr): Maybe add the new title to a vector of titles so that we can | 537 // TODO(flackr): Maybe add the new title to a vector of titles so that we can |
614 // filter any of the titles the window had while in the overview session. | 538 // filter any of the titles the window had while in the overview session. |
615 window_label_button_view_->SetText(window->GetTitle()); | 539 window_label_button_view_->SetText(window->GetTitle()); |
616 UpdateCloseButtonAccessibilityName(); | 540 UpdateCloseButtonAccessibilityName(); |
617 } | 541 } |
618 | 542 |
619 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { | 543 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { |
620 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMarginMD); | 544 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMargin); |
621 return ScopedTransformOverviewWindow::GetItemScale( | 545 return ScopedTransformOverviewWindow::GetItemScale( |
622 transform_window_.GetTargetBoundsInScreen().size(), inset_size, | 546 transform_window_.GetTargetBoundsInScreen().size(), inset_size, |
623 hide_header() ? transform_window_.GetTopInset() : 0, | 547 transform_window_.GetTopInset(), |
624 close_button_->GetPreferredSize().height()); | 548 close_button_->GetPreferredSize().height()); |
625 } | 549 } |
626 | 550 |
627 gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const { | 551 gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const { |
628 return transform_window_.GetTargetBoundsInScreen(); | 552 return transform_window_.GetTargetBoundsInScreen(); |
629 } | 553 } |
630 | 554 |
631 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, | 555 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, |
632 OverviewAnimationType animation_type) { | 556 OverviewAnimationType animation_type) { |
633 DCHECK(root_window_ == GetWindow()->GetRootWindow()); | 557 DCHECK(root_window_ == GetWindow()->GetRootWindow()); |
634 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); | 558 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); |
635 | 559 |
636 // Avoid division by zero by ensuring screen bounds is not empty. | 560 // Avoid division by zero by ensuring screen bounds is not empty. |
637 gfx::Size screen_size(screen_rect.size()); | 561 gfx::Size screen_size(screen_rect.size()); |
638 screen_size.SetToMax(gfx::Size(1, 1)); | 562 screen_size.SetToMax(gfx::Size(1, 1)); |
639 screen_rect.set_size(screen_size); | 563 screen_rect.set_size(screen_size); |
640 | 564 |
641 int top_view_inset = 0; | 565 const int top_view_inset = transform_window_.GetTopInset(); |
642 int title_height = 0; | 566 const int title_height = close_button_->GetPreferredSize().height(); |
643 if (ash::MaterialDesignController::IsOverviewMaterial()) { | |
644 if (hide_header()) | |
645 top_view_inset = transform_window_.GetTopInset(); | |
646 title_height = close_button_->GetPreferredSize().height(); | |
647 } | |
648 gfx::Rect selector_item_bounds = | 567 gfx::Rect selector_item_bounds = |
649 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( | 568 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( |
650 screen_rect, target_bounds, top_view_inset, title_height); | 569 screen_rect, target_bounds, top_view_inset, title_height); |
651 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( | 570 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( |
652 screen_rect, selector_item_bounds); | 571 screen_rect, selector_item_bounds); |
653 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 572 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
654 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 573 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
655 transform_window_.SetTransform(root_window_, transform, use_mask_); | 574 transform_window_.SetTransform(root_window_, transform); |
656 transform_window_.set_overview_transform(transform); | 575 transform_window_.set_overview_transform(transform); |
657 } | 576 } |
658 | 577 |
659 void WindowSelectorItem::SetOpacity(float opacity) { | 578 void WindowSelectorItem::SetOpacity(float opacity) { |
660 window_label_->SetOpacity(opacity); | 579 window_label_->SetOpacity(opacity); |
661 if (background_view_) { | 580 if (background_view_) { |
662 background_view_->AnimateBackgroundOpacity( | 581 background_view_->AnimateBackgroundOpacity( |
663 selected_ ? 0.f : kHeaderOpacity * opacity); | 582 selected_ ? 0.f : kHeaderOpacity * opacity); |
664 } | 583 } |
665 | |
666 if (!ash::MaterialDesignController::IsOverviewMaterial()) | |
667 close_button_widget_->SetOpacity(opacity); | |
668 | |
669 transform_window_.SetOpacity(opacity); | 584 transform_window_.SetOpacity(opacity); |
670 } | 585 } |
671 | 586 |
672 void WindowSelectorItem::UpdateWindowLabel( | 587 void WindowSelectorItem::UpdateWindowLabel( |
673 const gfx::Rect& window_bounds, | 588 const gfx::Rect& window_bounds, |
674 OverviewAnimationType animation_type) { | 589 OverviewAnimationType animation_type) { |
675 if (!window_label_->IsVisible()) { | 590 if (!window_label_->IsVisible()) { |
676 window_label_->Show(); | 591 window_label_->Show(); |
677 SetupFadeInAfterLayout(window_label_.get()); | 592 SetupFadeInAfterLayout(window_label_.get()); |
678 } | 593 } |
679 | 594 |
680 gfx::Rect label_bounds = root_window_->ConvertRectFromScreen(window_bounds); | 595 gfx::Rect label_bounds = root_window_->ConvertRectFromScreen(window_bounds); |
681 window_label_button_view_->set_padding( | 596 window_label_button_view_->set_padding( |
682 gfx::Insets(label_bounds.height() - kVerticalLabelPadding, 0, 0, 0)); | 597 gfx::Insets(label_bounds.height() - kVerticalLabelPadding, 0, 0, 0)); |
683 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 598 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
684 ScopedOverviewAnimationSettingsFactory::Get() | 599 ScopedOverviewAnimationSettingsFactory::Get() |
685 ->CreateOverviewAnimationSettings( | 600 ->CreateOverviewAnimationSettings( |
686 animation_type, | 601 animation_type, |
687 WmLookup::Get()->GetWindowForWidget(window_label_.get())); | 602 WmLookup::Get()->GetWindowForWidget(window_label_.get())); |
688 | 603 |
689 WmWindow* window_label_window = | 604 WmWindow* window_label_window = |
690 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | 605 WmLookup::Get()->GetWindowForWidget(window_label_.get()); |
691 window_label_window->SetBounds(label_bounds); | 606 window_label_window->SetBounds(label_bounds); |
692 } | 607 } |
693 | 608 |
694 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { | 609 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { |
695 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); | 610 background_view_ = new RoundedContainerView(this, transform_window_.window(), |
696 if (material) { | 611 kLabelBackgroundRadius, |
697 background_view_ = new RoundedContainerView( | 612 transform_window_.GetTopColor()); |
698 this, transform_window_.window(), kLabelBackgroundRadius, | 613 // |background_view_| will get added as a child to CaptionContainerView. |
699 transform_window_.GetTopColor()); | |
700 // |background_view_| will get added as a child to CaptionContainerView. | |
701 } | |
702 views::Widget::InitParams params_label; | 614 views::Widget::InitParams params_label; |
703 params_label.type = views::Widget::InitParams::TYPE_POPUP; | 615 params_label.type = views::Widget::InitParams::TYPE_POPUP; |
704 params_label.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 616 params_label.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
705 params_label.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 617 params_label.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
706 params_label.visible_on_all_workspaces = true; | 618 params_label.visible_on_all_workspaces = true; |
707 params_label.name = "OverviewModeLabel"; | 619 params_label.name = "OverviewModeLabel"; |
708 params_label.activatable = | 620 params_label.activatable = |
709 views::Widget::InitParams::Activatable::ACTIVATABLE_DEFAULT; | 621 views::Widget::InitParams::Activatable::ACTIVATABLE_DEFAULT; |
710 params_label.accept_events = true; | 622 params_label.accept_events = true; |
711 root_window_->GetRootWindowController() | 623 root_window_->GetRootWindowController() |
712 ->ConfigureWidgetInitParamsForContainer( | 624 ->ConfigureWidgetInitParamsForContainer( |
713 window_label_.get(), | 625 window_label_.get(), |
714 transform_window_.window()->GetParent()->GetShellWindowId(), | 626 transform_window_.window()->GetParent()->GetShellWindowId(), |
715 ¶ms_label); | 627 ¶ms_label); |
716 window_label_.reset(new views::Widget); | 628 window_label_.reset(new views::Widget); |
717 window_label_->set_focus_on_creation(false); | 629 window_label_->set_focus_on_creation(false); |
718 window_label_->Init(params_label); | 630 window_label_->Init(params_label); |
719 window_label_button_view_ = new OverviewLabelButton(this, title); | 631 window_label_button_view_ = new OverviewLabelButton(this, title); |
720 window_label_button_view_->SetBorder(views::Border::NullBorder()); | 632 window_label_button_view_->SetBorder(views::Border::NullBorder()); |
721 window_label_button_view_->SetEnabledTextColors(kLabelColor); | 633 window_label_button_view_->SetEnabledTextColors(kLabelColor); |
722 window_label_button_view_->set_animate_on_state_change(false); | 634 window_label_button_view_->set_animate_on_state_change(false); |
723 if (material) { | 635 WmWindow* label_window = |
724 WmWindow* label_window = | 636 WmLookup::Get()->GetWindowForWidget(window_label_.get()); |
725 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | 637 if (transform_window_.GetTopInset()) { |
726 if (transform_window_.GetTopInset()) { | 638 // For windows with headers the overview header fades in above the |
727 // For windows with headers the overview header fades in above the | 639 // original window header. |
728 // original window header. | 640 label_window->GetParent()->StackChildAbove(label_window, |
729 label_window->GetParent()->StackChildAbove(label_window, | 641 transform_window_.window()); |
730 transform_window_.window()); | |
731 } else { | |
732 // For tabbed windows the overview header slides from behind. The stacking | |
733 // is then corrected when the animation completes. | |
734 label_window->GetParent()->StackChildBelow(label_window, | |
735 transform_window_.window()); | |
736 } | |
737 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
738 } else { | 642 } else { |
739 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 643 // For tabbed windows the overview header slides from behind. The stacking |
740 window_label_button_view_->SetTextShadows(gfx::ShadowValues( | 644 // is then corrected when the animation completes. |
741 1, gfx::ShadowValue(gfx::Vector2d(0, kVerticalShadowOffset), | 645 label_window->GetParent()->StackChildBelow(label_window, |
742 kShadowBlur, kLabelShadow))); | 646 transform_window_.window()); |
743 } | 647 } |
| 648 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
744 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 649 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
745 window_label_button_view_->SetFontList(bundle.GetFontList( | 650 window_label_button_view_->SetFontList( |
746 material ? ui::ResourceBundle::BaseFont : ui::ResourceBundle::BoldFont)); | 651 bundle.GetFontList(ui::ResourceBundle::BaseFont)); |
747 if (material) { | 652 // Hint at the background color that the label will be drawn onto (for |
748 // Hint at the background color that the label will be drawn onto (for | 653 // subpixel antialiasing). Does not actually set the background color. |
749 // subpixel antialiasing). Does not actually set the background color. | 654 window_label_button_view_->SetBackgroundColorHint(kLabelBackgroundColor); |
750 window_label_button_view_->SetBackgroundColorHint(kLabelBackgroundColor); | 655 caption_container_view_ = new CaptionContainerView( |
751 caption_container_view_ = new CaptionContainerView( | 656 window_label_button_view_, close_button_, background_view_); |
752 window_label_button_view_, close_button_, background_view_); | 657 window_label_->SetContentsView(caption_container_view_); |
753 window_label_->SetContentsView(caption_container_view_); | 658 window_label_button_view_->SetVisible(false); |
754 window_label_button_view_->SetVisible(false); | 659 window_label_->SetOpacity(0); |
755 window_label_->SetOpacity(0); | 660 window_label_->Show(); |
756 window_label_->Show(); | |
757 | 661 |
758 // TODO(varkha): Restore shadows when programmatic shadows exist. | 662 // TODO(varkha): Restore shadows when programmatic shadows exist. |
759 // Note: current shadow implementation does not allow proper animation when | 663 // Note: current shadow implementation does not allow proper animation when |
760 // the parent layer bounds change during the animation since | 664 // the parent layer bounds change during the animation since |
761 // Shadow::UpdateLayerBounds() only happens before the animation starts. | 665 // Shadow::UpdateLayerBounds() only happens before the animation starts. |
762 if (ash::MaterialDesignController::GetMode() == | 666 if (ash::MaterialDesignController::GetMode() == |
763 ash::MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL) { | 667 ash::MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL) { |
764 shadow_.reset(new ::wm::Shadow()); | 668 shadow_.reset(new ::wm::Shadow()); |
765 shadow_->Init(::wm::Shadow::STYLE_INACTIVE); | 669 shadow_->Init(::wm::Shadow::STYLE_INACTIVE); |
766 shadow_->layer()->SetVisible(true); | 670 shadow_->layer()->SetVisible(true); |
767 window_label_->GetLayer()->Add(shadow_->layer()); | 671 window_label_->GetLayer()->Add(shadow_->layer()); |
768 } | |
769 window_label_->GetLayer()->SetMasksToBounds(false); | |
770 } else { | |
771 // Indicate that the label will be drawn onto a transparent background | |
772 // (disables subpixel antialiasing). | |
773 window_label_button_view_->SetBackgroundColorHint(SK_ColorTRANSPARENT); | |
774 window_label_->SetContentsView(window_label_button_view_); | |
775 } | 672 } |
| 673 window_label_->GetLayer()->SetMasksToBounds(false); |
776 } | 674 } |
777 | 675 |
778 void WindowSelectorItem::UpdateHeaderLayout( | 676 void WindowSelectorItem::UpdateHeaderLayout( |
779 HeaderFadeInMode mode, | 677 HeaderFadeInMode mode, |
780 OverviewAnimationType animation_type) { | 678 OverviewAnimationType animation_type) { |
781 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( | 679 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( |
782 transform_window_.GetTransformedBounds(hide_header())); | 680 transform_window_.GetTransformedBounds()); |
783 | 681 |
784 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 682 gfx::Rect label_rect(close_button_->GetPreferredSize()); |
785 gfx::Rect label_rect(close_button_->GetPreferredSize()); | 683 label_rect.set_width(transformed_window_bounds.width()); |
786 label_rect.set_width(transformed_window_bounds.width()); | 684 // For tabbed windows the initial bounds of the caption are set such that it |
787 // For tabbed windows the initial bounds of the caption are set such that it | 685 // appears to be "growing" up from the window content area. |
788 // appears to be "growing" up from the window content area. | 686 label_rect.set_y( |
789 label_rect.set_y( | 687 (mode != HeaderFadeInMode::ENTER || transform_window_.GetTopInset()) |
790 (mode != HeaderFadeInMode::ENTER || transform_window_.GetTopInset()) | 688 ? -label_rect.height() |
791 ? -label_rect.height() | 689 : 0); |
792 : 0); | 690 if (background_view_) { |
793 if (background_view_) { | 691 if (mode == HeaderFadeInMode::ENTER) { |
794 if (mode == HeaderFadeInMode::ENTER) { | 692 background_view_->ObserveLayerAnimations(window_label_->GetLayer()); |
795 background_view_->ObserveLayerAnimations(window_label_->GetLayer()); | 693 background_view_->set_color(kLabelBackgroundColor); |
796 background_view_->set_color(kLabelBackgroundColor); | 694 // The color will be animated only once the label widget is faded in. |
797 // The color will be animated only once the label widget is faded in. | 695 } else if (mode == HeaderFadeInMode::EXIT) { |
798 } else if (mode == HeaderFadeInMode::EXIT) { | 696 // Normally the observer is disconnected when the fade-in animations |
799 // Normally the observer is disconnected when the fade-in animations | 697 // complete but some tests invoke animations with |NON_ZERO_DURATION| |
800 // complete but some tests invoke animations with |NON_ZERO_DURATION| | 698 // without waiting for completion so do it here. |
801 // without waiting for completion so do it here. | 699 background_view_->StopObservingLayerAnimations(); |
802 background_view_->StopObservingLayerAnimations(); | 700 // Make the header visible above the window. It will be faded out when |
803 // Make the header visible above the window. It will be faded out when | 701 // the Shutdown() is called. |
804 // the Shutdown() is called. | 702 background_view_->AnimateColor(gfx::Tween::EASE_OUT, |
805 background_view_->AnimateColor(gfx::Tween::EASE_OUT, | 703 kExitFadeInMilliseconds); |
806 kExitFadeInMilliseconds); | 704 background_view_->set_color(kLabelExitColor); |
807 background_view_->set_color(kLabelExitColor); | |
808 } | |
809 } | 705 } |
810 if (!window_label_button_view_->visible()) { | 706 } |
811 window_label_button_view_->SetVisible(true); | 707 if (!window_label_button_view_->visible()) { |
812 SetupFadeInAfterLayout(window_label_.get()); | 708 window_label_button_view_->SetVisible(true); |
813 } | 709 SetupFadeInAfterLayout(window_label_.get()); |
814 WmWindow* window_label_window = | 710 } |
815 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | 711 WmWindow* window_label_window = |
816 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 712 WmLookup::Get()->GetWindowForWidget(window_label_.get()); |
817 ScopedOverviewAnimationSettingsFactory::Get() | 713 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
818 ->CreateOverviewAnimationSettings(animation_type, | 714 ScopedOverviewAnimationSettingsFactory::Get() |
819 window_label_window); | 715 ->CreateOverviewAnimationSettings(animation_type, |
820 // |window_label_window| covers both the transformed window and the header | 716 window_label_window); |
821 // as well as the gap between the windows to prevent events from reaching | 717 // |window_label_window| covers both the transformed window and the header |
822 // the window including its sizing borders. | 718 // as well as the gap between the windows to prevent events from reaching |
823 if (mode != HeaderFadeInMode::ENTER) { | 719 // the window including its sizing borders. |
824 label_rect.set_height(close_button_->GetPreferredSize().height() + | 720 if (mode != HeaderFadeInMode::ENTER) { |
825 transformed_window_bounds.height()); | 721 label_rect.set_height(close_button_->GetPreferredSize().height() + |
826 } | 722 transformed_window_bounds.height()); |
827 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); | 723 } |
828 window_label_window->SetBounds(label_rect); | 724 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); |
829 gfx::Transform label_transform; | 725 window_label_window->SetBounds(label_rect); |
830 label_transform.Translate(transformed_window_bounds.x(), | 726 gfx::Transform label_transform; |
831 transformed_window_bounds.y()); | 727 label_transform.Translate(transformed_window_bounds.x(), |
832 window_label_window->SetTransform(label_transform); | 728 transformed_window_bounds.y()); |
| 729 window_label_window->SetTransform(label_transform); |
833 | 730 |
834 gfx::Rect shadow_bounds(label_rect.size()); | 731 gfx::Rect shadow_bounds(label_rect.size()); |
835 shadow_bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); | 732 shadow_bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); |
836 if (shadow_) | 733 if (shadow_) |
837 shadow_->SetContentBounds(shadow_bounds); | 734 shadow_->SetContentBounds(shadow_bounds); |
838 } else { | |
839 if (!close_button_->visible()) { | |
840 close_button_->SetVisible(true); | |
841 SetupFadeInAfterLayout(close_button_widget_.get()); | |
842 } | |
843 WmWindow* close_button_widget_window = | |
844 WmLookup::Get()->GetWindowForWidget(close_button_widget_.get()); | |
845 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | |
846 ScopedOverviewAnimationSettingsFactory::Get() | |
847 ->CreateOverviewAnimationSettings(animation_type, | |
848 close_button_widget_window); | |
849 | |
850 gfx::Transform close_button_transform; | |
851 close_button_transform.Translate(transformed_window_bounds.right(), | |
852 transformed_window_bounds.y()); | |
853 close_button_widget_window->SetTransform(close_button_transform); | |
854 } | |
855 } | 735 } |
856 | 736 |
857 void WindowSelectorItem::AnimateOpacity(float opacity, | 737 void WindowSelectorItem::AnimateOpacity(float opacity, |
858 OverviewAnimationType animation_type) { | 738 OverviewAnimationType animation_type) { |
859 DCHECK_GE(opacity, 0.f); | 739 DCHECK_GE(opacity, 0.f); |
860 DCHECK_LE(opacity, 1.f); | 740 DCHECK_LE(opacity, 1.f); |
861 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 741 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
862 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 742 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
863 transform_window_.SetOpacity(opacity); | 743 transform_window_.SetOpacity(opacity); |
864 | 744 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 window_selector_->delegate()->AddDelayedAnimationObserver( | 781 window_selector_->delegate()->AddDelayedAnimationObserver( |
902 std::move(observer)); | 782 std::move(observer)); |
903 widget_ptr->SetOpacity(0.f); | 783 widget_ptr->SetOpacity(0.f); |
904 } | 784 } |
905 | 785 |
906 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { | 786 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { |
907 return background_view_ ? background_view_->animation() : nullptr; | 787 return background_view_ ? background_view_->animation() : nullptr; |
908 } | 788 } |
909 | 789 |
910 } // namespace ash | 790 } // namespace ash |
OLD | NEW |