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