| 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/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 "chrome/common/chrome_view_type.h" |
| 9 #include "content/public/browser/content_browser_client.h" | 10 #include "content/public/browser/content_browser_client.h" |
| 10 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 11 #include "content/public/browser/render_widget_host_view.h" | 12 #include "content/public/browser/render_widget_host_view.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_view.h" | 14 #include "content/public/browser/web_contents_view.h" |
| 14 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 15 | 16 |
| 16 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) | 17 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) |
| 17 : host_(host), | 18 : host_(host), |
| 18 browser_(browser), | 19 browser_(browser), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 83 } |
| 83 | 84 |
| 84 void ExtensionView::ShowIfCompletelyLoaded() { | 85 void ExtensionView::ShowIfCompletelyLoaded() { |
| 85 if (visible() || is_clipped_) | 86 if (visible() || is_clipped_) |
| 86 return; | 87 return; |
| 87 | 88 |
| 88 // 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 |
| 89 // actually been created. These can happen in different orders. | 90 // actually been created. These can happen in different orders. |
| 90 if (host_->did_stop_loading()) { | 91 if (host_->did_stop_loading()) { |
| 91 SetVisible(true); | 92 SetVisible(true); |
| 92 UpdatePreferredSize(pending_preferred_size_); | 93 ResizeDueToAutoResize(pending_preferred_size_); |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 | 96 |
| 96 void ExtensionView::CleanUp() { | 97 void ExtensionView::CleanUp() { |
| 97 if (!initialized_) | 98 if (!initialized_) |
| 98 return; | 99 return; |
| 99 if (native_view()) | 100 if (native_view()) |
| 100 Detach(); | 101 Detach(); |
| 101 initialized_ = false; | 102 initialized_ = false; |
| 102 } | 103 } |
| 103 | 104 |
| 104 void ExtensionView::SetBackground(const SkBitmap& background) { | 105 void ExtensionView::SetBackground(const SkBitmap& background) { |
| 105 if (render_view_host()->IsRenderViewLive() && render_view_host()->GetView()) { | 106 if (render_view_host()->IsRenderViewLive() && render_view_host()->GetView()) { |
| 106 render_view_host()->GetView()->SetBackground(background); | 107 render_view_host()->GetView()->SetBackground(background); |
| 107 } else { | 108 } else { |
| 108 pending_background_ = background; | 109 pending_background_ = background; |
| 109 } | 110 } |
| 110 ShowIfCompletelyLoaded(); | 111 ShowIfCompletelyLoaded(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 void ExtensionView::UpdatePreferredSize(const gfx::Size& new_size) { | 114 void ExtensionView::ResizeDueToAutoResize(const gfx::Size& new_size) { |
| 114 // 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. |
| 115 // 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. |
| 116 if (!visible()) { | 117 if (!visible()) { |
| 117 pending_preferred_size_ = new_size; | 118 pending_preferred_size_ = new_size; |
| 118 return; | 119 return; |
| 119 } | 120 } |
| 120 | 121 |
| 121 gfx::Size preferred_size = GetPreferredSize(); | 122 gfx::Size preferred_size = GetPreferredSize(); |
| 122 if (new_size != preferred_size) | 123 if (new_size != preferred_size) |
| 123 SetPreferredSize(new_size); | 124 SetPreferredSize(new_size); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void ExtensionView::ViewHierarchyChanged(bool is_add, | 127 void ExtensionView::ViewHierarchyChanged(bool is_add, |
| 127 views::View *parent, | 128 views::View *parent, |
| 128 views::View *child) { | 129 views::View *child) { |
| 129 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); | 130 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); |
| 130 if (is_add && GetWidget() && !initialized_) | 131 if (is_add && GetWidget() && !initialized_) |
| 131 CreateWidgetHostView(); | 132 CreateWidgetHostView(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void ExtensionView::PreferredSizeChanged() { | 135 void ExtensionView::PreferredSizeChanged() { |
| 135 View::PreferredSizeChanged(); | 136 View::PreferredSizeChanged(); |
| 136 if (container_) | 137 if (container_) |
| 137 container_->OnExtensionPreferredSizeChanged(this); | 138 container_->OnExtensionSizeChanged(this); |
| 138 } | 139 } |
| 139 | 140 |
| 140 bool ExtensionView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { | 141 bool ExtensionView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { |
| 141 // Let the tab key event be processed by the renderer (instead of moving the | 142 // Let the tab key event be processed by the renderer (instead of moving the |
| 142 // focus to the next focusable view). Also handle Backspace, since otherwise | 143 // focus to the next focusable view). Also handle Backspace, since otherwise |
| 143 // (on Windows at least), pressing Backspace, when focus is on a text field | 144 // (on Windows at least), pressing Backspace, when focus is on a text field |
| 144 // within the ExtensionView, will navigate the page back instead of erasing a | 145 // within the ExtensionView, will navigate the page back instead of erasing a |
| 145 // character. | 146 // character. |
| 146 return (e.key_code() == ui::VKEY_TAB || e.key_code() == ui::VKEY_BACK); | 147 return (e.key_code() == ui::VKEY_TAB || e.key_code() == ui::VKEY_BACK); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void ExtensionView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 150 void ExtensionView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 150 // Propagate the new size to RenderWidgetHostView. | 151 // Propagate the new size to RenderWidgetHostView. |
| 151 // We can't send size zero because RenderWidget DCHECKs that. | 152 // We can't send size zero because RenderWidget DCHECKs that. |
| 152 if (render_view_host()->GetView() && !bounds().IsEmpty()) { | 153 if (render_view_host()->GetView() && !bounds().IsEmpty()) { |
| 153 render_view_host()->GetView()->SetSize(size()); | 154 render_view_host()->GetView()->SetSize(size()); |
| 154 | 155 |
| 155 if (container_) | 156 if (container_) |
| 156 container_->OnViewWasResized(); | 157 container_->OnViewWasResized(); |
| 157 } | 158 } |
| 158 } | 159 } |
| 159 | 160 |
| 160 void ExtensionView::RenderViewCreated() { | 161 void ExtensionView::RenderViewCreated() { |
| 161 if (!pending_background_.empty() && render_view_host()->GetView()) { | 162 if (!pending_background_.empty() && render_view_host()->GetView()) { |
| 162 render_view_host()->GetView()->SetBackground(pending_background_); | 163 render_view_host()->GetView()->SetBackground(pending_background_); |
| 163 pending_background_.reset(); | 164 pending_background_.reset(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // Tell the renderer not to draw scroll bars in popups unless the | 167 content::ViewType host_type = host_->extension_host_type(); |
| 167 // popups are at the maximum allowed size. | 168 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
| 168 gfx::Size largest_popup_size(ExtensionPopup::kMaxWidth, | 169 gfx::Size min_size(ExtensionPopup::kMinWidth, |
| 169 ExtensionPopup::kMaxHeight); | 170 ExtensionPopup::kMinHeight); |
| 170 host_->DisableScrollbarsForSmallWindows(largest_popup_size); | 171 gfx::Size max_size(ExtensionPopup::kMaxWidth, |
| 172 ExtensionPopup::kMaxHeight); |
| 173 render_view_host()->EnableAutoResize(min_size, max_size); |
| 174 } |
| 171 | 175 |
| 172 if (container_) | 176 if (container_) |
| 173 container_->OnViewWasResized(); | 177 container_->OnViewWasResized(); |
| 174 } | 178 } |
| OLD | NEW |