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

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: Merged & 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
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.
koz (OOO until 15th September) 2013/05/08 02:00:39 Under what circumstances can a second drag start b
Mr4D (OOO till 08-26) 2013/05/08 02:53:35 Done.
532 if (drag_and_drop_launcher_id_ ||
533 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
534 return false;
535
536 // If the AppsGridView (which was dispatching this event) was opened by our
537 // button, LauncherView dragging operations are locked and we have to unlock.
538 CancelDrag(-1);
539 drag_and_drop_item_created_ = false;
540 drag_and_drop_app_id_ = app_id;
541 drag_and_drop_launcher_id_ =
542 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_);
543
544 if (!drag_and_drop_launcher_id_) {
545 delegate_->PinAppWithID(app_id);
546 drag_and_drop_launcher_id_ =
547 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_);
548 if (!drag_and_drop_launcher_id_)
549 return false;
550 drag_and_drop_item_created_ = true;
551 }
552 views::View* drag_and_drop_view = view_model_->view_at(
553 model_->ItemIndexByID(drag_and_drop_launcher_id_));
554 DCHECK(drag_and_drop_view);
555
556 // Since there is already an icon presented, we hide this one for now.
557 drag_and_drop_view->SetVisible(false);
558 // First we have to center the mouse cursor over the item.
559 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint();
560 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt);
561 ui::MouseEvent event(ui::ET_MOUSE_PRESSED,
562 pt, location_in_screen_coordinates, 0);
563 PointerPressedOnButton(
564 drag_and_drop_view, LauncherButtonHost::DRAG_AND_DROP, event);
565
566 // Drag the item where it really belongs.
567 Drag(location_in_screen_coordinates);
568 return true;
569 }
570
571 bool LauncherView::Drag(const gfx::Point& location_in_screen_coordinates) {
572 if (!drag_and_drop_launcher_id_ ||
573 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
574 return false;
575
576 gfx::Point pt = location_in_screen_coordinates;
577 views::View* drag_and_drop_view = view_model_->view_at(
578 model_->ItemIndexByID(drag_and_drop_launcher_id_));
579 views::View::ConvertPointFromScreen(drag_and_drop_view, &pt);
580
581 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, gfx::Point(), 0);
582 PointerDraggedOnButton(
583 drag_and_drop_view, LauncherButtonHost::DRAG_AND_DROP, event);
584 return true;
585 }
586
587 void LauncherView::EndDrag(bool cancel) {
588 if (!drag_and_drop_launcher_id_)
589 return;
590
591 views::View* drag_and_drop_view = view_model_->view_at(
592 model_->ItemIndexByID(drag_and_drop_launcher_id_));
593 PointerReleasedOnButton(
594 drag_and_drop_view, LauncherButtonHost::DRAG_AND_DROP, cancel);
595
596 if (drag_and_drop_item_created_ && cancel)
597 delegate_->UnpinAppsWithID(drag_and_drop_app_id_);
598
599 if (drag_and_drop_view)
600 drag_and_drop_view->SetVisible(true);
601
602 drag_and_drop_launcher_id_ = 0;
603 }
604
526 void LauncherView::LayoutToIdealBounds() { 605 void LauncherView::LayoutToIdealBounds() {
527 IdealBounds ideal_bounds; 606 IdealBounds ideal_bounds;
528 CalculateIdealBounds(&ideal_bounds); 607 CalculateIdealBounds(&ideal_bounds);
529 608
530 if (bounds_animator_->IsAnimating()) 609 if (bounds_animator_->IsAnimating())
531 AnimateToIdealBounds(); 610 AnimateToIdealBounds();
532 else 611 else
533 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 612 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
534 613
535 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); 614 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds);
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 return; 1412 return;
1334 1413
1335 { 1414 {
1336 // Slow down activation animations if shift key is pressed. 1415 // Slow down activation animations if shift key is pressed.
1337 scoped_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; 1416 scoped_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations;
1338 if (event.IsShiftDown()) { 1417 if (event.IsShiftDown()) {
1339 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( 1418 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode(
1340 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); 1419 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
1341 } 1420 }
1342 1421
1343 // Collect usage statistics before we decide what to do with the click. 1422 // Collect usage statistics before we decide what to do with the click.
1344 switch (model_->items()[view_index].type) { 1423 switch (model_->items()[view_index].type) {
1345 case TYPE_APP_SHORTCUT: 1424 case TYPE_APP_SHORTCUT:
1346 case TYPE_WINDOWED_APP: 1425 case TYPE_WINDOWED_APP:
1347 case TYPE_PLATFORM_APP: 1426 case TYPE_PLATFORM_APP:
1348 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1427 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1349 UMA_LAUNCHER_CLICK_ON_APP); 1428 UMA_LAUNCHER_CLICK_ON_APP);
1350 // Fallthrough 1429 // Fallthrough
1351 case TYPE_TABBED: 1430 case TYPE_TABBED:
1352 case TYPE_APP_PANEL: 1431 case TYPE_APP_PANEL:
1353 delegate_->ItemSelected(model_->items()[view_index], event); 1432 delegate_->ItemSelected(model_->items()[view_index], event);
1354 break; 1433 break;
1355 1434
1356 case TYPE_APP_LIST: 1435 case TYPE_APP_LIST:
1357 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1436 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1358 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); 1437 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON);
1359 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView()); 1438 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView());
1360 break; 1439 // By setting us as DnD recipient, the app list knows that we can
1440 // handle items.
1441 // TODO(skuhne): Invert the flag
1442 if (CommandLine::ForCurrentProcess()->HasSwitch(
1443 ash::switches::kAshDragAndDropAppListToLauncher))
1444 Shell::GetInstance()->SetDragAndDropHostOfCurrentAppList(this);
1445 break;
1361 1446
1362 case TYPE_BROWSER_SHORTCUT: 1447 case TYPE_BROWSER_SHORTCUT:
1363 // Click on browser icon is counted in app clicks. 1448 // Click on browser icon is counted in app clicks.
1364 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1449 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1365 UMA_LAUNCHER_CLICK_ON_APP); 1450 UMA_LAUNCHER_CLICK_ON_APP);
1366 delegate_->OnBrowserShortcutClicked(event.flags()); 1451 delegate_->OnBrowserShortcutClicked(event.flags());
1367 break; 1452 break;
1368 } 1453 }
1369 } 1454 }
1370 1455
1371 if (model_->items()[view_index].type != TYPE_APP_LIST) 1456 if (model_->items()[view_index].type != TYPE_APP_LIST)
1372 ShowListMenuForView(model_->items()[view_index], sender, event.flags()); 1457 ShowListMenuForView(model_->items()[view_index], sender, event.flags());
1373 } 1458 }
1374 1459
1375 bool LauncherView::ShowListMenuForView(const LauncherItem& item, 1460 bool LauncherView::ShowListMenuForView(const LauncherItem& item,
1376 views::View* source, 1461 views::View* source,
1377 int event_flags) { 1462 int event_flags) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { 1607 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const {
1523 if (view == GetAppListButtonView() && 1608 if (view == GetAppListButtonView() &&
1524 Shell::GetInstance()->GetAppListWindow()) 1609 Shell::GetInstance()->GetAppListWindow())
1525 return false; 1610 return false;
1526 const LauncherItem* item = LauncherItemForView(view); 1611 const LauncherItem* item = LauncherItemForView(view);
1527 return (!item || delegate_->ShouldShowTooltip(*item)); 1612 return (!item || delegate_->ShouldShowTooltip(*item));
1528 } 1613 }
1529 1614
1530 } // namespace internal 1615 } // namespace internal
1531 } // namespace ash 1616 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698