| 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/infobars/infobar_tab_helper.h" | 10 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 GetDelegate()->set_observer(NULL); | 94 GetDelegate()->set_observer(NULL); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ExtensionInfoBar::Layout() { | 97 void ExtensionInfoBar::Layout() { |
| 98 InfoBarView::Layout(); | 98 InfoBarView::Layout(); |
| 99 | 99 |
| 100 gfx::Size menu_size = menu_->GetPreferredSize(); | 100 gfx::Size menu_size = menu_->GetPreferredSize(); |
| 101 menu_->SetBounds(StartX(), OffsetY(menu_size), menu_size.width(), | 101 menu_->SetBounds(StartX(), OffsetY(menu_size), menu_size.width(), |
| 102 menu_size.height()); | 102 menu_size.height()); |
| 103 | 103 |
| 104 GetDelegate()->extension_host()->view()->SetBounds( | 104 ExtensionViewViews* view = static_cast<ExtensionViewViews*>( |
| 105 menu_->bounds().right() + kMenuHorizontalMargin, | 105 GetDelegate()->extension_host()->GetExtensionView()); |
| 106 arrow_height(), | 106 view->SetBounds(menu_->bounds().right() + kMenuHorizontalMargin, |
| 107 std::max(0, EndX() - StartX() - ContentMinimumWidth()), | 107 arrow_height(), |
| 108 height() - arrow_height() - 1); | 108 std::max(0, EndX() - StartX() - ContentMinimumWidth()), |
| 109 height() - arrow_height() - 1); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void ExtensionInfoBar::ViewHierarchyChanged(bool is_add, | 112 void ExtensionInfoBar::ViewHierarchyChanged(bool is_add, |
| 112 views::View* parent, | 113 views::View* parent, |
| 113 views::View* child) { | 114 views::View* child) { |
| 114 if (!is_add || (child != this) || (menu_ != NULL)) { | 115 if (!is_add || (child != this) || (menu_ != NULL)) { |
| 115 InfoBarView::ViewHierarchyChanged(is_add, parent, child); | 116 InfoBarView::ViewHierarchyChanged(is_add, parent, child); |
| 116 return; | 117 return; |
| 117 } | 118 } |
| 118 | 119 |
| 119 menu_ = new views::MenuButton(NULL, string16(), this, false); | 120 menu_ = new views::MenuButton(NULL, string16(), this, false); |
| 120 menu_->SetVisible(false); | 121 menu_->SetVisible(false); |
| 121 menu_->set_focusable(true); | 122 menu_->set_focusable(true); |
| 122 AddChildView(menu_); | 123 AddChildView(menu_); |
| 123 | 124 |
| 124 extensions::ExtensionHost* extension_host = GetDelegate()->extension_host(); | 125 extensions::ExtensionHost* extension_host = GetDelegate()->extension_host(); |
| 125 AddChildView(extension_host->view()); | 126 ExtensionViewViews* view = |
| 127 static_cast<ExtensionViewViews*>(extension_host->GetExtensionView()); |
| 128 AddChildView(view); |
| 126 | 129 |
| 127 // This must happen after adding all other children so InfoBarView can ensure | 130 // This must happen after adding all other children so InfoBarView can ensure |
| 128 // the close button is the last child. | 131 // the close button is the last child. |
| 129 InfoBarView::ViewHierarchyChanged(is_add, parent, child); | 132 InfoBarView::ViewHierarchyChanged(is_add, parent, child); |
| 130 | 133 |
| 131 // This must happen after adding all children because it can trigger layout, | 134 // This must happen after adding all children because it can trigger layout, |
| 132 // which assumes that particular children (e.g. the close button) have already | 135 // which assumes that particular children (e.g. the close button) have already |
| 133 // been added. | 136 // been added. |
| 134 const extensions::Extension* extension = extension_host->extension(); | 137 const extensions::Extension* extension = extension_host->extension(); |
| 135 extension_misc::ExtensionIcons image_size = | 138 extension_misc::ExtensionIcons image_size = |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 187 |
| 185 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = | 188 scoped_refptr<ExtensionContextMenuModel> options_menu_contents = |
| 186 new ExtensionContextMenuModel(extension, browser_); | 189 new ExtensionContextMenuModel(extension, browser_); |
| 187 DCHECK_EQ(menu_, source); | 190 DCHECK_EQ(menu_, source); |
| 188 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT); | 191 RunMenuAt(options_menu_contents.get(), menu_, views::MenuItemView::TOPLEFT); |
| 189 } | 192 } |
| 190 | 193 |
| 191 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { | 194 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { |
| 192 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; | 195 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; |
| 193 } | 196 } |
| OLD | NEW |