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

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

Issue 152223002: Renames LauncherID, LauncherItem and LauncherItems... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: OWNERS Created 6 years, 10 months 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"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 view_->layer()->SetOpacity(1.0f); 287 view_->layer()->SetOpacity(1.0f);
288 view_->layer()->ScheduleDraw(); 288 view_->layer()->ScheduleDraw();
289 } 289 }
290 290
291 private: 291 private:
292 views::View* view_; 292 views::View* view_;
293 293
294 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); 294 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate);
295 }; 295 };
296 296
297 void ReflectItemStatus(const LauncherItem& item, ShelfButton* button) { 297 void ReflectItemStatus(const ShelfItem& item, ShelfButton* button) {
298 switch (item.status) { 298 switch (item.status) {
299 case STATUS_CLOSED: 299 case STATUS_CLOSED:
300 button->ClearState(ShelfButton::STATE_ACTIVE); 300 button->ClearState(ShelfButton::STATE_ACTIVE);
301 button->ClearState(ShelfButton::STATE_RUNNING); 301 button->ClearState(ShelfButton::STATE_RUNNING);
302 button->ClearState(ShelfButton::STATE_ATTENTION); 302 button->ClearState(ShelfButton::STATE_ATTENTION);
303 break; 303 break;
304 case STATUS_RUNNING: 304 case STATUS_RUNNING:
305 button->ClearState(ShelfButton::STATE_ACTIVE); 305 button->ClearState(ShelfButton::STATE_ACTIVE);
306 button->AddState(ShelfButton::STATE_RUNNING); 306 button->AddState(ShelfButton::STATE_RUNNING);
307 button->ClearState(ShelfButton::STATE_ATTENTION); 307 button->ClearState(ShelfButton::STATE_ATTENTION);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 drag_view_(NULL), 390 drag_view_(NULL),
391 drag_offset_(0), 391 drag_offset_(0),
392 start_drag_index_(-1), 392 start_drag_index_(-1),
393 context_menu_id_(0), 393 context_menu_id_(0),
394 leading_inset_(kDefaultLeadingInset), 394 leading_inset_(kDefaultLeadingInset),
395 cancelling_drag_model_changed_(false), 395 cancelling_drag_model_changed_(false),
396 last_hidden_index_(0), 396 last_hidden_index_(0),
397 closing_event_time_(base::TimeDelta()), 397 closing_event_time_(base::TimeDelta()),
398 got_deleted_(NULL), 398 got_deleted_(NULL),
399 drag_and_drop_item_pinned_(false), 399 drag_and_drop_item_pinned_(false),
400 drag_and_drop_launcher_id_(0), 400 drag_and_drop_shelf_id_(0),
401 dragged_off_shelf_(false), 401 dragged_off_shelf_(false),
402 snap_back_from_rip_off_view_(NULL), 402 snap_back_from_rip_off_view_(NULL),
403 item_manager_(Shell::GetInstance()->shelf_item_delegate_manager()), 403 item_manager_(Shell::GetInstance()->shelf_item_delegate_manager()),
404 layout_manager_(manager), 404 layout_manager_(manager),
405 overflow_mode_(false), 405 overflow_mode_(false),
406 main_shelf_(NULL), 406 main_shelf_(NULL),
407 dragged_off_from_overflow_to_shelf_(false) { 407 dragged_off_from_overflow_to_shelf_(false) {
408 DCHECK(model_); 408 DCHECK(model_);
409 bounds_animator_.reset(new views::BoundsAnimator(this)); 409 bounds_animator_.reset(new views::BoundsAnimator(this));
410 bounds_animator_->AddObserver(this); 410 bounds_animator_->AddObserver(this);
411 set_context_menu_controller(this); 411 set_context_menu_controller(this);
412 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); 412 focus_search_.reset(new ShelfFocusSearch(view_model_.get()));
413 tooltip_.reset(new ShelfTooltipManager(manager, this)); 413 tooltip_.reset(new ShelfTooltipManager(manager, this));
414 } 414 }
415 415
416 ShelfView::~ShelfView() { 416 ShelfView::~ShelfView() {
417 bounds_animator_->RemoveObserver(this); 417 bounds_animator_->RemoveObserver(this);
418 model_->RemoveObserver(this); 418 model_->RemoveObserver(this);
419 // If we are inside the MenuRunner, we need to know if we were getting 419 // If we are inside the MenuRunner, we need to know if we were getting
420 // deleted while it was running. 420 // deleted while it was running.
421 if (got_deleted_) 421 if (got_deleted_)
422 *got_deleted_ = true; 422 *got_deleted_ = true;
423 } 423 }
424 424
425 void ShelfView::Init() { 425 void ShelfView::Init() {
426 model_->AddObserver(this); 426 model_->AddObserver(this);
427 427
428 const LauncherItems& items(model_->items()); 428 const ShelfItems& items(model_->items());
429 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { 429 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) {
430 views::View* child = CreateViewForItem(*i); 430 views::View* child = CreateViewForItem(*i);
431 child->SetPaintToLayer(true); 431 child->SetPaintToLayer(true);
432 view_model_->Add(child, static_cast<int>(i - items.begin())); 432 view_model_->Add(child, static_cast<int>(i - items.begin()));
433 AddChildView(child); 433 AddChildView(child);
434 } 434 }
435 ShelfStatusChanged(); 435 ShelfStatusChanged();
436 overflow_button_ = new OverflowButton(this); 436 overflow_button_ = new OverflowButton(this);
437 overflow_button_->set_context_menu_controller(this); 437 overflow_button_->set_context_menu_controller(this);
438 ConfigureChildView(overflow_button_); 438 ConfigureChildView(overflow_button_);
439 AddChildView(overflow_button_); 439 AddChildView(overflow_button_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 472
473 void ShelfView::SchedulePaintForAllButtons() { 473 void ShelfView::SchedulePaintForAllButtons() {
474 for (int i = 0; i < view_model_->view_size(); ++i) { 474 for (int i = 0; i < view_model_->view_size(); ++i) {
475 if (i >= first_visible_index_ && i <= last_visible_index_) 475 if (i >= first_visible_index_ && i <= last_visible_index_)
476 view_model_->view_at(i)->SchedulePaint(); 476 view_model_->view_at(i)->SchedulePaint();
477 } 477 }
478 if (overflow_button_ && overflow_button_->visible()) 478 if (overflow_button_ && overflow_button_->visible())
479 overflow_button_->SchedulePaint(); 479 overflow_button_->SchedulePaint();
480 } 480 }
481 481
482 gfx::Rect ShelfView::GetIdealBoundsOfItemIcon(LauncherID id) { 482 gfx::Rect ShelfView::GetIdealBoundsOfItemIcon(ShelfID id) {
483 int index = model_->ItemIndexByID(id); 483 int index = model_->ItemIndexByID(id);
484 if (index == -1 || (index > last_visible_index_ && 484 if (index == -1 || (index > last_visible_index_ &&
485 index < model_->FirstPanelIndex())) 485 index < model_->FirstPanelIndex()))
486 return gfx::Rect(); 486 return gfx::Rect();
487 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); 487 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index));
488 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); 488 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type);
489 ShelfButton* button = static_cast<ShelfButton*>(view_model_->view_at(index)); 489 ShelfButton* button = static_cast<ShelfButton*>(view_model_->view_at(index));
490 gfx::Rect icon_bounds = button->GetIconBounds(); 490 gfx::Rect icon_bounds = button->GetIconBounds();
491 return gfx::Rect(GetMirroredXWithWidthInView( 491 return gfx::Rect(GetMirroredXWithWidthInView(
492 ideal_bounds.x() + icon_bounds.x(), icon_bounds.width()), 492 ideal_bounds.x() + icon_bounds.x(), icon_bounds.width()),
493 ideal_bounds.y() + icon_bounds.y(), 493 ideal_bounds.y() + icon_bounds.y(),
494 icon_bounds.width(), 494 icon_bounds.width(),
495 icon_bounds.height()); 495 icon_bounds.height());
496 } 496 }
497 497
498 void ShelfView::UpdatePanelIconPosition(LauncherID id, 498 void ShelfView::UpdatePanelIconPosition(ShelfID id,
499 const gfx::Point& midpoint) { 499 const gfx::Point& midpoint) {
500 int current_index = model_->ItemIndexByID(id); 500 int current_index = model_->ItemIndexByID(id);
501 int first_panel_index = model_->FirstPanelIndex(); 501 int first_panel_index = model_->FirstPanelIndex();
502 if (current_index < first_panel_index) 502 if (current_index < first_panel_index)
503 return; 503 return;
504 504
505 gfx::Point midpoint_in_view(GetMirroredXInView(midpoint.x()), 505 gfx::Point midpoint_in_view(GetMirroredXInView(midpoint.x()),
506 midpoint.y()); 506 midpoint.y());
507 int target_index = current_index; 507 int target_index = current_index;
508 while (target_index > first_panel_index && 508 while (target_index > first_panel_index &&
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 590
591 void ShelfView::DestroyDragIconProxy() { 591 void ShelfView::DestroyDragIconProxy() {
592 drag_image_.reset(); 592 drag_image_.reset();
593 drag_image_offset_ = gfx::Vector2d(0, 0); 593 drag_image_offset_ = gfx::Vector2d(0, 0);
594 } 594 }
595 595
596 bool ShelfView::StartDrag(const std::string& app_id, 596 bool ShelfView::StartDrag(const std::string& app_id,
597 const gfx::Point& location_in_screen_coordinates) { 597 const gfx::Point& location_in_screen_coordinates) {
598 // Bail if an operation is already going on - or the cursor is not inside. 598 // Bail if an operation is already going on - or the cursor is not inside.
599 // This could happen if mouse / touch operations overlap. 599 // This could happen if mouse / touch operations overlap.
600 if (drag_and_drop_launcher_id_ || 600 if (drag_and_drop_shelf_id_ ||
601 !GetBoundsInScreen().Contains(location_in_screen_coordinates)) 601 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
602 return false; 602 return false;
603 603
604 // If the AppsGridView (which was dispatching this event) was opened by our 604 // If the AppsGridView (which was dispatching this event) was opened by our
605 // button, ShelfView dragging operations are locked and we have to unlock. 605 // button, ShelfView dragging operations are locked and we have to unlock.
606 CancelDrag(-1); 606 CancelDrag(-1);
607 drag_and_drop_item_pinned_ = false; 607 drag_and_drop_item_pinned_ = false;
608 drag_and_drop_app_id_ = app_id; 608 drag_and_drop_app_id_ = app_id;
609 drag_and_drop_launcher_id_ = 609 drag_and_drop_shelf_id_ =
610 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_); 610 delegate_->GetShelfIDForAppID(drag_and_drop_app_id_);
611 // Check if the application is known and pinned - if not, we have to pin it so 611 // Check if the application is known and pinned - if not, we have to pin it so
612 // that we can re-arrange the shelf order accordingly. Note that items have 612 // that we can re-arrange the shelf order accordingly. Note that items have
613 // to be pinned to give them the same (order) possibilities as a shortcut. 613 // to be pinned to give them the same (order) possibilities as a shortcut.
614 // When an item is dragged from overflow to shelf, IsShowingOverflowBubble() 614 // When an item is dragged from overflow to shelf, IsShowingOverflowBubble()
615 // returns true. At this time, we don't need to pin the item. 615 // returns true. At this time, we don't need to pin the item.
616 if (!IsShowingOverflowBubble() && 616 if (!IsShowingOverflowBubble() &&
617 (!drag_and_drop_launcher_id_ || 617 (!drag_and_drop_shelf_id_ ||
618 !delegate_->IsAppPinned(app_id))) { 618 !delegate_->IsAppPinned(app_id))) {
619 delegate_->PinAppWithID(app_id); 619 delegate_->PinAppWithID(app_id);
620 drag_and_drop_launcher_id_ = 620 drag_and_drop_shelf_id_ =
621 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_); 621 delegate_->GetShelfIDForAppID(drag_and_drop_app_id_);
622 if (!drag_and_drop_launcher_id_) 622 if (!drag_and_drop_shelf_id_)
623 return false; 623 return false;
624 drag_and_drop_item_pinned_ = true; 624 drag_and_drop_item_pinned_ = true;
625 } 625 }
626 views::View* drag_and_drop_view = view_model_->view_at( 626 views::View* drag_and_drop_view = view_model_->view_at(
627 model_->ItemIndexByID(drag_and_drop_launcher_id_)); 627 model_->ItemIndexByID(drag_and_drop_shelf_id_));
628 DCHECK(drag_and_drop_view); 628 DCHECK(drag_and_drop_view);
629 629
630 // Since there is already an icon presented by the caller, we hide this item 630 // Since there is already an icon presented by the caller, we hide this item
631 // for now. That has to be done by reducing the size since the visibility will 631 // for now. That has to be done by reducing the size since the visibility will
632 // change once a regrouping animation is performed. 632 // change once a regrouping animation is performed.
633 pre_drag_and_drop_size_ = drag_and_drop_view->size(); 633 pre_drag_and_drop_size_ = drag_and_drop_view->size();
634 drag_and_drop_view->SetSize(gfx::Size()); 634 drag_and_drop_view->SetSize(gfx::Size());
635 635
636 // First we have to center the mouse cursor over the item. 636 // First we have to center the mouse cursor over the item.
637 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint(); 637 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint();
638 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt); 638 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt);
639 gfx::Point point_in_root = location_in_screen_coordinates; 639 gfx::Point point_in_root = location_in_screen_coordinates;
640 ash::wm::ConvertPointFromScreen( 640 ash::wm::ConvertPointFromScreen(
641 ash::wm::GetRootWindowAt(location_in_screen_coordinates), 641 ash::wm::GetRootWindowAt(location_in_screen_coordinates),
642 &point_in_root); 642 &point_in_root);
643 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, pt, point_in_root, 0, 0); 643 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, pt, point_in_root, 0, 0);
644 PointerPressedOnButton(drag_and_drop_view, 644 PointerPressedOnButton(drag_and_drop_view,
645 ShelfButtonHost::DRAG_AND_DROP, 645 ShelfButtonHost::DRAG_AND_DROP,
646 event); 646 event);
647 647
648 // Drag the item where it really belongs. 648 // Drag the item where it really belongs.
649 Drag(location_in_screen_coordinates); 649 Drag(location_in_screen_coordinates);
650 return true; 650 return true;
651 } 651 }
652 652
653 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) { 653 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) {
654 if (!drag_and_drop_launcher_id_ || 654 if (!drag_and_drop_shelf_id_ ||
655 !GetBoundsInScreen().Contains(location_in_screen_coordinates)) 655 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
656 return false; 656 return false;
657 657
658 gfx::Point pt = location_in_screen_coordinates; 658 gfx::Point pt = location_in_screen_coordinates;
659 views::View* drag_and_drop_view = view_model_->view_at( 659 views::View* drag_and_drop_view = view_model_->view_at(
660 model_->ItemIndexByID(drag_and_drop_launcher_id_)); 660 model_->ItemIndexByID(drag_and_drop_shelf_id_));
661 ConvertPointFromScreen(drag_and_drop_view, &pt); 661 ConvertPointFromScreen(drag_and_drop_view, &pt);
662 gfx::Point point_in_root = location_in_screen_coordinates; 662 gfx::Point point_in_root = location_in_screen_coordinates;
663 ash::wm::ConvertPointFromScreen( 663 ash::wm::ConvertPointFromScreen(
664 ash::wm::GetRootWindowAt(location_in_screen_coordinates), 664 ash::wm::GetRootWindowAt(location_in_screen_coordinates),
665 &point_in_root); 665 &point_in_root);
666 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root, 0, 0); 666 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root, 0, 0);
667 PointerDraggedOnButton(drag_and_drop_view, 667 PointerDraggedOnButton(drag_and_drop_view,
668 ShelfButtonHost::DRAG_AND_DROP, 668 ShelfButtonHost::DRAG_AND_DROP,
669 event); 669 event);
670 return true; 670 return true;
671 } 671 }
672 672
673 void ShelfView::EndDrag(bool cancel) { 673 void ShelfView::EndDrag(bool cancel) {
674 if (!drag_and_drop_launcher_id_) 674 if (!drag_and_drop_shelf_id_)
675 return; 675 return;
676 676
677 views::View* drag_and_drop_view = view_model_->view_at( 677 views::View* drag_and_drop_view = view_model_->view_at(
678 model_->ItemIndexByID(drag_and_drop_launcher_id_)); 678 model_->ItemIndexByID(drag_and_drop_shelf_id_));
679 PointerReleasedOnButton( 679 PointerReleasedOnButton(
680 drag_and_drop_view, ShelfButtonHost::DRAG_AND_DROP, cancel); 680 drag_and_drop_view, ShelfButtonHost::DRAG_AND_DROP, cancel);
681 681
682 // Either destroy the temporarily created item - or - make the item visible. 682 // Either destroy the temporarily created item - or - make the item visible.
683 if (drag_and_drop_item_pinned_ && cancel) 683 if (drag_and_drop_item_pinned_ && cancel)
684 delegate_->UnpinAppWithID(drag_and_drop_app_id_); 684 delegate_->UnpinAppWithID(drag_and_drop_app_id_);
685 else if (drag_and_drop_view) { 685 else if (drag_and_drop_view) {
686 if (cancel) { 686 if (cancel) {
687 // When a hosted drag gets canceled, the item can remain in the same slot 687 // When a hosted drag gets canceled, the item can remain in the same slot
688 // and it might have moved within the bounds. In that case the item need 688 // and it might have moved within the bounds. In that case the item need
689 // to animate back to its correct location. 689 // to animate back to its correct location.
690 AnimateToIdealBounds(); 690 AnimateToIdealBounds();
691 } else { 691 } else {
692 drag_and_drop_view->SetSize(pre_drag_and_drop_size_); 692 drag_and_drop_view->SetSize(pre_drag_and_drop_size_);
693 } 693 }
694 } 694 }
695 695
696 drag_and_drop_launcher_id_ = 0; 696 drag_and_drop_shelf_id_ = 0;
697 } 697 }
698 698
699 void ShelfView::LayoutToIdealBounds() { 699 void ShelfView::LayoutToIdealBounds() {
700 if (bounds_animator_->IsAnimating()) { 700 if (bounds_animator_->IsAnimating()) {
701 AnimateToIdealBounds(); 701 AnimateToIdealBounds();
702 return; 702 return;
703 } 703 }
704 704
705 IdealBounds ideal_bounds; 705 IdealBounds ideal_bounds;
706 CalculateIdealBounds(&ideal_bounds); 706 CalculateIdealBounds(&ideal_bounds);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 // Now that the item animation starts, we have to make sure that the 927 // Now that the item animation starts, we have to make sure that the
928 // padding of the first gets properly transferred to the new first item. 928 // padding of the first gets properly transferred to the new first item.
929 if (i && view->border()) 929 if (i && view->border())
930 view->SetBorder(views::Border::NullBorder()); 930 view->SetBorder(views::Border::NullBorder());
931 else if (!i && !view->border()) 931 else if (!i && !view->border())
932 UpdateFirstButtonPadding(); 932 UpdateFirstButtonPadding();
933 } 933 }
934 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); 934 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds);
935 } 935 }
936 936
937 views::View* ShelfView::CreateViewForItem(const LauncherItem& item) { 937 views::View* ShelfView::CreateViewForItem(const ShelfItem& item) {
938 views::View* view = NULL; 938 views::View* view = NULL;
939 switch (item.type) { 939 switch (item.type) {
940 case TYPE_BROWSER_SHORTCUT: 940 case TYPE_BROWSER_SHORTCUT:
941 case TYPE_APP_SHORTCUT: 941 case TYPE_APP_SHORTCUT:
942 case TYPE_WINDOWED_APP: 942 case TYPE_WINDOWED_APP:
943 case TYPE_PLATFORM_APP: 943 case TYPE_PLATFORM_APP:
944 case TYPE_DIALOG: 944 case TYPE_DIALOG:
945 case TYPE_APP_PANEL: { 945 case TYPE_APP_PANEL: {
946 ShelfButton* button = ShelfButton::Create(this, this, layout_manager_); 946 ShelfButton* button = ShelfButton::Create(this, this, layout_manager_);
947 button->SetImage(item.image); 947 button->SetImage(item.image);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 1024
1025 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( 1025 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
1026 model_->items()[current_index].id); 1026 model_->items()[current_index].id);
1027 if (!item_delegate->IsDraggable()) { 1027 if (!item_delegate->IsDraggable()) {
1028 CancelDrag(-1); 1028 CancelDrag(-1);
1029 return; 1029 return;
1030 } 1030 }
1031 1031
1032 // If this is not a drag and drop host operation and not the app list item, 1032 // If this is not a drag and drop host operation and not the app list item,
1033 // check if the item got ripped off the shelf - if it did we are done. 1033 // check if the item got ripped off the shelf - if it did we are done.
1034 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && 1034 if (!drag_and_drop_shelf_id_ && ash::switches::UseDragOffShelf() &&
1035 RemovableByRipOff(current_index) != NOT_REMOVABLE) { 1035 RemovableByRipOff(current_index) != NOT_REMOVABLE) {
1036 if (HandleRipOffDrag(event)) 1036 if (HandleRipOffDrag(event))
1037 return; 1037 return;
1038 // The rip off handler could have changed the location of the item. 1038 // The rip off handler could have changed the location of the item.
1039 current_index = view_model_->GetIndexOfView(drag_view_); 1039 current_index = view_model_->GetIndexOfView(drag_view_);
1040 } 1040 }
1041 1041
1042 // TODO: I don't think this works correctly with RTL. 1042 // TODO: I don't think this works correctly with RTL.
1043 gfx::Point drag_point(event.location()); 1043 gfx::Point drag_point(event.location());
1044 ConvertPointToTarget(drag_view_, this, &drag_point); 1044 ConvertPointToTarget(drag_view_, this, &drag_point);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 // Change the model, the ShelfItemMoved() callback will handle the 1088 // Change the model, the ShelfItemMoved() callback will handle the
1089 // |view_model_| update. 1089 // |view_model_| update.
1090 model_->Move(current_index, target_index); 1090 model_->Move(current_index, target_index);
1091 bounds_animator_->StopAnimatingView(drag_view_); 1091 bounds_animator_->StopAnimatingView(drag_view_);
1092 } 1092 }
1093 1093
1094 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) { 1094 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) {
1095 int current_index = view_model_->GetIndexOfView(drag_view_); 1095 int current_index = view_model_->GetIndexOfView(drag_view_);
1096 DCHECK_NE(-1, current_index); 1096 DCHECK_NE(-1, current_index);
1097 std::string dragged_app_id = 1097 std::string dragged_app_id =
1098 delegate_->GetAppIDForLauncherID(model_->items()[current_index].id); 1098 delegate_->GetAppIDForShelfID(model_->items()[current_index].id);
1099 1099
1100 gfx::Point screen_location = event.root_location(); 1100 gfx::Point screen_location = event.root_location();
1101 ash::wm::ConvertPointToScreen(GetWidget()->GetNativeWindow()->GetRootWindow(), 1101 ash::wm::ConvertPointToScreen(GetWidget()->GetNativeWindow()->GetRootWindow(),
1102 &screen_location); 1102 &screen_location);
1103 1103
1104 // To avoid ugly forwards and backwards flipping we use different constants 1104 // To avoid ugly forwards and backwards flipping we use different constants
1105 // for ripping off / re-inserting the items. 1105 // for ripping off / re-inserting the items.
1106 if (dragged_off_shelf_) { 1106 if (dragged_off_shelf_) {
1107 // If the shelf/overflow bubble bounds contains |screen_location| we insert 1107 // If the shelf/overflow bubble bounds contains |screen_location| we insert
1108 // the item back into the shelf. 1108 // the item back into the shelf.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 drag_view_->layer()->SetOpacity(1.0f); 1213 drag_view_->layer()->SetOpacity(1.0f);
1214 } else if (RemovableByRipOff(current_index) != REMOVABLE) { 1214 } else if (RemovableByRipOff(current_index) != REMOVABLE) {
1215 // Make sure we do not try to remove un-removable items like items which 1215 // Make sure we do not try to remove un-removable items like items which
1216 // were not pinned or have to be always there. 1216 // were not pinned or have to be always there.
1217 cancel = true; 1217 cancel = true;
1218 snap_back = true; 1218 snap_back = true;
1219 } else { 1219 } else {
1220 // Make sure the item stays invisible upon removal. 1220 // Make sure the item stays invisible upon removal.
1221 drag_view_->SetVisible(false); 1221 drag_view_->SetVisible(false);
1222 std::string app_id = 1222 std::string app_id =
1223 delegate_->GetAppIDForLauncherID(model_->items()[current_index].id); 1223 delegate_->GetAppIDForShelfID(model_->items()[current_index].id);
1224 delegate_->UnpinAppWithID(app_id); 1224 delegate_->UnpinAppWithID(app_id);
1225 } 1225 }
1226 } 1226 }
1227 if (cancel || snap_back) { 1227 if (cancel || snap_back) {
1228 if (dragged_off_from_overflow_to_shelf_) { 1228 if (dragged_off_from_overflow_to_shelf_) {
1229 dragged_off_from_overflow_to_shelf_ = false; 1229 dragged_off_from_overflow_to_shelf_ = false;
1230 // Main shelf handles revert of dragged item. 1230 // Main shelf handles revert of dragged item.
1231 main_shelf_->EndDrag(true); 1231 main_shelf_->EndDrag(true);
1232 drag_view_->layer()->SetOpacity(1.0f); 1232 drag_view_->layer()->SetOpacity(1.0f);
1233 } else if (!cancelling_drag_model_changed_) { 1233 } else if (!cancelling_drag_model_changed_) {
(...skipping 19 matching lines...) Expand all
1253 } 1253 }
1254 DestroyDragIconProxy(); 1254 DestroyDragIconProxy();
1255 } 1255 }
1256 1256
1257 ShelfView::RemovableState ShelfView::RemovableByRipOff(int index) { 1257 ShelfView::RemovableState ShelfView::RemovableByRipOff(int index) {
1258 DCHECK(index >= 0 && index < model_->item_count()); 1258 DCHECK(index >= 0 && index < model_->item_count());
1259 ShelfItemType type = model_->items()[index].type; 1259 ShelfItemType type = model_->items()[index].type;
1260 if (type == TYPE_APP_LIST || type == TYPE_DIALOG || !delegate_->CanPin()) 1260 if (type == TYPE_APP_LIST || type == TYPE_DIALOG || !delegate_->CanPin())
1261 return NOT_REMOVABLE; 1261 return NOT_REMOVABLE;
1262 1262
1263 std::string app_id = 1263 std::string app_id = delegate_->GetAppIDForShelfID(model_->items()[index].id);
1264 delegate_->GetAppIDForLauncherID(model_->items()[index].id);
1265 // Note: Only pinned app shortcuts can be removed! 1264 // Note: Only pinned app shortcuts can be removed!
1266 return (type == TYPE_APP_SHORTCUT && delegate_->IsAppPinned(app_id)) ? 1265 return (type == TYPE_APP_SHORTCUT && delegate_->IsAppPinned(app_id)) ?
1267 REMOVABLE : DRAGGABLE; 1266 REMOVABLE : DRAGGABLE;
1268 } 1267 }
1269 1268
1270 bool ShelfView::SameDragType(ShelfItemType typea, ShelfItemType typeb) const { 1269 bool ShelfView::SameDragType(ShelfItemType typea, ShelfItemType typeb) const {
1271 switch (typea) { 1270 switch (typea) {
1272 case TYPE_APP_SHORTCUT: 1271 case TYPE_APP_SHORTCUT:
1273 case TYPE_BROWSER_SHORTCUT: 1272 case TYPE_BROWSER_SHORTCUT:
1274 return (typeb == TYPE_APP_SHORTCUT || typeb == TYPE_BROWSER_SHORTCUT); 1273 return (typeb == TYPE_APP_SHORTCUT || typeb == TYPE_BROWSER_SHORTCUT);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 if (model_index <= last_visible_index_ || 1568 if (model_index <= last_visible_index_ ||
1570 model_index >= model_->FirstPanelIndex()) { 1569 model_index >= model_->FirstPanelIndex()) {
1571 bounds_animator_->SetAnimationDelegate( 1570 bounds_animator_->SetAnimationDelegate(
1572 view, new StartFadeAnimationDelegate(this, view), true); 1571 view, new StartFadeAnimationDelegate(this, view), true);
1573 } else { 1572 } else {
1574 // Undo the hiding if animation does not run. 1573 // Undo the hiding if animation does not run.
1575 view->layer()->SetOpacity(1.0f); 1574 view->layer()->SetOpacity(1.0f);
1576 } 1575 }
1577 } 1576 }
1578 1577
1579 void ShelfView::ShelfItemRemoved(int model_index, LauncherID id) { 1578 void ShelfView::ShelfItemRemoved(int model_index, ShelfID id) {
1580 if (id == context_menu_id_) 1579 if (id == context_menu_id_)
1581 launcher_menu_runner_.reset(); 1580 launcher_menu_runner_.reset();
1582 { 1581 {
1583 base::AutoReset<bool> cancelling_drag( 1582 base::AutoReset<bool> cancelling_drag(
1584 &cancelling_drag_model_changed_, true); 1583 &cancelling_drag_model_changed_, true);
1585 model_index = CancelDrag(model_index); 1584 model_index = CancelDrag(model_index);
1586 } 1585 }
1587 views::View* view = view_model_->view_at(model_index); 1586 views::View* view = view_model_->view_at(model_index);
1588 view_model_->Remove(model_index); 1587 view_model_->Remove(model_index);
1589 1588
(...skipping 19 matching lines...) Expand all
1609 // item is ripped out from the shelf, its |view| is already invisible. 1608 // item is ripped out from the shelf, its |view| is already invisible.
1610 AnimateToIdealBounds(); 1609 AnimateToIdealBounds();
1611 } 1610 }
1612 1611
1613 // Close the tooltip because it isn't needed any longer and its anchor view 1612 // Close the tooltip because it isn't needed any longer and its anchor view
1614 // will be deleted soon. 1613 // will be deleted soon.
1615 if (tooltip_->GetCurrentAnchorView() == view) 1614 if (tooltip_->GetCurrentAnchorView() == view)
1616 tooltip_->Close(); 1615 tooltip_->Close();
1617 } 1616 }
1618 1617
1619 void ShelfView::ShelfItemChanged(int model_index, 1618 void ShelfView::ShelfItemChanged(int model_index, const ShelfItem& old_item) {
1620 const LauncherItem& old_item) { 1619 const ShelfItem& item(model_->items()[model_index]);
1621 const LauncherItem& item(model_->items()[model_index]);
1622 if (old_item.type != item.type) { 1620 if (old_item.type != item.type) {
1623 // Type changed, swap the views. 1621 // Type changed, swap the views.
1624 model_index = CancelDrag(model_index); 1622 model_index = CancelDrag(model_index);
1625 scoped_ptr<views::View> old_view(view_model_->view_at(model_index)); 1623 scoped_ptr<views::View> old_view(view_model_->view_at(model_index));
1626 bounds_animator_->StopAnimatingView(old_view.get()); 1624 bounds_animator_->StopAnimatingView(old_view.get());
1627 // Removing and re-inserting a view in our view model will strip the ideal 1625 // Removing and re-inserting a view in our view model will strip the ideal
1628 // bounds from the item. To avoid recalculation of everything the bounds 1626 // bounds from the item. To avoid recalculation of everything the bounds
1629 // get remembered and restored after the insertion to the previous value. 1627 // get remembered and restored after the insertion to the previous value.
1630 gfx::Rect old_ideal_bounds = view_model_->ideal_bounds(model_index); 1628 gfx::Rect old_ideal_bounds = view_model_->ideal_bounds(model_index);
1631 view_model_->Remove(model_index); 1629 view_model_->Remove(model_index);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 break; 1826 break;
1829 } 1827 }
1830 1828
1831 ShelfItemDelegate* item_delegate = 1829 ShelfItemDelegate* item_delegate =
1832 item_manager_->GetShelfItemDelegate(model_->items()[view_index].id); 1830 item_manager_->GetShelfItemDelegate(model_->items()[view_index].id);
1833 if (!item_delegate->ItemSelected(event)) 1831 if (!item_delegate->ItemSelected(event))
1834 ShowListMenuForView(model_->items()[view_index], sender, event); 1832 ShowListMenuForView(model_->items()[view_index], sender, event);
1835 } 1833 }
1836 } 1834 }
1837 1835
1838 bool ShelfView::ShowListMenuForView(const LauncherItem& item, 1836 bool ShelfView::ShowListMenuForView(const ShelfItem& item,
1839 views::View* source, 1837 views::View* source,
1840 const ui::Event& event) { 1838 const ui::Event& event) {
1841 scoped_ptr<ShelfMenuModel> menu_model; 1839 scoped_ptr<ShelfMenuModel> menu_model;
1842 ShelfItemDelegate* item_delegate = 1840 ShelfItemDelegate* item_delegate =
1843 item_manager_->GetShelfItemDelegate(item.id); 1841 item_manager_->GetShelfItemDelegate(item.id);
1844 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags())); 1842 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags()));
1845 1843
1846 // Make sure we have a menu and it has at least two items in addition to the 1844 // Make sure we have a menu and it has at least two items in addition to the
1847 // application title and the 3 spacing separators. 1845 // application title and the 3 spacing separators.
1848 if (!menu_model.get() || menu_model->GetItemCount() <= 5) 1846 if (!menu_model.get() || menu_model->GetItemCount() <= 5)
(...skipping 18 matching lines...) Expand all
1867 } 1865 }
1868 1866
1869 scoped_ptr<ui::MenuModel> menu_model; 1867 scoped_ptr<ui::MenuModel> menu_model;
1870 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( 1868 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
1871 model_->items()[view_index].id); 1869 model_->items()[view_index].id);
1872 menu_model.reset(item_delegate->CreateContextMenu( 1870 menu_model.reset(item_delegate->CreateContextMenu(
1873 source->GetWidget()->GetNativeView()->GetRootWindow())); 1871 source->GetWidget()->GetNativeView()->GetRootWindow()));
1874 if (!menu_model) 1872 if (!menu_model)
1875 return; 1873 return;
1876 1874
1877 base::AutoReset<LauncherID> reseter( 1875 base::AutoReset<ShelfID> reseter(
1878 &context_menu_id_, 1876 &context_menu_id_,
1879 view_index == -1 ? 0 : model_->items()[view_index].id); 1877 view_index == -1 ? 0 : model_->items()[view_index].id);
1880 1878
1881 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1879 ShowMenu(scoped_ptr<views::MenuModelAdapter>(
1882 new views::MenuModelAdapter(menu_model.get())), 1880 new views::MenuModelAdapter(menu_model.get())),
1883 source, 1881 source,
1884 point, 1882 point,
1885 true, 1883 true,
1886 source_type); 1884 source_type);
1887 } 1885 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 return true; 2004 return true;
2007 2005
2008 base::TimeDelta delta = 2006 base::TimeDelta delta =
2009 base::TimeDelta(event.time_stamp() - closing_event_time_); 2007 base::TimeDelta(event.time_stamp() - closing_event_time_);
2010 closing_event_time_ = base::TimeDelta(); 2008 closing_event_time_ = base::TimeDelta();
2011 // TODO(skuhne): This time seems excessive, but it appears that the reposting 2009 // TODO(skuhne): This time seems excessive, but it appears that the reposting
2012 // takes that long. Need to come up with a better way of doing this. 2010 // takes that long. Need to come up with a better way of doing this.
2013 return (delta.InMilliseconds() < 0 || delta.InMilliseconds() > 130); 2011 return (delta.InMilliseconds() < 0 || delta.InMilliseconds() > 130);
2014 } 2012 }
2015 2013
2016 const LauncherItem* ShelfView::LauncherItemForView( 2014 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const {
2017 const views::View* view) const {
2018 int view_index = view_model_->GetIndexOfView(view); 2015 int view_index = view_model_->GetIndexOfView(view);
2019 if (view_index == -1) 2016 if (view_index == -1)
2020 return NULL; 2017 return NULL;
2021 return &(model_->items()[view_index]); 2018 return &(model_->items()[view_index]);
2022 } 2019 }
2023 2020
2024 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const { 2021 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const {
2025 if (view == GetAppListButtonView() && 2022 if (view == GetAppListButtonView() &&
2026 Shell::GetInstance()->GetAppListWindow()) 2023 Shell::GetInstance()->GetAppListWindow())
2027 return false; 2024 return false;
2028 const LauncherItem* item = LauncherItemForView(view); 2025 const ShelfItem* item = ShelfItemForView(view);
2029 if (!item) 2026 if (!item)
2030 return true; 2027 return true;
2031 ShelfItemDelegate* item_delegate = 2028 ShelfItemDelegate* item_delegate =
2032 item_manager_->GetShelfItemDelegate(item->id); 2029 item_manager_->GetShelfItemDelegate(item->id);
2033 return item_delegate->ShouldShowTooltip(); 2030 return item_delegate->ShouldShowTooltip();
2034 } 2031 }
2035 2032
2036 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 2033 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
2037 ShelfWidget* shelf = RootWindowController::ForShelf( 2034 ShelfWidget* shelf = RootWindowController::ForShelf(
2038 GetWidget()->GetNativeView())->shelf(); 2035 GetWidget()->GetNativeView())->shelf();
(...skipping 12 matching lines...) Expand all
2051 break; 2048 break;
2052 case SHELF_ALIGNMENT_TOP: 2049 case SHELF_ALIGNMENT_TOP:
2053 distance = coordinate.y() - bounds.bottom(); 2050 distance = coordinate.y() - bounds.bottom();
2054 break; 2051 break;
2055 } 2052 }
2056 return distance > 0 ? distance : 0; 2053 return distance > 0 ? distance : 0;
2057 } 2054 }
2058 2055
2059 } // namespace internal 2056 } // namespace internal
2060 } // namespace ash 2057 } // 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