| 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/gtk/extensions/extension_popup_gtk.h" | 5 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "chrome/browser/debugger/devtools_window.h" | 16 #include "chrome/browser/debugger/devtools_window.h" |
| 17 #include "chrome/browser/extensions/extension_host.h" | 17 #include "chrome/browser/extensions/extension_host.h" |
| 18 #include "chrome/browser/extensions/extension_process_manager.h" | 18 #include "chrome/browser/extensions/extension_process_manager.h" |
| 19 #include "chrome/browser/extensions/extension_view.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 23 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
| 26 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
| 27 #include "content/public/browser/render_widget_host_view.h" | 28 #include "content/public/browser/render_widget_host_view.h" |
| 28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 41 | 42 |
| 42 ExtensionPopupGtk::ExtensionPopupGtk(Browser* browser, | 43 ExtensionPopupGtk::ExtensionPopupGtk(Browser* browser, |
| 43 extensions::ExtensionHost* host, | 44 extensions::ExtensionHost* host, |
| 44 GtkWidget* anchor, | 45 GtkWidget* anchor, |
| 45 ShowAction show_action) | 46 ShowAction show_action) |
| 46 : browser_(browser), | 47 : browser_(browser), |
| 47 bubble_(NULL), | 48 bubble_(NULL), |
| 48 host_(host), | 49 host_(host), |
| 49 anchor_(anchor), | 50 anchor_(anchor), |
| 50 weak_factory_(this) { | 51 weak_factory_(this) { |
| 51 host_->view()->SetContainer(this); | 52 host_->GetExtensionView()->SetContainer(this); |
| 52 being_inspected_ = show_action == SHOW_AND_INSPECT; | 53 being_inspected_ = show_action == SHOW_AND_INSPECT; |
| 53 | 54 |
| 54 // If the host had somehow finished loading, then we'd miss the notification | 55 // If the host had somehow finished loading, then we'd miss the notification |
| 55 // and not show. This seems to happen in single-process mode. | 56 // and not show. This seems to happen in single-process mode. |
| 56 if (host->did_stop_loading()) { | 57 if (host->did_stop_loading()) { |
| 57 ShowPopup(); | 58 ShowPopup(); |
| 58 } else { | 59 } else { |
| 59 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 60 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
| 60 content::Source<Profile>(host->profile())); | 61 content::Source<Profile>(host->profile())); |
| 61 } | 62 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 NOTREACHED() << "Received unexpected notification"; | 132 NOTREACHED() << "Received unexpected notification"; |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 | 135 |
| 135 void ExtensionPopupGtk::BubbleClosing(BubbleGtk* bubble, | 136 void ExtensionPopupGtk::BubbleClosing(BubbleGtk* bubble, |
| 136 bool closed_by_escape) { | 137 bool closed_by_escape) { |
| 137 current_extension_popup_ = NULL; | 138 current_extension_popup_ = NULL; |
| 138 delete this; | 139 delete this; |
| 139 } | 140 } |
| 140 | 141 |
| 141 void ExtensionPopupGtk::OnExtensionSizeChanged( | 142 void ExtensionPopupGtk::OnExtensionSizeChanged(ExtensionView* view, |
| 142 ExtensionViewGtk* view, | 143 const gfx::Size& new_size) { |
| 143 const gfx::Size& new_size) { | |
| 144 int width = std::max(kMinWidth, std::min(kMaxWidth, new_size.width())); | 144 int width = std::max(kMinWidth, std::min(kMaxWidth, new_size.width())); |
| 145 int height = std::max(kMinHeight, std::min(kMaxHeight, new_size.height())); | 145 int height = std::max(kMinHeight, std::min(kMaxHeight, new_size.height())); |
| 146 | 146 |
| 147 view->render_view_host()->GetView()->SetSize(gfx::Size(width, height)); | 147 view->GetRenderViewHost()->GetView()->SetSize(gfx::Size(width, height)); |
| 148 gtk_widget_set_size_request(view->native_view(), width, height); | 148 gtk_widget_set_size_request(view->GetNativeView(), width, height); |
| 149 } |
| 150 |
| 151 void ExtensionPopupGtk::OnExtensionViewDidShow(ExtensionView* view) { |
| 149 } | 152 } |
| 150 | 153 |
| 151 bool ExtensionPopupGtk::DestroyPopup() { | 154 bool ExtensionPopupGtk::DestroyPopup() { |
| 152 if (!bubble_) { | 155 if (!bubble_) { |
| 153 NOTREACHED(); | 156 NOTREACHED(); |
| 154 return false; | 157 return false; |
| 155 } | 158 } |
| 156 | 159 |
| 157 bubble_->Close(); | 160 bubble_->Close(); |
| 158 return true; | 161 return true; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 172 // non-NULL if a browser action button is clicked while another extension | 175 // non-NULL if a browser action button is clicked while another extension |
| 173 // popup's extension host is still loading. | 176 // popup's extension host is still loading. |
| 174 if (current_extension_popup_) | 177 if (current_extension_popup_) |
| 175 current_extension_popup_->DestroyPopup(); | 178 current_extension_popup_->DestroyPopup(); |
| 176 current_extension_popup_ = this; | 179 current_extension_popup_ = this; |
| 177 | 180 |
| 178 GtkWidget* border_box = gtk_alignment_new(0, 0, 1.0, 1.0); | 181 GtkWidget* border_box = gtk_alignment_new(0, 0, 1.0, 1.0); |
| 179 // This border is necessary so the bubble's corners do not get cut off by the | 182 // This border is necessary so the bubble's corners do not get cut off by the |
| 180 // render view. | 183 // render view. |
| 181 gtk_container_set_border_width(GTK_CONTAINER(border_box), 2); | 184 gtk_container_set_border_width(GTK_CONTAINER(border_box), 2); |
| 182 gtk_container_add(GTK_CONTAINER(border_box), host_->view()->native_view()); | 185 gtk_container_add(GTK_CONTAINER(border_box), |
| 186 host_->GetExtensionView()->GetNativeView()); |
| 183 | 187 |
| 184 // We'll be in the upper-right corner of the window for LTR languages, so we | 188 // We'll be in the upper-right corner of the window for LTR languages, so we |
| 185 // want to put the arrow at the upper-right corner of the bubble to match the | 189 // want to put the arrow at the upper-right corner of the bubble to match the |
| 186 // page and app menus. | 190 // page and app menus. |
| 187 BubbleGtk::ArrowLocationGtk arrow_location = | 191 BubbleGtk::ArrowLocationGtk arrow_location = |
| 188 !base::i18n::IsRTL() ? | 192 !base::i18n::IsRTL() ? |
| 189 BubbleGtk::ARROW_LOCATION_TOP_RIGHT : | 193 BubbleGtk::ARROW_LOCATION_TOP_RIGHT : |
| 190 BubbleGtk::ARROW_LOCATION_TOP_LEFT; | 194 BubbleGtk::ARROW_LOCATION_TOP_LEFT; |
| 191 bubble_ = BubbleGtk::Show(anchor_, | 195 bubble_ = BubbleGtk::Show(anchor_, |
| 192 NULL, | 196 NULL, |
| 193 border_box, | 197 border_box, |
| 194 arrow_location, | 198 arrow_location, |
| 195 being_inspected_ ? 0 : | 199 being_inspected_ ? 0 : |
| 196 BubbleGtk::POPUP_WINDOW | BubbleGtk::GRAB_INPUT, | 200 BubbleGtk::POPUP_WINDOW | BubbleGtk::GRAB_INPUT, |
| 197 GtkThemeService::GetFrom(browser_->profile()), | 201 GtkThemeService::GetFrom(browser_->profile()), |
| 198 this); | 202 this); |
| 199 } | 203 } |
| 200 | 204 |
| 201 void ExtensionPopupGtk::DestroyPopupWithoutResult() { | 205 void ExtensionPopupGtk::DestroyPopupWithoutResult() { |
| 202 DestroyPopup(); | 206 DestroyPopup(); |
| 203 } | 207 } |
| 204 | 208 |
| 205 gfx::Rect ExtensionPopupGtk::GetViewBounds() { | 209 gfx::Rect ExtensionPopupGtk::GetViewBounds() { |
| 206 GtkAllocation allocation; | 210 GtkAllocation allocation; |
| 207 gtk_widget_get_allocation(host_->view()->native_view(), &allocation); | 211 gtk_widget_get_allocation(host_->GetExtensionView()->GetNativeView(), |
| 212 &allocation); |
| 208 return gfx::Rect(allocation); | 213 return gfx::Rect(allocation); |
| 209 } | 214 } |
| OLD | NEW |