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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/launcher/app_list_button.h" | 9 #include "ash/launcher/app_list_button.h" |
10 #include "ash/launcher/launcher_button.h" | 10 #include "ash/launcher/launcher_button.h" |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); | 386 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); |
387 continue; | 387 continue; |
388 } | 388 } |
389 | 389 |
390 view_model_->set_ideal_bounds(i, gfx::Rect( | 390 view_model_->set_ideal_bounds(i, gfx::Rect( |
391 x, y, kLauncherPreferredSize, kLauncherPreferredSize)); | 391 x, y, kLauncherPreferredSize, kLauncherPreferredSize)); |
392 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, 0); | 392 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, 0); |
393 y = primary_axis_coordinate(0, y + kLauncherPreferredSize + kButtonSpacing); | 393 y = primary_axis_coordinate(0, y + kLauncherPreferredSize + kButtonSpacing); |
394 } | 394 } |
395 | 395 |
396 int app_list_index = view_model_->view_size() - 1; | 396 int last_view_index = view_model_->view_size() - 1; |
397 if (is_overflow_mode()) { | 397 if (is_overflow_mode()) { |
398 last_visible_index_ = app_list_index - 1; | 398 last_visible_index_ = last_view_index; |
399 for (int i = 0; i < view_model_->view_size(); ++i) { | 399 for (int i = 0; i < view_model_->view_size(); ++i) { |
400 view_model_->view_at(i)->SetVisible( | 400 view_model_->view_at(i)->SetVisible( |
401 i >= first_visible_index_ && i <= last_visible_index_); | 401 i >= first_visible_index_ && i <= last_visible_index_); |
402 } | 402 } |
403 return; | 403 return; |
404 } | 404 } |
405 | 405 |
406 if (view_model_->view_size() > 0) { | 406 if (view_model_->view_size() > 0) { |
407 // Makes the first launcher button include the leading inset. | 407 // Makes the first launcher button include the leading inset. |
408 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size( | 408 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size( |
409 primary_axis_coordinate(leading_inset() + kLauncherPreferredSize, | 409 primary_axis_coordinate(leading_inset() + kLauncherPreferredSize, |
410 kLauncherPreferredSize), | 410 kLauncherPreferredSize), |
411 primary_axis_coordinate(kLauncherPreferredSize, | 411 primary_axis_coordinate(kLauncherPreferredSize, |
412 leading_inset() + kLauncherPreferredSize)))); | 412 leading_inset() + kLauncherPreferredSize)))); |
413 } | 413 } |
414 | 414 |
415 bounds->overflow_bounds.set_size( | 415 bounds->overflow_bounds.set_size( |
416 gfx::Size(kLauncherPreferredSize, kLauncherPreferredSize)); | 416 gfx::Size(kLauncherPreferredSize, kLauncherPreferredSize)); |
417 last_visible_index_ = DetermineLastVisibleIndex( | 417 last_visible_index_ = DetermineLastVisibleIndex( |
418 available_size - leading_inset() - kLauncherPreferredSize - | 418 available_size - leading_inset() - kLauncherPreferredSize - |
419 kButtonSpacing - kLauncherPreferredSize); | 419 kButtonSpacing - kLauncherPreferredSize); |
420 bool show_overflow = (last_visible_index_ + 1 < app_list_index); | 420 bool show_overflow = (last_visible_index_ < last_view_index); |
421 | 421 |
422 for (int i = 0; i < view_model_->view_size(); ++i) { | 422 for (int i = 0; i < view_model_->view_size(); ++i) { |
423 view_model_->view_at(i)->SetVisible( | 423 view_model_->view_at(i)->SetVisible(i <= last_visible_index_); |
424 i == app_list_index || i <= last_visible_index_); | |
425 } | 424 } |
426 | 425 |
427 overflow_button_->SetVisible(show_overflow); | 426 overflow_button_->SetVisible(show_overflow); |
428 if (show_overflow) { | 427 if (show_overflow) { |
429 DCHECK_NE(0, view_model_->view_size()); | 428 DCHECK_NE(0, view_model_->view_size()); |
430 if (last_visible_index_ == -1) { | 429 if (last_visible_index_ == -1) { |
431 x = primary_axis_coordinate(leading_inset(), 0); | 430 x = primary_axis_coordinate(leading_inset(), 0); |
432 y = primary_axis_coordinate(0, leading_inset()); | 431 y = primary_axis_coordinate(0, leading_inset()); |
433 } else { | 432 } else { |
434 x = primary_axis_coordinate( | 433 x = primary_axis_coordinate( |
435 view_model_->ideal_bounds(last_visible_index_).right(), 0); | 434 view_model_->ideal_bounds(last_visible_index_).right(), 0); |
436 y = primary_axis_coordinate(0, | 435 y = primary_axis_coordinate(0, |
437 view_model_->ideal_bounds(last_visible_index_).bottom()); | 436 view_model_->ideal_bounds(last_visible_index_).bottom()); |
438 } | 437 } |
439 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); | |
440 bounds->overflow_bounds.set_x(x); | 438 bounds->overflow_bounds.set_x(x); |
441 bounds->overflow_bounds.set_y(y); | 439 bounds->overflow_bounds.set_y(y); |
442 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, 0); | |
443 y = primary_axis_coordinate(0, y + kLauncherPreferredSize + kButtonSpacing); | |
444 app_list_bounds.set_x(x); | |
445 app_list_bounds.set_y(y); | |
446 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); | |
447 } else { | 440 } else { |
448 if (overflow_bubble_.get()) | 441 if (overflow_bubble_.get()) |
449 overflow_bubble_->Hide(); | 442 overflow_bubble_->Hide(); |
450 } | 443 } |
451 } | 444 } |
452 | 445 |
453 int LauncherView::DetermineLastVisibleIndex(int max_value) { | 446 int LauncherView::DetermineLastVisibleIndex(int max_value) { |
454 int index = view_model_->view_size() - 1; | 447 int index = view_model_->view_size() - 1; |
455 while (index >= 0 && | 448 while (index >= 0 && |
456 primary_axis_coordinate( | 449 primary_axis_coordinate( |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 drag_pointer_ = NONE; | 708 drag_pointer_ = NONE; |
716 drag_view_ = NULL; | 709 drag_view_ = NULL; |
717 if (drag_view_index == modified_index) { | 710 if (drag_view_index == modified_index) { |
718 // The view that was being dragged is being modified. Don't do anything. | 711 // The view that was being dragged is being modified. Don't do anything. |
719 return modified_index; | 712 return modified_index; |
720 } | 713 } |
721 if (!was_dragging) | 714 if (!was_dragging) |
722 return modified_index; | 715 return modified_index; |
723 | 716 |
724 // Restore previous position, tracking the position of the modified view. | 717 // Restore previous position, tracking the position of the modified view. |
| 718 model_->Move(drag_view_index, start_drag_index_); |
| 719 |
| 720 // Adding a new view at end. |
| 721 if (modified_index == view_model_->view_size()) |
| 722 return modified_index; |
| 723 |
725 views::View* removed_view = | 724 views::View* removed_view = |
726 (modified_index >= 0) ? view_model_->view_at(modified_index) : NULL; | 725 (modified_index >= 0) ? view_model_->view_at(modified_index) : NULL; |
727 model_->Move(drag_view_index, start_drag_index_); | |
728 return removed_view ? view_model_->GetIndexOfView(removed_view) : -1; | 726 return removed_view ? view_model_->GetIndexOfView(removed_view) : -1; |
729 } | 727 } |
730 | 728 |
731 gfx::Size LauncherView::GetPreferredSize() { | 729 gfx::Size LauncherView::GetPreferredSize() { |
732 IdealBounds ideal_bounds; | 730 IdealBounds ideal_bounds; |
733 CalculateIdealBounds(&ideal_bounds); | 731 CalculateIdealBounds(&ideal_bounds); |
734 | 732 |
735 const int app_list_index = view_model_->view_size() - 1; | |
736 const int last_button_index = is_overflow_mode() ? | |
737 last_visible_index_ : app_list_index; | |
738 const gfx::Rect last_button_bounds = | 733 const gfx::Rect last_button_bounds = |
739 last_button_index >= first_visible_index_ ? | 734 last_visible_index_ >= first_visible_index_ ? |
740 view_model_->view_at(last_button_index)->bounds() : | 735 view_model_->view_at(last_visible_index_)->bounds() : |
741 gfx::Rect(gfx::Size(kLauncherPreferredSize, | 736 gfx::Rect(gfx::Size(kLauncherPreferredSize, |
742 kLauncherPreferredSize)); | 737 kLauncherPreferredSize)); |
743 | 738 |
744 if (is_horizontal_alignment()) { | 739 if (is_horizontal_alignment()) { |
745 return gfx::Size(last_button_bounds.right() + leading_inset(), | 740 return gfx::Size(last_button_bounds.right() + leading_inset(), |
746 kLauncherPreferredSize); | 741 kLauncherPreferredSize); |
747 } | 742 } |
748 | 743 |
749 return gfx::Size(kLauncherPreferredSize, | 744 return gfx::Size(kLauncherPreferredSize, |
750 last_button_bounds.bottom() + leading_inset()); | 745 last_button_bounds.bottom() + leading_inset()); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, | 1063 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
1069 OnLauncherIconPositionsChanged()); | 1064 OnLauncherIconPositionsChanged()); |
1070 PreferredSizeChanged(); | 1065 PreferredSizeChanged(); |
1071 } | 1066 } |
1072 | 1067 |
1073 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 1068 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
1074 } | 1069 } |
1075 | 1070 |
1076 } // namespace internal | 1071 } // namespace internal |
1077 } // namespace ash | 1072 } // namespace ash |
OLD | NEW |