| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/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_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // Horizontal spacing between most items in the container, as well as after the | 43 // Horizontal spacing between most items in the container, as well as after the |
| 44 // last item or chevron (if visible). | 44 // last item or chevron (if visible). |
| 45 const int kItemSpacing = ToolbarView::kStandardSpacing; | 45 const int kItemSpacing = ToolbarView::kStandardSpacing; |
| 46 | 46 |
| 47 // Horizontal spacing before the chevron (if visible). | 47 // Horizontal spacing before the chevron (if visible). |
| 48 const int kChevronSpacing = kItemSpacing - 2; | 48 const int kChevronSpacing = kItemSpacing - 2; |
| 49 | 49 |
| 50 void RegisterUserPrefs(PrefRegistrySyncable* registry) { | |
| 51 registry->RegisterIntegerPref(prefs::kBrowserActionContainerWidth, | |
| 52 0, | |
| 53 PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 54 } | |
| 55 | |
| 56 } // namespace | 50 } // namespace |
| 57 | 51 |
| 58 // static | 52 // static |
| 59 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 53 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
| 60 | 54 |
| 61 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
| 62 // BrowserActionsContainer | 56 // BrowserActionsContainer |
| 63 | 57 |
| 58 // static |
| 59 void BrowserActionsContainer::RegisterUserPrefs( |
| 60 PrefRegistrySyncable* registry) { |
| 61 registry->RegisterIntegerPref(prefs::kBrowserActionContainerWidth, |
| 62 0, |
| 63 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 64 } |
| 65 |
| 64 BrowserActionsContainer::BrowserActionsContainer(Browser* browser, | 66 BrowserActionsContainer::BrowserActionsContainer(Browser* browser, |
| 65 View* owner_view) | 67 View* owner_view) |
| 66 : profile_(browser->profile()), | 68 : profile_(browser->profile()), |
| 67 browser_(browser), | 69 browser_(browser), |
| 68 owner_view_(owner_view), | 70 owner_view_(owner_view), |
| 69 popup_(NULL), | 71 popup_(NULL), |
| 70 popup_button_(NULL), | 72 popup_button_(NULL), |
| 71 model_(NULL), | 73 model_(NULL), |
| 72 container_width_(0), | 74 container_width_(0), |
| 73 chevron_(NULL), | 75 chevron_(NULL), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 StopShowFolderDropMenuTimer(); | 114 StopShowFolderDropMenuTimer(); |
| 113 if (popup_) | 115 if (popup_) |
| 114 popup_->GetWidget()->RemoveObserver(this); | 116 popup_->GetWidget()->RemoveObserver(this); |
| 115 HidePopup(); | 117 HidePopup(); |
| 116 DeleteBrowserActionViews(); | 118 DeleteBrowserActionViews(); |
| 117 } | 119 } |
| 118 | 120 |
| 119 void BrowserActionsContainer::Init() { | 121 void BrowserActionsContainer::Init() { |
| 120 LoadImages(); | 122 LoadImages(); |
| 121 | 123 |
| 122 // TODO(joi): Switch to official way of registering user prefs for | |
| 123 // this class, i.e. in a function called from | |
| 124 // browser_prefs::RegisterUserPrefs. | |
| 125 if (!profile_->GetPrefs()->FindPreference( | |
| 126 prefs::kBrowserActionContainerWidth)) | |
| 127 RegisterUserPrefs(static_cast<PrefRegistrySyncable*>( | |
| 128 profile_->GetPrefs()->DeprecatedGetPrefRegistry())); | |
| 129 | |
| 130 // We wait to set the container width until now so that the chevron images | 124 // We wait to set the container width until now so that the chevron images |
| 131 // will be loaded. The width calculation needs to know the chevron size. | 125 // will be loaded. The width calculation needs to know the chevron size. |
| 132 if (model_ && | 126 if (model_ && |
| 133 !profile_->GetPrefs()->HasPrefPath(prefs::kExtensionToolbarSize)) { | 127 !profile_->GetPrefs()->HasPrefPath(prefs::kExtensionToolbarSize)) { |
| 134 // Migration code to the new VisibleIconCount pref. | 128 // Migration code to the new VisibleIconCount pref. |
| 135 // TODO(mpcomplete): remove this after users are upgraded to 5.0. | 129 // TODO(mpcomplete): remove this after users are upgraded to 5.0. |
| 136 int predefined_width = | 130 int predefined_width = |
| 137 profile_->GetPrefs()->GetInteger(prefs::kBrowserActionContainerWidth); | 131 profile_->GetPrefs()->GetInteger(prefs::kBrowserActionContainerWidth); |
| 138 if (predefined_width != 0) | 132 if (predefined_width != 0) |
| 139 model_->SetVisibleIconCount(WidthToIconCount(predefined_width)); | 133 model_->SetVisibleIconCount(WidthToIconCount(predefined_width)); |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 848 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
| 855 popup_ = ExtensionPopup::ShowPopup(popup_url, | 849 popup_ = ExtensionPopup::ShowPopup(popup_url, |
| 856 browser_, | 850 browser_, |
| 857 reference_view, | 851 reference_view, |
| 858 arrow_location, | 852 arrow_location, |
| 859 show_action); | 853 show_action); |
| 860 popup_->GetWidget()->AddObserver(this); | 854 popup_->GetWidget()->AddObserver(this); |
| 861 popup_button_ = button; | 855 popup_button_ = button; |
| 862 popup_button_->SetButtonPushed(); | 856 popup_button_->SetButtonPushed(); |
| 863 } | 857 } |
| OLD | NEW |