Chromium Code Reviews| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 | 274 |
| 275 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); | 275 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); |
| 276 }; | 276 }; |
| 277 | 277 |
| 278 WindowSelectorItem::WindowSelectorItem(WmWindow* window, | 278 WindowSelectorItem::WindowSelectorItem(WmWindow* window, |
| 279 WindowSelector* window_selector) | 279 WindowSelector* window_selector) |
| 280 : dimmed_(false), | 280 : dimmed_(false), |
| 281 root_window_(window->GetRootWindow()), | 281 root_window_(window->GetRootWindow()), |
| 282 transform_window_(window), | 282 transform_window_(window), |
| 283 in_bounds_update_(false), | 283 in_bounds_update_(false), |
| 284 hide_header_(false), | |
|
tdanderson
2016/07/18 16:26:58
IIUC at any point in time, either all of the Windo
varkha
2016/07/19 00:29:07
Done (made static and controlled by flags).
| |
| 284 caption_container_view_(nullptr), | 285 caption_container_view_(nullptr), |
| 285 window_label_button_view_(nullptr), | 286 window_label_button_view_(nullptr), |
| 286 close_button_(new OverviewCloseButton(this)), | 287 close_button_(new OverviewCloseButton(this)), |
| 287 window_selector_(window_selector) { | 288 window_selector_(window_selector) { |
| 288 CreateWindowLabel(window->GetTitle()); | 289 CreateWindowLabel(window->GetTitle()); |
| 289 if (!ash::MaterialDesignController::IsOverviewMaterial()) { | 290 if (!ash::MaterialDesignController::IsOverviewMaterial()) { |
| 290 views::Widget::InitParams params; | 291 views::Widget::InitParams params; |
| 291 params.type = views::Widget::InitParams::TYPE_POPUP; | 292 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 292 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 293 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 293 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 294 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 | 448 |
| 448 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { | 449 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { |
| 449 // TODO(flackr): Maybe add the new title to a vector of titles so that we can | 450 // 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. | 451 // filter any of the titles the window had while in the overview session. |
| 451 window_label_button_view_->SetText(window->GetTitle()); | 452 window_label_button_view_->SetText(window->GetTitle()); |
| 452 UpdateCloseButtonAccessibilityName(); | 453 UpdateCloseButtonAccessibilityName(); |
| 453 } | 454 } |
| 454 | 455 |
| 455 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { | 456 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { |
| 456 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMarginMD); | 457 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMarginMD); |
| 458 const int header_inset = | |
| 459 hide_header_ | |
| 460 ? GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET) | |
| 461 : 0; | |
| 457 return ScopedTransformOverviewWindow::GetItemScale( | 462 return ScopedTransformOverviewWindow::GetItemScale( |
| 458 GetWindow()->GetTargetBounds().size(), inset_size, | 463 GetWindow()->GetTargetBounds().size(), inset_size, header_inset, |
| 459 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET), | |
| 460 close_button_->GetPreferredSize().height()); | 464 close_button_->GetPreferredSize().height()); |
| 461 } | 465 } |
| 462 | 466 |
| 463 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, | 467 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, |
| 464 OverviewAnimationType animation_type) { | 468 OverviewAnimationType animation_type) { |
| 465 DCHECK(root_window_ == GetWindow()->GetRootWindow()); | 469 DCHECK(root_window_ == GetWindow()->GetRootWindow()); |
| 466 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); | 470 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); |
| 467 | 471 |
| 468 // Avoid division by zero by ensuring screen bounds is not empty. | 472 // Avoid division by zero by ensuring screen bounds is not empty. |
| 469 gfx::Size screen_size(screen_rect.size()); | 473 gfx::Size screen_size(screen_rect.size()); |
| 470 screen_size.SetToMax(gfx::Size(1, 1)); | 474 screen_size.SetToMax(gfx::Size(1, 1)); |
| 471 screen_rect.set_size(screen_size); | 475 screen_rect.set_size(screen_size); |
| 472 | 476 |
| 473 int top_view_inset = 0; | 477 int top_view_inset = 0; |
| 474 int title_height = 0; | 478 int title_height = 0; |
| 475 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 479 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 476 top_view_inset = | 480 if (hide_header_) { |
| 477 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); | 481 top_view_inset = |
| 482 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); | |
| 483 } | |
| 478 title_height = close_button_->GetPreferredSize().height(); | 484 title_height = close_button_->GetPreferredSize().height(); |
| 479 } | 485 } |
| 480 gfx::Rect selector_item_bounds = | 486 gfx::Rect selector_item_bounds = |
| 481 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( | 487 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( |
| 482 screen_rect, target_bounds, top_view_inset, title_height); | 488 screen_rect, target_bounds, top_view_inset, title_height); |
| 483 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( | 489 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( |
| 484 screen_rect, selector_item_bounds); | 490 screen_rect, selector_item_bounds); |
| 485 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 491 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
| 486 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 492 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
| 487 // Rounded corners are achieved by using a mask layer on the original window | 493 // 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 | 494 // before the transform. Dividing by scale factor obtains the corner radius |
| 489 // which when scaled will yield |kLabelBackgroundRadius|. | 495 // which when scaled will yield |kLabelBackgroundRadius|. |
| 490 transform_window_.SetTransform( | 496 transform_window_.SetTransform( |
| 491 root_window_, transform, | 497 root_window_, transform, hide_header_, |
| 492 (kLabelBackgroundRadius / GetItemScale(target_bounds.size()))); | 498 (kLabelBackgroundRadius / GetItemScale(target_bounds.size()))); |
| 493 transform_window_.set_overview_transform(transform); | 499 transform_window_.set_overview_transform(transform); |
| 494 } | 500 } |
| 495 | 501 |
| 496 void WindowSelectorItem::SetOpacity(float opacity) { | 502 void WindowSelectorItem::SetOpacity(float opacity) { |
| 497 window_label_->SetOpacity(opacity); | 503 window_label_->SetOpacity(opacity); |
| 498 if (!ash::MaterialDesignController::IsOverviewMaterial()) | 504 if (!ash::MaterialDesignController::IsOverviewMaterial()) |
| 499 close_button_widget_->SetOpacity(opacity); | 505 close_button_widget_->SetOpacity(opacity); |
| 500 | 506 |
| 501 transform_window_.SetOpacity(opacity); | 507 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); | 579 window_label_selector_->set_focus_on_creation(false); |
| 574 window_label_selector_->SetContentsView(background_view); | 580 window_label_selector_->SetContentsView(background_view); |
| 575 window_label_selector_->Show(); | 581 window_label_selector_->Show(); |
| 576 } else { | 582 } else { |
| 577 window_label_->SetContentsView(window_label_button_view_); | 583 window_label_->SetContentsView(window_label_button_view_); |
| 578 } | 584 } |
| 579 } | 585 } |
| 580 | 586 |
| 581 void WindowSelectorItem::UpdateHeaderLayout( | 587 void WindowSelectorItem::UpdateHeaderLayout( |
| 582 OverviewAnimationType animation_type) { | 588 OverviewAnimationType animation_type) { |
| 583 gfx::Rect transformed_window_bounds = | 589 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( |
| 584 root_window_->ConvertRectFromScreen(GetTransformedBounds(GetWindow())); | 590 GetTransformedBounds(GetWindow(), hide_header_)); |
| 585 | 591 |
| 586 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 592 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 587 gfx::Rect label_rect(close_button_->GetPreferredSize()); | 593 gfx::Rect label_rect(close_button_->GetPreferredSize()); |
| 588 label_rect.set_y(-label_rect.height()); | 594 label_rect.set_y(-label_rect.height()); |
| 589 label_rect.set_width(transformed_window_bounds.width()); | 595 label_rect.set_width(transformed_window_bounds.width()); |
| 590 | 596 |
| 591 if (!window_label_button_view_->visible()) { | 597 if (!window_label_button_view_->visible()) { |
| 592 window_label_button_view_->SetVisible(true); | 598 window_label_button_view_->SetVisible(true); |
| 593 SetupFadeInAfterLayout(window_label_.get()); | 599 SetupFadeInAfterLayout(window_label_.get()); |
| 594 SetupFadeInAfterLayout(window_label_selector_.get()); | 600 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); | 673 window_label_selector_window->SetOpacity(opacity); |
| 668 } | 674 } |
| 669 | 675 |
| 670 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { | 676 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { |
| 671 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( | 677 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( |
| 672 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, | 678 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, |
| 673 GetWindow()->GetTitle())); | 679 GetWindow()->GetTitle())); |
| 674 } | 680 } |
| 675 | 681 |
| 676 } // namespace ash | 682 } // namespace ash |
| OLD | NEW |