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

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: 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 dnd_item_created_(false),
383 dnd_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 if (dnd_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 dnd_item_created_ = false;
540 dnd_app_id_ = app_id;
541 dnd_launcher_id_ = delegate_->GetLauncherIDForAppID(dnd_app_id_);
542
543 if (!dnd_launcher_id_) {
544 delegate_->PinAppWithID(app_id);
545 dnd_launcher_id_ = delegate_->GetLauncherIDForAppID(dnd_app_id_);
546 if (!dnd_launcher_id_)
547 return false;
548 dnd_item_created_ = true;
549 }
550 views::View* dnd_view = view_model_->view_at(
551 model_->ItemIndexByID(dnd_launcher_id_));
552 DCHECK(dnd_view);
553
554 // Since there is already an icon presented, we hide this one for now.
555 dnd_view_->SetVisible(false);
556 // First we have to center the mouse cursor over the item.
James Cook 2013/04/29 22:08:29 I don't understand this comment. Isn't the code s
Mr4D (OOO till 08-26) 2013/04/30 16:59:01 Done.
557 gfx::Point pt = dnd_view->GetBoundsInScreen().CenterPoint();
558 views::View::ConvertPointFromScreen(dnd_view, &pt);
559 ui::MouseEvent event(ui::ET_MOUSE_PRESSED,
560 pt, location_in_screen_coordinates, 0);
561 PointerPressedOnButton(dnd_view, LauncherButtonHost::DND, event);
562
563 // Drag the item where it really belongs.
564 Drag(location_in_screen_coordinates);
565 return true;
566 }
567
568 bool LauncherView::Drag(const gfx::Point& location_in_screen_coordinates) {
569 if (!dnd_launcher_id_ ||
570 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
571 return false;
572
573 gfx::Point pt = location_in_screen_coordinates;
574 views::View* dnd_view = view_model_->view_at(
James Cook 2013/04/29 22:08:29 Do you need to check if this is NULL? What if you
Mr4D (OOO till 08-26) 2013/04/30 16:59:01 Good one! I updated this!
575 model_->ItemIndexByID(dnd_launcher_id_));
576 views::View::ConvertPointFromScreen(dnd_view, &pt);
577
578 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, gfx::Point(), 0);
579 PointerDraggedOnButton(dnd_view, LauncherButtonHost::DND, event);
580 return true;
581 }
582
583 void LauncherView::EndDrag(bool cancel) {
584 if (!dnd_launcher_id_)
585 return;
586
587 views::View* dnd_view = view_model_->view_at(
588 model_->ItemIndexByID(dnd_launcher_id_));
589 PointerReleasedOnButton(dnd_view, LauncherButtonHost::DND, cancel);
590
591 if (dnd_item_created_ && cancel)
592 delegate_->UnpinAppsWithID(dnd_app_id_);
593
594 if (dnd_view)
595 dnd_view->SetVisible(true);
596
597 dnd_launcher_id_ = 0;
598 }
599
526 void LauncherView::LayoutToIdealBounds() { 600 void LauncherView::LayoutToIdealBounds() {
527 IdealBounds ideal_bounds; 601 IdealBounds ideal_bounds;
528 CalculateIdealBounds(&ideal_bounds); 602 CalculateIdealBounds(&ideal_bounds);
529 603
530 if (bounds_animator_->IsAnimating()) 604 if (bounds_animator_->IsAnimating())
531 AnimateToIdealBounds(); 605 AnimateToIdealBounds();
532 else 606 else
533 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 607 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
534 608
535 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); 609 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds);
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 return; 1407 return;
1334 1408
1335 { 1409 {
1336 // Slow down activation animations if shift key is pressed. 1410 // Slow down activation animations if shift key is pressed.
1337 scoped_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; 1411 scoped_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations;
1338 if (event.IsShiftDown()) { 1412 if (event.IsShiftDown()) {
1339 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( 1413 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode(
1340 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); 1414 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
1341 } 1415 }
1342 1416
1343 // Collect usage statistics before we decide what to do with the click. 1417 // Collect usage statistics before we decide what to do with the click.
1344 switch (model_->items()[view_index].type) { 1418 switch (model_->items()[view_index].type) {
1345 case TYPE_APP_SHORTCUT: 1419 case TYPE_APP_SHORTCUT:
1346 case TYPE_WINDOWED_APP: 1420 case TYPE_WINDOWED_APP:
1347 case TYPE_PLATFORM_APP: 1421 case TYPE_PLATFORM_APP:
1348 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1422 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1349 UMA_LAUNCHER_CLICK_ON_APP); 1423 UMA_LAUNCHER_CLICK_ON_APP);
1350 // Fallthrough 1424 // Fallthrough
1351 case TYPE_TABBED: 1425 case TYPE_TABBED:
1352 case TYPE_APP_PANEL: 1426 case TYPE_APP_PANEL:
1353 delegate_->ItemClicked(model_->items()[view_index], event); 1427 delegate_->ItemClicked(model_->items()[view_index], event);
1354 break; 1428 break;
1355 1429
1356 case TYPE_APP_LIST: 1430 case TYPE_APP_LIST:
1357 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1431 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1358 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); 1432 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON);
1359 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView()); 1433 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView());
1360 break; 1434 // By setting us as DnD recipient, the app list knows that we can
1435 // handle items.
1436 // TODO(skuhne): Invert the flag
1437 if (!CommandLine::ForCurrentProcess()->HasSwitch(
James Cook 2013/04/29 22:08:29 Did you want to invert this test before committing
Mr4D (OOO till 08-26) 2013/04/30 16:59:01 Done. (yes in deed - for some reason flags do not
1438 ash::switches::kAshDnDAppListToLauncher))
1439 Shell::GetInstance()->SetAppListDnDHost(this);
James Cook 2013/04/29 22:08:29 Can this be done once in the constructor or in Ini
Mr4D (OOO till 08-26) 2013/04/30 16:59:01 Since the application list is created upon every c
1440 break;
1361 1441
1362 case TYPE_BROWSER_SHORTCUT: 1442 case TYPE_BROWSER_SHORTCUT:
1363 // Click on browser icon is counted in app clicks. 1443 // Click on browser icon is counted in app clicks.
1364 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1444 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1365 UMA_LAUNCHER_CLICK_ON_APP); 1445 UMA_LAUNCHER_CLICK_ON_APP);
1366 delegate_->OnBrowserShortcutClicked(event.flags()); 1446 delegate_->OnBrowserShortcutClicked(event.flags());
1367 break; 1447 break;
1368 } 1448 }
1369 } 1449 }
1370 1450
1371 if (model_->items()[view_index].type != TYPE_APP_LIST) 1451 if (model_->items()[view_index].type != TYPE_APP_LIST)
1372 ShowListMenuForView(model_->items()[view_index], sender, event.flags()); 1452 ShowListMenuForView(model_->items()[view_index], sender, event.flags());
1373 } 1453 }
1374 1454
1375 bool LauncherView::ShowListMenuForView(const LauncherItem& item, 1455 bool LauncherView::ShowListMenuForView(const LauncherItem& item,
1376 views::View* source, 1456 views::View* source,
1377 int event_flags) { 1457 int event_flags) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { 1602 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const {
1523 if (view == GetAppListButtonView() && 1603 if (view == GetAppListButtonView() &&
1524 Shell::GetInstance()->GetAppListWindow()) 1604 Shell::GetInstance()->GetAppListWindow())
1525 return false; 1605 return false;
1526 const LauncherItem* item = LauncherItemForView(view); 1606 const LauncherItem* item = LauncherItemForView(view);
1527 return (!item || delegate_->ShouldShowTooltip(*item)); 1607 return (!item || delegate_->ShouldShowTooltip(*item));
1528 } 1608 }
1529 1609
1530 } // namespace internal 1610 } // namespace internal
1531 } // namespace ash 1611 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698