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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // static | 102 // static |
| 103 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 103 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
| 104 | 104 |
| 105 struct BrowserActionsContainer::DropPosition { | |
| 106 DropPosition(size_t row, size_t icon_in_row); | |
| 107 ~DropPosition(); | |
| 108 | |
| 109 // The (0-indexed) row into which the action will be dropped. | |
| 110 size_t row; | |
| 111 | |
| 112 // The (0-indexed) icon in the row before the action will be dropped. | |
| 113 size_t icon_in_row; | |
| 114 }; | |
| 115 | |
| 116 BrowserActionsContainer::DropPosition::DropPosition( | |
| 117 size_t row, size_t icon_in_row) | |
| 118 : row(row), icon_in_row(icon_in_row) { | |
| 119 } | |
| 120 | |
| 121 BrowserActionsContainer::DropPosition::~DropPosition() { | |
| 122 } | |
| 123 | |
| 105 //////////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////////// |
| 106 // BrowserActionsContainer | 125 // BrowserActionsContainer |
| 107 | 126 |
| 108 BrowserActionsContainer::BrowserActionsContainer( | 127 BrowserActionsContainer::BrowserActionsContainer( |
| 109 Browser* browser, | 128 Browser* browser, |
| 110 View* owner_view, | 129 View* owner_view, |
| 111 BrowserActionsContainer* main_container) | 130 BrowserActionsContainer* main_container) |
| 112 : profile_(browser->profile()), | 131 : profile_(browser->profile()), |
| 113 browser_(browser), | 132 browser_(browser), |
| 114 owner_view_(owner_view), | 133 owner_view_(owner_view), |
| 115 main_container_(main_container), | 134 main_container_(main_container), |
| 116 popup_(NULL), | 135 popup_(NULL), |
| 117 popup_button_(NULL), | 136 popup_button_(NULL), |
| 118 model_(NULL), | 137 model_(NULL), |
| 119 container_width_(0), | 138 container_width_(0), |
| 120 resize_area_(NULL), | 139 resize_area_(NULL), |
| 121 chevron_(NULL), | 140 chevron_(NULL), |
| 122 overflow_menu_(NULL), | 141 overflow_menu_(NULL), |
| 123 suppress_chevron_(false), | 142 suppress_chevron_(false), |
| 124 resize_amount_(0), | 143 resize_amount_(0), |
| 125 animation_target_size_(0), | 144 animation_target_size_(0), |
| 126 drop_indicator_position_(-1), | |
| 127 task_factory_(this), | 145 task_factory_(this), |
| 128 show_menu_task_factory_(this) { | 146 show_menu_task_factory_(this) { |
| 129 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 147 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
| 130 | 148 |
| 131 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); | 149 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); |
| 132 if (model_) | 150 if (model_) |
| 133 model_->AddObserver(this); | 151 model_->AddObserver(this); |
| 134 | 152 |
| 135 bool overflow_experiment = | 153 bool overflow_experiment = |
| 136 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); | 154 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 | 370 // Ensure that any browser actions shown in the main view are hidden in |
| 353 // the overflow view. | 371 // the overflow view. |
| 354 browser_action_views_[i]->SetVisible(false); | 372 browser_action_views_[i]->SetVisible(false); |
| 355 } | 373 } |
| 356 | 374 |
| 357 for (size_t i = main_container_->VisibleBrowserActionsAfterAnimation(); | 375 for (size_t i = main_container_->VisibleBrowserActionsAfterAnimation(); |
| 358 i < browser_action_views_.size(); ++i) { | 376 i < browser_action_views_.size(); ++i) { |
| 359 BrowserActionView* view = browser_action_views_[i]; | 377 BrowserActionView* view = browser_action_views_[i]; |
| 360 size_t index = i - main_container_->VisibleBrowserActionsAfterAnimation(); | 378 size_t index = i - main_container_->VisibleBrowserActionsAfterAnimation(); |
| 361 int row_index = static_cast<int>(index) / kIconsPerMenuRow; | 379 int row_index = static_cast<int>(index) / kIconsPerMenuRow; |
| 362 int x = (index * IconWidth(true)) - | 380 int x = kItemSpacing + (index * IconWidth(true)) - |
|
Devlin
2014/07/17 22:26:30
We need this so that we can see the drop indicator
| |
| 363 (row_index * IconWidth(true) * kIconsPerMenuRow); | 381 (row_index * IconWidth(true) * kIconsPerMenuRow); |
| 364 gfx::Rect rect_bounds( | 382 gfx::Rect rect_bounds( |
| 365 x, IconHeight() * row_index, icon_width, IconHeight()); | 383 x, IconHeight() * row_index, icon_width, IconHeight()); |
| 366 view->SetBoundsRect(rect_bounds); | 384 view->SetBoundsRect(rect_bounds); |
| 367 view->SetVisible(true); | 385 view->SetVisible(true); |
| 368 } | 386 } |
| 369 } else { | 387 } else { |
| 370 for (BrowserActionViews::const_iterator it = browser_action_views_.begin(); | 388 for (BrowserActionViews::const_iterator it = browser_action_views_.begin(); |
| 371 it < browser_action_views_.end(); ++it) { | 389 it < browser_action_views_.end(); ++it) { |
| 372 BrowserActionView* view = *it; | 390 BrowserActionView* view = *it; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 400 int BrowserActionsContainer::OnDragUpdated( | 418 int BrowserActionsContainer::OnDragUpdated( |
| 401 const ui::DropTargetEvent& event) { | 419 const ui::DropTargetEvent& event) { |
| 402 // First check if we are above the chevron (overflow) menu. | 420 // First check if we are above the chevron (overflow) menu. |
| 403 if (GetEventHandlerForPoint(event.location()) == chevron_) { | 421 if (GetEventHandlerForPoint(event.location()) == chevron_) { |
| 404 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) | 422 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) |
| 405 StartShowFolderDropMenuTimer(); | 423 StartShowFolderDropMenuTimer(); |
| 406 return ui::DragDropTypes::DRAG_MOVE; | 424 return ui::DragDropTypes::DRAG_MOVE; |
| 407 } | 425 } |
| 408 StopShowFolderDropMenuTimer(); | 426 StopShowFolderDropMenuTimer(); |
| 409 | 427 |
| 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: | 428 // Figure out where to display the indicator. This is a complex calculation: |
| 414 | 429 |
| 415 // First, we figure out how much space is to the left of the icon area, so we | 430 // 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. | 431 // can calculate the true offset into the icon area. The easiest way to do |
| 417 int width_before_icons = ToolbarView::kStandardSpacing; | 432 // this is to just find where the first icon starts. |
| 418 if (chevron_ && base::i18n::IsRTL()) { | 433 int width_before_icons = |
| 419 width_before_icons += | 434 browser_action_views_[GetFirstVisibleIconIndex()]->x(); |
|
Finnur
2014/07/18 10:52:41
Will this work in RTL?
Devlin
2014/07/18 17:58:20
Nope! But it does now. :)
| |
| 420 chevron_->GetPreferredSize().width() + kChevronSpacing; | |
| 421 } | |
| 422 int offset_into_icon_area = event.x() - width_before_icons; | 435 int offset_into_icon_area = event.x() - width_before_icons; |
| 423 | 436 |
| 437 // Next, figure out what row we're on. This only matters for overflow mode, | |
| 438 // but the calculation is the same for both. | |
| 439 int row_index = event.y() / IconHeight(); | |
| 440 | |
| 441 // Sanity check - we should never be on a different row in the main container. | |
| 442 DCHECK(in_overflow_mode() || row_index == 0); | |
| 443 | |
| 424 // Next, we determine which icon to place the indicator in front of. We want | 444 // 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 | 445 // 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 | 446 // midpoints of icons (n - 1) and n. To do this we take the offset into the |
| 427 // icon area and transform it as follows: | 447 // icon area and transform it as follows: |
| 428 // | 448 // |
| 429 // Real icon area: | 449 // Real icon area: |
| 430 // 0 a * b c | 450 // 0 a * b c |
| 431 // | | | | | 451 // | | | | |
| 432 // |[IC|ON] [IC|ON] [IC|ON] | 452 // |[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. | 453 // 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 | 454 // Here the "*" represents the offset into the icon area, and since it's |
| 435 // between a and b, we want to return "1". | 455 // between a and b, we want to return "1". |
| 436 // | 456 // |
| 437 // Transformed "icon area": | 457 // Transformed "icon area": |
| 438 // 0 a * b c | 458 // 0 a * b c |
| 439 // | | | | | 459 // | | | | |
| 440 // |[ICON] |[ICON] |[ICON] | | 460 // |[ICON] |[ICON] |[ICON] | |
| 441 // If we shift both our offset and our divider points later by half an icon | 461 // 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 | 462 // 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 | 463 // divider points we've passed, because they're the multiples of "one icon |
| 444 // plus padding". | 464 // plus padding". |
| 445 int before_icon_unclamped = (offset_into_icon_area + (IconWidth(false) / 2) + | 465 int before_icon_unclamped = (offset_into_icon_area + (IconWidth(false) / 2) + |
| 446 kItemSpacing) / IconWidth(true); | 466 kItemSpacing) / IconWidth(true); |
| 447 | 467 |
| 468 // We need to figure out how many icons are visible on the relevant row. | |
| 469 // In the main container, this will just be the visible actions. | |
| 470 int visible_icons_on_row = VisibleBrowserActionsAfterAnimation(); | |
| 471 if (in_overflow_mode()) { | |
| 472 // If this is the final row of the overflow, then this is the remainder of | |
| 473 // visible icons. Otherwise, it's a full row (kIconsPerRow). | |
| 474 visible_icons_on_row = | |
| 475 row_index == (visible_icons_on_row / kIconsPerMenuRow) ? | |
| 476 visible_icons_on_row % kIconsPerMenuRow : | |
| 477 kIconsPerMenuRow; | |
| 478 } | |
| 479 | |
| 448 // Because the user can drag outside the container bounds, we need to clamp to | 480 // 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 | 481 // 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 | 482 // (num icons - 1), because we represent the indicator being past the last |
| 451 // icon as being "before the (last + 1) icon". | 483 // icon as being "before the (last + 1) icon". |
| 452 int before_icon = std::min(std::max(before_icon_unclamped, 0), | 484 int before_icon_in_row = |
| 453 static_cast<int>(VisibleBrowserActions())); | 485 std::min(std::max(before_icon_unclamped, 0), visible_icons_on_row); |
|
Devlin
2014/07/17 22:26:30
These calculations plus using a row/icon_on_row st
| |
| 454 | 486 |
| 455 // Now we convert back to a pixel offset into the container. We want to place | 487 SetDropPosition(row_index, before_icon_in_row); |
| 456 // the center of the drop indicator at the midpoint of the space before our | |
| 457 // chosen icon. | |
| 458 SetDropIndicator(width_before_icons + (before_icon * IconWidth(true)) - | |
| 459 (kItemSpacing / 2)); | |
| 460 | 488 |
| 461 return ui::DragDropTypes::DRAG_MOVE; | 489 return ui::DragDropTypes::DRAG_MOVE; |
| 462 } | 490 } |
| 463 | 491 |
| 464 void BrowserActionsContainer::OnDragExited() { | 492 void BrowserActionsContainer::OnDragExited() { |
| 465 StopShowFolderDropMenuTimer(); | 493 StopShowFolderDropMenuTimer(); |
| 466 drop_indicator_position_ = -1; | 494 ResetDropPosition(); |
| 467 SchedulePaint(); | 495 SchedulePaint(); |
| 468 } | 496 } |
| 469 | 497 |
| 470 int BrowserActionsContainer::OnPerformDrop( | 498 int BrowserActionsContainer::OnPerformDrop( |
| 471 const ui::DropTargetEvent& event) { | 499 const ui::DropTargetEvent& event) { |
| 472 BrowserActionDragData data; | 500 BrowserActionDragData data; |
| 473 if (!data.Read(event.data())) | 501 if (!data.Read(event.data())) |
| 474 return ui::DragDropTypes::DRAG_NONE; | 502 return ui::DragDropTypes::DRAG_NONE; |
| 475 | 503 |
| 476 // Make sure we have the same view as we started with. | 504 // Make sure we have the same view as we started with. |
| 477 DCHECK_EQ(browser_action_views_[data.index()]->button()->extension()->id(), | 505 DCHECK_EQ(browser_action_views_[data.index()]->button()->extension()->id(), |
| 478 data.id()); | 506 data.id()); |
| 479 DCHECK(model_); | 507 DCHECK(model_); |
| 480 | 508 |
| 481 size_t i = 0; | 509 size_t i = |
| 482 for (; i < browser_action_views_.size(); ++i) { | 510 drop_position_->row * kIconsPerMenuRow + drop_position_->icon_in_row; |
| 483 int view_x = browser_action_views_[i]->GetMirroredBounds().x(); | 511 if (in_overflow_mode()) |
| 484 if (!browser_action_views_[i]->visible() || | 512 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 | 513 // |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, | 514 // 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 | 515 // 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. | 516 // 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. :) | 517 // * Well, it can also point to the end, but not when dragging to the left. :) |
| 498 if (i > data.index()) | 518 if (i > data.index()) |
| 499 --i; | 519 --i; |
| 500 | 520 |
| 501 if (profile_->IsOffTheRecord()) | 521 if (profile_->IsOffTheRecord()) |
| 502 i = model_->IncognitoIndexToOriginal(i); | 522 i = model_->IncognitoIndexToOriginal(i); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 | 703 |
| 684 for (BrowserActionViews::iterator it = browser_action_views_.begin(); | 704 for (BrowserActionViews::iterator it = browser_action_views_.begin(); |
| 685 it != browser_action_views_.end(); ++it) { | 705 it != browser_action_views_.end(); ++it) { |
| 686 BrowserActionButton* button = (*it)->button(); | 706 BrowserActionButton* button = (*it)->button(); |
| 687 if (button && button->extension() == extension) | 707 if (button && button->extension() == extension) |
| 688 return ShowPopup(button, ExtensionPopup::SHOW, should_grant); | 708 return ShowPopup(button, ExtensionPopup::SHOW, should_grant); |
| 689 } | 709 } |
| 690 return false; | 710 return false; |
| 691 } | 711 } |
| 692 | 712 |
| 713 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { | |
| 714 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; | |
| 715 } | |
| 716 | |
| 693 void BrowserActionsContainer::HidePopup() { | 717 void BrowserActionsContainer::HidePopup() { |
| 694 // Remove this as an observer and clear |popup_| and |popup_button_| here, | 718 // Remove this as an observer and clear |popup_| and |popup_button_| here, |
| 695 // since we might change them before OnWidgetDestroying() gets called. | 719 // since we might change them before OnWidgetDestroying() gets called. |
| 696 if (popup_) { | 720 if (popup_) { |
| 697 popup_->GetWidget()->RemoveObserver(this); | 721 popup_->GetWidget()->RemoveObserver(this); |
| 698 popup_->GetWidget()->Close(); | 722 popup_->GetWidget()->Close(); |
| 699 popup_ = NULL; | 723 popup_ = NULL; |
| 700 } | 724 } |
| 701 if (popup_button_) { | 725 if (popup_button_) { |
| 702 popup_button_->SetButtonNotPushed(); | 726 popup_button_->SetButtonNotPushed(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 720 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 744 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
| 721 // If the views haven't been initialized yet, wait for the next call to | 745 // If the views haven't been initialized yet, wait for the next call to |
| 722 // paint (one will be triggered by entering highlight mode). | 746 // paint (one will be triggered by entering highlight mode). |
| 723 if (model_->is_highlighting() && !browser_action_views_.empty()) { | 747 if (model_->is_highlighting() && !browser_action_views_.empty()) { |
| 724 views::Painter::PaintPainterAt( | 748 views::Painter::PaintPainterAt( |
| 725 canvas, highlight_painter_.get(), GetLocalBounds()); | 749 canvas, highlight_painter_.get(), GetLocalBounds()); |
| 726 } | 750 } |
| 727 | 751 |
| 728 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while | 752 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while |
| 729 // dragging (like we do for tab dragging). | 753 // dragging (like we do for tab dragging). |
| 730 if (drop_indicator_position_ > -1) { | 754 if (drop_position_.get()) { |
| 731 // The two-pixel width drop indicator. | 755 // The two-pixel width drop indicator. |
| 732 static const int kDropIndicatorWidth = 2; | 756 static const int kDropIndicatorWidth = 2; |
| 733 gfx::Rect indicator_bounds( | 757 |
| 734 drop_indicator_position_ - (kDropIndicatorWidth / 2), | 758 // Convert back to a pixel offset into the container. We want to place |
| 735 0, | 759 // the center of the drop indicator at the midpoint of the space before our |
| 736 kDropIndicatorWidth, | 760 // chosen icon. |
|
Finnur
2014/07/18 10:52:41
Nit: "Chosen icon" is a bit weird here, because yo
Devlin
2014/07/18 17:58:20
Done.
| |
| 737 height()); | 761 // This is: |
| 762 // The width before the first icon, plus | |
| 763 // The width of all icons before the target icon in the row, minus | |
| 764 // Half the spacing between the target icon and the previous icon, minus | |
| 765 // Half the width of the drop indicator, so it's centered. | |
| 766 int drop_indicator_x = | |
| 767 browser_action_views_[GetFirstVisibleIconIndex()]->x() + | |
| 768 drop_position_->icon_in_row * IconWidth(true) - | |
| 769 kItemSpacing / 2 - | |
| 770 kDropIndicatorWidth / 2; | |
| 771 | |
| 772 // The y is simply the start of the row (which for the main container is | |
| 773 // always 0). | |
| 774 int drop_indicator_y = IconHeight() * drop_position_->row; | |
| 775 | |
| 776 gfx::Rect indicator_bounds(drop_indicator_x, | |
| 777 drop_indicator_y, | |
| 778 kDropIndicatorWidth, | |
| 779 IconHeight()); | |
| 738 | 780 |
| 739 // Color of the drop indicator. | 781 // Color of the drop indicator. |
| 740 static const SkColor kDropIndicatorColor = SK_ColorBLACK; | 782 static const SkColor kDropIndicatorColor = SK_ColorBLACK; |
| 741 canvas->FillRect(indicator_bounds, kDropIndicatorColor); | 783 canvas->FillRect(indicator_bounds, kDropIndicatorColor); |
| 742 } | 784 } |
| 743 } | 785 } |
| 744 | 786 |
| 745 void BrowserActionsContainer::OnThemeChanged() { | 787 void BrowserActionsContainer::OnThemeChanged() { |
| 746 LoadImages(); | 788 LoadImages(); |
| 747 } | 789 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 void BrowserActionsContainer::StartShowFolderDropMenuTimer() { | 980 void BrowserActionsContainer::StartShowFolderDropMenuTimer() { |
| 939 base::MessageLoop::current()->PostDelayedTask( | 981 base::MessageLoop::current()->PostDelayedTask( |
| 940 FROM_HERE, | 982 FROM_HERE, |
| 941 base::Bind(&BrowserActionsContainer::ShowDropFolder, | 983 base::Bind(&BrowserActionsContainer::ShowDropFolder, |
| 942 show_menu_task_factory_.GetWeakPtr()), | 984 show_menu_task_factory_.GetWeakPtr()), |
| 943 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); | 985 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); |
| 944 } | 986 } |
| 945 | 987 |
| 946 void BrowserActionsContainer::ShowDropFolder() { | 988 void BrowserActionsContainer::ShowDropFolder() { |
| 947 DCHECK(!overflow_menu_); | 989 DCHECK(!overflow_menu_); |
| 948 SetDropIndicator(-1); | 990 ResetDropPosition(); |
| 949 overflow_menu_ = | 991 overflow_menu_ = |
| 950 new BrowserActionOverflowMenuController(this, | 992 new BrowserActionOverflowMenuController(this, |
| 951 browser_, | 993 browser_, |
| 952 chevron_, | 994 chevron_, |
| 953 browser_action_views_, | 995 browser_action_views_, |
| 954 VisibleBrowserActions(), | 996 VisibleBrowserActions(), |
| 955 true); | 997 true); |
| 956 overflow_menu_->set_observer(this); | 998 overflow_menu_->set_observer(this); |
| 957 overflow_menu_->RunMenu(GetWidget()); | 999 overflow_menu_->RunMenu(GetWidget()); |
| 958 } | 1000 } |
| 959 | 1001 |
| 960 void BrowserActionsContainer::SetDropIndicator(int x_pos) { | 1002 void BrowserActionsContainer::SetDropPosition(size_t row, size_t icon_in_row) { |
| 961 if (drop_indicator_position_ != x_pos) { | 1003 if (!drop_position_.get() || |
| 962 drop_indicator_position_ = x_pos; | 1004 !(drop_position_->row == row && |
| 1005 drop_position_->icon_in_row == icon_in_row)) { | |
| 1006 drop_position_.reset(new DropPosition(row, icon_in_row)); | |
| 963 SchedulePaint(); | 1007 SchedulePaint(); |
| 964 } | 1008 } |
| 965 } | 1009 } |
| 966 | 1010 |
| 1011 void BrowserActionsContainer::ResetDropPosition() { | |
| 1012 drop_position_.reset(); | |
| 1013 } | |
| 1014 | |
| 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 |