| 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/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 15 #include "chrome/browser/ui/view_ids.h" | 16 #include "chrome/browser/ui/view_ids.h" |
| 16 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 17 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 18 #include "chrome/browser/ui/views/extensions/extension_action_view_controller.h" |
| 17 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 19 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 18 #include "chrome/browser/ui/views/frame/browser_view.h" | 20 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 19 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" | 21 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" |
| 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 21 #include "chrome/common/extensions/command.h" | 23 #include "chrome/common/extensions/command.h" |
| 22 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 23 #include "extensions/browser/extension_system.h" | 25 #include "extensions/browser/extension_system.h" |
| 24 #include "extensions/browser/runtime_data.h" | 26 #include "extensions/browser/runtime_data.h" |
| 25 #include "extensions/common/feature_switch.h" | 27 #include "extensions/common/feature_switch.h" |
| 26 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 #include "ui/views/painter.h" | 41 #include "ui/views/painter.h" |
| 40 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
| 41 | 43 |
| 42 using extensions::Extension; | 44 using extensions::Extension; |
| 43 | 45 |
| 44 namespace { | 46 namespace { |
| 45 | 47 |
| 46 // Horizontal spacing before the chevron (if visible). | 48 // Horizontal spacing before the chevron (if visible). |
| 47 const int kChevronSpacing = ToolbarView::kStandardSpacing - 2; | 49 const int kChevronSpacing = ToolbarView::kStandardSpacing - 2; |
| 48 | 50 |
| 51 // Returns the set of controllers for all actions. |
| 52 // TODO(devlin): We should move this to the model, once it supports component |
| 53 // actions. |
| 54 ScopedVector<ToolbarActionViewController> GetToolbarActions( |
| 55 extensions::ExtensionToolbarModel* model, |
| 56 Browser* browser) { |
| 57 ScopedVector<ToolbarActionViewController> actions; |
| 58 |
| 59 // Extension actions come first. |
| 60 extensions::ExtensionActionManager* action_manager = |
| 61 extensions::ExtensionActionManager::Get(browser->profile()); |
| 62 const extensions::ExtensionList& toolbar_items = model->toolbar_items(); |
| 63 for (const scoped_refptr<const Extension>& extension : toolbar_items) { |
| 64 actions.push_back(new ExtensionActionViewController( |
| 65 extension.get(), |
| 66 browser, |
| 67 action_manager->GetExtensionAction(*extension))); |
| 68 } |
| 69 |
| 70 // Component actions come second. |
| 71 ScopedVector<ToolbarActionViewController> component_actions = |
| 72 ComponentToolbarActionsFactory::GetInstance()-> |
| 73 GetComponentToolbarActions(); |
| 74 DCHECK(extensions::FeatureSwitch::extension_action_redesign()->IsEnabled() || |
| 75 component_actions.empty()); |
| 76 actions.insert( |
| 77 actions.end(), component_actions.begin(), component_actions.end()); |
| 78 component_actions.weak_clear(); |
| 79 return actions.Pass(); |
| 80 } |
| 81 |
| 49 } // namespace | 82 } // namespace |
| 50 | 83 |
| 51 //////////////////////////////////////////////////////////////////////////////// | 84 //////////////////////////////////////////////////////////////////////////////// |
| 52 // BrowserActionsContainer::DropPosition | 85 // BrowserActionsContainer::DropPosition |
| 53 | 86 |
| 54 struct BrowserActionsContainer::DropPosition { | 87 struct BrowserActionsContainer::DropPosition { |
| 55 DropPosition(size_t row, size_t icon_in_row); | 88 DropPosition(size_t row, size_t icon_in_row); |
| 56 | 89 |
| 57 // The (0-indexed) row into which the action will be dropped. | 90 // The (0-indexed) row into which the action will be dropped. |
| 58 size_t row; | 91 size_t row; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // We wait to set the container width until now so that the chevron images | 172 // We wait to set the container width until now so that the chevron images |
| 140 // will be loaded. The width calculation needs to know the chevron size. | 173 // will be loaded. The width calculation needs to know the chevron size. |
| 141 if (model_ && model_->extensions_initialized()) { | 174 if (model_ && model_->extensions_initialized()) { |
| 142 container_width_ = GetPreferredWidth(); | 175 container_width_ = GetPreferredWidth(); |
| 143 SetChevronVisibility(); | 176 SetChevronVisibility(); |
| 144 } | 177 } |
| 145 | 178 |
| 146 initialized_ = true; | 179 initialized_ = true; |
| 147 } | 180 } |
| 148 | 181 |
| 182 const std::string& BrowserActionsContainer::GetIdAt(size_t index) { |
| 183 return browser_action_views_[index]->view_controller()->GetId(); |
| 184 } |
| 185 |
| 149 BrowserActionView* BrowserActionsContainer::GetViewForExtension( | 186 BrowserActionView* BrowserActionsContainer::GetViewForExtension( |
| 150 const Extension* extension) { | 187 const Extension* extension) { |
| 151 for (BrowserActionView* view : browser_action_views_) { | 188 for (BrowserActionView* view : browser_action_views_) { |
| 152 if (view->extension() == extension) | 189 if (view->view_controller()->GetId() == extension->id()) |
| 153 return view; | 190 return view; |
| 154 } | 191 } |
| 155 return NULL; | 192 return NULL; |
| 156 } | 193 } |
| 157 | 194 |
| 158 void BrowserActionsContainer::RefreshBrowserActionViews() { | 195 void BrowserActionsContainer::RefreshBrowserActionViews() { |
| 159 for (BrowserActionView* view : browser_action_views_) | 196 for (BrowserActionView* view : browser_action_views_) |
| 160 view->UpdateState(); | 197 view->UpdateState(); |
| 161 } | 198 } |
| 162 | 199 |
| 163 void BrowserActionsContainer::CreateBrowserActionViews() { | 200 void BrowserActionsContainer::CreateBrowserActionViews() { |
| 164 DCHECK(browser_action_views_.empty()); | 201 DCHECK(browser_action_views_.empty()); |
| 165 if (!model_) | 202 if (!model_) |
| 166 return; | 203 return; |
| 167 | 204 |
| 168 extensions::ExtensionActionManager* action_manager = | 205 ScopedVector<ToolbarActionViewController> actions = |
| 169 extensions::ExtensionActionManager::Get(profile_); | 206 GetToolbarActions(model_, browser_); |
| 170 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); | 207 for (ToolbarActionViewController* controller : actions) { |
| 171 for (const scoped_refptr<const Extension>& extension : toolbar_items) { | |
| 172 BrowserActionView* view = | 208 BrowserActionView* view = |
| 173 new BrowserActionView(extension.get(), | 209 new BrowserActionView(make_scoped_ptr(controller), browser_, this); |
| 174 action_manager->GetExtensionAction(*extension), | |
| 175 browser_, | |
| 176 this); | |
| 177 browser_action_views_.push_back(view); | 210 browser_action_views_.push_back(view); |
| 178 AddChildView(view); | 211 AddChildView(view); |
| 179 } | 212 } |
| 213 actions.weak_clear(); |
| 180 } | 214 } |
| 181 | 215 |
| 182 void BrowserActionsContainer::DeleteBrowserActionViews() { | 216 void BrowserActionsContainer::DeleteBrowserActionViews() { |
| 183 HideActivePopup(); | 217 HideActivePopup(); |
| 184 STLDeleteElements(&browser_action_views_); | 218 STLDeleteElements(&browser_action_views_); |
| 185 } | 219 } |
| 186 | 220 |
| 187 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 221 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
| 188 size_t visible_actions = 0; | 222 size_t visible_actions = 0; |
| 189 for (const BrowserActionView* view : browser_action_views_) { | 223 for (const BrowserActionView* view : browser_action_views_) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 DCHECK((!popup_owner_ && popup_owner) || | 281 DCHECK((!popup_owner_ && popup_owner) || |
| 248 (popup_owner_ && !popup_owner)); | 282 (popup_owner_ && !popup_owner)); |
| 249 popup_owner_ = popup_owner; | 283 popup_owner_ = popup_owner; |
| 250 } | 284 } |
| 251 | 285 |
| 252 void BrowserActionsContainer::HideActivePopup() { | 286 void BrowserActionsContainer::HideActivePopup() { |
| 253 if (popup_owner_) | 287 if (popup_owner_) |
| 254 popup_owner_->view_controller()->HidePopup(); | 288 popup_owner_->view_controller()->HidePopup(); |
| 255 } | 289 } |
| 256 | 290 |
| 257 BrowserActionView* BrowserActionsContainer::GetMainViewForExtension( | 291 BrowserActionView* BrowserActionsContainer::GetMainViewForAction( |
| 258 const Extension* extension) { | 292 BrowserActionView* view) { |
| 259 return in_overflow_mode() ? | 293 if (!in_overflow_mode()) |
| 260 main_container_->GetViewForExtension(extension) : | 294 return view; // This is the main view. |
| 261 GetViewForExtension(extension); | 295 |
| 296 // The overflow container and main container each have the same views and |
| 297 // view indices, so we can return the view of the index that |view| has in |
| 298 // this container. |
| 299 BrowserActionViews::const_iterator iter = |
| 300 std::find(browser_action_views_.begin(), |
| 301 browser_action_views_.end(), |
| 302 view); |
| 303 DCHECK(iter != browser_action_views_.end()); |
| 304 size_t index = iter - browser_action_views_.begin(); |
| 305 return main_container_->browser_action_views_[index]; |
| 262 } | 306 } |
| 263 | 307 |
| 264 void BrowserActionsContainer::AddObserver( | 308 void BrowserActionsContainer::AddObserver( |
| 265 BrowserActionsContainerObserver* observer) { | 309 BrowserActionsContainerObserver* observer) { |
| 266 observers_.AddObserver(observer); | 310 observers_.AddObserver(observer); |
| 267 } | 311 } |
| 268 | 312 |
| 269 void BrowserActionsContainer::RemoveObserver( | 313 void BrowserActionsContainer::RemoveObserver( |
| 270 BrowserActionsContainerObserver* observer) { | 314 BrowserActionsContainerObserver* observer) { |
| 271 observers_.RemoveObserver(observer); | 315 observers_.RemoveObserver(observer); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 SchedulePaint(); | 516 SchedulePaint(); |
| 473 } | 517 } |
| 474 | 518 |
| 475 int BrowserActionsContainer::OnPerformDrop( | 519 int BrowserActionsContainer::OnPerformDrop( |
| 476 const ui::DropTargetEvent& event) { | 520 const ui::DropTargetEvent& event) { |
| 477 BrowserActionDragData data; | 521 BrowserActionDragData data; |
| 478 if (!data.Read(event.data())) | 522 if (!data.Read(event.data())) |
| 479 return ui::DragDropTypes::DRAG_NONE; | 523 return ui::DragDropTypes::DRAG_NONE; |
| 480 | 524 |
| 481 // Make sure we have the same view as we started with. | 525 // Make sure we have the same view as we started with. |
| 482 DCHECK_EQ(browser_action_views_[data.index()]->extension()->id(), | 526 DCHECK_EQ(GetIdAt(data.index()), data.id()); |
| 483 data.id()); | |
| 484 DCHECK(model_); | 527 DCHECK(model_); |
| 485 | 528 |
| 486 size_t i = drop_position_->row * icons_per_overflow_menu_row_ + | 529 size_t i = drop_position_->row * icons_per_overflow_menu_row_ + |
| 487 drop_position_->icon_in_row; | 530 drop_position_->icon_in_row; |
| 488 if (in_overflow_mode()) | 531 if (in_overflow_mode()) |
| 489 i += main_container_->VisibleBrowserActionsAfterAnimation(); | 532 i += main_container_->VisibleBrowserActionsAfterAnimation(); |
| 490 // |i| now points to the item to the right of the drop indicator*, which is | 533 // |i| now points to the item to the right of the drop indicator*, which is |
| 491 // correct when dragging an icon to the left. When dragging to the right, | 534 // correct when dragging an icon to the left. When dragging to the right, |
| 492 // however, we want the icon being dragged to get the index of the item to | 535 // however, we want the icon being dragged to get the index of the item to |
| 493 // the left of the drop indicator, so we subtract one. | 536 // the left of the drop indicator, so we subtract one. |
| 494 // * Well, it can also point to the end, but not when dragging to the left. :) | 537 // * Well, it can also point to the end, but not when dragging to the left. :) |
| 495 if (i > data.index()) | 538 if (i > data.index()) |
| 496 --i; | 539 --i; |
| 497 | 540 |
| 498 // If this was a drag between containers, we will have to adjust the number of | 541 // If this was a drag between containers, we will have to adjust the number of |
| 499 // visible icons. | 542 // visible icons. |
| 500 bool drag_between_containers = | 543 bool drag_between_containers = |
| 501 !browser_action_views_[data.index()]->visible(); | 544 !browser_action_views_[data.index()]->visible(); |
| 502 model_->MoveExtensionIcon( | 545 model_->MoveExtensionIcon(GetIdAt(data.index()), i); |
| 503 browser_action_views_[data.index()]->extension(), i); | |
| 504 | 546 |
| 505 if (drag_between_containers) { | 547 if (drag_between_containers) { |
| 506 // Let the main container update the model. | 548 // Let the main container update the model. |
| 507 if (in_overflow_mode()) | 549 if (in_overflow_mode()) |
| 508 main_container_->NotifyActionMovedToOverflow(); | 550 main_container_->NotifyActionMovedToOverflow(); |
| 509 else // This is the main container. | 551 else // This is the main container. |
| 510 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); | 552 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); |
| 511 } | 553 } |
| 512 | 554 |
| 513 OnDragExited(); // Perform clean up after dragging. | 555 OnDragExited(); // Perform clean up after dragging. |
| 514 return ui::DragDropTypes::DRAG_MOVE; | 556 return ui::DragDropTypes::DRAG_MOVE; |
| 515 } | 557 } |
| 516 | 558 |
| 517 void BrowserActionsContainer::GetAccessibleState( | 559 void BrowserActionsContainer::GetAccessibleState( |
| 518 ui::AXViewState* state) { | 560 ui::AXViewState* state) { |
| 519 state->role = ui::AX_ROLE_GROUP; | 561 state->role = ui::AX_ROLE_GROUP; |
| 520 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); | 562 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); |
| 521 } | 563 } |
| 522 | 564 |
| 523 void BrowserActionsContainer::WriteDragDataForView(View* sender, | 565 void BrowserActionsContainer::WriteDragDataForView(View* sender, |
| 524 const gfx::Point& press_pt, | 566 const gfx::Point& press_pt, |
| 525 OSExchangeData* data) { | 567 OSExchangeData* data) { |
| 526 DCHECK(data); | 568 DCHECK(data); |
| 527 | 569 |
| 528 BrowserActionViews::iterator iter = std::find(browser_action_views_.begin(), | 570 BrowserActionViews::iterator iter = std::find(browser_action_views_.begin(), |
| 529 browser_action_views_.end(), | 571 browser_action_views_.end(), |
| 530 sender); | 572 sender); |
| 531 DCHECK(iter != browser_action_views_.end()); | 573 DCHECK(iter != browser_action_views_.end()); |
| 532 drag_utils::SetDragImageOnDataObject((*iter)->GetIconWithBadge(), | 574 ToolbarActionViewController* view_controller = (*iter)->view_controller(); |
| 533 press_pt.OffsetFromOrigin(), | 575 drag_utils::SetDragImageOnDataObject( |
| 534 data); | 576 view_controller->GetIconWithBadge(), |
| 577 press_pt.OffsetFromOrigin(), |
| 578 data); |
| 535 // Fill in the remaining info. | 579 // Fill in the remaining info. |
| 536 BrowserActionDragData drag_data((*iter)->extension()->id(), | 580 BrowserActionDragData drag_data(view_controller->GetId(), |
| 537 iter - browser_action_views_.begin()); | 581 iter - browser_action_views_.begin()); |
| 538 drag_data.Write(profile_, data); | 582 drag_data.Write(profile_, data); |
| 539 } | 583 } |
| 540 | 584 |
| 541 int BrowserActionsContainer::GetDragOperationsForView(View* sender, | 585 int BrowserActionsContainer::GetDragOperationsForView(View* sender, |
| 542 const gfx::Point& p) { | 586 const gfx::Point& p) { |
| 543 return ui::DragDropTypes::DRAG_MOVE; | 587 return ui::DragDropTypes::DRAG_MOVE; |
| 544 } | 588 } |
| 545 | 589 |
| 546 bool BrowserActionsContainer::CanStartDragForView(View* sender, | 590 bool BrowserActionsContainer::CanStartDragForView(View* sender, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 642 |
| 599 extensions::ActiveTabPermissionGranter* | 643 extensions::ActiveTabPermissionGranter* |
| 600 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 644 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 601 content::WebContents* web_contents = GetCurrentWebContents(); | 645 content::WebContents* web_contents = GetCurrentWebContents(); |
| 602 if (!web_contents) | 646 if (!web_contents) |
| 603 return NULL; | 647 return NULL; |
| 604 return extensions::TabHelper::FromWebContents(web_contents)-> | 648 return extensions::TabHelper::FromWebContents(web_contents)-> |
| 605 active_tab_permission_granter(); | 649 active_tab_permission_granter(); |
| 606 } | 650 } |
| 607 | 651 |
| 608 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { | 652 gfx::NativeView BrowserActionsContainer::TestGetPopup() { |
| 609 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; | 653 return popup_owner_ ? |
| 654 popup_owner_->view_controller()->GetPopupNativeView() : |
| 655 NULL; |
| 610 } | 656 } |
| 611 | 657 |
| 612 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 658 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
| 613 // If the views haven't been initialized yet, wait for the next call to | 659 // If the views haven't been initialized yet, wait for the next call to |
| 614 // paint (one will be triggered by entering highlight mode). | 660 // paint (one will be triggered by entering highlight mode). |
| 615 if (model_->is_highlighting() && !browser_action_views_.empty() && | 661 if (model_->is_highlighting() && !browser_action_views_.empty() && |
| 616 !in_overflow_mode()) { | 662 !in_overflow_mode()) { |
| 617 views::Painter::PaintPainterAt( | 663 views::Painter::PaintPainterAt( |
| 618 canvas, highlight_painter_.get(), GetLocalBounds()); | 664 canvas, highlight_painter_.get(), GetLocalBounds()); |
| 619 } | 665 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 759 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 714 DCHECK(browser_action_views_[i]->extension() != extension) << | 760 DCHECK(browser_action_views_[i]->extension() != extension) << |
| 715 "Asked to add a browser action view for an extension that already " | 761 "Asked to add a browser action view for an extension that already " |
| 716 "exists."; | 762 "exists."; |
| 717 } | 763 } |
| 718 #endif | 764 #endif |
| 719 if (chevron_) | 765 if (chevron_) |
| 720 chevron_->CloseMenu(); | 766 chevron_->CloseMenu(); |
| 721 | 767 |
| 722 // Add the new browser action to the vector and the view hierarchy. | 768 // Add the new browser action to the vector and the view hierarchy. |
| 723 BrowserActionView* view = | 769 BrowserActionView* view = new BrowserActionView( |
| 724 new BrowserActionView(extension, | 770 make_scoped_ptr(new ExtensionActionViewController( |
| 725 extensions::ExtensionActionManager::Get(profile_)-> | 771 extension, |
| 726 GetExtensionAction(*extension), | 772 browser_, |
| 727 browser_, | 773 extensions::ExtensionActionManager::Get(profile_)-> |
| 728 this); | 774 GetExtensionAction(*extension))), |
| 775 browser_, |
| 776 this); |
| 729 browser_action_views_.insert(browser_action_views_.begin() + index, view); | 777 browser_action_views_.insert(browser_action_views_.begin() + index, view); |
| 730 AddChildViewAt(view, index); | 778 AddChildViewAt(view, index); |
| 731 | 779 |
| 732 // If we are still initializing the container, don't bother animating. | 780 // If we are still initializing the container, don't bother animating. |
| 733 if (!model_->extensions_initialized()) | 781 if (!model_->extensions_initialized()) |
| 734 return; | 782 return; |
| 735 | 783 |
| 736 // If this is just an upgrade, then don't worry about resizing. | 784 // If this is just an upgrade, then don't worry about resizing. |
| 737 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 785 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
| 738 IsBeingUpgraded(extension)) { | 786 IsBeingUpgraded(extension)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 758 } | 806 } |
| 759 | 807 |
| 760 void BrowserActionsContainer::ToolbarExtensionRemoved( | 808 void BrowserActionsContainer::ToolbarExtensionRemoved( |
| 761 const Extension* extension) { | 809 const Extension* extension) { |
| 762 if (chevron_) | 810 if (chevron_) |
| 763 chevron_->CloseMenu(); | 811 chevron_->CloseMenu(); |
| 764 | 812 |
| 765 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); | 813 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); |
| 766 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 814 for (BrowserActionViews::iterator i(browser_action_views_.begin()); |
| 767 i != browser_action_views_.end(); ++i) { | 815 i != browser_action_views_.end(); ++i) { |
| 768 if ((*i)->extension() == extension) { | 816 if ((*i)->view_controller()->GetId() == extension->id()) { |
| 769 delete *i; | 817 delete *i; |
| 770 browser_action_views_.erase(i); | 818 browser_action_views_.erase(i); |
| 771 | 819 |
| 772 // If the extension is being upgraded we don't want the bar to shrink | 820 // If the extension is being upgraded we don't want the bar to shrink |
| 773 // because the icon is just going to get re-added to the same location. | 821 // because the icon is just going to get re-added to the same location. |
| 774 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 822 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
| 775 IsBeingUpgraded(extension)) | 823 IsBeingUpgraded(extension)) |
| 776 return; | 824 return; |
| 777 | 825 |
| 778 if (browser_action_views_.size() > visible_actions) { | 826 if (browser_action_views_.size() > visible_actions) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 792 } | 840 } |
| 793 } | 841 } |
| 794 } | 842 } |
| 795 | 843 |
| 796 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, | 844 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, |
| 797 int index) { | 845 int index) { |
| 798 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); | 846 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); |
| 799 | 847 |
| 800 BrowserActionViews::iterator iter = browser_action_views_.begin(); | 848 BrowserActionViews::iterator iter = browser_action_views_.begin(); |
| 801 while (iter != browser_action_views_.end() && | 849 while (iter != browser_action_views_.end() && |
| 802 (*iter)->extension() != extension) { | 850 (*iter)->view_controller()->GetId() != extension->id()) |
| 803 ++iter; | 851 ++iter; |
| 804 } | |
| 805 | 852 |
| 806 DCHECK(iter != browser_action_views_.end()); | 853 DCHECK(iter != browser_action_views_.end()); |
| 807 if (iter - browser_action_views_.begin() == index) | 854 if (iter - browser_action_views_.begin() == index) |
| 808 return; // Already in place. | 855 return; // Already in place. |
| 809 | 856 |
| 810 BrowserActionView* moved_view = *iter; | 857 BrowserActionView* moved_view = *iter; |
| 811 browser_action_views_.erase(iter); | 858 browser_action_views_.erase(iter); |
| 812 browser_action_views_.insert( | 859 browser_action_views_.insert( |
| 813 browser_action_views_.begin() + index, moved_view); | 860 browser_action_views_.begin() + index, moved_view); |
| 814 | 861 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 826 } | 873 } |
| 827 | 874 |
| 828 bool BrowserActionsContainer::ShowExtensionActionPopup( | 875 bool BrowserActionsContainer::ShowExtensionActionPopup( |
| 829 const Extension* extension, | 876 const Extension* extension, |
| 830 bool grant_active_tab) { | 877 bool grant_active_tab) { |
| 831 // Don't override another popup, and only show in the active window. | 878 // Don't override another popup, and only show in the active window. |
| 832 if (popup_owner_ || !browser_->window()->IsActive()) | 879 if (popup_owner_ || !browser_->window()->IsActive()) |
| 833 return false; | 880 return false; |
| 834 | 881 |
| 835 BrowserActionView* view = GetViewForExtension(extension); | 882 BrowserActionView* view = GetViewForExtension(extension); |
| 836 return view && view->view_controller()->ExecuteAction(ExtensionPopup::SHOW, | 883 return view && view->view_controller()->ExecuteAction(grant_active_tab); |
| 837 grant_active_tab); | |
| 838 } | 884 } |
| 839 | 885 |
| 840 void BrowserActionsContainer::ToolbarVisibleCountChanged() { | 886 void BrowserActionsContainer::ToolbarVisibleCountChanged() { |
| 841 if (GetPreferredWidth() != container_width_) | 887 if (GetPreferredWidth() != container_width_) |
| 842 Animate(gfx::Tween::EASE_OUT, GetIconCount()); | 888 Animate(gfx::Tween::EASE_OUT, GetIconCount()); |
| 843 } | 889 } |
| 844 | 890 |
| 845 void BrowserActionsContainer::ToolbarHighlightModeChanged( | 891 void BrowserActionsContainer::ToolbarHighlightModeChanged( |
| 846 bool is_highlighting) { | 892 bool is_highlighting) { |
| 847 // The visual highlighting is done in OnPaint(). It's a bit of a pain that | 893 // The visual highlighting is done in OnPaint(). It's a bit of a pain that |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 | 999 |
| 954 size_t BrowserActionsContainer::GetIconCount() const { | 1000 size_t BrowserActionsContainer::GetIconCount() const { |
| 955 if (!model_) | 1001 if (!model_) |
| 956 return 0u; | 1002 return 0u; |
| 957 | 1003 |
| 958 // Find the absolute value for the model's visible count. | 1004 // Find the absolute value for the model's visible count. |
| 959 int model_visible_size = model_->GetVisibleIconCount(); | 1005 int model_visible_size = model_->GetVisibleIconCount(); |
| 960 size_t absolute_model_visible_size = model_visible_size == -1 ? | 1006 size_t absolute_model_visible_size = model_visible_size == -1 ? |
| 961 model_->toolbar_items().size() : model_visible_size; | 1007 model_->toolbar_items().size() : model_visible_size; |
| 962 | 1008 |
| 1009 #if defined(DEBUG) |
| 963 // Good time for some sanity checks: We should never try to display more | 1010 // Good time for some sanity checks: We should never try to display more |
| 964 // icons than we have, and we should always have a view per item in the model. | 1011 // icons than we have, and we should always have a view per item in the model. |
| 965 // (The only exception is if this is in initialization.) | 1012 // (The only exception is if this is in initialization.) |
| 966 if (initialized_) { | 1013 if (initialized_) { |
| 1014 size_t num_extension_actions = 0u; |
| 1015 for (const BrowserActionView* view : browser_action_views_) { |
| 1016 num_extension_actions += |
| 1017 view->view_controller()->GetType() == |
| 1018 ToolbarActionViewController::TYPE_EXTENSION_ACTION ? 1 : 0; |
| 1019 } |
| 967 DCHECK_LE(absolute_model_visible_size, browser_action_views_.size()); | 1020 DCHECK_LE(absolute_model_visible_size, browser_action_views_.size()); |
| 968 DCHECK_EQ(model_->toolbar_items().size(), browser_action_views_.size()); | 1021 DCHECK_EQ(model_->toolbar_items().size(), browser_action_views_.size()); |
| 969 } | 1022 } |
| 1023 #endif |
| 970 | 1024 |
| 971 // The overflow displays any icons not shown by the main bar. | 1025 // The overflow displays any icons not shown by the main bar. |
| 972 return in_overflow_mode() ? | 1026 return in_overflow_mode() ? |
| 973 model_->toolbar_items().size() - absolute_model_visible_size : | 1027 model_->toolbar_items().size() - absolute_model_visible_size : |
| 974 absolute_model_visible_size; | 1028 absolute_model_visible_size; |
| 975 } | 1029 } |
| OLD | NEW |