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