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/gfx/canvas.h" | 7 #include "app/gfx/canvas.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/extensions/extension_popup.h" | 24 #include "chrome/browser/views/extensions/extension_popup.h" |
25 #include "chrome/common/notification_source.h" | 25 #include "chrome/common/notification_source.h" |
26 #include "chrome/common/notification_type.h" | 26 #include "chrome/common/notification_type.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
28 #include "grit/app_resources.h" | 28 #include "grit/app_resources.h" |
29 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
30 #include "third_party/skia/include/core/SkTypeface.h" | 30 #include "third_party/skia/include/core/SkTypeface.h" |
31 #include "third_party/skia/include/effects/SkGradientShader.h" | 31 #include "third_party/skia/include/effects/SkGradientShader.h" |
32 #include "views/controls/button/menu_button.h" | 32 #include "views/controls/button/menu_button.h" |
33 #include "views/controls/button/text_button.h" | 33 #include "views/controls/button/text_button.h" |
34 #include "views/drag_utils.h" | |
34 #include "views/window/window.h" | 35 #include "views/window/window.h" |
35 | 36 |
36 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
37 | 38 |
38 // The size (both dimensions) of the buttons for page actions. | 39 // The size (both dimensions) of the buttons for page actions. |
39 static const int kButtonSize = 29; | 40 static const int kButtonSize = 29; |
40 | 41 |
41 // The padding between the browser actions and the OmniBox/page menu. | 42 // The padding between the browser actions and the OmniBox/page menu. |
42 static const int kHorizontalPadding = 4; | 43 static const int kHorizontalPadding = 4; |
43 static const int kHorizontalPaddingRtl = 8; | 44 static const int kHorizontalPaddingRtl = 8; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 | 268 |
268 BrowserActionView::BrowserActionView(Extension* extension, | 269 BrowserActionView::BrowserActionView(Extension* extension, |
269 BrowserActionsContainer* panel) | 270 BrowserActionsContainer* panel) |
270 : panel_(panel) { | 271 : panel_(panel) { |
271 button_ = new BrowserActionButton(extension, panel); | 272 button_ = new BrowserActionButton(extension, panel); |
272 button_->SetDragController(panel_); | 273 button_->SetDragController(panel_); |
273 AddChildView(button_); | 274 AddChildView(button_); |
274 button_->UpdateState(); | 275 button_->UpdateState(); |
275 } | 276 } |
276 | 277 |
278 gfx::Canvas* BrowserActionView::GetIconWithBadge() { | |
279 int tab_id = panel_->GetCurrentTabId(); | |
280 | |
281 SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); | |
282 if (icon.isNull()) | |
283 icon = button_->default_icon(); | |
284 | |
285 gfx::Canvas* canvas = new gfx::Canvas(icon.width(), icon.height(), false); | |
286 canvas->DrawBitmapInt(icon, 0, 0); | |
287 | |
288 if (tab_id >= 0) { | |
289 gfx::Rect bounds = | |
290 gfx::Rect(icon.width(), icon.height() + kControlVertOffset); | |
291 button_->extension()->browser_action()->PaintBadge(canvas, bounds, tab_id); | |
292 } | |
293 | |
294 return canvas; | |
295 } | |
296 | |
277 void BrowserActionView::Layout() { | 297 void BrowserActionView::Layout() { |
278 button_->SetBounds(0, kControlVertOffset, width(), kButtonSize); | 298 button_->SetBounds(0, kControlVertOffset, width(), kButtonSize); |
279 } | 299 } |
280 | 300 |
281 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { | 301 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { |
282 View::PaintChildren(canvas); | 302 View::PaintChildren(canvas); |
283 ExtensionAction* action = button()->browser_action(); | 303 ExtensionAction* action = button()->browser_action(); |
284 int tab_id = panel_->GetCurrentTabId(); | 304 int tab_id = panel_->GetCurrentTabId(); |
285 if (tab_id < 0) | 305 if (tab_id < 0) |
286 return; | 306 return; |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 overflow_menu_->set_observer(this); | 845 overflow_menu_->set_observer(this); |
826 overflow_menu_->RunMenu(GetWindow()->GetNativeWindow(), false); | 846 overflow_menu_->RunMenu(GetWindow()->GetNativeWindow(), false); |
827 } | 847 } |
828 } | 848 } |
829 | 849 |
830 void BrowserActionsContainer::WriteDragData( | 850 void BrowserActionsContainer::WriteDragData( |
831 View* sender, int press_x, int press_y, OSExchangeData* data) { | 851 View* sender, int press_x, int press_y, OSExchangeData* data) { |
832 DCHECK(data); | 852 DCHECK(data); |
833 | 853 |
834 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 854 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
835 if (browser_action_views_[i]->button() == sender) { | 855 BrowserActionButton* button = browser_action_views_[i]->button(); |
856 if (button == sender) { | |
857 // Set the dragging image for the icon. | |
858 scoped_ptr<gfx::Canvas> canvas( | |
859 browser_action_views_[i]->GetIconWithBadge()); | |
860 drag_utils::SetDragImageOnDataObject(*canvas, button->width(), | |
861 button->height(), press_x, press_y, data); | |
862 // Fill in the remaining info. | |
Erik does not do reviews
2010/02/05 01:16:24
nit: newline above comment
| |
836 BrowserActionDragData drag_data( | 863 BrowserActionDragData drag_data( |
837 browser_action_views_[i]->button()->extension()->id(), i); | 864 browser_action_views_[i]->button()->extension()->id(), i); |
838 drag_data.Write(profile_, data); | 865 drag_data.Write(profile_, data); |
839 break; | 866 break; |
840 } | 867 } |
841 } | 868 } |
842 } | 869 } |
843 | 870 |
844 int BrowserActionsContainer::GetDragOperations(View* sender, int x, int y) { | 871 int BrowserActionsContainer::GetDragOperations(View* sender, int x, int y) { |
845 return DragDropTypes::DRAG_MOVE; | 872 return DragDropTypes::DRAG_MOVE; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1056 | 1083 |
1057 profile_->GetPrefs()->SetInteger(prefs::kBrowserActionContainerWidth, | 1084 profile_->GetPrefs()->SetInteger(prefs::kBrowserActionContainerWidth, |
1058 container_size_.width()); | 1085 container_size_.width()); |
1059 } | 1086 } |
1060 | 1087 |
1061 void BrowserActionsContainer::NotifyMenuDeleted( | 1088 void BrowserActionsContainer::NotifyMenuDeleted( |
1062 BrowserActionOverflowMenuController* controller) { | 1089 BrowserActionOverflowMenuController* controller) { |
1063 DCHECK(controller == overflow_menu_); | 1090 DCHECK(controller == overflow_menu_); |
1064 overflow_menu_ = NULL; | 1091 overflow_menu_ = NULL; |
1065 } | 1092 } |
OLD | NEW |