| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 107 // Calculates the |window| bounds after being transformed to the selector's |
| 108 // space. The returned Rect is in virtual screen coordinates. | 108 // space. The returned Rect is in virtual screen coordinates. |
| 109 gfx::Rect GetTransformedBounds(WmWindow* window) { | 109 gfx::Rect GetTransformedBounds(WmWindow* window, bool hide_header) { |
| 110 gfx::RectF bounds( | 110 gfx::RectF bounds( |
| 111 window->GetRootWindow()->ConvertRectToScreen(window->GetTargetBounds())); | 111 window->GetRootWindow()->ConvertRectToScreen(window->GetTargetBounds())); |
| 112 gfx::Transform new_transform = TransformAboutPivot( | 112 gfx::Transform new_transform = TransformAboutPivot( |
| 113 gfx::Point(bounds.x(), bounds.y()), window->GetTargetTransform()); | 113 gfx::Point(bounds.x(), bounds.y()), window->GetTargetTransform()); |
| 114 new_transform.TransformRect(&bounds); | 114 new_transform.TransformRect(&bounds); |
| 115 | 115 |
| 116 // With Material Design the preview title is shown above the preview window. | 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) | 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. | 118 // to avoid showing both the window header and the preview title. |
| 119 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 119 if (ash::MaterialDesignController::IsOverviewMaterial() && hide_header) { |
| 120 gfx::RectF header_bounds(bounds); | 120 gfx::RectF header_bounds(bounds); |
| 121 header_bounds.set_height( | 121 header_bounds.set_height( |
| 122 window->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET)); | 122 window->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET)); |
| 123 new_transform.TransformRect(&header_bounds); | 123 new_transform.TransformRect(&header_bounds); |
| 124 bounds.Inset(0, gfx::ToCeiledInt(header_bounds.height()), 0, 0); | 124 bounds.Inset(0, gfx::ToCeiledInt(header_bounds.height()), 0, 0); |
| 125 } | 125 } |
| 126 return ToEnclosingRect(bounds); | 126 return ToEnclosingRect(bounds); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Convenience method to fade in a Window with predefined animation settings. | 129 // Convenience method to fade in a Window with predefined animation settings. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 208 |
| 209 private: | 209 private: |
| 210 int corner_radius_; | 210 int corner_radius_; |
| 211 SkColor background_; | 211 SkColor background_; |
| 212 | 212 |
| 213 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); | 213 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 } // namespace | 216 } // namespace |
| 217 | 217 |
| 218 bool WindowSelectorItem::use_mask_ = false; |
| 219 bool WindowSelectorItem::use_shape_ = false; |
| 220 |
| 218 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( | 221 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( |
| 219 views::ButtonListener* listener, | 222 views::ButtonListener* listener, |
| 220 const base::string16& text) | 223 const base::string16& text) |
| 221 : LabelButton(listener, text) {} | 224 : LabelButton(listener, text) {} |
| 222 | 225 |
| 223 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} | 226 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} |
| 224 | 227 |
| 225 void WindowSelectorItem::OverviewLabelButton::SetBackgroundColor( | 228 void WindowSelectorItem::OverviewLabelButton::SetBackgroundColor( |
| 226 SkColor color) { | 229 SkColor color) { |
| 227 label()->SetBackgroundColor(color); | 230 label()->SetBackgroundColor(color); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 450 |
| 448 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { | 451 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { |
| 449 // TODO(flackr): Maybe add the new title to a vector of titles so that we can | 452 // TODO(flackr): Maybe add the new title to a vector of titles so that we can |
| 450 // filter any of the titles the window had while in the overview session. | 453 // filter any of the titles the window had while in the overview session. |
| 451 window_label_button_view_->SetText(window->GetTitle()); | 454 window_label_button_view_->SetText(window->GetTitle()); |
| 452 UpdateCloseButtonAccessibilityName(); | 455 UpdateCloseButtonAccessibilityName(); |
| 453 } | 456 } |
| 454 | 457 |
| 455 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { | 458 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { |
| 456 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMarginMD); | 459 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMarginMD); |
| 460 const int header_inset = |
| 461 hide_header() |
| 462 ? GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET) |
| 463 : 0; |
| 457 return ScopedTransformOverviewWindow::GetItemScale( | 464 return ScopedTransformOverviewWindow::GetItemScale( |
| 458 GetWindow()->GetTargetBounds().size(), inset_size, | 465 GetWindow()->GetTargetBounds().size(), inset_size, header_inset, |
| 459 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET), | |
| 460 close_button_->GetPreferredSize().height()); | 466 close_button_->GetPreferredSize().height()); |
| 461 } | 467 } |
| 462 | 468 |
| 463 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, | 469 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, |
| 464 OverviewAnimationType animation_type) { | 470 OverviewAnimationType animation_type) { |
| 465 DCHECK(root_window_ == GetWindow()->GetRootWindow()); | 471 DCHECK(root_window_ == GetWindow()->GetRootWindow()); |
| 466 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); | 472 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); |
| 467 | 473 |
| 468 // Avoid division by zero by ensuring screen bounds is not empty. | 474 // Avoid division by zero by ensuring screen bounds is not empty. |
| 469 gfx::Size screen_size(screen_rect.size()); | 475 gfx::Size screen_size(screen_rect.size()); |
| 470 screen_size.SetToMax(gfx::Size(1, 1)); | 476 screen_size.SetToMax(gfx::Size(1, 1)); |
| 471 screen_rect.set_size(screen_size); | 477 screen_rect.set_size(screen_size); |
| 472 | 478 |
| 473 int top_view_inset = 0; | 479 int top_view_inset = 0; |
| 474 int title_height = 0; | 480 int title_height = 0; |
| 475 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 481 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 476 top_view_inset = | 482 if (hide_header()) { |
| 477 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); | 483 top_view_inset = |
| 484 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); |
| 485 } |
| 478 title_height = close_button_->GetPreferredSize().height(); | 486 title_height = close_button_->GetPreferredSize().height(); |
| 479 } | 487 } |
| 480 gfx::Rect selector_item_bounds = | 488 gfx::Rect selector_item_bounds = |
| 481 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( | 489 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( |
| 482 screen_rect, target_bounds, top_view_inset, title_height); | 490 screen_rect, target_bounds, top_view_inset, title_height); |
| 483 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( | 491 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( |
| 484 screen_rect, selector_item_bounds); | 492 screen_rect, selector_item_bounds); |
| 485 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 493 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
| 486 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 494 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
| 487 // Rounded corners are achieved by using a mask layer on the original window | 495 // Rounded corners are achieved by using a mask layer on the original window |
| 488 // before the transform. Dividing by scale factor obtains the corner radius | 496 // before the transform. Dividing by scale factor obtains the corner radius |
| 489 // which when scaled will yield |kLabelBackgroundRadius|. | 497 // which when scaled will yield |kLabelBackgroundRadius|. |
| 490 transform_window_.SetTransform( | 498 transform_window_.SetTransform( |
| 491 root_window_, transform, | 499 root_window_, transform, use_mask_, use_shape_, |
| 492 (kLabelBackgroundRadius / GetItemScale(target_bounds.size()))); | 500 (kLabelBackgroundRadius / GetItemScale(target_bounds.size()))); |
| 493 transform_window_.set_overview_transform(transform); | 501 transform_window_.set_overview_transform(transform); |
| 494 } | 502 } |
| 495 | 503 |
| 496 void WindowSelectorItem::SetOpacity(float opacity) { | 504 void WindowSelectorItem::SetOpacity(float opacity) { |
| 497 window_label_->SetOpacity(opacity); | 505 window_label_->SetOpacity(opacity); |
| 498 if (!ash::MaterialDesignController::IsOverviewMaterial()) | 506 if (!ash::MaterialDesignController::IsOverviewMaterial()) |
| 499 close_button_widget_->SetOpacity(opacity); | 507 close_button_widget_->SetOpacity(opacity); |
| 500 | 508 |
| 501 transform_window_.SetOpacity(opacity); | 509 transform_window_.SetOpacity(opacity); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 window_label_selector_->set_focus_on_creation(false); | 581 window_label_selector_->set_focus_on_creation(false); |
| 574 window_label_selector_->SetContentsView(background_view); | 582 window_label_selector_->SetContentsView(background_view); |
| 575 window_label_selector_->Show(); | 583 window_label_selector_->Show(); |
| 576 } else { | 584 } else { |
| 577 window_label_->SetContentsView(window_label_button_view_); | 585 window_label_->SetContentsView(window_label_button_view_); |
| 578 } | 586 } |
| 579 } | 587 } |
| 580 | 588 |
| 581 void WindowSelectorItem::UpdateHeaderLayout( | 589 void WindowSelectorItem::UpdateHeaderLayout( |
| 582 OverviewAnimationType animation_type) { | 590 OverviewAnimationType animation_type) { |
| 583 gfx::Rect transformed_window_bounds = | 591 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( |
| 584 root_window_->ConvertRectFromScreen(GetTransformedBounds(GetWindow())); | 592 GetTransformedBounds(GetWindow(), hide_header())); |
| 585 | 593 |
| 586 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 594 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 587 gfx::Rect label_rect(close_button_->GetPreferredSize()); | 595 gfx::Rect label_rect(close_button_->GetPreferredSize()); |
| 588 label_rect.set_y(-label_rect.height()); | 596 label_rect.set_y(-label_rect.height()); |
| 589 label_rect.set_width(transformed_window_bounds.width()); | 597 label_rect.set_width(transformed_window_bounds.width()); |
| 590 | 598 |
| 591 if (!window_label_button_view_->visible()) { | 599 if (!window_label_button_view_->visible()) { |
| 592 window_label_button_view_->SetVisible(true); | 600 window_label_button_view_->SetVisible(true); |
| 593 SetupFadeInAfterLayout(window_label_.get()); | 601 SetupFadeInAfterLayout(window_label_.get()); |
| 594 SetupFadeInAfterLayout(window_label_selector_.get()); | 602 SetupFadeInAfterLayout(window_label_selector_.get()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 window_label_selector_window->SetOpacity(opacity); | 675 window_label_selector_window->SetOpacity(opacity); |
| 668 } | 676 } |
| 669 | 677 |
| 670 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { | 678 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { |
| 671 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( | 679 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( |
| 672 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, | 680 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, |
| 673 GetWindow()->GetTitle())); | 681 GetWindow()->GetTitle())); |
| 674 } | 682 } |
| 675 | 683 |
| 676 } // namespace ash | 684 } // namespace ash |
| OLD | NEW |