Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_action_view.cc

Issue 1492423003: Rejigger ThemeService: move exposure of ThemeProvider interface to a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a test Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 set_context_menu_controller(this); 77 set_context_menu_controller(this);
80 78
81 const int kInkDropLargeSize = 32; 79 const int kInkDropLargeSize = 32;
82 const int kInkDropLargeCornerRadius = 5; 80 const int kInkDropLargeCornerRadius = 5;
83 const int kInkDropSmallSize = 24; 81 const int kInkDropSmallSize = 24;
84 const int kInkDropSmallCornerRadius = 2; 82 const int kInkDropSmallCornerRadius = 2;
85 ink_drop_delegate()->SetInkDropSize( 83 ink_drop_delegate()->SetInkDropSize(
86 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize, 84 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize,
87 kInkDropSmallCornerRadius); 85 kInkDropSmallCornerRadius);
88 86
89 // We also listen for browser theme changes on linux because a switch from or
90 // to GTK requires that we regrab our browser action images.
91 registrar_.Add(
92 this,
93 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
94 content::Source<ThemeService>(
95 ThemeServiceFactory::GetForProfile(profile_)));
96
97 // If the button is within a menu, we need to make it focusable in order to 87 // If the button is within a menu, we need to make it focusable in order to
98 // have it accessible via keyboard navigation, but it shouldn't request focus 88 // have it accessible via keyboard navigation, but it shouldn't request focus
99 // (because that would close the menu). 89 // (because that would close the menu).
100 if (delegate_->ShownInsideMenu()) { 90 if (delegate_->ShownInsideMenu()) {
101 set_request_focus_on_press(false); 91 set_request_focus_on_press(false);
102 SetFocusable(true); 92 SetFocusable(true);
103 } 93 }
104 94
105 UpdateState(); 95 UpdateState();
106 } 96 }
107 97
108 ToolbarActionView::~ToolbarActionView() { 98 ToolbarActionView::~ToolbarActionView() {
109 if (context_menu_owner == this) 99 if (context_menu_owner == this)
110 context_menu_owner = nullptr; 100 context_menu_owner = nullptr;
111 view_controller_->SetDelegate(nullptr); 101 view_controller_->SetDelegate(nullptr);
112 } 102 }
113 103
104 void ToolbarActionView::OnThemeChanged() {
105 UpdateState();
106 }
pkotwicz 2015/12/04 23:16:50 Is OnThemeChanged() necessary? I don't see where t
Evan Stade 2015/12/09 00:57:11 you're right, it's not necessary. I forgot to remo
107
114 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { 108 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) {
115 views::MenuButton::GetAccessibleState(state); 109 views::MenuButton::GetAccessibleState(state);
116 state->role = ui::AX_ROLE_BUTTON; 110 state->role = ui::AX_ROLE_BUTTON;
117 } 111 }
118 112
119 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const { 113 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const {
120 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); 114 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder();
121 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, 115 border->set_insets(gfx::Insets(kBorderInset, kBorderInset,
122 kBorderInset, kBorderInset)); 116 kBorderInset, kBorderInset));
123 return border.Pass(); 117 return border.Pass();
(...skipping 26 matching lines...) Expand all
150 SetState(views::CustomButton::STATE_NORMAL); 144 SetState(views::CustomButton::STATE_NORMAL);
151 } 145 }
152 146
153 wants_to_run_ = view_controller_->WantsToRun(web_contents); 147 wants_to_run_ = view_controller_->WantsToRun(web_contents);
154 148
155 gfx::ImageSkia icon( 149 gfx::ImageSkia icon(
156 view_controller_->GetIcon(web_contents, 150 view_controller_->GetIcon(web_contents,
157 GetPreferredSize()).AsImageSkia()); 151 GetPreferredSize()).AsImageSkia());
158 152
159 if (!icon.isNull()) { 153 if (!icon.isNull()) {
160 ThemeService* theme = ThemeServiceFactory::GetForProfile(profile_); 154 gfx::ImageSkia bg = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
161 155 IDR_BROWSER_ACTION);
162 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION);
163 SetImage(views::Button::STATE_NORMAL, 156 SetImage(views::Button::STATE_NORMAL,
164 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); 157 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon));
165 } 158 }
166 159
167 SetTooltipText(view_controller_->GetTooltip(web_contents)); 160 SetTooltipText(view_controller_->GetTooltip(web_contents));
168 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); 161 SetAccessibleName(view_controller_->GetAccessibleName(web_contents));
169 162
170 Layout(); // We need to layout since we may have added an icon as a result. 163 Layout(); // We need to layout since we may have added an icon as a result.
171 SchedulePaint(); 164 SchedulePaint();
172 } 165 }
173 166
174 void ToolbarActionView::OnMenuButtonClicked(views::View* sender, 167 void ToolbarActionView::OnMenuButtonClicked(views::View* sender,
175 const gfx::Point& point) { 168 const gfx::Point& point) {
176 if (!view_controller_->IsEnabled(GetCurrentWebContents())) { 169 if (!view_controller_->IsEnabled(GetCurrentWebContents())) {
177 // We should only get a button pressed event with a non-enabled action if 170 // We should only get a button pressed event with a non-enabled action if
178 // the left-click behavior should open the menu. 171 // the left-click behavior should open the menu.
179 DCHECK(view_controller_->DisabledClickOpensMenu()); 172 DCHECK(view_controller_->DisabledClickOpensMenu());
180 context_menu_controller()->ShowContextMenuForView(this, point, 173 context_menu_controller()->ShowContextMenuForView(this, point,
181 ui::MENU_SOURCE_NONE); 174 ui::MENU_SOURCE_NONE);
182 } else { 175 } else {
183 view_controller_->ExecuteAction(true); 176 view_controller_->ExecuteAction(true);
184 } 177 }
185 } 178 }
186 179
187 void ToolbarActionView::Observe(int type,
188 const content::NotificationSource& source,
189 const content::NotificationDetails& details) {
190 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
191 UpdateState();
192 }
193
194 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) { 180 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
195 SetPaintToLayer(true); 181 SetPaintToLayer(true);
196 SetFillsBoundsOpaquely(false); 182 SetFillsBoundsOpaquely(false);
197 image()->SetPaintToLayer(true); 183 image()->SetPaintToLayer(true);
198 image()->SetFillsBoundsOpaquely(false); 184 image()->SetFillsBoundsOpaquely(false);
199 185
200 layer()->Add(ink_drop_layer); 186 layer()->Add(ink_drop_layer);
201 layer()->StackAtBottom(ink_drop_layer); 187 layer()->StackAtBottom(ink_drop_layer);
202 } 188 }
203 189
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (menu_controller->in_nested_run()) { 371 if (menu_controller->in_nested_run()) {
386 // There is another menu showing. Close the outermost menu (since we are 372 // There is another menu showing. Close the outermost menu (since we are
387 // shown in the same menu, we don't want to close the whole thing). 373 // shown in the same menu, we don't want to close the whole thing).
388 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); 374 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST);
389 return true; 375 return true;
390 } 376 }
391 } 377 }
392 378
393 return false; 379 return false;
394 } 380 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698