summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerikchen@chromium.org <erikchen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 01:09:32 +0000
committererikchen@chromium.org <erikchen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 01:09:32 +0000
commit01fb95b03e0254d5006daec42b9a429eb650bfc0 (patch)
treea4927fec2eeea47a38663bcca3a778d928b6a734
parentf234673808cba003edf4d74d57a0e77899d4ff48 (diff)
downloadchromium_src-01fb95b03e0254d5006daec42b9a429eb650bfc0.zip
chromium_src-01fb95b03e0254d5006daec42b9a429eb650bfc0.tar.gz
chromium_src-01fb95b03e0254d5006daec42b9a429eb650bfc0.tar.bz2
Remove references to WebContentsView::SizeContents from chrome/ and app/
WebContentsView::SizeContents was initially introduced as a hack to allow the content module to resize a WebContentsView. This is odd because the embedder should be in full control of the layout of the WebContentsView. Unfortunately, SizeContents started being used as a platform-agnostic way for the embedder to change the size of a WebContentsView. The mac implementation of SizeContents has never been correct. The implementation would work correctly when SizeContents was used by the embedder, but it did not work when used by the content module. See https://code.google.com/p/chromium/issues/detail?id=264207 for details. I changed the mac implementation of SizeContents to be a no-op, which fixed the use of SizeContents from the content module, and broke its usage from the embedder. This CL introduces a new platform agnostic utility method to resize a WebContents. I've replaced all calls to SizeContents from chrome/ and app/ with a call to the new utility method. There is no expected behavioral change on aura, gtk, or android. This should fix the problems that have arisen from my change to the mac implementation of SizeContents. Ideally, the utility method would take a gfx::NativeView as its parameter. Unfortunately, I was unable perform the resizing on a ui::AndroidView*, and I was forced to pass in the whole WebContents to mimic the behavior of WebContentsViewAndroid::SizeContents. BUG=354769 TEST=Follow steps listed in bug. Review URL: https://codereview.chromium.org/209023003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262276 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--apps/app_window.cc3
-rw-r--r--apps/apps.gypi10
-rw-r--r--apps/ui/web_contents_sizer.cc35
-rw-r--r--apps/ui/web_contents_sizer.h24
-rw-r--r--apps/ui/web_contents_sizer.mm26
-rw-r--r--chrome/browser/prerender/prerender_contents.cc3
-rw-r--r--chrome/browser/ui/browser_tabrestore.cc17
-rw-r--r--chrome/browser/ui/fullscreen/fullscreen_controller.cc3
-rw-r--r--chrome/browser/ui/tabs/tab_strip_model.cc5
9 files changed, 113 insertions, 13 deletions
diff --git a/apps/app_window.cc b/apps/app_window.cc
index b339cf2..0ee51cc 100644
--- a/apps/app_window.cc
+++ b/apps/app_window.cc
@@ -11,6 +11,7 @@
#include "apps/apps_client.h"
#include "apps/size_constraints.h"
#include "apps/ui/native_app_window.h"
+#include "apps/ui/web_contents_sizer.h"
#include "base/command_line.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -323,7 +324,7 @@ void AppWindow::Init(const GURL& url,
gfx::Insets frame_insets = native_app_window_->GetFrameInsets();
gfx::Rect initial_bounds = new_params.GetInitialWindowBounds(frame_insets);
initial_bounds.Inset(frame_insets);
- web_contents->GetView()->SizeContents(initial_bounds.size());
+ apps::ResizeWebContents(web_contents, initial_bounds.size());
}
// Prevent the browser process from shutting down while this window is open.
diff --git a/apps/apps.gypi b/apps/apps.gypi
index 998f7e4..25611b0 100644
--- a/apps/apps.gypi
+++ b/apps/apps.gypi
@@ -72,8 +72,18 @@
'ui/views/app_window_frame_view.h',
'ui/views/native_app_window_views.cc',
'ui/views/native_app_window_views.h',
+ 'ui/web_contents_sizer.h',
],
'conditions': [
+ ['OS=="mac"', {
+ 'sources': [
+ 'ui/web_contents_sizer.mm',
+ ],
+ }, { # OS!=mac
+ 'sources': [
+ 'ui/web_contents_sizer.cc',
+ ],
+ }],
['chromeos==1',
{
'dependencies': [
diff --git a/apps/ui/web_contents_sizer.cc b/apps/ui/web_contents_sizer.cc
new file mode 100644
index 0000000..e19f2cf
--- /dev/null
+++ b/apps/ui/web_contents_sizer.cc
@@ -0,0 +1,35 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/ui/web_contents_sizer.h"
+
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+
+#if defined(USE_AURA)
+#include "ui/aura/window.h"
+#elif defined(TOOLKIT_GTK)
+#include <gtk/gtk.h>
+#elif defined(OS_ANDROID)
+#include "content/public/browser/render_widget_host_view.h"
+#endif
+
+namespace apps {
+
+void ResizeWebContents(content::WebContents* web_contents,
+ const gfx::Size& new_size) {
+#if defined(USE_AURA)
+ aura::Window* window = web_contents->GetView()->GetNativeView();
+ window->SetBounds(gfx::Rect(window->bounds().origin(), new_size));
+#elif defined(TOOLKIT_GTK)
+ GtkWidget* widget = web_contents->GetView()->GetNativeView();
+ gtk_widget_set_size_request(widget, new_size.width(), new_size.height());
+#elif defined(OS_ANDROID)
+ content::RenderWidgetHostView* view = web_contents->GetRenderWidgetHostView();
+ if (view)
+ view->SetSize(new_size);
+#endif
+}
+
+} // namespace apps
diff --git a/apps/ui/web_contents_sizer.h b/apps/ui/web_contents_sizer.h
new file mode 100644
index 0000000..9b5818e
--- /dev/null
+++ b/apps/ui/web_contents_sizer.h
@@ -0,0 +1,24 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APPS_UI_WEB_CONTENTS_SIZER_H_
+#define APPS_UI_WEB_CONTENTS_SIZER_H_
+
+namespace content {
+class WebContents;
+}
+
+namespace gfx {
+class Size;
+}
+
+namespace apps {
+// A platform-agnostic function to resize a WebContents. The top-left corner of
+// the WebContents does not move during the resizing.
+void ResizeWebContents(content::WebContents* web_contents,
+ const gfx::Size& size);
+
+} // namespace apps
+
+#endif // APPS_UI_WEB_CONTENTS_SIZER_H_
diff --git a/apps/ui/web_contents_sizer.mm b/apps/ui/web_contents_sizer.mm
new file mode 100644
index 0000000..8dd7cbd
--- /dev/null
+++ b/apps/ui/web_contents_sizer.mm
@@ -0,0 +1,26 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/ui/web_contents_sizer.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+
+namespace apps {
+
+void ResizeWebContents(content::WebContents* web_contents,
+ const gfx::Size& new_size) {
+ NSView* view = web_contents->GetView()->GetNativeView();
+ NSRect old_wcv_frame = [view frame];
+ CGFloat new_x = old_wcv_frame.origin.x;
+ CGFloat new_y =
+ old_wcv_frame.origin.y + (old_wcv_frame.size.height - new_size.height());
+ NSRect new_wcv_frame =
+ NSMakeRect(new_x, new_y, new_size.width(), new_size.height());
+ [view setFrame:new_wcv_frame];
+}
+
+} // namespace apps
diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc
index 4c0bc11..720719d 100644
--- a/chrome/browser/prerender/prerender_contents.cc
+++ b/chrome/browser/prerender/prerender_contents.cc
@@ -8,6 +8,7 @@
#include <functional>
#include <utility>
+#include "apps/ui/web_contents_sizer.h"
#include "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -327,7 +328,7 @@ void PrerenderContents::StartPrerendering(
web_contents_delegate_.reset(new WebContentsDelegateImpl(this));
prerender_contents_.get()->SetDelegate(web_contents_delegate_.get());
// Set the size of the prerender WebContents.
- prerender_contents_->GetView()->SizeContents(size_);
+ apps::ResizeWebContents(prerender_contents_.get(), size_);
child_id_ = GetRenderViewHost()->GetProcess()->GetID();
route_id_ = GetRenderViewHost()->GetRoutingID();
diff --git a/chrome/browser/ui/browser_tabrestore.cc b/chrome/browser/ui/browser_tabrestore.cc
index f939a74..f009090 100644
--- a/chrome/browser/ui/browser_tabrestore.cc
+++ b/chrome/browser/ui/browser_tabrestore.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/browser_tabrestore.h"
+#include "apps/ui/web_contents_sizer.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_service.h"
@@ -113,14 +114,14 @@ content::WebContents* AddRestoredTab(
if (select) {
browser->window()->Activate();
} else {
- // We set the size of the view here, before WebKit does its initial
- // layout. If we don't, the initial layout of background tabs will be
- // performed with a view width of 0, which may cause script outputs and
- // anchor link location calculations to be incorrect even after a new
- // layout with proper view dimensions. TabStripModel::AddWebContents()
- // contains similar logic.
- web_contents->GetView()->SizeContents(
- browser->window()->GetRestoredBounds().size());
+ // We set the size of the view here, before Blink does its initial layout.
+ // If we don't, the initial layout of background tabs will be performed
+ // with a view width of 0, which may cause script outputs and anchor link
+ // location calculations to be incorrect even after a new layout with
+ // proper view dimensions. TabStripModel::AddWebContents() contains similar
+ // logic.
+ apps::ResizeWebContents(web_contents,
+ browser->window()->GetRestoredBounds().size());
web_contents->WasHidden();
}
SessionService* session_service =
diff --git a/chrome/browser/ui/fullscreen/fullscreen_controller.cc b/chrome/browser/ui/fullscreen/fullscreen_controller.cc
index 712a1fa..a99b0e3 100644
--- a/chrome/browser/ui/fullscreen/fullscreen_controller.cc
+++ b/chrome/browser/ui/fullscreen/fullscreen_controller.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
+#include "apps/ui/web_contents_sizer.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
@@ -312,7 +313,7 @@ void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) {
old_contents->GetFullscreenRenderWidgetHostView();
if (current_fs_view)
current_fs_view->SetSize(old_contents->GetPreferredSize());
- old_contents->GetView()->SizeContents(old_contents->GetPreferredSize());
+ apps::ResizeWebContents(old_contents, old_contents->GetPreferredSize());
}
void FullscreenController::OnTabClosing(WebContents* web_contents) {
diff --git a/chrome/browser/ui/tabs/tab_strip_model.cc b/chrome/browser/ui/tabs/tab_strip_model.cc
index dfad932..6904962 100644
--- a/chrome/browser/ui/tabs/tab_strip_model.cc
+++ b/chrome/browser/ui/tabs/tab_strip_model.cc
@@ -8,6 +8,7 @@
#include <map>
#include <string>
+#include "apps/ui/web_contents_sizer.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "chrome/app/chrome_command_ids.h"
@@ -837,8 +838,8 @@ void TabStripModel::AddWebContents(WebContents* contents,
// new background tab.
if (WebContents* old_contents = GetActiveWebContents()) {
if ((add_types & ADD_ACTIVE) == 0) {
- contents->GetView()->SizeContents(
- old_contents->GetView()->GetContainerSize());
+ apps::ResizeWebContents(contents,
+ old_contents->GetView()->GetContainerSize());
}
}
}