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); | 438 gfx::Rect last_view_bounds = view_model_->ideal_bounds(last_view_index); |
440 bounds->overflow_bounds.set_x(x); | 439 bounds->overflow_bounds.set_x(x); |
441 bounds->overflow_bounds.set_y(y); | 440 bounds->overflow_bounds.set_y(y); |
442 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, 0); | 441 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, 0); |
443 y = primary_axis_coordinate(0, y + kLauncherPreferredSize + kButtonSpacing); | 442 y = primary_axis_coordinate(0, y + kLauncherPreferredSize + kButtonSpacing); |
444 app_list_bounds.set_x(x); | 443 last_view_bounds.set_x(x); |
445 app_list_bounds.set_y(y); | 444 last_view_bounds.set_y(y); |
446 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); | 445 view_model_->set_ideal_bounds(last_view_index, last_view_bounds); |
sky
2012/09/11 00:18:32
Is this code needed anymore (438 and 441-445)? It
DaveMoore
2012/09/11 17:07:00
Removed
On 2012/09/11 00:18:32, sky wrote:
| |
447 } else { | 446 } else { |
448 if (overflow_bubble_.get()) | 447 if (overflow_bubble_.get()) |
449 overflow_bubble_->Hide(); | 448 overflow_bubble_->Hide(); |
450 } | 449 } |
451 } | 450 } |
452 | 451 |
453 int LauncherView::DetermineLastVisibleIndex(int max_value) { | 452 int LauncherView::DetermineLastVisibleIndex(int max_value) { |
454 int index = view_model_->view_size() - 1; | 453 int index = view_model_->view_size() - 1; |
455 while (index >= 0 && | 454 while (index >= 0 && |
456 primary_axis_coordinate( | 455 primary_axis_coordinate( |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
715 drag_pointer_ = NONE; | 714 drag_pointer_ = NONE; |
716 drag_view_ = NULL; | 715 drag_view_ = NULL; |
717 if (drag_view_index == modified_index) { | 716 if (drag_view_index == modified_index) { |
718 // The view that was being dragged is being modified. Don't do anything. | 717 // The view that was being dragged is being modified. Don't do anything. |
719 return modified_index; | 718 return modified_index; |
720 } | 719 } |
721 if (!was_dragging) | 720 if (!was_dragging) |
722 return modified_index; | 721 return modified_index; |
723 | 722 |
724 // Restore previous position, tracking the position of the modified view. | 723 // Restore previous position, tracking the position of the modified view. |
724 model_->Move(drag_view_index, start_drag_index_); | |
725 | |
726 // Adding a new view. | |
727 if (modified_index == view_model_->view_size()) | |
sky
2012/09/11 00:18:32
Your comment implies that if 727 is true then we'r
DaveMoore
2012/09/11 17:07:00
Updated comment. There's a case that existed befor
Mattias Nissler (ping if slow)
2012/09/12 12:08:18
I fail to follow the case you're describing. If we
| |
728 return modified_index; | |
729 | |
725 views::View* removed_view = | 730 views::View* removed_view = |
726 (modified_index >= 0) ? view_model_->view_at(modified_index) : NULL; | 731 (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; | 732 return removed_view ? view_model_->GetIndexOfView(removed_view) : -1; |
729 } | 733 } |
730 | 734 |
731 gfx::Size LauncherView::GetPreferredSize() { | 735 gfx::Size LauncherView::GetPreferredSize() { |
732 IdealBounds ideal_bounds; | 736 IdealBounds ideal_bounds; |
733 CalculateIdealBounds(&ideal_bounds); | 737 CalculateIdealBounds(&ideal_bounds); |
734 | 738 |
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 = | 739 const gfx::Rect last_button_bounds = |
739 last_button_index >= first_visible_index_ ? | 740 last_visible_index_ >= first_visible_index_ ? |
740 view_model_->view_at(last_button_index)->bounds() : | 741 view_model_->view_at(last_visible_index_)->bounds() : |
741 gfx::Rect(gfx::Size(kLauncherPreferredSize, | 742 gfx::Rect(gfx::Size(kLauncherPreferredSize, |
742 kLauncherPreferredSize)); | 743 kLauncherPreferredSize)); |
743 | 744 |
744 if (is_horizontal_alignment()) { | 745 if (is_horizontal_alignment()) { |
745 return gfx::Size(last_button_bounds.right() + leading_inset(), | 746 return gfx::Size(last_button_bounds.right() + leading_inset(), |
746 kLauncherPreferredSize); | 747 kLauncherPreferredSize); |
747 } | 748 } |
748 | 749 |
749 return gfx::Size(kLauncherPreferredSize, | 750 return gfx::Size(kLauncherPreferredSize, |
750 last_button_bounds.bottom() + leading_inset()); | 751 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_, | 1069 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
1069 OnLauncherIconPositionsChanged()); | 1070 OnLauncherIconPositionsChanged()); |
1070 PreferredSizeChanged(); | 1071 PreferredSizeChanged(); |
1071 } | 1072 } |
1072 | 1073 |
1073 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 1074 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
1074 } | 1075 } |
1075 | 1076 |
1076 } // namespace internal | 1077 } // namespace internal |
1077 } // namespace ash | 1078 } // namespace ash |
OLD | NEW |