| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/browser_actions_container.h" | 5 #include "chrome/browser/views/browser_actions_container.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "app/slide_animation.h" | 9 #include "app/slide_animation.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 if (drop_indicator_position_ != x_pos) { | 436 if (drop_indicator_position_ != x_pos) { |
| 437 drop_indicator_position_ = x_pos; | 437 drop_indicator_position_ = x_pos; |
| 438 SchedulePaint(); | 438 SchedulePaint(); |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 | 441 |
| 442 void BrowserActionsContainer::CreateBrowserActionViews() { | 442 void BrowserActionsContainer::CreateBrowserActionViews() { |
| 443 DCHECK(browser_action_views_.empty()); | 443 DCHECK(browser_action_views_.empty()); |
| 444 for (ExtensionList::iterator iter = model_->begin(); | 444 for (ExtensionList::iterator iter = model_->begin(); |
| 445 iter != model_->end(); ++iter) { | 445 iter != model_->end(); ++iter) { |
| 446 if (!ShouldDisplayBrowserAction(*iter)) |
| 447 continue; |
| 448 |
| 446 BrowserActionView* view = new BrowserActionView(*iter, this); | 449 BrowserActionView* view = new BrowserActionView(*iter, this); |
| 447 browser_action_views_.push_back(view); | 450 browser_action_views_.push_back(view); |
| 448 AddChildView(view); | 451 AddChildView(view); |
| 449 } | 452 } |
| 450 } | 453 } |
| 451 | 454 |
| 452 void BrowserActionsContainer::DeleteBrowserActionViews() { | 455 void BrowserActionsContainer::DeleteBrowserActionViews() { |
| 453 if (!browser_action_views_.empty()) { | 456 if (!browser_action_views_.empty()) { |
| 454 for (size_t i = 0; i < browser_action_views_.size(); ++i) | 457 for (size_t i = 0; i < browser_action_views_.size(); ++i) |
| 455 RemoveChildView(browser_action_views_[i]); | 458 RemoveChildView(browser_action_views_[i]); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 // We do this here instead of in the constructor because AddBrowserAction | 662 // We do this here instead of in the constructor because AddBrowserAction |
| 660 // calls Layout on the Toolbar, which needs this object to be constructed | 663 // calls Layout on the Toolbar, which needs this object to be constructed |
| 661 // before its Layout function is called. | 664 // before its Layout function is called. |
| 662 CreateBrowserActionViews(); | 665 CreateBrowserActionViews(); |
| 663 } | 666 } |
| 664 } | 667 } |
| 665 | 668 |
| 666 bool BrowserActionsContainer::GetDropFormats( | 669 bool BrowserActionsContainer::GetDropFormats( |
| 667 int* formats, std::set<OSExchangeData::CustomFormat>* custom_formats) { | 670 int* formats, std::set<OSExchangeData::CustomFormat>* custom_formats) { |
| 668 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat()); | 671 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat()); |
| 672 |
| 669 return true; | 673 return true; |
| 670 } | 674 } |
| 671 | 675 |
| 672 bool BrowserActionsContainer::AreDropTypesRequired() { | 676 bool BrowserActionsContainer::AreDropTypesRequired() { |
| 673 return true; | 677 return true; |
| 674 } | 678 } |
| 675 | 679 |
| 676 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { | 680 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { |
| 677 BrowserActionDragData drop_data; | 681 BrowserActionDragData drop_data; |
| 678 if (!drop_data.Read(data)) | 682 if (!drop_data.Read(data)) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 } | 763 } |
| 760 | 764 |
| 761 // |i| now points to the item to the right of the drop indicator*, which is | 765 // |i| now points to the item to the right of the drop indicator*, which is |
| 762 // correct when dragging an icon to the left. When dragging to the right, | 766 // correct when dragging an icon to the left. When dragging to the right, |
| 763 // however, we want the icon being dragged to get the index of the item to | 767 // however, we want the icon being dragged to get the index of the item to |
| 764 // the left of the drop indicator, so we subtract one. | 768 // the left of the drop indicator, so we subtract one. |
| 765 // * Well, it can also point to the end, but not when dragging to the left. :) | 769 // * Well, it can also point to the end, but not when dragging to the left. :) |
| 766 if (i > data.index()) | 770 if (i > data.index()) |
| 767 --i; | 771 --i; |
| 768 | 772 |
| 773 if (profile_->IsOffTheRecord()) |
| 774 i = model_->IncognitoIndexToOriginal(i); |
| 775 |
| 769 model_->MoveBrowserAction(dragging, i); | 776 model_->MoveBrowserAction(dragging, i); |
| 770 | 777 |
| 771 OnDragExited(); // Perform clean up after dragging. | 778 OnDragExited(); // Perform clean up after dragging. |
| 772 return DragDropTypes::DRAG_MOVE; | 779 return DragDropTypes::DRAG_MOVE; |
| 773 } | 780 } |
| 774 | 781 |
| 775 void BrowserActionsContainer::MoveBrowserAction( | 782 void BrowserActionsContainer::MoveBrowserAction( |
| 776 const std::string& extension_id, size_t new_index) { | 783 const std::string& extension_id, size_t new_index) { |
| 777 ExtensionsService* service = profile_->GetExtensionsService(); | 784 ExtensionsService* service = profile_->GetExtensionsService(); |
| 778 Extension* extension = service->GetExtensionById(extension_id, false); | 785 Extension* extension = service->GetExtensionById(extension_id, false); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 #if defined(DEBUG) | 928 #if defined(DEBUG) |
| 922 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 929 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 923 DCHECK(browser_action_views_[i]->button()->extension() != extension) << | 930 DCHECK(browser_action_views_[i]->button()->extension() != extension) << |
| 924 "Asked to add a browser action view for an extension that already " | 931 "Asked to add a browser action view for an extension that already " |
| 925 "exists."; | 932 "exists."; |
| 926 } | 933 } |
| 927 #endif | 934 #endif |
| 928 | 935 |
| 929 CloseOverflowMenu(); | 936 CloseOverflowMenu(); |
| 930 | 937 |
| 938 if (!ShouldDisplayBrowserAction(extension)) |
| 939 return; |
| 940 |
| 941 if (profile_->IsOffTheRecord()) |
| 942 index = model_->OriginalIndexToIncognito(index); |
| 943 |
| 931 // Before we change anything, determine the number of visible browser actions. | 944 // Before we change anything, determine the number of visible browser actions. |
| 932 size_t visible_actions = VisibleBrowserActions(); | 945 size_t visible_actions = VisibleBrowserActions(); |
| 933 | 946 |
| 934 // Add the new browser action to the vector and the view hierarchy. | 947 // Add the new browser action to the vector and the view hierarchy. |
| 935 BrowserActionView* view = new BrowserActionView(extension, this); | 948 BrowserActionView* view = new BrowserActionView(extension, this); |
| 936 browser_action_views_.insert(browser_action_views_.begin() + index, view); | 949 browser_action_views_.insert(browser_action_views_.begin() + index, view); |
| 937 AddChildView(index, view); | 950 AddChildView(index, view); |
| 938 | 951 |
| 939 // For details on why we do the following see the class comments in the | 952 // For details on why we do the following see the class comments in the |
| 940 // header. | 953 // header. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 resize_animation_->Reset(); | 1012 resize_animation_->Reset(); |
| 1000 resize_animation_->SetTweenType(SlideAnimation::EASE_OUT); | 1013 resize_animation_->SetTweenType(SlideAnimation::EASE_OUT); |
| 1001 resize_animation_->Show(); | 1014 resize_animation_->Show(); |
| 1002 return; | 1015 return; |
| 1003 } | 1016 } |
| 1004 } | 1017 } |
| 1005 } | 1018 } |
| 1006 | 1019 |
| 1007 void BrowserActionsContainer::BrowserActionMoved(Extension* extension, | 1020 void BrowserActionsContainer::BrowserActionMoved(Extension* extension, |
| 1008 int index) { | 1021 int index) { |
| 1022 if (!ShouldDisplayBrowserAction(extension)) |
| 1023 return; |
| 1024 |
| 1025 if (profile_->IsOffTheRecord()) |
| 1026 index = model_->OriginalIndexToIncognito(index); |
| 1027 |
| 1009 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); | 1028 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); |
| 1010 | 1029 |
| 1011 DeleteBrowserActionViews(); | 1030 DeleteBrowserActionViews(); |
| 1012 CreateBrowserActionViews(); | 1031 CreateBrowserActionViews(); |
| 1013 Layout(); | 1032 Layout(); |
| 1014 SchedulePaint(); | 1033 SchedulePaint(); |
| 1015 } | 1034 } |
| 1016 | 1035 |
| 1017 int BrowserActionsContainer::WidthOfNonIconArea() const { | 1036 int BrowserActionsContainer::WidthOfNonIconArea() const { |
| 1018 int chevron_size = (chevron_->IsVisible()) ? | 1037 int chevron_size = (chevron_->IsVisible()) ? |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 | 1111 |
| 1093 profile_->GetPrefs()->SetInteger(prefs::kBrowserActionContainerWidth, | 1112 profile_->GetPrefs()->SetInteger(prefs::kBrowserActionContainerWidth, |
| 1094 container_size_.width()); | 1113 container_size_.width()); |
| 1095 } | 1114 } |
| 1096 | 1115 |
| 1097 void BrowserActionsContainer::NotifyMenuDeleted( | 1116 void BrowserActionsContainer::NotifyMenuDeleted( |
| 1098 BrowserActionOverflowMenuController* controller) { | 1117 BrowserActionOverflowMenuController* controller) { |
| 1099 DCHECK(controller == overflow_menu_); | 1118 DCHECK(controller == overflow_menu_); |
| 1100 overflow_menu_ = NULL; | 1119 overflow_menu_ = NULL; |
| 1101 } | 1120 } |
| 1121 |
| 1122 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { |
| 1123 // Only display incognito-enabled extensions while in incognito mode. |
| 1124 return (!profile_->IsOffTheRecord() || |
| 1125 profile_->GetExtensionsService()-> |
| 1126 IsIncognitoEnabled(extension->id())); |
| 1127 } |
| OLD | NEW |