| 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/extension_message_bubble_controller.h" |
| 10 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 10 #include "chrome/browser/extensions/tab_helper.h" | 11 #include "chrome/browser/extensions/tab_helper.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d
elegate.h" | 14 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d
elegate.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 16 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 17 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 17 #include "chrome/browser/ui/view_ids.h" | 18 #include "chrome/browser/ui/view_ids.h" |
| 18 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 19 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 19 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" | 20 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 195 |
| 195 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { | 196 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { |
| 196 // With traditional overflow, the reference is the chevron. With the | 197 // With traditional overflow, the reference is the chevron. With the |
| 197 // redesign, we use the wrench menu instead. | 198 // redesign, we use the wrench menu instead. |
| 198 return chevron_ ? | 199 return chevron_ ? |
| 199 static_cast<views::MenuButton*>(chevron_) : | 200 static_cast<views::MenuButton*>(chevron_) : |
| 200 static_cast<views::MenuButton*>(BrowserView::GetBrowserViewForBrowser( | 201 static_cast<views::MenuButton*>(BrowserView::GetBrowserViewForBrowser( |
| 201 browser_)->toolbar()->app_menu()); | 202 browser_)->toolbar()->app_menu()); |
| 202 } | 203 } |
| 203 | 204 |
| 205 void BrowserActionsContainer::OnMouseEnteredToolbarActionView() { |
| 206 if (!shown_bubble_ && !toolbar_action_views_.empty() && |
| 207 ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( |
| 208 browser_->profile())) { |
| 209 ExtensionToolbarIconSurfacingBubble* bubble = |
| 210 new ExtensionToolbarIconSurfacingBubble( |
| 211 toolbar_action_views_[0], |
| 212 make_scoped_ptr(new ExtensionToolbarIconSurfacingBubbleDelegate( |
| 213 browser_->profile()))); |
| 214 views::BubbleDelegateView::CreateBubble(bubble); |
| 215 bubble->Show(); |
| 216 } |
| 217 shown_bubble_ = true; |
| 218 } |
| 219 |
| 204 void BrowserActionsContainer::AddViewForAction( | 220 void BrowserActionsContainer::AddViewForAction( |
| 205 ToolbarActionViewController* view_controller, | 221 ToolbarActionViewController* view_controller, |
| 206 size_t index) { | 222 size_t index) { |
| 207 if (chevron_) | 223 if (chevron_) |
| 208 chevron_->CloseMenu(); | 224 chevron_->CloseMenu(); |
| 209 | 225 |
| 210 ToolbarActionView* view = | 226 ToolbarActionView* view = |
| 211 new ToolbarActionView(view_controller, browser_->profile(), this); | 227 new ToolbarActionView(view_controller, browser_->profile(), this); |
| 212 toolbar_action_views_.insert(toolbar_action_views_.begin() + index, view); | 228 toolbar_action_views_.insert(toolbar_action_views_.begin() + index, view); |
| 213 AddChildViewAt(view, index); | 229 AddChildViewAt(view, index); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 index_in_row * ToolbarActionsBar::IconWidth(true), | 463 index_in_row * ToolbarActionsBar::IconWidth(true), |
| 448 row_index * ToolbarActionsBar::IconHeight(), | 464 row_index * ToolbarActionsBar::IconHeight(), |
| 449 ToolbarActionsBar::IconWidth(false), | 465 ToolbarActionsBar::IconWidth(false), |
| 450 ToolbarActionsBar::IconHeight()); | 466 ToolbarActionsBar::IconHeight()); |
| 451 view->SetVisible(true); | 467 view->SetVisible(true); |
| 452 } | 468 } |
| 453 } | 469 } |
| 454 } | 470 } |
| 455 | 471 |
| 456 void BrowserActionsContainer::OnMouseEntered(const ui::MouseEvent& event) { | 472 void BrowserActionsContainer::OnMouseEntered(const ui::MouseEvent& event) { |
| 457 if (!shown_bubble_ && !toolbar_action_views_.empty() && | 473 OnMouseEnteredToolbarActionView(); |
| 458 ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( | |
| 459 browser_->profile())) { | |
| 460 ExtensionToolbarIconSurfacingBubble* bubble = | |
| 461 new ExtensionToolbarIconSurfacingBubble( | |
| 462 toolbar_action_views_[0], | |
| 463 make_scoped_ptr(new ExtensionToolbarIconSurfacingBubbleDelegate( | |
| 464 browser_->profile()))); | |
| 465 views::BubbleDelegateView::CreateBubble(bubble); | |
| 466 bubble->Show(); | |
| 467 } | |
| 468 shown_bubble_ = true; | |
| 469 } | 474 } |
| 470 | 475 |
| 471 bool BrowserActionsContainer::GetDropFormats( | 476 bool BrowserActionsContainer::GetDropFormats( |
| 472 int* formats, | 477 int* formats, |
| 473 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 478 std::set<OSExchangeData::CustomFormat>* custom_formats) { |
| 474 return BrowserActionDragData::GetDropFormats(custom_formats); | 479 return BrowserActionDragData::GetDropFormats(custom_formats); |
| 475 } | 480 } |
| 476 | 481 |
| 477 bool BrowserActionsContainer::AreDropTypesRequired() { | 482 bool BrowserActionsContainer::AreDropTypesRequired() { |
| 478 return BrowserActionDragData::AreDropTypesRequired(); | 483 return BrowserActionDragData::AreDropTypesRequired(); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 if (!web_contents) | 697 if (!web_contents) |
| 693 return NULL; | 698 return NULL; |
| 694 return extensions::TabHelper::FromWebContents(web_contents)-> | 699 return extensions::TabHelper::FromWebContents(web_contents)-> |
| 695 active_tab_permission_granter(); | 700 active_tab_permission_granter(); |
| 696 } | 701 } |
| 697 | 702 |
| 698 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 703 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
| 699 // If the views haven't been initialized yet, wait for the next call to | 704 // If the views haven't been initialized yet, wait for the next call to |
| 700 // paint (one will be triggered by entering highlight mode). | 705 // paint (one will be triggered by entering highlight mode). |
| 701 if (toolbar_actions_bar_->is_highlighting() && | 706 if (toolbar_actions_bar_->is_highlighting() && |
| 702 !toolbar_action_views_.empty() && | 707 !toolbar_action_views_.empty() && !in_overflow_mode()) { |
| 703 highlight_painter_) { | 708 extensions::ExtensionToolbarModel::HighlightType highlight_type = |
| 704 views::Painter::PaintPainterAt( | 709 toolbar_actions_bar_->highlight_type(); |
| 705 canvas, highlight_painter_.get(), GetLocalBounds()); | 710 views::Painter* painter = |
| 711 highlight_type == extensions::ExtensionToolbarModel::HIGHLIGHT_INFO |
| 712 ? info_highlight_painter_.get() |
| 713 : warning_highlight_painter_.get(); |
| 714 views::Painter::PaintPainterAt(canvas, painter, GetLocalBounds()); |
| 706 } | 715 } |
| 707 | 716 |
| 708 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while | 717 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while |
| 709 // dragging (like we do for tab dragging). | 718 // dragging (like we do for tab dragging). |
| 710 if (drop_position_.get()) { | 719 if (drop_position_.get()) { |
| 711 // The two-pixel width drop indicator. | 720 // The two-pixel width drop indicator. |
| 712 static const int kDropIndicatorWidth = 2; | 721 static const int kDropIndicatorWidth = 2; |
| 713 | 722 |
| 714 // Convert back to a pixel offset into the container. First find the X | 723 // Convert back to a pixel offset into the container. First find the X |
| 715 // coordinate of the drop icon. | 724 // coordinate of the drop icon. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 void BrowserActionsContainer::LoadImages() { | 785 void BrowserActionsContainer::LoadImages() { |
| 777 if (in_overflow_mode()) | 786 if (in_overflow_mode()) |
| 778 return; // Overflow mode has neither a chevron nor highlighting. | 787 return; // Overflow mode has neither a chevron nor highlighting. |
| 779 | 788 |
| 780 ui::ThemeProvider* tp = GetThemeProvider(); | 789 ui::ThemeProvider* tp = GetThemeProvider(); |
| 781 if (tp && chevron_) { | 790 if (tp && chevron_) { |
| 782 chevron_->SetImage(views::Button::STATE_NORMAL, | 791 chevron_->SetImage(views::Button::STATE_NORMAL, |
| 783 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 792 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
| 784 } | 793 } |
| 785 | 794 |
| 786 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 795 const int kInfoImages[] = IMAGE_GRID(IDR_TOOLBAR_ACTION_HIGHLIGHT); |
| 787 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 796 info_highlight_painter_.reset( |
| 797 views::Painter::CreateImageGridPainter(kInfoImages)); |
| 798 const int kWarningImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
| 799 warning_highlight_painter_.reset( |
| 800 views::Painter::CreateImageGridPainter(kWarningImages)); |
| 788 } | 801 } |
| 789 | 802 |
| 790 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { | 803 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { |
| 791 DCHECK(active_bubble_); | 804 DCHECK(active_bubble_); |
| 792 DCHECK_EQ(active_bubble_->GetWidget(), widget); | 805 DCHECK_EQ(active_bubble_->GetWidget(), widget); |
| 793 widget->RemoveObserver(this); | 806 widget->RemoveObserver(this); |
| 794 active_bubble_ = nullptr; | 807 active_bubble_ = nullptr; |
| 795 } | 808 } |
| OLD | NEW |