Chromium Code Reviews| 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_model.h" | 9 #include "ash/launcher/launcher_model.h" |
| 10 #include "ash/launcher/tabbed_launcher_button.h" | 10 #include "ash/launcher/tabbed_launcher_button.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 case STATUS_RUNNING: | 174 case STATUS_RUNNING: |
| 175 button->ClearState(LauncherButton::STATE_ACTIVE); | 175 button->ClearState(LauncherButton::STATE_ACTIVE); |
| 176 button->AddState(LauncherButton::STATE_RUNNING); | 176 button->AddState(LauncherButton::STATE_RUNNING); |
| 177 break; | 177 break; |
| 178 case STATUS_ACTIVE: | 178 case STATUS_ACTIVE: |
| 179 button->AddState(LauncherButton::STATE_ACTIVE); | 179 button->AddState(LauncherButton::STATE_ACTIVE); |
| 180 button->ClearState(LauncherButton::STATE_RUNNING); | 180 button->ClearState(LauncherButton::STATE_RUNNING); |
| 181 break; | 181 break; |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 | |
| 184 } // namespace | 185 } // namespace |
| 185 | 186 |
| 186 // AnimationDelegate used when inserting a new item. This steadily decreased the | 187 // AnimationDelegate used when inserting a new item. This steadily decreased the |
| 187 // opacity of the layer as the animation progress. | 188 // opacity of the layer as the animation progress. |
| 188 class LauncherView::FadeOutAnimationDelegate : | 189 class LauncherView::FadeOutAnimationDelegate : |
| 189 public views::BoundsAnimator::OwnedAnimationDelegate { | 190 public views::BoundsAnimator::OwnedAnimationDelegate { |
| 190 public: | 191 public: |
| 191 FadeOutAnimationDelegate(LauncherView* host, views::View* view) | 192 FadeOutAnimationDelegate(LauncherView* host, views::View* view) |
| 192 : launcher_view_(host), | 193 : launcher_view_(host), |
| 193 view_(view) {} | 194 view_(view) {} |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 218 public views::BoundsAnimator::OwnedAnimationDelegate { | 219 public views::BoundsAnimator::OwnedAnimationDelegate { |
| 219 public: | 220 public: |
| 220 StartFadeAnimationDelegate(LauncherView* host, | 221 StartFadeAnimationDelegate(LauncherView* host, |
| 221 views::View* view) | 222 views::View* view) |
| 222 : launcher_view_(host), | 223 : launcher_view_(host), |
| 223 view_(view) {} | 224 view_(view) {} |
| 224 virtual ~StartFadeAnimationDelegate() {} | 225 virtual ~StartFadeAnimationDelegate() {} |
| 225 | 226 |
| 226 // AnimationDelegate overrides: | 227 // AnimationDelegate overrides: |
| 227 virtual void AnimationEnded(const Animation* animation) OVERRIDE { | 228 virtual void AnimationEnded(const Animation* animation) OVERRIDE { |
| 228 view_->SetVisible(true); | |
| 229 launcher_view_->FadeIn(view_); | 229 launcher_view_->FadeIn(view_); |
| 230 } | 230 } |
| 231 virtual void AnimationCanceled(const Animation* animation) OVERRIDE { | 231 virtual void AnimationCanceled(const Animation* animation) OVERRIDE { |
| 232 view_->SetVisible(true); | 232 view_->SetVisible(true); |
| 233 } | 233 } |
| 234 | 234 |
| 235 private: | 235 private: |
| 236 LauncherView* launcher_view_; | 236 LauncherView* launcher_view_; |
| 237 views::View* view_; | 237 views::View* view_; |
| 238 | 238 |
| 239 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); | 239 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 int LauncherView::TestAPI::GetButtonCount() { | |
| 243 return launcher_view_->view_model_->view_size(); | |
| 244 } | |
| 245 | |
| 246 LauncherButton* LauncherView::TestAPI::GetButton(int index) { | |
| 247 if (index == 0) | |
| 248 return NULL; | |
| 249 | |
| 250 return static_cast<LauncherButton*>( | |
| 251 launcher_view_->view_model_->view_at(index)); | |
| 252 } | |
| 253 | |
| 254 LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate) | 242 LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate) |
| 255 : model_(model), | 243 : model_(model), |
| 256 delegate_(delegate), | 244 delegate_(delegate), |
| 257 view_model_(new views::ViewModel), | 245 view_model_(new views::ViewModel), |
| 246 last_visible_index_(-1), | |
| 258 overflow_button_(NULL), | 247 overflow_button_(NULL), |
| 259 dragging_(NULL), | 248 dragging_(NULL), |
| 260 drag_view_(NULL), | 249 drag_view_(NULL), |
| 261 drag_offset_(0), | 250 drag_offset_(0), |
| 262 start_drag_index_(-1), | 251 start_drag_index_(-1), |
| 263 context_menu_id_(0) { | 252 context_menu_id_(0) { |
| 264 DCHECK(model_); | 253 DCHECK(model_); |
| 265 bounds_animator_.reset(new views::BoundsAnimator(this)); | 254 bounds_animator_.reset(new views::BoundsAnimator(this)); |
| 266 set_context_menu_controller(this); | 255 set_context_menu_controller(this); |
| 267 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); | 256 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 int x = kLeadingInset; | 346 int x = kLeadingInset; |
| 358 for (int i = 0; i < view_model_->view_size(); ++i) { | 347 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 359 gfx::Size pref(kButtonWidth, kButtonHeight); | 348 gfx::Size pref(kButtonWidth, kButtonHeight); |
| 360 view_model_->set_ideal_bounds(i, gfx::Rect( | 349 view_model_->set_ideal_bounds(i, gfx::Rect( |
| 361 x, (kLauncherPreferredHeight - pref.height()) / 2, pref.width(), | 350 x, (kLauncherPreferredHeight - pref.height()) / 2, pref.width(), |
| 362 pref.height())); | 351 pref.height())); |
| 363 x += pref.width() + kButtonSpacing; | 352 x += pref.width() + kButtonSpacing; |
| 364 } | 353 } |
| 365 | 354 |
| 366 bounds->overflow_bounds.set_size(gfx::Size(kButtonWidth, kButtonHeight)); | 355 bounds->overflow_bounds.set_size(gfx::Size(kButtonWidth, kButtonHeight)); |
| 367 int last_visible_index = DetermineLastVisibleIndex( | 356 last_visible_index_ = DetermineLastVisibleIndex( |
| 368 available_width - kLeadingInset - bounds->overflow_bounds.width() - | 357 available_width - kLeadingInset - bounds->overflow_bounds.width() - |
| 369 kButtonSpacing - kButtonWidth); | 358 kButtonSpacing - kButtonWidth); |
| 370 bool show_overflow = | |
| 371 (last_visible_index + 1 != view_model_->view_size()); | |
| 372 int app_list_index = view_model_->view_size() - 1; | 359 int app_list_index = view_model_->view_size() - 1; |
| 373 if (overflow_button_->visible() != show_overflow) { | 360 bool show_overflow = (last_visible_index_ + 1 < app_list_index); |
| 374 // Only change visibility of the views if the visibility of the overflow | 361 |
| 375 // button changes. Otherwise we'll effect the insertion animation, which | 362 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 376 // changes the visibility. | 363 view_model_->view_at(i)->SetVisible( |
| 377 for (int i = 0; i <= last_visible_index; ++i) | 364 i == app_list_index || i <= last_visible_index_); |
| 378 view_model_->view_at(i)->SetVisible(true); | |
| 379 for (int i = last_visible_index + 1; i < view_model_->view_size(); ++i) { | |
| 380 if (i != app_list_index) | |
| 381 view_model_->view_at(i)->SetVisible(false); | |
| 382 } | |
| 383 } | 365 } |
| 366 | |
| 384 overflow_button_->SetVisible(show_overflow); | 367 overflow_button_->SetVisible(show_overflow); |
| 385 if (show_overflow) { | 368 if (show_overflow) { |
| 386 DCHECK_NE(0, view_model_->view_size()); | 369 DCHECK_NE(0, view_model_->view_size()); |
| 387 // We always want the app list visible. | 370 // We always want the app list visible. |
| 388 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); | 371 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); |
| 389 x = last_visible_index == -1 ? | 372 x = last_visible_index_ == -1 ? |
| 390 kLeadingInset : view_model_->ideal_bounds(last_visible_index).right(); | 373 kLeadingInset : view_model_->ideal_bounds(last_visible_index_).right(); |
| 391 app_list_bounds.set_x(x); | 374 app_list_bounds.set_x(x); |
| 392 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); | 375 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); |
| 393 x = app_list_bounds.right() + kButtonSpacing; | 376 x = app_list_bounds.right() + kButtonSpacing; |
| 394 bounds->overflow_bounds.set_x(x); | 377 bounds->overflow_bounds.set_x(x); |
| 395 bounds->overflow_bounds.set_y( | 378 bounds->overflow_bounds.set_y( |
| 396 (kLauncherPreferredHeight - bounds->overflow_bounds.height()) / 2); | 379 (kLauncherPreferredHeight - bounds->overflow_bounds.height()) / 2); |
| 397 } | 380 } |
| 398 } | 381 } |
| 399 | 382 |
| 400 int LauncherView::DetermineLastVisibleIndex(int max_x) { | 383 int LauncherView::DetermineLastVisibleIndex(int max_x) { |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 views::FocusTraversable* LauncherView::GetPaneFocusTraversable() { | 650 views::FocusTraversable* LauncherView::GetPaneFocusTraversable() { |
| 668 return this; | 651 return this; |
| 669 } | 652 } |
| 670 | 653 |
| 671 void LauncherView::LauncherItemAdded(int model_index) { | 654 void LauncherView::LauncherItemAdded(int model_index) { |
| 672 CancelDrag(NULL); | 655 CancelDrag(NULL); |
| 673 | 656 |
| 674 views::View* view = CreateViewForItem(model_->items()[model_index]); | 657 views::View* view = CreateViewForItem(model_->items()[model_index]); |
| 675 AddChildView(view); | 658 AddChildView(view); |
| 676 // Hide the view, it'll be made visible when the animation is done. | 659 // Hide the view, it'll be made visible when the animation is done. |
| 677 view->SetVisible(false); | 660 view->layer()->SetOpacity(0); |
|
sky
2012/04/23 20:47:25
Add a comment as to why opacity is used here.
xiyuan
2012/04/23 21:01:21
Done.
| |
| 678 view_model_->Add(view, model_index); | 661 view_model_->Add(view, model_index); |
| 679 | 662 |
| 680 // Give the button it's ideal bounds. That way if we end up animating the | 663 // Give the button its ideal bounds. That way if we end up animating the |
| 681 // button before this animation completes it doesn't appear at some random | 664 // button before this animation completes it doesn't appear at some random |
| 682 // spot (because it was in the middle of animating from 0,0 0x0 to its | 665 // spot (because it was in the middle of animating from 0,0 0x0 to its |
| 683 // target). | 666 // target). |
| 684 IdealBounds ideal_bounds; | 667 IdealBounds ideal_bounds; |
| 685 CalculateIdealBounds(&ideal_bounds); | 668 CalculateIdealBounds(&ideal_bounds); |
| 686 view->SetBoundsRect(view_model_->ideal_bounds(model_index)); | 669 view->SetBoundsRect(view_model_->ideal_bounds(model_index)); |
| 687 | 670 |
| 688 // The first animation moves all the views to their target position. |view| is | 671 // The first animation moves all the views to their target position. |view| |
| 689 // hidden, so it visually appears as though we are providing space for | 672 // is hidden, so it visually appears as though we are providing space for |
| 690 // it. When done we'll fade the view in. | 673 // it. When done we'll fade the view in. |
| 691 AnimateToIdealBounds(); | 674 AnimateToIdealBounds(); |
| 692 if (!overflow_button_->visible()) { | 675 if (model_index <= last_visible_index_) { |
| 693 bounds_animator_->SetAnimationDelegate( | 676 bounds_animator_->SetAnimationDelegate( |
| 694 view, new StartFadeAnimationDelegate(this, view), true); | 677 view, new StartFadeAnimationDelegate(this, view), true); |
| 695 } | 678 } |
| 696 } | 679 } |
| 697 | 680 |
| 698 void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) { | 681 void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) { |
| 699 #if !defined(OS_MACOSX) | 682 #if !defined(OS_MACOSX) |
| 700 if (id == context_menu_id_) | 683 if (id == context_menu_id_) |
| 701 launcher_menu_runner_.reset(); | 684 launcher_menu_runner_.reset(); |
| 702 #endif | 685 #endif |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 source->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 871 source->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
| 889 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED) | 872 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED) |
| 890 return; | 873 return; |
| 891 | 874 |
| 892 Shell::GetInstance()->UpdateShelfVisibility(); | 875 Shell::GetInstance()->UpdateShelfVisibility(); |
| 893 #endif | 876 #endif |
| 894 } | 877 } |
| 895 | 878 |
| 896 } // namespace internal | 879 } // namespace internal |
| 897 } // namespace ash | 880 } // namespace ash |
| OLD | NEW |