diff options
author | engedy <engedy@chromium.org> | 2016-02-23 06:05:26 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-23 14:06:29 +0000 |
commit | abf86fd83c48a4dfa3f059f2db732fbb11cb614d (patch) | |
tree | db32b362dc2e32a6c9b1ae34129b1d0860715c0b | |
parent | 3673455317898f450211636919c2bef7a8e3fe0f (diff) | |
download | chromium_src-abf86fd83c48a4dfa3f059f2db732fbb11cb614d.zip chromium_src-abf86fd83c48a4dfa3f059f2db732fbb11cb614d.tar.gz chromium_src-abf86fd83c48a4dfa3f059f2db732fbb11cb614d.tar.bz2 |
Revert of [DevTools] Move screen orientation override to RenderWidgetScreenMetricsEmulator. (patchset #5 id:80001 of https://codereview.chromium.org/1711083002/ )
Reason for revert:
Suspected of breaking "fast/dom/Window/property-access-on-cached-properties-after-frame-removed-and-gced.html" on Webkit Linux Leak:
-FAIL window.cached_screen_orientation.type should be . Was portrait-primary.
+FAIL window.cached_screen_orientation.type should be . Was landscape-primary.
See: https://build.chromium.org/p/chromium.webkit/builders/WebKit%20Linux%20Leak/builds/17650
Original issue's description:
> [DevTools] Move screen orientation override to RenderWidgetScreenMetricsEmulator.
>
> This unifies screen orientation with the rest of screen emulation
> and covers window.orientation API.
>
> BUG=585185
>
> Committed: https://crrev.com/c7185a793efbeaa40e0d20d9d953bc1e2c32f5d1
> Cr-Commit-Position: refs/heads/master@{#376822}
TBR=pfeldman@chromium.org,tsepez@chromium.org,dgozman@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=585185
Review URL: https://codereview.chromium.org/1723663005
Cr-Commit-Position: refs/heads/master@{#376976}
23 files changed, 304 insertions, 181 deletions
diff --git a/components/test_runner/mock_screen_orientation_client.cc b/components/test_runner/mock_screen_orientation_client.cc index 7fe803d..80a1dbf 100644 --- a/components/test_runner/mock_screen_orientation_client.cc +++ b/components/test_runner/mock_screen_orientation_client.cc @@ -15,8 +15,7 @@ MockScreenOrientationClient::MockScreenOrientationClient() : main_frame_(NULL), current_lock_(blink::WebScreenOrientationLockDefault), device_orientation_(blink::WebScreenOrientationPortraitPrimary), - current_orientation_(blink::WebScreenOrientationPortraitPrimary), - is_active_(false) { + current_orientation_(blink::WebScreenOrientationPortraitPrimary) { } MockScreenOrientationClient::~MockScreenOrientationClient() { @@ -26,14 +25,12 @@ 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 15cb81d..ad86854 100644 --- a/components/test_runner/mock_screen_orientation_client.h +++ b/components/test_runner/mock_screen_orientation_client.h @@ -31,7 +31,6 @@ class TEST_RUNNER_EXPORT MockScreenOrientationClient blink::WebScreenOrientationType CurrentOrientationType() const; unsigned CurrentOrientationAngle() const; - bool is_active() const { return is_active_; } private: // From blink::WebScreenOrientationClient. @@ -52,7 +51,6 @@ 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 0941d7a..9a6d1f8 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_ || !screen_orientation_client_->is_active()) + if (!screen_orientation_client_) 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 2f24462..df56ffe 100755 --- a/content/browser/devtools/protocol/devtools_protocol_handler_generator.py +++ b/content/browser/devtools/protocol/devtools_protocol_handler_generator.py @@ -568,7 +568,6 @@ 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 6b124e3..f5945d7 100644 --- a/content/browser/devtools/protocol/emulation_handler.cc +++ b/content/browser/devtools/protocol/emulation_handler.cc @@ -23,19 +23,6 @@ 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 = @@ -145,11 +132,9 @@ Response EmulationHandler::SetDeviceMetricsOverride( const int* screen_width, const int* screen_height, const int* position_x, - const int* position_y, - const scoped_ptr<base::DictionaryValue>& screen_orientation) { + const int* position_y) { 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"); @@ -183,30 +168,6 @@ 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; @@ -221,8 +182,6 @@ 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 a5aec63..bcaeb0d 100644 --- a/content/browser/devtools/protocol/emulation_handler.h +++ b/content/browser/devtools/protocol/emulation_handler.h @@ -39,20 +39,18 @@ 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, - const scoped_ptr<base::DictionaryValue>& screen_orientation); + 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 ClearDeviceMetricsOverride(); private: diff --git a/content/common/view_messages.h b/content/common/view_messages.h index b343ced..db9b38d 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -161,8 +161,6 @@ 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 1022c27..5843379 100644 --- a/content/renderer/devtools/render_widget_screen_metrics_emulator.cc +++ b/content/renderer/devtools/render_widget_screen_metrics_emulator.cc @@ -99,14 +99,6 @@ 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 3f9d45d..9709d2e 100644 --- a/content/renderer/render_widget.cc +++ b/content/renderer/render_widget.cc @@ -567,7 +567,13 @@ 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( @@ -1054,10 +1060,6 @@ 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); @@ -1127,9 +1129,6 @@ 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 8739d87..c46022b 100644 --- a/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js +++ b/third_party/WebKit/LayoutTests/http/tests/inspector/inspector-test.js @@ -955,6 +955,7 @@ 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 e76a330..ebcf1df 100644 --- a/third_party/WebKit/LayoutTests/inspector/screen-orientation-override-expected.txt +++ b/third_party/WebKit/LayoutTests/inspector/screen-orientation-override-expected.txt @@ -1,18 +1,15 @@ -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 -error: Request Emulation.setDeviceMetricsOverride failed. {"code":-32602,"message":"Missing or invalid 'Screen orientation angle must be non-negative, less than 360' parameter"} +Angle should be in [0; 360) interval Running: setWrongAngle2 -error: Request Emulation.setDeviceMetricsOverride failed. {"code":-32602,"message":"Missing or invalid 'Screen orientation angle must be non-negative, less than 360' parameter"} +Angle should be in [0; 360) interval Running: setWrongType -error: Request Emulation.setDeviceMetricsOverride failed. {"code":-32602,"message":"Missing or invalid 'Invalid screen orientation type value' parameter"} +Wrong type value Running: setPortraitPrimary angle: 0; type: portrait-primary @@ -31,5 +28,5 @@ Running: setLandscapeSecondary angle: 270; type: landscape-secondary Running: clearOverride -Equals to initial: true +angle: 90; type: landscape-primary diff --git a/third_party/WebKit/LayoutTests/inspector/screen-orientation-override.html b/third_party/WebKit/LayoutTests/inspector/screen-orientation-override.html index b65b21d..11bf460 100644 --- a/third_party/WebKit/LayoutTests/inspector/screen-orientation-override.html +++ b/third_party/WebKit/LayoutTests/inspector/screen-orientation-override.html @@ -3,25 +3,16 @@ <script src="../http/tests/inspector/inspector-test.js"></script> <script> -var windowOrientationChangeEvent = false; -var screenOrientationChangeEvent = false; - -window.addEventListener("orientationchange", function() { windowOrientationChangeEvent = true; maybeLog(); }); -screen.orientation.addEventListener("change", function() { screenOrientationChangeEvent = true; maybeLog(); }); +if (!window.testRunner) + debug("This test requires testRunner"); function dump() { return "angle: " + screen.orientation.angle + "; type: " + screen.orientation.type; } -function maybeLog() -{ - if (windowOrientationChangeEvent && screenOrientationChangeEvent) { - windowOrientationChangeEvent = false; - screenOrientationChangeEvent = false; - console.log(dump()); - } -} +if (window.testRunner) + testRunner.setMockScreenOrientation("landscape-primary"); function test() { @@ -38,27 +29,29 @@ function test() function testOverride(angle, orientation, next) { - 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() {}); + var protocolCallback = addDumpResult.bind(null, next); + if (orientation) { + InspectorTest.ScreenOrientationAgent.setScreenOrientationOverride(angle, orientation, protocolCallback); + } else { + InspectorTest.ScreenOrientationAgent.clearScreenOrientationOverride(protocolCallback); + } } function testError(angle, orientation, next) { - InspectorTest.EmulationAgent.invoke_setDeviceMetricsOverride({width: 0, height: 0, deviceScaleFactor: 0, mobile: true, fitWindow: false, screenOrientation: {type: orientation, angle: angle}}, next); - } + InspectorTest.ScreenOrientationAgent.setScreenOrientationOverride(angle, orientation, protocolCallback); - var original; + function protocolCallback(error) + { + InspectorTest.addResult(error); + next(); + } + } InspectorTest.runTestSuite([ function initial(next) { - InspectorTest.evaluateInPage("dump()", dumpCallback); - - function dumpCallback(result) - { - original = result.value; - next(); - } + addDumpResult(next); }, function setWrongAngle1(next) @@ -103,18 +96,7 @@ function test() function clearOverride(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(); - } + testOverride(0, "", 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 159c002..b05b2c5 100644 --- a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js +++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js @@ -55,6 +55,8 @@ WebInspector.DeviceModeModel = function(updateCallback) this._touchEnabled = false; /** @type {string} */ this._touchConfiguration = ""; + /** @type {string} */ + this._screenOrientation = ""; /** @type {number} */ this._fitScale = 1; @@ -420,13 +422,15 @@ 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(), this._mode.orientation == WebInspector.EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary", resetPageScaleFactor); + this._applyDeviceMetrics(new Size(orientation.width, orientation.height), this._mode.insets, this._scaleSetting.get(), this._device.deviceScaleFactor, this._device.mobile(), 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()) @@ -438,8 +442,9 @@ 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, screenHeight >= screenWidth ? "portraitPrimary" : "landscapePrimary", resetPageScaleFactor); + this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new Insets(0, 0, 0, 0), this._scaleSetting.get(), this._deviceScaleFactorSetting.get() || defaultDeviceScaleFactor, mobile, resetPageScaleFactor); this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultMobileUserAgent : ""); + this._applyScreenOrientation(screenHeight >= screenWidth ? "portraitPrimary" : "landscapePrimary"); } this._reapplyTouch(); this._updateCallback.call(null); @@ -497,10 +502,9 @@ 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, screenOrientation, resetPageScaleFactor) + _applyDeviceMetrics: function(screenSize, insets, scale, deviceScaleFactor, mobile, resetPageScaleFactor) { screenSize.width = Math.max(1, Math.floor(screenSize.width)); screenSize.height = Math.max(1, Math.floor(screenSize.height)); @@ -509,7 +513,6 @@ 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; @@ -547,19 +550,13 @@ WebInspector.DeviceModeModel.prototype = { if (!this._target) return Promise.resolve(); - var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFactor && scale === 1 && !screenOrientation; + var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFactor && scale === 1; var allPromises = []; if (resetPageScaleFactor) allPromises.push(this._target.emulationAgent().resetPageScaleFactor()); - 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)); - } + 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)); allPromises.push(setDevicePromise); return Promise.all(allPromises); } @@ -617,5 +614,20 @@ 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 bd0b1a5..ddb17a1 100644 --- a/third_party/WebKit/Source/devtools/protocol.json +++ b/third_party/WebKit/Source/devtools/protocol.json @@ -336,8 +336,7 @@ { "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": "screenOrientation", "$ref": "Emulation.ScreenOrientation", "optional": true, "description": "Screen orientation override." } + { "name": "positionY", "type": "integer", "optional": true, "description": "Overriding view Y position on screen in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." } ], "handlers": ["browser"], "redirect": "Emulation", @@ -640,17 +639,6 @@ "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", @@ -667,8 +655,7 @@ { "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": "screenOrientation", "$ref": "ScreenOrientation", "optional": true, "description": "Screen orientation override." } + { "name": "positionY", "type": "integer", "optional": true, "description": "Overriding view Y position on screen in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." } ], "handlers": ["browser"] }, @@ -4823,6 +4810,32 @@ ] }, { + "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 5d03bed..8b44cbe 100644 --- a/third_party/WebKit/Source/modules/modules.gypi +++ b/third_party/WebKit/Source/modules/modules.gypi @@ -1401,6 +1401,8 @@ '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 de25e2c..8e3c862 100644 --- a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.cpp +++ b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.cpp @@ -40,6 +40,9 @@ 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) { } @@ -73,6 +76,16 @@ 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); @@ -80,16 +93,15 @@ void ScreenOrientationController::updateOrientation() ASSERT(frame()->host()); ChromeClient& chromeClient = frame()->host()->chromeClient(); - WebScreenInfo screenInfo = chromeClient.screenInfo(); - WebScreenOrientationType orientationType = screenInfo.orientationType; + WebScreenOrientationType orientationType = effectiveType(chromeClient); if (orientationType == WebScreenOrientationUndefined) { // The embedder could not provide us with an orientation, deduce it ourselves. - orientationType = computeOrientation(chromeClient.screenInfo().rect, screenInfo.orientationAngle); + orientationType = computeOrientation(chromeClient.screenInfo().rect, effectiveAngle(chromeClient)); } ASSERT(orientationType != WebScreenOrientationUndefined); m_orientation->setType(orientationType); - m_orientation->setAngle(screenInfo.orientationAngle); + m_orientation->setAngle(effectiveAngle(chromeClient)); } bool ScreenOrientationController::isActiveAndVisible() const @@ -106,7 +118,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 = frame()->host()->chromeClient().screenInfo().orientationAngle; + unsigned short currentAngle = effectiveAngle(frame()->host()->chromeClient()); // FIXME: sendOrientationChangeEvent() currently send an event all the // children of the frame, so it should only be called on the frame on @@ -170,6 +182,20 @@ 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 0a519d3..4a27fee 100644 --- a/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.h +++ b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationController.h @@ -37,6 +37,9 @@ 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(); @@ -58,6 +61,9 @@ private: // Inherited from LocalFrameLifecycleObserver. void willDetachFrameHost() override; + unsigned short effectiveAngle(ChromeClient&); + WebScreenOrientationType effectiveType(ChromeClient&); + void notifyDispatcher(); void updateOrientation(); @@ -69,6 +75,9 @@ 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 new file mode 100644 index 0000000..09968b9 --- /dev/null +++ b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp @@ -0,0 +1,112 @@ +// 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 new file mode 100644 index 0000000..b60b1ac --- /dev/null +++ b/third_party/WebKit/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.h @@ -0,0 +1,43 @@ +// 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 6d05aa8..bdf0232 100644 --- a/third_party/WebKit/Source/web/DevToolsEmulator.cpp +++ b/third_party/WebKit/Source/web/DevToolsEmulator.cpp @@ -51,7 +51,6 @@ 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()) @@ -256,8 +255,6 @@ 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); @@ -287,7 +284,6 @@ 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 74fe391..ca2c3f8 100644 --- a/third_party/WebKit/Source/web/DevToolsEmulator.h +++ b/third_party/WebKit/Source/web/DevToolsEmulator.h @@ -62,7 +62,6 @@ 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 c40a657..f561d18 100644 --- a/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp +++ b/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp @@ -69,6 +69,7 @@ #include "modules/cachestorage/InspectorCacheStorageAgent.h" #include "modules/device_orientation/DeviceOrientationInspectorAgent.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" @@ -386,6 +387,8 @@ 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 85f9f7c..c1e8f4c 100644 --- a/third_party/WebKit/public/web/WebDeviceEmulationParams.h +++ b/third_party/WebKit/public/web/WebDeviceEmulationParams.h @@ -9,7 +9,6 @@ #include "../platform/WebPoint.h" #include "../platform/WebRect.h" #include "../platform/WebSize.h" -#include "../platform/modules/screen_orientation/WebScreenOrientationType.h" namespace blink { @@ -46,27 +45,16 @@ 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) - , screenOrientationType(WebScreenOrientationUndefined) - , screenOrientationAngle(0) { } + , scale(1) { } }; 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 - && a.screenOrientationType == b.screenOrientationType && a.screenOrientationAngle == b.screenOrientationAngle; + 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; } inline bool operator!=(const WebDeviceEmulationParams& a, const WebDeviceEmulationParams& b) |