| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/launcher/launcher_view.h" | 5 #include "ash/launcher/launcher_view.h" |
| 6 | 6 |
| 7 #include "ash/launcher/launcher_button.h" | 7 #include "ash/launcher/launcher_button.h" |
| 8 #include "ash/launcher/launcher_delegate.h" | 8 #include "ash/launcher/launcher_delegate.h" |
| 9 #include "ash/launcher/launcher_icon_observer.h" |
| 9 #include "ash/launcher/launcher_model.h" | 10 #include "ash/launcher/launcher_model.h" |
| 10 #include "ash/launcher/tabbed_launcher_button.h" | 11 #include "ash/launcher/tabbed_launcher_button.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
| 13 #include "base/auto_reset.h" | 14 #include "base/auto_reset.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
| 16 #include "grit/ui_resources.h" | 17 #include "grit/ui_resources.h" |
| 17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 18 #include "ui/base/animation/animation.h" | 19 #include "ui/base/animation/animation.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 return NULL; | 249 return NULL; |
| 249 | 250 |
| 250 return static_cast<LauncherButton*>( | 251 return static_cast<LauncherButton*>( |
| 251 launcher_view_->view_model_->view_at(index)); | 252 launcher_view_->view_model_->view_at(index)); |
| 252 } | 253 } |
| 253 | 254 |
| 254 LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate) | 255 LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate) |
| 255 : model_(model), | 256 : model_(model), |
| 256 delegate_(delegate), | 257 delegate_(delegate), |
| 257 view_model_(new views::ViewModel), | 258 view_model_(new views::ViewModel), |
| 259 last_visible_index_(-1), |
| 258 overflow_button_(NULL), | 260 overflow_button_(NULL), |
| 259 dragging_(NULL), | 261 dragging_(NULL), |
| 260 drag_view_(NULL), | 262 drag_view_(NULL), |
| 261 drag_offset_(0), | 263 drag_offset_(0), |
| 262 start_drag_index_(-1), | 264 start_drag_index_(-1), |
| 263 context_menu_id_(0) { | 265 context_menu_id_(0) { |
| 264 DCHECK(model_); | 266 DCHECK(model_); |
| 265 bounds_animator_.reset(new views::BoundsAnimator(this)); | 267 bounds_animator_.reset(new views::BoundsAnimator(this)); |
| 266 set_context_menu_controller(this); | 268 set_context_menu_controller(this); |
| 267 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); | 269 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 298 l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME)); | 300 l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME)); |
| 299 overflow_button_->set_context_menu_controller(this); | 301 overflow_button_->set_context_menu_controller(this); |
| 300 ConfigureChildView(overflow_button_); | 302 ConfigureChildView(overflow_button_); |
| 301 AddChildView(overflow_button_); | 303 AddChildView(overflow_button_); |
| 302 | 304 |
| 303 // We'll layout when our bounds change. | 305 // We'll layout when our bounds change. |
| 304 } | 306 } |
| 305 | 307 |
| 306 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) { | 308 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) { |
| 307 int index = model_->ItemIndexByID(id); | 309 int index = model_->ItemIndexByID(id); |
| 308 if (index == -1 || !view_model_->view_at(index)->visible()) | 310 if (index == -1 || index > last_visible_index_) |
| 309 return gfx::Rect(); | 311 return gfx::Rect(); |
| 310 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); | 312 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); |
| 311 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); | 313 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); |
| 312 LauncherButton* button = | 314 LauncherButton* button = |
| 313 static_cast<LauncherButton*>(view_model_->view_at(index)); | 315 static_cast<LauncherButton*>(view_model_->view_at(index)); |
| 314 gfx::Rect icon_bounds = button->GetIconBounds(); | 316 gfx::Rect icon_bounds = button->GetIconBounds(); |
| 315 return gfx::Rect(ideal_bounds.x() + icon_bounds.x(), | 317 return gfx::Rect(ideal_bounds.x() + icon_bounds.x(), |
| 316 ideal_bounds.y() + icon_bounds.y(), | 318 ideal_bounds.y() + icon_bounds.y(), |
| 317 icon_bounds.width(), icon_bounds.height()); | 319 icon_bounds.width(), icon_bounds.height()); |
| 318 } | 320 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 int x = kLeadingInset; | 359 int x = kLeadingInset; |
| 358 for (int i = 0; i < view_model_->view_size(); ++i) { | 360 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 359 gfx::Size pref(kButtonWidth, kButtonHeight); | 361 gfx::Size pref(kButtonWidth, kButtonHeight); |
| 360 view_model_->set_ideal_bounds(i, gfx::Rect( | 362 view_model_->set_ideal_bounds(i, gfx::Rect( |
| 361 x, (kLauncherPreferredHeight - pref.height()) / 2, pref.width(), | 363 x, (kLauncherPreferredHeight - pref.height()) / 2, pref.width(), |
| 362 pref.height())); | 364 pref.height())); |
| 363 x += pref.width() + kButtonSpacing; | 365 x += pref.width() + kButtonSpacing; |
| 364 } | 366 } |
| 365 | 367 |
| 366 bounds->overflow_bounds.set_size(gfx::Size(kButtonWidth, kButtonHeight)); | 368 bounds->overflow_bounds.set_size(gfx::Size(kButtonWidth, kButtonHeight)); |
| 367 int last_visible_index = DetermineLastVisibleIndex( | 369 last_visible_index_ = DetermineLastVisibleIndex( |
| 368 available_width - kLeadingInset - bounds->overflow_bounds.width() - | 370 available_width - kLeadingInset - bounds->overflow_bounds.width() - |
| 369 kButtonSpacing - kButtonWidth); | 371 kButtonSpacing - kButtonWidth); |
| 370 bool show_overflow = | 372 bool show_overflow = |
| 371 (last_visible_index + 1 != view_model_->view_size()); | 373 (last_visible_index_ + 1 != view_model_->view_size()); |
| 372 int app_list_index = view_model_->view_size() - 1; | 374 int app_list_index = view_model_->view_size() - 1; |
| 373 if (overflow_button_->visible() != show_overflow) { | 375 if (overflow_button_->visible() != show_overflow) { |
| 374 // Only change visibility of the views if the visibility of the overflow | 376 // Only change visibility of the views if the visibility of the overflow |
| 375 // button changes. Otherwise we'll effect the insertion animation, which | 377 // button changes. Otherwise we'll effect the insertion animation, which |
| 376 // changes the visibility. | 378 // changes the visibility. |
| 377 for (int i = 0; i <= last_visible_index; ++i) | 379 for (int i = 0; i <= last_visible_index_; ++i) |
| 378 view_model_->view_at(i)->SetVisible(true); | 380 view_model_->view_at(i)->SetVisible(true); |
| 379 for (int i = last_visible_index + 1; i < view_model_->view_size(); ++i) { | 381 for (int i = last_visible_index_ + 1; i < view_model_->view_size(); ++i) { |
| 380 if (i != app_list_index) | 382 if (i != app_list_index) |
| 381 view_model_->view_at(i)->SetVisible(false); | 383 view_model_->view_at(i)->SetVisible(false); |
| 382 } | 384 } |
| 383 } | 385 } |
| 384 overflow_button_->SetVisible(show_overflow); | 386 overflow_button_->SetVisible(show_overflow); |
| 385 if (show_overflow) { | 387 if (show_overflow) { |
| 386 DCHECK_NE(0, view_model_->view_size()); | 388 DCHECK_NE(0, view_model_->view_size()); |
| 387 // We always want the app list visible. | 389 // We always want the app list visible. |
| 388 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); | 390 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); |
| 389 x = last_visible_index == -1 ? | 391 x = last_visible_index_ == -1 ? |
| 390 kLeadingInset : view_model_->ideal_bounds(last_visible_index).right(); | 392 kLeadingInset : view_model_->ideal_bounds(last_visible_index_).right(); |
| 391 app_list_bounds.set_x(x); | 393 app_list_bounds.set_x(x); |
| 392 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); | 394 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); |
| 393 x = app_list_bounds.right() + kButtonSpacing; | 395 x = app_list_bounds.right() + kButtonSpacing; |
| 394 bounds->overflow_bounds.set_x(x); | 396 bounds->overflow_bounds.set_x(x); |
| 395 bounds->overflow_bounds.set_y( | 397 bounds->overflow_bounds.set_y( |
| 396 (kLauncherPreferredHeight - bounds->overflow_bounds.height()) / 2); | 398 (kLauncherPreferredHeight - bounds->overflow_bounds.height()) / 2); |
| 397 } | 399 } |
| 398 } | 400 } |
| 399 | 401 |
| 400 int LauncherView::DetermineLastVisibleIndex(int max_x) { | 402 int LauncherView::DetermineLastVisibleIndex(int max_x) { |
| 401 int index = view_model_->view_size() - 1; | 403 int index = view_model_->view_size() - 1; |
| 402 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) | 404 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) |
| 403 index--; | 405 index--; |
| 404 return index; | 406 return index; |
| 405 } | 407 } |
| 406 | 408 |
| 409 void LauncherView::AddIconObserver(LauncherIconObserver* observer) { |
| 410 observers_.AddObserver(observer); |
| 411 } |
| 412 |
| 413 void LauncherView::RemoveIconObserver(LauncherIconObserver* observer) { |
| 414 observers_.RemoveObserver(observer); |
| 415 } |
| 416 |
| 407 void LauncherView::AnimateToIdealBounds() { | 417 void LauncherView::AnimateToIdealBounds() { |
| 408 IdealBounds ideal_bounds; | 418 IdealBounds ideal_bounds; |
| 409 CalculateIdealBounds(&ideal_bounds); | 419 CalculateIdealBounds(&ideal_bounds); |
| 410 for (int i = 0; i < view_model_->view_size(); ++i) { | 420 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 411 bounds_animator_->AnimateViewTo(view_model_->view_at(i), | 421 bounds_animator_->AnimateViewTo(view_model_->view_at(i), |
| 412 view_model_->ideal_bounds(i)); | 422 view_model_->ideal_bounds(i)); |
| 413 } | 423 } |
| 414 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); | 424 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
| 415 } | 425 } |
| 416 | 426 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 return; | 544 return; |
| 535 | 545 |
| 536 // Remove the observer while we mutate the model so that we don't attempt to | 546 // Remove the observer while we mutate the model so that we don't attempt to |
| 537 // cancel the drag. | 547 // cancel the drag. |
| 538 model_->RemoveObserver(this); | 548 model_->RemoveObserver(this); |
| 539 model_->Move(current_index, target_index); | 549 model_->Move(current_index, target_index); |
| 540 model_->AddObserver(this); | 550 model_->AddObserver(this); |
| 541 view_model_->Move(current_index, target_index); | 551 view_model_->Move(current_index, target_index); |
| 542 AnimateToIdealBounds(); | 552 AnimateToIdealBounds(); |
| 543 bounds_animator_->StopAnimatingView(drag_view_); | 553 bounds_animator_->StopAnimatingView(drag_view_); |
| 554 |
| 555 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
| 556 OnLauncherIconPositionsChanged()); |
| 544 } | 557 } |
| 545 | 558 |
| 546 bool LauncherView::SameDragType(LauncherItemType typea, | 559 bool LauncherView::SameDragType(LauncherItemType typea, |
| 547 LauncherItemType typeb) const { | 560 LauncherItemType typeb) const { |
| 548 switch(typea) { | 561 switch(typea) { |
| 549 case TYPE_TABBED: | 562 case TYPE_TABBED: |
| 550 case TYPE_APP_PANEL: | 563 case TYPE_APP_PANEL: |
| 551 return (typeb == TYPE_TABBED || typeb == TYPE_APP_PANEL); | 564 return (typeb == TYPE_TABBED || typeb == TYPE_APP_PANEL); |
| 552 case TYPE_APP_SHORTCUT: | 565 case TYPE_APP_SHORTCUT: |
| 553 case TYPE_APP_LIST: | 566 case TYPE_APP_LIST: |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 // Should always have two items. | 668 // Should always have two items. |
| 656 return gfx::Size(view_model_->ideal_bounds(1).right() + kLeadingInset, | 669 return gfx::Size(view_model_->ideal_bounds(1).right() + kLeadingInset, |
| 657 kLauncherPreferredHeight); | 670 kLauncherPreferredHeight); |
| 658 } | 671 } |
| 659 return gfx::Size(kButtonWidth * 2 + kLeadingInset * 2, | 672 return gfx::Size(kButtonWidth * 2 + kLeadingInset * 2, |
| 660 kLauncherPreferredHeight); | 673 kLauncherPreferredHeight); |
| 661 } | 674 } |
| 662 | 675 |
| 663 void LauncherView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 676 void LauncherView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 664 LayoutToIdealBounds(); | 677 LayoutToIdealBounds(); |
| 678 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
| 679 OnLauncherIconPositionsChanged()); |
| 665 } | 680 } |
| 666 | 681 |
| 667 views::FocusTraversable* LauncherView::GetPaneFocusTraversable() { | 682 views::FocusTraversable* LauncherView::GetPaneFocusTraversable() { |
| 668 return this; | 683 return this; |
| 669 } | 684 } |
| 670 | 685 |
| 671 void LauncherView::LauncherItemAdded(int model_index) { | 686 void LauncherView::LauncherItemAdded(int model_index) { |
| 672 CancelDrag(NULL); | 687 CancelDrag(NULL); |
| 673 | 688 |
| 674 views::View* view = CreateViewForItem(model_->items()[model_index]); | 689 views::View* view = CreateViewForItem(model_->items()[model_index]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 686 view->SetBoundsRect(view_model_->ideal_bounds(model_index)); | 701 view->SetBoundsRect(view_model_->ideal_bounds(model_index)); |
| 687 | 702 |
| 688 // The first animation moves all the views to their target position. |view| is | 703 // The first animation moves all the views to their target position. |view| is |
| 689 // hidden, so it visually appears as though we are providing space for | 704 // hidden, so it visually appears as though we are providing space for |
| 690 // it. When done we'll fade the view in. | 705 // it. When done we'll fade the view in. |
| 691 AnimateToIdealBounds(); | 706 AnimateToIdealBounds(); |
| 692 if (!overflow_button_->visible()) { | 707 if (!overflow_button_->visible()) { |
| 693 bounds_animator_->SetAnimationDelegate( | 708 bounds_animator_->SetAnimationDelegate( |
| 694 view, new StartFadeAnimationDelegate(this, view), true); | 709 view, new StartFadeAnimationDelegate(this, view), true); |
| 695 } | 710 } |
| 711 |
| 712 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
| 713 OnLauncherIconPositionsChanged()); |
| 696 } | 714 } |
| 697 | 715 |
| 698 void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) { | 716 void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) { |
| 699 #if !defined(OS_MACOSX) | 717 #if !defined(OS_MACOSX) |
| 700 if (id == context_menu_id_) | 718 if (id == context_menu_id_) |
| 701 launcher_menu_runner_.reset(); | 719 launcher_menu_runner_.reset(); |
| 702 #endif | 720 #endif |
| 703 views::View* view = view_model_->view_at(model_index); | 721 views::View* view = view_model_->view_at(model_index); |
| 704 CancelDrag(view); | 722 CancelDrag(view); |
| 705 view_model_->Remove(model_index); | 723 view_model_->Remove(model_index); |
| 706 // The first animation fades out the view. When done we'll animate the rest of | 724 // The first animation fades out the view. When done we'll animate the rest of |
| 707 // the views to their target location. | 725 // the views to their target location. |
| 708 bounds_animator_->AnimateViewTo(view, view->bounds()); | 726 bounds_animator_->AnimateViewTo(view, view->bounds()); |
| 709 bounds_animator_->SetAnimationDelegate( | 727 bounds_animator_->SetAnimationDelegate( |
| 710 view, new FadeOutAnimationDelegate(this, view), true); | 728 view, new FadeOutAnimationDelegate(this, view), true); |
| 729 |
| 730 // The animation will eventually update the ideal bounds, but we want to |
| 731 // force an update immediately so we can notify launcher icon observers. |
| 732 IdealBounds ideal_bounds; |
| 733 CalculateIdealBounds(&ideal_bounds); |
| 734 |
| 735 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
| 736 OnLauncherIconPositionsChanged()); |
| 711 } | 737 } |
| 712 | 738 |
| 713 void LauncherView::LauncherItemChanged(int model_index, | 739 void LauncherView::LauncherItemChanged(int model_index, |
| 714 const ash::LauncherItem& old_item) { | 740 const ash::LauncherItem& old_item) { |
| 715 const LauncherItem& item(model_->items()[model_index]); | 741 const LauncherItem& item(model_->items()[model_index]); |
| 716 if (old_item.type != item.type) { | 742 if (old_item.type != item.type) { |
| 717 // Type changed, swap the views. | 743 // Type changed, swap the views. |
| 718 scoped_ptr<views::View> old_view(view_model_->view_at(model_index)); | 744 scoped_ptr<views::View> old_view(view_model_->view_at(model_index)); |
| 719 bounds_animator_->StopAnimatingView(old_view.get()); | 745 bounds_animator_->StopAnimatingView(old_view.get()); |
| 720 CancelDrag(old_view.get()); | 746 CancelDrag(old_view.get()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 750 } | 776 } |
| 751 | 777 |
| 752 default: | 778 default: |
| 753 break; | 779 break; |
| 754 } | 780 } |
| 755 } | 781 } |
| 756 | 782 |
| 757 void LauncherView::LauncherItemMoved(int start_index, int target_index) { | 783 void LauncherView::LauncherItemMoved(int start_index, int target_index) { |
| 758 view_model_->Move(start_index, target_index); | 784 view_model_->Move(start_index, target_index); |
| 759 AnimateToIdealBounds(); | 785 AnimateToIdealBounds(); |
| 786 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
| 787 OnLauncherIconPositionsChanged()); |
| 760 } | 788 } |
| 761 | 789 |
| 762 void LauncherView::LauncherItemWillChange(int index) { | 790 void LauncherView::LauncherItemWillChange(int index) { |
| 763 const LauncherItem& item(model_->items()[index]); | 791 const LauncherItem& item(model_->items()[index]); |
| 764 views::View* view = view_model_->view_at(index); | 792 views::View* view = view_model_->view_at(index); |
| 765 if (item.type == TYPE_TABBED) | 793 if (item.type == TYPE_TABBED) |
| 766 static_cast<TabbedLauncherButton*>(view)->PrepareForImageChange(); | 794 static_cast<TabbedLauncherButton*>(view)->PrepareForImageChange(); |
| 767 } | 795 } |
| 768 | 796 |
| 769 void LauncherView::MousePressedOnButton(views::View* view, | 797 void LauncherView::MousePressedOnButton(views::View* view, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 source->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 916 source->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
| 889 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED) | 917 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED) |
| 890 return; | 918 return; |
| 891 | 919 |
| 892 Shell::GetInstance()->UpdateShelfVisibility(); | 920 Shell::GetInstance()->UpdateShelfVisibility(); |
| 893 #endif | 921 #endif |
| 894 } | 922 } |
| 895 | 923 |
| 896 } // namespace internal | 924 } // namespace internal |
| 897 } // namespace ash | 925 } // namespace ash |
| OLD | NEW |