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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 size_t visible_actions = 0; | 520 size_t visible_actions = 0; |
521 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 521 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
522 if (browser_action_views_[i]->visible()) | 522 if (browser_action_views_[i]->visible()) |
523 ++visible_actions; | 523 ++visible_actions; |
524 } | 524 } |
525 return visible_actions; | 525 return visible_actions; |
526 } | 526 } |
527 | 527 |
528 void BrowserActionsContainer::OnBrowserActionExecuted( | 528 void BrowserActionsContainer::OnBrowserActionExecuted( |
529 BrowserActionButton* button) { | 529 BrowserActionButton* button) { |
530 ExtensionAction* browser_action = button->browser_action(); | 530 const Extension* extension = button->extension(); |
531 | 531 GURL popup_url; |
532 // Popups just display. No notification to the extension. | 532 switch (model_->ExecuteBrowserAction(extension, browser_, &popup_url)) { |
533 // TODO(erikkay): should there be? | 533 case ExtensionToolbarModel::ACTION_NONE: |
534 if (!button->IsPopup()) { | 534 break; |
535 model_->ExecuteBrowserAction(browser_action->extension_id(), browser_); | 535 case ExtensionToolbarModel::ACTION_SHOW_POPUP: |
536 return; | 536 ShowPopup(button, popup_url); |
| 537 break; |
537 } | 538 } |
538 | |
539 // If we're showing the same popup, just hide it and return. | |
540 bool same_showing = popup_ && button == popup_button_; | |
541 | |
542 // Always hide the current popup, even if it's not the same. | |
543 // Only one popup should be visible at a time. | |
544 HidePopup(); | |
545 | |
546 if (same_showing) | |
547 return; | |
548 | |
549 // We can get the execute event for browser actions that are not visible, | |
550 // since buttons can be activated from the overflow menu (chevron). In that | |
551 // case we show the popup as originating from the chevron. | |
552 View* reference_view = button->parent()->visible() ? button : chevron_; | |
553 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? | |
554 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | |
555 popup_ = ExtensionPopup::ShowPopup(button->GetPopupUrl(), browser_, | |
556 reference_view, arrow_location); | |
557 popup_->GetWidget()->AddObserver(this); | |
558 popup_button_ = button; | |
559 popup_button_->SetButtonPushed(); | |
560 } | 539 } |
561 | 540 |
562 gfx::Size BrowserActionsContainer::GetPreferredSize() { | 541 gfx::Size BrowserActionsContainer::GetPreferredSize() { |
563 if (browser_action_views_.empty()) | 542 if (browser_action_views_.empty()) |
564 return gfx::Size(ToolbarView::kStandardSpacing, 0); | 543 return gfx::Size(ToolbarView::kStandardSpacing, 0); |
565 | 544 |
566 // We calculate the size of the view by taking the current width and | 545 // We calculate the size of the view by taking the current width and |
567 // subtracting resize_amount_ (the latter represents how far the user is | 546 // subtracting resize_amount_ (the latter represents how far the user is |
568 // resizing the view or, if animating the snapping, how far to animate it). | 547 // resizing the view or, if animating the snapping, how far to animate it). |
569 // But we also clamp it to a minimum size and the maximum size, so that the | 548 // But we also clamp it to a minimum size and the maximum size, so that the |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 } | 1121 } |
1143 } | 1122 } |
1144 | 1123 |
1145 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1124 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
1146 const Extension* extension) { | 1125 const Extension* extension) { |
1147 // Only display incognito-enabled extensions while in incognito mode. | 1126 // Only display incognito-enabled extensions while in incognito mode. |
1148 return | 1127 return |
1149 (!profile_->IsOffTheRecord() || | 1128 (!profile_->IsOffTheRecord() || |
1150 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); | 1129 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); |
1151 } | 1130 } |
| 1131 |
| 1132 void BrowserActionsContainer::ShowPopup(BrowserActionButton* button, |
| 1133 const GURL& popup_url) { |
| 1134 // If we're showing the same popup, just hide it and return. |
| 1135 bool same_showing = popup_ && button == popup_button_; |
| 1136 |
| 1137 // Always hide the current popup, even if it's not the same. |
| 1138 // Only one popup should be visible at a time. |
| 1139 HidePopup(); |
| 1140 |
| 1141 if (same_showing) |
| 1142 return; |
| 1143 |
| 1144 // We can get the execute event for browser actions that are not visible, |
| 1145 // since buttons can be activated from the overflow menu (chevron). In that |
| 1146 // case we show the popup as originating from the chevron. |
| 1147 View* reference_view = button->parent()->visible() ? button : chevron_; |
| 1148 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? |
| 1149 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
| 1150 popup_ = ExtensionPopup::ShowPopup(popup_url, |
| 1151 browser_, |
| 1152 reference_view, |
| 1153 arrow_location); |
| 1154 popup_->GetWidget()->AddObserver(this); |
| 1155 popup_button_ = button; |
| 1156 popup_button_->SetButtonPushed(); |
| 1157 } |
OLD | NEW |