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