diff options
author | dgozman <dgozman@chromium.org> | 2016-02-22 14:08:35 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-22 22:09:23 +0000 |
commit | c7185a793efbeaa40e0d20d9d953bc1e2c32f5d1 (patch) | |
tree | 23950fb23c0960525edd09d1714c8bddb0e57410 | |
parent | 4b6f9cfbf319a0208da51034caa4908c21fa61d6 (diff) | |
download | chromium_src-c7185a793efbeaa40e0d20d9d953bc1e2c32f5d1.zip chromium_src-c7185a793efbeaa40e0d20d9d953bc1e2c32f5d1.tar.gz chromium_src-c7185a793efbeaa40e0d20d9d953bc1e2c32f5d1.tar.bz2 |
[DevTools] Move screen orientation override to RenderWidgetScreenMetricsEmulator.
This unifies screen orientation with the rest of screen emulation
and covers window.orientation API.
BUG=585185
Review URL: https://codereview.chromium.org/1711083002
Cr-Commit-Position: refs/heads/master@{#376822}
23 files changed, 181 insertions, 304 deletions
diff --git a/components/test_runner/mock_screen_orientation_client.cc b/components/test_runner/mock_screen_orientation_client.cc index 80a1dbf..7fe803d 100644 --- a/components/test_runner/mock_screen_orientation_client.cc +++ b/components/test_runner/mock_screen_orientation_client.cc @@ -15,7 +15,8 @@ MockScreenOrientationClient::MockScreenOrientationClient() : main_frame_(NULL), current_lock_(blink::WebScreenOrientationLockDefault), device_orientation_(blink::WebScreenOrientationPortraitPrimary), - current_orientation_(blink::WebScreenOrientationPortraitPrimary) { + current_orientation_(blink::WebScreenOrientationPortraitPrimary), + is_active_(false) { } MockScreenOrientationClient::~MockScreenOrientationClient() { @@ -25,12 +26,14 @@ void MockScreenOrientationClient::ResetData() { current_lock_ = blink::WebScreenOrientationLockDefault; device_orientation_ = blink::WebScreenOrientationPortraitPrimary; current_orientation_ = blink::WebScreenOrientationPortraitPrimary; + is_active_ = true; } void MockScreenOrientationClient::UpdateDeviceOrientation( blink::WebLocalFrame* main_frame, blink::WebScreenOrientationType orientation) { main_frame_ = main_frame; + is_active_ = true; if (device_orientation_ == orientation) return; device_orientation_ = orientation; diff --git a/components/test_runner/mock_screen_orientation_client.h b/components/test_runner/mock_screen_orientation_client.h index ad86854..15cb81d 100644 --- a/components/test_runner/mock_screen_orientation_client.h +++ b/components/test_runner/mock_screen_orientation_client.h @@ -31,6 +31,7 @@ class TEST_RUNNER_EXPORT MockScreenOrientationClient blink::WebScreenOrientationType CurrentOrientationType() const; unsigned CurrentOrientationAngle() const; + bool is_active() const { return is_active_; } private: // From blink::WebScreenOrientationClient. @@ -51,6 +52,7 @@ class TEST_RUNNER_EXPORT MockScreenOrientationClient blink::WebScreenOrientationLockType current_lock_; blink::WebScreenOrientationType device_orientation_; blink::WebScreenOrientationType current_orientation_; + bool is_active_; DISALLOW_COPY_AND_ASSIGN(MockScreenOrientationClient); }; diff --git a/components/test_runner/web_test_proxy.cc b/components/test_runner/web_test_proxy.cc index 9a6d1f8..0941d7a 100644 --- a/components/test_runner/web_test_proxy.cc +++ b/components/test_runner/web_test_proxy.cc @@ -592,7 +592,7 @@ void WebTestProxyBase::LayoutAndPaintAsyncThen(const base::Closure& callback) { void WebTestProxyBase::GetScreenOrientationForTesting( blink::WebScreenInfo& screen_info) { - if (!screen_orientation_client_) + if (!screen_orientation_client_ || !screen_orientation_client_->is_active()) return; // Override screen orientation information with mock data. screen_info.orientationType = diff --git a/content/browser/devtools/protocol/devtools_protocol_handler_generator.py b/content/browser/devtools/protocol/devtools_protocol_handler_generator.py index df56ffe..2f24462 100755 --- a/content/browser/devtools/protocol/devtools_protocol_handler_generator.py +++ b/content/browser/devtools/protocol/devtools_protocol_handler_generator.py @@ -568,6 +568,7 @@ def ResolveObject(json, mapping): mapping["storage_type"] = "scoped_ptr<base::DictionaryValue>" mapping["raw_type"] = "base::DictionaryValue*" mapping["pass_template"] = tmpl_object_pass + mapping["init"] = " = nullptr" if "properties" in json: if not "declared_name" in mapping: mapping["declared_name"] = ("%s%s" % diff --git a/content/browser/devtools/protocol/emulation_handler.cc b/content/browser/devtools/protocol/emulation_handler.cc index f5945d7..6b124e3 100644 --- a/content/browser/devtools/protocol/emulation_handler.cc +++ b/content/browser/devtools/protocol/emulation_handler.cc @@ -23,6 +23,19 @@ using Response = DevToolsProtocolClient::Response; namespace { +blink::WebScreenOrientationType WebScreenOrientationTypeFromString( + const std::string& type) { + if (type == screen_orientation::kTypePortraitPrimary) + return blink::WebScreenOrientationPortraitPrimary; + if (type == screen_orientation::kTypePortraitSecondary) + return blink::WebScreenOrientationPortraitSecondary; + if (type == screen_orientation::kTypeLandscapePrimary) + return blink::WebScreenOrientationLandscapePrimary; + if (type == screen_orientation::kTypeLandscapeSecondary) + return blink::WebScreenOrientationLandscapeSecondary; + return blink::WebScreenOrientationUndefined; +} + ui::GestureProviderConfigType TouchEmulationConfigurationToType( const std::string& protocol_value) { ui::GestureProviderConfigType result = @@ -132,9 +145,11 @@ Response EmulationHandler::SetDeviceMetricsOverride( const int* screen_width, const int* screen_height, const int* position_x, - const int* position_y) { + const int* position_y, + const scoped_ptr<base::DictionaryValue>& screen_orientation) { const static int max_size = 10000000; const static double max_scale = 10; + const static int max_orientation_angle = 360; if (!host_) return Response::InternalError("Could not connect to view"); @@ -168,6 +183,30 @@ Response EmulationHandler::SetDeviceMetricsOverride( base::DoubleToString(max_scale)); } + blink::WebScreenOrientationType orientationType = + blink::WebScreenOrientationUndefined; + int orientationAngle = 0; + if (screen_orientation) { + std::string orientationTypeString; + if (!screen_orientation->GetString("type", &orientationTypeString)) { + return Response::InvalidParams( + "Screen orientation type must be a string"); + } + orientationType = WebScreenOrientationTypeFromString(orientationTypeString); + if (orientationType == blink::WebScreenOrientationUndefined) + return Response::InvalidParams("Invalid screen orientation type value"); + + if (!screen_orientation->GetInteger("angle", &orientationAngle)) { + return Response::InvalidParams( + "Screen orientation angle must be a number"); + } + if (orientationAngle < 0 || orientationAngle >= max_orientation_angle) { + return Response::InvalidParams( + "Screen orientation angle must be non-negative, less than " + + base::IntToString(max_orientation_angle)); + } + } + blink::WebDeviceEmulationParams params; params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : blink::WebDeviceEmulationParams::Desktop; @@ -182,6 +221,8 @@ Response EmulationHandler::SetDeviceMetricsOverride( params.offset = blink::WebFloatPoint( optional_offset_x ? *optional_offset_x : 0.f, optional_offset_y ? *optional_offset_y : 0.f); + params.screenOrientationType = orientationType; + params.screenOrientationAngle = orientationAngle; if (device_emulation_enabled_ && params == device_emulation_params_) return Response::OK(); diff --git a/content/browser/devtools/protocol/emulation_handler.h b/content/browser/devtools/protocol/emulation_handler.h index bcaeb0d..a5aec63 100644 --- a/content/browser/devtools/protocol/emulation_handler.h +++ b/content/browser/devtools/protocol/emulation_handler.h @@ -39,18 +39,20 @@ class EmulationHandler { const std::string* configuration); Response CanEmulate(bool* result); - Response SetDeviceMetricsOverride(int width, - int height, - double device_scale_factor, - bool mobile, - bool fit_window, - const double* optional_scale, - const double* optional_offset_x, - const double* optional_offset_y, - const int* screen_widget, - const int* screen_height, - const int* position_x, - const int* position_y); + Response SetDeviceMetricsOverride( + int width, + int height, + double device_scale_factor, + bool mobile, + bool fit_window, + const double* optional_scale, + const double* optional_offset_x, + const double* optional_offset_y, + const int* screen_widget, + const int* screen_height, + const int* position_x, + const int* position_y, + const scoped_ptr<base::DictionaryValue>& screen_orientation); Response ClearDeviceMetricsOverride(); private: diff --git a/content/common/view_messages.h b/content/common/view_messages.h index db9b38d..b343ced 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -161,6 +161,8 @@ IPC_STRUCT_TRAITS_BEGIN(blink::WebDeviceEmulationParams) IPC_STRUCT_TRAITS_MEMBER(fitToView) IPC_STRUCT_TRAITS_MEMBER(offset) IPC_STRUCT_TRAITS_MEMBER(scale) + IPC_STRUCT_TRAITS_MEMBER(screenOrientationAngle) + IPC_STRUCT_TRAITS_MEMBER(screenOrientationType) IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_BEGIN(blink::WebScreenInfo) diff --git a/content/renderer/devtools/render_widget_screen_metrics_emulator.cc b/content/renderer/devtools/render_widget_screen_metrics_emulator.cc index 5843379..1022c27 100644 --- a/content/renderer/devtools/render_widget_screen_metrics_emulator.cc +++ b/content/renderer/devtools/render_widget_screen_metrics_emulator.cc @@ -99,6 +99,14 @@ void RenderWidgetScreenMetricsEmulator::Apply() { ? emulation_params_.deviceScaleFactor : original_screen_info().deviceScaleFactor; + if (emulation_params_.screenOrientationType != + blink::WebScreenOrientationUndefined) { + modified_resize_params.screen_info.orientationType = + emulation_params_.screenOrientationType; + modified_resize_params.screen_info.orientationAngle = + emulation_params_.screenOrientationAngle; + } + // Pass three emulation parameters to the blink side: // - we keep the real device scale factor in compositor to produce sharp image // even when emulating different scale factor; diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc index 9709d2e..3f9d45d 100644 --- a/content/renderer/render_widget.cc +++ b/content/renderer/render_widget.cc @@ -567,13 +567,7 @@ void RenderWidget::OnResize(const ResizeParams& params) { return; } - bool orientation_changed = - screen_info_.orientationAngle != params.screen_info.orientationAngle; - Resize(params); - - if (orientation_changed) - OnOrientationChange(); } void RenderWidget::OnEnableDeviceEmulation( @@ -1060,6 +1054,10 @@ void RenderWidget::Redraw() { } void RenderWidget::Resize(const ResizeParams& params) { + bool orientation_changed = + screen_info_.orientationAngle != params.screen_info.orientationAngle || + screen_info_.orientationType != params.screen_info.orientationType; + screen_info_ = params.screen_info; SetDeviceScaleFactor(screen_info_.deviceScaleFactor); @@ -1129,6 +1127,9 @@ void RenderWidget::Resize(const ResizeParams& params) { if (fullscreen_change) DidToggleFullscreen(); + if (orientation_changed) + OnOrientationChange(); + // If a resize ack is requested and it isn't set-up, then no more resizes will // come in and in general things will go wrong. DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack()); diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js b/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js index c46022b..8739d87 100644 --- a/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js +++ b/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js @@ -955,7 +955,6 @@ WebInspector.targetManager.observeTargets({ InspectorTest.PageAgent = target.pageAgent(); InspectorTest.ProfilerAgent = target.profilerAgent(); InspectorTest.RuntimeAgent = target.runtimeAgent(); - InspectorTest.ScreenOrientationAgent = target.screenOrientationAgent(); InspectorTest.WorkerAgent = target.workerAgent(); InspectorTest.consoleModel = target.consoleModel; diff --git a/third_party/WebKit/LayoutTests/inspector/screen-orientation-override-expected.txt b/third_party/WebKit/LayoutTests/inspector/screen-orientation-override-expected.txt index ebcf1df..e76a330 100644 --- a/third_party/WebKit/LayoutTests/inspector/screen-orientation-override-expected.txt +++ b/third_party/WebKit/LayoutTests/inspector/screen-orientation-override-expected.txt @@ -1,15 +1,18 @@ +CONSOLE MESSAGE: line 22: angle: 0; type: portrait-primary +CONSOLE MESSAGE: line 22: angle: 180; type: portrait-secondary +CONSOLE MESSAGE: line 22: angle: 90; type: landscape-primary +CONSOLE MESSAGE: line 22: angle: 270; type: landscape-secondary Running: initial -angle: 90; type: landscape-primary Running: setWrongAngle1 -Angle should be in [0; 360) interval +error: Request Emulation.setDeviceMetricsOverride failed. {"code":-32602,"message":"Missing or invalid 'Screen orientation angle must be non-negative, less than 360' parameter"} Running: setWrongAngle2 -Angle should be in [0; 360) interval +error: Request Emulation.setDeviceMetricsOverride failed. {"code":-32602,"message":"Missing or invalid 'Screen orientation angle must be non-negative, less than 360' parameter"} Running: setWrongType -Wrong type value +error: Request Emulation.setDeviceMetricsOverride failed. {"code":-32602,"message":"Missing or invalid 'Invalid screen orientation type value' parameter"} Running: setPortraitPrimary angle: 0; type: portrait-primary @@ -28,5 +31,5 @@ Running: setLandscapeSecondary angle: 270; type: landscape-secondary Running: clearOverride -angle: 90; type: landscape-primary +Equals to initial: true diff --git a/third_party/WebKit/LayoutTests/inspector/screen-orientation-override.html b/third_party/WebKit/LayoutTests/inspector/screen-orientation-override.html index 11bf460..b65b21d 100644 --- a/third_party/WebKit/LayoutTests/inspector/screen-orientation-override.html +++ b/third_party/WebKit/LayoutTests/inspector/screen-orientation-override.html @@ -3,16 +3,25 @@ <script src="../http/tests/inspector/inspector-test.js"></script> <script> -if (!window.testRunner) - debug("This test requires testRunner"); +var windowOrientationChangeEvent = false; +var screenOrientationChangeEvent = false; + +window.addEventListener("orientationchange", function() { windowOrientationChangeEvent = true; maybeLog(); }); +screen.orientation.addEventListener("change", function() { screenOrientationChangeEvent = true; maybeLog(); }); function dump() { return "angle: " + screen.orientation.angle + "; type: " + screen.orientation.type; } -if (window.testRunner) - testRunner.setMockScreenOrientation("landscape-primary"); +function maybeLog() +{ + if (windowOrientationChangeEvent && screenOrientationChangeEvent) { + windowOrientationChangeEvent = false; + screenOrientationChangeEvent = false; + console.log(dump()); + } +} function test() { @@ -29,29 +38,27 @@ function test() function testOverride(angle, orientation, next) { - var protocolCallback = addDumpResult.bind(null, next); - if (orientation) { - InspectorTest.ScreenOrientationAgent.setScreenOrientationOverride(angle, orientation, protocolCallback); - } else { - InspectorTest.ScreenOrientationAgent.clearScreenOrientationOverride(protocolCallback); - } + InspectorTest.addConsoleSniffer(addDumpResult.bind(null, next)); + InspectorTest.EmulationAgent.invoke_setDeviceMetricsOverride({width: 0, height: 0, deviceScaleFactor: 0, mobile: true, fitWindow: false, screenOrientation: {type: orientation, angle: angle}}, function() {}); } function testError(angle, orientation, next) { - InspectorTest.ScreenOrientationAgent.setScreenOrientationOverride(angle, orientation, protocolCallback); - - function protocolCallback(error) - { - InspectorTest.addResult(error); - next(); - } + InspectorTest.EmulationAgent.invoke_setDeviceMetricsOverride({width: 0, height: 0, deviceScaleFactor: 0, mobile: true, fitWindow: false, screenOrientation: {type: orientation, angle: angle}}, next); } + var original; + InspectorTest.runTestSuite([ function initial(next) { - addDumpResult(next); + InspectorTest.evaluateInPage("dump()", dumpCallback); + + function dumpCallback(result) + { + original = result.value; + next(); + } }, function setWrongAngle1(next) @@ -96,7 +103,18 @@ function test() function clearOverride(next) { - testOverride(0, "", next); + InspectorTest.EmulationAgent.clearDeviceMetricsOverride(checkInitial); + + function checkInitial() + { + InspectorTest.evaluateInPage("dump()", dumpCallback); + } + + function dumpCallback(result) + { + InspectorTest.addResult("Equals to initial: " + (original === result.value ? "true" : "false")); + next(); + } } ]); } diff --git a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js index b05b2c5..159c002 100644 --- a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js +++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js @@ -55,8 +55,6 @@ WebInspector.DeviceModeModel = function(updateCallback) this._touchEnabled = false; /** @type {string} */ this._touchConfiguration = ""; - /** @type {string} */ - this._screenOrientation = ""; /** @type {number} */ this._fitScale = 1; @@ -422,15 +420,13 @@ WebInspector.DeviceModeModel.prototype = { this._appliedUserAgentType = this._device.touch() ? WebInspector.DeviceModeModel.UA.Mobile : WebInspector.DeviceModeModel.UA.MobileNoTouch; else this._appliedUserAgentType = this._device.touch() ? WebInspector.DeviceModeModel.UA.DesktopTouch : WebInspector.DeviceModeModel.UA.Desktop; - this._applyDeviceMetrics(new Size(orientation.width, orientation.height), this._mode.insets, this._scaleSetting.get(), this._device.deviceScaleFactor, this._device.mobile(), resetPageScaleFactor); + this._applyDeviceMetrics(new Size(orientation.width, orientation.height), this._mode.insets, this._scaleSetting.get(), this._device.deviceScaleFactor, this._device.mobile(), this._mode.orientation == WebInspector.EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary", resetPageScaleFactor); this._applyUserAgent(this._device.userAgent); - this._applyScreenOrientation(this._mode.orientation == WebInspector.EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary"); } else if (this._type === WebInspector.DeviceModeModel.Type.None) { this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height); this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop; - this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0), 1, 0, false, resetPageScaleFactor); + this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0), 1, 0, false, "", resetPageScaleFactor); this._applyUserAgent(""); - this._applyScreenOrientation(""); } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) { var screenWidth = this._widthSetting.get(); if (!screenWidth || screenWidth > this._preferredScaledWidth()) @@ -442,9 +438,8 @@ WebInspector.DeviceModeModel.prototype = { var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel.defaultMobileScaleFactor : 0; this._fitScale = this._calculateFitScale(this._widthSetting.get(), this._heightSetting.get()); this._appliedUserAgentType = this._uaSetting.get(); - this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new Insets(0, 0, 0, 0), this._scaleSetting.get(), this._deviceScaleFactorSetting.get() || defaultDeviceScaleFactor, mobile, resetPageScaleFactor); + this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new Insets(0, 0, 0, 0), this._scaleSetting.get(), this._deviceScaleFactorSetting.get() || defaultDeviceScaleFactor, mobile, screenHeight >= screenWidth ? "portraitPrimary" : "landscapePrimary", resetPageScaleFactor); this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultMobileUserAgent : ""); - this._applyScreenOrientation(screenHeight >= screenWidth ? "portraitPrimary" : "landscapePrimary"); } this._reapplyTouch(); this._updateCallback.call(null); @@ -502,9 +497,10 @@ WebInspector.DeviceModeModel.prototype = { * @param {number} scale * @param {number} deviceScaleFactor * @param {boolean} mobile + * @param {string} screenOrientation * @param {boolean} resetPageScaleFactor */ - _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor, mobile, resetPageScaleFactor) + _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor, mobile, screenOrientation, resetPageScaleFactor) { screenSize.width = Math.max(1, Math.floor(screenSize.width)); screenSize.height = Math.max(1, Math.floor(screenSize.height)); @@ -513,6 +509,7 @@ WebInspector.DeviceModeModel.prototype = { var pageHeight = screenSize.height - insets.top - insets.bottom; var positionX = insets.left; var positionY = insets.top; + var screenOrientationAngle = screenOrientation === "landscapePrimary" ? 90 : 0; this._appliedDeviceSize = screenSize; this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixelRatio; @@ -550,13 +547,19 @@ WebInspector.DeviceModeModel.prototype = { if (!this._target) return Promise.resolve(); - var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFactor && scale === 1; + var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFactor && scale === 1 && !screenOrientation; var allPromises = []; if (resetPageScaleFactor) allPromises.push(this._target.emulationAgent().resetPageScaleFactor()); - var setDevicePromise = clear ? - this._target.emulationAgent().clearDeviceMetricsOverride(this._deviceMetricsOverrideAppliedForTest.bind(this)) : - this._target.emulationAgent().setDeviceMetricsOverride(pageWidth, pageHeight, deviceScaleFactor, mobile, false, scale, 0, 0, screenSize.width, screenSize.height, positionX, positionY, this._deviceMetricsOverrideAppliedForTest.bind(this)); + var setDevicePromise; + if (clear) { + setDevicePromise = this._target.emulationAgent().clearDeviceMetricsOverride(this._deviceMetricsOverrideAppliedForTest.bind(this)); + } else { + var params = {width: pageWidth, height: pageHeight, deviceScaleFactor: deviceScaleFactor, mobile: mobile, fitWindow: false, scale: scale, screenWidth: screenSize.width, screenHeight: screenSize.height, positionX: positionX, positionY: positionY}; + if (screenOrientation) + params.screenOrientation = {type: screenOrientation, angle: screenOrientationAngle}; + setDevicePromise = this._target.emulationAgent().invoke_setDeviceMetricsOverride(params, this._deviceMetricsOverrideAppliedForTest.bind(this)); + } allPromises.push(setDevicePromise); return Promise.all(allPromises); } @@ -614,20 +617,5 @@ WebInspector.DeviceModeModel.prototype = { target.emulationAgent().setTouchEmulationEnabled(touchEnabled, configuration); this._touchEnabled = touchEnabled; this._touchConfiguration = configuration; - }, - - /** - * @param {string} orientation - */ - _applyScreenOrientation: function(orientation) - { - if (!this._target || orientation === this._screenOrientation) - return; - - this._screenOrientation = orientation; - if (!this._screenOrientation) - this._target.screenOrientationAgent().clearScreenOrientationOverride(); - else - this._target.screenOrientationAgent().setScreenOrientationOverride(this._screenOrientation === "landscapePrimary" ? 90 : 0, /** @type {!ScreenOrientationAgent.OrientationType} */ (this._screenOrientation)); } } diff --git a/third_party/WebKit/Source/devtools/protocol.json b/third_party/WebKit/Source/devtools/protocol.json index 367bcab..982574f 100644 --- a/third_party/WebKit/Source/devtools/protocol.json +++ b/third_party/WebKit/Source/devtools/protocol.json @@ -337,7 +337,8 @@ { "name": "screenWidth", "type": "integer", "optional": true, "description": "Overriding screen width value in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." }, { "name": "screenHeight", "type": "integer", "optional": true, "description": "Overriding screen height value in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." }, { "name": "positionX", "type": "integer", "optional": true, "description": "Overriding view X position on screen in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." }, - { "name": "positionY", "type": "integer", "optional": true, "description": "Overriding view Y position on screen in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." } + { "name": "positionY", "type": "integer", "optional": true, "description": "Overriding view Y position on screen in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." }, + { "name": "screenOrientation", "$ref": "Emulation.ScreenOrientation", "optional": true, "description": "Screen orientation override." } ], "handlers": ["browser"], "redirect": "Emulation", @@ -641,6 +642,17 @@ "domain": "Emulation", "description": "This domain emulates different environments for the page.", "hidden": true, + "types": [ + { + "id": "ScreenOrientation", + "type": "object", + "description": "Screen orientation.", + "properties": [ + { "name": "type", "type": "string", "enum": ["portraitPrimary", "portraitSecondary", "landscapePrimary", "landscapeSecondary"], "description": "Orientation type." }, + { "name": "angle", "type": "integer", "description": "Orientation angle." } + ] + } + ], "commands": [ { "name": "setDeviceMetricsOverride", @@ -657,7 +669,8 @@ { "name": "screenWidth", "type": "integer", "optional": true, "description": "Overriding screen width value in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." }, { "name": "screenHeight", "type": "integer", "optional": true, "description": "Overriding screen height value in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." }, { "name": "positionX", "type": "integer", "optional": true, "description": "Overriding view X position on screen in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." }, - { "name": "positionY", "type": "integer", "optional": true, "description": "Overriding view Y position on screen in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." } + { "name": "positionY", "type": "integer", "optional": true, "description": "Overriding view Y position on screen in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." }, + { "name": "screenOrientation", "$ref": "ScreenOrientation", "optional": true, "description": "Screen orientation override." } ], "handlers": ["browser"] }, @@ -4915,32 +4928,6 @@ ] }, { - "domain": "ScreenOrientation", - "hidden": true, - "types": [ - { - "id": "OrientationType", - "type": "string", - "enum": ["portraitPrimary", "portraitSecondary", "landscapePrimary", "landscapeSecondary"], - "description": "Orientation type" - } - ], - "commands": [ - { - "name": "setScreenOrientationOverride", - "description": "Overrides the Screen Orientation.", - "parameters": [ - { "name": "angle", "type": "integer", "description": "Orientation angle" }, - { "name": "type", "$ref": "OrientationType", "description": "Orientation type" } - ] - }, - { - "name": "clearScreenOrientationOverride", - "description": "Clears the overridden Screen Orientation." - } - ] - }, - { "domain": "Tracing", "commands": [ { diff --git a/third_party/WebKit/Source/modules/modules.gypi b/third_party/WebKit/Source/modules/modules.gypi index b4a7ee5..1e39415 100644 --- a/third_party/WebKit/Source/modules/modules.gypi +++ b/third_party/WebKit/Source/modules/modules.gypi @@ -1403,8 +1403,6 @@ 'screen_orientation/ScreenOrientationController.h', 'screen_orientation/ScreenOrientationDispatcher.cpp', 'screen_orientation/ScreenOrientationDispatcher.h', - 'screen_orientation/ScreenOrientationInspectorAgent.cpp', - 'screen_orientation/ScreenOrientationInspectorAgent.h', 'serviceworkers/ExtendableEvent.cpp', 'serviceworkers/ExtendableEvent.h', 'serviceworkers/ExtendableMessageEvent.cpp', diff --git a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.cpp b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.cpp index 8e3c862..de25e2c 100644 --- a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.cpp +++ b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.cpp @@ -40,9 +40,6 @@ ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS , PlatformEventController(frame.page()) , m_client(client) , m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTimerFired) - , m_override(false) - , m_overrideType(WebScreenOrientationUndefined) - , m_overrideAngle(0) { } @@ -76,16 +73,6 @@ WebScreenOrientationType ScreenOrientationController::computeOrientation(const I } } -unsigned short ScreenOrientationController::effectiveAngle(ChromeClient& chromeClient) -{ - return m_override ? m_overrideAngle : chromeClient.screenInfo().orientationAngle; -} - -WebScreenOrientationType ScreenOrientationController::effectiveType(ChromeClient& chromeClient) -{ - return m_override ? m_overrideType : chromeClient.screenInfo().orientationType; -} - void ScreenOrientationController::updateOrientation() { ASSERT(m_orientation); @@ -93,15 +80,16 @@ void ScreenOrientationController::updateOrientation() ASSERT(frame()->host()); ChromeClient& chromeClient = frame()->host()->chromeClient(); - WebScreenOrientationType orientationType = effectiveType(chromeClient); + WebScreenInfo screenInfo = chromeClient.screenInfo(); + WebScreenOrientationType orientationType = screenInfo.orientationType; if (orientationType == WebScreenOrientationUndefined) { // The embedder could not provide us with an orientation, deduce it ourselves. - orientationType = computeOrientation(chromeClient.screenInfo().rect, effectiveAngle(chromeClient)); + orientationType = computeOrientation(chromeClient.screenInfo().rect, screenInfo.orientationAngle); } ASSERT(orientationType != WebScreenOrientationUndefined); m_orientation->setType(orientationType); - m_orientation->setAngle(effectiveAngle(chromeClient)); + m_orientation->setAngle(screenInfo.orientationAngle); } bool ScreenOrientationController::isActiveAndVisible() const @@ -118,7 +106,7 @@ void ScreenOrientationController::pageVisibilityChanged() // The orientation type and angle are tied in a way that if the angle has // changed, the type must have changed. - unsigned short currentAngle = effectiveAngle(frame()->host()->chromeClient()); + unsigned short currentAngle = frame()->host()->chromeClient().screenInfo().orientationAngle; // FIXME: sendOrientationChangeEvent() currently send an event all the // children of the frame, so it should only be called on the frame on @@ -182,20 +170,6 @@ void ScreenOrientationController::unlock() m_client->unlockOrientation(); } -void ScreenOrientationController::setOverride(WebScreenOrientationType type, unsigned short angle) -{ - m_override = true; - m_overrideType = type; - m_overrideAngle = angle; - notifyOrientationChanged(); -} - -void ScreenOrientationController::clearOverride() -{ - m_override = false; - notifyOrientationChanged(); -} - void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientationController>*) { if (!m_orientation) diff --git a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.h b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.h index 4a27fee..0a519d3 100644 --- a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.h +++ b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.h @@ -37,9 +37,6 @@ public: void lock(WebScreenOrientationLockType, WebLockOrientationCallback*); void unlock(); - void setOverride(WebScreenOrientationType, unsigned short angle); - void clearOverride(); - static void provideTo(LocalFrame&, WebScreenOrientationClient*); static ScreenOrientationController* from(LocalFrame&); static const char* supplementName(); @@ -61,9 +58,6 @@ private: // Inherited from LocalFrameLifecycleObserver. void willDetachFrameHost() override; - unsigned short effectiveAngle(ChromeClient&); - WebScreenOrientationType effectiveType(ChromeClient&); - void notifyDispatcher(); void updateOrientation(); @@ -75,9 +69,6 @@ private: PersistentWillBeMember<ScreenOrientation> m_orientation; WebScreenOrientationClient* m_client; Timer<ScreenOrientationController> m_dispatchEventTimer; - bool m_override; - WebScreenOrientationType m_overrideType; - unsigned short m_overrideAngle; }; } // namespace blink diff --git a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp deleted file mode 100644 index 09968b9..0000000 --- a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2015 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 "modules/screen_orientation/ScreenOrientationInspectorAgent.h" - -#include "core/frame/LocalFrame.h" -#include "modules/screen_orientation/ScreenOrientation.h" -#include "modules/screen_orientation/ScreenOrientationController.h" -#include "platform/inspector_protocol/TypeBuilder.h" - -namespace blink { - -namespace ScreenOrientationInspectorAgentState { -static const char angle[] = "angle"; -static const char type[] = "type"; -static const char overrideEnabled[] = "overrideEnabled"; -} - -namespace { - -WebScreenOrientationType WebScreenOrientationTypeFromString(const String& type) -{ - if (type == protocol::TypeBuilder::getEnumConstantValue(protocol::TypeBuilder::ScreenOrientation::OrientationType::PortraitPrimary)) - return WebScreenOrientationPortraitPrimary; - if (type == protocol::TypeBuilder::getEnumConstantValue(protocol::TypeBuilder::ScreenOrientation::OrientationType::PortraitSecondary)) - return WebScreenOrientationPortraitSecondary; - if (type == protocol::TypeBuilder::getEnumConstantValue(protocol::TypeBuilder::ScreenOrientation::OrientationType::LandscapePrimary)) - return WebScreenOrientationLandscapePrimary; - if (type == protocol::TypeBuilder::getEnumConstantValue(protocol::TypeBuilder::ScreenOrientation::OrientationType::LandscapeSecondary)) - return WebScreenOrientationLandscapeSecondary; - return WebScreenOrientationUndefined; -} - -} // namespace - -// static -PassOwnPtrWillBeRawPtr<ScreenOrientationInspectorAgent> ScreenOrientationInspectorAgent::create(LocalFrame& frame) -{ - return adoptPtrWillBeNoop(new ScreenOrientationInspectorAgent(frame)); -} - -ScreenOrientationInspectorAgent::~ScreenOrientationInspectorAgent() -{ -} - -ScreenOrientationInspectorAgent::ScreenOrientationInspectorAgent(LocalFrame& frame) - : InspectorBaseAgent<ScreenOrientationInspectorAgent, protocol::Frontend::ScreenOrientation>("ScreenOrientation") - , m_frame(&frame) -{ -} - -DEFINE_TRACE(ScreenOrientationInspectorAgent) -{ - visitor->trace(m_frame); - InspectorBaseAgent<ScreenOrientationInspectorAgent, protocol::Frontend::ScreenOrientation>::trace(visitor); -} - -void ScreenOrientationInspectorAgent::setScreenOrientationOverride(ErrorString* error, int angle, const String& typeString) -{ - if (angle < 0 || angle >= 360) { - *error = "Angle should be in [0; 360) interval"; - return; - } - WebScreenOrientationType type = WebScreenOrientationTypeFromString(typeString); - if (type == WebScreenOrientationUndefined) { - *error = "Wrong type value"; - return; - } - ScreenOrientationController* controller = ScreenOrientationController::from(*m_frame); - if (!controller) { - *error = "Cannot connect to orientation controller"; - return; - } - m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, true); - m_state->setNumber(ScreenOrientationInspectorAgentState::angle, angle); - m_state->setNumber(ScreenOrientationInspectorAgentState::type, type); - controller->setOverride(type, angle); -} - -void ScreenOrientationInspectorAgent::clearScreenOrientationOverride(ErrorString* error) -{ - ScreenOrientationController* controller = ScreenOrientationController::from(*m_frame); - if (!controller) { - *error = "Cannot connect to orientation controller"; - return; - } - m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, false); - controller->clearOverride(); -} - -void ScreenOrientationInspectorAgent::disable(ErrorString*) -{ - m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, false); - if (ScreenOrientationController* controller = ScreenOrientationController::from(*m_frame)) - controller->clearOverride(); -} - -void ScreenOrientationInspectorAgent::restore() -{ - if (m_state->booleanProperty(ScreenOrientationInspectorAgentState::overrideEnabled, false)) { - long longType = static_cast<long>(WebScreenOrientationUndefined); - m_state->getNumber(ScreenOrientationInspectorAgentState::type, &longType); - WebScreenOrientationType type = static_cast<WebScreenOrientationType>(longType); - int angle = 0; - m_state->getNumber(ScreenOrientationInspectorAgentState::angle, &angle); - if (ScreenOrientationController* controller = ScreenOrientationController::from(*m_frame)) - controller->setOverride(type, angle); - } -} - -} // namespace blink diff --git a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.h b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.h deleted file mode 100644 index b60b1ac..0000000 --- a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 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 ScreenOrientationInspectorAgent_h -#define ScreenOrientationInspectorAgent_h - -#include "core/inspector/InspectorBaseAgent.h" -#include "modules/ModulesExport.h" -#include "wtf/text/WTFString.h" - -namespace blink { - -class ScreenOrientationController; - -typedef String ErrorString; - -class MODULES_EXPORT ScreenOrientationInspectorAgent final : public InspectorBaseAgent<ScreenOrientationInspectorAgent, protocol::Frontend::ScreenOrientation>, public protocol::Dispatcher::ScreenOrientationCommandHandler { - WTF_MAKE_NONCOPYABLE(ScreenOrientationInspectorAgent); -public: - static PassOwnPtrWillBeRawPtr<ScreenOrientationInspectorAgent> create(LocalFrame&); - - ~ScreenOrientationInspectorAgent() override; - - DECLARE_VIRTUAL_TRACE(); - - // Protocol methods. - void setScreenOrientationOverride(ErrorString*, int, const String&) override; - void clearScreenOrientationOverride(ErrorString*) override; - - // InspectorBaseAgent overrides. - void disable(ErrorString*) override; - void restore() override; - -private: - explicit ScreenOrientationInspectorAgent(LocalFrame&); - RawPtrWillBeMember<LocalFrame> m_frame; -}; - -} // namespace blink - - -#endif // !defined(ScreenOrientationInspectorAgent_h) diff --git a/third_party/WebKit/Source/web/DevToolsEmulator.cpp b/third_party/WebKit/Source/web/DevToolsEmulator.cpp index bdf0232..6d05aa8 100644 --- a/third_party/WebKit/Source/web/DevToolsEmulator.cpp +++ b/third_party/WebKit/Source/web/DevToolsEmulator.cpp @@ -51,6 +51,7 @@ DevToolsEmulator::DevToolsEmulator(WebViewImpl* webViewImpl) , m_deviceMetricsEnabled(false) , m_emulateMobileEnabled(false) , m_isOverlayScrollbarsEnabled(false) + , m_isOrientationEventEnabled(false) , m_originalDefaultMinimumPageScaleFactor(0) , m_originalDefaultMaximumPageScaleFactor(0) , m_embedderTextAutosizingEnabled(webViewImpl->page()->settings().textAutosizingEnabled()) @@ -255,6 +256,8 @@ void DevToolsEmulator::enableMobileEmulation() m_emulateMobileEnabled = true; m_isOverlayScrollbarsEnabled = RuntimeEnabledFeatures::overlayScrollbarsEnabled(); RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); + m_isOrientationEventEnabled = RuntimeEnabledFeatures::orientationEventEnabled(); + RuntimeEnabledFeatures::setOrientationEventEnabled(true); m_webViewImpl->page()->settings().setUseMobileViewportStyle(true); m_webViewImpl->enableViewport(); m_webViewImpl->settings()->setViewportMetaEnabled(true); @@ -284,6 +287,7 @@ void DevToolsEmulator::disableMobileEmulation() if (!m_emulateMobileEnabled) return; RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(m_isOverlayScrollbarsEnabled); + RuntimeEnabledFeatures::setOrientationEventEnabled(m_isOrientationEventEnabled); m_webViewImpl->disableViewport(); m_webViewImpl->settings()->setViewportMetaEnabled(false); m_webViewImpl->page()->frameHost().visualViewport().initializeScrollbars(); diff --git a/third_party/WebKit/Source/web/DevToolsEmulator.h b/third_party/WebKit/Source/web/DevToolsEmulator.h index ca2c3f8..74fe391 100644 --- a/third_party/WebKit/Source/web/DevToolsEmulator.h +++ b/third_party/WebKit/Source/web/DevToolsEmulator.h @@ -62,6 +62,7 @@ private: WebDeviceEmulationParams m_emulationParams; bool m_isOverlayScrollbarsEnabled; + bool m_isOrientationEventEnabled; float m_originalDefaultMinimumPageScaleFactor; float m_originalDefaultMaximumPageScaleFactor; bool m_embedderTextAutosizingEnabled; diff --git a/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp b/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp index 0653e9c..3d435cc 100644 --- a/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp +++ b/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp @@ -70,7 +70,6 @@ #include "modules/device_orientation/DeviceOrientationInspectorAgent.h" #include "modules/filesystem/InspectorFileSystemAgent.h" #include "modules/indexeddb/InspectorIndexedDBAgent.h" -#include "modules/screen_orientation/ScreenOrientationInspectorAgent.h" #include "modules/storage/InspectorDOMStorageAgent.h" #include "modules/webdatabase/InspectorDatabaseAgent.h" #include "platform/JSONValues.h" @@ -388,8 +387,6 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl( m_agents.append(workerAgentPtr.release()); m_agents.append(pageConsoleAgentPtr.release()); - - m_agents.append(ScreenOrientationInspectorAgent::create(*m_webLocalFrameImpl->frame())); } WebDevToolsAgentImpl::~WebDevToolsAgentImpl() diff --git a/third_party/WebKit/public/web/WebDeviceEmulationParams.h b/third_party/WebKit/public/web/WebDeviceEmulationParams.h index c1e8f4c..85f9f7c 100644 --- a/third_party/WebKit/public/web/WebDeviceEmulationParams.h +++ b/third_party/WebKit/public/web/WebDeviceEmulationParams.h @@ -9,6 +9,7 @@ #include "../platform/WebPoint.h" #include "../platform/WebRect.h" #include "../platform/WebSize.h" +#include "../platform/modules/screen_orientation/WebScreenOrientationType.h" namespace blink { @@ -45,16 +46,27 @@ struct WebDeviceEmulationParams { // Scale of emulated view inside available space, not in fit to view mode. float scale; + // Optional screen orientation type, with WebScreenOrientationUndefined + // value meaning no emulation necessary. + WebScreenOrientationType screenOrientationType; + + // Screen orientation angle, used together with screenOrientationType. + int screenOrientationAngle; + WebDeviceEmulationParams() : screenPosition(Desktop) , deviceScaleFactor(0) , fitToView(false) - , scale(1) { } + , scale(1) + , screenOrientationType(WebScreenOrientationUndefined) + , screenOrientationAngle(0) { } }; inline bool operator==(const WebDeviceEmulationParams& a, const WebDeviceEmulationParams& b) { - return a.screenPosition == b.screenPosition && a.screenSize == b.screenSize && a.viewPosition == b.viewPosition && a.deviceScaleFactor == b.deviceScaleFactor && a.viewSize == b.viewSize && a.fitToView == b.fitToView && a.offset == b.offset && a.scale == b.scale; + return a.screenPosition == b.screenPosition && a.screenSize == b.screenSize && a.viewPosition == b.viewPosition && a.deviceScaleFactor == b.deviceScaleFactor + && a.viewSize == b.viewSize && a.fitToView == b.fitToView && a.offset == b.offset && a.scale == b.scale + && a.screenOrientationType == b.screenOrientationType && a.screenOrientationAngle == b.screenOrientationAngle; } inline bool operator!=(const WebDeviceEmulationParams& a, const WebDeviceEmulationParams& b) |