/* 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 is the overall component for the toolbox toolbar. It is designed to not know how * the state is being managed, and attempts to be as pure as possible. The * ToolboxController component controls the changing state, and passes in everything as * props.
*/ class ToolboxToolbar extends Component { static get propTypes() { return { // The currently focused item (for arrow keyboard navigation) // This ID determines the tabindex being 0 or -1.
focusedButton: PropTypes.string, // List of command button definitions.
toolboxButtons: PropTypes.array, // The id of the currently selected tool, e.g. "inspector"
currentToolId: PropTypes.string, // An optionally highlighted tools, e.g. "inspector" (used by ToolboxTabs // component).
highlightedTools: PropTypes.instanceOf(Set), // List of tool panel definitions (used by ToolboxTabs component).
panelDefinitions: PropTypes.array, // List of possible docking options.
hostTypes: PropTypes.arrayOf(
PropTypes.shape({
position: PropTypes.string.isRequired,
switchHost: PropTypes.func.isRequired,
})
), // Current docking type. Typically one of the position values in // |hostTypes| but this is not always the case (e.g. for "browsertoolbox").
currentHostType: PropTypes.string, // Are docking options enabled? They are not enabled in certain situations // like when the toolbox is opened in a tab.
areDockOptionsEnabled: PropTypes.bool, // Do we need to add UI for closing the toolbox? We don't when the // toolbox is undocked, for example.
canCloseToolbox: PropTypes.bool, // Is the split console currently visible?
isSplitConsoleActive: PropTypes.bool, // Are we disabling the behavior where pop-ups are automatically closed // when clicking outside them? // // This is a tri-state value that may be true/false or undefined where // undefined means that the option is not relevant in this context // (i.e. we're not in a browser toolbox).
disableAutohide: PropTypes.bool, // Are we displaying the window always on top? // // This is a tri-state value that may be true/false or undefined where // undefined means that the option is not relevant in this context // (i.e. we're not in a local web extension toolbox).
alwaysOnTop: PropTypes.bool, // Is the toolbox currently focused? // // This will only be defined when alwaysOnTop is true.
focusedState: PropTypes.bool, // Function to turn the options panel on / off.
toggleOptions: PropTypes.func.isRequired, // Function to turn the split console on / off.
toggleSplitConsole: PropTypes.func, // Function to turn the disable pop-up autohide behavior on / off.
toggleNoAutohide: PropTypes.func, // Function to turn the always on top behavior on / off.
toggleAlwaysOnTop: PropTypes.func, // Function to completely close the toolbox.
closeToolbox: PropTypes.func, // Keep a record of what button is focused.
focusButton: PropTypes.func, // Hold off displaying the toolbar until enough information is ready for // it to render nicely.
canRender: PropTypes.bool, // Localization interface.
L10N: PropTypes.object.isRequired, // The devtools toolbox
toolbox: PropTypes.object, // Call back function to detect tabs order updated.
onTabsOrderUpdated: PropTypes.func.isRequired, // Count of visible toolbox buttons which is used by ToolboxTabs component // to recognize that the visibility of toolbox buttons were changed. // Because in the component we cannot compare the visibility since the // button definition instance in toolboxButtons will be unchanged.
visibleToolboxButtonCount: PropTypes.number, // Data to show debug target info, if needed
debugTargetData: PropTypes.shape({
runtimeInfo: PropTypes.object.isRequired,
descriptorType: PropTypes.string.isRequired,
}), // The loaded Fluent localization bundles.
fluentBundles: PropTypes.array.isRequired,
};
}
hideMenu() { if (this.refs.meatballMenuButton) { this.refs.meatballMenuButton.hideMenu();
}
if (this.refs.frameMenuButton) { this.refs.frameMenuButton.hideMenu();
}
}
/** * A little helper function to call renderToolboxButtons for buttons at the start * of the toolbox.
*/
renderToolboxButtonsStart() { returnthis.renderToolboxButtons(true);
}
/** * A little helper function to call renderToolboxButtons for buttons at the end * of the toolbox.
*/
renderToolboxButtonsEnd() { returnthis.renderToolboxButtons(false);
}
/** * Render all of the tabs, this takes in a list of toolbox button states. These are plain * objects that have all of the relevant information needed to render the button. * See Toolbox.prototype._createButtonState in devtools/client/framework/toolbox.js for * documentation on this object. * * @param {String} focusedButton - The id of the focused button. * @param {Array} toolboxButtons - Array of objects that define the command buttons. * @param {Function} focusButton - Keep a record of the currently focused button. * @param {boolean} isStart - Render either the starting buttons, or ending buttons.
*/
renderToolboxButtons(isStart) { const { focusedButton, toolboxButtons, focusButton } = this.props; const visibleButtons = toolboxButtons.filter(command => { const { isVisible, isInStartContainer } = command; return isVisible && (isStart ? isInStartContainer : !isInStartContainer);
});
if (visibleButtons.length === 0) { returnnull;
}
// The RDM button, if present, should always go last const rdmIndex = visibleButtons.findIndex(
button => button.id === "command-button-responsive"
); if (rdmIndex !== -1 && rdmIndex !== visibleButtons.length - 1) { const rdm = visibleButtons.splice(rdmIndex, 1)[0];
visibleButtons.push(rdm);
}
// If button is frame button, create menu button in order to // use the doorhanger menu. if (id === "command-button-frames") { returnthis.renderFrameButton(command);
}
if (id === "command-button-errorcount") { returnthis.renderErrorIcon(command);
}
// Add the appropriate separator, if needed. const children = renderedButtons; if (renderedButtons.length) { if (isStart) {
children.push(this.renderSeparator()); // For the end group we add a separator *before* the RDM button if it // exists, but only if it is not the only button.
} elseif (rdmIndex !== -1 && renderedButtons.length > 1) {
children.splice(children.length - 1, 0, this.renderSeparator());
}
}
/** * Render the toolbox control buttons. The following props are expected: * * @param {string} props.focusedButton * The id of the focused button. * @param {string} props.currentToolId * The id of the currently selected tool, e.g. "inspector". * @param {Object[]} props.hostTypes * Array of host type objects. * @param {string} props.hostTypes[].position * Position name. * @param {Function} props.hostTypes[].switchHost * Function to switch the host. * @param {string} props.currentHostType * The current docking configuration. * @param {boolean} props.areDockOptionsEnabled * They are not enabled in certain situations like when the toolbox is * in a tab. * @param {boolean} props.canCloseToolbox * Do we need to add UI for closing the toolbox? We don't when the * toolbox is undocked, for example. * @param {boolean} props.isSplitConsoleActive * Is the split console currently visible? * toolbox is undocked, for example. * @param {boolean|undefined} props.disableAutohide * Are we disabling the behavior where pop-ups are automatically * closed when clicking outside them? * (Only defined for the browser toolbox.) * @param {Function} props.selectTool * Function to select a tool based on its id. * @param {Function} props.toggleOptions * Function to turn the options panel on / off. * @param {Function} props.toggleSplitConsole * Function to turn the split console on / off. * @param {Function} props.toggleNoAutohide * Function to turn the disable pop-up autohide behavior on / off. * @param {Function} props.toggleAlwaysOnTop * Function to turn the always on top behavior on / off. * @param {Function} props.closeToolbox * Completely close the toolbox. * @param {Function} props.focusButton * Keep a record of the currently focused button. * @param {Object} props.L10N * Localization interface. * @param {Object} props.toolbox * The devtools toolbox. Used by the MenuButton component to display * the menu popup. * @param {Object} refs * The components refs object. Used to keep a reference to the MenuButton * for the meatball menu so that we can tell it to resize its contents * when they change.
*/
renderToolboxControls() { const {
focusedButton,
canCloseToolbox,
closeToolbox,
focusButton,
L10N,
toolbox,
} = this.props;
/** * The render function is kept fairly short for maintainability. See the individual * render functions for how each of the sections is rendered.
*/
render() { const { L10N, debugTargetData, toolbox, fluentBundles } = this.props; const classnames = ["devtools-tabbar"]; const startButtons = this.renderToolboxButtonsStart(); const endButtons = this.renderToolboxButtonsEnd();
if (!startButtons) {
classnames.push("devtools-tabbar-has-start");
} if (!endButtons) {
classnames.push("devtools-tabbar-has-end");
}
// Display the toolbar in the MBT and about:debugging MBT if we have server support for it. const chromeDebugToolbar = toolbox.commands.targetCommand.descriptorFront
.isBrowserProcessDescriptor
? ChromeDebugToolbar()
: null;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.