Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container.cc

Issue 411063003: Combine BrowserActionView and BrowserActionButton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/toolbar/browser_actions_container.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/extensions/extension_util.h" 10 #include "chrome/browser/extensions/extension_util.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 model_->SetVisibleIconCount(WidthToIconCount(predefined_width)); 206 model_->SetVisibleIconCount(WidthToIconCount(predefined_width));
207 } 207 }
208 if (model_ && model_->extensions_initialized()) 208 if (model_ && model_->extensions_initialized())
209 SetContainerWidth(); 209 SetContainerWidth();
210 } 210 }
211 211
212 BrowserActionView* BrowserActionsContainer::GetBrowserActionView( 212 BrowserActionView* BrowserActionsContainer::GetBrowserActionView(
213 ExtensionAction* action) { 213 ExtensionAction* action) {
214 for (BrowserActionViews::iterator i(browser_action_views_.begin()); 214 for (BrowserActionViews::iterator i(browser_action_views_.begin());
215 i != browser_action_views_.end(); ++i) { 215 i != browser_action_views_.end(); ++i) {
216 if ((*i)->button()->extension_action() == action) 216 if ((*i)->extension_action() == action)
217 return *i; 217 return *i;
218 } 218 }
219 return NULL; 219 return NULL;
220 } 220 }
221 221
222 void BrowserActionsContainer::RefreshBrowserActionViews() { 222 void BrowserActionsContainer::RefreshBrowserActionViews() {
223 for (size_t i = 0; i < browser_action_views_.size(); ++i) 223 for (size_t i = 0; i < browser_action_views_.size(); ++i)
224 browser_action_views_[i]->button()->UpdateState(); 224 browser_action_views_[i]->UpdateState();
225 } 225 }
226 226
227 void BrowserActionsContainer::CreateBrowserActionViews() { 227 void BrowserActionsContainer::CreateBrowserActionViews() {
228 DCHECK(browser_action_views_.empty()); 228 DCHECK(browser_action_views_.empty());
229 if (!model_) 229 if (!model_)
230 return; 230 return;
231 231
232 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); 232 const extensions::ExtensionList& toolbar_items = model_->toolbar_items();
233 for (extensions::ExtensionList::const_iterator i(toolbar_items.begin()); 233 for (extensions::ExtensionList::const_iterator i(toolbar_items.begin());
234 i != toolbar_items.end(); ++i) { 234 i != toolbar_items.end(); ++i) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 OnBrowserActionDragDone()); 287 OnBrowserActionDragDone());
288 } 288 }
289 289
290 views::View* BrowserActionsContainer::GetOverflowReferenceView() { 290 views::View* BrowserActionsContainer::GetOverflowReferenceView() {
291 // We should only need an overflow reference when using the traditional 291 // We should only need an overflow reference when using the traditional
292 // chevron overflow. 292 // chevron overflow.
293 DCHECK(chevron_); 293 DCHECK(chevron_);
294 return chevron_; 294 return chevron_;
295 } 295 }
296 296
297 void BrowserActionsContainer::SetPopupOwner(BrowserActionButton* popup_owner) { 297 void BrowserActionsContainer::SetPopupOwner(BrowserActionView* popup_owner) {
298 // We should never be setting a popup owner when one already exists. 298 // We should never be setting a popup owner when one already exists.
299 DCHECK(!popup_owner_ || !popup_owner); 299 DCHECK(!popup_owner_ || !popup_owner);
300 popup_owner_ = popup_owner; 300 popup_owner_ = popup_owner;
301 } 301 }
302 302
303 void BrowserActionsContainer::HideActivePopup() { 303 void BrowserActionsContainer::HideActivePopup() {
304 if (popup_owner_) 304 if (popup_owner_)
305 popup_owner_->view_controller()->HidePopup(); 305 popup_owner_->view_controller()->HidePopup();
306 } 306 }
307 307
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 SchedulePaint(); 518 SchedulePaint();
519 } 519 }
520 520
521 int BrowserActionsContainer::OnPerformDrop( 521 int BrowserActionsContainer::OnPerformDrop(
522 const ui::DropTargetEvent& event) { 522 const ui::DropTargetEvent& event) {
523 BrowserActionDragData data; 523 BrowserActionDragData data;
524 if (!data.Read(event.data())) 524 if (!data.Read(event.data()))
525 return ui::DragDropTypes::DRAG_NONE; 525 return ui::DragDropTypes::DRAG_NONE;
526 526
527 // Make sure we have the same view as we started with. 527 // Make sure we have the same view as we started with.
528 DCHECK_EQ(browser_action_views_[data.index()]->button()->extension()->id(), 528 DCHECK_EQ(browser_action_views_[data.index()]->extension()->id(),
529 data.id()); 529 data.id());
530 DCHECK(model_); 530 DCHECK(model_);
531 531
532 size_t i = 532 size_t i =
533 drop_position_->row * kIconsPerMenuRow + drop_position_->icon_in_row; 533 drop_position_->row * kIconsPerMenuRow + drop_position_->icon_in_row;
534 if (in_overflow_mode()) 534 if (in_overflow_mode())
535 i += GetFirstVisibleIconIndex(); 535 i += GetFirstVisibleIconIndex();
536 // |i| now points to the item to the right of the drop indicator*, which is 536 // |i| now points to the item to the right of the drop indicator*, which is
537 // correct when dragging an icon to the left. When dragging to the right, 537 // correct when dragging an icon to the left. When dragging to the right,
538 // however, we want the icon being dragged to get the index of the item to 538 // however, we want the icon being dragged to get the index of the item to
539 // the left of the drop indicator, so we subtract one. 539 // the left of the drop indicator, so we subtract one.
540 // * Well, it can also point to the end, but not when dragging to the left. :) 540 // * Well, it can also point to the end, but not when dragging to the left. :)
541 if (i > data.index()) 541 if (i > data.index())
542 --i; 542 --i;
543 543
544 if (profile_->IsOffTheRecord()) 544 if (profile_->IsOffTheRecord())
545 i = model_->IncognitoIndexToOriginal(i); 545 i = model_->IncognitoIndexToOriginal(i);
546 546
547 model_->MoveBrowserAction( 547 model_->MoveBrowserAction(
548 browser_action_views_[data.index()]->button()->extension(), i); 548 browser_action_views_[data.index()]->extension(), i);
549 549
550 OnDragExited(); // Perform clean up after dragging. 550 OnDragExited(); // Perform clean up after dragging.
551 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, 551 FOR_EACH_OBSERVER(BrowserActionsContainerObserver,
552 observers_, 552 observers_,
553 OnBrowserActionDragDone()); 553 OnBrowserActionDragDone());
554 return ui::DragDropTypes::DRAG_MOVE; 554 return ui::DragDropTypes::DRAG_MOVE;
555 } 555 }
556 556
557 void BrowserActionsContainer::GetAccessibleState( 557 void BrowserActionsContainer::GetAccessibleState(
558 ui::AXViewState* state) { 558 ui::AXViewState* state) {
(...skipping 15 matching lines...) Expand all
574 overflow_menu_->RunMenu(GetWidget()); 574 overflow_menu_->RunMenu(GetWidget());
575 } 575 }
576 } 576 }
577 577
578 void BrowserActionsContainer::WriteDragDataForView(View* sender, 578 void BrowserActionsContainer::WriteDragDataForView(View* sender,
579 const gfx::Point& press_pt, 579 const gfx::Point& press_pt,
580 OSExchangeData* data) { 580 OSExchangeData* data) {
581 DCHECK(data); 581 DCHECK(data);
582 582
583 for (size_t i = 0; i < browser_action_views_.size(); ++i) { 583 for (size_t i = 0; i < browser_action_views_.size(); ++i) {
584 BrowserActionButton* button = browser_action_views_[i]->button(); 584 BrowserActionView* view = browser_action_views_[i];
585 if (button == sender) { 585 if (view == sender) {
586 // Set the dragging image for the icon. 586 // Set the dragging image for the icon.
587 gfx::ImageSkia badge(browser_action_views_[i]->GetIconWithBadge()); 587 gfx::ImageSkia badge(view->GetIconWithBadge());
588 drag_utils::SetDragImageOnDataObject(badge, 588 drag_utils::SetDragImageOnDataObject(badge,
589 press_pt.OffsetFromOrigin(), 589 press_pt.OffsetFromOrigin(),
590 data); 590 data);
591 591
592 // Fill in the remaining info. 592 // Fill in the remaining info.
593 BrowserActionDragData drag_data( 593 BrowserActionDragData drag_data(view->extension()->id(), i);
594 browser_action_views_[i]->button()->extension()->id(), i);
595 drag_data.Write(profile_, data); 594 drag_data.Write(profile_, data);
596 break; 595 break;
597 } 596 }
598 } 597 }
599 } 598 }
600 599
601 int BrowserActionsContainer::GetDragOperationsForView(View* sender, 600 int BrowserActionsContainer::GetDragOperationsForView(View* sender,
602 const gfx::Point& p) { 601 const gfx::Point& p) {
603 return ui::DragDropTypes::DRAG_MOVE; 602 return ui::DragDropTypes::DRAG_MOVE;
604 } 603 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 icon_height = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 785 icon_height = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
787 IDR_BROWSER_ACTION)->height(); 786 IDR_BROWSER_ACTION)->height();
788 } 787 }
789 return icon_height; 788 return icon_height;
790 } 789 }
791 790
792 void BrowserActionsContainer::BrowserActionAdded(const Extension* extension, 791 void BrowserActionsContainer::BrowserActionAdded(const Extension* extension,
793 int index) { 792 int index) {
794 #if defined(DEBUG) 793 #if defined(DEBUG)
795 for (size_t i = 0; i < browser_action_views_.size(); ++i) { 794 for (size_t i = 0; i < browser_action_views_.size(); ++i) {
796 DCHECK(browser_action_views_[i]->button()->extension() != extension) << 795 DCHECK(browser_action_views_[i]->extension() != extension) <<
797 "Asked to add a browser action view for an extension that already " 796 "Asked to add a browser action view for an extension that already "
798 "exists."; 797 "exists.";
799 } 798 }
800 #endif 799 #endif
801 CloseOverflowMenu(); 800 CloseOverflowMenu();
802 801
803 if (!ShouldDisplayBrowserAction(extension)) 802 if (!ShouldDisplayBrowserAction(extension))
804 return; 803 return;
805 804
806 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); 805 size_t visible_actions = VisibleBrowserActionsAfterAnimation();
(...skipping 21 matching lines...) Expand all
828 OnBrowserActionVisibilityChanged(); 827 OnBrowserActionVisibilityChanged();
829 } 828 }
830 } 829 }
831 830
832 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { 831 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) {
833 CloseOverflowMenu(); 832 CloseOverflowMenu();
834 833
835 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); 834 size_t visible_actions = VisibleBrowserActionsAfterAnimation();
836 for (BrowserActionViews::iterator i(browser_action_views_.begin()); 835 for (BrowserActionViews::iterator i(browser_action_views_.begin());
837 i != browser_action_views_.end(); ++i) { 836 i != browser_action_views_.end(); ++i) {
838 if ((*i)->button()->extension() == extension) { 837 if ((*i)->extension() == extension) {
839 delete *i; 838 delete *i;
840 browser_action_views_.erase(i); 839 browser_action_views_.erase(i);
841 840
842 // If the extension is being upgraded we don't want the bar to shrink 841 // If the extension is being upgraded we don't want the bar to shrink
843 // because the icon is just going to get re-added to the same location. 842 // because the icon is just going to get re-added to the same location.
844 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> 843 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()->
845 IsBeingUpgraded(extension)) 844 IsBeingUpgraded(extension))
846 return; 845 return;
847 846
848 if (browser_action_views_.size() > visible_actions) { 847 if (browser_action_views_.size() > visible_actions) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 // fixed. 1037 // fixed.
1039 if (!can_override && 1038 if (!can_override &&
1040 (popup_owner_ || 1039 (popup_owner_ ||
1041 !browser_->window()->IsActive() || 1040 !browser_->window()->IsActive() ||
1042 !browser_->window()->IsToolbarVisible())) { 1041 !browser_->window()->IsToolbarVisible())) {
1043 return false; 1042 return false;
1044 } 1043 }
1045 1044
1046 for (BrowserActionViews::iterator iter = browser_action_views_.begin(); 1045 for (BrowserActionViews::iterator iter = browser_action_views_.begin();
1047 iter != browser_action_views_.end(); ++iter) { 1046 iter != browser_action_views_.end(); ++iter) {
1048 BrowserActionButton* button = (*iter)->button(); 1047 BrowserActionView* view = (*iter);
1049 if (button->extension() == extension) 1048 if (view->extension() == extension)
1050 return button->view_controller()->ExecuteAction( 1049 return view->view_controller()->ExecuteAction(
1051 ExtensionPopup::SHOW, grant_tab_permissions); 1050 ExtensionPopup::SHOW, grant_tab_permissions);
1052 } 1051 }
1053 return false; 1052 return false;
1054 } 1053 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/browser_actions_container.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698