Bug 1523305 - Show Font Editor in read-only mode for pseudo-elements. r=gl

Adds a new `disabled` property to the Font Editor Redux store applicable to all input fields.
When inspecting a pseudo-element, this `disabled` property is set to true.
This allows the pseudo-element to be inspected, but prevents editing font property values because it's currently not possible to write them back to CSS rules other than element inline styles.

Differential Revision: https://phabricator.services.mozilla.com/D18364

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Razvan Caliman 2019-02-04 12:05:23 +00:00
Родитель e26b523f00
Коммит b82d1224bf
14 изменённых файлов: 58 добавлений и 22 удалений

Просмотреть файл

@ -7,6 +7,7 @@
const { const {
APPLY_FONT_VARIATION_INSTANCE, APPLY_FONT_VARIATION_INSTANCE,
RESET_EDITOR, RESET_EDITOR,
SET_FONT_EDITOR_DISABLED,
UPDATE_AXIS_VALUE, UPDATE_AXIS_VALUE,
UPDATE_CUSTOM_INSTANCE, UPDATE_CUSTOM_INSTANCE,
UPDATE_EDITOR_STATE, UPDATE_EDITOR_STATE,
@ -22,6 +23,13 @@ module.exports = {
}; };
}, },
setEditorDisabled(disabled = false) {
return {
type: SET_FONT_EDITOR_DISABLED,
disabled,
};
},
applyInstance(name, values) { applyInstance(name, values) {
return { return {
type: APPLY_FONT_VARIATION_INSTANCE, type: APPLY_FONT_VARIATION_INSTANCE,

Просмотреть файл

@ -7,25 +7,24 @@
const { createEnum } = require("devtools/client/shared/enum"); const { createEnum } = require("devtools/client/shared/enum");
createEnum([ createEnum([
// Update the custom font variation instance with the current axes values.
"UPDATE_CUSTOM_INSTANCE",
// Reset font editor to intial state. // Reset font editor to intial state.
"RESET_EDITOR", "RESET_EDITOR",
// Set the font editor disabled state which prevents users from interacting with inputs.
"SET_FONT_EDITOR_DISABLED",
// Apply the variation settings of a font instance. // Apply the variation settings of a font instance.
"APPLY_FONT_VARIATION_INSTANCE", "APPLY_FONT_VARIATION_INSTANCE",
// Update the custom font variation instance with the current axes values.
"UPDATE_CUSTOM_INSTANCE",
// Update the value of a variable font axis. // Update the value of a variable font axis.
"UPDATE_AXIS_VALUE", "UPDATE_AXIS_VALUE",
// Update font editor with applicable fonts and user-defined CSS font properties. // Update font editor with applicable fonts and user-defined CSS font properties.
"UPDATE_EDITOR_STATE", "UPDATE_EDITOR_STATE",
// Toggle the visibiltiy of the font editor
"UPDATE_EDITOR_VISIBILITY",
// Update the list of fonts. // Update the list of fonts.
"UPDATE_FONTS", "UPDATE_FONTS",

Просмотреть файл

@ -15,6 +15,7 @@ class FontAxis extends PureComponent {
static get propTypes() { static get propTypes() {
return { return {
axis: PropTypes.shape(Types.fontVariationAxis), axis: PropTypes.shape(Types.fontVariationAxis),
disabled: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired, value: PropTypes.string.isRequired,
}; };
@ -51,6 +52,7 @@ class FontAxis extends PureComponent {
return FontPropertyValue({ return FontPropertyValue({
className: "font-control-axis", className: "font-control-axis",
disabled: this.props.disabled,
label: axis.name, label: axis.name,
min: axis.minValue, min: axis.minValue,
minLabel: true, minLabel: true,

Просмотреть файл

@ -54,6 +54,7 @@ class FontEditor extends PureComponent {
return FontAxis({ return FontAxis({
key: axis.tag, key: axis.tag,
axis, axis,
disabled: this.props.fontEditor.disabled,
onChange: this.props.onPropertyChange, onChange: this.props.onPropertyChange,
minLabel: true, minLabel: true,
maxLabel: true, maxLabel: true,
@ -143,6 +144,7 @@ class FontEditor extends PureComponent {
renderFontSize(value) { renderFontSize(value) {
return value !== null && FontSize({ return value !== null && FontSize({
key: `${this.props.fontEditor.id}:font-size`, key: `${this.props.fontEditor.id}:font-size`,
disabled: this.props.fontEditor.disabled,
onChange: this.props.onPropertyChange, onChange: this.props.onPropertyChange,
value, value,
}); });
@ -151,6 +153,7 @@ class FontEditor extends PureComponent {
renderLineHeight(value) { renderLineHeight(value) {
return value !== null && LineHeight({ return value !== null && LineHeight({
key: `${this.props.fontEditor.id}:line-height`, key: `${this.props.fontEditor.id}:line-height`,
disabled: this.props.fontEditor.disabled,
onChange: this.props.onPropertyChange, onChange: this.props.onPropertyChange,
value, value,
}); });
@ -159,6 +162,7 @@ class FontEditor extends PureComponent {
renderFontStyle(value) { renderFontStyle(value) {
return value && FontStyle({ return value && FontStyle({
onChange: this.props.onPropertyChange, onChange: this.props.onPropertyChange,
disabled: this.props.fontEditor.disabled,
value, value,
}); });
} }
@ -166,6 +170,7 @@ class FontEditor extends PureComponent {
renderFontWeight(value) { renderFontWeight(value) {
return value !== null && FontWeight({ return value !== null && FontWeight({
onChange: this.props.onPropertyChange, onChange: this.props.onPropertyChange,
disabled: this.props.fontEditor.disabled,
value, value,
}); });
} }

Просмотреть файл

@ -24,6 +24,7 @@ class FontPropertyValue extends PureComponent {
autoIncrement: PropTypes.bool, autoIncrement: PropTypes.bool,
className: PropTypes.string, className: PropTypes.string,
defaultValue: PropTypes.number, defaultValue: PropTypes.number,
disabled: PropTypes.bool.isRequired,
label: PropTypes.string.isRequired, label: PropTypes.string.isRequired,
min: PropTypes.number.isRequired, min: PropTypes.number.isRequired,
// Whether to show the `min` prop value as a label. // Whether to show the `min` prop value as a label.
@ -375,12 +376,13 @@ class FontPropertyValue extends PureComponent {
return dom.select( return dom.select(
{ {
className: "font-value-select", className: "font-value-select",
disabled: this.props.disabled,
onChange: this.onUnitChange, onChange: this.onUnitChange,
value: this.props.unit,
}, },
options.map(unit => { options.map(unit => {
return dom.option( return dom.option(
{ {
selected: unit === this.props.unit,
value: unit, value: unit,
}, },
unit unit
@ -450,6 +452,7 @@ class FontPropertyValue extends PureComponent {
onMouseMove: this.onMouseMove, onMouseMove: this.onMouseMove,
onMouseUp: this.onMouseUp, onMouseUp: this.onMouseUp,
className: "font-value-slider", className: "font-value-slider",
disabled: this.props.disabled,
name: this.props.name, name: this.props.name,
title: this.props.label, title: this.props.label,
type: "range", type: "range",
@ -463,6 +466,7 @@ class FontPropertyValue extends PureComponent {
max: this.props.autoIncrement ? null : this.props.max, max: this.props.autoIncrement ? null : this.props.max,
name: this.props.name, name: this.props.name,
className: "font-value-input", className: "font-value-input",
disabled: this.props.disabled,
type: "number", type: "number",
} }
); );
@ -470,6 +474,7 @@ class FontPropertyValue extends PureComponent {
return dom.label( return dom.label(
{ {
className: `font-control ${this.props.className}`, className: `font-control ${this.props.className}`,
disabled: this.props.disabled,
}, },
dom.div( dom.div(
{ {

Просмотреть файл

@ -15,6 +15,7 @@ const { getUnitFromValue, getStepForUnit } = require("../utils/font-utils");
class FontSize extends PureComponent { class FontSize extends PureComponent {
static get propTypes() { static get propTypes() {
return { return {
disabled: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired, value: PropTypes.string.isRequired,
}; };
@ -59,6 +60,7 @@ class FontSize extends PureComponent {
return FontPropertyValue({ return FontPropertyValue({
autoIncrement: true, autoIncrement: true,
disabled: this.props.disabled,
label: getStr("fontinspector.fontSizeLabel"), label: getStr("fontinspector.fontSizeLabel"),
min: 0, min: 0,
max: this.historicMax[unit], max: this.historicMax[unit],

Просмотреть файл

@ -13,6 +13,7 @@ const { getStr } = require("../utils/l10n");
class FontStyle extends PureComponent { class FontStyle extends PureComponent {
static get propTypes() { static get propTypes() {
return { return {
disabled: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired, value: PropTypes.string.isRequired,
}; };
@ -47,6 +48,7 @@ class FontStyle extends PureComponent {
{ {
checked: this.props.value === "italic" || this.props.value === "oblique", checked: this.props.value === "italic" || this.props.value === "oblique",
className: "devtools-checkbox-toggle", className: "devtools-checkbox-toggle",
disabled: this.props.disabled,
name: this.name, name: this.name,
onChange: this.onToggle, onChange: this.onToggle,
type: "checkbox", type: "checkbox",

Просмотреть файл

@ -14,6 +14,7 @@ const { getStr } = require("../utils/l10n");
class FontWeight extends PureComponent { class FontWeight extends PureComponent {
static get propTypes() { static get propTypes() {
return { return {
disabled: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired, value: PropTypes.string.isRequired,
}; };
@ -21,6 +22,7 @@ class FontWeight extends PureComponent {
render() { render() {
return FontPropertyValue({ return FontPropertyValue({
disabled: this.props.disabled,
label: getStr("fontinspector.fontWeightLabel"), label: getStr("fontinspector.fontWeightLabel"),
min: 100, min: 100,
max: 900, max: 900,

Просмотреть файл

@ -15,6 +15,7 @@ const { getUnitFromValue, getStepForUnit } = require("../utils/font-utils");
class LineHeight extends PureComponent { class LineHeight extends PureComponent {
static get propTypes() { static get propTypes() {
return { return {
disabled: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired, value: PropTypes.string.isRequired,
}; };
@ -62,6 +63,7 @@ class LineHeight extends PureComponent {
return FontPropertyValue({ return FontPropertyValue({
autoIncrement: true, autoIncrement: true,
disabled: this.props.disabled,
label: getStr("fontinspector.lineHeightLabelCapitalized"), label: getStr("fontinspector.lineHeightLabelCapitalized"),
min: 0, min: 0,
max: this.historicMax[unit], max: this.historicMax[unit],

Просмотреть файл

@ -25,11 +25,11 @@ const { updateFonts } = require("./actions/fonts");
const { const {
applyInstance, applyInstance,
resetFontEditor, resetFontEditor,
setEditorDisabled,
updateAxis, updateAxis,
updateCustomInstance, updateCustomInstance,
updateFontEditor, updateFontEditor,
updateFontProperty, updateFontProperty,
updateWarningMessage,
} = require("./actions/font-editor"); } = require("./actions/font-editor");
const { updatePreviewText } = require("./actions/font-options"); const { updatePreviewText } = require("./actions/font-options");
@ -549,8 +549,7 @@ class FontInspector {
return this.inspector && return this.inspector &&
this.inspector.selection.nodeFront && this.inspector.selection.nodeFront &&
this.inspector.selection.isConnected() && this.inspector.selection.isConnected() &&
this.inspector.selection.isElementNode() && this.inspector.selection.isElementNode();
!this.inspector.selection.isPseudoElementNode();
} }
/** /**
@ -794,13 +793,6 @@ class FontInspector {
*/ */
async refreshFontEditor() { async refreshFontEditor() {
if (!this.store || !this.isSelectedNodeValid()) { if (!this.store || !this.isSelectedNodeValid()) {
if (this.inspector.selection.isPseudoElementNode()) {
const noPseudoWarning = getStr("fontinspector.noPseduoWarning");
this.store.dispatch(resetFontEditor());
this.store.dispatch(updateWarningMessage(noPseudoWarning));
return;
}
// If the selection is a TextNode, switch selection to be its parent node. // If the selection is a TextNode, switch selection to be its parent node.
if (this.inspector.selection.isTextNode()) { if (this.inspector.selection.isTextNode()) {
const selection = this.inspector.selection; const selection = this.inspector.selection;
@ -865,6 +857,9 @@ class FontInspector {
}); });
this.store.dispatch(updateFontEditor(fonts, properties, node.actorID)); this.store.dispatch(updateFontEditor(fonts, properties, node.actorID));
const isPseudo = this.inspector.selection.isPseudoElementNode();
this.store.dispatch(setEditorDisabled(isPseudo));
this.inspector.emit("fonteditor-updated"); this.inspector.emit("fonteditor-updated");
// Listen to manual changes in the Rule view that could update the Font Editor state // Listen to manual changes in the Rule view that could update the Font Editor state
this.ruleView.on("property-value-updated", this.onRulePropertyUpdated); this.ruleView.on("property-value-updated", this.onRulePropertyUpdated);

Просмотреть файл

@ -10,6 +10,7 @@ const { parseFontVariationAxes } = require("../utils/font-utils");
const { const {
APPLY_FONT_VARIATION_INSTANCE, APPLY_FONT_VARIATION_INSTANCE,
RESET_EDITOR, RESET_EDITOR,
SET_FONT_EDITOR_DISABLED,
UPDATE_AXIS_VALUE, UPDATE_AXIS_VALUE,
UPDATE_CUSTOM_INSTANCE, UPDATE_CUSTOM_INSTANCE,
UPDATE_EDITOR_STATE, UPDATE_EDITOR_STATE,
@ -22,6 +23,8 @@ const INITIAL_STATE = {
axes: {}, axes: {},
// Copy of the most recent axes values. Used to revert from a named instance. // Copy of the most recent axes values. Used to revert from a named instance.
customInstanceValues: [], customInstanceValues: [],
// When true, prevent users from interacting with inputs in the font editor.
disabled: false,
// Fonts used on the selected element. // Fonts used on the selected element.
fonts: [], fonts: [],
// Current selected font variation instance. // Current selected font variation instance.
@ -75,6 +78,10 @@ const reducers = {
return newState; return newState;
}, },
[SET_FONT_EDITOR_DISABLED](state, { disabled }) {
return { ...state, disabled };
},
[UPDATE_EDITOR_STATE](state, { fonts, properties, id }) { [UPDATE_EDITOR_STATE](state, { fonts, properties, id }) {
const axes = parseFontVariationAxes(properties["font-variation-settings"]); const axes = parseFontVariationAxes(properties["font-variation-settings"]);

Просмотреть файл

@ -49,10 +49,6 @@ fontinspector.showMore=Show more
# LOCALIZATION NOTE (fontinspector.showLess): Label for an expanded list of fonts. # LOCALIZATION NOTE (fontinspector.showLess): Label for an expanded list of fonts.
fontinspector.showLess=Show less fontinspector.showLess=Show less
# LOCALIZATION NOTE (fontinspector.noPseduoWarning): Warning message shown when the
# selected element is a pseudo-element that the font editor cannot work with.
fontinspector.noPseduoWarning=Pseudo-elements are not currently supported.
# LOCALIZATION NOTE (fontinspector.lineHeightLabelCapitalized): Label for the UI to change the line height in the font editor. # LOCALIZATION NOTE (fontinspector.lineHeightLabelCapitalized): Label for the UI to change the line height in the font editor.
fontinspector.lineHeightLabelCapitalized=Line Height fontinspector.lineHeightLabelCapitalized=Line Height

Просмотреть файл

@ -826,6 +826,10 @@ checkbox:-moz-focusring {
transition: background-color .1s ease-out; transition: background-color .1s ease-out;
} }
.devtools-checkbox-toggle[disabled]{
opacity: 0.5;
}
/* For right-to-left layout, the toggle thumb goes in the opposite direction. */ /* For right-to-left layout, the toggle thumb goes in the opposite direction. */
html[dir="rtl"] .devtools-checkbox-toggle { html[dir="rtl"] .devtools-checkbox-toggle {
--x-pos: -.15em; --x-pos: -.15em;

Просмотреть файл

@ -254,6 +254,13 @@
background-color: var(--input-background-color); background-color: var(--input-background-color);
} }
/* Styles for disabled input fields */
.font-value-input[disabled],
.font-value-select[disabled],
.font-value-slider[disabled] {
opacity: 0.5;
}
/* Do not use browser "invalid" state */ /* Do not use browser "invalid" state */
.font-value-slider:-moz-ui-invalid, .font-value-slider:-moz-ui-invalid,
.font-value-input:-moz-ui-invalid { .font-value-input:-moz-ui-invalid {