summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/boxmodel/actions
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--devtools/client/inspector/boxmodel/actions/box-model-highlighter.js86
-rw-r--r--devtools/client/inspector/boxmodel/actions/box-model.js46
-rw-r--r--devtools/client/inspector/boxmodel/actions/index.js21
-rw-r--r--devtools/client/inspector/boxmodel/actions/moz.build11
4 files changed, 164 insertions, 0 deletions
diff --git a/devtools/client/inspector/boxmodel/actions/box-model-highlighter.js b/devtools/client/inspector/boxmodel/actions/box-model-highlighter.js
new file mode 100644
index 0000000000..9033dc46ae
--- /dev/null
+++ b/devtools/client/inspector/boxmodel/actions/box-model-highlighter.js
@@ -0,0 +1,86 @@
+/* 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";
+
+/**
+ * This module exports thunks.
+ * Thunks are functions that can be dispatched to the Inspector Redux store.
+ *
+ * These functions receive one object with options that contains:
+ * - dispatch() => function to dispatch Redux actions to the store
+ * - getState() => function to get the current state of the entire Inspector Redux store
+ * - inspector => object instance of Inspector client
+ *
+ * They provide a shortcut for React components to invoke the box model highlighter
+ * without having to know where the highlighter exists.
+ */
+
+module.exports = {
+ /**
+ * Show the box model highlighter for the currently selected node front.
+ * The selected node is obtained from the Selection instance on the Inspector.
+ *
+ * @param {Object} options
+ * Optional configuration options passed to the box model highlighter
+ */
+ highlightSelectedNode(options = {}) {
+ return async thunkOptions => {
+ const { inspector } = thunkOptions;
+ if (!inspector || inspector._destroyed) {
+ return;
+ }
+
+ const { nodeFront } = inspector.selection;
+ if (!nodeFront) {
+ return;
+ }
+
+ await inspector.highlighters.showHighlighterTypeForNode(
+ inspector.highlighters.TYPES.BOXMODEL,
+ nodeFront,
+ options
+ );
+ };
+ },
+
+ /**
+ * Show the box model highlighter for the given node front.
+ *
+ * @param {NodeFront} nodeFront
+ * Node that should be highlighted.
+ * @param {Object} options
+ * Optional configuration options passed to the box model highlighter
+ */
+ highlightNode(nodeFront, options = {}) {
+ return async thunkOptions => {
+ const { inspector } = thunkOptions;
+ if (!inspector || inspector._destroyed) {
+ return;
+ }
+
+ await inspector.highlighters.showHighlighterTypeForNode(
+ inspector.highlighters.TYPES.BOXMODEL,
+ nodeFront,
+ options
+ );
+ };
+ },
+
+ /**
+ * Hide the box model highlighter for any highlighted node.
+ */
+ unhighlightNode() {
+ return async thunkOptions => {
+ const { inspector } = thunkOptions;
+ if (!inspector || inspector._destroyed) {
+ return;
+ }
+
+ await inspector.highlighters.hideHighlighterType(
+ inspector.highlighters.TYPES.BOXMODEL
+ );
+ };
+ },
+};
diff --git a/devtools/client/inspector/boxmodel/actions/box-model.js b/devtools/client/inspector/boxmodel/actions/box-model.js
new file mode 100644
index 0000000000..322cf6cb00
--- /dev/null
+++ b/devtools/client/inspector/boxmodel/actions/box-model.js
@@ -0,0 +1,46 @@
+/* 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 {
+ UPDATE_GEOMETRY_EDITOR_ENABLED,
+ UPDATE_LAYOUT,
+ UPDATE_OFFSET_PARENT,
+} = require("resource://devtools/client/inspector/boxmodel/actions/index.js");
+
+module.exports = {
+ /**
+ * Updates the geometry editor's enabled state.
+ *
+ * @param {Boolean} enabled
+ * Whether or not the geometry editor is enabled or not.
+ */
+ updateGeometryEditorEnabled(enabled) {
+ return {
+ type: UPDATE_GEOMETRY_EDITOR_ENABLED,
+ enabled,
+ };
+ },
+
+ /**
+ * Updates the layout state with the new layout properties.
+ */
+ updateLayout(layout) {
+ return {
+ type: UPDATE_LAYOUT,
+ layout,
+ };
+ },
+
+ /**
+ * Updates the offset parent state with the new DOM node.
+ */
+ updateOffsetParent(offsetParent) {
+ return {
+ type: UPDATE_OFFSET_PARENT,
+ offsetParent,
+ };
+ },
+};
diff --git a/devtools/client/inspector/boxmodel/actions/index.js b/devtools/client/inspector/boxmodel/actions/index.js
new file mode 100644
index 0000000000..813b4e9e11
--- /dev/null
+++ b/devtools/client/inspector/boxmodel/actions/index.js
@@ -0,0 +1,21 @@
+/* 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 { createEnum } = require("resource://devtools/client/shared/enum.js");
+
+createEnum(
+ [
+ // Updates the geometry editor's enabled state.
+ "UPDATE_GEOMETRY_EDITOR_ENABLED",
+
+ // Updates the layout state with the latest layout properties.
+ "UPDATE_LAYOUT",
+
+ // Updates the offset parent state with the new DOM node.
+ "UPDATE_OFFSET_PARENT",
+ ],
+ module.exports
+);
diff --git a/devtools/client/inspector/boxmodel/actions/moz.build b/devtools/client/inspector/boxmodel/actions/moz.build
new file mode 100644
index 0000000000..7ee681b35c
--- /dev/null
+++ b/devtools/client/inspector/boxmodel/actions/moz.build
@@ -0,0 +1,11 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+DevToolsModules(
+ "box-model-highlighter.js",
+ "box-model.js",
+ "index.js",
+)