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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return visible_actions; | 170 return visible_actions; |
171 } | 171 } |
172 | 172 |
173 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const { | 173 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const { |
174 if (!animating()) | 174 if (!animating()) |
175 return VisibleBrowserActions(); | 175 return VisibleBrowserActions(); |
176 | 176 |
177 return toolbar_actions_bar_->WidthToIconCount(animation_target_size_); | 177 return toolbar_actions_bar_->WidthToIconCount(animation_target_size_); |
178 } | 178 } |
179 | 179 |
| 180 void BrowserActionsContainer::ExecuteExtensionCommand( |
| 181 const extensions::Extension* extension, |
| 182 const extensions::Command& command) { |
| 183 // Global commands are handled by the ExtensionCommandsGlobalRegistry |
| 184 // instance. |
| 185 DCHECK(!command.global()); |
| 186 extension_keybinding_registry_->ExecuteCommand(extension->id(), |
| 187 command.accelerator()); |
| 188 } |
| 189 |
180 bool BrowserActionsContainer::ShownInsideMenu() const { | 190 bool BrowserActionsContainer::ShownInsideMenu() const { |
181 return in_overflow_mode(); | 191 return in_overflow_mode(); |
182 } | 192 } |
183 | 193 |
184 void BrowserActionsContainer::OnToolbarActionViewDragDone() { | 194 void BrowserActionsContainer::OnToolbarActionViewDragDone() { |
185 toolbar_actions_bar_->OnDragEnded(); | 195 toolbar_actions_bar_->OnDragEnded(); |
186 } | 196 } |
187 | 197 |
188 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { | 198 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { |
189 // With traditional overflow, the reference is the chevron. With the redesign, | 199 // With traditional overflow, the reference is the chevron. With the redesign, |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 suppress_chevron_ = false; | 678 suppress_chevron_ = false; |
669 parent()->Layout(); | 679 parent()->Layout(); |
670 | 680 |
671 toolbar_actions_bar_->OnAnimationEnded(); | 681 toolbar_actions_bar_->OnAnimationEnded(); |
672 } | 682 } |
673 | 683 |
674 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { | 684 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { |
675 return browser_->tab_strip_model()->GetActiveWebContents(); | 685 return browser_->tab_strip_model()->GetActiveWebContents(); |
676 } | 686 } |
677 | 687 |
| 688 extensions::ActiveTabPermissionGranter* |
| 689 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 690 content::WebContents* web_contents = GetCurrentWebContents(); |
| 691 if (!web_contents) |
| 692 return NULL; |
| 693 return extensions::TabHelper::FromWebContents(web_contents)-> |
| 694 active_tab_permission_granter(); |
| 695 } |
| 696 |
678 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 697 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
679 // If the views haven't been initialized yet, wait for the next call to | 698 // If the views haven't been initialized yet, wait for the next call to |
680 // paint (one will be triggered by entering highlight mode). | 699 // paint (one will be triggered by entering highlight mode). |
681 if (toolbar_actions_bar_->is_highlighting() && | 700 if (toolbar_actions_bar_->is_highlighting() && |
682 !toolbar_action_views_.empty() && !in_overflow_mode()) { | 701 !toolbar_action_views_.empty() && !in_overflow_mode()) { |
683 ToolbarActionsModel::HighlightType highlight_type = | 702 ToolbarActionsModel::HighlightType highlight_type = |
684 toolbar_actions_bar_->highlight_type(); | 703 toolbar_actions_bar_->highlight_type(); |
685 views::Painter* painter = | 704 views::Painter* painter = |
686 highlight_type == ToolbarActionsModel::HIGHLIGHT_INFO | 705 highlight_type == ToolbarActionsModel::HIGHLIGHT_INFO |
687 ? info_highlight_painter_.get() | 706 ? info_highlight_painter_.get() |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 void BrowserActionsContainer::OnThemeChanged() { | 745 void BrowserActionsContainer::OnThemeChanged() { |
727 LoadImages(); | 746 LoadImages(); |
728 } | 747 } |
729 | 748 |
730 void BrowserActionsContainer::ViewHierarchyChanged( | 749 void BrowserActionsContainer::ViewHierarchyChanged( |
731 const ViewHierarchyChangedDetails& details) { | 750 const ViewHierarchyChangedDetails& details) { |
732 if (!toolbar_actions_bar_->enabled()) | 751 if (!toolbar_actions_bar_->enabled()) |
733 return; | 752 return; |
734 | 753 |
735 if (details.is_add && details.child == this) { | 754 if (details.is_add && details.child == this) { |
| 755 if (!in_overflow_mode() && // We only need one keybinding registry. |
| 756 parent()->GetFocusManager()) { // focus manager can be null in tests. |
| 757 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
| 758 browser_->profile(), |
| 759 parent()->GetFocusManager(), |
| 760 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
| 761 this)); |
| 762 } |
| 763 |
736 // Initial toolbar button creation and placement in the widget hierarchy. | 764 // Initial toolbar button creation and placement in the widget hierarchy. |
737 // We do this here instead of in the constructor because adding views | 765 // We do this here instead of in the constructor because adding views |
738 // calls Layout on the Toolbar, which needs this object to be constructed | 766 // calls Layout on the Toolbar, which needs this object to be constructed |
739 // before its Layout function is called. | 767 // before its Layout function is called. |
740 toolbar_actions_bar_->CreateActions(); | 768 toolbar_actions_bar_->CreateActions(); |
741 | 769 |
742 added_to_view_ = true; | 770 added_to_view_ = true; |
743 } | 771 } |
744 } | 772 } |
745 | 773 |
(...skipping 14 matching lines...) Expand all Loading... |
760 warning_highlight_painter_.reset( | 788 warning_highlight_painter_.reset( |
761 views::Painter::CreateImageGridPainter(kWarningImages)); | 789 views::Painter::CreateImageGridPainter(kWarningImages)); |
762 } | 790 } |
763 | 791 |
764 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { | 792 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { |
765 DCHECK(active_bubble_); | 793 DCHECK(active_bubble_); |
766 DCHECK_EQ(active_bubble_->GetWidget(), widget); | 794 DCHECK_EQ(active_bubble_->GetWidget(), widget); |
767 widget->RemoveObserver(this); | 795 widget->RemoveObserver(this); |
768 active_bubble_ = nullptr; | 796 active_bubble_ = nullptr; |
769 } | 797 } |
OLD | NEW |