Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: content/test/layouttest_support.cc

Issue 2036873002: Making EventSender talk to the right WebWidget (for OOPIF support). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use RenderWidget::viewRect() [rather than windowRect()] in TransformScreenToWidgetCoordinates. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/BUILD.gn ('k') | third_party/WebKit/LayoutTests/FlagExpectations/site-per-process » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/layouttest_support.cc
diff --git a/content/test/layouttest_support.cc b/content/test/layouttest_support.cc
index 7795796956c46dcc3d14e8a8af4c08224906d7d4..7d4a647aae63fbc59b905cba09711167ca0b5519 100644
--- a/content/test/layouttest_support.cc
+++ b/content/test/layouttest_support.cc
@@ -41,11 +41,15 @@
#include "gpu/ipc/service/image_transport_surface.h"
#include "third_party/WebKit/public/platform/WebFloatRect.h"
#include "third_party/WebKit/public/platform/WebGamepads.h"
+#include "third_party/WebKit/public/platform/WebInputEvent.h"
+#include "third_party/WebKit/public/platform/WebRect.h"
#include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionData.h"
#include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceOrientationData.h"
#include "third_party/WebKit/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/WebKit/public/web/WebHistoryItem.h"
#include "third_party/WebKit/public/web/WebView.h"
+#include "ui/events/blink/blink_event_util.h"
+#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/icc_profile.h"
#if defined(OS_MACOSX)
@@ -134,6 +138,12 @@ RenderFrameImpl* CreateWebFrameTestProxy(
return render_frame_proxy;
}
+float GetWindowToViewportScale(RenderWidget* render_widget) {
+ blink::WebFloatRect rect(0, 0, 1.0f, 0.0);
+ render_widget->convertWindowToViewport(&rect);
+ return rect.width;
+}
+
#if defined(OS_WIN)
// DirectWrite only has access to %WINDIR%\Fonts by default. For developer
// side-loading, support kRegisterFontFiles to allow access to additional fonts.
@@ -164,6 +174,55 @@ test_runner::WebFrameTestProxyBase* GetWebFrameTestProxyBase(
return static_cast<test_runner::WebFrameTestProxyBase*>(render_frame_proxy);
}
+test_runner::WebWidgetTestProxyBase* GetWebWidgetTestProxyBase(
+ blink::WebLocalFrame* frame) {
+ DCHECK(frame);
+ RenderFrame* local_root = RenderFrame::FromWebFrame(frame->localRoot());
+ DCHECK(local_root);
+ // TODO(lfg): Simplify once RenderView no longer inherits from RenderWidget.
+ if (local_root->IsMainFrame()) {
+ test_runner::WebViewTestProxyBase* web_view_test_proxy_base =
+ GetWebViewTestProxyBase(local_root->GetRenderView());
+ auto* web_widget_test_proxy_base =
+ static_cast<test_runner::WebWidgetTestProxyBase*>(
+ web_view_test_proxy_base);
+ DCHECK(web_widget_test_proxy_base->web_widget()->isWebView());
+ return web_widget_test_proxy_base;
+ } else {
+ RenderWidget* render_widget =
+ static_cast<RenderFrameImpl*>(local_root)->GetRenderWidget();
+ DCHECK(render_widget);
+ WebWidgetTestProxyType* render_widget_proxy =
+ static_cast<WebWidgetTestProxyType*>(render_widget);
+ auto* web_widget_test_proxy_base =
+ static_cast<test_runner::WebWidgetTestProxyBase*>(render_widget_proxy);
+ DCHECK(web_widget_test_proxy_base->web_widget()->isWebFrameWidget());
+ return web_widget_test_proxy_base;
+ }
+}
+
+RenderWidget* GetRenderWidget(
+ test_runner::WebWidgetTestProxyBase* web_widget_test_proxy_base) {
+ DCHECK(web_widget_test_proxy_base);
+
+ blink::WebWidget* widget = web_widget_test_proxy_base->web_widget();
+ // TODO(lfg): Simplify once RenderView no longer inherits from RenderWidget.
+ if (widget->isWebView()) {
+ WebViewTestProxyType* render_view_proxy =
+ static_cast<WebViewTestProxyType*>(web_widget_test_proxy_base);
+ RenderViewImpl* render_view_impl =
+ static_cast<RenderViewImpl*>(render_view_proxy);
+ return render_view_impl;
+ } else if (widget->isWebFrameWidget()) {
+ WebWidgetTestProxyType* render_widget_proxy =
+ static_cast<WebWidgetTestProxyType*>(web_widget_test_proxy_base);
+ return static_cast<RenderWidget*>(render_widget_proxy);
+ } else {
+ NOTREACHED();
+ return nullptr;
+ }
+}
+
void EnableWebTestProxyCreation(
const ViewProxyCreationCallback& view_proxy_creation_callback,
const WidgetProxyCreationCallback& widget_proxy_creation_callback,
@@ -392,9 +451,20 @@ void SetDeviceScaleFactor(RenderView* render_view, float factor) {
}
float GetWindowToViewportScale(RenderView* render_view) {
- blink::WebFloatRect rect(0, 0, 1.0f, 0.0);
- static_cast<RenderViewImpl*>(render_view)->convertWindowToViewport(&rect);
- return rect.width;
+ return GetWindowToViewportScale(
+ static_cast<RenderViewImpl*>(render_view)->GetWidget());
+}
+
+std::unique_ptr<blink::WebInputEvent> TransformScreenToWidgetCoordinates(
+ test_runner::WebWidgetTestProxyBase* web_widget_test_proxy_base,
+ const blink::WebInputEvent& event) {
+ DCHECK(web_widget_test_proxy_base);
+ RenderWidget* render_widget = GetRenderWidget(web_widget_test_proxy_base);
+
+ blink::WebRect view_rect = render_widget->viewRect();
+ float scale = GetWindowToViewportScale(render_widget);
+ gfx::Vector2d delta(-view_rect.x, -view_rect.y);
+ return ui::TranslateAndScaleWebInputEvent(event, delta, scale);
}
gfx::ICCProfile GetTestingICCProfile(const std::string& name) {
« no previous file with comments | « content/test/BUILD.gn ('k') | third_party/WebKit/LayoutTests/FlagExpectations/site-per-process » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698