| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_action_view.h" | 5 #include "chrome/browser/ui/views/browser_action_view.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" | 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" |
| 10 #include "chrome/browser/extensions/extension_context_menu_model.h" | 10 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 keybinding_.reset(new ui::Accelerator( | 93 keybinding_.reset(new ui::Accelerator( |
| 94 browser_action_command.accelerator())); | 94 browser_action_command.accelerator())); |
| 95 panel_->GetFocusManager()->RegisterAccelerator( | 95 panel_->GetFocusManager()->RegisterAccelerator( |
| 96 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this); | 96 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 MenuButton::ViewHierarchyChanged(is_add, parent, child); | 100 MenuButton::ViewHierarchyChanged(is_add, parent, child); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool BrowserActionButton::IsEnabled() const { |
| 104 int tab_id = panel_->GetCurrentTabId(); |
| 105 if (tab_id < 0) { |
| 106 // Default is "true" because disabled is the uncommon state. |
| 107 return true; |
| 108 } |
| 109 |
| 110 return browser_action()->GetIsVisible(tab_id); |
| 111 } |
| 112 |
| 103 bool BrowserActionButton::CanHandleAccelerators() const { | 113 bool BrowserActionButton::CanHandleAccelerators() const { |
| 104 // View::CanHandleAccelerators() checks to see if the view is visible before | 114 // View::CanHandleAccelerators() checks to see if the view is visible before |
| 105 // allowing it to process accelerators. This is not appropriate for browser | 115 // allowing it to process accelerators. This is not appropriate for browser |
| 106 // actions buttons, which can be hidden inside the overflow area. | 116 // actions buttons, which can be hidden inside the overflow area. |
| 107 return true; | 117 return true; |
| 108 } | 118 } |
| 109 | 119 |
| 110 void BrowserActionButton::ButtonPressed(views::Button* sender, | 120 void BrowserActionButton::ButtonPressed(views::Button* sender, |
| 111 const views::Event& event) { | 121 const views::Event& event) { |
| 112 panel_->OnBrowserActionExecuted(this); | 122 panel_->OnBrowserActionExecuted(this); |
| 113 } | 123 } |
| 114 | 124 |
| 115 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, | 125 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, |
| 116 const std::string& extension_id, | 126 const std::string& extension_id, |
| 117 int index) { | 127 int index) { |
| 118 if (!image.IsEmpty()) | 128 if (!image.IsEmpty()) |
| 119 default_icon_ = *image.ToSkBitmap(); | 129 default_icon_ = *image.ToSkBitmap(); |
| 120 | 130 |
| 121 // Call back to UpdateState() because a more specific icon might have been set | 131 // Call back to UpdateState() because a more specific icon might have been set |
| 122 // while the load was outstanding. | 132 // while the load was outstanding. |
| 123 UpdateState(); | 133 UpdateState(); |
| 124 } | 134 } |
| 125 | 135 |
| 126 void BrowserActionButton::UpdateState() { | 136 void BrowserActionButton::UpdateState() { |
| 127 int tab_id = panel_->GetCurrentTabId(); | 137 int tab_id = panel_->GetCurrentTabId(); |
| 128 if (tab_id < 0) | 138 if (tab_id < 0) |
| 129 return; | 139 return; |
| 130 | 140 |
| 141 // XXX: this needs to cooperate with SetButton(Not)Pushed. |
| 142 SetState(IsEnabled() ? |
| 143 views::CustomButton::BS_NORMAL : |
| 144 views::CustomButton::BS_DISABLED); |
| 145 |
| 131 SkBitmap icon(browser_action()->GetIcon(tab_id)); | 146 SkBitmap icon(browser_action()->GetIcon(tab_id)); |
| 132 if (icon.isNull()) | 147 if (icon.isNull()) |
| 133 icon = default_icon_; | 148 icon = default_icon_; |
| 134 if (!icon.isNull()) { | 149 if (!icon.isNull()) { |
| 150 icon = browser_action()->RenderIconVisibility(icon, tab_id); |
| 151 |
| 135 SkPaint paint; | 152 SkPaint paint; |
| 136 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); | 153 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); |
| 137 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 154 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 138 | 155 |
| 139 SkBitmap bg; | 156 SkBitmap bg; |
| 140 rb.GetBitmapNamed(IDR_BROWSER_ACTION)->copyTo(&bg, | 157 rb.GetBitmapNamed(IDR_BROWSER_ACTION)->copyTo(&bg, |
| 141 SkBitmap::kARGB_8888_Config); | 158 SkBitmap::kARGB_8888_Config); |
| 142 SkCanvas bg_canvas(bg); | 159 SkCanvas bg_canvas(bg); |
| 143 bg_canvas.drawBitmap(icon, SkIntToScalar((bg.width() - icon.width()) / 2), | 160 bg_canvas.drawBitmap(icon, SkIntToScalar((bg.width() - icon.width()) / 2), |
| 144 SkIntToScalar((bg.height() - icon.height()) / 2), &paint); | 161 SkIntToScalar((bg.height() - icon.height()) / 2), &paint); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 state->role = ui::AccessibilityTypes::ROLE_GROUPING; | 356 state->role = ui::AccessibilityTypes::ROLE_GROUPING; |
| 340 } | 357 } |
| 341 | 358 |
| 342 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { | 359 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { |
| 343 View::PaintChildren(canvas); | 360 View::PaintChildren(canvas); |
| 344 ExtensionAction* action = button()->browser_action(); | 361 ExtensionAction* action = button()->browser_action(); |
| 345 int tab_id = panel_->GetCurrentTabId(); | 362 int tab_id = panel_->GetCurrentTabId(); |
| 346 if (tab_id >= 0) | 363 if (tab_id >= 0) |
| 347 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id); | 364 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id); |
| 348 } | 365 } |
| OLD | NEW |