OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/browser_actions_container.h" | 5 #include "chrome/browser/views/browser_actions_container.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "app/slide_animation.h" | 9 #include "app/slide_animation.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/views/detachable_toolbar_view.h" | 24 #include "chrome/browser/views/detachable_toolbar_view.h" |
25 #include "chrome/browser/views/extensions/browser_action_drag_data.h" | 25 #include "chrome/browser/views/extensions/browser_action_drag_data.h" |
26 #include "chrome/browser/views/extensions/extension_popup.h" | 26 #include "chrome/browser/views/extensions/extension_popup.h" |
27 #include "chrome/browser/views/toolbar_view.h" | 27 #include "chrome/browser/views/toolbar_view.h" |
28 #include "chrome/common/extensions/extension_action.h" | 28 #include "chrome/common/extensions/extension_action.h" |
29 #include "chrome/common/extensions/extension_resource.h" | 29 #include "chrome/common/extensions/extension_resource.h" |
30 #include "chrome/common/notification_source.h" | 30 #include "chrome/common/notification_source.h" |
31 #include "chrome/common/notification_type.h" | 31 #include "chrome/common/notification_type.h" |
32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
33 #include "gfx/canvas.h" | 33 #include "gfx/canvas.h" |
| 34 #include "gfx/canvas_skia.h" |
34 #include "grit/app_resources.h" | 35 #include "grit/app_resources.h" |
35 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
36 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
37 #include "third_party/skia/include/core/SkTypeface.h" | 38 #include "third_party/skia/include/core/SkTypeface.h" |
38 #include "third_party/skia/include/effects/SkGradientShader.h" | 39 #include "third_party/skia/include/effects/SkGradientShader.h" |
39 #include "views/controls/button/menu_button.h" | 40 #include "views/controls/button/menu_button.h" |
40 #include "views/controls/button/text_button.h" | 41 #include "views/controls/button/text_button.h" |
41 #include "views/controls/menu/menu_2.h" | 42 #include "views/controls/menu/menu_2.h" |
42 #include "views/drag_utils.h" | 43 #include "views/drag_utils.h" |
43 #include "views/window/window.h" | 44 #include "views/window/window.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 button_->UpdateState(); | 309 button_->UpdateState(); |
309 SetAccessibleName( | 310 SetAccessibleName( |
310 l10n_util::GetString(IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION)); | 311 l10n_util::GetString(IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION)); |
311 } | 312 } |
312 | 313 |
313 BrowserActionView::~BrowserActionView() { | 314 BrowserActionView::~BrowserActionView() { |
314 RemoveChildView(button_); | 315 RemoveChildView(button_); |
315 button_->Destroy(); | 316 button_->Destroy(); |
316 } | 317 } |
317 | 318 |
318 gfx::Canvas* BrowserActionView::GetIconWithBadge() { | 319 gfx::CanvasSkia* BrowserActionView::GetIconWithBadge() { |
319 int tab_id = panel_->GetCurrentTabId(); | 320 int tab_id = panel_->GetCurrentTabId(); |
320 | 321 |
321 SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); | 322 SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); |
322 if (icon.isNull()) | 323 if (icon.isNull()) |
323 icon = button_->default_icon(); | 324 icon = button_->default_icon(); |
324 | 325 |
325 gfx::Canvas* canvas = new gfx::Canvas(icon.width(), icon.height(), false); | 326 gfx::CanvasSkia* canvas = |
| 327 new gfx::CanvasSkia(icon.width(), icon.height(), false); |
326 canvas->DrawBitmapInt(icon, 0, 0); | 328 canvas->DrawBitmapInt(icon, 0, 0); |
327 | 329 |
328 if (tab_id >= 0) { | 330 if (tab_id >= 0) { |
329 gfx::Rect bounds = | 331 gfx::Rect bounds = |
330 gfx::Rect(icon.width(), icon.height() + kControlVertOffset); | 332 gfx::Rect(icon.width(), icon.height() + kControlVertOffset); |
331 button_->extension()->browser_action()->PaintBadge(canvas, bounds, tab_id); | 333 button_->extension()->browser_action()->PaintBadge(canvas->AsCanvas(), |
| 334 bounds, tab_id); |
332 } | 335 } |
333 | 336 |
334 return canvas; | 337 return canvas; |
335 } | 338 } |
336 | 339 |
337 bool BrowserActionView::GetAccessibleRole(AccessibilityTypes::Role* role) { | 340 bool BrowserActionView::GetAccessibleRole(AccessibilityTypes::Role* role) { |
338 DCHECK(role); | 341 DCHECK(role); |
339 *role = AccessibilityTypes::ROLE_GROUPING; | 342 *role = AccessibilityTypes::ROLE_GROUPING; |
340 return true; | 343 return true; |
341 } | 344 } |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 | 861 |
859 void BrowserActionsContainer::WriteDragData(View* sender, | 862 void BrowserActionsContainer::WriteDragData(View* sender, |
860 const gfx::Point& press_pt, | 863 const gfx::Point& press_pt, |
861 OSExchangeData* data) { | 864 OSExchangeData* data) { |
862 DCHECK(data); | 865 DCHECK(data); |
863 | 866 |
864 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 867 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
865 BrowserActionButton* button = browser_action_views_[i]->button(); | 868 BrowserActionButton* button = browser_action_views_[i]->button(); |
866 if (button == sender) { | 869 if (button == sender) { |
867 // Set the dragging image for the icon. | 870 // Set the dragging image for the icon. |
868 scoped_ptr<gfx::Canvas> canvas( | 871 scoped_ptr<gfx::CanvasSkia> canvas( |
869 browser_action_views_[i]->GetIconWithBadge()); | 872 browser_action_views_[i]->GetIconWithBadge()); |
870 drag_utils::SetDragImageOnDataObject(*canvas, button->size(), press_pt, | 873 drag_utils::SetDragImageOnDataObject(*canvas->AsCanvas(), button->size(),
press_pt, |
871 data); | 874 data); |
872 | 875 |
873 // Fill in the remaining info. | 876 // Fill in the remaining info. |
874 BrowserActionDragData drag_data( | 877 BrowserActionDragData drag_data( |
875 browser_action_views_[i]->button()->extension()->id(), i); | 878 browser_action_views_[i]->button()->extension()->id(), i); |
876 drag_data.Write(profile_, data); | 879 drag_data.Write(profile_, data); |
877 break; | 880 break; |
878 } | 881 } |
879 } | 882 } |
880 } | 883 } |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 popup_ = NULL; | 1163 popup_ = NULL; |
1161 popup_button_->SetButtonNotPushed(); | 1164 popup_button_->SetButtonNotPushed(); |
1162 popup_button_ = NULL; | 1165 popup_button_ = NULL; |
1163 } | 1166 } |
1164 | 1167 |
1165 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { | 1168 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { |
1166 // Only display incognito-enabled extensions while in incognito mode. | 1169 // Only display incognito-enabled extensions while in incognito mode. |
1167 return (!profile_->IsOffTheRecord() || | 1170 return (!profile_->IsOffTheRecord() || |
1168 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); | 1171 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); |
1169 } | 1172 } |
OLD | NEW |