diff --git a/devtools/client/responsive/browser/content.js b/devtools/client/responsive/browser/content.js index c0168ac23081..067bd66b2630 100644 --- a/devtools/client/responsive/browser/content.js +++ b/devtools/client/responsive/browser/content.js @@ -154,6 +154,11 @@ var global = this; .getInterface(Ci.nsIWebProgress); webProgress.removeProgressListener(WebProgressListener); docShell.deviceSizeIsPageSize = gDeviceSizeWasPageSize; + // Restore the original physical screen orientation values before RDM is stopped. + // This is necessary since the window document's `setCurrentRDMPaneOrientation` + // WebIDL operation can only modify the window's screen orientation values while the + // window content is in RDM. + restoreScreenOrientation(); restoreScrollbars(); setDocumentInRDMPane(false); stopOnResize(); @@ -203,6 +208,13 @@ var global = this; flushStyle(); } + function restoreScreenOrientation() { + docShell.contentViewer.DOMDocument.setRDMPaneOrientation( + "landscape-primary", + 0 + ); + } + function setDocumentInRDMPane(inRDMPane) { // We don't propegate this property to descendent documents. docShell.browsingContext.inRDMPane = inRDMPane; diff --git a/devtools/client/responsive/components/Browser.js b/devtools/client/responsive/components/Browser.js index 2cc3d99e227b..4deb5a89f048 100644 --- a/devtools/client/responsive/components/Browser.js +++ b/devtools/client/responsive/components/Browser.js @@ -12,6 +12,7 @@ const { PureComponent } = require("devtools/client/shared/vendor/react"); const dom = require("devtools/client/shared/vendor/react-dom-factories"); const PropTypes = require("devtools/client/shared/vendor/react-prop-types"); +const { PORTRAIT_PRIMARY, LANDSCAPE_PRIMARY } = require("../constants"); const Types = require("../types"); const e10s = require("../utils/e10s"); const message = require("../utils/message"); @@ -41,6 +42,7 @@ class Browser extends PureComponent { super(props); this.onContentResize = this.onContentResize.bind(this); this.onResizeViewport = this.onResizeViewport.bind(this); + this.onSetScreenOrientation = this.onSetScreenOrientation.bind(this); } /** @@ -111,8 +113,21 @@ class Browser extends PureComponent { }); } + onSetScreenOrientation(msg) { + const { width, height } = msg.data; + const { angle, id } = this.props.viewport; + const type = height >= width ? PORTRAIT_PRIMARY : LANDSCAPE_PRIMARY; + + this.props.onChangeViewportOrientation(id, type, angle); + } + async startFrameScript() { - const { browser, onContentResize, onResizeViewport } = this; + const { + browser, + onContentResize, + onResizeViewport, + onSetScreenOrientation, + } = this; const mm = browser.frameLoader.messageManager; // Notify tests when the content has received a resize event. This is not @@ -121,6 +136,7 @@ class Browser extends PureComponent { // resized to match. e10s.on(mm, "OnContentResize", onContentResize); e10s.on(mm, "OnResizeViewport", onResizeViewport); + e10s.on(mm, "OnLocationChange", onSetScreenOrientation); const ready = e10s.once(mm, "ChildScriptReady"); mm.loadFrameScript(FRAME_SCRIPT, true); @@ -139,11 +155,17 @@ class Browser extends PureComponent { } async stopFrameScript() { - const { browser, onContentResize, onResizeViewport } = this; + const { + browser, + onContentResize, + onResizeViewport, + onSetScreenOrientation, + } = this; const mm = browser.frameLoader.messageManager; e10s.off(mm, "OnContentResize", onContentResize); e10s.off(mm, "OnResizeViewport", onResizeViewport); + e10s.off(mm, "OnLocationChange", onSetScreenOrientation); await e10s.request(mm, "Stop"); message.post(window, "stop-frame-script:done"); } diff --git a/devtools/client/responsive/ui.js b/devtools/client/responsive/ui.js index 8ecdbc9a20a0..f042add89560 100644 --- a/devtools/client/responsive/ui.js +++ b/devtools/client/responsive/ui.js @@ -304,9 +304,6 @@ class ResponsiveUI { // Ensure init has finished before starting destroy if (!isTabContentDestroying) { await this.inited; - - // Restore screen orientation of physical device. - await this.updateScreenOrientation("landscape-primary", 0); } if (this.isBrowserUIEnabled) { diff --git a/devtools/server/actors/emulation.js b/devtools/server/actors/emulation.js index 0e0a54f8a0cc..22eeefe9c3e3 100644 --- a/devtools/server/actors/emulation.js +++ b/devtools/server/actors/emulation.js @@ -423,7 +423,7 @@ const EmulationActor = protocol.ActorClassWithSpec(emulationSpec, { this.win.screen.orientation.angle !== angle || this.win.screen.orientation.type !== type ) { - this.docShell.browsingContext.setRDMPaneOrientation(type, angle); + this.win.document.setRDMPaneOrientation(type, angle); } }, diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index 660273909638..e859fbabcaa1 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -52,17 +52,6 @@ extern mozilla::LazyLogModule gAutoplayPermissionLog; #define AUTOPLAY_LOG(msg, ...) \ MOZ_LOG(gAutoplayPermissionLog, LogLevel::Debug, (msg, ##__VA_ARGS__)) -namespace IPC { -// Allow serialization and deserialization of OrientationType over IPC -template <> -struct ParamTraits - : public ContiguousEnumSerializerInclusive< - mozilla::dom::OrientationType, - mozilla::dom::OrientationType::Portrait_primary, - mozilla::dom::OrientationType::Landscape_secondary> {}; - -} // namespace IPC - namespace mozilla { namespace dom { diff --git a/docshell/base/BrowsingContext.h b/docshell/base/BrowsingContext.h index a19601fbd78e..54fcfa96a4c4 100644 --- a/docshell/base/BrowsingContext.h +++ b/docshell/base/BrowsingContext.h @@ -273,18 +273,6 @@ class BrowsingContext : public nsISupports, bool IsLoading(); - // ScreenOrientation related APIs - void SetCurrentOrientation(OrientationType aType, float aAngle) { - SetCurrentOrientationType(aType); - SetCurrentOrientationAngle(aAngle); - } - - void SetRDMPaneOrientation(OrientationType aType, float aAngle) { - if (mInRDMPane) { - SetCurrentOrientation(aType, aAngle); - } - } - // Using the rules for choosing a browsing context we try to find // the browsing context with the given name in the set of // transitively reachable browsing contexts. Performs access control diff --git a/docshell/base/BrowsingContextFieldList.h b/docshell/base/BrowsingContextFieldList.h index f2f5f84f34ce..12a190f2efb1 100644 --- a/docshell/base/BrowsingContextFieldList.h +++ b/docshell/base/BrowsingContextFieldList.h @@ -42,11 +42,6 @@ MOZ_BC_FIELD(FeaturePolicy, RefPtr) // See nsSandboxFlags.h for the possible flags. MOZ_BC_FIELD(SandboxFlags, uint32_t) -// ScreenOrientation-related APIs -MOZ_BC_FIELD(CurrentOrientationAngle, float) - -MOZ_BC_FIELD(CurrentOrientationType, mozilla::dom::OrientationType) - MOZ_BC_FIELD(HistoryID, nsID) MOZ_BC_FIELD(InRDMPane, bool) diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index c1fb28999a7e..74950a3ca65f 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -1346,6 +1346,8 @@ Document::Document(const char* aContentType) mFlashClassification(FlashClassification::Unknown), mScrollAnchorAdjustmentLength(0), mScrollAnchorAdjustmentCount(0), + mCurrentOrientationAngle(0), + mCurrentOrientationType(OrientationType::Portrait_primary), mServoRestyleRootDirtyBits(0), mThrowOnDynamicMarkupInsertionCounter(0), mIgnoreOpensDuringUnloadCounter(0), @@ -13570,6 +13572,12 @@ bool Document::SetOrientationPendingPromise(Promise* aPromise) { return true; } +void Document::SetRDMPaneOrientation(OrientationType aType, uint16_t aAngle) { + if (GetBrowsingContext()->InRDMPane()) { + SetCurrentOrientation(aType, aAngle); + } +} + static void DispatchPointerLockChange(Document* aTarget) { if (!aTarget) { return; diff --git a/dom/base/Document.h b/dom/base/Document.h index 04dc98c4a8ce..2ff664c96237 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -2289,12 +2289,23 @@ class Document : public nsINode, // ScreenOrientation related APIs + void SetCurrentOrientation(OrientationType aType, uint16_t aAngle) { + mCurrentOrientationType = aType; + mCurrentOrientationAngle = aAngle; + } + + uint16_t CurrentOrientationAngle() const { return mCurrentOrientationAngle; } + OrientationType CurrentOrientationType() const { + return mCurrentOrientationType; + } void ClearOrientationPendingPromise(); bool SetOrientationPendingPromise(Promise* aPromise); Promise* GetOrientationPendingPromise() const { return mOrientationPendingPromise; } + void SetRDMPaneOrientation(OrientationType aType, uint16_t aAngle); + //---------------------------------------------------------------------- // Document notification API's @@ -5237,6 +5248,9 @@ class Document : public nsINode, // http://www.w3.org/TR/screen-orientation/ RefPtr mOrientationPendingPromise; + uint16_t mCurrentOrientationAngle; + OrientationType mCurrentOrientationType; + nsTArray> mInitializableFrameLoaders; nsTArray> mFrameLoaderFinalizers; RefPtr> mFrameLoaderRunner; diff --git a/dom/base/ScreenOrientation.cpp b/dom/base/ScreenOrientation.cpp index 91d3cee831bb..c50ca005488a 100644 --- a/dom/base/ScreenOrientation.cpp +++ b/dom/base/ScreenOrientation.cpp @@ -78,9 +78,8 @@ ScreenOrientation::ScreenOrientation(nsPIDOMWindowInner* aWindow, mAngle = config.angle(); Document* doc = GetResponsibleDocument(); - BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr; - if (bc && !bc->InRDMPane()) { - bc->SetCurrentOrientation(mType, mAngle); + if (doc) { + doc->SetCurrentOrientation(mType, mAngle); } } @@ -195,10 +194,9 @@ ScreenOrientation::LockOrientationTask::Run() { return NS_OK; } - BrowsingContext* bc = mDocument->GetBrowsingContext(); - if (OrientationLockContains(bc->GetCurrentOrientationType()) || + if (OrientationLockContains(mDocument->CurrentOrientationType()) || (mOrientationLock == hal::eScreenOrientation_Default && - bc->GetCurrentOrientationAngle() == 0)) { + mDocument->CurrentOrientationAngle() == 0)) { // Orientation lock will not cause an orientation change. mPromise->MaybeResolveWithUndefined(); mDocument->ClearOrientationPendingPromise(); @@ -422,13 +420,12 @@ OrientationType ScreenOrientation::GetType(CallerType aCallerType, } Document* doc = GetResponsibleDocument(); - BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr; - if (!bc) { + if (!doc) { aRv.Throw(NS_ERROR_UNEXPECTED); return OrientationType::Portrait_primary; } - return bc->GetCurrentOrientationType(); + return doc->CurrentOrientationType(); } uint16_t ScreenOrientation::GetAngle(CallerType aCallerType, @@ -438,13 +435,12 @@ uint16_t ScreenOrientation::GetAngle(CallerType aCallerType, } Document* doc = GetResponsibleDocument(); - BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr; - if (!bc) { + if (!doc) { aRv.Throw(NS_ERROR_UNEXPECTED); return 0; } - return bc->GetCurrentOrientationAngle(); + return doc->CurrentOrientationAngle(); } ScreenOrientation::LockPermission @@ -494,8 +490,7 @@ void ScreenOrientation::Notify(const hal::ScreenConfiguration& aConfiguration) { } Document* doc = GetResponsibleDocument(); - BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr; - if (!bc) { + if (!doc) { return; } @@ -531,8 +526,8 @@ void ScreenOrientation::Notify(const hal::ScreenConfiguration& aConfiguration) { return; } - if (mType != bc->GetCurrentOrientationType()) { - bc->SetCurrentOrientation(mType, mAngle); + if (mType != doc->CurrentOrientationType()) { + doc->SetCurrentOrientation(mType, mAngle); nsCOMPtr runnable = DispatchChangeEventAndResolvePromise(); rv = NS_DispatchToMainThread(runnable); @@ -614,10 +609,9 @@ ScreenOrientation::VisibleEventListener::HandleEvent(Event* aEvent) { target->RemoveSystemEventListener(NS_LITERAL_STRING("visibilitychange"), this, true); - BrowsingContext* bc = doc->GetBrowsingContext(); - if (bc && bc->GetCurrentOrientationType() != + if (doc->CurrentOrientationType() != orientation->DeviceType(CallerType::System)) { - bc->SetCurrentOrientation(orientation->DeviceType(CallerType::System), + doc->SetCurrentOrientation(orientation->DeviceType(CallerType::System), orientation->DeviceAngle(CallerType::System)); nsCOMPtr runnable = diff --git a/dom/chrome-webidl/BrowsingContext.webidl b/dom/chrome-webidl/BrowsingContext.webidl index b8bd42c9fa8e..c658b4075171 100644 --- a/dom/chrome-webidl/BrowsingContext.webidl +++ b/dom/chrome-webidl/BrowsingContext.webidl @@ -51,10 +51,6 @@ interface BrowsingContext { // The inRDMPane flag indicates whether or not Responsive Design Mode is // active for the browsing context. attribute boolean inRDMPane; - - // Extension to give chrome JS the ability to set the window screen - // orientation while in RDM. - void setRDMPaneOrientation(OrientationType type, float rotationAngle); }; [Exposed=Window, ChromeOnly] diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index f9228873fc27..6a8d4c590014 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -622,6 +622,16 @@ partial interface Document { readonly attribute FeaturePolicy featurePolicy; }; +/** + * Document extensions to support devtools. + */ +partial interface Document { + // Extension to give chrome JS the ability to set the window screen + // orientation while in RDM. + [ChromeOnly] + void setRDMPaneOrientation(OrientationType type, float rotationAngle); +}; + // Extension to give chrome JS the ability to specify a non-default keypress // event model. partial interface Document {