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

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: respond to comments 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 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 SetState(views::CustomButton::STATE_NORMAL); 140 SetState(views::CustomButton::STATE_NORMAL);
151 } 141 }
152 142
153 wants_to_run_ = view_controller_->WantsToRun(web_contents); 143 wants_to_run_ = view_controller_->WantsToRun(web_contents);
154 144
155 gfx::ImageSkia icon( 145 gfx::ImageSkia icon(
156 view_controller_->GetIcon(web_contents, 146 view_controller_->GetIcon(web_contents,
157 GetPreferredSize()).AsImageSkia()); 147 GetPreferredSize()).AsImageSkia());
158 148
159 if (!icon.isNull()) { 149 if (!icon.isNull()) {
160 ThemeService* theme = ThemeServiceFactory::GetForProfile(profile_); 150 gfx::ImageSkia bg = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
161 151 IDR_BROWSER_ACTION);
162 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION);
163 SetImage(views::Button::STATE_NORMAL, 152 SetImage(views::Button::STATE_NORMAL,
164 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); 153 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon));
165 } 154 }
166 155
167 SetTooltipText(view_controller_->GetTooltip(web_contents)); 156 SetTooltipText(view_controller_->GetTooltip(web_contents));
168 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); 157 SetAccessibleName(view_controller_->GetAccessibleName(web_contents));
169 158
170 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.
171 SchedulePaint(); 160 SchedulePaint();
172 } 161 }
173 162
174 void ToolbarActionView::OnMenuButtonClicked(views::View* sender, 163 void ToolbarActionView::OnMenuButtonClicked(views::View* sender,
175 const gfx::Point& point) { 164 const gfx::Point& point) {
176 if (!view_controller_->IsEnabled(GetCurrentWebContents())) { 165 if (!view_controller_->IsEnabled(GetCurrentWebContents())) {
177 // We should only get a button pressed event with a non-enabled action if 166 // We should only get a button pressed event with a non-enabled action if
178 // the left-click behavior should open the menu. 167 // the left-click behavior should open the menu.
179 DCHECK(view_controller_->DisabledClickOpensMenu()); 168 DCHECK(view_controller_->DisabledClickOpensMenu());
180 context_menu_controller()->ShowContextMenuForView(this, point, 169 context_menu_controller()->ShowContextMenuForView(this, point,
181 ui::MENU_SOURCE_NONE); 170 ui::MENU_SOURCE_NONE);
182 } else { 171 } else {
183 view_controller_->ExecuteAction(true); 172 view_controller_->ExecuteAction(true);
184 } 173 }
185 } 174 }
186 175
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) { 176 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
195 SetPaintToLayer(true); 177 SetPaintToLayer(true);
196 SetFillsBoundsOpaquely(false); 178 SetFillsBoundsOpaquely(false);
197 image()->SetPaintToLayer(true); 179 image()->SetPaintToLayer(true);
198 image()->SetFillsBoundsOpaquely(false); 180 image()->SetFillsBoundsOpaquely(false);
199 181
200 layer()->Add(ink_drop_layer); 182 layer()->Add(ink_drop_layer);
201 layer()->StackAtBottom(ink_drop_layer); 183 layer()->StackAtBottom(ink_drop_layer);
202 } 184 }
203 185
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (menu_controller->in_nested_run()) { 367 if (menu_controller->in_nested_run()) {
386 // There is another menu showing. Close the outermost menu (since we are 368 // 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). 369 // shown in the same menu, we don't want to close the whole thing).
388 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); 370 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST);
389 return true; 371 return true;
390 } 372 }
391 } 373 }
392 374
393 return false; 375 return false;
394 } 376 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698