| 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/infobars/extension_infobar.h" | 5 #include "chrome/browser/ui/views/infobars/extension_infobar.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_context_menu_model.h" | 7 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
| 9 #include "chrome/browser/extensions/extension_infobar_delegate.h" | 9 #include "chrome/browser/extensions/extension_infobar_delegate.h" |
| 10 #include "chrome/browser/platform_util.h" | 10 #include "chrome/browser/platform_util.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.h" | 11 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "chrome/common/extensions/extension_constants.h" |
| 13 #include "chrome/common/extensions/extension_icon_set.h" | 14 #include "chrome/common/extensions/extension_icon_set.h" |
| 14 #include "chrome/common/extensions/extension_resource.h" | 15 #include "chrome/common/extensions/extension_resource.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #include "ui/base/animation/slide_animation.h" | 17 #include "ui/base/animation/slide_animation.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 19 #include "ui/gfx/image/canvas_image_source.h" | 20 #include "ui/gfx/image/canvas_image_source.h" |
| 20 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| 21 #include "ui/views/controls/button/menu_button.h" | 22 #include "ui/views/controls/button/menu_button.h" |
| 22 #include "ui/views/controls/menu/menu_item_view.h" | 23 #include "ui/views/controls/menu/menu_item_view.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 : gfx::CanvasImageSource(ComputeSize(drop_image), false), | 41 : gfx::CanvasImageSource(ComputeSize(drop_image), false), |
| 41 icon_(icon), | 42 icon_(icon), |
| 42 drop_image_(drop_image) { | 43 drop_image_(drop_image) { |
| 43 } | 44 } |
| 44 | 45 |
| 45 virtual ~MenuImageSource() { | 46 virtual ~MenuImageSource() { |
| 46 } | 47 } |
| 47 | 48 |
| 48 // Overridden from gfx::CanvasImageSource | 49 // Overridden from gfx::CanvasImageSource |
| 49 void Draw(gfx::Canvas* canvas) OVERRIDE { | 50 void Draw(gfx::Canvas* canvas) OVERRIDE { |
| 50 int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; | 51 int image_size = extension_misc::EXTENSION_ICON_BITTY; |
| 51 canvas->DrawImageInt(icon_, 0, 0, icon_.width(), icon_.height(), 0, 0, | 52 canvas->DrawImageInt(icon_, 0, 0, icon_.width(), icon_.height(), 0, 0, |
| 52 image_size, image_size, false); | 53 image_size, image_size, false); |
| 53 canvas->DrawImageInt(drop_image_, image_size + kDropArrowLeftMargin, | 54 canvas->DrawImageInt(drop_image_, image_size + kDropArrowLeftMargin, |
| 54 image_size / 2); | 55 image_size / 2); |
| 55 } | 56 } |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 gfx::Size ComputeSize(const gfx::ImageSkia& drop_image) const { | 59 gfx::Size ComputeSize(const gfx::ImageSkia& drop_image) const { |
| 59 int image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; | 60 int image_size = extension_misc::EXTENSION_ICON_BITTY; |
| 60 return gfx::Size(image_size + kDropArrowLeftMargin + drop_image.width(), | 61 return gfx::Size(image_size + kDropArrowLeftMargin + drop_image.width(), |
| 61 image_size); | 62 image_size); |
| 62 } | 63 } |
| 63 | 64 |
| 64 // The margin between the extension icon and the drop-down arrow image. | 65 // The margin between the extension icon and the drop-down arrow image. |
| 65 static const int kDropArrowLeftMargin = 3; | 66 static const int kDropArrowLeftMargin = 3; |
| 66 | 67 |
| 67 const gfx::ImageSkia icon_; | 68 const gfx::ImageSkia icon_; |
| 68 const gfx::ImageSkia drop_image_; | 69 const gfx::ImageSkia drop_image_; |
| 69 | 70 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 AddChildView(extension_host->view()); | 123 AddChildView(extension_host->view()); |
| 123 | 124 |
| 124 // This must happen after adding all other children so InfoBarView can ensure | 125 // This must happen after adding all other children so InfoBarView can ensure |
| 125 // the close button is the last child. | 126 // the close button is the last child. |
| 126 InfoBarView::ViewHierarchyChanged(is_add, parent, child); | 127 InfoBarView::ViewHierarchyChanged(is_add, parent, child); |
| 127 | 128 |
| 128 // This must happen after adding all children because it can trigger layout, | 129 // This must happen after adding all children because it can trigger layout, |
| 129 // which assumes that particular children (e.g. the close button) have already | 130 // which assumes that particular children (e.g. the close button) have already |
| 130 // been added. | 131 // been added. |
| 131 const extensions::Extension* extension = extension_host->extension(); | 132 const extensions::Extension* extension = extension_host->extension(); |
| 132 ExtensionIconSet::Icons image_size = ExtensionIconSet::EXTENSION_ICON_BITTY; | 133 extension_misc::ExtensionIcons image_size = |
| 134 extension_misc::EXTENSION_ICON_BITTY; |
| 133 ExtensionResource icon_resource = extension->GetIconResource( | 135 ExtensionResource icon_resource = extension->GetIconResource( |
| 134 image_size, ExtensionIconSet::MATCH_EXACTLY); | 136 image_size, ExtensionIconSet::MATCH_EXACTLY); |
| 135 tracker_.LoadImage(extension, icon_resource, | 137 tracker_.LoadImage(extension, icon_resource, |
| 136 gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE); | 138 gfx::Size(image_size, image_size), ImageLoadingTracker::DONT_CACHE); |
| 137 } | 139 } |
| 138 | 140 |
| 139 int ExtensionInfoBar::ContentMinimumWidth() const { | 141 int ExtensionInfoBar::ContentMinimumWidth() const { |
| 140 return menu_->GetPreferredSize().width() + kMenuHorizontalMargin; | 142 return menu_->GetPreferredSize().width() + kMenuHorizontalMargin; |
| 141 } | 143 } |
| 142 | 144 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 182 |
| 181 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = | 183 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = |
| 182 new ExtensionContextMenuModel(extension, browser_); | 184 new ExtensionContextMenuModel(extension, browser_); |
| 183 DCHECK_EQ(menu_, source); | 185 DCHECK_EQ(menu_, source); |
| 184 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT); | 186 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT); |
| 185 } | 187 } |
| 186 | 188 |
| 187 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { | 189 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { |
| 188 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; | 190 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; |
| 189 } | 191 } |
| OLD | NEW |