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/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
| 10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 //////////////////////////////////////////////////////////////////////////////// | 118 //////////////////////////////////////////////////////////////////////////////// |
| 119 // BrowserActionsContainer | 119 // BrowserActionsContainer |
| 120 | 120 |
| 121 // static | 121 // static |
| 122 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 122 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
| 123 | 123 |
| 124 BrowserActionsContainer::BrowserActionsContainer( | 124 BrowserActionsContainer::BrowserActionsContainer( |
| 125 Browser* browser, | 125 Browser* browser, |
| 126 View* owner_view, | 126 View* owner_view, |
| 127 BrowserActionsContainer* main_container) | 127 BrowserActionsContainer* main_container) |
| 128 : profile_(browser->profile()), | 128 : initialized_(false), |
| 129 profile_(browser->profile()), | |
| 129 browser_(browser), | 130 browser_(browser), |
| 130 owner_view_(owner_view), | 131 owner_view_(owner_view), |
| 131 main_container_(main_container), | 132 main_container_(main_container), |
| 132 popup_owner_(NULL), | 133 popup_owner_(NULL), |
| 133 model_(NULL), | 134 model_(NULL), |
| 134 container_width_(0), | 135 container_width_(0), |
| 135 resize_area_(NULL), | 136 resize_area_(NULL), |
| 136 chevron_(NULL), | 137 chevron_(NULL), |
| 137 overflow_menu_(NULL), | 138 overflow_menu_(NULL), |
| 138 suppress_chevron_(false), | 139 suppress_chevron_(false), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 | 190 |
| 190 void BrowserActionsContainer::Init() { | 191 void BrowserActionsContainer::Init() { |
| 191 LoadImages(); | 192 LoadImages(); |
| 192 | 193 |
| 193 // We wait to set the container width until now so that the chevron images | 194 // We wait to set the container width until now so that the chevron images |
| 194 // will be loaded. The width calculation needs to know the chevron size. | 195 // will be loaded. The width calculation needs to know the chevron size. |
| 195 if (model_ && model_->extensions_initialized()) { | 196 if (model_ && model_->extensions_initialized()) { |
| 196 container_width_ = GetPreferredWidth(); | 197 container_width_ = GetPreferredWidth(); |
| 197 SetChevronVisibility(); | 198 SetChevronVisibility(); |
| 198 } | 199 } |
| 200 | |
| 201 initialized_ = true; | |
| 199 } | 202 } |
| 200 | 203 |
| 201 BrowserActionView* BrowserActionsContainer::GetViewForExtension( | 204 BrowserActionView* BrowserActionsContainer::GetViewForExtension( |
| 202 const Extension* extension) { | 205 const Extension* extension) { |
| 203 for (BrowserActionViews::iterator view = browser_action_views_.begin(); | 206 for (BrowserActionViews::iterator view = browser_action_views_.begin(); |
| 204 view != browser_action_views_.end(); ++view) { | 207 view != browser_action_views_.end(); ++view) { |
| 205 if ((*view)->extension() == extension) | 208 if ((*view)->extension() == extension) |
| 206 return *view; | 209 return *view; |
| 207 } | 210 } |
| 208 return NULL; | 211 return NULL; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 void BrowserActionsContainer::ExecuteExtensionCommand( | 265 void BrowserActionsContainer::ExecuteExtensionCommand( |
| 263 const extensions::Extension* extension, | 266 const extensions::Extension* extension, |
| 264 const extensions::Command& command) { | 267 const extensions::Command& command) { |
| 265 // Global commands are handled by the ExtensionCommandsGlobalRegistry | 268 // Global commands are handled by the ExtensionCommandsGlobalRegistry |
| 266 // instance. | 269 // instance. |
| 267 DCHECK(!command.global()); | 270 DCHECK(!command.global()); |
| 268 extension_keybinding_registry_->ExecuteCommand(extension->id(), | 271 extension_keybinding_registry_->ExecuteCommand(extension->id(), |
| 269 command.accelerator()); | 272 command.accelerator()); |
| 270 } | 273 } |
| 271 | 274 |
| 275 void BrowserActionsContainer::NotifyActionMovedToOverflow() { | |
| 276 // When an action is moved to overflow, we shrink the size of the container | |
| 277 // by 1. | |
| 278 if (!profile_->IsOffTheRecord()) | |
| 279 model_->SetVisibleIconCount(model_->GetVisibleIconCount() - 1); | |
| 280 Animate(gfx::Tween::EASE_OUT, | |
| 281 VisibleBrowserActionsAfterAnimation() - 1); | |
| 282 } | |
| 283 | |
| 272 bool BrowserActionsContainer::ShownInsideMenu() const { | 284 bool BrowserActionsContainer::ShownInsideMenu() const { |
| 273 return in_overflow_mode(); | 285 return in_overflow_mode(); |
| 274 } | 286 } |
| 275 | 287 |
| 276 void BrowserActionsContainer::OnBrowserActionViewDragDone() { | 288 void BrowserActionsContainer::OnBrowserActionViewDragDone() { |
| 277 // We notify here as well as in OnPerformDrop because the dragged view is | 289 ToolbarVisibleCountChanged(); |
| 278 // removed in OnPerformDrop, so it will never get its OnDragDone() call. | |
| 279 // TODO(devlin): we should see about fixing that. | |
| 280 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 290 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 281 observers_, | 291 observers_, |
| 282 OnBrowserActionDragDone()); | 292 OnBrowserActionDragDone()); |
| 283 } | 293 } |
| 284 | 294 |
| 285 views::View* BrowserActionsContainer::GetOverflowReferenceView() { | 295 views::View* BrowserActionsContainer::GetOverflowReferenceView() { |
| 286 // We should only need an overflow reference when using the traditional | 296 // We should only need an overflow reference when using the traditional |
| 287 // chevron overflow. | 297 // chevron overflow. |
| 288 DCHECK(chevron_); | 298 DCHECK(chevron_); |
| 289 return chevron_; | 299 return chevron_; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 return BrowserActionDragData::AreDropTypesRequired(); | 427 return BrowserActionDragData::AreDropTypesRequired(); |
| 418 } | 428 } |
| 419 | 429 |
| 420 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { | 430 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { |
| 421 return BrowserActionDragData::CanDrop(data, profile_); | 431 return BrowserActionDragData::CanDrop(data, profile_); |
| 422 } | 432 } |
| 423 | 433 |
| 424 int BrowserActionsContainer::OnDragUpdated( | 434 int BrowserActionsContainer::OnDragUpdated( |
| 425 const ui::DropTargetEvent& event) { | 435 const ui::DropTargetEvent& event) { |
| 426 // First check if we are above the chevron (overflow) menu. | 436 // First check if we are above the chevron (overflow) menu. |
| 427 if (GetEventHandlerForPoint(event.location()) == chevron_) { | 437 if (chevron_ && GetEventHandlerForPoint(event.location()) == chevron_) { |
| 428 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) | 438 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) |
| 429 StartShowFolderDropMenuTimer(); | 439 StartShowFolderDropMenuTimer(); |
| 430 return ui::DragDropTypes::DRAG_MOVE; | 440 return ui::DragDropTypes::DRAG_MOVE; |
| 431 } | 441 } |
| 432 StopShowFolderDropMenuTimer(); | 442 StopShowFolderDropMenuTimer(); |
| 433 | 443 |
| 434 // Figure out where to display the indicator. This is a complex calculation: | 444 // Figure out where to display the indicator. This is a complex calculation: |
| 435 | 445 |
| 436 // First, we figure out how much space is to the left of the icon area, so we | 446 // First, we figure out how much space is to the left of the icon area, so we |
| 437 // can calculate the true offset into the icon area. The easiest way to do | 447 // can calculate the true offset into the icon area. The easiest way to do |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 // correct when dragging an icon to the left. When dragging to the right, | 540 // correct when dragging an icon to the left. When dragging to the right, |
| 531 // however, we want the icon being dragged to get the index of the item to | 541 // however, we want the icon being dragged to get the index of the item to |
| 532 // the left of the drop indicator, so we subtract one. | 542 // the left of the drop indicator, so we subtract one. |
| 533 // * Well, it can also point to the end, but not when dragging to the left. :) | 543 // * Well, it can also point to the end, but not when dragging to the left. :) |
| 534 if (i > data.index()) | 544 if (i > data.index()) |
| 535 --i; | 545 --i; |
| 536 | 546 |
| 537 if (profile_->IsOffTheRecord()) | 547 if (profile_->IsOffTheRecord()) |
| 538 i = model_->IncognitoIndexToOriginal(i); | 548 i = model_->IncognitoIndexToOriginal(i); |
| 539 | 549 |
| 550 // If this was a drag between containers, we will have to adjust the number of | |
| 551 // visible icons. | |
| 552 bool drag_between_containers = | |
| 553 !browser_action_views_[data.index()]->visible(); | |
| 540 model_->MoveExtensionIcon( | 554 model_->MoveExtensionIcon( |
| 541 browser_action_views_[data.index()]->extension(), i); | 555 browser_action_views_[data.index()]->extension(), i); |
| 542 | 556 |
| 557 if (drag_between_containers) { | |
| 558 // Add one for the dropped icon. | |
| 559 size_t new_icon_count = VisibleBrowserActionsAfterAnimation() + 1; | |
| 560 | |
| 561 // Let the main container update the model. | |
| 562 if (in_overflow_mode()) | |
| 563 main_container_->NotifyActionMovedToOverflow(); | |
| 564 else if (!profile_->IsOffTheRecord()) // This is the main container. | |
| 565 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); | |
| 566 | |
| 567 // The size changed, so we need to animate. | |
| 568 Animate(gfx::Tween::EASE_OUT, new_icon_count); | |
| 569 } | |
| 570 | |
| 543 OnDragExited(); // Perform clean up after dragging. | 571 OnDragExited(); // Perform clean up after dragging. |
| 544 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | |
| 545 observers_, | |
| 546 OnBrowserActionDragDone()); | |
| 547 return ui::DragDropTypes::DRAG_MOVE; | 572 return ui::DragDropTypes::DRAG_MOVE; |
| 548 } | 573 } |
| 549 | 574 |
| 550 void BrowserActionsContainer::GetAccessibleState( | 575 void BrowserActionsContainer::GetAccessibleState( |
| 551 ui::AXViewState* state) { | 576 ui::AXViewState* state) { |
| 552 state->role = ui::AX_ROLE_GROUP; | 577 state->role = ui::AX_ROLE_GROUP; |
| 553 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); | 578 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); |
| 554 } | 579 } |
| 555 | 580 |
| 556 void BrowserActionsContainer::OnMenuButtonClicked(views::View* source, | 581 void BrowserActionsContainer::OnMenuButtonClicked(views::View* source, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 | 643 |
| 619 // Save off the desired number of visible icons. We do this now instead of at | 644 // Save off the desired number of visible icons. We do this now instead of at |
| 620 // the end of the animation so that even if the browser is shut down while | 645 // the end of the animation so that even if the browser is shut down while |
| 621 // animating, the right value will be restored on next run. | 646 // animating, the right value will be restored on next run. |
| 622 // NOTE: Don't save the icon count in incognito because there may be fewer | 647 // NOTE: Don't save the icon count in incognito because there may be fewer |
| 623 // icons in that mode. The result is that the container in a normal window is | 648 // icons in that mode. The result is that the container in a normal window is |
| 624 // always at least as wide as in an incognito window. | 649 // always at least as wide as in an incognito window. |
| 625 int visible_icons = WidthToIconCount(container_width_); | 650 int visible_icons = WidthToIconCount(container_width_); |
| 626 if (!profile_->IsOffTheRecord()) | 651 if (!profile_->IsOffTheRecord()) |
| 627 model_->SetVisibleIconCount(visible_icons); | 652 model_->SetVisibleIconCount(visible_icons); |
| 628 | |
| 629 Animate(gfx::Tween::EASE_OUT, visible_icons); | 653 Animate(gfx::Tween::EASE_OUT, visible_icons); |
| 630 } | 654 } |
| 631 | 655 |
| 632 void BrowserActionsContainer::AnimationProgressed( | 656 void BrowserActionsContainer::AnimationProgressed( |
| 633 const gfx::Animation* animation) { | 657 const gfx::Animation* animation) { |
| 634 DCHECK_EQ(resize_animation_.get(), animation); | 658 DCHECK_EQ(resize_animation_.get(), animation); |
| 635 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * | 659 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * |
| 636 (container_width_ - animation_target_size_)); | 660 (container_width_ - animation_target_size_)); |
| 637 OnBrowserActionVisibilityChanged(); | 661 OnBrowserActionVisibilityChanged(); |
| 638 } | 662 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 664 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 688 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 665 content::WebContents* web_contents = | 689 content::WebContents* web_contents = |
| 666 browser_->tab_strip_model()->GetActiveWebContents(); | 690 browser_->tab_strip_model()->GetActiveWebContents(); |
| 667 if (!web_contents) | 691 if (!web_contents) |
| 668 return NULL; | 692 return NULL; |
| 669 return extensions::TabHelper::FromWebContents(web_contents)-> | 693 return extensions::TabHelper::FromWebContents(web_contents)-> |
| 670 active_tab_permission_granter(); | 694 active_tab_permission_granter(); |
| 671 } | 695 } |
| 672 | 696 |
| 673 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { | 697 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { |
| 674 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; | 698 return in_overflow_mode() ? |
| 699 main_container_->VisibleBrowserActionsAfterAnimation() : 0; | |
| 675 } | 700 } |
| 676 | 701 |
| 677 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { | 702 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { |
| 678 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; | 703 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; |
| 679 } | 704 } |
| 680 | 705 |
| 681 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { | 706 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { |
| 682 model_->SetVisibleIconCount(icons); | 707 model_->SetVisibleIconCountForTest(icons); |
| 683 chevron_->SetVisible(icons < browser_action_views_.size()); | |
| 684 container_width_ = IconCountToWidth(icons, chevron_->visible()); | |
| 685 Layout(); | |
| 686 SchedulePaint(); | |
| 687 } | 708 } |
| 688 | 709 |
| 689 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 710 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
| 690 // If the views haven't been initialized yet, wait for the next call to | 711 // If the views haven't been initialized yet, wait for the next call to |
| 691 // paint (one will be triggered by entering highlight mode). | 712 // paint (one will be triggered by entering highlight mode). |
| 692 if (model_->is_highlighting() && !browser_action_views_.empty()) { | 713 if (model_->is_highlighting() && !browser_action_views_.empty()) { |
| 693 views::Painter::PaintPainterAt( | 714 views::Painter::PaintPainterAt( |
| 694 canvas, highlight_painter_.get(), GetLocalBounds()); | 715 canvas, highlight_painter_.get(), GetLocalBounds()); |
| 695 } | 716 } |
| 696 | 717 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 945 | 966 |
| 946 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 967 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
| 947 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 968 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
| 948 } | 969 } |
| 949 | 970 |
| 950 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 971 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
| 951 SetVisible(!browser_action_views_.empty()); | 972 SetVisible(!browser_action_views_.empty()); |
| 952 if (owner_view_) { | 973 if (owner_view_) { |
| 953 owner_view_->Layout(); | 974 owner_view_->Layout(); |
| 954 owner_view_->SchedulePaint(); | 975 owner_view_->SchedulePaint(); |
| 976 } else { | |
| 977 // In overflow mode, we don't have an owner view, but we still have to | |
| 978 // update ourselves. | |
| 979 Layout(); | |
| 980 SchedulePaint(); | |
| 955 } | 981 } |
| 956 } | 982 } |
| 957 | 983 |
| 958 int BrowserActionsContainer::GetPreferredWidth() { | 984 int BrowserActionsContainer::GetPreferredWidth() { |
| 959 size_t visible_actions = GetIconCount(); | 985 size_t visible_actions = GetIconCount(); |
| 960 return IconCountToWidth( | 986 return IconCountToWidth( |
| 961 visible_actions, | 987 visible_actions, |
| 962 chevron_ && visible_actions < browser_action_views_.size()); | 988 chevron_ && visible_actions < browser_action_views_.size()); |
| 963 } | 989 } |
| 964 | 990 |
| 965 void BrowserActionsContainer::SetChevronVisibility() { | 991 void BrowserActionsContainer::SetChevronVisibility() { |
| 966 if (chevron_) | 992 if (chevron_) { |
| 967 chevron_->SetVisible(GetIconCount() < browser_action_views_.size()); | 993 chevron_->SetVisible( |
| 994 VisibleBrowserActionsAfterAnimation() < browser_action_views_.size()); | |
| 995 } | |
| 968 } | 996 } |
| 969 | 997 |
| 970 void BrowserActionsContainer::CloseOverflowMenu() { | 998 void BrowserActionsContainer::CloseOverflowMenu() { |
| 971 if (overflow_menu_) | 999 if (overflow_menu_) |
| 972 overflow_menu_->CancelMenu(); | 1000 overflow_menu_->CancelMenu(); |
| 973 } | 1001 } |
| 974 | 1002 |
| 975 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { | 1003 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { |
| 976 show_menu_task_factory_.InvalidateWeakPtrs(); | 1004 show_menu_task_factory_.InvalidateWeakPtrs(); |
| 977 } | 1005 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1010 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; | 1038 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; |
| 1011 return ToolbarView::kStandardSpacing + icons_size + chevron_size + | 1039 return ToolbarView::kStandardSpacing + icons_size + chevron_size + |
| 1012 ToolbarView::kStandardSpacing; | 1040 ToolbarView::kStandardSpacing; |
| 1013 } | 1041 } |
| 1014 | 1042 |
| 1015 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { | 1043 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { |
| 1016 // Check for widths large enough to show the entire icon set. | 1044 // Check for widths large enough to show the entire icon set. |
| 1017 if (pixels >= IconCountToWidth(-1, false)) | 1045 if (pixels >= IconCountToWidth(-1, false)) |
| 1018 return browser_action_views_.size(); | 1046 return browser_action_views_.size(); |
| 1019 | 1047 |
| 1020 // We need to reserve space for the resize area, chevron, and the spacing on | 1048 // We reserve space for the padding on either side of the toolbar... |
| 1021 // either side of the chevron. | 1049 int available_space = pixels - (ToolbarView::kStandardSpacing * 2); |
| 1022 int available_space = pixels - ToolbarView::kStandardSpacing - | 1050 // ... and, if the chevron is enabled, the chevron. |
| 1023 (chevron_ ? chevron_->GetPreferredSize().width() : 0) - | 1051 if (chevron_) |
| 1024 kChevronSpacing - ToolbarView::kStandardSpacing; | 1052 available_space -= (chevron_->GetPreferredSize().width() + kChevronSpacing); |
| 1053 | |
| 1025 // Now we add an extra between-item padding value so the space can be divided | 1054 // Now we add an extra between-item padding value so the space can be divided |
| 1026 // evenly by (size of icon with padding). | 1055 // evenly by (size of icon with padding). |
| 1027 return static_cast<size_t>( | 1056 return static_cast<size_t>( |
| 1028 std::max(0, available_space + kItemSpacing) / IconWidth(true)); | 1057 std::max(0, available_space + kItemSpacing) / IconWidth(true)); |
| 1029 } | 1058 } |
| 1030 | 1059 |
| 1031 int BrowserActionsContainer::MinimumNonemptyWidth() const { | 1060 int BrowserActionsContainer::MinimumNonemptyWidth() const { |
| 1032 if (!chevron_) | 1061 if (!chevron_) |
| 1033 return ToolbarView::kStandardSpacing; | 1062 return ToolbarView::kStandardSpacing; |
| 1034 return (ToolbarView::kStandardSpacing * 2) + kChevronSpacing + | 1063 return (ToolbarView::kStandardSpacing * 2) + kChevronSpacing + |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1055 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1084 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
| 1056 const Extension* extension) const { | 1085 const Extension* extension) const { |
| 1057 // Only display incognito-enabled extensions while in incognito mode. | 1086 // Only display incognito-enabled extensions while in incognito mode. |
| 1058 return !profile_->IsOffTheRecord() || | 1087 return !profile_->IsOffTheRecord() || |
| 1059 extensions::util::IsIncognitoEnabled(extension->id(), profile_); | 1088 extensions::util::IsIncognitoEnabled(extension->id(), profile_); |
| 1060 } | 1089 } |
| 1061 | 1090 |
| 1062 size_t BrowserActionsContainer::GetIconCount() const { | 1091 size_t BrowserActionsContainer::GetIconCount() const { |
| 1063 if (!model_) | 1092 if (!model_) |
| 1064 return 0u; | 1093 return 0u; |
| 1065 // Find the number of icons which could be displayed. | 1094 |
| 1066 size_t displayable_icon_count = 0u; | |
| 1067 const extensions::ExtensionList& extensions = model_->toolbar_items(); | 1095 const extensions::ExtensionList& extensions = model_->toolbar_items(); |
| 1068 for (extensions::ExtensionList::const_iterator iter = extensions.begin(); | 1096 |
| 1069 iter != extensions.end(); ++iter) { | |
| 1070 displayable_icon_count += ShouldDisplayBrowserAction(iter->get()) ? 1u : 0u; | |
| 1071 } | |
| 1072 // Find the absolute value for the model's visible count. | 1097 // Find the absolute value for the model's visible count. |
| 1073 int model_size = model_->GetVisibleIconCount(); | 1098 int model_size = model_->GetVisibleIconCount(); |
|
Finnur
2014/09/12 10:30:24
Maybe it is just too early in the morning for me,
Devlin
2014/09/12 14:01:30
Well, it's actually how many are visible, accordin
Finnur
2014/09/12 15:29:52
LGTM, with name change.
Devlin
2014/09/12 15:54:53
Done.
| |
| 1074 size_t absolute_model_size = | 1099 size_t absolute_model_size = |
| 1075 model_size == -1 ? extensions.size() : model_size; | 1100 model_size == -1 ? extensions.size() : model_size; |
| 1076 | 1101 |
| 1077 // The main container will try to show |model_size| icons, but reduce if there | 1102 // Find the number of icons which could be displayed. |
| 1078 // aren't enough displayable icons to do so. | 1103 size_t displayable_icon_count = 0u; |
| 1079 size_t main_displayed = std::min(displayable_icon_count, absolute_model_size); | 1104 size_t main_displayed = 0u; |
| 1080 // The overflow will display the extras, if any. | 1105 for (size_t i = 0; i < extensions.size(); ++i) { |
| 1106 // Should there be an icon for this extension at all? | |
| 1107 if (ShouldDisplayBrowserAction(extensions[i].get())) { | |
| 1108 ++displayable_icon_count; | |
| 1109 // Should we display it on the main bar? If this is an incognito window, | |
| 1110 // icons have the same overflow status they do in a regular window. | |
| 1111 main_displayed += i < absolute_model_size ? 1u : 0u; | |
| 1112 } | |
| 1113 } | |
| 1114 | |
| 1115 // If this is an existing (initialized) container from an incognito profile, | |
| 1116 // we can't trust the model (because the incognito bars don't adjust model | |
| 1117 // settings). Instead, we go off what we currently have displayed. | |
| 1118 if (initialized_ && profile_->IsOffTheRecord()) { | |
|
Finnur
2014/09/12 10:30:24
Out of curiosity, under what circumstances is |ini
Devlin
2014/09/12 14:01:30
Initialized is false when we call this method from
| |
| 1119 main_displayed = in_overflow_mode() ? | |
| 1120 main_container_->VisibleBrowserActionsAfterAnimation() : | |
| 1121 VisibleBrowserActionsAfterAnimation(); | |
| 1122 } | |
| 1123 | |
| 1124 // The overflow displays any (displayable) icons not shown by the main bar. | |
| 1081 return in_overflow_mode() ? | 1125 return in_overflow_mode() ? |
| 1082 displayable_icon_count - main_displayed : main_displayed; | 1126 displayable_icon_count - main_displayed : main_displayed; |
| 1083 } | 1127 } |
| OLD | NEW |