diff options
-rw-r--r-- | content/shell/browser/shell.cc | 33 | ||||
-rw-r--r-- | content/shell/browser/shell.h | 15 | ||||
-rw-r--r-- | content/shell/browser/shell_gtk.cc | 19 |
3 files changed, 39 insertions, 28 deletions
diff --git a/content/shell/browser/shell.cc b/content/shell/browser/shell.cc index dc64a49..55cf85a 100644 --- a/content/shell/browser/shell.cc +++ b/content/shell/browser/shell.cc @@ -144,6 +144,12 @@ void Shell::Initialize() { gfx::Size(kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip)); } +gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) { + if (!initial_size.IsEmpty()) + return initial_size; + return gfx::Size(kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip); +} + Shell* Shell::CreateNewWindow(BrowserContext* browser_context, const GURL& url, SiteInstance* site_instance, @@ -151,11 +157,7 @@ Shell* Shell::CreateNewWindow(BrowserContext* browser_context, const gfx::Size& initial_size) { WebContents::CreateParams create_params(browser_context, site_instance); create_params.routing_id = routing_id; - if (!initial_size.IsEmpty()) - create_params.initial_size = initial_size; - else - create_params.initial_size = - gfx::Size(kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip); + create_params.initial_size = AdjustWindowSize(initial_size); WebContents* web_contents = WebContents::Create(create_params); Shell* shell = CreateShell(web_contents, create_params.initial_size); if (!url.is_empty()) @@ -176,6 +178,17 @@ void Shell::LoadURLForFrame(const GURL& url, const std::string& frame_name) { web_contents_->GetView()->Focus(); } +void Shell::AddNewContents(WebContents* source, + WebContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture, + bool* was_blocked) { + CreateShell(new_contents, AdjustWindowSize(initial_pos.size())); + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) + NotifyDoneForwarder::CreateForWebContents(new_contents); +} + void Shell::GoBackOrForward(int offset) { web_contents_->GetController().GoToOffset(offset); web_contents_->GetView()->Focus(); @@ -292,16 +305,6 @@ bool Shell::CanOverscrollContent() const { #endif } -void Shell::WebContentsCreated(WebContents* source_contents, - int64 source_frame_id, - const string16& frame_name, - const GURL& target_url, - WebContents* new_contents) { - CreateShell(new_contents, source_contents->GetView()->GetContainerSize()); - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) - NotifyDoneForwarder::CreateForWebContents(new_contents); -} - void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) { PlatformSetAddressBarURL(web_contents->GetLastCommittedURL()); } diff --git a/content/shell/browser/shell.h b/content/shell/browser/shell.h index 86c4497..3707202 100644 --- a/content/shell/browser/shell.h +++ b/content/shell/browser/shell.h @@ -110,6 +110,12 @@ class Shell : public WebContentsDelegate, // WebContentsDelegate virtual WebContents* OpenURLFromTab(WebContents* source, const OpenURLParams& params) OVERRIDE; + virtual void AddNewContents(WebContents* source, + WebContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture, + bool* was_blocked) OVERRIDE; virtual void LoadingStateChanged(WebContents* source) OVERRIDE; #if defined(OS_ANDROID) virtual void LoadProgressChanged(WebContents* source, @@ -124,11 +130,6 @@ class Shell : public WebContentsDelegate, bool last_unlocked_by_target) OVERRIDE; virtual void CloseContents(WebContents* source) OVERRIDE; virtual bool CanOverscrollContent() const OVERRIDE; - virtual void WebContentsCreated(WebContents* source_contents, - int64 source_frame_id, - const string16& frame_name, - const GURL& target_url, - WebContents* new_contents) OVERRIDE; virtual void DidNavigateMainFramePostCommit( WebContents* web_contents) OVERRIDE; virtual JavaScriptDialogManager* GetJavaScriptDialogManager() OVERRIDE; @@ -165,6 +166,10 @@ class Shell : public WebContentsDelegate, // Helper for one time initialization of application static void PlatformInitialize(const gfx::Size& default_window_size); + // Adjust the size when Blink sends 0 for width and/or height. + // This happens when Blink requests a default-sized window. + static gfx::Size AdjustWindowSize(const gfx::Size& initial_size); + // All the methods that begin with Platform need to be implemented by the // platform specific Shell implementation. // Called from the destructor to let each platform do any necessary cleanup. diff --git a/content/shell/browser/shell_gtk.cc b/content/shell/browser/shell_gtk.cc index 3cc71f7..f6e9059 100644 --- a/content/shell/browser/shell_gtk.cc +++ b/content/shell/browser/shell_gtk.cc @@ -12,6 +12,7 @@ #include "base/strings/utf_string_conversions.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/native_web_keyboard_event.h" +#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "content/public/common/renderer_preferences.h" @@ -103,7 +104,8 @@ void Shell::PlatformSetIsLoading(bool loading) { void Shell::PlatformCreateWindow(int width, int height) { ui_elements_height_ = 0; if (headless_) { - SizeTo(width, height); + content_width_ = width; + content_height_ = height; return; } @@ -225,8 +227,10 @@ void Shell::PlatformCreateWindow(int width, int height) { } void Shell::PlatformSetContents() { - if (headless_) + if (headless_) { + SizeTo(content_width_, content_height_); return; + } WebContentsView* content_view = web_contents_->GetView(); gtk_container_add(GTK_CONTAINER(vbox_), content_view->GetNativeView()); @@ -236,19 +240,18 @@ void Shell::SizeTo(int width, int height) { content_width_ = width; content_height_ = height; - // Prefer setting the top level window's size (if we have one), rather than - // setting the inner widget's minimum size (so that the user can shrink the - // window if she wants). if (window_) { gtk_window_resize(window_, width, height + ui_elements_height_); } else if (web_contents_) { - gtk_widget_set_size_request(web_contents_->GetView()->GetNativeView(), - width, height); + RenderWidgetHostView* render_widget_host_view = + web_contents_->GetRenderWidgetHostView(); + if (render_widget_host_view) + render_widget_host_view->SetSize(gfx::Size(width, height)); } } void Shell::PlatformResizeSubViews() { - SizeTo(content_width_, content_height_); + // Not needed; the subviews are bound. } void Shell::Close() { |