| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_view.h" | 5 #include "chrome/browser/ui/views/extensions/extension_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
| 8 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 8 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 9 #include "content/browser/renderer_host/render_view_host.h" | 9 #include "content/browser/renderer_host/render_view_host.h" |
| 10 #include "content/browser/renderer_host/render_widget_host_view.h" | 10 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "content/browser/tab_contents/tab_contents_view.h" |
| 11 #include "content/public/browser/content_browser_client.h" | 13 #include "content/public/browser/content_browser_client.h" |
| 12 #include "views/widget/widget.h" | 14 #include "views/widget/widget.h" |
| 13 | 15 |
| 14 #if defined(USE_AURA) | |
| 15 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | |
| 16 #elif defined(TOUCH_UI) | |
| 17 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" | |
| 18 #elif defined(TOOLKIT_USES_GTK) | |
| 19 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" | |
| 20 #elif defined(OS_WIN) | |
| 21 #include "content/browser/renderer_host/render_widget_host_view_win.h" | |
| 22 #endif | |
| 23 | |
| 24 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) | 16 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) |
| 25 : host_(host), | 17 : host_(host), |
| 26 browser_(browser), | 18 browser_(browser), |
| 27 initialized_(false), | 19 initialized_(false), |
| 28 container_(NULL), | 20 container_(NULL), |
| 29 is_clipped_(false) { | 21 is_clipped_(false) { |
| 30 host_->set_view(this); | 22 host_->set_view(this); |
| 31 | 23 |
| 32 // This view needs to be focusable so it can act as the focused view for the | 24 // This view needs to be focusable so it can act as the focused view for the |
| 33 // focus manager. This is required to have SkipDefaultKeyEventProcessing | 25 // focus manager. This is required to have SkipDefaultKeyEventProcessing |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 render_view_host()->view()->Show(); | 69 render_view_host()->view()->Show(); |
| 78 else | 70 else |
| 79 render_view_host()->view()->Hide(); | 71 render_view_host()->view()->Hide(); |
| 80 } | 72 } |
| 81 } | 73 } |
| 82 } | 74 } |
| 83 | 75 |
| 84 void ExtensionView::CreateWidgetHostView() { | 76 void ExtensionView::CreateWidgetHostView() { |
| 85 DCHECK(!initialized_); | 77 DCHECK(!initialized_); |
| 86 initialized_ = true; | 78 initialized_ = true; |
| 87 RenderWidgetHostView* view = | 79 host_->CreateRenderViewSoon(); |
| 88 content::GetContentClient()->browser()->CreateViewForWidget( | 80 SetVisible(false); |
| 89 render_view_host()); | |
| 90 | 81 |
| 91 // TODO(mpcomplete): RWHV needs a cross-platform Init function. | 82 Attach(host_->host_contents()->view()->GetNativeView()); |
| 92 #if defined(USE_AURA) | |
| 93 static_cast<RenderWidgetHostViewAura*>(view)->InitAsChild(); | |
| 94 #elif defined(TOUCH_UI) | |
| 95 static_cast<RenderWidgetHostViewViews*>(view)->InitAsChild(); | |
| 96 #elif defined(TOOLKIT_USES_GTK) | |
| 97 static_cast<RenderWidgetHostViewGtk*>(view)->InitAsChild(); | |
| 98 #elif defined(OS_WIN) | |
| 99 // Create the HWND. Note: | |
| 100 // RenderWidgetHostHWND supports windowed plugins, but if we ever also | |
| 101 // wanted to support constrained windows with this, we would need an | |
| 102 // additional HWND to parent off of because windowed plugin HWNDs cannot | |
| 103 // exist in the same z-order as constrained windows. | |
| 104 RenderWidgetHostViewWin* view_win = | |
| 105 static_cast<RenderWidgetHostViewWin*>(view); | |
| 106 view_win->Create(GetWidget()->GetNativeView()); | |
| 107 view_win->ShowWindow(SW_SHOW); | |
| 108 #else | |
| 109 NOTIMPLEMENTED(); | |
| 110 #endif | |
| 111 | |
| 112 Attach(view->GetNativeView()); | |
| 113 host_->CreateRenderViewSoon(view); | |
| 114 SetVisible(false); | |
| 115 } | 83 } |
| 116 | 84 |
| 117 void ExtensionView::ShowIfCompletelyLoaded() { | 85 void ExtensionView::ShowIfCompletelyLoaded() { |
| 118 if (IsVisible() || is_clipped_) | 86 if (IsVisible() || is_clipped_) |
| 119 return; | 87 return; |
| 120 | 88 |
| 121 // We wait to show the ExtensionView until it has loaded, and the view has | 89 // We wait to show the ExtensionView until it has loaded, and the view has |
| 122 // actually been created. These can happen in different orders. | 90 // actually been created. These can happen in different orders. |
| 123 if (host_->did_stop_loading()) { | 91 if (host_->did_stop_loading()) { |
| 124 SetVisible(true); | 92 SetVisible(true); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 145 | 113 |
| 146 void ExtensionView::UpdatePreferredSize(const gfx::Size& new_size) { | 114 void ExtensionView::UpdatePreferredSize(const gfx::Size& new_size) { |
| 147 // Don't actually do anything with this information until we have been shown. | 115 // Don't actually do anything with this information until we have been shown. |
| 148 // Size changes will not be honored by lower layers while we are hidden. | 116 // Size changes will not be honored by lower layers while we are hidden. |
| 149 if (!IsVisible()) { | 117 if (!IsVisible()) { |
| 150 pending_preferred_size_ = new_size; | 118 pending_preferred_size_ = new_size; |
| 151 return; | 119 return; |
| 152 } | 120 } |
| 153 | 121 |
| 154 gfx::Size preferred_size = GetPreferredSize(); | 122 gfx::Size preferred_size = GetPreferredSize(); |
| 155 if (new_size != preferred_size) | 123 if (new_size != preferred_size) { |
| 156 SetPreferredSize(new_size); | 124 SetPreferredSize(new_size); |
| 125 host_->host_contents()->view()->SizeContents(new_size); |
| 126 } |
| 157 } | 127 } |
| 158 | 128 |
| 159 void ExtensionView::ViewHierarchyChanged(bool is_add, | 129 void ExtensionView::ViewHierarchyChanged(bool is_add, |
| 160 views::View *parent, | 130 views::View *parent, |
| 161 views::View *child) { | 131 views::View *child) { |
| 162 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); | 132 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); |
| 163 if (is_add && GetWidget() && !initialized_) | 133 if (is_add && GetWidget() && !initialized_) |
| 164 CreateWidgetHostView(); | 134 CreateWidgetHostView(); |
| 165 } | 135 } |
| 166 | 136 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 179 return (e.key_code() == ui::VKEY_TAB || e.key_code() == ui::VKEY_BACK); | 149 return (e.key_code() == ui::VKEY_TAB || e.key_code() == ui::VKEY_BACK); |
| 180 } | 150 } |
| 181 | 151 |
| 182 void ExtensionView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 152 void ExtensionView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 183 // Propagate the new size to RenderWidgetHostView. | 153 // Propagate the new size to RenderWidgetHostView. |
| 184 // We can't send size zero because RenderWidget DCHECKs that. | 154 // We can't send size zero because RenderWidget DCHECKs that. |
| 185 if (render_view_host()->view() && !bounds().IsEmpty()) | 155 if (render_view_host()->view() && !bounds().IsEmpty()) |
| 186 render_view_host()->view()->SetSize(size()); | 156 render_view_host()->view()->SetSize(size()); |
| 187 } | 157 } |
| 188 | 158 |
| 189 void ExtensionView::HandleMouseMove() { | |
| 190 if (container_) | |
| 191 container_->OnExtensionMouseMove(this); | |
| 192 } | |
| 193 | |
| 194 void ExtensionView::HandleMouseLeave() { | |
| 195 if (container_) | |
| 196 container_->OnExtensionMouseLeave(this); | |
| 197 } | |
| 198 | |
| 199 void ExtensionView::RenderViewCreated() { | 159 void ExtensionView::RenderViewCreated() { |
| 200 if (!pending_background_.empty() && render_view_host()->view()) { | 160 if (!pending_background_.empty() && render_view_host()->view()) { |
| 201 render_view_host()->view()->SetBackground(pending_background_); | 161 render_view_host()->view()->SetBackground(pending_background_); |
| 202 pending_background_.reset(); | 162 pending_background_.reset(); |
| 203 } | 163 } |
| 204 | 164 |
| 205 // Tell the renderer not to draw scroll bars in popups unless the | 165 // Tell the renderer not to draw scroll bars in popups unless the |
| 206 // popups are at the maximum allowed size. | 166 // popups are at the maximum allowed size. |
| 207 gfx::Size largest_popup_size(ExtensionPopup::kMaxWidth, | 167 gfx::Size largest_popup_size(ExtensionPopup::kMaxWidth, |
| 208 ExtensionPopup::kMaxHeight); | 168 ExtensionPopup::kMaxHeight); |
| 209 host_->DisableScrollbarsForSmallWindows(largest_popup_size); | 169 host_->DisableScrollbarsForSmallWindows(largest_popup_size); |
| 210 } | 170 } |
| OLD | NEW |