OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
9 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 14 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
14 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
15 #include "chrome/browser/ui/view_ids.h" | 16 #include "chrome/browser/ui/view_ids.h" |
16 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 17 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 18 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" |
17 #include "chrome/browser/ui/views/extensions/extension_toolbar_icon_surfacing_bu
bble_views.h" | 19 #include "chrome/browser/ui/views/extensions/extension_toolbar_icon_surfacing_bu
bble_views.h" |
18 #include "chrome/browser/ui/views/frame/browser_view.h" | 20 #include "chrome/browser/ui/views/frame/browser_view.h" |
19 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" | 21 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" |
20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
21 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" | 23 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" |
22 #include "chrome/common/extensions/command.h" | 24 #include "chrome/common/extensions/command.h" |
23 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
24 #include "extensions/common/feature_switch.h" | 26 #include "extensions/common/feature_switch.h" |
25 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
26 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
27 #include "ui/accessibility/ax_view_state.h" | 29 #include "ui/accessibility/ax_view_state.h" |
28 #include "ui/base/dragdrop/drag_utils.h" | 30 #include "ui/base/dragdrop/drag_utils.h" |
29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/base/nine_image_painter_factory.h" | 32 #include "ui/base/nine_image_painter_factory.h" |
31 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
32 #include "ui/base/theme_provider.h" | 34 #include "ui/base/theme_provider.h" |
33 #include "ui/gfx/canvas.h" | 35 #include "ui/gfx/canvas.h" |
34 #include "ui/gfx/geometry/rect.h" | 36 #include "ui/gfx/geometry/rect.h" |
35 #include "ui/resources/grit/ui_resources.h" | 37 #include "ui/resources/grit/ui_resources.h" |
| 38 #include "ui/views/bubble/bubble_delegate.h" |
36 #include "ui/views/controls/resize_area.h" | 39 #include "ui/views/controls/resize_area.h" |
37 #include "ui/views/painter.h" | 40 #include "ui/views/painter.h" |
38 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
39 | 42 |
40 namespace { | 43 namespace { |
41 | 44 |
42 // Horizontal spacing before the chevron (if visible). | 45 // Horizontal spacing before the chevron (if visible). |
43 const int kChevronSpacing = ToolbarView::kStandardSpacing - 2; | 46 const int kChevronSpacing = ToolbarView::kStandardSpacing - 2; |
44 | 47 |
45 } // namespace | 48 } // namespace |
(...skipping 30 matching lines...) Expand all Loading... |
76 browser_(browser), | 79 browser_(browser), |
77 main_container_(main_container), | 80 main_container_(main_container), |
78 popup_owner_(NULL), | 81 popup_owner_(NULL), |
79 container_width_(0), | 82 container_width_(0), |
80 resize_area_(NULL), | 83 resize_area_(NULL), |
81 chevron_(NULL), | 84 chevron_(NULL), |
82 suppress_chevron_(false), | 85 suppress_chevron_(false), |
83 added_to_view_(false), | 86 added_to_view_(false), |
84 shown_bubble_(false), | 87 shown_bubble_(false), |
85 resize_amount_(0), | 88 resize_amount_(0), |
86 animation_target_size_(0) { | 89 animation_target_size_(0), |
| 90 active_bubble_(nullptr) { |
87 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 91 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
88 | 92 |
89 bool overflow_experiment = | 93 bool overflow_experiment = |
90 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); | 94 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); |
91 DCHECK(!in_overflow_mode() || overflow_experiment); | 95 DCHECK(!in_overflow_mode() || overflow_experiment); |
92 | 96 |
93 if (!in_overflow_mode()) { | 97 if (!in_overflow_mode()) { |
94 resize_animation_.reset(new gfx::SlideAnimation(this)); | 98 resize_animation_.reset(new gfx::SlideAnimation(this)); |
95 resize_area_ = new views::ResizeArea(this); | 99 resize_area_ = new views::ResizeArea(this); |
96 AddChildView(resize_area_); | 100 AddChildView(resize_area_); |
97 | 101 |
98 // 'Main' mode doesn't need a chevron overflow when overflow is shown inside | 102 // 'Main' mode doesn't need a chevron overflow when overflow is shown inside |
99 // the Chrome menu. | 103 // the Chrome menu. |
100 if (!overflow_experiment) { | 104 if (!overflow_experiment) { |
101 // Since the ChevronMenuButton holds a raw pointer to us, we need to | 105 // Since the ChevronMenuButton holds a raw pointer to us, we need to |
102 // ensure it doesn't outlive us. Having it owned by the view hierarchy as | 106 // ensure it doesn't outlive us. Having it owned by the view hierarchy as |
103 // a child will suffice. | 107 // a child will suffice. |
104 chevron_ = new ChevronMenuButton(this); | 108 chevron_ = new ChevronMenuButton(this); |
105 chevron_->EnableCanvasFlippingForRTLUI(true); | 109 chevron_->EnableCanvasFlippingForRTLUI(true); |
106 chevron_->SetAccessibleName( | 110 chevron_->SetAccessibleName( |
107 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | 111 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); |
108 chevron_->SetVisible(false); | 112 chevron_->SetVisible(false); |
109 AddChildView(chevron_); | 113 AddChildView(chevron_); |
110 } | 114 } |
111 } | 115 } |
112 } | 116 } |
113 | 117 |
114 BrowserActionsContainer::~BrowserActionsContainer() { | 118 BrowserActionsContainer::~BrowserActionsContainer() { |
| 119 if (active_bubble_) |
| 120 active_bubble_->GetWidget()->Close(); |
| 121 // We should synchronously receive the OnWidgetClosing() event, so we should |
| 122 // always have cleared the active bubble by now. |
| 123 DCHECK(!active_bubble_); |
| 124 |
115 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 125 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
116 observers_, | 126 observers_, |
117 OnBrowserActionsContainerDestroyed()); | 127 OnBrowserActionsContainerDestroyed()); |
118 | 128 |
119 toolbar_actions_bar_->DeleteActions(); | 129 toolbar_actions_bar_->DeleteActions(); |
120 // All views should be removed as part of ToolbarActionsBar::DeleteActions(). | 130 // All views should be removed as part of ToolbarActionsBar::DeleteActions(). |
121 DCHECK(toolbar_action_views_.empty()); | 131 DCHECK(toolbar_action_views_.empty()); |
122 } | 132 } |
123 | 133 |
124 void BrowserActionsContainer::Init() { | 134 void BrowserActionsContainer::Init() { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 342 } |
333 | 343 |
334 void BrowserActionsContainer::OnOverflowedActionWantsToRunChanged( | 344 void BrowserActionsContainer::OnOverflowedActionWantsToRunChanged( |
335 bool overflowed_action_wants_to_run) { | 345 bool overflowed_action_wants_to_run) { |
336 DCHECK(!in_overflow_mode()); | 346 DCHECK(!in_overflow_mode()); |
337 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()-> | 347 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()-> |
338 app_menu()->SetOverflowedToolbarActionWantsToRun( | 348 app_menu()->SetOverflowedToolbarActionWantsToRun( |
339 overflowed_action_wants_to_run); | 349 overflowed_action_wants_to_run); |
340 } | 350 } |
341 | 351 |
| 352 void BrowserActionsContainer::ShowExtensionMessageBubble( |
| 353 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { |
| 354 if (animating()) { |
| 355 // Similarly, if the container is animating, we can't effectively anchor the |
| 356 // bubble, so wait until animation stops. |
| 357 pending_extension_bubble_controller_ = controller.Pass(); |
| 358 return; |
| 359 } |
| 360 |
| 361 views::View* reference_view = VisibleBrowserActions() > 0 ? |
| 362 static_cast<views::View*>(toolbar_action_views_[0]) : |
| 363 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu(); |
| 364 |
| 365 extensions::ExtensionMessageBubbleController* weak_controller = |
| 366 controller.get(); |
| 367 extensions::ExtensionMessageBubbleView* bubble = |
| 368 new extensions::ExtensionMessageBubbleView( |
| 369 reference_view, |
| 370 views::BubbleBorder::TOP_RIGHT, |
| 371 controller.Pass()); |
| 372 views::BubbleDelegateView::CreateBubble(bubble); |
| 373 active_bubble_ = bubble; |
| 374 active_bubble_->GetWidget()->AddObserver(this); |
| 375 weak_controller->Show(bubble); |
| 376 } |
| 377 |
| 378 void BrowserActionsContainer::OnWidgetClosing(views::Widget* widget) { |
| 379 ClearActiveBubble(widget); |
| 380 } |
| 381 |
| 382 void BrowserActionsContainer::OnWidgetDestroying(views::Widget* widget) { |
| 383 ClearActiveBubble(widget); |
| 384 } |
| 385 |
342 void BrowserActionsContainer::AddObserver( | 386 void BrowserActionsContainer::AddObserver( |
343 BrowserActionsContainerObserver* observer) { | 387 BrowserActionsContainerObserver* observer) { |
344 observers_.AddObserver(observer); | 388 observers_.AddObserver(observer); |
345 } | 389 } |
346 | 390 |
347 void BrowserActionsContainer::RemoveObserver( | 391 void BrowserActionsContainer::RemoveObserver( |
348 BrowserActionsContainerObserver* observer) { | 392 BrowserActionsContainerObserver* observer) { |
349 observers_.RemoveObserver(observer); | 393 observers_.RemoveObserver(observer); |
350 } | 394 } |
351 | 395 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 | 705 |
662 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) { | 706 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) { |
663 container_width_ = animation_target_size_; | 707 container_width_ = animation_target_size_; |
664 animation_target_size_ = 0; | 708 animation_target_size_ = 0; |
665 resize_amount_ = 0; | 709 resize_amount_ = 0; |
666 suppress_chevron_ = false; | 710 suppress_chevron_ = false; |
667 Redraw(false); | 711 Redraw(false); |
668 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 712 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
669 observers_, | 713 observers_, |
670 OnBrowserActionsContainerAnimationEnded()); | 714 OnBrowserActionsContainerAnimationEnded()); |
| 715 |
| 716 if (pending_extension_bubble_controller_) |
| 717 ShowExtensionMessageBubble(pending_extension_bubble_controller_.Pass()); |
671 } | 718 } |
672 | 719 |
673 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { | 720 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { |
674 return browser_->tab_strip_model()->GetActiveWebContents(); | 721 return browser_->tab_strip_model()->GetActiveWebContents(); |
675 } | 722 } |
676 | 723 |
677 extensions::ActiveTabPermissionGranter* | 724 extensions::ActiveTabPermissionGranter* |
678 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 725 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
679 content::WebContents* web_contents = GetCurrentWebContents(); | 726 content::WebContents* web_contents = GetCurrentWebContents(); |
680 if (!web_contents) | 727 if (!web_contents) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 | 820 |
774 ui::ThemeProvider* tp = GetThemeProvider(); | 821 ui::ThemeProvider* tp = GetThemeProvider(); |
775 if (tp && chevron_) { | 822 if (tp && chevron_) { |
776 chevron_->SetImage(views::Button::STATE_NORMAL, | 823 chevron_->SetImage(views::Button::STATE_NORMAL, |
777 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 824 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
778 } | 825 } |
779 | 826 |
780 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 827 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
781 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 828 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
782 } | 829 } |
| 830 |
| 831 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { |
| 832 DCHECK(active_bubble_); |
| 833 DCHECK_EQ(active_bubble_->GetWidget(), widget); |
| 834 widget->RemoveObserver(this); |
| 835 active_bubble_ = nullptr; |
| 836 } |
OLD | NEW |