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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // Opacity for fading out during closing a window. | 97 // Opacity for fading out during closing a window. |
98 static const float kClosingItemOpacity = 0.8f; | 98 static const float kClosingItemOpacity = 0.8f; |
99 | 99 |
100 // Duration of background opacity transition for the selected label. | 100 // Duration of background opacity transition for the selected label. |
101 static const int kSelectorFadeInMilliseconds = 350; | 101 static const int kSelectorFadeInMilliseconds = 350; |
102 | 102 |
103 // Before closing a window animate both the window and the caption to shrink by | 103 // Before closing a window animate both the window and the caption to shrink by |
104 // this fraction of size. | 104 // this fraction of size. |
105 static const float kPreCloseScale = 0.02f; | 105 static const float kPreCloseScale = 0.02f; |
106 | 106 |
107 // Calculates the |window| bounds after being transformed to the selector's | |
108 // space. The returned Rect is in virtual screen coordinates. | |
109 gfx::Rect GetTransformedBounds(WmWindow* window, bool hide_header) { | |
110 gfx::RectF bounds( | |
111 window->GetRootWindow()->ConvertRectToScreen(window->GetTargetBounds())); | |
112 gfx::Transform new_transform = TransformAboutPivot( | |
113 gfx::Point(bounds.x(), bounds.y()), window->GetTargetTransform()); | |
114 new_transform.TransformRect(&bounds); | |
115 | |
116 // With Material Design the preview title is shown above the preview window. | |
117 // Hide the window header for apps or browser windows with no tabs (web apps) | |
118 // to avoid showing both the window header and the preview title. | |
119 if (ash::MaterialDesignController::IsOverviewMaterial() && hide_header) { | |
120 gfx::RectF header_bounds(bounds); | |
121 header_bounds.set_height( | |
122 window->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET)); | |
123 new_transform.TransformRect(&header_bounds); | |
124 bounds.Inset(0, gfx::ToCeiledInt(header_bounds.height()), 0, 0); | |
125 } | |
126 return ToEnclosingRect(bounds); | |
127 } | |
128 | |
129 // Convenience method to fade in a Window with predefined animation settings. | 107 // Convenience method to fade in a Window with predefined animation settings. |
130 // Note: The fade in animation will occur after a delay where the delay is how | 108 // Note: The fade in animation will occur after a delay where the delay is how |
131 // long the lay out animations take. | 109 // long the lay out animations take. |
132 void SetupFadeInAfterLayout(views::Widget* widget) { | 110 void SetupFadeInAfterLayout(views::Widget* widget) { |
133 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); | 111 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); |
134 window->SetOpacity(0.0f); | 112 window->SetOpacity(0.0f); |
135 std::unique_ptr<ScopedOverviewAnimationSettings> | 113 std::unique_ptr<ScopedOverviewAnimationSettings> |
136 scoped_overview_animation_settings = | 114 scoped_overview_animation_settings = |
137 ScopedOverviewAnimationSettingsFactory::Get() | 115 ScopedOverviewAnimationSettingsFactory::Get() |
138 ->CreateOverviewAnimationSettings( | 116 ->CreateOverviewAnimationSettings( |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 431 |
454 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { | 432 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { |
455 // TODO(flackr): Maybe add the new title to a vector of titles so that we can | 433 // TODO(flackr): Maybe add the new title to a vector of titles so that we can |
456 // filter any of the titles the window had while in the overview session. | 434 // filter any of the titles the window had while in the overview session. |
457 window_label_button_view_->SetText(window->GetTitle()); | 435 window_label_button_view_->SetText(window->GetTitle()); |
458 UpdateCloseButtonAccessibilityName(); | 436 UpdateCloseButtonAccessibilityName(); |
459 } | 437 } |
460 | 438 |
461 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { | 439 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { |
462 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMarginMD); | 440 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMarginMD); |
463 const int header_inset = | |
464 hide_header() | |
465 ? GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET) | |
466 : 0; | |
467 return ScopedTransformOverviewWindow::GetItemScale( | 441 return ScopedTransformOverviewWindow::GetItemScale( |
468 GetWindow()->GetTargetBounds().size(), inset_size, header_inset, | 442 transform_window_.GetTargetBoundsInScreen().size(), inset_size, |
| 443 hide_header() ? transform_window_.GetTopInset() : 0, |
469 close_button_->GetPreferredSize().height()); | 444 close_button_->GetPreferredSize().height()); |
470 } | 445 } |
471 | 446 |
| 447 gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const { |
| 448 return transform_window_.GetTargetBoundsInScreen(); |
| 449 } |
| 450 |
472 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, | 451 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, |
473 OverviewAnimationType animation_type) { | 452 OverviewAnimationType animation_type) { |
474 DCHECK(root_window_ == GetWindow()->GetRootWindow()); | 453 DCHECK(root_window_ == GetWindow()->GetRootWindow()); |
475 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); | 454 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); |
476 | 455 |
477 // Avoid division by zero by ensuring screen bounds is not empty. | 456 // Avoid division by zero by ensuring screen bounds is not empty. |
478 gfx::Size screen_size(screen_rect.size()); | 457 gfx::Size screen_size(screen_rect.size()); |
479 screen_size.SetToMax(gfx::Size(1, 1)); | 458 screen_size.SetToMax(gfx::Size(1, 1)); |
480 screen_rect.set_size(screen_size); | 459 screen_rect.set_size(screen_size); |
481 | 460 |
482 int top_view_inset = 0; | 461 int top_view_inset = 0; |
483 int title_height = 0; | 462 int title_height = 0; |
484 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 463 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
485 if (hide_header()) { | 464 if (hide_header()) |
486 top_view_inset = | 465 top_view_inset = transform_window_.GetTopInset(); |
487 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); | |
488 } | |
489 title_height = close_button_->GetPreferredSize().height(); | 466 title_height = close_button_->GetPreferredSize().height(); |
490 } | 467 } |
491 gfx::Rect selector_item_bounds = | 468 gfx::Rect selector_item_bounds = |
492 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( | 469 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( |
493 screen_rect, target_bounds, top_view_inset, title_height); | 470 screen_rect, target_bounds, top_view_inset, title_height); |
494 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( | 471 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( |
495 screen_rect, selector_item_bounds); | 472 screen_rect, selector_item_bounds); |
496 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 473 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
497 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 474 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
498 // Rounded corners are achieved by using a mask layer on the original window | 475 // Rounded corners are achieved by using a mask layer on the original window |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 // Indicate that the label will be drawn onto a transparent background | 568 // Indicate that the label will be drawn onto a transparent background |
592 // (disables subpixel antialiasing). | 569 // (disables subpixel antialiasing). |
593 window_label_button_view_->SetBackgroundColorHint(SK_ColorTRANSPARENT); | 570 window_label_button_view_->SetBackgroundColorHint(SK_ColorTRANSPARENT); |
594 window_label_->SetContentsView(window_label_button_view_); | 571 window_label_->SetContentsView(window_label_button_view_); |
595 } | 572 } |
596 } | 573 } |
597 | 574 |
598 void WindowSelectorItem::UpdateHeaderLayout( | 575 void WindowSelectorItem::UpdateHeaderLayout( |
599 OverviewAnimationType animation_type) { | 576 OverviewAnimationType animation_type) { |
600 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( | 577 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( |
601 GetTransformedBounds(GetWindow(), hide_header())); | 578 transform_window_.GetTransformedBounds(hide_header())); |
602 | 579 |
603 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 580 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
604 gfx::Rect label_rect(close_button_->GetPreferredSize()); | 581 gfx::Rect label_rect(close_button_->GetPreferredSize()); |
605 label_rect.set_y(-label_rect.height()); | 582 label_rect.set_y(-label_rect.height()); |
606 label_rect.set_width(transformed_window_bounds.width()); | 583 label_rect.set_width(transformed_window_bounds.width()); |
607 | 584 |
608 if (!window_label_button_view_->visible()) { | 585 if (!window_label_button_view_->visible()) { |
609 window_label_button_view_->SetVisible(true); | 586 window_label_button_view_->SetVisible(true); |
610 SetupFadeInAfterLayout(window_label_.get()); | 587 SetupFadeInAfterLayout(window_label_.get()); |
611 SetupFadeInAfterLayout(window_label_selector_.get()); | 588 SetupFadeInAfterLayout(window_label_selector_.get()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 window_label_selector_window->SetOpacity(opacity); | 661 window_label_selector_window->SetOpacity(opacity); |
685 } | 662 } |
686 | 663 |
687 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { | 664 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { |
688 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( | 665 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( |
689 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, | 666 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, |
690 GetWindow()->GetTitle())); | 667 GetWindow()->GetTitle())); |
691 } | 668 } |
692 | 669 |
693 } // namespace ash | 670 } // namespace ash |
OLD | NEW |