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/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_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/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 void ShelfView::Init() { | 421 void ShelfView::Init() { |
422 model_->AddObserver(this); | 422 model_->AddObserver(this); |
423 | 423 |
424 const LauncherItems& items(model_->items()); | 424 const LauncherItems& items(model_->items()); |
425 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 425 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
426 views::View* child = CreateViewForItem(*i); | 426 views::View* child = CreateViewForItem(*i); |
427 child->SetPaintToLayer(true); | 427 child->SetPaintToLayer(true); |
428 view_model_->Add(child, static_cast<int>(i - items.begin())); | 428 view_model_->Add(child, static_cast<int>(i - items.begin())); |
429 AddChildView(child); | 429 AddChildView(child); |
430 } | 430 } |
431 LauncherStatusChanged(); | 431 ShelfStatusChanged(); |
432 overflow_button_ = new OverflowButton(this); | 432 overflow_button_ = new OverflowButton(this); |
433 overflow_button_->set_context_menu_controller(this); | 433 overflow_button_->set_context_menu_controller(this); |
434 ConfigureChildView(overflow_button_); | 434 ConfigureChildView(overflow_button_); |
435 AddChildView(overflow_button_); | 435 AddChildView(overflow_button_); |
436 UpdateFirstButtonPadding(); | 436 UpdateFirstButtonPadding(); |
437 | 437 |
438 // We'll layout when our bounds change. | 438 // We'll layout when our bounds change. |
439 } | 439 } |
440 | 440 |
441 void ShelfView::OnShelfAlignmentChanged() { | 441 void ShelfView::OnShelfAlignmentChanged() { |
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 void ShelfView::GetAccessibleState(ui::AccessibleViewState* state) { | 1383 void ShelfView::GetAccessibleState(ui::AccessibleViewState* state) { |
1384 state->role = ui::AccessibilityTypes::ROLE_TOOLBAR; | 1384 state->role = ui::AccessibilityTypes::ROLE_TOOLBAR; |
1385 state->name = l10n_util::GetStringUTF16(IDS_ASH_SHELF_ACCESSIBLE_NAME); | 1385 state->name = l10n_util::GetStringUTF16(IDS_ASH_SHELF_ACCESSIBLE_NAME); |
1386 } | 1386 } |
1387 | 1387 |
1388 void ShelfView::OnGestureEvent(ui::GestureEvent* event) { | 1388 void ShelfView::OnGestureEvent(ui::GestureEvent* event) { |
1389 if (gesture_handler_.ProcessGestureEvent(*event)) | 1389 if (gesture_handler_.ProcessGestureEvent(*event)) |
1390 event->StopPropagation(); | 1390 event->StopPropagation(); |
1391 } | 1391 } |
1392 | 1392 |
1393 void ShelfView::LauncherItemAdded(int model_index) { | 1393 void ShelfView::ShelfItemAdded(int model_index) { |
1394 { | 1394 { |
1395 base::AutoReset<bool> cancelling_drag( | 1395 base::AutoReset<bool> cancelling_drag( |
1396 &cancelling_drag_model_changed_, true); | 1396 &cancelling_drag_model_changed_, true); |
1397 model_index = CancelDrag(model_index); | 1397 model_index = CancelDrag(model_index); |
1398 } | 1398 } |
1399 views::View* view = CreateViewForItem(model_->items()[model_index]); | 1399 views::View* view = CreateViewForItem(model_->items()[model_index]); |
1400 AddChildView(view); | 1400 AddChildView(view); |
1401 // Hide the view, it'll be made visible when the animation is done. Using | 1401 // Hide the view, it'll be made visible when the animation is done. Using |
1402 // opacity 0 here to avoid messing with CalculateIdealBounds which touches | 1402 // opacity 0 here to avoid messing with CalculateIdealBounds which touches |
1403 // the view's visibility. | 1403 // the view's visibility. |
(...skipping 15 matching lines...) Expand all Loading... |
1419 if (model_index <= last_visible_index_ || | 1419 if (model_index <= last_visible_index_ || |
1420 model_index >= model_->FirstPanelIndex()) { | 1420 model_index >= model_->FirstPanelIndex()) { |
1421 bounds_animator_->SetAnimationDelegate( | 1421 bounds_animator_->SetAnimationDelegate( |
1422 view, new StartFadeAnimationDelegate(this, view), true); | 1422 view, new StartFadeAnimationDelegate(this, view), true); |
1423 } else { | 1423 } else { |
1424 // Undo the hiding if animation does not run. | 1424 // Undo the hiding if animation does not run. |
1425 view->layer()->SetOpacity(1.0f); | 1425 view->layer()->SetOpacity(1.0f); |
1426 } | 1426 } |
1427 } | 1427 } |
1428 | 1428 |
1429 void ShelfView::LauncherItemRemoved(int model_index, LauncherID id) { | 1429 void ShelfView::ShelfItemRemoved(int model_index, LauncherID id) { |
1430 if (id == context_menu_id_) | 1430 if (id == context_menu_id_) |
1431 launcher_menu_runner_.reset(); | 1431 launcher_menu_runner_.reset(); |
1432 { | 1432 { |
1433 base::AutoReset<bool> cancelling_drag( | 1433 base::AutoReset<bool> cancelling_drag( |
1434 &cancelling_drag_model_changed_, true); | 1434 &cancelling_drag_model_changed_, true); |
1435 model_index = CancelDrag(model_index); | 1435 model_index = CancelDrag(model_index); |
1436 } | 1436 } |
1437 views::View* view = view_model_->view_at(model_index); | 1437 views::View* view = view_model_->view_at(model_index); |
1438 view_model_->Remove(model_index); | 1438 view_model_->Remove(model_index); |
1439 | 1439 |
(...skipping 19 matching lines...) Expand all Loading... |
1459 // item is ripped out from the shelf, its |view| is already invisible. | 1459 // item is ripped out from the shelf, its |view| is already invisible. |
1460 AnimateToIdealBounds(); | 1460 AnimateToIdealBounds(); |
1461 } | 1461 } |
1462 | 1462 |
1463 // Close the tooltip because it isn't needed any longer and its anchor view | 1463 // Close the tooltip because it isn't needed any longer and its anchor view |
1464 // will be deleted soon. | 1464 // will be deleted soon. |
1465 if (tooltip_->GetCurrentAnchorView() == view) | 1465 if (tooltip_->GetCurrentAnchorView() == view) |
1466 tooltip_->Close(); | 1466 tooltip_->Close(); |
1467 } | 1467 } |
1468 | 1468 |
1469 void ShelfView::LauncherItemChanged(int model_index, | 1469 void ShelfView::ShelfItemChanged(int model_index, |
1470 const ash::LauncherItem& old_item) { | 1470 const LauncherItem& old_item) { |
1471 const LauncherItem& item(model_->items()[model_index]); | 1471 const LauncherItem& item(model_->items()[model_index]); |
1472 if (old_item.type != item.type) { | 1472 if (old_item.type != item.type) { |
1473 // Type changed, swap the views. | 1473 // Type changed, swap the views. |
1474 model_index = CancelDrag(model_index); | 1474 model_index = CancelDrag(model_index); |
1475 scoped_ptr<views::View> old_view(view_model_->view_at(model_index)); | 1475 scoped_ptr<views::View> old_view(view_model_->view_at(model_index)); |
1476 bounds_animator_->StopAnimatingView(old_view.get()); | 1476 bounds_animator_->StopAnimatingView(old_view.get()); |
1477 // Removing and re-inserting a view in our view model will strip the ideal | 1477 // Removing and re-inserting a view in our view model will strip the ideal |
1478 // bounds from the item. To avoid recalculation of everything the bounds | 1478 // bounds from the item. To avoid recalculation of everything the bounds |
1479 // get remembered and restored after the insertion to the previous value. | 1479 // get remembered and restored after the insertion to the previous value. |
1480 gfx::Rect old_ideal_bounds = view_model_->ideal_bounds(model_index); | 1480 gfx::Rect old_ideal_bounds = view_model_->ideal_bounds(model_index); |
(...skipping 23 matching lines...) Expand all Loading... |
1504 button->SetImage(item.image); | 1504 button->SetImage(item.image); |
1505 button->SchedulePaint(); | 1505 button->SchedulePaint(); |
1506 break; | 1506 break; |
1507 } | 1507 } |
1508 | 1508 |
1509 default: | 1509 default: |
1510 break; | 1510 break; |
1511 } | 1511 } |
1512 } | 1512 } |
1513 | 1513 |
1514 void ShelfView::LauncherItemMoved(int start_index, int target_index) { | 1514 void ShelfView::ShelfItemMoved(int start_index, int target_index) { |
1515 view_model_->Move(start_index, target_index); | 1515 view_model_->Move(start_index, target_index); |
1516 // When cancelling a drag due to a launcher item being added, the currently | 1516 // When cancelling a drag due to a launcher item being added, the currently |
1517 // dragged item is moved back to its initial position. AnimateToIdealBounds | 1517 // dragged item is moved back to its initial position. AnimateToIdealBounds |
1518 // will be called again when the new item is added to the |view_model_| but | 1518 // will be called again when the new item is added to the |view_model_| but |
1519 // at this time the |view_model_| is inconsistent with the |model_|. | 1519 // at this time the |view_model_| is inconsistent with the |model_|. |
1520 if (!cancelling_drag_model_changed_) | 1520 if (!cancelling_drag_model_changed_) |
1521 AnimateToIdealBounds(); | 1521 AnimateToIdealBounds(); |
1522 } | 1522 } |
1523 | 1523 |
1524 void ShelfView::LauncherStatusChanged() { | 1524 void ShelfView::ShelfStatusChanged() { |
1525 if (ash::switches::UseAlternateShelfLayout()) | 1525 if (ash::switches::UseAlternateShelfLayout()) |
1526 return; | 1526 return; |
1527 AppListButton* app_list_button = | 1527 AppListButton* app_list_button = |
1528 static_cast<AppListButton*>(GetAppListButtonView()); | 1528 static_cast<AppListButton*>(GetAppListButtonView()); |
1529 if (model_->status() == LauncherModel::STATUS_LOADING) | 1529 if (model_->status() == LauncherModel::STATUS_LOADING) |
1530 app_list_button->StartLoadingAnimation(); | 1530 app_list_button->StartLoadingAnimation(); |
1531 else | 1531 else |
1532 app_list_button->StopLoadingAnimation(); | 1532 app_list_button->StopLoadingAnimation(); |
1533 } | 1533 } |
1534 | 1534 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1899 break; | 1899 break; |
1900 case ash::SHELF_ALIGNMENT_TOP: | 1900 case ash::SHELF_ALIGNMENT_TOP: |
1901 distance = coordinate.y() - bounds.bottom(); | 1901 distance = coordinate.y() - bounds.bottom(); |
1902 break; | 1902 break; |
1903 } | 1903 } |
1904 return distance > 0 ? distance : 0; | 1904 return distance > 0 ? distance : 0; |
1905 } | 1905 } |
1906 | 1906 |
1907 } // namespace internal | 1907 } // namespace internal |
1908 } // namespace ash | 1908 } // namespace ash |
OLD | NEW |