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

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

Issue 10659003: ash: Add launcher overflow bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + fix clang Created 8 years, 5 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/launcher/overflow_bubble.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/launcher/app_list_button.h" 9 #include "ash/launcher/app_list_button.h"
10 #include "ash/launcher/launcher_button.h" 10 #include "ash/launcher/launcher_button.h"
11 #include "ash/launcher/launcher_delegate.h" 11 #include "ash/launcher/launcher_delegate.h"
12 #include "ash/launcher/launcher_icon_observer.h" 12 #include "ash/launcher/launcher_icon_observer.h"
13 #include "ash/launcher/launcher_model.h" 13 #include "ash/launcher/launcher_model.h"
14 #include "ash/launcher/launcher_tooltip_manager.h" 14 #include "ash/launcher/launcher_tooltip_manager.h"
15 #include "ash/launcher/overflow_bubble.h"
15 #include "ash/launcher/tabbed_launcher_button.h" 16 #include "ash/launcher/tabbed_launcher_button.h"
16 #include "ash/shell.h" 17 #include "ash/shell.h"
17 #include "ash/shell_delegate.h" 18 #include "ash/shell_delegate.h"
18 #include "base/auto_reset.h" 19 #include "base/auto_reset.h"
19 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
20 #include "grit/ash_strings.h" 21 #include "grit/ash_strings.h"
21 #include "grit/ui_resources.h" 22 #include "grit/ui_resources.h"
22 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
23 #include "ui/base/animation/animation.h" 24 #include "ui/base/animation/animation.h"
24 #include "ui/base/animation/throb_animation.h" 25 #include "ui/base/animation/throb_animation.h"
(...skipping 12 matching lines...) Expand all
37 #include "ui/views/view_model_utils.h" 38 #include "ui/views/view_model_utils.h"
38 #include "ui/views/widget/root_view.h" 39 #include "ui/views/widget/root_view.h"
39 #include "ui/views/widget/widget.h" 40 #include "ui/views/widget/widget.h"
40 41
41 using ui::Animation; 42 using ui::Animation;
42 using views::View; 43 using views::View;
43 44
44 namespace ash { 45 namespace ash {
45 namespace internal { 46 namespace internal {
46 47
47 // Amount content is inset on the left edge. 48 // Default amount content is inset on the left edge.
48 static const int kLeadingInset = 8; 49 static const int kDefaultLeadingInset = 8;
49 50
50 // Minimum distance before drag starts. 51 // Minimum distance before drag starts.
51 static const int kMinimumDragDistance = 8; 52 static const int kMinimumDragDistance = 8;
52 53
53 // Size between the buttons. 54 // Size between the buttons.
54 static const int kButtonSpacing = 4; 55 static const int kButtonSpacing = 4;
55 56
56 namespace { 57 namespace {
57 58
58 // Custom FocusSearch used to navigate the launcher in the order items are in 59 // Custom FocusSearch used to navigate the launcher in the order items are in
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 261
261 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); 262 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate);
262 }; 263 };
263 264
264 LauncherView::LauncherView(LauncherModel* model, 265 LauncherView::LauncherView(LauncherModel* model,
265 LauncherDelegate* delegate, 266 LauncherDelegate* delegate,
266 ShelfLayoutManager* shelf_layout_manager) 267 ShelfLayoutManager* shelf_layout_manager)
267 : model_(model), 268 : model_(model),
268 delegate_(delegate), 269 delegate_(delegate),
269 view_model_(new views::ViewModel), 270 view_model_(new views::ViewModel),
271 first_visible_index_(0),
270 last_visible_index_(-1), 272 last_visible_index_(-1),
271 overflow_button_(NULL), 273 overflow_button_(NULL),
272 dragging_(false), 274 dragging_(false),
273 drag_view_(NULL), 275 drag_view_(NULL),
274 drag_offset_(0), 276 drag_offset_(0),
275 start_drag_index_(-1), 277 start_drag_index_(-1),
276 context_menu_id_(0), 278 context_menu_id_(0),
277 alignment_(SHELF_ALIGNMENT_BOTTOM) { 279 alignment_(SHELF_ALIGNMENT_BOTTOM),
280 leading_inset_(kDefaultLeadingInset) {
278 DCHECK(model_); 281 DCHECK(model_);
279 bounds_animator_.reset(new views::BoundsAnimator(this)); 282 bounds_animator_.reset(new views::BoundsAnimator(this));
280 bounds_animator_->AddObserver(this); 283 bounds_animator_->AddObserver(this);
281 set_context_menu_controller(this); 284 set_context_menu_controller(this);
282 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); 285 focus_search_.reset(new LauncherFocusSearch(view_model_.get()));
283 tooltip_.reset(new LauncherTooltipManager(alignment_, shelf_layout_manager)); 286 tooltip_.reset(new LauncherTooltipManager(alignment_, shelf_layout_manager));
284 } 287 }
285 288
286 LauncherView::~LauncherView() { 289 LauncherView::~LauncherView() {
287 bounds_animator_->RemoveObserver(this); 290 bounds_animator_->RemoveObserver(this);
288 model_->RemoveObserver(this); 291 model_->RemoveObserver(this);
289 } 292 }
290 293
291 void LauncherView::Init() { 294 void LauncherView::Init() {
292 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 295 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
293 model_->AddObserver(this); 296 model_->AddObserver(this);
294 297
295 const LauncherItems& items(model_->items()); 298 const LauncherItems& items(model_->items());
296 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { 299 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) {
297 views::View* child = CreateViewForItem(*i); 300 views::View* child = CreateViewForItem(*i);
298 child->SetPaintToLayer(true); 301 child->SetPaintToLayer(true);
299 view_model_->Add(child, static_cast<int>(i - items.begin())); 302 view_model_->Add(child, static_cast<int>(i - items.begin()));
300 AddChildView(child); 303 AddChildView(child);
301 } 304 }
302 UpdateFirstButtonPadding(); 305 UpdateFirstButtonPadding();
303 306
304 overflow_button_ = new views::ImageButton(this); 307 overflow_button_ = new views::ImageButton(this);
305 overflow_button_->set_accessibility_focusable(true); 308 overflow_button_->set_accessibility_focusable(true);
309 overflow_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
310 views::ImageButton::ALIGN_MIDDLE);
306 overflow_button_->SetImage( 311 overflow_button_->SetImage(
307 views::CustomButton::BS_NORMAL, 312 views::CustomButton::BS_NORMAL,
308 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia()); 313 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia());
309 overflow_button_->SetImage( 314 overflow_button_->SetImage(
310 views::CustomButton::BS_HOT, 315 views::CustomButton::BS_HOT,
311 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_HOT).ToImageSkia()); 316 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_HOT).ToImageSkia());
312 overflow_button_->SetImage( 317 overflow_button_->SetImage(
313 views::CustomButton::BS_PUSHED, 318 views::CustomButton::BS_PUSHED,
314 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_PUSHED).ToImageSkia()); 319 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_PUSHED).ToImageSkia());
315 overflow_button_->SetAccessibleName( 320 overflow_button_->SetAccessibleName(
316 l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME)); 321 l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME));
317 overflow_button_->set_context_menu_controller(this); 322 overflow_button_->set_context_menu_controller(this);
318 ConfigureChildView(overflow_button_); 323 ConfigureChildView(overflow_button_);
319 AddChildView(overflow_button_); 324 AddChildView(overflow_button_);
320 325
321 // We'll layout when our bounds change. 326 // We'll layout when our bounds change.
322 } 327 }
323 328
324 void LauncherView::SetAlignment(ShelfAlignment alignment) { 329 void LauncherView::SetAlignment(ShelfAlignment alignment) {
325 if (alignment_ == alignment) 330 if (alignment_ == alignment)
326 return; 331 return;
327 alignment_ = alignment; 332 alignment_ = alignment;
328 UpdateFirstButtonPadding(); 333 UpdateFirstButtonPadding();
329 LayoutToIdealBounds(); 334 LayoutToIdealBounds();
330 tooltip_->SetArrowLocation(alignment_); 335 tooltip_->SetArrowLocation(alignment_);
336 if (overflow_bubble_.get())
337 overflow_bubble_->Hide();
331 } 338 }
332 339
333 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) { 340 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) {
334 int index = model_->ItemIndexByID(id); 341 int index = model_->ItemIndexByID(id);
335 if (index == -1 || index > last_visible_index_) 342 if (index == -1 || index > last_visible_index_)
336 return gfx::Rect(); 343 return gfx::Rect();
337 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); 344 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index));
338 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); 345 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type);
339 LauncherButton* button = 346 LauncherButton* button =
340 static_cast<LauncherButton*>(view_model_->view_at(index)); 347 static_cast<LauncherButton*>(view_model_->view_at(index));
341 gfx::Rect icon_bounds = button->GetIconBounds(); 348 gfx::Rect icon_bounds = button->GetIconBounds();
342 return gfx::Rect(ideal_bounds.x() + icon_bounds.x(), 349 return gfx::Rect(ideal_bounds.x() + icon_bounds.x(),
343 ideal_bounds.y() + icon_bounds.y(), 350 ideal_bounds.y() + icon_bounds.y(),
344 icon_bounds.width(), icon_bounds.height()); 351 icon_bounds.width(), icon_bounds.height());
345 } 352 }
346 353
347 bool LauncherView::IsShowingMenu() const { 354 bool LauncherView::IsShowingMenu() const {
348 #if !defined(OS_MACOSX) 355 #if !defined(OS_MACOSX)
349 return (overflow_menu_runner_.get() && 356 return (launcher_menu_runner_.get() &&
350 overflow_menu_runner_->IsRunning()) ||
351 (launcher_menu_runner_.get() &&
352 launcher_menu_runner_->IsRunning()); 357 launcher_menu_runner_->IsRunning());
353 #endif 358 #endif
354 return false; 359 return false;
355 } 360 }
356 361
362 bool LauncherView::IsShowingOverflowBubble() const {
363 return overflow_bubble_.get() && overflow_bubble_->IsShowing();
364 }
365
357 views::View* LauncherView::GetAppListButtonView() const { 366 views::View* LauncherView::GetAppListButtonView() const {
358 for (int i = 0; i < model_->item_count(); ++i) { 367 for (int i = 0; i < model_->item_count(); ++i) {
359 if (model_->items()[i].type == TYPE_APP_LIST) 368 if (model_->items()[i].type == TYPE_APP_LIST)
360 return view_model_->view_at(i); 369 return view_model_->view_at(i);
361 } 370 }
362 371
363 NOTREACHED() << "Applist button not found"; 372 NOTREACHED() << "Applist button not found";
364 return NULL; 373 return NULL;
365 } 374 }
366 375
(...skipping 22 matching lines...) Expand all
389 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 398 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
390 399
391 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); 400 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds);
392 } 401 }
393 402
394 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { 403 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) {
395 int available_size = primary_axis_coordinate(width(), height()); 404 int available_size = primary_axis_coordinate(width(), height());
396 if (!available_size) 405 if (!available_size)
397 return; 406 return;
398 407
399 int x = primary_axis_coordinate(kLeadingInset, 0); 408 int x = primary_axis_coordinate(leading_inset(), 0);
400 int y = primary_axis_coordinate(0, kLeadingInset); 409 int y = primary_axis_coordinate(0, leading_inset());
401 for (int i = 0; i < view_model_->view_size(); ++i) { 410 for (int i = 0; i < view_model_->view_size(); ++i) {
411 if (i < first_visible_index_) {
412 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0));
413 continue;
414 }
415
402 view_model_->set_ideal_bounds(i, gfx::Rect( 416 view_model_->set_ideal_bounds(i, gfx::Rect(
403 x, y, kLauncherPreferredSize, kLauncherPreferredSize)); 417 x, y, kLauncherPreferredSize, kLauncherPreferredSize));
404 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, 0); 418 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, 0);
405 y = primary_axis_coordinate(0, y + kLauncherPreferredSize + kButtonSpacing); 419 y = primary_axis_coordinate(0, y + kLauncherPreferredSize + kButtonSpacing);
406 } 420 }
407 421
422 int app_list_index = view_model_->view_size() - 1;
423 if (is_overflow_mode()) {
424 last_visible_index_ = app_list_index - 1;
425 for (int i = 0; i < view_model_->view_size(); ++i) {
426 view_model_->view_at(i)->SetVisible(
427 i >= first_visible_index_ && i <= last_visible_index_);
428 }
429 return;
430 }
431
408 if (view_model_->view_size() > 0) { 432 if (view_model_->view_size() > 0) {
409 // Makes the first launcher button include the leading inset. 433 // Makes the first launcher button include the leading inset.
410 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size( 434 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size(
411 primary_axis_coordinate(kLeadingInset + kLauncherPreferredSize, 435 primary_axis_coordinate(leading_inset() + kLauncherPreferredSize,
412 kLauncherPreferredSize), 436 kLauncherPreferredSize),
413 primary_axis_coordinate(kLauncherPreferredSize, 437 primary_axis_coordinate(kLauncherPreferredSize,
414 kLeadingInset + kLauncherPreferredSize)))); 438 leading_inset() + kLauncherPreferredSize))));
415 } 439 }
416 440
417 bounds->overflow_bounds.set_size( 441 bounds->overflow_bounds.set_size(
418 gfx::Size(kLauncherPreferredSize, kLauncherPreferredSize)); 442 gfx::Size(kLauncherPreferredSize, kLauncherPreferredSize));
419 last_visible_index_ = DetermineLastVisibleIndex( 443 last_visible_index_ = DetermineLastVisibleIndex(
420 available_size - kLeadingInset - kLauncherPreferredSize - 444 available_size - leading_inset() - kLauncherPreferredSize -
421 kButtonSpacing - kLauncherPreferredSize); 445 kButtonSpacing - kLauncherPreferredSize);
422 int app_list_index = view_model_->view_size() - 1;
423 bool show_overflow = (last_visible_index_ + 1 < app_list_index); 446 bool show_overflow = (last_visible_index_ + 1 < app_list_index);
424 447
425 for (int i = 0; i < view_model_->view_size(); ++i) { 448 for (int i = 0; i < view_model_->view_size(); ++i) {
426 view_model_->view_at(i)->SetVisible( 449 view_model_->view_at(i)->SetVisible(
427 i == app_list_index || i <= last_visible_index_); 450 i == app_list_index || i <= last_visible_index_);
428 } 451 }
429 452
430 overflow_button_->SetVisible(show_overflow); 453 overflow_button_->SetVisible(show_overflow);
431 if (show_overflow) { 454 if (show_overflow) {
432 DCHECK_NE(0, view_model_->view_size()); 455 DCHECK_NE(0, view_model_->view_size());
433 if (last_visible_index_ == -1) { 456 if (last_visible_index_ == -1) {
434 x = primary_axis_coordinate(kLeadingInset, 0); 457 x = primary_axis_coordinate(leading_inset(), 0);
435 y = primary_axis_coordinate(0, kLeadingInset); 458 y = primary_axis_coordinate(0, leading_inset());
436 } else { 459 } else {
437 x = primary_axis_coordinate( 460 x = primary_axis_coordinate(
438 view_model_->ideal_bounds(last_visible_index_).right(), 0); 461 view_model_->ideal_bounds(last_visible_index_).right(), 0);
439 y = primary_axis_coordinate(0, 462 y = primary_axis_coordinate(0,
440 view_model_->ideal_bounds(last_visible_index_).bottom()); 463 view_model_->ideal_bounds(last_visible_index_).bottom());
441 } 464 }
442 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); 465 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index);
466 bounds->overflow_bounds.set_x(x);
467 bounds->overflow_bounds.set_y(y);
468 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, 0);
469 y = primary_axis_coordinate(0, y + kLauncherPreferredSize + kButtonSpacing);
443 app_list_bounds.set_x(x); 470 app_list_bounds.set_x(x);
444 app_list_bounds.set_y(y); 471 app_list_bounds.set_y(y);
445 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); 472 view_model_->set_ideal_bounds(app_list_index, app_list_bounds);
446 x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, 0); 473 } else {
447 y = primary_axis_coordinate(0, y + kLauncherPreferredSize + kButtonSpacing); 474 if (overflow_bubble_.get())
448 bounds->overflow_bounds.set_x(x); 475 overflow_bubble_->Hide();
449 bounds->overflow_bounds.set_y(y);
450 } 476 }
451 } 477 }
452 478
453 int LauncherView::DetermineLastVisibleIndex(int max_value) { 479 int LauncherView::DetermineLastVisibleIndex(int max_value) {
454 int index = view_model_->view_size() - 1; 480 int index = view_model_->view_size() - 1;
455 while (index >= 0 && 481 while (index >= 0 &&
456 primary_axis_coordinate( 482 primary_axis_coordinate(
457 view_model_->ideal_bounds(index).right(), 483 view_model_->ideal_bounds(index).right(),
458 view_model_->ideal_bounds(index).bottom()) > max_value) { 484 view_model_->ideal_bounds(index).bottom()) > max_value) {
459 index--; 485 index--;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 while (index < view_model_->view_size()) { 705 while (index < view_model_->view_size()) {
680 const LauncherItem& item = model_->items()[index]; 706 const LauncherItem& item = model_->items()[index];
681 if (item.type == TYPE_TABBED || 707 if (item.type == TYPE_TABBED ||
682 item.type == TYPE_APP_PANEL || 708 item.type == TYPE_APP_PANEL ||
683 item.type == TYPE_APP_SHORTCUT) 709 item.type == TYPE_APP_SHORTCUT)
684 items->push_back(item); 710 items->push_back(item);
685 index++; 711 index++;
686 } 712 }
687 } 713 }
688 714
689 void LauncherView::ShowOverflowMenu() { 715 void LauncherView::ShowOverflowBubble() {
690 #if !defined(OS_MACOSX) 716 int first_overflow_index = last_visible_index_ + 1;
691 if (!delegate_) 717 DCHECK_LT(first_overflow_index, view_model_->view_size() - 1);
692 return;
693 718
694 std::vector<LauncherItem> items; 719 if (!overflow_bubble_.get())
695 GetOverflowItems(&items); 720 overflow_bubble_.reset(new OverflowBubble());
696 if (items.empty())
697 return;
698 721
699 MenuDelegateImpl menu_delegate; 722 overflow_bubble_->Show(delegate_,
700 ui::SimpleMenuModel menu_model(&menu_delegate); 723 model_,
701 for (size_t i = 0; i < items.size(); ++i) 724 overflow_button_,
702 menu_model.AddItem(static_cast<int>(i), delegate_->GetTitle(items[i])); 725 alignment_,
703 views::MenuModelAdapter menu_adapter(&menu_model); 726 first_overflow_index);
704 overflow_menu_runner_.reset(new views::MenuRunner(menu_adapter.CreateMenu()));
705 gfx::Rect bounds(overflow_button_->size());
706 gfx::Point origin;
707 ConvertPointToScreen(overflow_button_, &origin);
708 if (overflow_menu_runner_->RunMenuAt(GetWidget(), NULL,
709 gfx::Rect(origin, size()), views::MenuItemView::TOPLEFT, 0) ==
710 views::MenuRunner::MENU_DELETED)
711 return;
712 727
713 Shell::GetInstance()->UpdateShelfVisibility(); 728 Shell::GetInstance()->UpdateShelfVisibility();
714
715 if (menu_delegate.activated_command_id() == -1)
716 return;
717
718 LauncherID activated_id = items[menu_delegate.activated_command_id()].id;
719 LauncherItems::const_iterator window_iter = model_->ItemByID(activated_id);
720 if (window_iter == model_->items().end())
721 return; // Window was deleted while menu was up.
722 delegate_->ItemClicked(*window_iter, ui::EF_NONE);
723 #endif // !defined(OS_MACOSX)
724 } 729 }
725 730
726 void LauncherView::UpdateFirstButtonPadding() { 731 void LauncherView::UpdateFirstButtonPadding() {
727 // Creates an empty border for first launcher button to make included leading 732 // Creates an empty border for first launcher button to make included leading
728 // inset act as the button's padding. This is only needed on button creation 733 // inset act as the button's padding. This is only needed on button creation
729 // and when shelf alignment changes. 734 // and when shelf alignment changes.
730 if (view_model_->view_size() > 0) { 735 if (view_model_->view_size() > 0) {
731 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder( 736 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder(
732 primary_axis_coordinate(0, kLeadingInset), 737 primary_axis_coordinate(0, leading_inset()),
733 primary_axis_coordinate(kLeadingInset, 0), 738 primary_axis_coordinate(leading_inset(), 0),
734 0, 739 0,
735 0)); 740 0));
736 } 741 }
737 } 742 }
738 743
739 bool LauncherView::ShouldHideTooltip(const gfx::Point& cursor_location) { 744 bool LauncherView::ShouldHideTooltip(const gfx::Point& cursor_location) {
740 gfx::Rect active_bounds; 745 gfx::Rect active_bounds;
741 746
742 for (int i = 0; i < child_count(); ++i) { 747 for (int i = 0; i < child_count(); ++i) {
743 views::View* child = child_at(i); 748 views::View* child = child_at(i);
(...skipping 24 matching lines...) Expand all
768 // Restore previous position, tracking the position of the modified view. 773 // Restore previous position, tracking the position of the modified view.
769 views::View* removed_view = 774 views::View* removed_view =
770 (modified_index >= 0) ? view_model_->view_at(modified_index) : NULL; 775 (modified_index >= 0) ? view_model_->view_at(modified_index) : NULL;
771 model_->Move(drag_view_index, start_drag_index_); 776 model_->Move(drag_view_index, start_drag_index_);
772 return removed_view ? view_model_->GetIndexOfView(removed_view) : -1; 777 return removed_view ? view_model_->GetIndexOfView(removed_view) : -1;
773 } 778 }
774 779
775 gfx::Size LauncherView::GetPreferredSize() { 780 gfx::Size LauncherView::GetPreferredSize() {
776 IdealBounds ideal_bounds; 781 IdealBounds ideal_bounds;
777 CalculateIdealBounds(&ideal_bounds); 782 CalculateIdealBounds(&ideal_bounds);
783
784 const int app_list_index = view_model_->view_size() - 1;
785 const int last_button_index = is_overflow_mode() ?
786 last_visible_index_ : app_list_index;
787 const gfx::Rect last_button_bounds =
788 last_button_index >= first_visible_index_ ?
789 view_model_->view_at(last_button_index)->bounds() :
790 gfx::Rect(gfx::Size(kLauncherPreferredSize,
791 kLauncherPreferredSize));
792
778 if (is_horizontal_alignment()) { 793 if (is_horizontal_alignment()) {
779 if (view_model_->view_size() >= 2) { 794 return gfx::Size(last_button_bounds.right() + leading_inset(),
780 // Should always have two items.
781 return gfx::Size(view_model_->ideal_bounds(1).right() + kLeadingInset,
782 kLauncherPreferredSize);
783 }
784 return gfx::Size(kLauncherPreferredSize * 2 + kLeadingInset * 2,
785 kLauncherPreferredSize); 795 kLauncherPreferredSize);
786 } 796 }
787 if (view_model_->view_size() >= 2) { 797
788 // Should always have two items.
789 return gfx::Size(kLauncherPreferredSize,
790 view_model_->ideal_bounds(1).bottom() + kLeadingInset);
791 }
792 return gfx::Size(kLauncherPreferredSize, 798 return gfx::Size(kLauncherPreferredSize,
793 kLauncherPreferredSize * 2 + kLeadingInset * 2); 799 last_button_bounds.bottom() + leading_inset());
794 } 800 }
795 801
796 void LauncherView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 802 void LauncherView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
797 LayoutToIdealBounds(); 803 LayoutToIdealBounds();
798 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, 804 FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
799 OnLauncherIconPositionsChanged()); 805 OnLauncherIconPositionsChanged());
806
807 if (IsShowingOverflowBubble())
808 overflow_bubble_->Hide();
800 } 809 }
801 810
802 views::FocusTraversable* LauncherView::GetPaneFocusTraversable() { 811 views::FocusTraversable* LauncherView::GetPaneFocusTraversable() {
803 return this; 812 return this;
804 } 813 }
805 814
806 void LauncherView::OnMouseMoved(const views::MouseEvent& event) { 815 void LauncherView::OnMouseMoved(const views::MouseEvent& event) {
807 if (ShouldHideTooltip(event.location()) && tooltip_->IsVisible()) 816 if (ShouldHideTooltip(event.location()) && tooltip_->IsVisible())
808 tooltip_->Close(); 817 tooltip_->Close();
809 } 818 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 } 1004 }
996 return string16(); 1005 return string16();
997 } 1006 }
998 1007
999 void LauncherView::ButtonPressed(views::Button* sender, 1008 void LauncherView::ButtonPressed(views::Button* sender,
1000 const views::Event& event) { 1009 const views::Event& event) {
1001 // Do not handle mouse release during drag. 1010 // Do not handle mouse release during drag.
1002 if (dragging_) 1011 if (dragging_)
1003 return; 1012 return;
1004 1013
1005 if (sender == overflow_button_) 1014 if (sender == overflow_button_) {
1006 ShowOverflowMenu(); 1015 ShowOverflowBubble();
1016 return;
1017 }
1007 1018
1008 if (!delegate_) 1019 if (!delegate_)
1009 return; 1020 return;
1010 int view_index = view_model_->GetIndexOfView(sender); 1021 int view_index = view_model_->GetIndexOfView(sender);
1011 // May be -1 while in the process of animating closed. 1022 // May be -1 while in the process of animating closed.
1012 if (view_index == -1) 1023 if (view_index == -1)
1013 return; 1024 return;
1014 1025
1015 switch (model_->items()[view_index].type) { 1026 switch (model_->items()[view_index].type) {
1016 case TYPE_TABBED: 1027 case TYPE_TABBED:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED) 1074 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED)
1064 return; 1075 return;
1065 1076
1066 Shell::GetInstance()->UpdateShelfVisibility(); 1077 Shell::GetInstance()->UpdateShelfVisibility();
1067 #endif 1078 #endif
1068 } 1079 }
1069 1080
1070 void LauncherView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) { 1081 void LauncherView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) {
1071 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, 1082 FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
1072 OnLauncherIconPositionsChanged()); 1083 OnLauncherIconPositionsChanged());
1084 PreferredSizeChanged();
1073 } 1085 }
1074 1086
1075 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { 1087 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
1076 } 1088 }
1077 1089
1078 } // namespace internal 1090 } // namespace internal
1079 } // namespace ash 1091 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_view.h ('k') | ash/launcher/overflow_bubble.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698