| 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/infobars/extension_infobar.h" | 5 #include "chrome/browser/views/infobars/extension_infobar.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 "chrome/browser/extensions/extension_action_context_menu_model.h" | 10 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 11 #include "chrome/browser/extensions/extension_infobar_delegate.h" | 11 #include "chrome/browser/extensions/extension_infobar_delegate.h" |
| 12 #include "chrome/browser/extensions/extension_host.h" | 12 #include "chrome/browser/extensions/extension_host.h" |
| 13 #include "chrome/browser/views/frame/browser_view.h" |
| 13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 14 #include "grit/browser_resources.h" | 15 #include "grit/browser_resources.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #include "views/controls/button/menu_button.h" | 17 #include "views/controls/button/menu_button.h" |
| 17 #include "views/controls/menu/menu_2.h" | 18 #include "views/controls/menu/menu_2.h" |
| 19 #include "views/widget/widget.h" |
| 18 | 20 |
| 19 // The horizontal margin between the menu and the Extension (HTML) view. | 21 // The horizontal margin between the menu and the Extension (HTML) view. |
| 20 static const int kMenuHorizontalMargin = 1; | 22 static const int kMenuHorizontalMargin = 1; |
| 21 | 23 |
| 22 // The amount of space to the right of the Extension (HTML) view (to avoid | 24 // The amount of space to the right of the Extension (HTML) view (to avoid |
| 23 // overlapping the close button for the InfoBar). | 25 // overlapping the close button for the InfoBar). |
| 24 static const int kFarRightMargin = 30; | 26 static const int kFarRightMargin = 30; |
| 25 | 27 |
| 26 // The margin between the extension icon and the drop-down arrow bitmap. | 28 // The margin between the extension icon and the drop-down arrow bitmap. |
| 27 static const int kDropArrowLeftMargin = 3; | 29 static const int kDropArrowLeftMargin = 3; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 (height() - sz.height()) / 2, | 84 (height() - sz.height()) / 2, |
| 83 sz.width(), sz.height()); | 85 sz.width(), sz.height()); |
| 84 x += sz.width() + kMenuHorizontalMargin; | 86 x += sz.width() + kMenuHorizontalMargin; |
| 85 | 87 |
| 86 // Layout the ExtensionView, showing the HTML InfoBar. | 88 // Layout the ExtensionView, showing the HTML InfoBar. |
| 87 ExtensionView* view = delegate_->extension_host()->view(); | 89 ExtensionView* view = delegate_->extension_host()->view(); |
| 88 view->SetBounds(x, 0, width() - x - kFarRightMargin - 1, height() - 1); | 90 view->SetBounds(x, 0, width() - x - kFarRightMargin - 1, height() - 1); |
| 89 } | 91 } |
| 90 | 92 |
| 91 void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) { | 93 void ExtensionInfoBar::RunMenu(View* source, const gfx::Point& pt) { |
| 92 if (!options_menu_contents_.get()) | 94 if (!options_menu_contents_.get()) { |
| 93 options_menu_contents_.reset(new ExtensionActionContextMenuModel( | 95 Browser* browser = BrowserView::GetBrowserViewForNativeWindow( |
| 94 delegate_->extension_host()->extension(), | 96 ::GetAncestor(source->GetWidget()->GetNativeView(), GA_ROOT))-> |
| 95 // Do not include "Inspect Popup" in menu: | 97 browser(); |
| 96 NULL, // ExtensionAction | 98 options_menu_contents_.reset(new ExtensionContextMenuModel( |
| 97 NULL, // PrefService | 99 delegate_->extension_host()->extension(), browser, NULL)); |
| 98 NULL)); // ExtensionActionContextMenuModel::MenuDelegate | 100 } |
| 99 | 101 |
| 100 options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get())); | 102 options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get())); |
| 101 options_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPLEFT); | 103 options_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPLEFT); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void ExtensionInfoBar::SetupIconAndMenu() { | 106 void ExtensionInfoBar::SetupIconAndMenu() { |
| 105 SkBitmap icon; | 107 SkBitmap icon; |
| 106 | 108 |
| 107 ExtensionResource icon_resource; | 109 ExtensionResource icon_resource; |
| 108 Extension::Icons size = delegate_->extension_host()->extension()-> | 110 Extension::Icons size = delegate_->extension_host()->extension()-> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 138 image_size + kDropArrowLeftMargin, | 140 image_size + kDropArrowLeftMargin, |
| 139 image_size / 2); | 141 image_size / 2); |
| 140 menu_->SetIcon(canvas->ExtractBitmap()); | 142 menu_->SetIcon(canvas->ExtractBitmap()); |
| 141 | 143 |
| 142 AddChildView(menu_); | 144 AddChildView(menu_); |
| 143 } | 145 } |
| 144 | 146 |
| 145 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { | 147 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { |
| 146 return new ExtensionInfoBar(this); | 148 return new ExtensionInfoBar(this); |
| 147 } | 149 } |
| OLD | NEW |