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/l10n_util.h" | 7 #include "app/l10n_util.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" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/browser_window.h" | 13 #include "chrome/browser/browser_window.h" |
14 #include "chrome/browser/extensions/extension_browser_event_router.h" | 14 #include "chrome/browser/extensions/extension_browser_event_router.h" |
15 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
16 #include "chrome/browser/extensions/extension_tabs_module.h" | 16 #include "chrome/browser/extensions/extension_tabs_module.h" |
17 #include "chrome/browser/extensions/extensions_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/renderer_host/render_view_host.h" | 19 #include "chrome/browser/renderer_host/render_view_host.h" |
20 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 20 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
21 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
22 #include "chrome/browser/themes/browser_theme_provider.h" | 22 #include "chrome/browser/themes/browser_theme_provider.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/view_ids.h" | 24 #include "chrome/browser/ui/view_ids.h" |
25 #include "chrome/browser/ui/views/detachable_toolbar_view.h" | 25 #include "chrome/browser/ui/views/detachable_toolbar_view.h" |
26 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 26 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
27 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 27 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 chevron_(NULL), | 354 chevron_(NULL), |
355 overflow_menu_(NULL), | 355 overflow_menu_(NULL), |
356 suppress_chevron_(false), | 356 suppress_chevron_(false), |
357 resize_amount_(0), | 357 resize_amount_(0), |
358 animation_target_size_(0), | 358 animation_target_size_(0), |
359 drop_indicator_position_(-1), | 359 drop_indicator_position_(-1), |
360 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), | 360 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), |
361 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { | 361 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { |
362 SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 362 SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
363 | 363 |
364 if (profile_->GetExtensionsService()) { | 364 if (profile_->GetExtensionService()) { |
365 model_ = profile_->GetExtensionsService()->toolbar_model(); | 365 model_ = profile_->GetExtensionService()->toolbar_model(); |
366 model_->AddObserver(this); | 366 model_->AddObserver(this); |
367 } | 367 } |
368 | 368 |
369 resize_animation_.reset(new SlideAnimation(this)); | 369 resize_animation_.reset(new SlideAnimation(this)); |
370 resize_area_ = new views::ResizeArea(this); | 370 resize_area_ = new views::ResizeArea(this); |
371 resize_area_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_SEPARATOR)); | 371 resize_area_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_SEPARATOR)); |
372 AddChildView(resize_area_); | 372 AddChildView(resize_area_); |
373 | 373 |
374 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false); | 374 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false); |
375 chevron_->set_border(NULL); | 375 chevron_->set_border(NULL); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 void BrowserActionsContainer::ExtensionPopupIsClosing(ExtensionPopup* popup) { | 829 void BrowserActionsContainer::ExtensionPopupIsClosing(ExtensionPopup* popup) { |
830 // ExtensionPopup is ref-counted, so we don't need to delete it. | 830 // ExtensionPopup is ref-counted, so we don't need to delete it. |
831 DCHECK_EQ(popup_, popup); | 831 DCHECK_EQ(popup_, popup); |
832 popup_ = NULL; | 832 popup_ = NULL; |
833 popup_button_->SetButtonNotPushed(); | 833 popup_button_->SetButtonNotPushed(); |
834 popup_button_ = NULL; | 834 popup_button_ = NULL; |
835 } | 835 } |
836 | 836 |
837 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, | 837 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, |
838 size_t new_index) { | 838 size_t new_index) { |
839 ExtensionsService* service = profile_->GetExtensionsService(); | 839 ExtensionService* service = profile_->GetExtensionService(); |
840 if (service) { | 840 if (service) { |
841 const Extension* extension = service->GetExtensionById(extension_id, false); | 841 const Extension* extension = service->GetExtensionById(extension_id, false); |
842 model_->MoveBrowserAction(extension, new_index); | 842 model_->MoveBrowserAction(extension, new_index); |
843 SchedulePaint(); | 843 SchedulePaint(); |
844 } | 844 } |
845 } | 845 } |
846 | 846 |
847 void BrowserActionsContainer::HidePopup() { | 847 void BrowserActionsContainer::HidePopup() { |
848 if (popup_) | 848 if (popup_) |
849 popup_->Close(); | 849 popup_->Close(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 browser_action_views_.insert(browser_action_views_.begin() + index, view); | 909 browser_action_views_.insert(browser_action_views_.begin() + index, view); |
910 AddChildView(index, view); | 910 AddChildView(index, view); |
911 | 911 |
912 // If we are still initializing the container, don't bother animating. | 912 // If we are still initializing the container, don't bother animating. |
913 if (!model_->extensions_initialized()) | 913 if (!model_->extensions_initialized()) |
914 return; | 914 return; |
915 | 915 |
916 // Enlarge the container if it was already at maximum size and we're not in | 916 // Enlarge the container if it was already at maximum size and we're not in |
917 // the middle of upgrading. | 917 // the middle of upgrading. |
918 if ((model_->GetVisibleIconCount() < 0) && | 918 if ((model_->GetVisibleIconCount() < 0) && |
919 !profile_->GetExtensionsService()->IsBeingUpgraded(extension)) { | 919 !profile_->GetExtensionService()->IsBeingUpgraded(extension)) { |
920 suppress_chevron_ = true; | 920 suppress_chevron_ = true; |
921 SaveDesiredSizeAndAnimate(Tween::LINEAR, visible_actions + 1); | 921 SaveDesiredSizeAndAnimate(Tween::LINEAR, visible_actions + 1); |
922 } else { | 922 } else { |
923 // Just redraw the (possibly modified) visible icon set. | 923 // Just redraw the (possibly modified) visible icon set. |
924 OnBrowserActionVisibilityChanged(); | 924 OnBrowserActionVisibilityChanged(); |
925 } | 925 } |
926 } | 926 } |
927 | 927 |
928 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { | 928 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { |
929 CloseOverflowMenu(); | 929 CloseOverflowMenu(); |
930 | 930 |
931 if (popup_ && popup_->host()->extension() == extension) | 931 if (popup_ && popup_->host()->extension() == extension) |
932 HidePopup(); | 932 HidePopup(); |
933 | 933 |
934 size_t visible_actions = VisibleBrowserActions(); | 934 size_t visible_actions = VisibleBrowserActions(); |
935 for (BrowserActionViews::iterator iter = browser_action_views_.begin(); | 935 for (BrowserActionViews::iterator iter = browser_action_views_.begin(); |
936 iter != browser_action_views_.end(); ++iter) { | 936 iter != browser_action_views_.end(); ++iter) { |
937 if ((*iter)->button()->extension() == extension) { | 937 if ((*iter)->button()->extension() == extension) { |
938 RemoveChildView(*iter); | 938 RemoveChildView(*iter); |
939 delete *iter; | 939 delete *iter; |
940 browser_action_views_.erase(iter); | 940 browser_action_views_.erase(iter); |
941 | 941 |
942 // If the extension is being upgraded we don't want the bar to shrink | 942 // If the extension is being upgraded we don't want the bar to shrink |
943 // because the icon is just going to get re-added to the same location. | 943 // because the icon is just going to get re-added to the same location. |
944 if (profile_->GetExtensionsService()->IsBeingUpgraded(extension)) | 944 if (profile_->GetExtensionService()->IsBeingUpgraded(extension)) |
945 return; | 945 return; |
946 | 946 |
947 if (browser_action_views_.size() > visible_actions) { | 947 if (browser_action_views_.size() > visible_actions) { |
948 // If we have more icons than we can show, then we must not be changing | 948 // If we have more icons than we can show, then we must not be changing |
949 // the container size (since we either removed an icon from the main | 949 // the container size (since we either removed an icon from the main |
950 // area and one from the overflow list will have shifted in, or we | 950 // area and one from the overflow list will have shifted in, or we |
951 // removed an entry directly from the overflow list). | 951 // removed an entry directly from the overflow list). |
952 OnBrowserActionVisibilityChanged(); | 952 OnBrowserActionVisibilityChanged(); |
953 } else { | 953 } else { |
954 // Either we went from overflow to no-overflow, or we shrunk the no- | 954 // Either we went from overflow to no-overflow, or we shrunk the no- |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 } else { | 1089 } else { |
1090 animation_target_size_ = target_size; | 1090 animation_target_size_ = target_size; |
1091 AnimationEnded(resize_animation_.get()); | 1091 AnimationEnded(resize_animation_.get()); |
1092 } | 1092 } |
1093 } | 1093 } |
1094 | 1094 |
1095 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1095 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
1096 const Extension* extension) { | 1096 const Extension* extension) { |
1097 // Only display incognito-enabled extensions while in incognito mode. | 1097 // Only display incognito-enabled extensions while in incognito mode. |
1098 return (!profile_->IsOffTheRecord() || | 1098 return (!profile_->IsOffTheRecord() || |
1099 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); | 1099 profile_->GetExtensionService()->IsIncognitoEnabled(extension)); |
1100 } | 1100 } |
OLD | NEW |