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/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 // TODO(mpcomplete): remove this after users are upgraded to 5.0. | 120 // TODO(mpcomplete): remove this after users are upgraded to 5.0. |
121 int predefined_width = | 121 int predefined_width = |
122 profile_->GetPrefs()->GetInteger(prefs::kBrowserActionContainerWidth); | 122 profile_->GetPrefs()->GetInteger(prefs::kBrowserActionContainerWidth); |
123 if (predefined_width != 0) | 123 if (predefined_width != 0) |
124 model_->SetVisibleIconCount(WidthToIconCount(predefined_width)); | 124 model_->SetVisibleIconCount(WidthToIconCount(predefined_width)); |
125 } | 125 } |
126 if (model_ && model_->extensions_initialized()) | 126 if (model_ && model_->extensions_initialized()) |
127 SetContainerWidth(); | 127 SetContainerWidth(); |
128 } | 128 } |
129 | 129 |
130 int BrowserActionsContainer::GetCurrentTabId() const { | |
131 TabContents* tab = chrome::GetActiveTabContents(browser_); | |
132 return tab ? tab->restore_tab_helper()->session_id().id() : -1; | |
133 } | |
134 | |
135 BrowserActionView* BrowserActionsContainer::GetBrowserActionView( | 130 BrowserActionView* BrowserActionsContainer::GetBrowserActionView( |
136 ExtensionAction* action) { | 131 ExtensionAction* action) { |
137 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 132 for (BrowserActionViews::iterator i(browser_action_views_.begin()); |
138 i != browser_action_views_.end(); ++i) { | 133 i != browser_action_views_.end(); ++i) { |
139 if ((*i)->button()->browser_action() == action) | 134 if ((*i)->button()->browser_action() == action) |
140 return *i; | 135 return *i; |
141 } | 136 } |
142 return NULL; | 137 return NULL; |
143 } | 138 } |
144 | 139 |
(...skipping 16 matching lines...) Expand all Loading... | |
161 browser_action_views_.push_back(view); | 156 browser_action_views_.push_back(view); |
162 AddChildView(view); | 157 AddChildView(view); |
163 } | 158 } |
164 } | 159 } |
165 | 160 |
166 void BrowserActionsContainer::DeleteBrowserActionViews() { | 161 void BrowserActionsContainer::DeleteBrowserActionViews() { |
167 HidePopup(); | 162 HidePopup(); |
168 STLDeleteElements(&browser_action_views_); | 163 STLDeleteElements(&browser_action_views_); |
169 } | 164 } |
170 | 165 |
171 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | |
172 SetVisible(!browser_action_views_.empty()); | |
173 owner_view_->Layout(); | |
174 owner_view_->SchedulePaint(); | |
175 } | |
176 | |
177 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 166 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
178 size_t visible_actions = 0; | 167 size_t visible_actions = 0; |
179 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 168 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
180 if (browser_action_views_[i]->visible()) | 169 if (browser_action_views_[i]->visible()) |
181 ++visible_actions; | 170 ++visible_actions; |
182 } | 171 } |
183 return visible_actions; | 172 return visible_actions; |
184 } | 173 } |
185 | 174 |
186 void BrowserActionsContainer::OnBrowserActionExecuted( | |
187 BrowserActionButton* button) { | |
188 const Extension* extension = button->extension(); | |
189 GURL popup_url; | |
190 switch (model_->ExecuteBrowserAction(extension, browser_, &popup_url)) { | |
191 case ExtensionToolbarModel::ACTION_NONE: | |
192 break; | |
193 case ExtensionToolbarModel::ACTION_SHOW_POPUP: | |
194 ShowPopup(button, popup_url); | |
195 break; | |
196 } | |
197 } | |
198 | |
199 gfx::Size BrowserActionsContainer::GetPreferredSize() { | 175 gfx::Size BrowserActionsContainer::GetPreferredSize() { |
200 if (browser_action_views_.empty()) | 176 if (browser_action_views_.empty()) |
201 return gfx::Size(ToolbarView::kStandardSpacing, 0); | 177 return gfx::Size(ToolbarView::kStandardSpacing, 0); |
202 | 178 |
203 // We calculate the size of the view by taking the current width and | 179 // We calculate the size of the view by taking the current width and |
204 // subtracting resize_amount_ (the latter represents how far the user is | 180 // subtracting resize_amount_ (the latter represents how far the user is |
205 // resizing the view or, if animating the snapping, how far to animate it). | 181 // resizing the view or, if animating the snapping, how far to animate it). |
206 // But we also clamp it to a minimum size and the maximum size, so that the | 182 // But we also clamp it to a minimum size and the maximum size, so that the |
207 // container can never shrink too far or take up more space than it needs. In | 183 // container can never shrink too far or take up more space than it needs. In |
208 // other words: ContainerMinSize() < width() - resize < ClampTo(MAX). | 184 // other words: ContainerMinSize() < width() - resize < ClampTo(MAX). |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 DCHECK_EQ(popup_->GetWidget(), widget); | 446 DCHECK_EQ(popup_->GetWidget(), widget); |
471 popup_->GetWidget()->RemoveObserver(this); | 447 popup_->GetWidget()->RemoveObserver(this); |
472 popup_ = NULL; | 448 popup_ = NULL; |
473 // |popup_button_| is NULL if the extension has been removed. | 449 // |popup_button_| is NULL if the extension has been removed. |
474 if (popup_button_) { | 450 if (popup_button_) { |
475 popup_button_->SetButtonNotPushed(); | 451 popup_button_->SetButtonNotPushed(); |
476 popup_button_ = NULL; | 452 popup_button_ = NULL; |
477 } | 453 } |
478 } | 454 } |
479 | 455 |
456 Browser* BrowserActionsContainer::GetBrowser() const { | |
457 return browser_; | |
458 } | |
459 | |
460 int BrowserActionsContainer::GetCurrentTabId() const { | |
461 TabContents* tab = chrome::GetActiveTabContents(browser_); | |
462 return tab ? tab->restore_tab_helper()->session_id().id() : -1; | |
463 } | |
464 | |
465 void BrowserActionsContainer::OnBrowserActionExecuted( | |
466 BrowserActionButton* button) { | |
467 const Extension* extension = button->extension(); | |
468 GURL popup_url; | |
469 switch (model_->ExecuteBrowserAction(extension, browser_, &popup_url)) { | |
Peter Kasting
2012/07/18 01:37:25
Nit: Why not just:
if (model_->ExecuteBrowserAc
yefimt
2012/07/18 23:18:13
I just moved this function to match h file order,
Peter Kasting
2012/07/19 04:27:31
Consider this a suggestion to go ahead and change
yefimt
2012/07/19 20:00:15
Done.
| |
470 case ExtensionToolbarModel::ACTION_NONE: | |
471 break; | |
472 case ExtensionToolbarModel::ACTION_SHOW_POPUP: | |
473 ShowPopup(button, popup_url); | |
474 break; | |
475 } | |
476 } | |
477 | |
478 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | |
479 SetVisible(!browser_action_views_.empty()); | |
480 owner_view_->Layout(); | |
481 owner_view_->SchedulePaint(); | |
482 } | |
483 | |
484 gfx::Size BrowserActionsContainer::GetViewContentOffset() const { | |
485 return gfx::Size(0, ToolbarView::kVertSpacing); | |
486 } | |
487 | |
480 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, | 488 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, |
481 size_t new_index) { | 489 size_t new_index) { |
482 ExtensionService* service = profile_->GetExtensionService(); | 490 ExtensionService* service = profile_->GetExtensionService(); |
483 if (service) { | 491 if (service) { |
484 const Extension* extension = service->GetExtensionById(extension_id, false); | 492 const Extension* extension = service->GetExtensionById(extension_id, false); |
485 model_->MoveBrowserAction(extension, new_index); | 493 model_->MoveBrowserAction(extension, new_index); |
486 SchedulePaint(); | 494 SchedulePaint(); |
487 } | 495 } |
488 } | 496 } |
489 | 497 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
806 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? | 814 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? |
807 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 815 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
808 popup_ = ExtensionPopup::ShowPopup(popup_url, | 816 popup_ = ExtensionPopup::ShowPopup(popup_url, |
809 browser_, | 817 browser_, |
810 reference_view, | 818 reference_view, |
811 arrow_location); | 819 arrow_location); |
812 popup_->GetWidget()->AddObserver(this); | 820 popup_->GetWidget()->AddObserver(this); |
813 popup_button_ = button; | 821 popup_button_ = button; |
814 popup_button_->SetButtonPushed(); | 822 popup_button_->SetButtonPushed(); |
815 } | 823 } |
OLD | NEW |