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

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

Issue 11434099: Use the correct launcher assets for shelf alignment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years 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/launcher/launcher_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/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/launcher/app_list_button.h" 10 #include "ash/launcher/app_list_button.h"
11 #include "ash/launcher/launcher_button.h" 11 #include "ash/launcher/launcher_button.h"
12 #include "ash/launcher/launcher_delegate.h" 12 #include "ash/launcher/launcher_delegate.h"
13 #include "ash/launcher/launcher_icon_observer.h" 13 #include "ash/launcher/launcher_icon_observer.h"
14 #include "ash/launcher/launcher_model.h" 14 #include "ash/launcher/launcher_model.h"
15 #include "ash/launcher/launcher_tooltip_manager.h" 15 #include "ash/launcher/launcher_tooltip_manager.h"
16 #include "ash/launcher/overflow_bubble.h" 16 #include "ash/launcher/overflow_bubble.h"
17 #include "ash/launcher/overflow_button.h" 17 #include "ash/launcher/overflow_button.h"
18 #include "ash/launcher/tabbed_launcher_button.h" 18 #include "ash/launcher/tabbed_launcher_button.h"
19 #include "ash/shell.h"
20 #include "ash/shell_delegate.h" 19 #include "ash/shell_delegate.h"
20 #include "ash/wm/shelf_layout_manager.h"
21 #include "base/auto_reset.h" 21 #include "base/auto_reset.h"
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "grit/ash_strings.h" 23 #include "grit/ash_strings.h"
24 #include "grit/ash_resources.h" 24 #include "grit/ash_resources.h"
25 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/models/simple_menu_model.h" 27 #include "ui/base/models/simple_menu_model.h"
28 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/compositor/layer.h" 29 #include "ui/compositor/layer.h"
30 #include "ui/compositor/layer_animator.h" 30 #include "ui/compositor/layer_animator.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 delegate_(delegate), 275 delegate_(delegate),
276 view_model_(new views::ViewModel), 276 view_model_(new views::ViewModel),
277 first_visible_index_(0), 277 first_visible_index_(0),
278 last_visible_index_(-1), 278 last_visible_index_(-1),
279 overflow_button_(NULL), 279 overflow_button_(NULL),
280 drag_pointer_(NONE), 280 drag_pointer_(NONE),
281 drag_view_(NULL), 281 drag_view_(NULL),
282 drag_offset_(0), 282 drag_offset_(0),
283 start_drag_index_(-1), 283 start_drag_index_(-1),
284 context_menu_id_(0), 284 context_menu_id_(0),
285 alignment_(SHELF_ALIGNMENT_BOTTOM),
286 leading_inset_(kDefaultLeadingInset) { 285 leading_inset_(kDefaultLeadingInset) {
287 DCHECK(model_); 286 DCHECK(model_);
288 bounds_animator_.reset(new views::BoundsAnimator(this)); 287 bounds_animator_.reset(new views::BoundsAnimator(this));
289 bounds_animator_->AddObserver(this); 288 bounds_animator_->AddObserver(this);
290 set_context_menu_controller(this); 289 set_context_menu_controller(this);
291 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); 290 focus_search_.reset(new LauncherFocusSearch(view_model_.get()));
292 tooltip_.reset(new LauncherTooltipManager( 291 tooltip_.reset(new LauncherTooltipManager(
293 alignment_, shelf_layout_manager, this)); 292 shelf_layout_manager, this));
294 } 293 }
295 294
296 LauncherView::~LauncherView() { 295 LauncherView::~LauncherView() {
297 bounds_animator_->RemoveObserver(this); 296 bounds_animator_->RemoveObserver(this);
298 model_->RemoveObserver(this); 297 model_->RemoveObserver(this);
299 } 298 }
300 299
301 void LauncherView::Init() { 300 void LauncherView::Init() {
302 model_->AddObserver(this); 301 model_->AddObserver(this);
303 302
(...skipping 13 matching lines...) Expand all
317 AddChildView(overflow_button_); 316 AddChildView(overflow_button_);
318 317
319 // We'll layout when our bounds change. 318 // We'll layout when our bounds change.
320 } 319 }
321 320
322 void LauncherView::SetAlignment(ShelfAlignment alignment) { 321 void LauncherView::SetAlignment(ShelfAlignment alignment) {
323 if (alignment_ == alignment) 322 if (alignment_ == alignment)
324 return; 323 return;
325 alignment_ = alignment; 324 alignment_ = alignment;
326 UpdateFirstButtonPadding(); 325 UpdateFirstButtonPadding();
327 overflow_button_->SetShelfAlignment(alignment_); 326 overflow_button_->OnShelfAlignmentChanged();
328 LayoutToIdealBounds(); 327 LayoutToIdealBounds();
329 tooltip_->SetArrowLocation(alignment_); 328 tooltip_->UpdateArrowLocation();
330 if (overflow_bubble_.get()) 329 if (overflow_bubble_.get())
331 overflow_bubble_->Hide(); 330 overflow_bubble_->Hide();
332 } 331 }
333 332
334 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) { 333 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) {
335 int index = model_->ItemIndexByID(id); 334 int index = model_->ItemIndexByID(id);
336 if (index == -1 || index > last_visible_index_) 335 if (index == -1 || index > last_visible_index_)
337 return gfx::Rect(); 336 return gfx::Rect();
338 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); 337 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index));
339 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); 338 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 387
389 if (bounds_animator_->IsAnimating()) 388 if (bounds_animator_->IsAnimating())
390 AnimateToIdealBounds(); 389 AnimateToIdealBounds();
391 else 390 else
392 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 391 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
393 392
394 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); 393 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds);
395 } 394 }
396 395
397 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { 396 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) {
398 int available_size = primary_axis_coordinate(width(), height()); 397 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
398
399 int available_size = shelf->PrimaryAxisValue(width(), height());
399 if (!available_size) 400 if (!available_size)
400 return; 401 return;
401 402
402 // Initial x,y values account both leading_inset in primary 403 // Initial x,y values account both leading_inset in primary
403 // coordinate and secondary coordinate based on the dynamic edge of the 404 // coordinate and secondary coordinate based on the dynamic edge of the
404 // launcher (eg top edge on bottom-aligned launcher). 405 // launcher (eg top edge on bottom-aligned launcher).
405 int x = alignment_based_value(leading_inset(), 406 int x = shelf->SelectValueForShelfAlignment(
407 leading_inset(),
406 width() - kLauncherPreferredSize, 408 width() - kLauncherPreferredSize,
407 std::max(width() - kLauncherPreferredSize, 409 std::max(width() - kLauncherPreferredSize,
408 ShelfLayoutManager::kAutoHideSize + 1)); 410 ShelfLayoutManager::kAutoHideSize + 1));
409 int y = primary_axis_coordinate(0, leading_inset()); 411 int y = shelf->PrimaryAxisValue(0, leading_inset());
410 for (int i = 0; i < view_model_->view_size(); ++i) { 412 for (int i = 0; i < view_model_->view_size(); ++i) {
411 if (i < first_visible_index_) { 413 if (i < first_visible_index_) {
412 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); 414 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0));
413 continue; 415 continue;
414 } 416 }
415 417
416 int w = primary_axis_coordinate(kLauncherPreferredSize, width()); 418 int w = shelf->PrimaryAxisValue(kLauncherPreferredSize, width());
417 int h = primary_axis_coordinate(height(), kLauncherPreferredSize); 419 int h = shelf->PrimaryAxisValue(height(), kLauncherPreferredSize);
418 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 420 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
419 x = primary_axis_coordinate(x + w + kButtonSpacing, x); 421 x = shelf->PrimaryAxisValue(x + w + kButtonSpacing, x);
420 y = primary_axis_coordinate(y, y + h + kButtonSpacing); 422 y = shelf->PrimaryAxisValue(y, y + h + kButtonSpacing);
421 } 423 }
422 424
423 int app_list_index = view_model_->view_size() - 1; 425 int app_list_index = view_model_->view_size() - 1;
424 if (is_overflow_mode()) { 426 if (is_overflow_mode()) {
425 last_visible_index_ = app_list_index - 1; 427 last_visible_index_ = app_list_index - 1;
426 for (int i = 0; i < view_model_->view_size(); ++i) { 428 for (int i = 0; i < view_model_->view_size(); ++i) {
427 view_model_->view_at(i)->SetVisible( 429 view_model_->view_at(i)->SetVisible(
428 i >= first_visible_index_ && i <= last_visible_index_); 430 i >= first_visible_index_ && i <= last_visible_index_);
429 } 431 }
430 return; 432 return;
431 } 433 }
432 434
433 bounds->overflow_bounds.set_size(gfx::Size( 435 bounds->overflow_bounds.set_size(gfx::Size(
434 primary_axis_coordinate(kLauncherPreferredSize, width()), 436 shelf->PrimaryAxisValue(kLauncherPreferredSize, width()),
435 primary_axis_coordinate(height(), kLauncherPreferredSize))); 437 shelf->PrimaryAxisValue(height(), kLauncherPreferredSize)));
436 last_visible_index_ = DetermineLastVisibleIndex( 438 last_visible_index_ = DetermineLastVisibleIndex(
437 available_size - leading_inset() - kLauncherPreferredSize - 439 available_size - leading_inset() - kLauncherPreferredSize -
438 kButtonSpacing - kLauncherPreferredSize); 440 kButtonSpacing - kLauncherPreferredSize);
439 bool show_overflow = (last_visible_index_ + 1 < app_list_index); 441 bool show_overflow = (last_visible_index_ + 1 < app_list_index);
440 442
441 for (int i = 0; i < view_model_->view_size(); ++i) { 443 for (int i = 0; i < view_model_->view_size(); ++i) {
442 view_model_->view_at(i)->SetVisible( 444 view_model_->view_at(i)->SetVisible(
443 i == app_list_index || i <= last_visible_index_); 445 i == app_list_index || i <= last_visible_index_);
444 } 446 }
445 447
446 overflow_button_->SetVisible(show_overflow); 448 overflow_button_->SetVisible(show_overflow);
447 if (show_overflow) { 449 if (show_overflow) {
448 DCHECK_NE(0, view_model_->view_size()); 450 DCHECK_NE(0, view_model_->view_size());
449 if (last_visible_index_ == -1) { 451 if (last_visible_index_ == -1) {
450 x = alignment_based_value(leading_inset(), 452 x = shelf->SelectValueForShelfAlignment(
451 width() - kLauncherPreferredSize, 453 leading_inset(),
452 std::max(width() - kLauncherPreferredSize, 454 width() - kLauncherPreferredSize,
453 ShelfLayoutManager::kAutoHideSize + 1)); 455 std::max(width() - kLauncherPreferredSize,
454 y = primary_axis_coordinate(0, leading_inset()); 456 ShelfLayoutManager::kAutoHideSize + 1));
457 y = shelf->PrimaryAxisValue(0, leading_inset());
455 } else { 458 } else {
456 x = primary_axis_coordinate( 459 x = shelf->PrimaryAxisValue(
457 view_model_->ideal_bounds(last_visible_index_).right(), 460 view_model_->ideal_bounds(last_visible_index_).right(),
458 view_model_->ideal_bounds(last_visible_index_).x()); 461 view_model_->ideal_bounds(last_visible_index_).x());
459 y = primary_axis_coordinate( 462 y = shelf->PrimaryAxisValue(
460 view_model_->ideal_bounds(last_visible_index_).y(), 463 view_model_->ideal_bounds(last_visible_index_).y(),
461 view_model_->ideal_bounds(last_visible_index_).bottom()); 464 view_model_->ideal_bounds(last_visible_index_).bottom());
462 } 465 }
463 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); 466 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index);
464 bounds->overflow_bounds.set_x(x); 467 bounds->overflow_bounds.set_x(x);
465 bounds->overflow_bounds.set_y(y); 468 bounds->overflow_bounds.set_y(y);
466 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, x); 469 x = shelf->PrimaryAxisValue(x + kLauncherPreferredSize + kButtonSpacing, x);
467 y = primary_axis_coordinate(y, y + kLauncherPreferredSize + kButtonSpacing); 470 y = shelf->PrimaryAxisValue(y, y + kLauncherPreferredSize + kButtonSpacing);
468 app_list_bounds.set_x(x); 471 app_list_bounds.set_x(x);
469 app_list_bounds.set_y(y); 472 app_list_bounds.set_y(y);
470 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); 473 view_model_->set_ideal_bounds(app_list_index, app_list_bounds);
471 } else { 474 } else {
472 if (overflow_bubble_.get()) 475 if (overflow_bubble_.get())
473 overflow_bubble_->Hide(); 476 overflow_bubble_->Hide();
474 } 477 }
475 } 478 }
476 479
477 int LauncherView::DetermineLastVisibleIndex(int max_value) { 480 int LauncherView::DetermineLastVisibleIndex(int max_value) {
481 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
482
478 int index = view_model_->view_size() - 1; 483 int index = view_model_->view_size() - 1;
479 while (index >= 0 && 484 while (index >= 0 &&
480 primary_axis_coordinate( 485 shelf->PrimaryAxisValue(
481 view_model_->ideal_bounds(index).right(), 486 view_model_->ideal_bounds(index).right(),
482 view_model_->ideal_bounds(index).bottom()) > max_value) { 487 view_model_->ideal_bounds(index).bottom()) > max_value) {
483 index--; 488 index--;
484 } 489 }
485 return index; 490 return index;
486 } 491 }
487 492
488 void LauncherView::AddIconObserver(LauncherIconObserver* observer) { 493 void LauncherView::AddIconObserver(LauncherIconObserver* observer) {
489 observers_.AddObserver(observer); 494 observers_.AddObserver(observer);
490 } 495 }
(...skipping 13 matching lines...) Expand all
504 } 509 }
505 510
506 views::View* LauncherView::CreateViewForItem(const LauncherItem& item) { 511 views::View* LauncherView::CreateViewForItem(const LauncherItem& item) {
507 views::View* view = NULL; 512 views::View* view = NULL;
508 switch (item.type) { 513 switch (item.type) {
509 case TYPE_TABBED: { 514 case TYPE_TABBED: {
510 TabbedLauncherButton* button = 515 TabbedLauncherButton* button =
511 TabbedLauncherButton::Create( 516 TabbedLauncherButton::Create(
512 this, 517 this,
513 this, 518 this,
519 tooltip_->shelf_layout_manager(),
514 item.is_incognito ? 520 item.is_incognito ?
515 TabbedLauncherButton::STATE_INCOGNITO : 521 TabbedLauncherButton::STATE_INCOGNITO :
516 TabbedLauncherButton::STATE_NOT_INCOGNITO); 522 TabbedLauncherButton::STATE_NOT_INCOGNITO);
517 button->SetTabImage(item.image); 523 button->SetTabImage(item.image);
518 ReflectItemStatus(item, button); 524 ReflectItemStatus(item, button);
519 view = button; 525 view = button;
520 break; 526 break;
521 } 527 }
522 528
523 case TYPE_APP_SHORTCUT: 529 case TYPE_APP_SHORTCUT:
524 case TYPE_PLATFORM_APP: 530 case TYPE_PLATFORM_APP:
525 case TYPE_APP_PANEL: { 531 case TYPE_APP_PANEL: {
526 LauncherButton* button = LauncherButton::Create(this, this); 532 LauncherButton* button = LauncherButton::Create(
533 this, this, tooltip_->shelf_layout_manager());
527 button->SetImage(item.image); 534 button->SetImage(item.image);
528 ReflectItemStatus(item, button); 535 ReflectItemStatus(item, button);
529 view = button; 536 view = button;
530 break; 537 break;
531 } 538 }
532 539
533 case TYPE_APP_LIST: { 540 case TYPE_APP_LIST: {
534 // TODO(dave): turn this into a LauncherButton too. 541 // TODO(dave): turn this into a LauncherButton too.
535 AppListButton* button = new AppListButton(this, this); 542 AppListButton* button = new AppListButton(this, this);
536 view = button; 543 view = button;
537 break; 544 break;
538 } 545 }
539 546
540 case TYPE_BROWSER_SHORTCUT: { 547 case TYPE_BROWSER_SHORTCUT: {
541 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 548 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
542 LauncherButton* button = LauncherButton::Create(this, this); 549 LauncherButton* button = LauncherButton::Create(
550 this, this, tooltip_->shelf_layout_manager());
543 int image_id = delegate_ ? 551 int image_id = delegate_ ?
544 delegate_->GetBrowserShortcutResourceId() : 552 delegate_->GetBrowserShortcutResourceId() :
545 IDR_AURA_LAUNCHER_BROWSER_SHORTCUT; 553 IDR_AURA_LAUNCHER_BROWSER_SHORTCUT;
546 button->SetImage(*rb.GetImageNamed(image_id).ToImageSkia()); 554 button->SetImage(*rb.GetImageNamed(image_id).ToImageSkia());
547 view = button; 555 view = button;
548 break; 556 break;
549 } 557 }
550 558
551 default: 559 default:
552 break; 560 break;
(...skipping 27 matching lines...) Expand all
580 CancelDrag(-1); 588 CancelDrag(-1);
581 return; 589 return;
582 } 590 }
583 591
584 // Move the view to the front so that it appears on top of other views. 592 // Move the view to the front so that it appears on top of other views.
585 ReorderChildView(drag_view_, -1); 593 ReorderChildView(drag_view_, -1);
586 bounds_animator_->StopAnimatingView(drag_view_); 594 bounds_animator_->StopAnimatingView(drag_view_);
587 } 595 }
588 596
589 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { 597 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) {
598 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
599
590 // TODO: I don't think this works correctly with RTL. 600 // TODO: I don't think this works correctly with RTL.
591 gfx::Point drag_point(event.location()); 601 gfx::Point drag_point(event.location());
592 views::View::ConvertPointToTarget(drag_view_, this, &drag_point); 602 views::View::ConvertPointToTarget(drag_view_, this, &drag_point);
593 int current_index = view_model_->GetIndexOfView(drag_view_); 603 int current_index = view_model_->GetIndexOfView(drag_view_);
594 DCHECK_NE(-1, current_index); 604 DCHECK_NE(-1, current_index);
595 605
596 // If the item is no longer draggable, bail out. 606 // If the item is no longer draggable, bail out.
597 if (current_index == -1 || 607 if (current_index == -1 ||
598 !delegate_->IsDraggable(model_->items()[current_index])) { 608 !delegate_->IsDraggable(model_->items()[current_index])) {
599 CancelDrag(-1); 609 CancelDrag(-1);
600 return; 610 return;
601 } 611 }
602 612
603 // Constrain the location to the range of valid indices for the type. 613 // Constrain the location to the range of valid indices for the type.
604 std::pair<int, int> indices(GetDragRange(current_index)); 614 std::pair<int, int> indices(GetDragRange(current_index));
605 int last_drag_index = indices.second; 615 int last_drag_index = indices.second;
606 // If the last index isn't valid, we're overflowing. Constrain to the app list 616 // If the last index isn't valid, we're overflowing. Constrain to the app list
607 // (which is the last visible item). 617 // (which is the last visible item).
608 if (last_drag_index > last_visible_index_) 618 if (last_drag_index > last_visible_index_)
609 last_drag_index = last_visible_index_; 619 last_drag_index = last_visible_index_;
610 int x = 0, y = 0; 620 int x = 0, y = 0;
611 if (is_horizontal_alignment()) { 621 if (shelf->IsHorizontalAlignment()) {
612 x = std::max(view_model_->ideal_bounds(indices.first).x(), 622 x = std::max(view_model_->ideal_bounds(indices.first).x(),
613 drag_point.x() - drag_offset_); 623 drag_point.x() - drag_offset_);
614 x = std::min(view_model_->ideal_bounds(last_drag_index).right() - 624 x = std::min(view_model_->ideal_bounds(last_drag_index).right() -
615 view_model_->ideal_bounds(current_index).width(), 625 view_model_->ideal_bounds(current_index).width(),
616 x); 626 x);
617 if (drag_view_->x() == x) 627 if (drag_view_->x() == x)
618 return; 628 return;
619 drag_view_->SetX(x); 629 drag_view_->SetX(x);
620 } else { 630 } else {
621 y = std::max(view_model_->ideal_bounds(indices.first).y(), 631 y = std::max(view_model_->ideal_bounds(indices.first).y(),
622 drag_point.y() - drag_offset_); 632 drag_point.y() - drag_offset_);
623 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() - 633 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() -
624 view_model_->ideal_bounds(current_index).height(), 634 view_model_->ideal_bounds(current_index).height(),
625 y); 635 y);
626 if (drag_view_->y() == y) 636 if (drag_view_->y() == y)
627 return; 637 return;
628 drag_view_->SetY(y); 638 drag_view_->SetY(y);
629 } 639 }
630 640
631 int target_index = 641 int target_index =
632 views::ViewModelUtils::DetermineMoveIndex( 642 views::ViewModelUtils::DetermineMoveIndex(
633 *view_model_, drag_view_, 643 *view_model_, drag_view_,
634 is_horizontal_alignment() ? 644 shelf->IsHorizontalAlignment() ?
635 views::ViewModelUtils::HORIZONTAL : 645 views::ViewModelUtils::HORIZONTAL :
636 views::ViewModelUtils::VERTICAL, 646 views::ViewModelUtils::VERTICAL,
637 x, y); 647 x, y);
638 target_index = 648 target_index =
639 std::min(indices.second, std::max(target_index, indices.first)); 649 std::min(indices.second, std::max(target_index, indices.first));
640 if (target_index == current_index) 650 if (target_index == current_index)
641 return; 651 return;
642 652
643 // Change the model, the LauncherItemMoved() callback will handle the 653 // Change the model, the LauncherItemMoved() callback will handle the
644 // |view_model_| update. 654 // |view_model_| update.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 void LauncherView::ShowOverflowBubble() { 696 void LauncherView::ShowOverflowBubble() {
687 int first_overflow_index = last_visible_index_ + 1; 697 int first_overflow_index = last_visible_index_ + 1;
688 DCHECK_LT(first_overflow_index, view_model_->view_size() - 1); 698 DCHECK_LT(first_overflow_index, view_model_->view_size() - 1);
689 699
690 if (!overflow_bubble_.get()) 700 if (!overflow_bubble_.get())
691 overflow_bubble_.reset(new OverflowBubble()); 701 overflow_bubble_.reset(new OverflowBubble());
692 702
693 overflow_bubble_->Show(delegate_, 703 overflow_bubble_->Show(delegate_,
694 model_, 704 model_,
695 overflow_button_, 705 overflow_button_,
696 alignment_,
697 first_overflow_index); 706 first_overflow_index);
698 707
699 Shell::GetInstance()->UpdateShelfVisibility(); 708 Shell::GetInstance()->UpdateShelfVisibility();
700 } 709 }
701 710
702 void LauncherView::UpdateFirstButtonPadding() { 711 void LauncherView::UpdateFirstButtonPadding() {
712 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
713
703 // Creates an empty border for first launcher button to make included leading 714 // Creates an empty border for first launcher button to make included leading
704 // inset act as the button's padding. This is only needed on button creation 715 // inset act as the button's padding. This is only needed on button creation
705 // and when shelf alignment changes. 716 // and when shelf alignment changes.
706 if (view_model_->view_size() > 0) { 717 if (view_model_->view_size() > 0) {
707 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder( 718 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder(
708 primary_axis_coordinate(0, leading_inset()), 719 shelf->PrimaryAxisValue(0, leading_inset()),
709 primary_axis_coordinate(leading_inset(), 0), 720 shelf->PrimaryAxisValue(leading_inset(), 0),
710 0, 721 0,
711 0)); 722 0));
712 } 723 }
713 } 724 }
714 725
715 bool LauncherView::ShouldHideTooltip(const gfx::Point& cursor_location) { 726 bool LauncherView::ShouldHideTooltip(const gfx::Point& cursor_location) {
716 gfx::Rect active_bounds; 727 gfx::Rect active_bounds;
717 728
718 for (int i = 0; i < child_count(); ++i) { 729 for (int i = 0; i < child_count(); ++i) {
719 views::View* child = child_at(i); 730 views::View* child = child_at(i);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 770
760 const int app_list_index = view_model_->view_size() - 1; 771 const int app_list_index = view_model_->view_size() - 1;
761 const int last_button_index = is_overflow_mode() ? 772 const int last_button_index = is_overflow_mode() ?
762 last_visible_index_ : app_list_index; 773 last_visible_index_ : app_list_index;
763 const gfx::Rect last_button_bounds = 774 const gfx::Rect last_button_bounds =
764 last_button_index >= first_visible_index_ ? 775 last_button_index >= first_visible_index_ ?
765 view_model_->view_at(last_button_index)->bounds() : 776 view_model_->view_at(last_button_index)->bounds() :
766 gfx::Rect(gfx::Size(kLauncherPreferredSize, 777 gfx::Rect(gfx::Size(kLauncherPreferredSize,
767 kLauncherPreferredSize)); 778 kLauncherPreferredSize));
768 779
769 if (is_horizontal_alignment()) { 780 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
781
782 if (shelf->IsHorizontalAlignment()) {
770 return gfx::Size(last_button_bounds.right() + leading_inset(), 783 return gfx::Size(last_button_bounds.right() + leading_inset(),
771 kLauncherPreferredSize); 784 kLauncherPreferredSize);
772 } 785 }
773 786
774 return gfx::Size(kLauncherPreferredSize, 787 return gfx::Size(kLauncherPreferredSize,
775 last_button_bounds.bottom() + leading_inset()); 788 last_button_bounds.bottom() + leading_inset());
776 } 789 }
777 790
778 void LauncherView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 791 void LauncherView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
779 LayoutToIdealBounds(); 792 LayoutToIdealBounds();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 if (drag_view_) 917 if (drag_view_)
905 return; 918 return;
906 919
907 tooltip_->Close(); 920 tooltip_->Close();
908 int index = view_model_->GetIndexOfView(view); 921 int index = view_model_->GetIndexOfView(view);
909 if (index == -1 || 922 if (index == -1 ||
910 view_model_->view_size() <= 1 || 923 view_model_->view_size() <= 1 ||
911 !delegate_->IsDraggable(model_->items()[index])) 924 !delegate_->IsDraggable(model_->items()[index]))
912 return; // View is being deleted or not draggable, ignore request. 925 return; // View is being deleted or not draggable, ignore request.
913 926
927 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
928
914 drag_view_ = view; 929 drag_view_ = view;
915 drag_offset_ = primary_axis_coordinate(event.x(), event.y()); 930 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y());
916 } 931 }
917 932
918 void LauncherView::PointerDraggedOnButton(views::View* view, 933 void LauncherView::PointerDraggedOnButton(views::View* view,
919 Pointer pointer, 934 Pointer pointer,
920 const ui::LocatedEvent& event) { 935 const ui::LocatedEvent& event) {
936 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
921 if (!dragging() && drag_view_ && 937 if (!dragging() && drag_view_ &&
922 primary_axis_coordinate(abs(event.x() - drag_offset_), 938 shelf->PrimaryAxisValue(abs(event.x() - drag_offset_),
923 abs(event.y() - drag_offset_)) >= 939 abs(event.y() - drag_offset_)) >=
924 kMinimumDragDistance) { 940 kMinimumDragDistance) {
925 PrepareForDrag(pointer, event); 941 PrepareForDrag(pointer, event);
926 } 942 }
927 if (drag_pointer_ == pointer) 943 if (drag_pointer_ == pointer)
928 ContinueDrag(event); 944 ContinueDrag(event);
929 } 945 }
930 946
931 void LauncherView::PointerReleasedOnButton(views::View* view, 947 void LauncherView::PointerReleasedOnButton(views::View* view,
932 Pointer pointer, 948 Pointer pointer,
(...skipping 30 matching lines...) Expand all
963 } else { 979 } else {
964 tooltip_->ShowDelayed(view, GetAccessibleName(view)); 980 tooltip_->ShowDelayed(view, GetAccessibleName(view));
965 } 981 }
966 } 982 }
967 983
968 void LauncherView::MouseExitedButton(views::View* view) { 984 void LauncherView::MouseExitedButton(views::View* view) {
969 if (!tooltip_->IsVisible()) 985 if (!tooltip_->IsVisible())
970 tooltip_->StopTimer(); 986 tooltip_->StopTimer();
971 } 987 }
972 988
973 ShelfAlignment LauncherView::GetShelfAlignment() const {
974 return alignment_;
975 }
976
977 string16 LauncherView::GetAccessibleName(const views::View* view) { 989 string16 LauncherView::GetAccessibleName(const views::View* view) {
978 int view_index = view_model_->GetIndexOfView(view); 990 int view_index = view_model_->GetIndexOfView(view);
979 // May be -1 while in the process of animating closed. 991 // May be -1 while in the process of animating closed.
980 if (view_index == -1) 992 if (view_index == -1)
981 return string16(); 993 return string16();
982 994
983 switch (model_->items()[view_index].type) { 995 switch (model_->items()[view_index].type) {
984 case TYPE_TABBED: 996 case TYPE_TABBED:
985 case TYPE_APP_PANEL: 997 case TYPE_APP_PANEL:
986 case TYPE_APP_SHORTCUT: 998 case TYPE_APP_SHORTCUT:
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, 1099 FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
1088 OnLauncherIconPositionsChanged()); 1100 OnLauncherIconPositionsChanged());
1089 PreferredSizeChanged(); 1101 PreferredSizeChanged();
1090 } 1102 }
1091 1103
1092 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { 1104 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
1093 } 1105 }
1094 1106
1095 } // namespace internal 1107 } // namespace internal
1096 } // namespace ash 1108 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_view.h ('k') | ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698