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" |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 334 } |
333 | 335 |
334 void BrowserActionsContainer::OnOverflowedActionWantsToRunChanged( | 336 void BrowserActionsContainer::OnOverflowedActionWantsToRunChanged( |
335 bool overflowed_action_wants_to_run) { | 337 bool overflowed_action_wants_to_run) { |
336 DCHECK(!in_overflow_mode()); | 338 DCHECK(!in_overflow_mode()); |
337 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()-> | 339 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()-> |
338 app_menu()->SetOverflowedToolbarActionWantsToRun( | 340 app_menu()->SetOverflowedToolbarActionWantsToRun( |
339 overflowed_action_wants_to_run); | 341 overflowed_action_wants_to_run); |
340 } | 342 } |
341 | 343 |
| 344 void BrowserActionsContainer::ShowExtensionMessageBubble( |
| 345 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { |
| 346 if (animating()) { |
| 347 // If the container is animating, we can't effectively anchor the bubble, |
| 348 // so wait until animation stops. |
| 349 pending_extension_bubble_controller_ = controller.Pass(); |
| 350 return; |
| 351 } |
| 352 |
| 353 views::View* reference_view = VisibleBrowserActions() > 0 ? |
| 354 static_cast<views::View*>(toolbar_action_views_[0]) : |
| 355 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu(); |
| 356 |
| 357 extensions::ExtensionMessageBubbleController* weak_controller = |
| 358 controller.get(); |
| 359 extensions::ExtensionMessageBubbleView* bubble = |
| 360 new extensions::ExtensionMessageBubbleView( |
| 361 reference_view, |
| 362 views::BubbleBorder::TOP_RIGHT, |
| 363 controller.Pass()); |
| 364 views::BubbleDelegateView::CreateBubble(bubble); |
| 365 weak_controller->Show(bubble); |
| 366 } |
| 367 |
342 void BrowserActionsContainer::AddObserver( | 368 void BrowserActionsContainer::AddObserver( |
343 BrowserActionsContainerObserver* observer) { | 369 BrowserActionsContainerObserver* observer) { |
344 observers_.AddObserver(observer); | 370 observers_.AddObserver(observer); |
345 } | 371 } |
346 | 372 |
347 void BrowserActionsContainer::RemoveObserver( | 373 void BrowserActionsContainer::RemoveObserver( |
348 BrowserActionsContainerObserver* observer) { | 374 BrowserActionsContainerObserver* observer) { |
349 observers_.RemoveObserver(observer); | 375 observers_.RemoveObserver(observer); |
350 } | 376 } |
351 | 377 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 | 687 |
662 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) { | 688 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) { |
663 container_width_ = animation_target_size_; | 689 container_width_ = animation_target_size_; |
664 animation_target_size_ = 0; | 690 animation_target_size_ = 0; |
665 resize_amount_ = 0; | 691 resize_amount_ = 0; |
666 suppress_chevron_ = false; | 692 suppress_chevron_ = false; |
667 Redraw(false); | 693 Redraw(false); |
668 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 694 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
669 observers_, | 695 observers_, |
670 OnBrowserActionsContainerAnimationEnded()); | 696 OnBrowserActionsContainerAnimationEnded()); |
| 697 |
| 698 if (pending_extension_bubble_controller_) |
| 699 ShowExtensionMessageBubble(pending_extension_bubble_controller_.Pass()); |
671 } | 700 } |
672 | 701 |
673 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { | 702 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { |
674 return browser_->tab_strip_model()->GetActiveWebContents(); | 703 return browser_->tab_strip_model()->GetActiveWebContents(); |
675 } | 704 } |
676 | 705 |
677 extensions::ActiveTabPermissionGranter* | 706 extensions::ActiveTabPermissionGranter* |
678 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 707 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
679 content::WebContents* web_contents = GetCurrentWebContents(); | 708 content::WebContents* web_contents = GetCurrentWebContents(); |
680 if (!web_contents) | 709 if (!web_contents) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 | 802 |
774 ui::ThemeProvider* tp = GetThemeProvider(); | 803 ui::ThemeProvider* tp = GetThemeProvider(); |
775 if (tp && chevron_) { | 804 if (tp && chevron_) { |
776 chevron_->SetImage(views::Button::STATE_NORMAL, | 805 chevron_->SetImage(views::Button::STATE_NORMAL, |
777 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 806 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
778 } | 807 } |
779 | 808 |
780 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 809 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
781 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 810 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
782 } | 811 } |
OLD | NEW |