mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 11:37:43 -10:00
This patch gives the RDM UI the ability to update the screen orientation based on the orientation of the simulated device screen. It fixes the following issues: - Initializing the orientation state of the selected device when RDM is opened. - Updating orientation state when the rotate button in the RDM toolbar is pressed. - Updating the orientation state when a new device is selected. There are three actions creators that are responsible for notifying the ResponsiveUI manager, `changeDevice`, `restoreDeviceState`, and `rotateViewport`. In particular: - `restoreDeviceState` is dispatched when the Responsive UI has finished initializing. If a previous RDM session had a device selected, then this action creator will also dispatch the `changeDevice` action to update the RDM UI to reflect the currently selected device. - `changeDevice` is dispatched when a device is selected. - `rotateViewport` is dispatched when the rotate button is clicked in the RDM toolbar. When either of these actions is dispatched, we post a "viewport-orientation-change" message to the window that notifies the manager to update the screen orientation accordingly. Finally, when RDM is closed, we need to ensure the original physical screen orientation is restored. We do this by calling the `setRDMPaneOrientation` on the docShell's document in the content frame script. Differential Revision: https://phabricator.services.mozilla.com/D30440
99 lines
3.1 KiB
JavaScript
99 lines
3.1 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
const { createFactory, 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 { connect } = require("devtools/client/shared/vendor/react-redux");
|
|
|
|
const ResizableViewport = createFactory(require("./ResizableViewport"));
|
|
|
|
const Types = require("../types");
|
|
|
|
class Viewports extends PureComponent {
|
|
static get propTypes() {
|
|
return {
|
|
leftAlignmentEnabled: PropTypes.bool.isRequired,
|
|
onBrowserMounted: PropTypes.func.isRequired,
|
|
onChangeViewportOrientation: PropTypes.func.isRequired,
|
|
onContentResize: PropTypes.func.isRequired,
|
|
onRemoveDeviceAssociation: PropTypes.func.isRequired,
|
|
doResizeViewport: PropTypes.func.isRequired,
|
|
onResizeViewport: PropTypes.func.isRequired,
|
|
screenshot: PropTypes.shape(Types.screenshot).isRequired,
|
|
viewports: PropTypes.arrayOf(PropTypes.shape(Types.viewport)).isRequired,
|
|
};
|
|
}
|
|
|
|
render() {
|
|
const {
|
|
leftAlignmentEnabled,
|
|
onBrowserMounted,
|
|
onChangeViewportOrientation,
|
|
onContentResize,
|
|
onRemoveDeviceAssociation,
|
|
doResizeViewport,
|
|
onResizeViewport,
|
|
screenshot,
|
|
viewports,
|
|
} = this.props;
|
|
|
|
const viewportSize = window.getViewportSize();
|
|
// The viewport may not have been created yet. Default to justify-content: center
|
|
// for the container.
|
|
let justifyContent = "center";
|
|
|
|
// If the RDM viewport is bigger than the window's inner width, set the container's
|
|
// justify-content to start so that the left-most viewport is visible when there's
|
|
// horizontal overflow. That is when the horizontal space become smaller than the
|
|
// viewports and a scrollbar appears, then the first viewport will still be visible.
|
|
if (leftAlignmentEnabled ||
|
|
(viewportSize && viewportSize.width > window.innerWidth)) {
|
|
justifyContent = "start";
|
|
}
|
|
|
|
return (
|
|
dom.div(
|
|
{
|
|
id: "viewports-container",
|
|
style: {
|
|
justifyContent,
|
|
},
|
|
},
|
|
dom.div(
|
|
{
|
|
id: "viewports",
|
|
className: leftAlignmentEnabled ? "left-aligned" : "",
|
|
},
|
|
viewports.map((viewport, i) => {
|
|
return ResizableViewport({
|
|
key: viewport.id,
|
|
leftAlignmentEnabled,
|
|
onBrowserMounted,
|
|
onChangeViewportOrientation,
|
|
onContentResize,
|
|
onRemoveDeviceAssociation,
|
|
doResizeViewport,
|
|
onResizeViewport,
|
|
screenshot,
|
|
swapAfterMount: i == 0,
|
|
viewport,
|
|
});
|
|
})
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = state => {
|
|
return {
|
|
leftAlignmentEnabled: state.ui.leftAlignmentEnabled,
|
|
};
|
|
};
|
|
|
|
module.exports = connect(mapStateToProps)(Viewports);
|