| 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_icon_observer.h" |
| 10 #include "ash/launcher/launcher_model.h" | 10 #include "ash/launcher/launcher_model.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 case STATUS_RUNNING: | 175 case STATUS_RUNNING: |
| 176 button->ClearState(LauncherButton::STATE_ACTIVE); | 176 button->ClearState(LauncherButton::STATE_ACTIVE); |
| 177 button->AddState(LauncherButton::STATE_RUNNING); | 177 button->AddState(LauncherButton::STATE_RUNNING); |
| 178 break; | 178 break; |
| 179 case STATUS_ACTIVE: | 179 case STATUS_ACTIVE: |
| 180 button->AddState(LauncherButton::STATE_ACTIVE); | 180 button->AddState(LauncherButton::STATE_ACTIVE); |
| 181 button->ClearState(LauncherButton::STATE_RUNNING); | 181 button->ClearState(LauncherButton::STATE_RUNNING); |
| 182 break; | 182 break; |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 |
| 185 } // namespace | 186 } // namespace |
| 186 | 187 |
| 187 // AnimationDelegate used when inserting a new item. This steadily decreased the | 188 // AnimationDelegate used when inserting a new item. This steadily decreased the |
| 188 // opacity of the layer as the animation progress. | 189 // opacity of the layer as the animation progress. |
| 189 class LauncherView::FadeOutAnimationDelegate : | 190 class LauncherView::FadeOutAnimationDelegate : |
| 190 public views::BoundsAnimator::OwnedAnimationDelegate { | 191 public views::BoundsAnimator::OwnedAnimationDelegate { |
| 191 public: | 192 public: |
| 192 FadeOutAnimationDelegate(LauncherView* host, views::View* view) | 193 FadeOutAnimationDelegate(LauncherView* host, views::View* view) |
| 193 : launcher_view_(host), | 194 : launcher_view_(host), |
| 194 view_(view) {} | 195 view_(view) {} |
| (...skipping 24 matching lines...) Expand all Loading... |
| 219 public views::BoundsAnimator::OwnedAnimationDelegate { | 220 public views::BoundsAnimator::OwnedAnimationDelegate { |
| 220 public: | 221 public: |
| 221 StartFadeAnimationDelegate(LauncherView* host, | 222 StartFadeAnimationDelegate(LauncherView* host, |
| 222 views::View* view) | 223 views::View* view) |
| 223 : launcher_view_(host), | 224 : launcher_view_(host), |
| 224 view_(view) {} | 225 view_(view) {} |
| 225 virtual ~StartFadeAnimationDelegate() {} | 226 virtual ~StartFadeAnimationDelegate() {} |
| 226 | 227 |
| 227 // AnimationDelegate overrides: | 228 // AnimationDelegate overrides: |
| 228 virtual void AnimationEnded(const Animation* animation) OVERRIDE { | 229 virtual void AnimationEnded(const Animation* animation) OVERRIDE { |
| 229 view_->SetVisible(true); | |
| 230 launcher_view_->FadeIn(view_); | 230 launcher_view_->FadeIn(view_); |
| 231 } | 231 } |
| 232 virtual void AnimationCanceled(const Animation* animation) OVERRIDE { | 232 virtual void AnimationCanceled(const Animation* animation) OVERRIDE { |
| 233 view_->SetVisible(true); | 233 view_->SetVisible(true); |
| 234 } | 234 } |
| 235 | 235 |
| 236 private: | 236 private: |
| 237 LauncherView* launcher_view_; | 237 LauncherView* launcher_view_; |
| 238 views::View* view_; | 238 views::View* view_; |
| 239 | 239 |
| 240 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); | 240 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 int LauncherView::TestAPI::GetButtonCount() { | |
| 244 return launcher_view_->view_model_->view_size(); | |
| 245 } | |
| 246 | |
| 247 LauncherButton* LauncherView::TestAPI::GetButton(int index) { | |
| 248 if (index == 0) | |
| 249 return NULL; | |
| 250 | |
| 251 return static_cast<LauncherButton*>( | |
| 252 launcher_view_->view_model_->view_at(index)); | |
| 253 } | |
| 254 | |
| 255 LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate) | 243 LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate) |
| 256 : model_(model), | 244 : model_(model), |
| 257 delegate_(delegate), | 245 delegate_(delegate), |
| 258 view_model_(new views::ViewModel), | 246 view_model_(new views::ViewModel), |
| 259 last_visible_index_(-1), | 247 last_visible_index_(-1), |
| 260 overflow_button_(NULL), | 248 overflow_button_(NULL), |
| 261 dragging_(NULL), | 249 dragging_(NULL), |
| 262 drag_view_(NULL), | 250 drag_view_(NULL), |
| 263 drag_offset_(0), | 251 drag_offset_(0), |
| 264 start_drag_index_(-1), | 252 start_drag_index_(-1), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 view_model_->set_ideal_bounds(i, gfx::Rect( | 350 view_model_->set_ideal_bounds(i, gfx::Rect( |
| 363 x, (kLauncherPreferredHeight - pref.height()) / 2, pref.width(), | 351 x, (kLauncherPreferredHeight - pref.height()) / 2, pref.width(), |
| 364 pref.height())); | 352 pref.height())); |
| 365 x += pref.width() + kButtonSpacing; | 353 x += pref.width() + kButtonSpacing; |
| 366 } | 354 } |
| 367 | 355 |
| 368 bounds->overflow_bounds.set_size(gfx::Size(kButtonWidth, kButtonHeight)); | 356 bounds->overflow_bounds.set_size(gfx::Size(kButtonWidth, kButtonHeight)); |
| 369 last_visible_index_ = DetermineLastVisibleIndex( | 357 last_visible_index_ = DetermineLastVisibleIndex( |
| 370 available_width - kLeadingInset - bounds->overflow_bounds.width() - | 358 available_width - kLeadingInset - bounds->overflow_bounds.width() - |
| 371 kButtonSpacing - kButtonWidth); | 359 kButtonSpacing - kButtonWidth); |
| 372 bool show_overflow = | |
| 373 (last_visible_index_ + 1 != view_model_->view_size()); | |
| 374 int app_list_index = view_model_->view_size() - 1; | 360 int app_list_index = view_model_->view_size() - 1; |
| 375 if (overflow_button_->visible() != show_overflow) { | 361 bool show_overflow = (last_visible_index_ + 1 < app_list_index); |
| 376 // Only change visibility of the views if the visibility of the overflow | 362 |
| 377 // button changes. Otherwise we'll effect the insertion animation, which | 363 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 378 // changes the visibility. | 364 view_model_->view_at(i)->SetVisible( |
| 379 for (int i = 0; i <= last_visible_index_; ++i) | 365 i == app_list_index || i <= last_visible_index_); |
| 380 view_model_->view_at(i)->SetVisible(true); | |
| 381 for (int i = last_visible_index_ + 1; i < view_model_->view_size(); ++i) { | |
| 382 if (i != app_list_index) | |
| 383 view_model_->view_at(i)->SetVisible(false); | |
| 384 } | |
| 385 } | 366 } |
| 367 |
| 386 overflow_button_->SetVisible(show_overflow); | 368 overflow_button_->SetVisible(show_overflow); |
| 387 if (show_overflow) { | 369 if (show_overflow) { |
| 388 DCHECK_NE(0, view_model_->view_size()); | 370 DCHECK_NE(0, view_model_->view_size()); |
| 389 // We always want the app list visible. | 371 // We always want the app list visible. |
| 390 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); | 372 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); |
| 391 x = last_visible_index_ == -1 ? | 373 x = last_visible_index_ == -1 ? |
| 392 kLeadingInset : view_model_->ideal_bounds(last_visible_index_).right(); | 374 kLeadingInset : view_model_->ideal_bounds(last_visible_index_).right(); |
| 393 app_list_bounds.set_x(x); | 375 app_list_bounds.set_x(x); |
| 394 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); | 376 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); |
| 395 x = app_list_bounds.right() + kButtonSpacing; | 377 x = app_list_bounds.right() + kButtonSpacing; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 | 663 |
| 682 views::FocusTraversable* LauncherView::GetPaneFocusTraversable() { | 664 views::FocusTraversable* LauncherView::GetPaneFocusTraversable() { |
| 683 return this; | 665 return this; |
| 684 } | 666 } |
| 685 | 667 |
| 686 void LauncherView::LauncherItemAdded(int model_index) { | 668 void LauncherView::LauncherItemAdded(int model_index) { |
| 687 CancelDrag(NULL); | 669 CancelDrag(NULL); |
| 688 | 670 |
| 689 views::View* view = CreateViewForItem(model_->items()[model_index]); | 671 views::View* view = CreateViewForItem(model_->items()[model_index]); |
| 690 AddChildView(view); | 672 AddChildView(view); |
| 691 // Hide the view, it'll be made visible when the animation is done. | 673 // Hide the view, it'll be made visible when the animation is done. Using |
| 692 view->SetVisible(false); | 674 // opacity 0 here to avoid messing with CalculateIdealBounds which touches |
| 675 // the view's visibility. |
| 676 view->layer()->SetOpacity(0); |
| 693 view_model_->Add(view, model_index); | 677 view_model_->Add(view, model_index); |
| 694 | 678 |
| 695 // Give the button it's ideal bounds. That way if we end up animating the | 679 // Give the button its ideal bounds. That way if we end up animating the |
| 696 // button before this animation completes it doesn't appear at some random | 680 // button before this animation completes it doesn't appear at some random |
| 697 // spot (because it was in the middle of animating from 0,0 0x0 to its | 681 // spot (because it was in the middle of animating from 0,0 0x0 to its |
| 698 // target). | 682 // target). |
| 699 IdealBounds ideal_bounds; | 683 IdealBounds ideal_bounds; |
| 700 CalculateIdealBounds(&ideal_bounds); | 684 CalculateIdealBounds(&ideal_bounds); |
| 701 view->SetBoundsRect(view_model_->ideal_bounds(model_index)); | 685 view->SetBoundsRect(view_model_->ideal_bounds(model_index)); |
| 702 | 686 |
| 703 // The first animation moves all the views to their target position. |view| is | 687 // The first animation moves all the views to their target position. |view| |
| 704 // hidden, so it visually appears as though we are providing space for | 688 // is hidden, so it visually appears as though we are providing space for |
| 705 // it. When done we'll fade the view in. | 689 // it. When done we'll fade the view in. |
| 706 AnimateToIdealBounds(); | 690 AnimateToIdealBounds(); |
| 707 if (!overflow_button_->visible()) { | 691 if (model_index <= last_visible_index_) { |
| 708 bounds_animator_->SetAnimationDelegate( | 692 bounds_animator_->SetAnimationDelegate( |
| 709 view, new StartFadeAnimationDelegate(this, view), true); | 693 view, new StartFadeAnimationDelegate(this, view), true); |
| 694 } else { |
| 695 // Undo the hiding if animation does not run. |
| 696 view->layer()->SetOpacity(1.0f); |
| 710 } | 697 } |
| 711 | 698 |
| 712 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, | 699 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
| 713 OnLauncherIconPositionsChanged()); | 700 OnLauncherIconPositionsChanged()); |
| 714 } | 701 } |
| 715 | 702 |
| 716 void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) { | 703 void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) { |
| 717 #if !defined(OS_MACOSX) | 704 #if !defined(OS_MACOSX) |
| 718 if (id == context_menu_id_) | 705 if (id == context_menu_id_) |
| 719 launcher_menu_runner_.reset(); | 706 launcher_menu_runner_.reset(); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 source->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 902 source->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
| 916 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED) | 903 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED) |
| 917 return; | 904 return; |
| 918 | 905 |
| 919 Shell::GetInstance()->UpdateShelfVisibility(); | 906 Shell::GetInstance()->UpdateShelfVisibility(); |
| 920 #endif | 907 #endif |
| 921 } | 908 } |
| 922 | 909 |
| 923 } // namespace internal | 910 } // namespace internal |
| 924 } // namespace ash | 911 } // namespace ash |
| OLD | NEW |