| 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/toolbar_action_view.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sessions/session_tab_helper.h" | 11 #include "chrome/browser/sessions/session_tab_helper.h" |
| 12 #include "chrome/browser/themes/theme_service.h" | 12 #include "chrome/browser/themes/theme_service.h" |
| 13 #include "chrome/browser/themes/theme_service_factory.h" | 13 #include "chrome/browser/themes/theme_service_factory.h" |
| 14 #include "chrome/browser/ui/browser.h" | |
| 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 14 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 17 #include "chrome/browser/ui/view_ids.h" | 16 #include "chrome/browser/ui/view_ids.h" |
| 18 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 19 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | |
| 20 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" | |
| 21 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 18 #include "content/public/browser/notification_source.h" |
| 22 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 23 #include "ui/accessibility/ax_view_state.h" | 20 #include "ui/accessibility/ax_view_state.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 26 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
| 27 #include "ui/gfx/image/image_skia_operations.h" | 24 #include "ui/gfx/image/image_skia_operations.h" |
| 28 #include "ui/gfx/image/image_skia_source.h" | 25 #include "ui/gfx/image/image_skia_source.h" |
| 29 #include "ui/resources/grit/ui_resources.h" | 26 #include "ui/resources/grit/ui_resources.h" |
| 30 #include "ui/views/controls/button/label_button_border.h" | 27 #include "ui/views/controls/button/label_button_border.h" |
| 31 | 28 |
| 32 using views::LabelButtonBorder; | 29 using views::LabelButtonBorder; |
| 33 | 30 |
| 34 namespace { | 31 namespace { |
| 35 | 32 |
| 36 // We have smaller insets than normal STYLE_TEXTBUTTON buttons so that we can | 33 // We have smaller insets than normal STYLE_TEXTBUTTON buttons so that we can |
| 37 // fit user supplied icons in without clipping them. | 34 // fit user supplied icons in without clipping them. |
| 38 const int kBorderInset = 4; | 35 const int kBorderInset = 4; |
| 39 | 36 |
| 40 } // namespace | 37 } // namespace |
| 41 | 38 |
| 42 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
| 43 // ToolbarActionView | 40 // ToolbarActionView |
| 44 | 41 |
| 45 ToolbarActionView::ToolbarActionView( | 42 ToolbarActionView::ToolbarActionView( |
| 46 ToolbarActionViewController* view_controller, | 43 ToolbarActionViewController* view_controller, |
| 47 Browser* browser, | 44 Profile* profile, |
| 48 ToolbarActionView::Delegate* delegate) | 45 ToolbarActionView::Delegate* delegate) |
| 49 : MenuButton(this, base::string16(), NULL, false), | 46 : MenuButton(this, base::string16(), NULL, false), |
| 50 view_controller_(view_controller), | 47 view_controller_(view_controller), |
| 51 browser_(browser), | 48 profile_(profile), |
| 52 delegate_(delegate), | 49 delegate_(delegate), |
| 53 called_register_command_(false), | 50 called_register_command_(false), |
| 54 wants_to_run_(false) { | 51 wants_to_run_(false) { |
| 55 set_id(VIEW_ID_BROWSER_ACTION); | 52 set_id(VIEW_ID_BROWSER_ACTION); |
| 56 view_controller_->SetDelegate(this); | 53 view_controller_->SetDelegate(this); |
| 57 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 54 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 58 if (view_controller_->CanDrag()) | 55 if (view_controller_->CanDrag()) |
| 59 set_drag_controller(delegate_); | 56 set_drag_controller(delegate_); |
| 60 | 57 |
| 61 // We also listen for browser theme changes on linux because a switch from or | 58 // We also listen for browser theme changes on linux because a switch from or |
| 62 // to GTK requires that we regrab our browser action images. | 59 // to GTK requires that we regrab our browser action images. |
| 63 registrar_.Add( | 60 registrar_.Add( |
| 64 this, | 61 this, |
| 65 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 62 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 66 content::Source<ThemeService>( | 63 content::Source<ThemeService>( |
| 67 ThemeServiceFactory::GetForProfile(browser->profile()))); | 64 ThemeServiceFactory::GetForProfile(profile_))); |
| 68 | 65 |
| 69 wants_to_run_border_ = CreateDefaultBorder(); | 66 wants_to_run_border_ = CreateDefaultBorder(); |
| 70 DecorateWantsToRunBorder(wants_to_run_border_.get()); | 67 DecorateWantsToRunBorder(wants_to_run_border_.get()); |
| 71 | 68 |
| 72 UpdateState(); | 69 UpdateState(); |
| 73 } | 70 } |
| 74 | 71 |
| 75 ToolbarActionView::~ToolbarActionView() { | 72 ToolbarActionView::~ToolbarActionView() { |
| 76 view_controller_->SetDelegate(nullptr); | 73 view_controller_->SetDelegate(nullptr); |
| 77 } | 74 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 if (!view_controller_->IsEnabled(web_contents)) | 139 if (!view_controller_->IsEnabled(web_contents)) |
| 143 SetState(views::CustomButton::STATE_DISABLED); | 140 SetState(views::CustomButton::STATE_DISABLED); |
| 144 else if (state() == views::CustomButton::STATE_DISABLED) | 141 else if (state() == views::CustomButton::STATE_DISABLED) |
| 145 SetState(views::CustomButton::STATE_NORMAL); | 142 SetState(views::CustomButton::STATE_NORMAL); |
| 146 | 143 |
| 147 wants_to_run_ = view_controller_->WantsToRun(web_contents); | 144 wants_to_run_ = view_controller_->WantsToRun(web_contents); |
| 148 | 145 |
| 149 gfx::ImageSkia icon(view_controller_->GetIcon(web_contents).AsImageSkia()); | 146 gfx::ImageSkia icon(view_controller_->GetIcon(web_contents).AsImageSkia()); |
| 150 | 147 |
| 151 if (!icon.isNull()) { | 148 if (!icon.isNull()) { |
| 152 ThemeService* theme = | 149 ThemeService* theme = ThemeServiceFactory::GetForProfile(profile_); |
| 153 ThemeServiceFactory::GetForProfile(browser_->profile()); | |
| 154 | 150 |
| 155 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); | 151 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); |
| 156 SetImage(views::Button::STATE_NORMAL, | 152 SetImage(views::Button::STATE_NORMAL, |
| 157 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); | 153 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); |
| 158 } | 154 } |
| 159 | 155 |
| 160 SetTooltipText(view_controller_->GetTooltip(web_contents)); | 156 SetTooltipText(view_controller_->GetTooltip(web_contents)); |
| 161 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); | 157 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); |
| 162 | 158 |
| 163 Layout(); // We need to layout since we may have added an icon as a result. | 159 Layout(); // We need to layout since we may have added an icon as a result. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 242 } |
| 247 | 243 |
| 248 views::FocusManager* ToolbarActionView::GetFocusManagerForAccelerator() { | 244 views::FocusManager* ToolbarActionView::GetFocusManagerForAccelerator() { |
| 249 return GetFocusManager(); | 245 return GetFocusManager(); |
| 250 } | 246 } |
| 251 | 247 |
| 252 views::Widget* ToolbarActionView::GetParentForContextMenu() { | 248 views::Widget* ToolbarActionView::GetParentForContextMenu() { |
| 253 // RunMenuAt expects a nested menu to be parented by the same widget as the | 249 // RunMenuAt expects a nested menu to be parented by the same widget as the |
| 254 // already visible menu, in this case the Chrome menu. | 250 // already visible menu, in this case the Chrome menu. |
| 255 return delegate_->ShownInsideMenu() ? | 251 return delegate_->ShownInsideMenu() ? |
| 256 BrowserView::GetBrowserViewForBrowser(browser_) | 252 delegate_->GetOverflowReferenceView()->GetWidget() : |
| 257 ->toolbar()->app_menu()->GetWidget() : | |
| 258 GetWidget(); | 253 GetWidget(); |
| 259 } | 254 } |
| 260 | 255 |
| 261 ToolbarActionViewController* | 256 ToolbarActionViewController* |
| 262 ToolbarActionView::GetPreferredPopupViewController() { | 257 ToolbarActionView::GetPreferredPopupViewController() { |
| 263 return delegate_->ShownInsideMenu() ? | 258 return delegate_->ShownInsideMenu() ? |
| 264 delegate_->GetMainViewForAction(this)->view_controller() : | 259 delegate_->GetMainViewForAction(this)->view_controller() : |
| 265 view_controller(); | 260 view_controller(); |
| 266 } | 261 } |
| 267 | 262 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 292 views::MenuButton* reference_view = | 287 views::MenuButton* reference_view = |
| 293 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); | 288 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); |
| 294 pressed_lock_.reset(new views::MenuButton::PressedLock(reference_view)); | 289 pressed_lock_.reset(new views::MenuButton::PressedLock(reference_view)); |
| 295 } | 290 } |
| 296 } | 291 } |
| 297 | 292 |
| 298 void ToolbarActionView::OnPopupClosed() { | 293 void ToolbarActionView::OnPopupClosed() { |
| 299 delegate_->SetPopupOwner(nullptr); | 294 delegate_->SetPopupOwner(nullptr); |
| 300 pressed_lock_.reset(); // Unpress the menu button if it was pressed. | 295 pressed_lock_.reset(); // Unpress the menu button if it was pressed. |
| 301 } | 296 } |
| OLD | NEW |