Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 border->set_insets(gfx::Insets()); | 92 border->set_insets(gfx::Insets()); |
| 93 return border.Pass(); | 93 return border.Pass(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(ChevronMenuButton); | 97 DISALLOW_COPY_AND_ASSIGN(ChevronMenuButton); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 | 101 |
| 102 //////////////////////////////////////////////////////////////////////////////// | |
| 103 // BrowserActionsContainer::DropPosition | |
| 104 | |
| 105 struct BrowserActionsContainer::DropPosition { | |
| 106 DropPosition(size_t row, size_t icon_in_row); | |
| 107 | |
| 108 // The (0-indexed) row into which the action will be dropped. | |
| 109 size_t row; | |
| 110 | |
| 111 // The (0-indexed) icon in the row before the action will be dropped. | |
| 112 size_t icon_in_row; | |
| 113 }; | |
| 114 | |
| 115 BrowserActionsContainer::DropPosition::DropPosition( | |
| 116 size_t row, size_t icon_in_row) | |
| 117 : row(row), icon_in_row(icon_in_row) { | |
| 118 } | |
| 119 | |
| 120 //////////////////////////////////////////////////////////////////////////////// | |
| 121 // BrowserActionsContainer | |
| 122 | |
| 102 // static | 123 // static |
| 103 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 124 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
| 104 | 125 |
| 105 //////////////////////////////////////////////////////////////////////////////// | |
| 106 // BrowserActionsContainer | |
| 107 | |
| 108 BrowserActionsContainer::BrowserActionsContainer( | 126 BrowserActionsContainer::BrowserActionsContainer( |
| 109 Browser* browser, | 127 Browser* browser, |
| 110 View* owner_view, | 128 View* owner_view, |
| 111 BrowserActionsContainer* main_container) | 129 BrowserActionsContainer* main_container) |
| 112 : profile_(browser->profile()), | 130 : profile_(browser->profile()), |
| 113 browser_(browser), | 131 browser_(browser), |
| 114 owner_view_(owner_view), | 132 owner_view_(owner_view), |
| 115 main_container_(main_container), | 133 main_container_(main_container), |
| 116 popup_(NULL), | 134 popup_(NULL), |
| 117 popup_button_(NULL), | 135 popup_button_(NULL), |
| 118 model_(NULL), | 136 model_(NULL), |
| 119 container_width_(0), | 137 container_width_(0), |
| 120 resize_area_(NULL), | 138 resize_area_(NULL), |
| 121 chevron_(NULL), | 139 chevron_(NULL), |
| 122 overflow_menu_(NULL), | 140 overflow_menu_(NULL), |
| 123 suppress_chevron_(false), | 141 suppress_chevron_(false), |
| 124 resize_amount_(0), | 142 resize_amount_(0), |
| 125 animation_target_size_(0), | 143 animation_target_size_(0), |
| 126 drop_indicator_position_(-1), | |
| 127 task_factory_(this), | 144 task_factory_(this), |
| 128 show_menu_task_factory_(this) { | 145 show_menu_task_factory_(this) { |
| 129 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 146 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
| 130 | 147 |
| 131 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); | 148 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); |
| 132 if (model_) | 149 if (model_) |
| 133 model_->AddObserver(this); | 150 model_->AddObserver(this); |
| 134 | 151 |
| 135 bool overflow_experiment = | 152 bool overflow_experiment = |
| 136 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); | 153 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 // Ensure that any browser actions shown in the main view are hidden in | 369 // Ensure that any browser actions shown in the main view are hidden in |
| 353 // the overflow view. | 370 // the overflow view. |
| 354 browser_action_views_[i]->SetVisible(false); | 371 browser_action_views_[i]->SetVisible(false); |
| 355 } | 372 } |
| 356 | 373 |
| 357 for (size_t i = main_container_->VisibleBrowserActionsAfterAnimation(); | 374 for (size_t i = main_container_->VisibleBrowserActionsAfterAnimation(); |
| 358 i < browser_action_views_.size(); ++i) { | 375 i < browser_action_views_.size(); ++i) { |
| 359 BrowserActionView* view = browser_action_views_[i]; | 376 BrowserActionView* view = browser_action_views_[i]; |
| 360 size_t index = i - main_container_->VisibleBrowserActionsAfterAnimation(); | 377 size_t index = i - main_container_->VisibleBrowserActionsAfterAnimation(); |
| 361 int row_index = static_cast<int>(index) / kIconsPerMenuRow; | 378 int row_index = static_cast<int>(index) / kIconsPerMenuRow; |
| 362 int x = (index * IconWidth(true)) - | 379 int x = kItemSpacing + (index * IconWidth(true)) - |
| 363 (row_index * IconWidth(true) * kIconsPerMenuRow); | 380 (row_index * IconWidth(true) * kIconsPerMenuRow); |
| 364 gfx::Rect rect_bounds( | 381 gfx::Rect rect_bounds( |
| 365 x, IconHeight() * row_index, icon_width, IconHeight()); | 382 x, IconHeight() * row_index, icon_width, IconHeight()); |
| 366 view->SetBoundsRect(rect_bounds); | 383 view->SetBoundsRect(rect_bounds); |
| 367 view->SetVisible(true); | 384 view->SetVisible(true); |
| 368 } | 385 } |
| 369 } else { | 386 } else { |
| 370 for (BrowserActionViews::const_iterator it = browser_action_views_.begin(); | 387 for (BrowserActionViews::const_iterator it = browser_action_views_.begin(); |
| 371 it < browser_action_views_.end(); ++it) { | 388 it < browser_action_views_.end(); ++it) { |
| 372 BrowserActionView* view = *it; | 389 BrowserActionView* view = *it; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 400 int BrowserActionsContainer::OnDragUpdated( | 417 int BrowserActionsContainer::OnDragUpdated( |
| 401 const ui::DropTargetEvent& event) { | 418 const ui::DropTargetEvent& event) { |
| 402 // First check if we are above the chevron (overflow) menu. | 419 // First check if we are above the chevron (overflow) menu. |
| 403 if (GetEventHandlerForPoint(event.location()) == chevron_) { | 420 if (GetEventHandlerForPoint(event.location()) == chevron_) { |
| 404 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) | 421 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) |
| 405 StartShowFolderDropMenuTimer(); | 422 StartShowFolderDropMenuTimer(); |
| 406 return ui::DragDropTypes::DRAG_MOVE; | 423 return ui::DragDropTypes::DRAG_MOVE; |
| 407 } | 424 } |
| 408 StopShowFolderDropMenuTimer(); | 425 StopShowFolderDropMenuTimer(); |
| 409 | 426 |
| 410 // TODO(devlin): This calculation needs to take 'overflow' mode into account | |
| 411 // once the wrench menu becomes a drag target for browser action icons. | |
| 412 | |
| 413 // Figure out where to display the indicator. This is a complex calculation: | 427 // Figure out where to display the indicator. This is a complex calculation: |
| 414 | 428 |
| 415 // First, we figure out how much space is to the left of the icon area, so we | 429 // First, we figure out how much space is to the left of the icon area, so we |
| 416 // can calculate the true offset into the icon area. | 430 // can calculate the true offset into the icon area. The easiest way to do |
| 417 int width_before_icons = ToolbarView::kStandardSpacing; | 431 // this is to just find where the first icon starts. |
| 418 if (chevron_ && base::i18n::IsRTL()) { | 432 int width_before_icons = |
| 419 width_before_icons += | 433 browser_action_views_[GetFirstVisibleIconIndex()]->x(); |
| 420 chevron_->GetPreferredSize().width() + kChevronSpacing; | 434 |
| 421 } | 435 // If we're right-to-left, we flip the mirror the event.x() so that our |
| 422 int offset_into_icon_area = event.x() - width_before_icons; | 436 // calculations are consistent with left-to-right. |
| 437 int offset_into_icon_area = | |
| 438 GetMirroredXInView(event.x()) - width_before_icons; | |
| 439 | |
| 440 // Next, figure out what row we're on. This only matters for overflow mode, | |
| 441 // but the calculation is the same for both. | |
| 442 size_t row_index = event.y() / IconHeight(); | |
| 443 | |
| 444 // Sanity check - we should never be on a different row in the main container. | |
| 445 DCHECK(in_overflow_mode() || row_index == 0); | |
| 423 | 446 |
| 424 // Next, we determine which icon to place the indicator in front of. We want | 447 // Next, we determine which icon to place the indicator in front of. We want |
| 425 // to place the indicator in front of icon n when the cursor is between the | 448 // to place the indicator in front of icon n when the cursor is between the |
| 426 // midpoints of icons (n - 1) and n. To do this we take the offset into the | 449 // midpoints of icons (n - 1) and n. To do this we take the offset into the |
| 427 // icon area and transform it as follows: | 450 // icon area and transform it as follows: |
| 428 // | 451 // |
| 429 // Real icon area: | 452 // Real icon area: |
| 430 // 0 a * b c | 453 // 0 a * b c |
| 431 // | | | | | 454 // | | | | |
| 432 // |[IC|ON] [IC|ON] [IC|ON] | 455 // |[IC|ON] [IC|ON] [IC|ON] |
| 433 // We want to be before icon 0 for 0 < x <= a, icon 1 for a < x <= b, etc. | 456 // We want to be before icon 0 for 0 < x <= a, icon 1 for a < x <= b, etc. |
| 434 // Here the "*" represents the offset into the icon area, and since it's | 457 // Here the "*" represents the offset into the icon area, and since it's |
| 435 // between a and b, we want to return "1". | 458 // between a and b, we want to return "1". |
| 436 // | 459 // |
| 437 // Transformed "icon area": | 460 // Transformed "icon area": |
| 438 // 0 a * b c | 461 // 0 a * b c |
| 439 // | | | | | 462 // | | | | |
| 440 // |[ICON] |[ICON] |[ICON] | | 463 // |[ICON] |[ICON] |[ICON] | |
| 441 // If we shift both our offset and our divider points later by half an icon | 464 // If we shift both our offset and our divider points later by half an icon |
| 442 // plus one spacing unit, then it becomes very easy to calculate how many | 465 // plus one spacing unit, then it becomes very easy to calculate how many |
| 443 // divider points we've passed, because they're the multiples of "one icon | 466 // divider points we've passed, because they're the multiples of "one icon |
| 444 // plus padding". | 467 // plus padding". |
| 445 int before_icon_unclamped = (offset_into_icon_area + (IconWidth(false) / 2) + | 468 int before_icon_unclamped = (offset_into_icon_area + (IconWidth(false) / 2) + |
| 446 kItemSpacing) / IconWidth(true); | 469 kItemSpacing) / IconWidth(true); |
| 447 | 470 |
| 471 // We need to figure out how many icons are visible on the relevant row. | |
| 472 // In the main container, this will just be the visible actions. | |
| 473 int visible_icons_on_row = VisibleBrowserActionsAfterAnimation(); | |
| 474 if (in_overflow_mode()) { | |
| 475 // If this is the final row of the overflow, then this is the remainder of | |
| 476 // visible icons. Otherwise, it's a full row (kIconsPerRow). | |
| 477 visible_icons_on_row = | |
| 478 row_index == | |
| 479 static_cast<size_t>(visible_icons_on_row / kIconsPerMenuRow) ? | |
| 480 visible_icons_on_row % kIconsPerMenuRow : | |
| 481 kIconsPerMenuRow; | |
| 482 } | |
| 483 | |
| 448 // Because the user can drag outside the container bounds, we need to clamp to | 484 // Because the user can drag outside the container bounds, we need to clamp to |
| 449 // the valid range. Note that the maximum allowable value is (num icons), not | 485 // the valid range. Note that the maximum allowable value is (num icons), not |
| 450 // (num icons - 1), because we represent the indicator being past the last | 486 // (num icons - 1), because we represent the indicator being past the last |
| 451 // icon as being "before the (last + 1) icon". | 487 // icon as being "before the (last + 1) icon". |
| 452 int before_icon = std::min(std::max(before_icon_unclamped, 0), | 488 size_t before_icon_in_row = |
| 453 static_cast<int>(VisibleBrowserActions())); | 489 std::min(std::max(before_icon_unclamped, 0), visible_icons_on_row); |
| 454 | 490 |
| 455 // Now we convert back to a pixel offset into the container. We want to place | 491 if (!drop_position_.get() || |
| 456 // the center of the drop indicator at the midpoint of the space before our | 492 !(drop_position_->row == row_index && |
| 457 // chosen icon. | 493 drop_position_->icon_in_row == before_icon_in_row)) { |
| 458 SetDropIndicator(width_before_icons + (before_icon * IconWidth(true)) - | 494 drop_position_.reset(new DropPosition(row_index, before_icon_in_row)); |
| 459 (kItemSpacing / 2)); | 495 SchedulePaint(); |
| 496 } | |
| 460 | 497 |
| 461 return ui::DragDropTypes::DRAG_MOVE; | 498 return ui::DragDropTypes::DRAG_MOVE; |
| 462 } | 499 } |
| 463 | 500 |
| 464 void BrowserActionsContainer::OnDragExited() { | 501 void BrowserActionsContainer::OnDragExited() { |
| 465 StopShowFolderDropMenuTimer(); | 502 StopShowFolderDropMenuTimer(); |
| 466 drop_indicator_position_ = -1; | 503 drop_position_.reset(); |
| 467 SchedulePaint(); | 504 SchedulePaint(); |
| 468 } | 505 } |
| 469 | 506 |
| 470 int BrowserActionsContainer::OnPerformDrop( | 507 int BrowserActionsContainer::OnPerformDrop( |
| 471 const ui::DropTargetEvent& event) { | 508 const ui::DropTargetEvent& event) { |
| 472 BrowserActionDragData data; | 509 BrowserActionDragData data; |
| 473 if (!data.Read(event.data())) | 510 if (!data.Read(event.data())) |
| 474 return ui::DragDropTypes::DRAG_NONE; | 511 return ui::DragDropTypes::DRAG_NONE; |
| 475 | 512 |
| 476 // Make sure we have the same view as we started with. | 513 // Make sure we have the same view as we started with. |
| 477 DCHECK_EQ(browser_action_views_[data.index()]->button()->extension()->id(), | 514 DCHECK_EQ(browser_action_views_[data.index()]->button()->extension()->id(), |
| 478 data.id()); | 515 data.id()); |
| 479 DCHECK(model_); | 516 DCHECK(model_); |
| 480 | 517 |
| 481 size_t i = 0; | 518 size_t i = |
| 482 for (; i < browser_action_views_.size(); ++i) { | 519 drop_position_->row * kIconsPerMenuRow + drop_position_->icon_in_row; |
| 483 int view_x = browser_action_views_[i]->GetMirroredBounds().x(); | 520 if (in_overflow_mode()) |
| 484 if (!browser_action_views_[i]->visible() || | 521 i += GetFirstVisibleIconIndex(); |
| 485 (base::i18n::IsRTL() ? (view_x < drop_indicator_position_) : | |
| 486 (view_x >= drop_indicator_position_))) { | |
| 487 // We have reached the end of the visible icons or found one that has a | |
| 488 // higher x position than the drop point. | |
| 489 break; | |
| 490 } | |
| 491 } | |
| 492 | |
| 493 // |i| now points to the item to the right of the drop indicator*, which is | 522 // |i| now points to the item to the right of the drop indicator*, which is |
| 494 // correct when dragging an icon to the left. When dragging to the right, | 523 // correct when dragging an icon to the left. When dragging to the right, |
| 495 // however, we want the icon being dragged to get the index of the item to | 524 // however, we want the icon being dragged to get the index of the item to |
| 496 // the left of the drop indicator, so we subtract one. | 525 // the left of the drop indicator, so we subtract one. |
| 497 // * Well, it can also point to the end, but not when dragging to the left. :) | 526 // * Well, it can also point to the end, but not when dragging to the left. :) |
| 498 if (i > data.index()) | 527 if (i > data.index()) |
| 499 --i; | 528 --i; |
| 500 | 529 |
| 501 if (profile_->IsOffTheRecord()) | 530 if (profile_->IsOffTheRecord()) |
| 502 i = model_->IncognitoIndexToOriginal(i); | 531 i = model_->IncognitoIndexToOriginal(i); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 | 712 |
| 684 for (BrowserActionViews::iterator it = browser_action_views_.begin(); | 713 for (BrowserActionViews::iterator it = browser_action_views_.begin(); |
| 685 it != browser_action_views_.end(); ++it) { | 714 it != browser_action_views_.end(); ++it) { |
| 686 BrowserActionButton* button = (*it)->button(); | 715 BrowserActionButton* button = (*it)->button(); |
| 687 if (button && button->extension() == extension) | 716 if (button && button->extension() == extension) |
| 688 return ShowPopup(button, ExtensionPopup::SHOW, should_grant); | 717 return ShowPopup(button, ExtensionPopup::SHOW, should_grant); |
| 689 } | 718 } |
| 690 return false; | 719 return false; |
| 691 } | 720 } |
| 692 | 721 |
| 722 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { | |
| 723 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; | |
| 724 } | |
| 725 | |
| 693 void BrowserActionsContainer::HidePopup() { | 726 void BrowserActionsContainer::HidePopup() { |
| 694 // Remove this as an observer and clear |popup_| and |popup_button_| here, | 727 // Remove this as an observer and clear |popup_| and |popup_button_| here, |
| 695 // since we might change them before OnWidgetDestroying() gets called. | 728 // since we might change them before OnWidgetDestroying() gets called. |
| 696 if (popup_) { | 729 if (popup_) { |
| 697 popup_->GetWidget()->RemoveObserver(this); | 730 popup_->GetWidget()->RemoveObserver(this); |
| 698 popup_->GetWidget()->Close(); | 731 popup_->GetWidget()->Close(); |
| 699 popup_ = NULL; | 732 popup_ = NULL; |
| 700 } | 733 } |
| 701 if (popup_button_) { | 734 if (popup_button_) { |
| 702 popup_button_->SetButtonNotPushed(); | 735 popup_button_->SetButtonNotPushed(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 720 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 753 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
| 721 // If the views haven't been initialized yet, wait for the next call to | 754 // If the views haven't been initialized yet, wait for the next call to |
| 722 // paint (one will be triggered by entering highlight mode). | 755 // paint (one will be triggered by entering highlight mode). |
| 723 if (model_->is_highlighting() && !browser_action_views_.empty()) { | 756 if (model_->is_highlighting() && !browser_action_views_.empty()) { |
| 724 views::Painter::PaintPainterAt( | 757 views::Painter::PaintPainterAt( |
| 725 canvas, highlight_painter_.get(), GetLocalBounds()); | 758 canvas, highlight_painter_.get(), GetLocalBounds()); |
| 726 } | 759 } |
| 727 | 760 |
| 728 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while | 761 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while |
| 729 // dragging (like we do for tab dragging). | 762 // dragging (like we do for tab dragging). |
| 730 if (drop_indicator_position_ > -1) { | 763 if (drop_position_.get()) { |
| 731 // The two-pixel width drop indicator. | 764 // The two-pixel width drop indicator. |
| 732 static const int kDropIndicatorWidth = 2; | 765 static const int kDropIndicatorWidth = 2; |
| 733 gfx::Rect indicator_bounds( | 766 |
| 734 drop_indicator_position_ - (kDropIndicatorWidth / 2), | 767 // Convert back to a pixel offset into the container. First find the X |
| 735 0, | 768 // coordinate of the drop icon. |
| 736 kDropIndicatorWidth, | 769 int drop_icon_x = browser_action_views_[GetFirstVisibleIconIndex()]->x() + |
| 737 height()); | 770 (drop_position_->icon_in_row * IconWidth(true)); |
| 771 // Next, find the space before the previous icon. This will either be | |
|
Peter Kasting
2014/07/22 22:17:03
Nit: I think you either mean to say "the space aft
Devlin
2014/07/22 22:24:38
d'oh. Done.
| |
| 772 // kItemSpacing or ToolbarView::kStandardSpacing, depending on whether this | |
| 773 // is the first icon. | |
| 774 // NOTE: Right now, these are the same. But let's do this right for if they | |
| 775 // ever aren't. | |
| 776 int space_before_icon = drop_position_->icon_in_row == 0 ? | |
| 777 ToolbarView::kStandardSpacing : kItemSpacing; | |
| 778 // Now place the drop indicator halfway between this and the end of the | |
| 779 // previous icon. If there is an odd amount of available space between the | |
| 780 // two icons (or the icon and the address bar) after subtracting the drop | |
| 781 // indicator width, this calculation puts the extra pixel on the left side | |
| 782 // of the indicator, since when the indicator is between the address bar and | |
| 783 // the first icon, it looks better closer to the icon. | |
| 784 int drop_indicator_x = drop_icon_x - | |
| 785 ((space_before_icon + kDropIndicatorWidth) / 2); | |
| 786 int row_height = IconHeight(); | |
| 787 int drop_indicator_y = row_height * drop_position_->row; | |
| 788 gfx::Rect indicator_bounds(drop_indicator_x, | |
| 789 drop_indicator_y, | |
| 790 kDropIndicatorWidth, | |
| 791 row_height); | |
| 792 indicator_bounds.set_x(GetMirroredXForRect(indicator_bounds)); | |
| 738 | 793 |
| 739 // Color of the drop indicator. | 794 // Color of the drop indicator. |
| 740 static const SkColor kDropIndicatorColor = SK_ColorBLACK; | 795 static const SkColor kDropIndicatorColor = SK_ColorBLACK; |
| 741 canvas->FillRect(indicator_bounds, kDropIndicatorColor); | 796 canvas->FillRect(indicator_bounds, kDropIndicatorColor); |
| 742 } | 797 } |
| 743 } | 798 } |
| 744 | 799 |
| 745 void BrowserActionsContainer::OnThemeChanged() { | 800 void BrowserActionsContainer::OnThemeChanged() { |
| 746 LoadImages(); | 801 LoadImages(); |
| 747 } | 802 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 void BrowserActionsContainer::StartShowFolderDropMenuTimer() { | 993 void BrowserActionsContainer::StartShowFolderDropMenuTimer() { |
| 939 base::MessageLoop::current()->PostDelayedTask( | 994 base::MessageLoop::current()->PostDelayedTask( |
| 940 FROM_HERE, | 995 FROM_HERE, |
| 941 base::Bind(&BrowserActionsContainer::ShowDropFolder, | 996 base::Bind(&BrowserActionsContainer::ShowDropFolder, |
| 942 show_menu_task_factory_.GetWeakPtr()), | 997 show_menu_task_factory_.GetWeakPtr()), |
| 943 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); | 998 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); |
| 944 } | 999 } |
| 945 | 1000 |
| 946 void BrowserActionsContainer::ShowDropFolder() { | 1001 void BrowserActionsContainer::ShowDropFolder() { |
| 947 DCHECK(!overflow_menu_); | 1002 DCHECK(!overflow_menu_); |
| 948 SetDropIndicator(-1); | 1003 drop_position_.reset(); |
| 949 overflow_menu_ = | 1004 overflow_menu_ = |
| 950 new BrowserActionOverflowMenuController(this, | 1005 new BrowserActionOverflowMenuController(this, |
| 951 browser_, | 1006 browser_, |
| 952 chevron_, | 1007 chevron_, |
| 953 browser_action_views_, | 1008 browser_action_views_, |
| 954 VisibleBrowserActions(), | 1009 VisibleBrowserActions(), |
| 955 true); | 1010 true); |
| 956 overflow_menu_->set_observer(this); | 1011 overflow_menu_->set_observer(this); |
| 957 overflow_menu_->RunMenu(GetWidget()); | 1012 overflow_menu_->RunMenu(GetWidget()); |
| 958 } | 1013 } |
| 959 | 1014 |
| 960 void BrowserActionsContainer::SetDropIndicator(int x_pos) { | |
| 961 if (drop_indicator_position_ != x_pos) { | |
| 962 drop_indicator_position_ = x_pos; | |
| 963 SchedulePaint(); | |
| 964 } | |
| 965 } | |
| 966 | |
| 967 int BrowserActionsContainer::IconCountToWidth(int icons, | 1015 int BrowserActionsContainer::IconCountToWidth(int icons, |
| 968 bool display_chevron) const { | 1016 bool display_chevron) const { |
| 969 if (icons < 0) | 1017 if (icons < 0) |
| 970 icons = browser_action_views_.size(); | 1018 icons = browser_action_views_.size(); |
| 971 if ((icons == 0) && !display_chevron) | 1019 if ((icons == 0) && !display_chevron) |
| 972 return ToolbarView::kStandardSpacing; | 1020 return ToolbarView::kStandardSpacing; |
| 973 int icons_size = | 1021 int icons_size = |
| 974 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); | 1022 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); |
| 975 int chevron_size = chevron_ && display_chevron ? | 1023 int chevron_size = chevron_ && display_chevron ? |
| 976 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; | 1024 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 views::BubbleBorder::TOP_RIGHT, | 1112 views::BubbleBorder::TOP_RIGHT, |
| 1065 show_action); | 1113 show_action); |
| 1066 popup_->GetWidget()->AddObserver(this); | 1114 popup_->GetWidget()->AddObserver(this); |
| 1067 popup_button_ = button; | 1115 popup_button_ = button; |
| 1068 | 1116 |
| 1069 // Only set button as pushed if it was triggered by a user click. | 1117 // Only set button as pushed if it was triggered by a user click. |
| 1070 if (should_grant) | 1118 if (should_grant) |
| 1071 popup_button_->SetButtonPushed(); | 1119 popup_button_->SetButtonPushed(); |
| 1072 return true; | 1120 return true; |
| 1073 } | 1121 } |
| OLD | NEW |