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

Side by Side Diff: ash/common/wm/overview/window_selector_item.cc

Issue 2184543005: [ash-md] Improves smoothness with many windows in overview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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
« no previous file with comments | « ash/common/wm/overview/window_selector_item.h ('k') | ash/frame/custom_frame_view_ash.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 // Duration of background opacity transition for the selected label. 97 // Duration of background opacity transition for the selected label.
98 static const int kSelectorFadeInMilliseconds = 350; 98 static const int kSelectorFadeInMilliseconds = 350;
99 99
100 // Before closing a window animate both the window and the caption to shrink by 100 // Before closing a window animate both the window and the caption to shrink by
101 // this fraction of size. 101 // this fraction of size.
102 static const float kPreCloseScale = 0.02f; 102 static const float kPreCloseScale = 0.02f;
103 103
104 // Calculates the |window| bounds after being transformed to the selector's 104 // Calculates the |window| bounds after being transformed to the selector's
105 // space. The returned Rect is in virtual screen coordinates. 105 // space. The returned Rect is in virtual screen coordinates.
106 gfx::Rect GetTransformedBounds(WmWindow* window) { 106 gfx::Rect GetTransformedBounds(WmWindow* window, bool hide_header) {
107 gfx::RectF bounds( 107 gfx::RectF bounds(
108 window->GetRootWindow()->ConvertRectToScreen(window->GetTargetBounds())); 108 window->GetRootWindow()->ConvertRectToScreen(window->GetTargetBounds()));
109 gfx::Transform new_transform = TransformAboutPivot( 109 gfx::Transform new_transform = TransformAboutPivot(
110 gfx::Point(bounds.x(), bounds.y()), window->GetTargetTransform()); 110 gfx::Point(bounds.x(), bounds.y()), window->GetTargetTransform());
111 new_transform.TransformRect(&bounds); 111 new_transform.TransformRect(&bounds);
112 112
113 // With Material Design the preview title is shown above the preview window. 113 // With Material Design the preview title is shown above the preview window.
114 // Hide the window header for apps or browser windows with no tabs (web apps) 114 // Hide the window header for apps or browser windows with no tabs (web apps)
115 // to avoid showing both the window header and the preview title. 115 // to avoid showing both the window header and the preview title.
116 if (ash::MaterialDesignController::IsOverviewMaterial()) { 116 if (ash::MaterialDesignController::IsOverviewMaterial() && hide_header) {
117 gfx::RectF header_bounds(bounds); 117 gfx::RectF header_bounds(bounds);
118 header_bounds.set_height( 118 header_bounds.set_height(
119 window->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET)); 119 window->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET));
120 new_transform.TransformRect(&header_bounds); 120 new_transform.TransformRect(&header_bounds);
121 bounds.Inset(0, gfx::ToCeiledInt(header_bounds.height()), 0, 0); 121 bounds.Inset(0, gfx::ToCeiledInt(header_bounds.height()), 0, 0);
122 } 122 }
123 return ToEnclosingRect(bounds); 123 return ToEnclosingRect(bounds);
124 } 124 }
125 125
126 // Convenience method to fade in a Window with predefined animation settings. 126 // Convenience method to fade in a Window with predefined animation settings.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 205
206 private: 206 private:
207 int corner_radius_; 207 int corner_radius_;
208 SkColor background_; 208 SkColor background_;
209 209
210 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); 210 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView);
211 }; 211 };
212 212
213 } // namespace 213 } // namespace
214 214
215 bool WindowSelectorItem::use_mask_ = false;
216 bool WindowSelectorItem::use_shape_ = false;
217
215 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( 218 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton(
216 views::ButtonListener* listener, 219 views::ButtonListener* listener,
217 const base::string16& text) 220 const base::string16& text)
218 : LabelButton(listener, text) {} 221 : LabelButton(listener, text) {}
219 222
220 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} 223 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {}
221 224
222 void WindowSelectorItem::OverviewLabelButton::SetBackgroundColorHint( 225 void WindowSelectorItem::OverviewLabelButton::SetBackgroundColorHint(
223 SkColor color) { 226 SkColor color) {
224 // Tell the label what color it will be drawn onto. It will use whether the 227 // Tell the label what color it will be drawn onto. It will use whether the
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 435
433 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { 436 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) {
434 // TODO(flackr): Maybe add the new title to a vector of titles so that we can 437 // TODO(flackr): Maybe add the new title to a vector of titles so that we can
435 // filter any of the titles the window had while in the overview session. 438 // filter any of the titles the window had while in the overview session.
436 window_label_button_view_->SetText(window->GetTitle()); 439 window_label_button_view_->SetText(window->GetTitle());
437 UpdateCloseButtonAccessibilityName(); 440 UpdateCloseButtonAccessibilityName();
438 } 441 }
439 442
440 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { 443 float WindowSelectorItem::GetItemScale(const gfx::Size& size) {
441 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMarginMD); 444 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMarginMD);
445 const int header_inset =
446 hide_header()
447 ? GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET)
448 : 0;
442 return ScopedTransformOverviewWindow::GetItemScale( 449 return ScopedTransformOverviewWindow::GetItemScale(
443 GetWindow()->GetTargetBounds().size(), inset_size, 450 GetWindow()->GetTargetBounds().size(), inset_size, header_inset,
444 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET),
445 close_button_->GetPreferredSize().height()); 451 close_button_->GetPreferredSize().height());
446 } 452 }
447 453
448 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, 454 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds,
449 OverviewAnimationType animation_type) { 455 OverviewAnimationType animation_type) {
450 DCHECK(root_window_ == GetWindow()->GetRootWindow()); 456 DCHECK(root_window_ == GetWindow()->GetRootWindow());
451 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); 457 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen();
452 458
453 // Avoid division by zero by ensuring screen bounds is not empty. 459 // Avoid division by zero by ensuring screen bounds is not empty.
454 gfx::Size screen_size(screen_rect.size()); 460 gfx::Size screen_size(screen_rect.size());
455 screen_size.SetToMax(gfx::Size(1, 1)); 461 screen_size.SetToMax(gfx::Size(1, 1));
456 screen_rect.set_size(screen_size); 462 screen_rect.set_size(screen_size);
457 463
458 int top_view_inset = 0; 464 int top_view_inset = 0;
459 int title_height = 0; 465 int title_height = 0;
460 if (ash::MaterialDesignController::IsOverviewMaterial()) { 466 if (ash::MaterialDesignController::IsOverviewMaterial()) {
461 top_view_inset = 467 if (hide_header()) {
462 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET); 468 top_view_inset =
469 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET);
470 }
463 title_height = close_button_->GetPreferredSize().height(); 471 title_height = close_button_->GetPreferredSize().height();
464 } 472 }
465 gfx::Rect selector_item_bounds = 473 gfx::Rect selector_item_bounds =
466 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( 474 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio(
467 screen_rect, target_bounds, top_view_inset, title_height); 475 screen_rect, target_bounds, top_view_inset, title_height);
468 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( 476 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect(
469 screen_rect, selector_item_bounds); 477 screen_rect, selector_item_bounds);
470 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; 478 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
471 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); 479 transform_window_.BeginScopedAnimation(animation_type, &animation_settings);
472 // Rounded corners are achieved by using a mask layer on the original window 480 // Rounded corners are achieved by using a mask layer on the original window
473 // before the transform. Dividing by scale factor obtains the corner radius 481 // before the transform. Dividing by scale factor obtains the corner radius
474 // which when scaled will yield |kLabelBackgroundRadius|. 482 // which when scaled will yield |kLabelBackgroundRadius|.
475 transform_window_.SetTransform( 483 transform_window_.SetTransform(
476 root_window_, transform, 484 root_window_, transform, use_mask_, use_shape_,
477 (kLabelBackgroundRadius / GetItemScale(target_bounds.size()))); 485 (kLabelBackgroundRadius / GetItemScale(target_bounds.size())));
478 transform_window_.set_overview_transform(transform); 486 transform_window_.set_overview_transform(transform);
479 } 487 }
480 488
481 void WindowSelectorItem::SetOpacity(float opacity) { 489 void WindowSelectorItem::SetOpacity(float opacity) {
482 window_label_->SetOpacity(opacity); 490 window_label_->SetOpacity(opacity);
483 if (!ash::MaterialDesignController::IsOverviewMaterial()) 491 if (!ash::MaterialDesignController::IsOverviewMaterial())
484 close_button_widget_->SetOpacity(opacity); 492 close_button_widget_->SetOpacity(opacity);
485 493
486 transform_window_.SetOpacity(opacity); 494 transform_window_.SetOpacity(opacity);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } else { 566 } else {
559 // Indicate that the label will be drawn onto a transparent background 567 // Indicate that the label will be drawn onto a transparent background
560 // (disables subpixel antialiasing). 568 // (disables subpixel antialiasing).
561 window_label_button_view_->SetBackgroundColorHint(SK_ColorTRANSPARENT); 569 window_label_button_view_->SetBackgroundColorHint(SK_ColorTRANSPARENT);
562 window_label_->SetContentsView(window_label_button_view_); 570 window_label_->SetContentsView(window_label_button_view_);
563 } 571 }
564 } 572 }
565 573
566 void WindowSelectorItem::UpdateHeaderLayout( 574 void WindowSelectorItem::UpdateHeaderLayout(
567 OverviewAnimationType animation_type) { 575 OverviewAnimationType animation_type) {
568 gfx::Rect transformed_window_bounds = 576 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen(
569 root_window_->ConvertRectFromScreen(GetTransformedBounds(GetWindow())); 577 GetTransformedBounds(GetWindow(), hide_header()));
570 578
571 if (ash::MaterialDesignController::IsOverviewMaterial()) { 579 if (ash::MaterialDesignController::IsOverviewMaterial()) {
572 gfx::Rect label_rect(close_button_->GetPreferredSize()); 580 gfx::Rect label_rect(close_button_->GetPreferredSize());
573 label_rect.set_y(-label_rect.height()); 581 label_rect.set_y(-label_rect.height());
574 label_rect.set_width(transformed_window_bounds.width()); 582 label_rect.set_width(transformed_window_bounds.width());
575 583
576 if (!window_label_button_view_->visible()) { 584 if (!window_label_button_view_->visible()) {
577 window_label_button_view_->SetVisible(true); 585 window_label_button_view_->SetVisible(true);
578 SetupFadeInAfterLayout(window_label_.get()); 586 SetupFadeInAfterLayout(window_label_.get());
579 SetupFadeInAfterLayout(window_label_selector_.get()); 587 SetupFadeInAfterLayout(window_label_selector_.get());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 window_label_selector_window->SetOpacity(opacity); 656 window_label_selector_window->SetOpacity(opacity);
649 } 657 }
650 658
651 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { 659 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() {
652 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( 660 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16(
653 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, 661 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME,
654 GetWindow()->GetTitle())); 662 GetWindow()->GetTitle()));
655 } 663 }
656 664
657 } // namespace ash 665 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/overview/window_selector_item.h ('k') | ash/frame/custom_frame_view_ash.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698