| 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 "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/sessions/session_tab_helper.h" | 12 #include "chrome/browser/sessions/session_tab_helper.h" |
| 13 #include "chrome/browser/themes/theme_service.h" | |
| 14 #include "chrome/browser/themes/theme_service_factory.h" | |
| 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 14 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 17 #include "chrome/browser/ui/view_ids.h" | 15 #include "chrome/browser/ui/view_ids.h" |
| 18 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 19 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 20 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 21 #include "ui/accessibility/ax_view_state.h" | 19 #include "ui/accessibility/ax_view_state.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/compositor/paint_recorder.h" | 21 #include "ui/compositor/paint_recorder.h" |
| 24 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 set_context_menu_controller(this); | 76 set_context_menu_controller(this); |
| 79 | 77 |
| 80 const int kInkDropLargeSize = 32; | 78 const int kInkDropLargeSize = 32; |
| 81 const int kInkDropLargeCornerRadius = 5; | 79 const int kInkDropLargeCornerRadius = 5; |
| 82 const int kInkDropSmallSize = 24; | 80 const int kInkDropSmallSize = 24; |
| 83 const int kInkDropSmallCornerRadius = 2; | 81 const int kInkDropSmallCornerRadius = 2; |
| 84 ink_drop_delegate()->SetInkDropSize( | 82 ink_drop_delegate()->SetInkDropSize( |
| 85 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize, | 83 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize, |
| 86 kInkDropSmallCornerRadius); | 84 kInkDropSmallCornerRadius); |
| 87 | 85 |
| 88 // We also listen for browser theme changes on linux because a switch from or | |
| 89 // to GTK requires that we regrab our browser action images. | |
| 90 registrar_.Add( | |
| 91 this, | |
| 92 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | |
| 93 content::Source<ThemeService>( | |
| 94 ThemeServiceFactory::GetForProfile(profile_))); | |
| 95 | |
| 96 // If the button is within a menu, we need to make it focusable in order to | 86 // If the button is within a menu, we need to make it focusable in order to |
| 97 // have it accessible via keyboard navigation, but it shouldn't request focus | 87 // have it accessible via keyboard navigation, but it shouldn't request focus |
| 98 // (because that would close the menu). | 88 // (because that would close the menu). |
| 99 if (delegate_->ShownInsideMenu()) { | 89 if (delegate_->ShownInsideMenu()) { |
| 100 set_request_focus_on_press(false); | 90 set_request_focus_on_press(false); |
| 101 SetFocusable(true); | 91 SetFocusable(true); |
| 102 } | 92 } |
| 103 | 93 |
| 104 UpdateState(); | 94 UpdateState(); |
| 105 } | 95 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 SetState(views::CustomButton::STATE_NORMAL); | 141 SetState(views::CustomButton::STATE_NORMAL); |
| 152 } | 142 } |
| 153 | 143 |
| 154 wants_to_run_ = view_controller_->WantsToRun(web_contents); | 144 wants_to_run_ = view_controller_->WantsToRun(web_contents); |
| 155 | 145 |
| 156 gfx::ImageSkia icon( | 146 gfx::ImageSkia icon( |
| 157 view_controller_->GetIcon(web_contents, | 147 view_controller_->GetIcon(web_contents, |
| 158 GetPreferredSize()).AsImageSkia()); | 148 GetPreferredSize()).AsImageSkia()); |
| 159 | 149 |
| 160 if (!icon.isNull()) { | 150 if (!icon.isNull()) { |
| 161 ThemeService* theme = ThemeServiceFactory::GetForProfile(profile_); | 151 gfx::ImageSkia bg = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 162 | 152 IDR_BROWSER_ACTION); |
| 163 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); | |
| 164 SetImage(views::Button::STATE_NORMAL, | 153 SetImage(views::Button::STATE_NORMAL, |
| 165 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); | 154 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); |
| 166 } | 155 } |
| 167 | 156 |
| 168 SetTooltipText(view_controller_->GetTooltip(web_contents)); | 157 SetTooltipText(view_controller_->GetTooltip(web_contents)); |
| 169 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); | 158 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); |
| 170 | 159 |
| 171 Layout(); // We need to layout since we may have added an icon as a result. | 160 Layout(); // We need to layout since we may have added an icon as a result. |
| 172 SchedulePaint(); | 161 SchedulePaint(); |
| 173 } | 162 } |
| 174 | 163 |
| 175 void ToolbarActionView::OnMenuButtonClicked(views::View* sender, | 164 void ToolbarActionView::OnMenuButtonClicked(views::View* sender, |
| 176 const gfx::Point& point) { | 165 const gfx::Point& point) { |
| 177 if (!view_controller_->IsEnabled(GetCurrentWebContents())) { | 166 if (!view_controller_->IsEnabled(GetCurrentWebContents())) { |
| 178 // We should only get a button pressed event with a non-enabled action if | 167 // We should only get a button pressed event with a non-enabled action if |
| 179 // the left-click behavior should open the menu. | 168 // the left-click behavior should open the menu. |
| 180 DCHECK(view_controller_->DisabledClickOpensMenu()); | 169 DCHECK(view_controller_->DisabledClickOpensMenu()); |
| 181 context_menu_controller()->ShowContextMenuForView(this, point, | 170 context_menu_controller()->ShowContextMenuForView(this, point, |
| 182 ui::MENU_SOURCE_NONE); | 171 ui::MENU_SOURCE_NONE); |
| 183 } else { | 172 } else { |
| 184 view_controller_->ExecuteAction(true); | 173 view_controller_->ExecuteAction(true); |
| 185 } | 174 } |
| 186 } | 175 } |
| 187 | 176 |
| 188 void ToolbarActionView::Observe(int type, | |
| 189 const content::NotificationSource& source, | |
| 190 const content::NotificationDetails& details) { | |
| 191 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); | |
| 192 UpdateState(); | |
| 193 } | |
| 194 | |
| 195 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 177 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 196 SetPaintToLayer(true); | 178 SetPaintToLayer(true); |
| 197 SetFillsBoundsOpaquely(false); | 179 SetFillsBoundsOpaquely(false); |
| 198 image()->SetPaintToLayer(true); | 180 image()->SetPaintToLayer(true); |
| 199 image()->SetFillsBoundsOpaquely(false); | 181 image()->SetFillsBoundsOpaquely(false); |
| 200 | 182 |
| 201 layer()->Add(ink_drop_layer); | 183 layer()->Add(ink_drop_layer); |
| 202 layer()->StackAtBottom(ink_drop_layer); | 184 layer()->StackAtBottom(ink_drop_layer); |
| 203 } | 185 } |
| 204 | 186 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 if (menu_controller->in_nested_run()) { | 368 if (menu_controller->in_nested_run()) { |
| 387 // There is another menu showing. Close the outermost menu (since we are | 369 // There is another menu showing. Close the outermost menu (since we are |
| 388 // shown in the same menu, we don't want to close the whole thing). | 370 // shown in the same menu, we don't want to close the whole thing). |
| 389 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); | 371 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); |
| 390 return true; | 372 return true; |
| 391 } | 373 } |
| 392 } | 374 } |
| 393 | 375 |
| 394 return false; | 376 return false; |
| 395 } | 377 } |
| OLD | NEW |