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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 main_container_(main_container), | 131 main_container_(main_container), |
132 popup_owner_(NULL), | 132 popup_owner_(NULL), |
133 model_(NULL), | 133 model_(NULL), |
134 container_width_(0), | 134 container_width_(0), |
135 resize_area_(NULL), | 135 resize_area_(NULL), |
136 chevron_(NULL), | 136 chevron_(NULL), |
137 overflow_menu_(NULL), | 137 overflow_menu_(NULL), |
138 suppress_chevron_(false), | 138 suppress_chevron_(false), |
139 resize_amount_(0), | 139 resize_amount_(0), |
140 animation_target_size_(0), | 140 animation_target_size_(0), |
141 task_factory_(this), | |
142 show_menu_task_factory_(this) { | 141 show_menu_task_factory_(this) { |
143 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 142 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
144 | 143 |
145 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); | 144 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); |
146 if (model_) | 145 if (model_) |
147 model_->AddObserver(this); | 146 model_->AddObserver(this); |
148 | 147 |
149 bool overflow_experiment = | 148 bool overflow_experiment = |
150 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); | 149 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); |
151 DCHECK(!in_overflow_mode() || overflow_experiment); | 150 DCHECK(!in_overflow_mode() || overflow_experiment); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 189 |
191 void BrowserActionsContainer::Init() { | 190 void BrowserActionsContainer::Init() { |
192 LoadImages(); | 191 LoadImages(); |
193 | 192 |
194 // We wait to set the container width until now so that the chevron images | 193 // We wait to set the container width until now so that the chevron images |
195 // will be loaded. The width calculation needs to know the chevron size. | 194 // will be loaded. The width calculation needs to know the chevron size. |
196 if (model_ && model_->extensions_initialized()) | 195 if (model_ && model_->extensions_initialized()) |
197 SetContainerWidth(); | 196 SetContainerWidth(); |
198 } | 197 } |
199 | 198 |
200 BrowserActionView* BrowserActionsContainer::GetBrowserActionView( | 199 BrowserActionView* BrowserActionsContainer::GetViewForExtension( |
201 ExtensionAction* action) { | 200 const Extension* extension) { |
202 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 201 for (BrowserActionViews::iterator view = browser_action_views_.begin(); |
203 i != browser_action_views_.end(); ++i) { | 202 view != browser_action_views_.end(); ++view) { |
204 if ((*i)->extension_action() == action) | 203 if ((*view)->extension() == extension) |
205 return *i; | 204 return *view; |
206 } | 205 } |
207 return NULL; | 206 return NULL; |
208 } | 207 } |
209 | 208 |
210 void BrowserActionsContainer::RefreshBrowserActionViews() { | 209 void BrowserActionsContainer::RefreshBrowserActionViews() { |
211 for (size_t i = 0; i < browser_action_views_.size(); ++i) | 210 for (size_t i = 0; i < browser_action_views_.size(); ++i) |
212 browser_action_views_[i]->UpdateState(); | 211 browser_action_views_[i]->UpdateState(); |
213 } | 212 } |
214 | 213 |
215 void BrowserActionsContainer::CreateBrowserActionViews() { | 214 void BrowserActionsContainer::CreateBrowserActionViews() { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 412 } |
414 | 413 |
415 bool BrowserActionsContainer::AreDropTypesRequired() { | 414 bool BrowserActionsContainer::AreDropTypesRequired() { |
416 return BrowserActionDragData::AreDropTypesRequired(); | 415 return BrowserActionDragData::AreDropTypesRequired(); |
417 } | 416 } |
418 | 417 |
419 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { | 418 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { |
420 return BrowserActionDragData::CanDrop(data, profile_); | 419 return BrowserActionDragData::CanDrop(data, profile_); |
421 } | 420 } |
422 | 421 |
423 void BrowserActionsContainer::OnDragEntered( | |
424 const ui::DropTargetEvent& event) { | |
425 } | |
426 | |
427 int BrowserActionsContainer::OnDragUpdated( | 422 int BrowserActionsContainer::OnDragUpdated( |
428 const ui::DropTargetEvent& event) { | 423 const ui::DropTargetEvent& event) { |
429 // First check if we are above the chevron (overflow) menu. | 424 // First check if we are above the chevron (overflow) menu. |
430 if (GetEventHandlerForPoint(event.location()) == chevron_) { | 425 if (GetEventHandlerForPoint(event.location()) == chevron_) { |
431 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) | 426 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) |
432 StartShowFolderDropMenuTimer(); | 427 StartShowFolderDropMenuTimer(); |
433 return ui::DragDropTypes::DRAG_MOVE; | 428 return ui::DragDropTypes::DRAG_MOVE; |
434 } | 429 } |
435 StopShowFolderDropMenuTimer(); | 430 StopShowFolderDropMenuTimer(); |
436 | 431 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 extensions::ActiveTabPermissionGranter* | 660 extensions::ActiveTabPermissionGranter* |
666 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 661 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
667 content::WebContents* web_contents = | 662 content::WebContents* web_contents = |
668 browser_->tab_strip_model()->GetActiveWebContents(); | 663 browser_->tab_strip_model()->GetActiveWebContents(); |
669 if (!web_contents) | 664 if (!web_contents) |
670 return NULL; | 665 return NULL; |
671 return extensions::TabHelper::FromWebContents(web_contents)-> | 666 return extensions::TabHelper::FromWebContents(web_contents)-> |
672 active_tab_permission_granter(); | 667 active_tab_permission_granter(); |
673 } | 668 } |
674 | 669 |
675 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, | |
676 size_t new_index) { | |
677 const Extension* extension = extensions::ExtensionRegistry::Get(profile_)-> | |
678 enabled_extensions().GetByID(extension_id); | |
679 model_->MoveExtensionIcon(extension, new_index); | |
680 SchedulePaint(); | |
681 } | |
682 | |
683 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { | 670 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { |
684 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; | 671 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; |
685 } | 672 } |
686 | 673 |
687 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { | 674 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { |
688 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; | 675 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; |
689 } | 676 } |
690 | 677 |
691 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { | 678 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { |
692 model_->SetVisibleIconCount(icons); | 679 model_->SetVisibleIconCount(icons); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 } | 1038 } |
1052 } | 1039 } |
1053 | 1040 |
1054 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1041 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
1055 const Extension* extension) const { | 1042 const Extension* extension) const { |
1056 // Only display incognito-enabled extensions while in incognito mode. | 1043 // Only display incognito-enabled extensions while in incognito mode. |
1057 return !profile_->IsOffTheRecord() || | 1044 return !profile_->IsOffTheRecord() || |
1058 extensions::util::IsIncognitoEnabled(extension->id(), profile_); | 1045 extensions::util::IsIncognitoEnabled(extension->id(), profile_); |
1059 } | 1046 } |
1060 | 1047 |
1061 BrowserActionView* BrowserActionsContainer::GetViewForExtension( | |
1062 const Extension* extension) { | |
1063 for (BrowserActionViews::iterator view = browser_action_views_.begin(); | |
1064 view != browser_action_views_.end(); ++view) { | |
1065 if ((*view)->extension() == extension) | |
1066 return *view; | |
1067 } | |
1068 | |
1069 return NULL; | |
1070 } | |
1071 | |
1072 size_t BrowserActionsContainer::GetIconCount() const { | 1048 size_t BrowserActionsContainer::GetIconCount() const { |
1073 if (!model_) | 1049 if (!model_) |
1074 return 0u; | 1050 return 0u; |
1075 // Find the number of icons which could be displayed. | 1051 // Find the number of icons which could be displayed. |
1076 size_t displayable_icon_count = 0u; | 1052 size_t displayable_icon_count = 0u; |
1077 const extensions::ExtensionList& extensions = model_->toolbar_items(); | 1053 const extensions::ExtensionList& extensions = model_->toolbar_items(); |
1078 for (extensions::ExtensionList::const_iterator iter = extensions.begin(); | 1054 for (extensions::ExtensionList::const_iterator iter = extensions.begin(); |
1079 iter != extensions.end(); ++iter) { | 1055 iter != extensions.end(); ++iter) { |
1080 displayable_icon_count += ShouldDisplayBrowserAction(iter->get()) ? 1u : 0u; | 1056 displayable_icon_count += ShouldDisplayBrowserAction(iter->get()) ? 1u : 0u; |
1081 } | 1057 } |
1082 // Find the absolute value for the model's visible count. | 1058 // Find the absolute value for the model's visible count. |
1083 int model_size = model_->GetVisibleIconCount(); | 1059 int model_size = model_->GetVisibleIconCount(); |
1084 size_t absolute_model_size = | 1060 size_t absolute_model_size = |
1085 model_size == -1 ? extensions.size() : model_size; | 1061 model_size == -1 ? extensions.size() : model_size; |
1086 | 1062 |
1087 // The main container will try to show |model_size| icons, but reduce if there | 1063 // The main container will try to show |model_size| icons, but reduce if there |
1088 // aren't enough displayable icons to do so. | 1064 // aren't enough displayable icons to do so. |
1089 size_t main_displayed = std::min(displayable_icon_count, absolute_model_size); | 1065 size_t main_displayed = std::min(displayable_icon_count, absolute_model_size); |
1090 // The overflow will display the extras, if any. | 1066 // The overflow will display the extras, if any. |
1091 return in_overflow_mode() ? | 1067 return in_overflow_mode() ? |
1092 displayable_icon_count - main_displayed : main_displayed; | 1068 displayable_icon_count - main_displayed : main_displayed; |
1093 } | 1069 } |
OLD | NEW |