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/wm/overview/window_selector_item.h" | 5 #include "ash/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/screen_util.h" | 10 #include "ash/screen_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "ui/views/controls/button/image_button.h" | 28 #include "ui/views/controls/button/image_button.h" |
| 29 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
| 30 #include "ui/views/layout/box_layout.h" | 30 #include "ui/views/layout/box_layout.h" |
| 31 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
| 32 #include "ui/wm/core/window_util.h" | 32 #include "ui/wm/core/window_util.h" |
| 33 | 33 |
| 34 namespace ash { | 34 namespace ash { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // The minimum opacity used during touch scroll gestures. | |
| 39 const float kMinimumOpacity = 0.2f; | |
|
flackr
2014/11/07 19:10:52
0.f seems like a decent close opacity. If you drag
bruthig
2015/01/02 16:49:17
I consulted with stevet@ with the 0.2f value. If w
| |
| 40 | |
| 41 // The distance at which the minimum opacity should take effect. | |
| 42 const float kMinimumOpacityDistance = 200.0f; | |
|
flackr
2014/11/07 19:10:52
Shouldn't this be the same as the close distance?
bruthig
2015/01/02 16:49:17
I agree, this should be in sync with the actual cl
| |
| 43 | |
| 44 // Calculates the window opacity from the given scroll |distance|. | |
| 45 float CalculateOpacityFromScrollDistance(int distance) { | |
| 46 float opacity = | |
| 47 1.0 - static_cast<float>(abs(distance)) / kMinimumOpacityDistance; | |
| 48 return std::min(1.0f, std::max(kMinimumOpacity, opacity)); | |
| 49 } | |
| 50 | |
| 38 gfx::Rect GetTransformedBounds(aura::Window* window) { | 51 gfx::Rect GetTransformedBounds(aura::Window* window) { |
| 39 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(window->GetRootWindow(), | 52 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(window->GetRootWindow(), |
| 40 window->layer()->bounds())); | 53 window->layer()->bounds())); |
| 41 gfx::Transform new_transform; | 54 gfx::Transform new_transform; |
| 42 new_transform.Translate(bounds.x(), bounds.y()); | 55 new_transform.Translate(bounds.x(), bounds.y()); |
| 43 new_transform.PreconcatTransform(window->layer()->GetTargetTransform()); | 56 new_transform.PreconcatTransform(window->layer()->GetTargetTransform()); |
| 44 new_transform.Translate(-bounds.x(), -bounds.y()); | 57 new_transform.Translate(-bounds.x(), -bounds.y()); |
| 45 new_transform.TransformRect(&bounds); | 58 new_transform.TransformRect(&bounds); |
| 46 return ToEnclosingRect(bounds); | 59 return ToEnclosingRect(bounds); |
| 47 } | 60 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 | 153 |
| 141 WindowSelectorItem::WindowListItem::WindowListItem(aura::Window* window) | 154 WindowSelectorItem::WindowListItem::WindowListItem(aura::Window* window) |
| 142 : activate_button_( | 155 : activate_button_( |
| 143 new TransparentActivateWindowButton(window->GetRootWindow(), this)), | 156 new TransparentActivateWindowButton(window->GetRootWindow(), this)), |
| 144 transform_window_(new ScopedTransformOverviewWindow(window)) { | 157 transform_window_(new ScopedTransformOverviewWindow(window)) { |
| 145 } | 158 } |
| 146 | 159 |
| 147 WindowSelectorItem::WindowListItem::~WindowListItem() { | 160 WindowSelectorItem::WindowListItem::~WindowListItem() { |
| 148 } | 161 } |
| 149 | 162 |
| 163 void WindowSelectorItem::WindowListItem::Scroll(int delta_x) { | |
| 164 const float opacity = CalculateOpacityFromScrollDistance(delta_x); | |
| 165 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | |
| 166 transform_window_->BeginScopedAnimation( | |
| 167 OverviewAnimationSettingsProvider::AnimationType::SELECTOR_ITEM_SCROLL, | |
| 168 &animation_settings); | |
| 169 | |
| 170 gfx::Transform new_transform; | |
| 171 new_transform.Translate(delta_x, 0); | |
| 172 new_transform.PreconcatTransform(transform_window_->get_overview_transform()); | |
| 173 transform_window_->SetTransform(transform_window_->window()->GetRootWindow(), | |
| 174 new_transform); | |
| 175 | |
| 176 transform_window_->SetOpacity(opacity); | |
| 177 } | |
| 178 | |
| 179 void WindowSelectorItem::WindowListItem::CancelScroll() { | |
| 180 aura::Window* window = transform_window_->window(); | |
| 181 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | |
| 182 transform_window_->BeginScopedAnimation( | |
| 183 OverviewAnimationSettingsProvider::AnimationType:: | |
| 184 SELECTOR_ITEM_SCROLL_CANCEL, | |
| 185 &animation_settings); | |
| 186 // The target opacity is set before the transform so that the | |
| 187 // WindowSelectorItem::OnWindowTransformed handler can properly | |
| 188 // update the opacity of the close button to the window's target | |
| 189 // opacity. | |
| 190 transform_window_->SetOpacity(1.0); | |
| 191 transform_window_->SetTransform(window->GetRootWindow(), | |
| 192 transform_window_->get_overview_transform()); | |
| 193 } | |
| 194 | |
| 150 void WindowSelectorItem::WindowListItem::Select() { | 195 void WindowSelectorItem::WindowListItem::Select() { |
| 151 aura::Window* window = transform_window_->window(); | 196 aura::Window* window = transform_window_->window(); |
| 152 wm::GetWindowState(window)->Activate(); | 197 wm::GetWindowState(window)->Activate(); |
| 153 } | 198 } |
| 154 | 199 |
| 155 void WindowSelectorItem::WindowListItem::Close() { | 200 void WindowSelectorItem::WindowListItem::Close() { |
| 156 aura::Window* window = transform_window_->window(); | 201 aura::Window* window = transform_window_->window(); |
| 157 while (::wm::GetTransientParent(window)) | 202 while (::wm::GetTransientParent(window)) |
| 158 window = ::wm::GetTransientParent(window); | 203 window = ::wm::GetTransientParent(window); |
| 159 views::Widget::GetWidgetForNativeView(window)->Close(); | 204 views::Widget::GetWidgetForNativeView(window)->Close(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 | 370 |
| 326 UpdateWindowLabels(target_bounds, root_window, animate); | 371 UpdateWindowLabels(target_bounds, root_window, animate); |
| 327 | 372 |
| 328 gfx::Rect inset_bounds(target_bounds); | 373 gfx::Rect inset_bounds(target_bounds); |
| 329 inset_bounds.Inset(kWindowMargin, kWindowMargin); | 374 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
| 330 SetItemBounds(root_window, inset_bounds, animate); | 375 SetItemBounds(root_window, inset_bounds, animate); |
| 331 | 376 |
| 332 // SetItemBounds is called before UpdateCloseButtonLayout so the close button | 377 // SetItemBounds is called before UpdateCloseButtonLayout so the close button |
| 333 // can properly use the updated windows bounds. | 378 // can properly use the updated windows bounds. |
| 334 UpdateCloseButtonLayout(animate); | 379 UpdateCloseButtonLayout(animate); |
| 380 SetCloseWindowDistanceMinimum(target_bounds_.size().width() / 2); | |
| 335 UpdateSelectorButtons(); | 381 UpdateSelectorButtons(); |
| 336 } | 382 } |
| 337 | 383 |
| 338 void WindowSelectorItem::RecomputeWindowTransforms() { | 384 void WindowSelectorItem::RecomputeWindowTransforms() { |
| 339 if (in_bounds_update_ || target_bounds_.IsEmpty()) | 385 if (in_bounds_update_ || target_bounds_.IsEmpty()) |
| 340 return; | 386 return; |
| 341 DCHECK(root_window_); | 387 DCHECK(root_window_); |
| 342 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); | 388 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); |
| 343 gfx::Rect inset_bounds(target_bounds_); | 389 gfx::Rect inset_bounds(target_bounds_); |
| 344 inset_bounds.Inset(kWindowMargin, kWindowMargin); | 390 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 close_button_widget_.GetNativeWindow()->layer()->SetOpacity( | 439 close_button_widget_.GetNativeWindow()->layer()->SetOpacity( |
| 394 window->layer()->GetTargetOpacity()); | 440 window->layer()->GetTargetOpacity()); |
| 395 // Stack the close button of the moving window on top so that if a user | 441 // Stack the close button of the moving window on top so that if a user |
| 396 // scrolls it over top of another close button and taps them then this one | 442 // scrolls it over top of another close button and taps them then this one |
| 397 // will handle event. | 443 // will handle event. |
| 398 close_button_widget_.GetNativeWindow()->parent()->StackChildAtTop( | 444 close_button_widget_.GetNativeWindow()->parent()->StackChildAtTop( |
| 399 close_button_widget_.GetNativeWindow()); | 445 close_button_widget_.GetNativeWindow()); |
| 400 } | 446 } |
| 401 } | 447 } |
| 402 | 448 |
| 449 void WindowSelectorItem::Scroll(int delta_x) { | |
| 450 for (WindowList::iterator iter = window_list_.begin(); | |
| 451 iter != window_list_.end(); | |
| 452 iter++) { | |
| 453 (*iter)->Scroll(delta_x); | |
| 454 } | |
| 455 } | |
| 456 | |
| 457 void WindowSelectorItem::CancelScroll() { | |
| 458 for (WindowList::iterator iter = window_list_.begin(); | |
| 459 iter != window_list_.end(); | |
| 460 iter++) { | |
| 461 (*iter)->CancelScroll(); | |
| 462 } | |
| 463 } | |
| 464 | |
| 403 void WindowSelectorItem::Select() { | 465 void WindowSelectorItem::Select() { |
| 404 aura::Window* selection_window = SelectionWindow(); | 466 aura::Window* selection_window = SelectionWindow(); |
| 405 if (selection_window) | 467 if (selection_window) |
| 406 wm::GetWindowState(selection_window)->Activate(); | 468 wm::GetWindowState(selection_window)->Activate(); |
| 407 } | 469 } |
| 408 | 470 |
| 471 void WindowSelectorItem::Close() { | |
| 472 for (WindowList::iterator iter = window_list_.begin(); | |
| 473 iter != window_list_.end(); | |
| 474 iter++) { | |
| 475 (*iter)->Close(); | |
| 476 } | |
| 477 } | |
| 478 | |
| 409 void WindowSelectorItem::SetItemBounds(aura::Window* root_window, | 479 void WindowSelectorItem::SetItemBounds(aura::Window* root_window, |
| 410 const gfx::Rect& target_bounds, | 480 const gfx::Rect& target_bounds, |
| 411 bool animate) { | 481 bool animate) { |
| 412 gfx::Rect bounding_rect; | 482 gfx::Rect bounding_rect; |
| 413 for (WindowList::iterator iter = window_list_.begin(); | 483 for (WindowList::iterator iter = window_list_.begin(); |
| 414 iter != window_list_.end(); | 484 iter != window_list_.end(); |
| 415 ++iter) { | 485 ++iter) { |
| 416 bounding_rect.Union((*iter)->transform_window()->GetBoundsInScreen()); | 486 bounding_rect.Union((*iter)->transform_window()->GetBoundsInScreen()); |
| 417 } | 487 } |
| 418 set_bounds( | 488 set_bounds( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 window_label_view_->SetText(title); | 619 window_label_view_->SetText(title); |
| 550 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, | 620 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, |
| 551 0, | 621 0, |
| 552 kVerticalLabelPadding, | 622 kVerticalLabelPadding, |
| 553 0); | 623 0); |
| 554 window_label_view_->SetLayoutManager(layout); | 624 window_label_view_->SetLayoutManager(layout); |
| 555 window_label_->SetContentsView(window_label_view_); | 625 window_label_->SetContentsView(window_label_view_); |
| 556 window_label_->Show(); | 626 window_label_->Show(); |
| 557 } | 627 } |
| 558 | 628 |
| 629 void WindowSelectorItem::SetCloseWindowDistanceMinimum(int distance) { | |
| 630 selector_item_activate_window_button_->SetCloseWindowDistanceMinimum( | |
| 631 distance); | |
| 632 for (WindowList::iterator iter = window_list_.begin(); | |
| 633 iter != window_list_.end(); | |
| 634 ++iter) { | |
| 635 (*iter)->activate_button()->SetCloseWindowDistanceMinimum(distance); | |
| 636 } | |
| 637 } | |
| 638 | |
| 559 void WindowSelectorItem::UpdateSelectorButtons() { | 639 void WindowSelectorItem::UpdateSelectorButtons() { |
| 560 selector_item_activate_window_button_->SetBounds(target_bounds()); | 640 selector_item_activate_window_button_->SetBounds(target_bounds()); |
| 561 | 641 |
| 562 if (window_list_.size() == 0) { | 642 if (window_list_.size() == 0) { |
| 563 selector_item_activate_window_button_->SetAccessibleName( | 643 selector_item_activate_window_button_->SetAccessibleName( |
| 564 base::EmptyString16()); | 644 base::EmptyString16()); |
| 565 } else { | 645 } else { |
| 566 selector_item_activate_window_button_->SetAccessibleName( | 646 selector_item_activate_window_button_->SetAccessibleName( |
| 567 window_list_.front()->transform_window()->window()->title()); | 647 window_list_.front()->transform_window()->window()->title()); |
| 568 } | 648 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { | 691 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { |
| 612 std::vector<base::string16> name_parts; | 692 std::vector<base::string16> name_parts; |
| 613 name_parts.push_back(SelectionWindow() ? SelectionWindow()->title() | 693 name_parts.push_back(SelectionWindow() ? SelectionWindow()->title() |
| 614 : base::EmptyString16()); | 694 : base::EmptyString16()); |
| 615 name_parts.push_back(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); | 695 name_parts.push_back(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); |
| 616 close_button_->SetAccessibleName( | 696 close_button_->SetAccessibleName( |
| 617 JoinString(name_parts, base::ASCIIToUTF16(" - "))); | 697 JoinString(name_parts, base::ASCIIToUTF16(" - "))); |
| 618 } | 698 } |
| 619 | 699 |
| 620 } // namespace ash | 700 } // namespace ash |
| OLD | NEW |