| 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(OS_WIN) | |
| 15 #include "content/browser/renderer_host/render_widget_host_view_win.h" | |
| 16 #elif defined(TOUCH_UI) || defined(USE_AURA) | |
| 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 #endif | |
| 21 | |
| 22 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) | 16 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) |
| 23 : host_(host), | 17 : host_(host), |
| 24 browser_(browser), | 18 browser_(browser), |
| 25 initialized_(false), | 19 initialized_(false), |
| 26 container_(NULL), | 20 container_(NULL), |
| 27 is_clipped_(false) { | 21 is_clipped_(false) { |
| 28 host_->set_view(this); | 22 host_->set_view(this); |
| 29 | 23 |
| 30 // 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 |
| 31 // 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... |
| 75 render_view_host()->view()->Show(); | 69 render_view_host()->view()->Show(); |
| 76 else | 70 else |
| 77 render_view_host()->view()->Hide(); | 71 render_view_host()->view()->Hide(); |
| 78 } | 72 } |
| 79 } | 73 } |
| 80 } | 74 } |
| 81 | 75 |
| 82 void ExtensionView::CreateWidgetHostView() { | 76 void ExtensionView::CreateWidgetHostView() { |
| 83 DCHECK(!initialized_); | 77 DCHECK(!initialized_); |
| 84 initialized_ = true; | 78 initialized_ = true; |
| 85 RenderWidgetHostView* view = | 79 host_->CreateRenderViewSoon(); |
| 86 content::GetContentClient()->browser()->CreateViewForWidget( | 80 SetVisible(false); |
| 87 render_view_host()); | |
| 88 | 81 |
| 89 // TODO(mpcomplete): RWHV needs a cross-platform Init function. | 82 Attach(host_->host_contents()->view()->GetNativeView()); |
| 90 #if defined(USE_AURA) | |
| 91 // TODO(beng): should be same as TOUCH_UI | |
| 92 NOTIMPLEMENTED(); | |
| 93 #elif defined(OS_WIN) | |
| 94 // Create the HWND. Note: | |
| 95 // RenderWidgetHostHWND supports windowed plugins, but if we ever also | |
| 96 // wanted to support constrained windows with this, we would need an | |
| 97 // additional HWND to parent off of because windowed plugin HWNDs cannot | |
| 98 // exist in the same z-order as constrained windows. | |
| 99 RenderWidgetHostViewWin* view_win = | |
| 100 static_cast<RenderWidgetHostViewWin*>(view); | |
| 101 HWND hwnd = view_win->Create(GetWidget()->GetNativeView()); | |
| 102 view_win->ShowWindow(SW_SHOW); | |
| 103 Attach(hwnd); | |
| 104 #elif defined(TOUCH_UI) | |
| 105 RenderWidgetHostViewViews* view_views = | |
| 106 static_cast<RenderWidgetHostViewViews*>(view); | |
| 107 view_views->InitAsChild(); | |
| 108 AttachToView(view_views); | |
| 109 #elif defined(TOOLKIT_USES_GTK) | |
| 110 RenderWidgetHostViewGtk* view_gtk = | |
| 111 static_cast<RenderWidgetHostViewGtk*>(view); | |
| 112 view_gtk->InitAsChild(); | |
| 113 Attach(view_gtk->GetNativeView()); | |
| 114 #else | |
| 115 NOTIMPLEMENTED(); | |
| 116 #endif | |
| 117 | |
| 118 host_->CreateRenderViewSoon(view); | |
| 119 SetVisible(false); | |
| 120 } | 83 } |
| 121 | 84 |
| 122 void ExtensionView::ShowIfCompletelyLoaded() { | 85 void ExtensionView::ShowIfCompletelyLoaded() { |
| 123 if (IsVisible() || is_clipped_) | 86 if (IsVisible() || is_clipped_) |
| 124 return; | 87 return; |
| 125 | 88 |
| 126 // 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 |
| 127 // actually been created. These can happen in different orders. | 90 // actually been created. These can happen in different orders. |
| 128 if (host_->did_stop_loading()) { | 91 if (host_->did_stop_loading()) { |
| 129 SetVisible(true); | 92 SetVisible(true); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 150 | 113 |
| 151 void ExtensionView::UpdatePreferredSize(const gfx::Size& new_size) { | 114 void ExtensionView::UpdatePreferredSize(const gfx::Size& new_size) { |
| 152 // 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. |
| 153 // 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. |
| 154 if (!IsVisible()) { | 117 if (!IsVisible()) { |
| 155 pending_preferred_size_ = new_size; | 118 pending_preferred_size_ = new_size; |
| 156 return; | 119 return; |
| 157 } | 120 } |
| 158 | 121 |
| 159 gfx::Size preferred_size = GetPreferredSize(); | 122 gfx::Size preferred_size = GetPreferredSize(); |
| 160 if (new_size != preferred_size) | 123 if (new_size != preferred_size) { |
| 161 SetPreferredSize(new_size); | 124 SetPreferredSize(new_size); |
| 125 host_->host_contents()->view()->SizeContents(new_size); |
| 126 } |
| 162 } | 127 } |
| 163 | 128 |
| 164 void ExtensionView::ViewHierarchyChanged(bool is_add, | 129 void ExtensionView::ViewHierarchyChanged(bool is_add, |
| 165 views::View *parent, | 130 views::View *parent, |
| 166 views::View *child) { | 131 views::View *child) { |
| 167 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); | 132 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); |
| 168 if (is_add && GetWidget() && !initialized_) | 133 if (is_add && GetWidget() && !initialized_) |
| 169 CreateWidgetHostView(); | 134 CreateWidgetHostView(); |
| 170 } | 135 } |
| 171 | 136 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 184 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); |
| 185 } | 150 } |
| 186 | 151 |
| 187 void ExtensionView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 152 void ExtensionView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 188 // Propagate the new size to RenderWidgetHostView. | 153 // Propagate the new size to RenderWidgetHostView. |
| 189 // We can't send size zero because RenderWidget DCHECKs that. | 154 // We can't send size zero because RenderWidget DCHECKs that. |
| 190 if (render_view_host()->view() && !bounds().IsEmpty()) | 155 if (render_view_host()->view() && !bounds().IsEmpty()) |
| 191 render_view_host()->view()->SetSize(size()); | 156 render_view_host()->view()->SetSize(size()); |
| 192 } | 157 } |
| 193 | 158 |
| 194 void ExtensionView::HandleMouseMove() { | |
| 195 if (container_) | |
| 196 container_->OnExtensionMouseMove(this); | |
| 197 } | |
| 198 | |
| 199 void ExtensionView::HandleMouseLeave() { | |
| 200 if (container_) | |
| 201 container_->OnExtensionMouseLeave(this); | |
| 202 } | |
| 203 | |
| 204 void ExtensionView::RenderViewCreated() { | 159 void ExtensionView::RenderViewCreated() { |
| 205 if (!pending_background_.empty() && render_view_host()->view()) { | 160 if (!pending_background_.empty() && render_view_host()->view()) { |
| 206 render_view_host()->view()->SetBackground(pending_background_); | 161 render_view_host()->view()->SetBackground(pending_background_); |
| 207 pending_background_.reset(); | 162 pending_background_.reset(); |
| 208 } | 163 } |
| 209 | 164 |
| 210 // 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 |
| 211 // popups are at the maximum allowed size. | 166 // popups are at the maximum allowed size. |
| 212 gfx::Size largest_popup_size(ExtensionPopup::kMaxWidth, | 167 gfx::Size largest_popup_size(ExtensionPopup::kMaxWidth, |
| 213 ExtensionPopup::kMaxHeight); | 168 ExtensionPopup::kMaxHeight); |
| 214 host_->DisableScrollbarsForSmallWindows(largest_popup_size); | 169 host_->DisableScrollbarsForSmallWindows(largest_popup_size); |
| 215 } | 170 } |
| OLD | NEW |