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

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

Issue 340003002: Revert of views: Move MenuButton from TextButton to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months 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 | Annotate | Revision Log
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/browser_action_view.h" 5 #include "chrome/browser/ui/views/toolbar/browser_action_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/api/commands/command_service.h" 9 #include "chrome/browser/extensions/api/commands/command_service.h"
10 #include "chrome/browser/extensions/extension_action.h" 10 #include "chrome/browser/extensions/extension_action.h"
(...skipping 19 matching lines...) Expand all
30 #include "ui/gfx/image/image_skia_operations.h" 30 #include "ui/gfx/image/image_skia_operations.h"
31 #include "ui/gfx/image/image_skia_source.h" 31 #include "ui/gfx/image/image_skia_source.h"
32 #include "ui/views/controls/menu/menu_item_view.h" 32 #include "ui/views/controls/menu/menu_item_view.h"
33 #include "ui/views/controls/menu/menu_runner.h" 33 #include "ui/views/controls/menu/menu_runner.h"
34 34
35 using extensions::Extension; 35 using extensions::Extension;
36 36
37 //////////////////////////////////////////////////////////////////////////////// 37 ////////////////////////////////////////////////////////////////////////////////
38 // BrowserActionView 38 // BrowserActionView
39 39
40 bool BrowserActionView::Delegate::NeedToShowMultipleIconStates() const {
41 return true;
42 }
43
44 bool BrowserActionView::Delegate::NeedToShowTooltip() const {
45 return true;
46 }
47
40 BrowserActionView::BrowserActionView(const Extension* extension, 48 BrowserActionView::BrowserActionView(const Extension* extension,
41 Browser* browser, 49 Browser* browser,
42 BrowserActionView::Delegate* delegate) 50 BrowserActionView::Delegate* delegate)
43 : browser_(browser), 51 : browser_(browser),
44 delegate_(delegate), 52 delegate_(delegate),
45 button_(NULL), 53 button_(NULL),
46 extension_(extension) { 54 extension_(extension) {
47 set_id(VIEW_ID_BROWSER_ACTION); 55 set_id(VIEW_ID_BROWSER_ACTION);
48 button_ = new BrowserActionButton(extension_, browser_, delegate_); 56 button_ = new BrowserActionButton(extension_, browser_, delegate_);
49 button_->set_drag_controller(delegate_); 57 button_->set_drag_controller(delegate_);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 browser_action_( 103 browser_action_(
96 extensions::ExtensionActionManager::Get(browser->profile())-> 104 extensions::ExtensionActionManager::Get(browser->profile())->
97 GetBrowserAction(*extension)), 105 GetBrowserAction(*extension)),
98 extension_(extension), 106 extension_(extension),
99 icon_factory_(browser->profile(), extension, browser_action_, this), 107 icon_factory_(browser->profile(), extension, browser_action_, this),
100 delegate_(delegate), 108 delegate_(delegate),
101 context_menu_(NULL), 109 context_menu_(NULL),
102 called_registered_extension_command_(false), 110 called_registered_extension_command_(false),
103 icon_observer_(NULL) { 111 icon_observer_(NULL) {
104 SetBorder(views::Border::NullBorder()); 112 SetBorder(views::Border::NullBorder());
105 SetHorizontalAlignment(gfx::ALIGN_CENTER); 113 set_alignment(TextButton::ALIGN_CENTER);
106 set_context_menu_controller(this); 114 set_context_menu_controller(this);
107 115
108 // No UpdateState() here because View hierarchy not setup yet. Our parent 116 // No UpdateState() here because View hierarchy not setup yet. Our parent
109 // should call UpdateState() after creation. 117 // should call UpdateState() after creation.
110 118
111 content::NotificationSource notification_source = 119 content::NotificationSource notification_source =
112 content::Source<Profile>(browser_->profile()->GetOriginalProfile()); 120 content::Source<Profile>(browser_->profile()->GetOriginalProfile());
113 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, 121 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
114 content::Source<ExtensionAction>(browser_action_)); 122 content::Source<ExtensionAction>(browser_action_));
115 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, 123 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 menu_runner_.reset(); 204 menu_runner_.reset();
197 SetButtonNotPushed(); 205 SetButtonNotPushed();
198 context_menu_ = NULL; 206 context_menu_ = NULL;
199 } 207 }
200 208
201 void BrowserActionButton::UpdateState() { 209 void BrowserActionButton::UpdateState() {
202 int tab_id = delegate_->GetCurrentTabId(); 210 int tab_id = delegate_->GetCurrentTabId();
203 if (tab_id < 0) 211 if (tab_id < 0)
204 return; 212 return;
205 213
214 SetShowMultipleIconStates(delegate_->NeedToShowMultipleIconStates());
215
206 if (!IsEnabled(tab_id)) { 216 if (!IsEnabled(tab_id)) {
207 SetState(views::CustomButton::STATE_DISABLED); 217 SetState(views::CustomButton::STATE_DISABLED);
208 } else { 218 } else {
209 SetState(menu_visible_ ? 219 SetState(menu_visible_ ?
210 views::CustomButton::STATE_PRESSED : 220 views::CustomButton::STATE_PRESSED :
211 views::CustomButton::STATE_NORMAL); 221 views::CustomButton::STATE_NORMAL);
212 } 222 }
213 223
214 gfx::ImageSkia icon = *icon_factory_.GetIcon(tab_id).ToImageSkia(); 224 gfx::ImageSkia icon = *icon_factory_.GetIcon(tab_id).ToImageSkia();
215 225
216 if (!icon.isNull()) { 226 if (!icon.isNull()) {
217 if (!browser_action()->GetIsVisible(tab_id)) 227 if (!browser_action()->GetIsVisible(tab_id))
218 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); 228 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25);
219 229
220 ThemeService* theme = 230 ThemeService* theme =
221 ThemeServiceFactory::GetForProfile(browser_->profile()); 231 ThemeServiceFactory::GetForProfile(browser_->profile());
222 232
223 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); 233 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION);
224 SetImage(views::Button::STATE_NORMAL, 234 SetIcon(gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon));
225 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon));
226 235
227 gfx::ImageSkia bg_h = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION_H); 236 gfx::ImageSkia bg_h = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION_H);
228 SetImage(views::Button::STATE_HOVERED, 237 SetHoverIcon(gfx::ImageSkiaOperations::CreateSuperimposedImage(bg_h, icon));
229 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg_h, icon));
230 238
231 gfx::ImageSkia bg_p = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION_P); 239 gfx::ImageSkia bg_p = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION_P);
232 SetImage(views::Button::STATE_PRESSED, 240 SetPushedIcon(
233 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg_p, icon)); 241 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg_p, icon));
234 } 242 }
235 243
236 // If the browser action name is empty, show the extension name instead. 244 // If the browser action name is empty, show the extension name instead.
237 std::string title = browser_action()->GetTitle(tab_id); 245 std::string title = browser_action()->GetTitle(tab_id);
238 base::string16 name = 246 base::string16 name =
239 base::UTF8ToUTF16(title.empty() ? extension()->name() : title); 247 base::UTF8ToUTF16(title.empty() ? extension()->name() : title);
240 SetTooltipText(name); 248 SetTooltipText(delegate_->NeedToShowTooltip() ? name : base::string16());
241 SetAccessibleName(name); 249 SetAccessibleName(name);
242 250
243 parent()->SchedulePaint(); 251 parent()->SchedulePaint();
244 } 252 }
245 253
246 bool BrowserActionButton::IsPopup() { 254 bool BrowserActionButton::IsPopup() {
247 int tab_id = delegate_->GetCurrentTabId(); 255 int tab_id = delegate_->GetCurrentTabId();
248 return (tab_id < 0) ? false : browser_action_->HasPopup(tab_id); 256 return (tab_id < 0) ? false : browser_action_->HasPopup(tab_id);
249 } 257 }
250 258
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // The return value of this method is returned via OnMousePressed. 313 // The return value of this method is returned via OnMousePressed.
306 // We need to return false here since we're handing off focus to another 314 // We need to return false here since we're handing off focus to another
307 // widget/view, and true will grab it right back and try to send events 315 // widget/view, and true will grab it right back and try to send events
308 // to us. 316 // to us.
309 return false; 317 return false;
310 } 318 }
311 319
312 bool BrowserActionButton::OnMousePressed(const ui::MouseEvent& event) { 320 bool BrowserActionButton::OnMousePressed(const ui::MouseEvent& event) {
313 if (!event.IsRightMouseButton()) { 321 if (!event.IsRightMouseButton()) {
314 return IsPopup() ? MenuButton::OnMousePressed(event) : 322 return IsPopup() ? MenuButton::OnMousePressed(event) :
315 LabelButton::OnMousePressed(event); 323 TextButton::OnMousePressed(event);
316 } 324 }
317 325
318 if (!views::View::ShouldShowContextMenuOnMousePress()) { 326 if (!views::View::ShouldShowContextMenuOnMousePress()) {
319 // See comments in MenuButton::Activate() as to why this is needed. 327 // See comments in MenuButton::Activate() as to why this is needed.
320 SetMouseHandler(NULL); 328 SetMouseHandler(NULL);
321 329
322 ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 330 ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
323 } 331 }
324 return false; 332 return false;
325 } 333 }
326 334
327 void BrowserActionButton::OnMouseReleased(const ui::MouseEvent& event) { 335 void BrowserActionButton::OnMouseReleased(const ui::MouseEvent& event) {
328 if (IsPopup() || context_menu_) { 336 if (IsPopup() || context_menu_) {
329 // TODO(erikkay) this never actually gets called (probably because of the 337 // TODO(erikkay) this never actually gets called (probably because of the
330 // loss of focus). 338 // loss of focus).
331 MenuButton::OnMouseReleased(event); 339 MenuButton::OnMouseReleased(event);
332 } else { 340 } else {
333 LabelButton::OnMouseReleased(event); 341 TextButton::OnMouseReleased(event);
334 } 342 }
335 } 343 }
336 344
337 void BrowserActionButton::OnMouseExited(const ui::MouseEvent& event) { 345 void BrowserActionButton::OnMouseExited(const ui::MouseEvent& event) {
338 if (IsPopup() || context_menu_) 346 if (IsPopup() || context_menu_)
339 MenuButton::OnMouseExited(event); 347 MenuButton::OnMouseExited(event);
340 else 348 else
341 LabelButton::OnMouseExited(event); 349 TextButton::OnMouseExited(event);
342 } 350 }
343 351
344 bool BrowserActionButton::OnKeyReleased(const ui::KeyEvent& event) { 352 bool BrowserActionButton::OnKeyReleased(const ui::KeyEvent& event) {
345 return IsPopup() ? MenuButton::OnKeyReleased(event) : 353 return IsPopup() ? MenuButton::OnKeyReleased(event) :
346 LabelButton::OnKeyReleased(event); 354 TextButton::OnKeyReleased(event);
347 } 355 }
348 356
349 void BrowserActionButton::OnGestureEvent(ui::GestureEvent* event) { 357 void BrowserActionButton::OnGestureEvent(ui::GestureEvent* event) {
350 if (IsPopup()) 358 if (IsPopup())
351 MenuButton::OnGestureEvent(event); 359 MenuButton::OnGestureEvent(event);
352 else 360 else
353 LabelButton::OnGestureEvent(event); 361 TextButton::OnGestureEvent(event);
354 } 362 }
355 363
356 bool BrowserActionButton::AcceleratorPressed( 364 bool BrowserActionButton::AcceleratorPressed(
357 const ui::Accelerator& accelerator) { 365 const ui::Accelerator& accelerator) {
358 delegate_->OnBrowserActionExecuted(this); 366 delegate_->OnBrowserActionExecuted(this);
359 return true; 367 return true;
360 } 368 }
361 369
362 void BrowserActionButton::SetButtonPushed() { 370 void BrowserActionButton::SetButtonPushed() {
363 SetState(views::CustomButton::STATE_PRESSED); 371 SetState(views::CustomButton::STATE_PRESSED);
(...skipping 12 matching lines...) Expand all
376 gfx::ImageSkia BrowserActionButton::GetIconWithBadge() { 384 gfx::ImageSkia BrowserActionButton::GetIconWithBadge() {
377 int tab_id = delegate_->GetCurrentTabId(); 385 int tab_id = delegate_->GetCurrentTabId();
378 gfx::Size spacing(0, ToolbarView::kVertSpacing); 386 gfx::Size spacing(0, ToolbarView::kVertSpacing);
379 gfx::ImageSkia icon = *icon_factory_.GetIcon(tab_id).ToImageSkia(); 387 gfx::ImageSkia icon = *icon_factory_.GetIcon(tab_id).ToImageSkia();
380 if (!IsEnabled(tab_id)) 388 if (!IsEnabled(tab_id))
381 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); 389 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25);
382 return browser_action_->GetIconWithBadge(icon, tab_id, spacing); 390 return browser_action_->GetIconWithBadge(icon, tab_id, spacing);
383 } 391 }
384 392
385 gfx::ImageSkia BrowserActionButton::GetIconForTest() { 393 gfx::ImageSkia BrowserActionButton::GetIconForTest() {
386 return GetImage(views::Button::STATE_NORMAL); 394 return icon();
387 } 395 }
388 396
389 BrowserActionButton::~BrowserActionButton() { 397 BrowserActionButton::~BrowserActionButton() {
390 } 398 }
391 399
392 void BrowserActionButton::MaybeRegisterExtensionCommand() { 400 void BrowserActionButton::MaybeRegisterExtensionCommand() {
393 extensions::CommandService* command_service = 401 extensions::CommandService* command_service =
394 extensions::CommandService::Get(browser_->profile()); 402 extensions::CommandService::Get(browser_->profile());
395 extensions::Command browser_action_command; 403 extensions::Command browser_action_command;
396 if (command_service->GetBrowserActionCommand( 404 if (command_service->GetBrowserActionCommand(
(...skipping 18 matching lines...) Expand all
415 extensions::Command browser_action_command; 423 extensions::Command browser_action_command;
416 if (!only_if_active || !command_service->GetBrowserActionCommand( 424 if (!only_if_active || !command_service->GetBrowserActionCommand(
417 extension_->id(), 425 extension_->id(),
418 extensions::CommandService::ACTIVE_ONLY, 426 extensions::CommandService::ACTIVE_ONLY,
419 &browser_action_command, 427 &browser_action_command,
420 NULL)) { 428 NULL)) {
421 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); 429 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this);
422 keybinding_.reset(NULL); 430 keybinding_.reset(NULL);
423 } 431 }
424 } 432 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/browser_action_view.h ('k') | chrome/browser/ui/views/toolbar/browser_actions_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698