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

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

Issue 10533086: Action box menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Action box menu Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
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
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
145 void BrowserActionsContainer::RefreshBrowserActionViews() { 140 void BrowserActionsContainer::RefreshBrowserActionViews() {
146 for (size_t i = 0; i < browser_action_views_.size(); ++i) 141 for (size_t i = 0; i < browser_action_views_.size(); ++i)
147 browser_action_views_[i]->button()->UpdateState(); 142 browser_action_views_[i]->button()->UpdateState();
148 } 143 }
149 144
150 void BrowserActionsContainer::CreateBrowserActionViews() { 145 void BrowserActionsContainer::CreateBrowserActionViews() {
151 DCHECK(browser_action_views_.empty()); 146 DCHECK(browser_action_views_.empty());
152 if (!model_) 147 if (!model_)
153 return; 148 return;
154 149
155 for (extensions::ExtensionList::iterator i(model_->begin()); 150 for (extensions::ExtensionList::iterator i(model_->begin());
156 i != model_->end(); ++i) { 151 i != model_->end(); ++i) {
157 if (!ShouldDisplayBrowserAction(*i)) 152 if (!ShouldDisplayBrowserAction(*i))
158 continue; 153 continue;
159 154
160 BrowserActionView* view = new BrowserActionView(*i, this); 155 BrowserActionView* view = new BrowserActionView(*i, browser_, this);
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
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)) {
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 CloseOverflowMenu(); 594 CloseOverflowMenu();
587 595
588 if (!ShouldDisplayBrowserAction(extension)) 596 if (!ShouldDisplayBrowserAction(extension))
589 return; 597 return;
590 598
591 size_t visible_actions = VisibleBrowserActions(); 599 size_t visible_actions = VisibleBrowserActions();
592 600
593 // Add the new browser action to the vector and the view hierarchy. 601 // Add the new browser action to the vector and the view hierarchy.
594 if (profile_->IsOffTheRecord()) 602 if (profile_->IsOffTheRecord())
595 index = model_->OriginalIndexToIncognito(index); 603 index = model_->OriginalIndexToIncognito(index);
596 BrowserActionView* view = new BrowserActionView(extension, this); 604 BrowserActionView* view = new BrowserActionView(extension, browser_, this);
597 browser_action_views_.insert(browser_action_views_.begin() + index, view); 605 browser_action_views_.insert(browser_action_views_.begin() + index, view);
598 AddChildViewAt(view, index); 606 AddChildViewAt(view, index);
599 607
600 // If we are still initializing the container, don't bother animating. 608 // If we are still initializing the container, don't bother animating.
601 if (!model_->extensions_initialized()) 609 if (!model_->extensions_initialized())
602 return; 610 return;
603 611
604 // Enlarge the container if it was already at maximum size and we're not in 612 // Enlarge the container if it was already at maximum size and we're not in
605 // the middle of upgrading. 613 // the middle of upgrading.
606 if ((model_->GetVisibleIconCount() < 0) && 614 if ((model_->GetVisibleIconCount() < 0) &&
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698