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_infobar_delegate.h" | 8 #include "chrome/browser/extensions/extension_infobar_delegate.h" |
9 #include "chrome/browser/extensions/extension_view_host.h" | 9 #include "chrome/browser/extensions/extension_view_host.h" |
10 #include "chrome/browser/platform_util.h" | 10 #include "chrome/browser/platform_util.h" |
| 11 #include "chrome/browser/ui/views/extensions/extension_view_views.h" |
11 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
12 #include "extensions/browser/image_loader.h" | 13 #include "extensions/browser/image_loader.h" |
13 #include "extensions/common/constants.h" | 14 #include "extensions/common/constants.h" |
14 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
15 #include "extensions/common/extension_icon_set.h" | 16 #include "extensions/common/extension_icon_set.h" |
16 #include "extensions/common/extension_resource.h" | 17 #include "extensions/common/extension_resource.h" |
17 #include "extensions/common/manifest_handlers/icons_handler.h" | 18 #include "extensions/common/manifest_handlers/icons_handler.h" |
18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/animation/slide_animation.h" | 21 #include "ui/gfx/animation/slide_animation.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 weak_ptr_factory_(this) { | 93 weak_ptr_factory_(this) { |
93 } | 94 } |
94 | 95 |
95 ExtensionInfoBar::~ExtensionInfoBar() { | 96 ExtensionInfoBar::~ExtensionInfoBar() { |
96 } | 97 } |
97 | 98 |
98 void ExtensionInfoBar::Layout() { | 99 void ExtensionInfoBar::Layout() { |
99 InfoBarView::Layout(); | 100 InfoBarView::Layout(); |
100 | 101 |
101 infobar_icon_->SetPosition(gfx::Point(StartX(), OffsetY(infobar_icon_))); | 102 infobar_icon_->SetPosition(gfx::Point(StartX(), OffsetY(infobar_icon_))); |
102 ExtensionViewViews* extension_view = | 103 ExtensionViewViews* extension_view = GetExtensionView(); |
103 GetDelegate()->extension_view_host()->view(); | |
104 // TODO(pkasting): We'd like to simply set the extension view's desired height | 104 // TODO(pkasting): We'd like to simply set the extension view's desired height |
105 // at creation time and position using OffsetY() like for other infobar items, | 105 // at creation time and position using OffsetY() like for other infobar items, |
106 // but the NativeViewHost inside does not seem to be clipped by the ClipRect() | 106 // but the NativeViewHost inside does not seem to be clipped by the ClipRect() |
107 // call in InfoBarView::PaintChildren(), so we have to manually clamp the size | 107 // call in InfoBarView::PaintChildren(), so we have to manually clamp the size |
108 // here. | 108 // here. |
109 extension_view->SetSize( | 109 extension_view->SetSize( |
110 gfx::Size(std::max(0, EndX() - StartX() - NonExtensionViewWidth()), | 110 gfx::Size(std::max(0, EndX() - StartX() - NonExtensionViewWidth()), |
111 std::min(height() - kSeparatorLineHeight - arrow_height(), | 111 std::min(height() - kSeparatorLineHeight - arrow_height(), |
112 GetDelegate()->height()))); | 112 GetDelegate()->height()))); |
113 // We do SetPosition() separately after SetSize() so OffsetY() will work. | 113 // We do SetPosition() separately after SetSize() so OffsetY() will work. |
(...skipping 22 matching lines...) Expand all Loading... |
136 } | 136 } |
137 | 137 |
138 // Wait until the icon image is loaded before showing it. | 138 // Wait until the icon image is loaded before showing it. |
139 infobar_icon_->SetVisible(false); | 139 infobar_icon_->SetVisible(false); |
140 AddChildView(infobar_icon_); | 140 AddChildView(infobar_icon_); |
141 | 141 |
142 // Set the desired height of the ExtensionViewViews, so that when the | 142 // Set the desired height of the ExtensionViewViews, so that when the |
143 // AddChildView() call triggers InfoBarView::ViewHierarchyChanged(), it can | 143 // AddChildView() call triggers InfoBarView::ViewHierarchyChanged(), it can |
144 // read the correct height off this object in order to calculate the overall | 144 // read the correct height off this object in order to calculate the overall |
145 // desired infobar height. | 145 // desired infobar height. |
146 extension_view_host->view()->SetSize(gfx::Size(0, GetDelegate()->height())); | 146 GetExtensionView()->SetSize(gfx::Size(0, GetDelegate()->height())); |
147 AddChildView(extension_view_host->view()); | 147 AddChildView(GetExtensionView()); |
148 | 148 |
149 // This must happen after adding all other children so InfoBarView can ensure | 149 // This must happen after adding all other children so InfoBarView can ensure |
150 // the close button is the last child. | 150 // the close button is the last child. |
151 InfoBarView::ViewHierarchyChanged(details); | 151 InfoBarView::ViewHierarchyChanged(details); |
152 | 152 |
153 // This must happen after adding all children because it can trigger layout, | 153 // This must happen after adding all children because it can trigger layout, |
154 // which assumes that particular children (e.g. the close button) have already | 154 // which assumes that particular children (e.g. the close button) have already |
155 // been added. | 155 // been added. |
156 const extensions::Extension* extension = extension_view_host->extension(); | 156 const extensions::Extension* extension = extension_view_host->extension(); |
157 extension_misc::ExtensionIcons image_size = | 157 extension_misc::ExtensionIcons image_size = |
158 extension_misc::EXTENSION_ICON_BITTY; | 158 extension_misc::EXTENSION_ICON_BITTY; |
159 extensions::ExtensionResource icon_resource = | 159 extensions::ExtensionResource icon_resource = |
160 extensions::IconsInfo::GetIconResource( | 160 extensions::IconsInfo::GetIconResource( |
161 extension, image_size, ExtensionIconSet::MATCH_EXACTLY); | 161 extension, image_size, ExtensionIconSet::MATCH_EXACTLY); |
162 extensions::ImageLoader* loader = | 162 extensions::ImageLoader* loader = |
163 extensions::ImageLoader::Get(extension_view_host->browser_context()); | 163 extensions::ImageLoader::Get(extension_view_host->browser_context()); |
164 loader->LoadImageAsync( | 164 loader->LoadImageAsync( |
165 extension, | 165 extension, |
166 icon_resource, | 166 icon_resource, |
167 gfx::Size(image_size, image_size), | 167 gfx::Size(image_size, image_size), |
168 base::Bind(&ExtensionInfoBar::OnImageLoaded, | 168 base::Bind(&ExtensionInfoBar::OnImageLoaded, |
169 weak_ptr_factory_.GetWeakPtr())); | 169 weak_ptr_factory_.GetWeakPtr())); |
170 } | 170 } |
171 | 171 |
172 int ExtensionInfoBar::ContentMinimumWidth() const { | 172 int ExtensionInfoBar::ContentMinimumWidth() const { |
173 return NonExtensionViewWidth() + | 173 return NonExtensionViewWidth() + static_cast<const ExtensionViewViews*>( |
174 delegate()->AsExtensionInfoBarDelegate()->extension_view_host()-> | 174 GetDelegate()->extension_view_host()->view())->GetMinimumSize().width(); |
175 view()->GetMinimumSize().width(); | |
176 } | 175 } |
177 | 176 |
178 void ExtensionInfoBar::OnMenuButtonClicked(views::View* source, | 177 void ExtensionInfoBar::OnMenuButtonClicked(views::View* source, |
179 const gfx::Point& point) { | 178 const gfx::Point& point) { |
180 if (!owner()) | 179 if (!owner()) |
181 return; // We're closing; don't call anything, it might access the owner. | 180 return; // We're closing; don't call anything, it might access the owner. |
182 const extensions::Extension* extension = | 181 const extensions::Extension* extension = |
183 GetDelegate()->extension_view_host()->extension(); | 182 GetDelegate()->extension_view_host()->extension(); |
184 DCHECK(icon_as_menu_); | 183 DCHECK(icon_as_menu_); |
185 | 184 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 219 } |
221 | 220 |
222 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { | 221 ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { |
223 return delegate()->AsExtensionInfoBarDelegate(); | 222 return delegate()->AsExtensionInfoBarDelegate(); |
224 } | 223 } |
225 | 224 |
226 const ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() const { | 225 const ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() const { |
227 return delegate()->AsExtensionInfoBarDelegate(); | 226 return delegate()->AsExtensionInfoBarDelegate(); |
228 } | 227 } |
229 | 228 |
| 229 ExtensionViewViews* ExtensionInfoBar::GetExtensionView() { |
| 230 return static_cast<ExtensionViewViews*>( |
| 231 GetDelegate()->extension_view_host()->view()); |
| 232 } |
| 233 |
230 int ExtensionInfoBar::NonExtensionViewWidth() const { | 234 int ExtensionInfoBar::NonExtensionViewWidth() const { |
231 return infobar_icon_->width() + kIconHorizontalMargin; | 235 return infobar_icon_->width() + kIconHorizontalMargin; |
232 } | 236 } |
OLD | NEW |