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" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 infobar_icon_(NULL), | 89 infobar_icon_(NULL), |
90 icon_as_menu_(NULL), | 90 icon_as_menu_(NULL), |
91 icon_as_image_(NULL), | 91 icon_as_image_(NULL), |
92 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
93 } | 93 } |
94 | 94 |
95 ExtensionInfoBar::~ExtensionInfoBar() { | 95 ExtensionInfoBar::~ExtensionInfoBar() { |
96 } | 96 } |
97 | 97 |
98 void ExtensionInfoBar::Layout() { | 98 void ExtensionInfoBar::Layout() { |
| 99 DCHECK(owner()); |
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 = GetExtensionView(); | 103 ExtensionViewViews* extension_view = GetExtensionView(); |
103 // 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 |
104 // 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, |
105 // 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() |
106 // 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 |
107 // here. | 108 // here. |
108 extension_view->SetSize( | 109 const infobars::InfoBarConstants& constants = owner()->GetInfoBarConstants(); |
109 gfx::Size(std::max(0, EndX() - StartX() - NonExtensionViewWidth()), | 110 extension_view->SetSize(gfx::Size( |
110 std::min(height() - kSeparatorLineHeight - arrow_height(), | 111 std::max(0, EndX() - StartX() - NonExtensionViewWidth()), |
111 GetDelegate()->height()))); | 112 std::min(height() - constants.separator_line_height - arrow_height(), |
| 113 GetDelegate()->height()))); |
112 // We do SetPosition() separately after SetSize() so OffsetY() will work. | 114 // We do SetPosition() separately after SetSize() so OffsetY() will work. |
113 extension_view->SetPosition( | 115 extension_view->SetPosition( |
114 gfx::Point(infobar_icon_->bounds().right() + kIconHorizontalMargin, | 116 gfx::Point(infobar_icon_->bounds().right() + kIconHorizontalMargin, |
115 std::max(arrow_height(), OffsetY(extension_view)))); | 117 std::max(arrow_height(), OffsetY(extension_view)))); |
116 } | 118 } |
117 | 119 |
118 void ExtensionInfoBar::ViewHierarchyChanged( | 120 void ExtensionInfoBar::ViewHierarchyChanged( |
119 const ViewHierarchyChangedDetails& details) { | 121 const ViewHierarchyChangedDetails& details) { |
120 if (!details.is_add || (details.child != this) || (infobar_icon_ != NULL)) { | 122 if (!details.is_add || (details.child != this) || (infobar_icon_ != NULL)) { |
121 InfoBarView::ViewHierarchyChanged(details); | 123 InfoBarView::ViewHierarchyChanged(details); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 228 } |
227 | 229 |
228 ExtensionViewViews* ExtensionInfoBar::GetExtensionView() { | 230 ExtensionViewViews* ExtensionInfoBar::GetExtensionView() { |
229 return static_cast<ExtensionViewViews*>( | 231 return static_cast<ExtensionViewViews*>( |
230 GetDelegate()->extension_view_host()->view()); | 232 GetDelegate()->extension_view_host()->view()); |
231 } | 233 } |
232 | 234 |
233 int ExtensionInfoBar::NonExtensionViewWidth() const { | 235 int ExtensionInfoBar::NonExtensionViewWidth() const { |
234 return infobar_icon_->width() + kIconHorizontalMargin; | 236 return infobar_icon_->width() + kIconHorizontalMargin; |
235 } | 237 } |
OLD | NEW |