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

Side by Side Diff: ash/launcher/launcher_view.cc

Issue 14533006: Drag and drop between app list and launcher - First patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Created 7 years, 7 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/launcher/launcher_view.h ('k') | ash/shell.h » ('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/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/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/launcher/app_list_button.h" 11 #include "ash/launcher/app_list_button.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_icon_observer.h" 14 #include "ash/launcher/launcher_icon_observer.h"
15 #include "ash/launcher/launcher_model.h" 15 #include "ash/launcher/launcher_model.h"
16 #include "ash/launcher/launcher_tooltip_manager.h" 16 #include "ash/launcher/launcher_tooltip_manager.h"
17 #include "ash/launcher/overflow_bubble.h" 17 #include "ash/launcher/overflow_bubble.h"
18 #include "ash/launcher/overflow_button.h" 18 #include "ash/launcher/overflow_button.h"
19 #include "ash/launcher/tabbed_launcher_button.h" 19 #include "ash/launcher/tabbed_launcher_button.h"
20 #include "ash/root_window_controller.h" 20 #include "ash/root_window_controller.h"
21 #include "ash/shelf/shelf_layout_manager.h" 21 #include "ash/shelf/shelf_layout_manager.h"
22 #include "ash/shelf/shelf_widget.h" 22 #include "ash/shelf/shelf_widget.h"
23 #include "ash/shell_delegate.h" 23 #include "ash/shell_delegate.h"
24 #include "base/auto_reset.h" 24 #include "base/auto_reset.h"
25 #include "base/command_line.h"
25 #include "base/memory/scoped_ptr.h" 26 #include "base/memory/scoped_ptr.h"
26 #include "grit/ash_resources.h" 27 #include "grit/ash_resources.h"
27 #include "grit/ash_strings.h" 28 #include "grit/ash_strings.h"
28 #include "ui/aura/window.h" 29 #include "ui/aura/window.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/models/simple_menu_model.h" 31 #include "ui/base/models/simple_menu_model.h"
31 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/compositor/layer.h" 33 #include "ui/compositor/layer.h"
33 #include "ui/compositor/layer_animator.h" 34 #include "ui/compositor/layer_animator.h"
34 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 35 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 overflow_button_(NULL), 371 overflow_button_(NULL),
371 drag_pointer_(NONE), 372 drag_pointer_(NONE),
372 drag_view_(NULL), 373 drag_view_(NULL),
373 drag_offset_(0), 374 drag_offset_(0),
374 start_drag_index_(-1), 375 start_drag_index_(-1),
375 context_menu_id_(0), 376 context_menu_id_(0),
376 leading_inset_(kDefaultLeadingInset), 377 leading_inset_(kDefaultLeadingInset),
377 cancelling_drag_model_changed_(false), 378 cancelling_drag_model_changed_(false),
378 last_hidden_index_(0), 379 last_hidden_index_(0),
379 closing_event_time_(base::TimeDelta()), 380 closing_event_time_(base::TimeDelta()),
380 got_deleted_(NULL) { 381 got_deleted_(NULL),
382 drag_and_drop_item_created_(false),
383 drag_and_drop_launcher_id_(0) {
381 DCHECK(model_); 384 DCHECK(model_);
382 bounds_animator_.reset(new views::BoundsAnimator(this)); 385 bounds_animator_.reset(new views::BoundsAnimator(this));
383 bounds_animator_->AddObserver(this); 386 bounds_animator_->AddObserver(this);
384 set_context_menu_controller(this); 387 set_context_menu_controller(this);
385 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); 388 focus_search_.reset(new LauncherFocusSearch(view_model_.get()));
386 tooltip_.reset(new LauncherTooltipManager( 389 tooltip_.reset(new LauncherTooltipManager(
387 shelf_layout_manager, this)); 390 shelf_layout_manager, this));
388 } 391 }
389 392
390 LauncherView::~LauncherView() { 393 LauncherView::~LauncherView() {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 } 519 }
517 520
518 views::FocusTraversable* LauncherView::GetFocusTraversableParent() { 521 views::FocusTraversable* LauncherView::GetFocusTraversableParent() {
519 return parent()->GetFocusTraversable(); 522 return parent()->GetFocusTraversable();
520 } 523 }
521 524
522 View* LauncherView::GetFocusTraversableParentView() { 525 View* LauncherView::GetFocusTraversableParentView() {
523 return this; 526 return this;
524 } 527 }
525 528
529 bool LauncherView::StartDrag(const std::string& app_id,
530 const gfx::Point& location_in_screen_coordinates) {
531 // Bail if an operation is already going on - or the cursor is not inside.
532 // This could happen if mouse / touch operations overlap.
533 if (drag_and_drop_launcher_id_ ||
534 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
535 return false;
536
537 // If the AppsGridView (which was dispatching this event) was opened by our
538 // button, LauncherView dragging operations are locked and we have to unlock.
539 CancelDrag(-1);
540 drag_and_drop_item_created_ = false;
541 drag_and_drop_app_id_ = app_id;
542 drag_and_drop_launcher_id_ =
543 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_);
544
545 if (!drag_and_drop_launcher_id_) {
546 delegate_->PinAppWithID(app_id);
547 drag_and_drop_launcher_id_ =
548 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_);
549 if (!drag_and_drop_launcher_id_)
550 return false;
551 drag_and_drop_item_created_ = true;
552 }
553 views::View* drag_and_drop_view = view_model_->view_at(
554 model_->ItemIndexByID(drag_and_drop_launcher_id_));
555 DCHECK(drag_and_drop_view);
556
557 // Since there is already an icon presented, we hide this one for now.
558 drag_and_drop_view->SetVisible(false);
559 // First we have to center the mouse cursor over the item.
560 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint();
561 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt);
562 ui::MouseEvent event(ui::ET_MOUSE_PRESSED,
563 pt, location_in_screen_coordinates, 0);
564 PointerPressedOnButton(
565 drag_and_drop_view, LauncherButtonHost::DRAG_AND_DROP, event);
566
567 // Drag the item where it really belongs.
568 Drag(location_in_screen_coordinates);
569 return true;
570 }
571
572 bool LauncherView::Drag(const gfx::Point& location_in_screen_coordinates) {
573 if (!drag_and_drop_launcher_id_ ||
574 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
575 return false;
576
577 gfx::Point pt = location_in_screen_coordinates;
578 views::View* drag_and_drop_view = view_model_->view_at(
579 model_->ItemIndexByID(drag_and_drop_launcher_id_));
580 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt);
581
582 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, gfx::Point(), 0);
583 PointerDraggedOnButton(
584 drag_and_drop_view, LauncherButtonHost::DRAG_AND_DROP, event);
585 return true;
586 }
587
588 void LauncherView::EndDrag(bool cancel) {
589 if (!drag_and_drop_launcher_id_)
590 return;
591
592 views::View* drag_and_drop_view = view_model_->view_at(
593 model_->ItemIndexByID(drag_and_drop_launcher_id_));
594 PointerReleasedOnButton(
595 drag_and_drop_view, LauncherButtonHost::DRAG_AND_DROP, cancel);
596
597 if (drag_and_drop_item_created_ && cancel)
598 delegate_->UnpinAppsWithID(drag_and_drop_app_id_);
599
600 if (drag_and_drop_view)
601 drag_and_drop_view->SetVisible(true);
602
603 drag_and_drop_launcher_id_ = 0;
604 }
605
526 void LauncherView::LayoutToIdealBounds() { 606 void LauncherView::LayoutToIdealBounds() {
527 IdealBounds ideal_bounds; 607 IdealBounds ideal_bounds;
528 CalculateIdealBounds(&ideal_bounds); 608 CalculateIdealBounds(&ideal_bounds);
529 609
530 if (bounds_animator_->IsAnimating()) 610 if (bounds_animator_->IsAnimating())
531 AnimateToIdealBounds(); 611 AnimateToIdealBounds();
532 else 612 else
533 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 613 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
534 614
535 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); 615 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds);
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 return; 1413 return;
1334 1414
1335 { 1415 {
1336 // Slow down activation animations if shift key is pressed. 1416 // Slow down activation animations if shift key is pressed.
1337 scoped_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; 1417 scoped_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations;
1338 if (event.IsShiftDown()) { 1418 if (event.IsShiftDown()) {
1339 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( 1419 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode(
1340 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); 1420 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
1341 } 1421 }
1342 1422
1343 // Collect usage statistics before we decide what to do with the click. 1423 // Collect usage statistics before we decide what to do with the click.
1344 switch (model_->items()[view_index].type) { 1424 switch (model_->items()[view_index].type) {
1345 case TYPE_APP_SHORTCUT: 1425 case TYPE_APP_SHORTCUT:
1346 case TYPE_WINDOWED_APP: 1426 case TYPE_WINDOWED_APP:
1347 case TYPE_PLATFORM_APP: 1427 case TYPE_PLATFORM_APP:
1348 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1428 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1349 UMA_LAUNCHER_CLICK_ON_APP); 1429 UMA_LAUNCHER_CLICK_ON_APP);
1350 // Fallthrough 1430 // Fallthrough
1351 case TYPE_TABBED: 1431 case TYPE_TABBED:
1352 case TYPE_APP_PANEL: 1432 case TYPE_APP_PANEL:
1353 delegate_->ItemSelected(model_->items()[view_index], event); 1433 delegate_->ItemSelected(model_->items()[view_index], event);
1354 break; 1434 break;
1355 1435
1356 case TYPE_APP_LIST: 1436 case TYPE_APP_LIST:
1357 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1437 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1358 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); 1438 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON);
1359 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView()); 1439 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView());
1360 break; 1440 // By setting us as DnD recipient, the app list knows that we can
1441 // handle items.
1442 // TODO(skuhne): Invert the flag
1443 if (CommandLine::ForCurrentProcess()->HasSwitch(
1444 ash::switches::kAshDragAndDropAppListToLauncher))
1445 Shell::GetInstance()->SetDragAndDropHostOfCurrentAppList(this);
xiyuan 2013/05/08 16:43:47 What happens if app list is invoked via shortcut k
1446 break;
1361 1447
1362 case TYPE_BROWSER_SHORTCUT: 1448 case TYPE_BROWSER_SHORTCUT:
1363 // Click on browser icon is counted in app clicks. 1449 // Click on browser icon is counted in app clicks.
1364 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1450 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1365 UMA_LAUNCHER_CLICK_ON_APP); 1451 UMA_LAUNCHER_CLICK_ON_APP);
1366 delegate_->OnBrowserShortcutClicked(event.flags()); 1452 delegate_->OnBrowserShortcutClicked(event.flags());
1367 break; 1453 break;
1368 } 1454 }
1369 } 1455 }
1370 1456
1371 if (model_->items()[view_index].type != TYPE_APP_LIST) 1457 if (model_->items()[view_index].type != TYPE_APP_LIST)
1372 ShowListMenuForView(model_->items()[view_index], sender, event.flags()); 1458 ShowListMenuForView(model_->items()[view_index], sender, event.flags());
1373 } 1459 }
1374 1460
1375 bool LauncherView::ShowListMenuForView(const LauncherItem& item, 1461 bool LauncherView::ShowListMenuForView(const LauncherItem& item,
1376 views::View* source, 1462 views::View* source,
1377 int event_flags) { 1463 int event_flags) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { 1608 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const {
1523 if (view == GetAppListButtonView() && 1609 if (view == GetAppListButtonView() &&
1524 Shell::GetInstance()->GetAppListWindow()) 1610 Shell::GetInstance()->GetAppListWindow())
1525 return false; 1611 return false;
1526 const LauncherItem* item = LauncherItemForView(view); 1612 const LauncherItem* item = LauncherItemForView(view);
1527 return (!item || delegate_->ShouldShowTooltip(*item)); 1613 return (!item || delegate_->ShouldShowTooltip(*item));
1528 } 1614 }
1529 1615
1530 } // namespace internal 1616 } // namespace internal
1531 } // namespace ash 1617 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_view.h ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698