mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 07:18:39 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
131
devtools/client/responsive.html/components/dpr-selector.js
Normal file
131
devtools/client/responsive.html/components/dpr-selector.js
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/* 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/. */
|
||||
|
||||
/* eslint-env browser */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { DOM: dom, createClass, PropTypes, addons } =
|
||||
require("devtools/client/shared/vendor/react");
|
||||
|
||||
const Types = require("../types");
|
||||
const { getStr, getFormatStr } = require("../utils/l10n");
|
||||
|
||||
const PIXEL_RATIO_PRESET = [1, 2, 3];
|
||||
|
||||
const createVisibleOption = value =>
|
||||
dom.option({
|
||||
value,
|
||||
title: value,
|
||||
key: value,
|
||||
}, value);
|
||||
|
||||
const createHiddenOption = value =>
|
||||
dom.option({
|
||||
value,
|
||||
title: value,
|
||||
hidden: true,
|
||||
disabled: true,
|
||||
}, value);
|
||||
|
||||
module.exports = createClass({
|
||||
displayName: "DPRSelector",
|
||||
|
||||
propTypes: {
|
||||
devices: PropTypes.shape(Types.devices).isRequired,
|
||||
displayPixelRatio: Types.pixelRatio.value.isRequired,
|
||||
selectedDevice: PropTypes.string.isRequired,
|
||||
selectedPixelRatio: PropTypes.shape(Types.pixelRatio).isRequired,
|
||||
onChangePixelRatio: PropTypes.func.isRequired,
|
||||
},
|
||||
|
||||
mixins: [ addons.PureRenderMixin ],
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
isFocused: false
|
||||
};
|
||||
},
|
||||
|
||||
onFocusChange({type}) {
|
||||
this.setState({
|
||||
isFocused: type === "focus"
|
||||
});
|
||||
},
|
||||
|
||||
onSelectChange({ target }) {
|
||||
this.props.onChangePixelRatio(+target.value);
|
||||
},
|
||||
|
||||
render() {
|
||||
let {
|
||||
devices,
|
||||
displayPixelRatio,
|
||||
selectedDevice,
|
||||
selectedPixelRatio,
|
||||
} = this.props;
|
||||
|
||||
let hiddenOptions = [];
|
||||
|
||||
for (let type of devices.types) {
|
||||
for (let device of devices[type]) {
|
||||
if (device.displayed &&
|
||||
!hiddenOptions.includes(device.pixelRatio) &&
|
||||
!PIXEL_RATIO_PRESET.includes(device.pixelRatio)) {
|
||||
hiddenOptions.push(device.pixelRatio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!PIXEL_RATIO_PRESET.includes(displayPixelRatio)) {
|
||||
hiddenOptions.push(displayPixelRatio);
|
||||
}
|
||||
|
||||
let state = devices.listState;
|
||||
let isDisabled = (state !== Types.deviceListState.LOADED) || (selectedDevice !== "");
|
||||
let selectorClass = "";
|
||||
let title;
|
||||
|
||||
if (isDisabled) {
|
||||
selectorClass += " disabled";
|
||||
title = getFormatStr("responsive.autoDPR", selectedDevice);
|
||||
} else {
|
||||
title = getStr("responsive.devicePixelRatio");
|
||||
|
||||
if (selectedPixelRatio.value) {
|
||||
selectorClass += " selected";
|
||||
}
|
||||
}
|
||||
|
||||
if (this.state.isFocused) {
|
||||
selectorClass += " focused";
|
||||
}
|
||||
|
||||
let listContent = PIXEL_RATIO_PRESET.map(createVisibleOption);
|
||||
|
||||
if (state == Types.deviceListState.LOADED) {
|
||||
listContent = listContent.concat(hiddenOptions.map(createHiddenOption));
|
||||
}
|
||||
|
||||
return dom.label(
|
||||
{
|
||||
id: "global-dpr-selector",
|
||||
className: selectorClass,
|
||||
title,
|
||||
},
|
||||
"DPR",
|
||||
dom.select(
|
||||
{
|
||||
value: selectedPixelRatio.value || displayPixelRatio,
|
||||
disabled: isDisabled,
|
||||
onChange: this.onSelectChange,
|
||||
onFocus: this.onFocusChange,
|
||||
onBlur: this.onFocusChange,
|
||||
},
|
||||
...listContent
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue