| 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/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/launcher/app_list_button.h" | 10 #include "ash/launcher/app_list_button.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 303 |
| 304 const LauncherItems& items(model_->items()); | 304 const LauncherItems& items(model_->items()); |
| 305 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 305 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
| 306 views::View* child = CreateViewForItem(*i); | 306 views::View* child = CreateViewForItem(*i); |
| 307 child->SetPaintToLayer(true); | 307 child->SetPaintToLayer(true); |
| 308 view_model_->Add(child, static_cast<int>(i - items.begin())); | 308 view_model_->Add(child, static_cast<int>(i - items.begin())); |
| 309 AddChildView(child); | 309 AddChildView(child); |
| 310 } | 310 } |
| 311 UpdateFirstButtonPadding(); | 311 UpdateFirstButtonPadding(); |
| 312 LauncherStatusChanged(); | 312 LauncherStatusChanged(); |
| 313 |
| 313 overflow_button_ = new OverflowButton(this); | 314 overflow_button_ = new OverflowButton(this); |
| 314 overflow_button_->set_context_menu_controller(this); | 315 overflow_button_->set_context_menu_controller(this); |
| 315 ConfigureChildView(overflow_button_); | 316 ConfigureChildView(overflow_button_); |
| 316 AddChildView(overflow_button_); | 317 AddChildView(overflow_button_); |
| 317 | 318 |
| 318 // We'll layout when our bounds change. | 319 // We'll layout when our bounds change. |
| 319 } | 320 } |
| 320 | 321 |
| 321 void LauncherView::SetAlignment(ShelfAlignment alignment) { | 322 void LauncherView::SetAlignment(ShelfAlignment alignment) { |
| 322 if (alignment_ == alignment) | 323 if (alignment_ == alignment) |
| 323 return; | 324 return; |
| 324 alignment_ = alignment; | 325 alignment_ = alignment; |
| 325 UpdateFirstButtonPadding(); | 326 UpdateFirstButtonPadding(); |
| 326 overflow_button_->SetShelfAlignment(alignment_); | 327 overflow_button_->SetShelfAlignment(alignment_); |
| 327 LayoutToIdealBounds(); | 328 LayoutToIdealBounds(); |
| 328 tooltip_->SetArrowLocation(alignment_); | 329 tooltip_->SetArrowLocation(alignment_); |
| 329 if (overflow_bubble_.get()) | 330 if (overflow_bubble_.get()) |
| 330 overflow_bubble_->Hide(); | 331 overflow_bubble_->Hide(); |
| 331 } | 332 } |
| 332 | 333 |
| 333 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) { | 334 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) { |
| 334 int index = model_->ItemIndexByID(id); | 335 int index = model_->ItemIndexByID(id); |
| 335 if (index == -1 || (index > last_visible_index_ && | 336 if (index == -1 || index > last_visible_index_) |
| 336 index < model_->FirstPanelIndex())) | |
| 337 return gfx::Rect(); | 337 return gfx::Rect(); |
| 338 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); | 338 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); |
| 339 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); | 339 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); |
| 340 LauncherButton* button = | 340 LauncherButton* button = |
| 341 static_cast<LauncherButton*>(view_model_->view_at(index)); | 341 static_cast<LauncherButton*>(view_model_->view_at(index)); |
| 342 gfx::Rect icon_bounds = button->GetIconBounds(); | 342 gfx::Rect icon_bounds = button->GetIconBounds(); |
| 343 return gfx::Rect(ideal_bounds.x() + icon_bounds.x(), | 343 return gfx::Rect(ideal_bounds.x() + icon_bounds.x(), |
| 344 ideal_bounds.y() + icon_bounds.y(), | 344 ideal_bounds.y() + icon_bounds.y(), |
| 345 icon_bounds.width(), icon_bounds.height()); | 345 icon_bounds.width(), icon_bounds.height()); |
| 346 } | 346 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 if (bounds_animator_->IsAnimating()) | 389 if (bounds_animator_->IsAnimating()) |
| 390 AnimateToIdealBounds(); | 390 AnimateToIdealBounds(); |
| 391 else | 391 else |
| 392 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 392 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
| 393 | 393 |
| 394 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); | 394 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { | 397 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { |
| 398 int available_size = primary_axis_coordinate(width(), height()); | 398 int available_size = primary_axis_coordinate(width(), height()); |
| 399 int first_panel_index = model_->FirstPanelIndex(); | |
| 400 if (!available_size) | 399 if (!available_size) |
| 401 return; | 400 return; |
| 402 | 401 |
| 403 // Initial x,y values account both leading_inset in primary | 402 // Initial x,y values account both leading_inset in primary |
| 404 // coordinate and secondary coordinate based on the dynamic edge of the | 403 // coordinate and secondary coordinate based on the dynamic edge of the |
| 405 // launcher (eg top edge on bottom-aligned launcher). | 404 // launcher (eg top edge on bottom-aligned launcher). |
| 406 int x = alignment_based_value(leading_inset(), | 405 int x = alignment_based_value(leading_inset(), |
| 407 width() - kLauncherPreferredSize, | 406 width() - kLauncherPreferredSize, |
| 408 std::max(width() - kLauncherPreferredSize, | 407 std::max(width() - kLauncherPreferredSize, |
| 409 ShelfLayoutManager::kAutoHideSize + 1)); | 408 ShelfLayoutManager::kAutoHideSize + 1)); |
| 410 int y = primary_axis_coordinate(0, leading_inset()); | 409 int y = primary_axis_coordinate(0, leading_inset()); |
| 411 int w = primary_axis_coordinate(kLauncherPreferredSize, width()); | 410 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 412 int h = primary_axis_coordinate(height(), kLauncherPreferredSize); | |
| 413 for (int i = 0; i < first_panel_index; ++i) { | |
| 414 if (i < first_visible_index_) { | 411 if (i < first_visible_index_) { |
| 415 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); | 412 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); |
| 416 continue; | 413 continue; |
| 417 } | 414 } |
| 418 | 415 |
| 416 int w = primary_axis_coordinate(kLauncherPreferredSize, width()); |
| 417 int h = primary_axis_coordinate(height(), kLauncherPreferredSize); |
| 419 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 418 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
| 420 x = primary_axis_coordinate(x + w + kButtonSpacing, x); | 419 x = primary_axis_coordinate(x + w + kButtonSpacing, x); |
| 421 y = primary_axis_coordinate(y, y + h + kButtonSpacing); | 420 y = primary_axis_coordinate(y, y + h + kButtonSpacing); |
| 422 } | 421 } |
| 423 | 422 |
| 424 int app_list_index = first_panel_index - 1; | 423 int app_list_index = view_model_->view_size() - 1; |
| 425 if (is_overflow_mode()) { | 424 if (is_overflow_mode()) { |
| 426 last_visible_index_ = app_list_index - 1; | 425 last_visible_index_ = app_list_index - 1; |
| 427 for (int i = 0; i < view_model_->view_size(); ++i) { | 426 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 428 view_model_->view_at(i)->SetVisible( | 427 view_model_->view_at(i)->SetVisible( |
| 429 i >= first_visible_index_ && i <= last_visible_index_); | 428 i >= first_visible_index_ && i <= last_visible_index_); |
| 430 } | 429 } |
| 431 return; | 430 return; |
| 432 } | 431 } |
| 433 | 432 |
| 434 // Right aligned icons. | |
| 435 // TODO(flackr): The right aligned icons may not fit in the launcher in which | |
| 436 // case they should be moved to an overflow bubble. See | |
| 437 // http://crbug.com/162558 for panel overflow details. | |
| 438 int end_position = available_size - kButtonSpacing; | |
| 439 x = primary_axis_coordinate(end_position, leading_inset()); | |
| 440 y = primary_axis_coordinate(0, end_position); | |
| 441 for (int i = view_model_->view_size() - 1; | |
| 442 i >= first_panel_index; --i) { | |
| 443 x = primary_axis_coordinate(x - w - kButtonSpacing, x); | |
| 444 y = primary_axis_coordinate(y, y - h - kButtonSpacing); | |
| 445 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | |
| 446 end_position = primary_axis_coordinate(x, y); | |
| 447 } | |
| 448 | |
| 449 bounds->overflow_bounds.set_size(gfx::Size( | 433 bounds->overflow_bounds.set_size(gfx::Size( |
| 450 primary_axis_coordinate(kLauncherPreferredSize, width()), | 434 primary_axis_coordinate(kLauncherPreferredSize, width()), |
| 451 primary_axis_coordinate(height(), kLauncherPreferredSize))); | 435 primary_axis_coordinate(height(), kLauncherPreferredSize))); |
| 452 last_visible_index_ = DetermineLastVisibleIndex( | 436 last_visible_index_ = DetermineLastVisibleIndex( |
| 453 end_position - leading_inset() - 2 * kLauncherPreferredSize); | 437 available_size - leading_inset() - kLauncherPreferredSize - |
| 438 kButtonSpacing - kLauncherPreferredSize); |
| 454 bool show_overflow = (last_visible_index_ + 1 < app_list_index); | 439 bool show_overflow = (last_visible_index_ + 1 < app_list_index); |
| 455 | 440 |
| 456 for (int i = 0; i < view_model_->view_size(); ++i) { | 441 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 457 view_model_->view_at(i)->SetVisible( | 442 view_model_->view_at(i)->SetVisible( |
| 458 i <= last_visible_index_ || i >= app_list_index); | 443 i == app_list_index || i <= last_visible_index_); |
| 459 } | 444 } |
| 460 | 445 |
| 461 overflow_button_->SetVisible(show_overflow); | 446 overflow_button_->SetVisible(show_overflow); |
| 462 if (show_overflow) { | 447 if (show_overflow) { |
| 463 DCHECK_NE(0, view_model_->view_size()); | 448 DCHECK_NE(0, view_model_->view_size()); |
| 464 if (last_visible_index_ == -1) { | 449 if (last_visible_index_ == -1) { |
| 465 x = alignment_based_value(leading_inset(), | 450 x = alignment_based_value(leading_inset(), |
| 466 width() - kLauncherPreferredSize, | 451 width() - kLauncherPreferredSize, |
| 467 std::max(width() - kLauncherPreferredSize, | 452 std::max(width() - kLauncherPreferredSize, |
| 468 ShelfLayoutManager::kAutoHideSize + 1)); | 453 ShelfLayoutManager::kAutoHideSize + 1)); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 595 |
| 611 // If the item is no longer draggable, bail out. | 596 // If the item is no longer draggable, bail out. |
| 612 if (current_index == -1 || | 597 if (current_index == -1 || |
| 613 !delegate_->IsDraggable(model_->items()[current_index])) { | 598 !delegate_->IsDraggable(model_->items()[current_index])) { |
| 614 CancelDrag(-1); | 599 CancelDrag(-1); |
| 615 return; | 600 return; |
| 616 } | 601 } |
| 617 | 602 |
| 618 // Constrain the location to the range of valid indices for the type. | 603 // Constrain the location to the range of valid indices for the type. |
| 619 std::pair<int, int> indices(GetDragRange(current_index)); | 604 std::pair<int, int> indices(GetDragRange(current_index)); |
| 620 int first_drag_index = indices.first; | |
| 621 int last_drag_index = indices.second; | 605 int last_drag_index = indices.second; |
| 622 // If the last index isn't valid, we're overflowing. Constrain to the app list | 606 // If the last index isn't valid, we're overflowing. Constrain to the app list |
| 623 // (which is the last visible item). | 607 // (which is the last visible item). |
| 624 if (first_drag_index < model_->FirstPanelIndex() && | 608 if (last_drag_index > last_visible_index_) |
| 625 last_drag_index > last_visible_index_) | |
| 626 last_drag_index = last_visible_index_; | 609 last_drag_index = last_visible_index_; |
| 627 int x = 0, y = 0; | 610 int x = 0, y = 0; |
| 628 if (is_horizontal_alignment()) { | 611 if (is_horizontal_alignment()) { |
| 629 x = std::max(view_model_->ideal_bounds(indices.first).x(), | 612 x = std::max(view_model_->ideal_bounds(indices.first).x(), |
| 630 drag_point.x() - drag_offset_); | 613 drag_point.x() - drag_offset_); |
| 631 x = std::min(view_model_->ideal_bounds(last_drag_index).right() - | 614 x = std::min(view_model_->ideal_bounds(last_drag_index).right() - |
| 632 view_model_->ideal_bounds(current_index).width(), | 615 view_model_->ideal_bounds(current_index).width(), |
| 633 x); | 616 x); |
| 634 if (drag_view_->x() == x) | 617 if (drag_view_->x() == x) |
| 635 return; | 618 return; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 660 // Change the model, the LauncherItemMoved() callback will handle the | 643 // Change the model, the LauncherItemMoved() callback will handle the |
| 661 // |view_model_| update. | 644 // |view_model_| update. |
| 662 model_->Move(current_index, target_index); | 645 model_->Move(current_index, target_index); |
| 663 bounds_animator_->StopAnimatingView(drag_view_); | 646 bounds_animator_->StopAnimatingView(drag_view_); |
| 664 } | 647 } |
| 665 | 648 |
| 666 bool LauncherView::SameDragType(LauncherItemType typea, | 649 bool LauncherView::SameDragType(LauncherItemType typea, |
| 667 LauncherItemType typeb) const { | 650 LauncherItemType typeb) const { |
| 668 switch (typea) { | 651 switch (typea) { |
| 669 case TYPE_TABBED: | 652 case TYPE_TABBED: |
| 653 case TYPE_APP_PANEL: |
| 670 case TYPE_PLATFORM_APP: | 654 case TYPE_PLATFORM_APP: |
| 671 return (typeb == TYPE_TABBED || typeb == TYPE_PLATFORM_APP); | 655 return (typeb == TYPE_TABBED || |
| 656 typeb == TYPE_APP_PANEL || |
| 657 typeb == TYPE_PLATFORM_APP); |
| 672 case TYPE_APP_SHORTCUT: | 658 case TYPE_APP_SHORTCUT: |
| 673 case TYPE_APP_LIST: | 659 case TYPE_APP_LIST: |
| 674 case TYPE_APP_PANEL: | |
| 675 case TYPE_BROWSER_SHORTCUT: | 660 case TYPE_BROWSER_SHORTCUT: |
| 676 return typeb == typea; | 661 return typeb == typea; |
| 677 } | 662 } |
| 678 NOTREACHED(); | 663 NOTREACHED(); |
| 679 return false; | 664 return false; |
| 680 } | 665 } |
| 681 | 666 |
| 682 std::pair<int, int> LauncherView::GetDragRange(int index) { | 667 std::pair<int, int> LauncherView::GetDragRange(int index) { |
| 683 int min_index = -1; | 668 int min_index = -1; |
| 684 int max_index = -1; | 669 int max_index = -1; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 // spot (because it was in the middle of animating from 0,0 0x0 to its | 808 // spot (because it was in the middle of animating from 0,0 0x0 to its |
| 824 // target). | 809 // target). |
| 825 IdealBounds ideal_bounds; | 810 IdealBounds ideal_bounds; |
| 826 CalculateIdealBounds(&ideal_bounds); | 811 CalculateIdealBounds(&ideal_bounds); |
| 827 view->SetBoundsRect(view_model_->ideal_bounds(model_index)); | 812 view->SetBoundsRect(view_model_->ideal_bounds(model_index)); |
| 828 | 813 |
| 829 // The first animation moves all the views to their target position. |view| | 814 // The first animation moves all the views to their target position. |view| |
| 830 // is hidden, so it visually appears as though we are providing space for | 815 // is hidden, so it visually appears as though we are providing space for |
| 831 // it. When done we'll fade the view in. | 816 // it. When done we'll fade the view in. |
| 832 AnimateToIdealBounds(); | 817 AnimateToIdealBounds(); |
| 833 if (model_index <= last_visible_index_ || | 818 if (model_index <= last_visible_index_) { |
| 834 model_index >= model_->FirstPanelIndex()) { | |
| 835 bounds_animator_->SetAnimationDelegate( | 819 bounds_animator_->SetAnimationDelegate( |
| 836 view, new StartFadeAnimationDelegate(this, view), true); | 820 view, new StartFadeAnimationDelegate(this, view), true); |
| 837 } else { | 821 } else { |
| 838 // Undo the hiding if animation does not run. | 822 // Undo the hiding if animation does not run. |
| 839 view->layer()->SetOpacity(1.0f); | 823 view->layer()->SetOpacity(1.0f); |
| 840 } | 824 } |
| 841 } | 825 } |
| 842 | 826 |
| 843 void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) { | 827 void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) { |
| 844 #if !defined(OS_MACOSX) | 828 #if !defined(OS_MACOSX) |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, | 1087 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
| 1104 OnLauncherIconPositionsChanged()); | 1088 OnLauncherIconPositionsChanged()); |
| 1105 PreferredSizeChanged(); | 1089 PreferredSizeChanged(); |
| 1106 } | 1090 } |
| 1107 | 1091 |
| 1108 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 1092 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
| 1109 } | 1093 } |
| 1110 | 1094 |
| 1111 } // namespace internal | 1095 } // namespace internal |
| 1112 } // namespace ash | 1096 } // namespace ash |
| OLD | NEW |