Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar/browser_actions_container.cc |
| diff --git a/chrome/browser/ui/views/toolbar/browser_actions_container.cc b/chrome/browser/ui/views/toolbar/browser_actions_container.cc |
| index 5ed94f3e2f00e37eb91ffd966dbf4b2c33d79a12..a5282f40edd718a52751bb2f9c046ec591d84b00 100644 |
| --- a/chrome/browser/ui/views/toolbar/browser_actions_container.cc |
| +++ b/chrome/browser/ui/views/toolbar/browser_actions_container.cc |
| @@ -274,9 +274,7 @@ bool BrowserActionsContainer::ShownInsideMenu() const { |
| } |
| void BrowserActionsContainer::OnBrowserActionViewDragDone() { |
| - // We notify here as well as in OnPerformDrop because the dragged view is |
| - // removed in OnPerformDrop, so it will never get its OnDragDone() call. |
| - // TODO(devlin): we should see about fixing that. |
| + ToolbarVisibleCountChanged(); |
| FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| observers_, |
| OnBrowserActionDragDone()); |
| @@ -424,7 +422,7 @@ bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { |
| int BrowserActionsContainer::OnDragUpdated( |
| const ui::DropTargetEvent& event) { |
| // First check if we are above the chevron (overflow) menu. |
| - if (GetEventHandlerForPoint(event.location()) == chevron_) { |
| + if (chevron_ && GetEventHandlerForPoint(event.location()) == chevron_) { |
| if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) |
| StartShowFolderDropMenuTimer(); |
| return ui::DragDropTypes::DRAG_MOVE; |
| @@ -537,13 +535,44 @@ int BrowserActionsContainer::OnPerformDrop( |
| if (profile_->IsOffTheRecord()) |
| i = model_->IncognitoIndexToOriginal(i); |
| + // Check if the size of the toolbar needs to be adjusted; this happens when |
| + // dragging from overflow to main or vice versa. We can check if this happened |
| + // by seeing if the view is visible - if it's not, then the drag originated |
| + // from the other container. |
| + int size_modifier = 0; |
| + if (!browser_action_views_[data.index()]->visible()) { |
| + if (i > data.index()) { |
|
Finnur
2014/09/10 09:48:01
I understand why dragging an icon to the left subt
Devlin
2014/09/10 15:58:30
Wow. Yeah, that's easier. Shoulda seen that... t
|
| + // Dragging to the right, so hiding one. |
| + size_modifier = -1; |
| + } else if (i < data.index()) { |
| + // Dragging to the left, so showing one. |
| + size_modifier = 1; |
| + } else { // i == data.index() |
| + // Edge case: dragging to the same index, but in the other menu. |
| + // If this was *dropped* in the overflow container, then we're hiding one, |
| + // otherwise we're showing one. |
| + size_modifier = in_overflow_mode() ? -1 : 1; |
| + } |
| + } |
| + |
| model_->MoveExtensionIcon( |
| browser_action_views_[data.index()]->extension(), i); |
| + // Adjust the size of the container, if needed. |
| + if (size_modifier) { |
| + // Let the main container update the model. |
| + if (in_overflow_mode()) { |
| + main_container_->NotifyActionMovedToOverflow(); |
| + } else if (!profile_->IsOffTheRecord()) { |
| + model_->SetVisibleIconCount( |
| + model_->GetVisibleIconCount() + size_modifier); |
| + } |
| + |
| + // The size changed, so we need to animate. |
| + Animate(gfx::Tween::EASE_OUT, GetIconCount()); |
| + } |
| + |
| OnDragExited(); // Perform clean up after dragging. |
| - FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| - observers_, |
| - OnBrowserActionDragDone()); |
| return ui::DragDropTypes::DRAG_MOVE; |
| } |
| @@ -625,7 +654,6 @@ void BrowserActionsContainer::OnResize(int resize_amount, bool done_resizing) { |
| int visible_icons = WidthToIconCount(container_width_); |
| if (!profile_->IsOffTheRecord()) |
| model_->SetVisibleIconCount(visible_icons); |
| - |
| Animate(gfx::Tween::EASE_OUT, visible_icons); |
| } |
| @@ -656,6 +684,15 @@ void BrowserActionsContainer::NotifyMenuDeleted( |
| overflow_menu_ = NULL; |
| } |
| +void BrowserActionsContainer::NotifyActionMovedToOverflow() { |
| + // When an action is moved to overflow, we shrink the size of the container |
| + // by 1. |
| + if (!profile_->IsOffTheRecord()) |
| + model_->SetVisibleIconCount(model_->GetVisibleIconCount() - 1); |
| + Animate(gfx::Tween::EASE_OUT, |
| + VisibleBrowserActionsAfterAnimation() - 1); |
| +} |
| + |
| content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { |
| return browser_->tab_strip_model()->GetActiveWebContents(); |
| } |
| @@ -679,11 +716,7 @@ ExtensionPopup* BrowserActionsContainer::TestGetPopup() { |
| } |
| void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { |
| - model_->SetVisibleIconCount(icons); |
| - chevron_->SetVisible(icons < browser_action_views_.size()); |
| - container_width_ = IconCountToWidth(icons, chevron_->visible()); |
| - Layout(); |
| - SchedulePaint(); |
| + model_->SetVisibleIconCountForTest(icons); |
| } |
| void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
| @@ -1017,11 +1050,12 @@ size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { |
| if (pixels >= IconCountToWidth(-1, false)) |
| return browser_action_views_.size(); |
| - // We need to reserve space for the resize area, chevron, and the spacing on |
| - // either side of the chevron. |
| - int available_space = pixels - ToolbarView::kStandardSpacing - |
| - (chevron_ ? chevron_->GetPreferredSize().width() : 0) - |
| - kChevronSpacing - ToolbarView::kStandardSpacing; |
| + // We reserve space for the padding on either side of the toolbar... |
| + int available_space = pixels - (ToolbarView::kStandardSpacing * 2); |
| + // ... and, if the chevron is enabled, the chevron. |
| + if (chevron_) |
| + available_space -= (chevron_->GetPreferredSize().width() + kChevronSpacing); |
| + |
| // Now we add an extra between-item padding value so the space can be divided |
| // evenly by (size of icon with padding). |
| return static_cast<size_t>( |