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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
149 BrowserActionView* BrowserActionsContainer::GetViewForExtension( | 182 BrowserActionView* BrowserActionsContainer::GetViewForExtension( |
150 const Extension* extension) { | 183 const Extension* extension) { |
151 for (BrowserActionView* view : browser_action_views_) { | 184 for (BrowserActionView* view : browser_action_views_) { |
152 if (view->extension() == extension) | 185 if (view->view_controller()->GetType() == |
| 186 ToolbarActionViewController::TYPE_EXTENSION_ACTION && |
| 187 view->GetExtensionActionViewController()->extension() == extension) |
153 return view; | 188 return view; |
154 } | 189 } |
155 return NULL; | 190 return NULL; |
156 } | 191 } |
157 | 192 |
| 193 const Extension* BrowserActionsContainer::GetExtensionAt(size_t index) const { |
| 194 DCHECK_EQ(ToolbarActionViewController::TYPE_EXTENSION_ACTION, |
| 195 browser_action_views_[index]->view_controller()->GetType()); |
| 196 return browser_action_views_[index]->GetExtensionActionViewController()-> |
| 197 extension(); |
| 198 } |
| 199 |
158 void BrowserActionsContainer::RefreshBrowserActionViews() { | 200 void BrowserActionsContainer::RefreshBrowserActionViews() { |
159 for (BrowserActionView* view : browser_action_views_) | 201 for (BrowserActionView* view : browser_action_views_) |
160 view->UpdateState(); | 202 view->UpdateState(); |
161 } | 203 } |
162 | 204 |
163 void BrowserActionsContainer::CreateBrowserActionViews() { | 205 void BrowserActionsContainer::CreateBrowserActionViews() { |
164 DCHECK(browser_action_views_.empty()); | 206 DCHECK(browser_action_views_.empty()); |
165 if (!model_) | 207 if (!model_) |
166 return; | 208 return; |
167 | 209 |
168 extensions::ExtensionActionManager* action_manager = | 210 ScopedVector<ToolbarActionViewController> actions = |
169 extensions::ExtensionActionManager::Get(profile_); | 211 GetToolbarActions(model_, browser_); |
170 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); | 212 for (ToolbarActionViewController* controller : actions) { |
171 for (const scoped_refptr<const Extension>& extension : toolbar_items) { | |
172 BrowserActionView* view = | 213 BrowserActionView* view = |
173 new BrowserActionView(extension.get(), | 214 new BrowserActionView(make_scoped_ptr(controller), browser_, this); |
174 action_manager->GetExtensionAction(*extension), | |
175 browser_, | |
176 this); | |
177 browser_action_views_.push_back(view); | 215 browser_action_views_.push_back(view); |
178 AddChildView(view); | 216 AddChildView(view); |
179 } | 217 } |
| 218 actions.weak_clear(); |
180 } | 219 } |
181 | 220 |
182 void BrowserActionsContainer::DeleteBrowserActionViews() { | 221 void BrowserActionsContainer::DeleteBrowserActionViews() { |
183 HideActivePopup(); | 222 HideActivePopup(); |
184 STLDeleteElements(&browser_action_views_); | 223 STLDeleteElements(&browser_action_views_); |
185 } | 224 } |
186 | 225 |
187 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 226 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
188 size_t visible_actions = 0; | 227 size_t visible_actions = 0; |
189 for (const BrowserActionView* view : browser_action_views_) { | 228 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) || | 286 DCHECK((!popup_owner_ && popup_owner) || |
248 (popup_owner_ && !popup_owner)); | 287 (popup_owner_ && !popup_owner)); |
249 popup_owner_ = popup_owner; | 288 popup_owner_ = popup_owner; |
250 } | 289 } |
251 | 290 |
252 void BrowserActionsContainer::HideActivePopup() { | 291 void BrowserActionsContainer::HideActivePopup() { |
253 if (popup_owner_) | 292 if (popup_owner_) |
254 popup_owner_->view_controller()->HidePopup(); | 293 popup_owner_->view_controller()->HidePopup(); |
255 } | 294 } |
256 | 295 |
257 BrowserActionView* BrowserActionsContainer::GetMainViewForExtension( | 296 BrowserActionView* BrowserActionsContainer::GetMainViewForAction( |
258 const Extension* extension) { | 297 BrowserActionView* view) { |
259 return in_overflow_mode() ? | 298 if (!in_overflow_mode()) |
260 main_container_->GetViewForExtension(extension) : | 299 return view; // This is the main view. |
261 GetViewForExtension(extension); | 300 |
| 301 // The overflow container and main container each have the same views and |
| 302 // view indices, so we can return the view of the index that |view| has in |
| 303 // this container. |
| 304 BrowserActionViews::const_iterator iter = |
| 305 std::find(browser_action_views_.begin(), |
| 306 browser_action_views_.end(), |
| 307 view); |
| 308 DCHECK(iter != browser_action_views_.end()); |
| 309 size_t index = iter - browser_action_views_.begin(); |
| 310 return main_container_->browser_action_views_[index]; |
262 } | 311 } |
263 | 312 |
264 void BrowserActionsContainer::AddObserver( | 313 void BrowserActionsContainer::AddObserver( |
265 BrowserActionsContainerObserver* observer) { | 314 BrowserActionsContainerObserver* observer) { |
266 observers_.AddObserver(observer); | 315 observers_.AddObserver(observer); |
267 } | 316 } |
268 | 317 |
269 void BrowserActionsContainer::RemoveObserver( | 318 void BrowserActionsContainer::RemoveObserver( |
270 BrowserActionsContainerObserver* observer) { | 319 BrowserActionsContainerObserver* observer) { |
271 observers_.RemoveObserver(observer); | 320 observers_.RemoveObserver(observer); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 SchedulePaint(); | 521 SchedulePaint(); |
473 } | 522 } |
474 | 523 |
475 int BrowserActionsContainer::OnPerformDrop( | 524 int BrowserActionsContainer::OnPerformDrop( |
476 const ui::DropTargetEvent& event) { | 525 const ui::DropTargetEvent& event) { |
477 BrowserActionDragData data; | 526 BrowserActionDragData data; |
478 if (!data.Read(event.data())) | 527 if (!data.Read(event.data())) |
479 return ui::DragDropTypes::DRAG_NONE; | 528 return ui::DragDropTypes::DRAG_NONE; |
480 | 529 |
481 // Make sure we have the same view as we started with. | 530 // Make sure we have the same view as we started with. |
482 DCHECK_EQ(browser_action_views_[data.index()]->extension()->id(), | 531 DCHECK_EQ(GetExtensionAt(data.index())->id(), data.id()); |
483 data.id()); | |
484 DCHECK(model_); | 532 DCHECK(model_); |
485 | 533 |
486 size_t i = drop_position_->row * icons_per_overflow_menu_row_ + | 534 size_t i = drop_position_->row * icons_per_overflow_menu_row_ + |
487 drop_position_->icon_in_row; | 535 drop_position_->icon_in_row; |
488 if (in_overflow_mode()) | 536 if (in_overflow_mode()) |
489 i += main_container_->VisibleBrowserActionsAfterAnimation(); | 537 i += main_container_->VisibleBrowserActionsAfterAnimation(); |
490 // |i| now points to the item to the right of the drop indicator*, which is | 538 // |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, | 539 // 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 | 540 // 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. | 541 // 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. :) | 542 // * Well, it can also point to the end, but not when dragging to the left. :) |
495 if (i > data.index()) | 543 if (i > data.index()) |
496 --i; | 544 --i; |
497 | 545 |
498 // If this was a drag between containers, we will have to adjust the number of | 546 // If this was a drag between containers, we will have to adjust the number of |
499 // visible icons. | 547 // visible icons. |
500 bool drag_between_containers = | 548 bool drag_between_containers = |
501 !browser_action_views_[data.index()]->visible(); | 549 !browser_action_views_[data.index()]->visible(); |
502 model_->MoveExtensionIcon( | 550 model_->MoveExtensionIcon(GetExtensionAt(data.index()), i); |
503 browser_action_views_[data.index()]->extension(), i); | |
504 | 551 |
505 if (drag_between_containers) { | 552 if (drag_between_containers) { |
506 // Let the main container update the model. | 553 // Let the main container update the model. |
507 if (in_overflow_mode()) | 554 if (in_overflow_mode()) |
508 main_container_->NotifyActionMovedToOverflow(); | 555 main_container_->NotifyActionMovedToOverflow(); |
509 else // This is the main container. | 556 else // This is the main container. |
510 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); | 557 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); |
511 } | 558 } |
512 | 559 |
513 OnDragExited(); // Perform clean up after dragging. | 560 OnDragExited(); // Perform clean up after dragging. |
514 return ui::DragDropTypes::DRAG_MOVE; | 561 return ui::DragDropTypes::DRAG_MOVE; |
515 } | 562 } |
516 | 563 |
517 void BrowserActionsContainer::GetAccessibleState( | 564 void BrowserActionsContainer::GetAccessibleState( |
518 ui::AXViewState* state) { | 565 ui::AXViewState* state) { |
519 state->role = ui::AX_ROLE_GROUP; | 566 state->role = ui::AX_ROLE_GROUP; |
520 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); | 567 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); |
521 } | 568 } |
522 | 569 |
523 void BrowserActionsContainer::WriteDragDataForView(View* sender, | 570 void BrowserActionsContainer::WriteDragDataForView(View* sender, |
524 const gfx::Point& press_pt, | 571 const gfx::Point& press_pt, |
525 OSExchangeData* data) { | 572 OSExchangeData* data) { |
526 DCHECK(data); | 573 DCHECK(data); |
527 | 574 |
528 BrowserActionViews::iterator iter = std::find(browser_action_views_.begin(), | 575 BrowserActionViews::iterator iter = std::find(browser_action_views_.begin(), |
529 browser_action_views_.end(), | 576 browser_action_views_.end(), |
530 sender); | 577 sender); |
531 DCHECK(iter != browser_action_views_.end()); | 578 DCHECK(iter != browser_action_views_.end()); |
532 drag_utils::SetDragImageOnDataObject((*iter)->GetIconWithBadge(), | 579 ExtensionActionViewController* view_controller = |
| 580 (*iter)->GetExtensionActionViewController(); |
| 581 drag_utils::SetDragImageOnDataObject(view_controller->GetIconWithBadge(), |
533 press_pt.OffsetFromOrigin(), | 582 press_pt.OffsetFromOrigin(), |
534 data); | 583 data); |
535 // Fill in the remaining info. | 584 // Fill in the remaining info. |
536 BrowserActionDragData drag_data((*iter)->extension()->id(), | 585 BrowserActionDragData drag_data(view_controller->extension()->id(), |
537 iter - browser_action_views_.begin()); | 586 iter - browser_action_views_.begin()); |
538 drag_data.Write(profile_, data); | 587 drag_data.Write(profile_, data); |
539 } | 588 } |
540 | 589 |
541 int BrowserActionsContainer::GetDragOperationsForView(View* sender, | 590 int BrowserActionsContainer::GetDragOperationsForView(View* sender, |
542 const gfx::Point& p) { | 591 const gfx::Point& p) { |
543 return ui::DragDropTypes::DRAG_MOVE; | 592 return ui::DragDropTypes::DRAG_MOVE; |
544 } | 593 } |
545 | 594 |
546 bool BrowserActionsContainer::CanStartDragForView(View* sender, | 595 bool BrowserActionsContainer::CanStartDragForView(View* sender, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 extensions::ActiveTabPermissionGranter* | 648 extensions::ActiveTabPermissionGranter* |
600 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 649 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
601 content::WebContents* web_contents = GetCurrentWebContents(); | 650 content::WebContents* web_contents = GetCurrentWebContents(); |
602 if (!web_contents) | 651 if (!web_contents) |
603 return NULL; | 652 return NULL; |
604 return extensions::TabHelper::FromWebContents(web_contents)-> | 653 return extensions::TabHelper::FromWebContents(web_contents)-> |
605 active_tab_permission_granter(); | 654 active_tab_permission_granter(); |
606 } | 655 } |
607 | 656 |
608 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { | 657 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { |
609 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; | 658 return popup_owner_ ? |
| 659 popup_owner_->GetExtensionActionViewController()->popup() : |
| 660 NULL; |
610 } | 661 } |
611 | 662 |
612 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 663 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
613 // If the views haven't been initialized yet, wait for the next call to | 664 // If the views haven't been initialized yet, wait for the next call to |
614 // paint (one will be triggered by entering highlight mode). | 665 // paint (one will be triggered by entering highlight mode). |
615 if (model_->is_highlighting() && !browser_action_views_.empty() && | 666 if (model_->is_highlighting() && !browser_action_views_.empty() && |
616 !in_overflow_mode()) { | 667 !in_overflow_mode()) { |
617 views::Painter::PaintPainterAt( | 668 views::Painter::PaintPainterAt( |
618 canvas, highlight_painter_.get(), GetLocalBounds()); | 669 canvas, highlight_painter_.get(), GetLocalBounds()); |
619 } | 670 } |
(...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) { | 764 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
714 DCHECK(browser_action_views_[i]->extension() != extension) << | 765 DCHECK(browser_action_views_[i]->extension() != extension) << |
715 "Asked to add a browser action view for an extension that already " | 766 "Asked to add a browser action view for an extension that already " |
716 "exists."; | 767 "exists."; |
717 } | 768 } |
718 #endif | 769 #endif |
719 if (chevron_) | 770 if (chevron_) |
720 chevron_->CloseMenu(); | 771 chevron_->CloseMenu(); |
721 | 772 |
722 // Add the new browser action to the vector and the view hierarchy. | 773 // Add the new browser action to the vector and the view hierarchy. |
723 BrowserActionView* view = | 774 BrowserActionView* view = new BrowserActionView( |
724 new BrowserActionView(extension, | 775 make_scoped_ptr(new ExtensionActionViewController( |
725 extensions::ExtensionActionManager::Get(profile_)-> | 776 extension, |
726 GetExtensionAction(*extension), | 777 browser_, |
727 browser_, | 778 extensions::ExtensionActionManager::Get(profile_)-> |
728 this); | 779 GetExtensionAction(*extension))), |
| 780 browser_, |
| 781 this); |
729 browser_action_views_.insert(browser_action_views_.begin() + index, view); | 782 browser_action_views_.insert(browser_action_views_.begin() + index, view); |
730 AddChildViewAt(view, index); | 783 AddChildViewAt(view, index); |
731 | 784 |
732 // If we are still initializing the container, don't bother animating. | 785 // If we are still initializing the container, don't bother animating. |
733 if (!model_->extensions_initialized()) | 786 if (!model_->extensions_initialized()) |
734 return; | 787 return; |
735 | 788 |
736 // If this is just an upgrade, then don't worry about resizing. | 789 // If this is just an upgrade, then don't worry about resizing. |
737 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 790 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
738 IsBeingUpgraded(extension)) { | 791 IsBeingUpgraded(extension)) { |
(...skipping 19 matching lines...) Expand all Loading... |
758 } | 811 } |
759 | 812 |
760 void BrowserActionsContainer::ToolbarExtensionRemoved( | 813 void BrowserActionsContainer::ToolbarExtensionRemoved( |
761 const Extension* extension) { | 814 const Extension* extension) { |
762 if (chevron_) | 815 if (chevron_) |
763 chevron_->CloseMenu(); | 816 chevron_->CloseMenu(); |
764 | 817 |
765 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); | 818 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); |
766 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 819 for (BrowserActionViews::iterator i(browser_action_views_.begin()); |
767 i != browser_action_views_.end(); ++i) { | 820 i != browser_action_views_.end(); ++i) { |
768 if ((*i)->extension() == extension) { | 821 if ((*i)->GetExtensionActionViewController()->extension() == extension) { |
769 delete *i; | 822 delete *i; |
770 browser_action_views_.erase(i); | 823 browser_action_views_.erase(i); |
771 | 824 |
772 // If the extension is being upgraded we don't want the bar to shrink | 825 // 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. | 826 // because the icon is just going to get re-added to the same location. |
774 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 827 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
775 IsBeingUpgraded(extension)) | 828 IsBeingUpgraded(extension)) |
776 return; | 829 return; |
777 | 830 |
778 if (browser_action_views_.size() > visible_actions) { | 831 if (browser_action_views_.size() > visible_actions) { |
(...skipping 13 matching lines...) Expand all Loading... |
792 } | 845 } |
793 } | 846 } |
794 } | 847 } |
795 | 848 |
796 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, | 849 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, |
797 int index) { | 850 int index) { |
798 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); | 851 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); |
799 | 852 |
800 BrowserActionViews::iterator iter = browser_action_views_.begin(); | 853 BrowserActionViews::iterator iter = browser_action_views_.begin(); |
801 while (iter != browser_action_views_.end() && | 854 while (iter != browser_action_views_.end() && |
802 (*iter)->extension() != extension) { | 855 (*iter)->GetExtensionActionViewController()->extension() != extension) |
803 ++iter; | 856 ++iter; |
804 } | |
805 | 857 |
806 DCHECK(iter != browser_action_views_.end()); | 858 DCHECK(iter != browser_action_views_.end()); |
807 if (iter - browser_action_views_.begin() == index) | 859 if (iter - browser_action_views_.begin() == index) |
808 return; // Already in place. | 860 return; // Already in place. |
809 | 861 |
810 BrowserActionView* moved_view = *iter; | 862 BrowserActionView* moved_view = *iter; |
811 browser_action_views_.erase(iter); | 863 browser_action_views_.erase(iter); |
812 browser_action_views_.insert( | 864 browser_action_views_.insert( |
813 browser_action_views_.begin() + index, moved_view); | 865 browser_action_views_.begin() + index, moved_view); |
814 | 866 |
815 Layout(); | 867 Layout(); |
816 SchedulePaint(); | 868 SchedulePaint(); |
817 } | 869 } |
818 | 870 |
819 void BrowserActionsContainer::ToolbarExtensionUpdated( | 871 void BrowserActionsContainer::ToolbarExtensionUpdated( |
820 const Extension* extension) { | 872 const Extension* extension) { |
821 BrowserActionView* view = GetViewForExtension(extension); | 873 BrowserActionView* view = GetViewForExtension(extension); |
822 DCHECK(view); | 874 DCHECK(view); |
823 view->UpdateState(); | 875 view->UpdateState(); |
824 } | 876 } |
825 | 877 |
826 bool BrowserActionsContainer::ShowExtensionActionPopup( | 878 bool BrowserActionsContainer::ShowExtensionActionPopup( |
827 const Extension* extension, | 879 const Extension* extension, |
828 bool grant_active_tab) { | 880 bool grant_active_tab) { |
829 // Don't override another popup, and only show in the active window. | 881 // Don't override another popup, and only show in the active window. |
830 if (popup_owner_ || !browser_->window()->IsActive()) | 882 if (popup_owner_ || !browser_->window()->IsActive()) |
831 return false; | 883 return false; |
832 | 884 |
833 BrowserActionView* view = GetViewForExtension(extension); | 885 BrowserActionView* view = GetViewForExtension(extension); |
834 return view && view->view_controller()->ExecuteAction(ExtensionPopup::SHOW, | 886 return view && view->GetExtensionActionViewController()->ExecuteAction( |
835 grant_active_tab); | 887 ExtensionPopup::SHOW, grant_active_tab); |
836 } | 888 } |
837 | 889 |
838 void BrowserActionsContainer::ToolbarVisibleCountChanged() { | 890 void BrowserActionsContainer::ToolbarVisibleCountChanged() { |
839 if (GetPreferredWidth() != container_width_) | 891 if (GetPreferredWidth() != container_width_) |
840 Animate(gfx::Tween::EASE_OUT, GetIconCount()); | 892 Animate(gfx::Tween::EASE_OUT, GetIconCount()); |
841 } | 893 } |
842 | 894 |
843 void BrowserActionsContainer::ToolbarHighlightModeChanged( | 895 void BrowserActionsContainer::ToolbarHighlightModeChanged( |
844 bool is_highlighting) { | 896 bool is_highlighting) { |
845 // The visual highlighting is done in OnPaint(). It's a bit of a pain that | 897 // 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... |
951 | 1003 |
952 size_t BrowserActionsContainer::GetIconCount() const { | 1004 size_t BrowserActionsContainer::GetIconCount() const { |
953 if (!model_) | 1005 if (!model_) |
954 return 0u; | 1006 return 0u; |
955 | 1007 |
956 // Find the absolute value for the model's visible count. | 1008 // Find the absolute value for the model's visible count. |
957 int model_visible_size = model_->GetVisibleIconCount(); | 1009 int model_visible_size = model_->GetVisibleIconCount(); |
958 size_t absolute_model_visible_size = model_visible_size == -1 ? | 1010 size_t absolute_model_visible_size = model_visible_size == -1 ? |
959 model_->toolbar_items().size() : model_visible_size; | 1011 model_->toolbar_items().size() : model_visible_size; |
960 | 1012 |
| 1013 #if defined(DEBUG) |
961 // Good time for some sanity checks: We should never try to display more | 1014 // Good time for some sanity checks: We should never try to display more |
962 // icons than we have, and we should always have a view per item in the model. | 1015 // icons than we have, and we should always have a view per item in the model. |
963 // (The only exception is if this is in initialization.) | 1016 // (The only exception is if this is in initialization.) |
964 if (initialized_) { | 1017 if (initialized_) { |
| 1018 size_t num_extension_actions = 0u; |
| 1019 for (const BrowserActionView* view : browser_action_views_) { |
| 1020 num_extension_actions += |
| 1021 view->view_controller()->GetType() == |
| 1022 ToolbarActionViewController::TYPE_EXTENSION_ACTION ? 1 : 0; |
| 1023 } |
965 DCHECK_LE(absolute_model_visible_size, browser_action_views_.size()); | 1024 DCHECK_LE(absolute_model_visible_size, browser_action_views_.size()); |
966 DCHECK_EQ(model_->toolbar_items().size(), browser_action_views_.size()); | 1025 DCHECK_EQ(model_->toolbar_items().size(), browser_action_views_.size()); |
967 } | 1026 } |
| 1027 #endif |
968 | 1028 |
969 // The overflow displays any icons not shown by the main bar. | 1029 // The overflow displays any icons not shown by the main bar. |
970 return in_overflow_mode() ? | 1030 return in_overflow_mode() ? |
971 model_->toolbar_items().size() - absolute_model_visible_size : | 1031 model_->toolbar_items().size() - absolute_model_visible_size : |
972 absolute_model_visible_size; | 1032 absolute_model_visible_size; |
973 } | 1033 } |
OLD | NEW |