Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1142)

Side by Side Diff: ash/shelf/shelf_view.cc

Issue 71653003: ash: Rename LauncherModel to ShelfModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: chrome changes Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ash/drag_drop/drag_image_view.h" 11 #include "ash/drag_drop/drag_image_view.h"
12 #include "ash/launcher/launcher_button.h" 12 #include "ash/launcher/launcher_button.h"
13 #include "ash/launcher/launcher_delegate.h" 13 #include "ash/launcher/launcher_delegate.h"
14 #include "ash/launcher/launcher_item_delegate.h" 14 #include "ash/launcher/launcher_item_delegate.h"
15 #include "ash/launcher/launcher_item_delegate_manager.h" 15 #include "ash/launcher/launcher_item_delegate_manager.h"
16 #include "ash/launcher/launcher_model.h"
17 #include "ash/root_window_controller.h" 16 #include "ash/root_window_controller.h"
18 #include "ash/scoped_target_root_window.h" 17 #include "ash/scoped_target_root_window.h"
19 #include "ash/shelf/alternate_app_list_button.h" 18 #include "ash/shelf/alternate_app_list_button.h"
20 #include "ash/shelf/app_list_button.h" 19 #include "ash/shelf/app_list_button.h"
21 #include "ash/shelf/overflow_bubble.h" 20 #include "ash/shelf/overflow_bubble.h"
22 #include "ash/shelf/overflow_button.h" 21 #include "ash/shelf/overflow_button.h"
23 #include "ash/shelf/shelf_icon_observer.h" 22 #include "ash/shelf/shelf_icon_observer.h"
24 #include "ash/shelf/shelf_layout_manager.h" 23 #include "ash/shelf/shelf_layout_manager.h"
24 #include "ash/shelf/shelf_model.h"
25 #include "ash/shelf/shelf_tooltip_manager.h" 25 #include "ash/shelf/shelf_tooltip_manager.h"
26 #include "ash/shelf/shelf_widget.h" 26 #include "ash/shelf/shelf_widget.h"
27 #include "ash/shell_delegate.h" 27 #include "ash/shell_delegate.h"
28 #include "base/auto_reset.h" 28 #include "base/auto_reset.h"
29 #include "base/memory/scoped_ptr.h" 29 #include "base/memory/scoped_ptr.h"
30 #include "grit/ash_resources.h" 30 #include "grit/ash_resources.h"
31 #include "grit/ash_strings.h" 31 #include "grit/ash_strings.h"
32 #include "ui/aura/client/screen_position_client.h" 32 #include "ui/aura/client/screen_position_client.h"
33 #include "ui/aura/root_window.h" 33 #include "ui/aura/root_window.h"
34 #include "ui/aura/window.h" 34 #include "ui/aura/window.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 view_->layer()->SetOpacity(1.0f); 368 view_->layer()->SetOpacity(1.0f);
369 } 369 }
370 370
371 private: 371 private:
372 ShelfView* shelf_view_; 372 ShelfView* shelf_view_;
373 views::View* view_; 373 views::View* view_;
374 374
375 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); 375 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate);
376 }; 376 };
377 377
378 ShelfView::ShelfView(LauncherModel* model, 378 ShelfView::ShelfView(ShelfModel* model,
379 LauncherDelegate* delegate, 379 LauncherDelegate* delegate,
380 ShelfLayoutManager* shelf_layout_manager) 380 ShelfLayoutManager* shelf_layout_manager)
381 : model_(model), 381 : model_(model),
382 delegate_(delegate), 382 delegate_(delegate),
383 view_model_(new views::ViewModel), 383 view_model_(new views::ViewModel),
384 first_visible_index_(0), 384 first_visible_index_(0),
385 last_visible_index_(-1), 385 last_visible_index_(-1),
386 overflow_button_(NULL), 386 overflow_button_(NULL),
387 owner_overflow_bubble_(NULL), 387 owner_overflow_bubble_(NULL),
388 drag_pointer_(NONE), 388 drag_pointer_(NONE),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 UpdateFirstButtonPadding(); 437 UpdateFirstButtonPadding();
438 438
439 // We'll layout when our bounds change. 439 // We'll layout when our bounds change.
440 } 440 }
441 441
442 void ShelfView::OnShelfAlignmentChanged() { 442 void ShelfView::OnShelfAlignmentChanged() {
443 UpdateFirstButtonPadding(); 443 UpdateFirstButtonPadding();
444 overflow_button_->OnShelfAlignmentChanged(); 444 overflow_button_->OnShelfAlignmentChanged();
445 LayoutToIdealBounds(); 445 LayoutToIdealBounds();
446 for (int i=0; i < view_model_->view_size(); ++i) { 446 for (int i=0; i < view_model_->view_size(); ++i) {
447 // TODO: remove when AppIcon is a Launcher Button. 447 // TODO: remove when AppIcon is a Shelf Button.
448 if (TYPE_APP_LIST == model_->items()[i].type && 448 if (TYPE_APP_LIST == model_->items()[i].type &&
449 !ash::switches::UseAlternateShelfLayout()) { 449 !ash::switches::UseAlternateShelfLayout()) {
450 static_cast<AppListButton*>(view_model_->view_at(i))->SetImageAlignment( 450 static_cast<AppListButton*>(view_model_->view_at(i))->SetImageAlignment(
451 layout_manager_->SelectValueForShelfAlignment( 451 layout_manager_->SelectValueForShelfAlignment(
452 views::ImageButton::ALIGN_CENTER, 452 views::ImageButton::ALIGN_CENTER,
453 views::ImageButton::ALIGN_LEFT, 453 views::ImageButton::ALIGN_LEFT,
454 views::ImageButton::ALIGN_RIGHT, 454 views::ImageButton::ALIGN_RIGHT,
455 views::ImageButton::ALIGN_CENTER), 455 views::ImageButton::ALIGN_CENTER),
456 layout_manager_->SelectValueForShelfAlignment( 456 layout_manager_->SelectValueForShelfAlignment(
457 views::ImageButton::ALIGN_TOP, 457 views::ImageButton::ALIGN_TOP,
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 base::AutoReset<bool> cancelling_drag( 1459 base::AutoReset<bool> cancelling_drag(
1460 &cancelling_drag_model_changed_, true); 1460 &cancelling_drag_model_changed_, true);
1461 model_index = CancelDrag(model_index); 1461 model_index = CancelDrag(model_index);
1462 } 1462 }
1463 views::View* view = view_model_->view_at(model_index); 1463 views::View* view = view_model_->view_at(model_index);
1464 view_model_->Remove(model_index); 1464 view_model_->Remove(model_index);
1465 1465
1466 // When the overflow bubble is visible, the overflow range needs to be set 1466 // When the overflow bubble is visible, the overflow range needs to be set
1467 // before CalculateIdealBounds() gets called. Otherwise CalculateIdealBounds() 1467 // before CalculateIdealBounds() gets called. Otherwise CalculateIdealBounds()
1468 // could trigger a LauncherItemChanged() by hiding the overflow bubble and 1468 // could trigger a LauncherItemChanged() by hiding the overflow bubble and
1469 // since the overflow bubble is not yet synced with the LauncherModel this 1469 // since the overflow bubble is not yet synced with the ShelfModel this
1470 // could cause a crash. 1470 // could cause a crash.
1471 if (overflow_bubble_ && overflow_bubble_->IsShowing()) { 1471 if (overflow_bubble_ && overflow_bubble_->IsShowing()) {
1472 last_hidden_index_ = std::min(last_hidden_index_, 1472 last_hidden_index_ = std::min(last_hidden_index_,
1473 view_model_->view_size() - 1); 1473 view_model_->view_size() - 1);
1474 UpdateOverflowRange(overflow_bubble_->shelf_view()); 1474 UpdateOverflowRange(overflow_bubble_->shelf_view());
1475 } 1475 }
1476 1476
1477 if (view->visible()) { 1477 if (view->visible()) {
1478 // The first animation fades out the view. When done we'll animate the rest 1478 // The first animation fades out the view. When done we'll animate the rest
1479 // of the views to their target location. 1479 // of the views to their target location.
(...skipping 29 matching lines...) Expand all
1509 AddChildView(new_view); 1509 AddChildView(new_view);
1510 view_model_->Add(new_view, model_index); 1510 view_model_->Add(new_view, model_index);
1511 view_model_->set_ideal_bounds(model_index, old_ideal_bounds); 1511 view_model_->set_ideal_bounds(model_index, old_ideal_bounds);
1512 new_view->SetBoundsRect(old_view->bounds()); 1512 new_view->SetBoundsRect(old_view->bounds());
1513 return; 1513 return;
1514 } 1514 }
1515 1515
1516 views::View* view = view_model_->view_at(model_index); 1516 views::View* view = view_model_->view_at(model_index);
1517 switch (item.type) { 1517 switch (item.type) {
1518 case TYPE_BROWSER_SHORTCUT: 1518 case TYPE_BROWSER_SHORTCUT:
1519 // Fallthrough for the new Launcher since it needs to show the activation 1519 // Fallthrough for the new Shelf since it needs to show the activation
1520 // change as well. 1520 // change as well.
1521 case TYPE_APP_SHORTCUT: 1521 case TYPE_APP_SHORTCUT:
1522 case TYPE_WINDOWED_APP: 1522 case TYPE_WINDOWED_APP:
1523 case TYPE_PLATFORM_APP: 1523 case TYPE_PLATFORM_APP:
1524 case TYPE_APP_PANEL: { 1524 case TYPE_APP_PANEL: {
1525 LauncherButton* button = static_cast<LauncherButton*>(view); 1525 LauncherButton* button = static_cast<LauncherButton*>(view);
1526 ReflectItemStatus(item, button); 1526 ReflectItemStatus(item, button);
1527 // The browser shortcut is currently not a "real" item and as such the 1527 // The browser shortcut is currently not a "real" item and as such the
1528 // the image is bogous as well. We therefore keep the image as is for it. 1528 // the image is bogous as well. We therefore keep the image as is for it.
1529 if (item.type != TYPE_BROWSER_SHORTCUT) 1529 if (item.type != TYPE_BROWSER_SHORTCUT)
(...skipping 15 matching lines...) Expand all
1545 // at this time the |view_model_| is inconsistent with the |model_|. 1545 // at this time the |view_model_| is inconsistent with the |model_|.
1546 if (!cancelling_drag_model_changed_) 1546 if (!cancelling_drag_model_changed_)
1547 AnimateToIdealBounds(); 1547 AnimateToIdealBounds();
1548 } 1548 }
1549 1549
1550 void ShelfView::ShelfStatusChanged() { 1550 void ShelfView::ShelfStatusChanged() {
1551 if (ash::switches::UseAlternateShelfLayout()) 1551 if (ash::switches::UseAlternateShelfLayout())
1552 return; 1552 return;
1553 AppListButton* app_list_button = 1553 AppListButton* app_list_button =
1554 static_cast<AppListButton*>(GetAppListButtonView()); 1554 static_cast<AppListButton*>(GetAppListButtonView());
1555 if (model_->status() == LauncherModel::STATUS_LOADING) 1555 if (model_->status() == ShelfModel::STATUS_LOADING)
1556 app_list_button->StartLoadingAnimation(); 1556 app_list_button->StartLoadingAnimation();
1557 else 1557 else
1558 app_list_button->StopLoadingAnimation(); 1558 app_list_button->StopLoadingAnimation();
1559 } 1559 }
1560 1560
1561 void ShelfView::PointerPressedOnButton(views::View* view, 1561 void ShelfView::PointerPressedOnButton(views::View* view,
1562 Pointer pointer, 1562 Pointer pointer,
1563 const ui::LocatedEvent& event) { 1563 const ui::LocatedEvent& event) {
1564 if (drag_view_) 1564 if (drag_view_)
1565 return; 1565 return;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 anchor_point = source->GetBoundsInScreen(); 1785 anchor_point = source->GetBoundsInScreen();
1786 1786
1787 // It is possible to invoke the menu while it is sliding into view. To cover 1787 // It is possible to invoke the menu while it is sliding into view. To cover
1788 // that case, the screen coordinates are offsetted by the animation delta. 1788 // that case, the screen coordinates are offsetted by the animation delta.
1789 gfx::Vector2d offset = 1789 gfx::Vector2d offset =
1790 source->GetWidget()->GetNativeWindow()->bounds().origin() - 1790 source->GetWidget()->GetNativeWindow()->bounds().origin() -
1791 source->GetWidget()->GetNativeWindow()->GetTargetBounds().origin(); 1791 source->GetWidget()->GetNativeWindow()->GetTargetBounds().origin();
1792 anchor_point.set_x(anchor_point.x() - offset.x()); 1792 anchor_point.set_x(anchor_point.x() - offset.x());
1793 anchor_point.set_y(anchor_point.y() - offset.y()); 1793 anchor_point.set_y(anchor_point.y() - offset.y());
1794 1794
1795 // Launcher items can have an asymmetrical border for spacing reasons. 1795 // Shelf items can have an asymmetrical border for spacing reasons.
1796 // Adjust anchor location for this. 1796 // Adjust anchor location for this.
1797 if (source->border()) 1797 if (source->border())
1798 anchor_point.Inset(source->border()->GetInsets()); 1798 anchor_point.Inset(source->border()->GetInsets());
1799 1799
1800 switch (align) { 1800 switch (align) {
1801 case ash::SHELF_ALIGNMENT_BOTTOM: 1801 case ash::SHELF_ALIGNMENT_BOTTOM:
1802 menu_alignment = views::MenuItemView::BUBBLE_ABOVE; 1802 menu_alignment = views::MenuItemView::BUBBLE_ABOVE;
1803 break; 1803 break;
1804 case ash::SHELF_ALIGNMENT_LEFT: 1804 case ash::SHELF_ALIGNMENT_LEFT:
1805 menu_alignment = views::MenuItemView::BUBBLE_RIGHT; 1805 menu_alignment = views::MenuItemView::BUBBLE_RIGHT;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 break; 1925 break;
1926 case ash::SHELF_ALIGNMENT_TOP: 1926 case ash::SHELF_ALIGNMENT_TOP:
1927 distance = coordinate.y() - bounds.bottom(); 1927 distance = coordinate.y() - bounds.bottom();
1928 break; 1928 break;
1929 } 1929 }
1930 return distance > 0 ? distance : 0; 1930 return distance > 0 ? distance : 0;
1931 } 1931 }
1932 1932
1933 } // namespace internal 1933 } // namespace internal
1934 } // namespace ash 1934 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698