Bug 1106272 - Part 1: Remove the selector highlight on hover and add a selector icon instead. r=miker

--HG--
extra : rebase_source : 57dcc58a96c35d42111f5b3671de2d4e8da78e35
This commit is contained in:
Patrick Brosset 2015-03-24 14:42:27 +01:00
parent e4b121c689
commit 7a37471593
4 changed files with 121 additions and 19 deletions

View File

@ -1206,6 +1206,87 @@ CssRuleView.prototype = {
popupset.appendChild(this._contextmenu);
},
/**
* Get an instance of SelectorHighlighter (used to highlight nodes that match
* selectors in the rule-view). A new instance is only created the first time
* this function is called. The same instance will then be returned.
* @return {Promise} Resolves to the instance of the highlighter.
*/
getSelectorHighlighter: Task.async(function*() {
let utils = this.inspector.toolbox.highlighterUtils;
if (!utils.supportsCustomHighlighters()) {
return null;
}
if (this.selectorHighlighter) {
return this.selectorHighlighter;
}
try {
let h = yield utils.getHighlighterByType("SelectorHighlighter");
return this.selectorHighlighter = h;
} catch (e) {
// The SelectorHighlighter type could not be created in the current target.
// It could be an older server, or a XUL page.
return null;
}
}),
/**
* Highlight/unhighlight all the nodes that match a given set of selectors
* inside the document of the current selected node.
* Only one selector can be highlighted at a time, so calling the method a
* second time with a different selector will first unhighlight the previously
* highlighted nodes.
* Calling the method a second time with the same selector will just
* unhighlight the highlighted nodes.
*
* @param {DOMNode} The icon that was clicked to toggle the selector. The
* class 'highlighted' will be added when the selector is highlighted.
* @param {String} The selector used to find nodes in the page.
*/
toggleSelectorHighlighter: function(selectorIcon, selector) {
if (this.lastSelectorIcon) {
this.lastSelectorIcon.classList.remove("highlighted");
}
selectorIcon.classList.remove("highlighted");
this.unhighlightSelector().then(() => {
if (selector !== this.highlightedSelector) {
this.highlightedSelector = selector;
selectorIcon.classList.add("highlighted");
this.lastSelectorIcon = selectorIcon;
this.highlightSelector(selector).catch(Cu.reportError);
} else {
this.highlightedSelector = null;
}
}, Cu.reportError);
},
highlightSelector: Task.async(function*(selector) {
let node = this.inspector.selection.nodeFront;
let highlighter = yield this.getSelectorHighlighter();
if (!highlighter) {
return;
}
yield highlighter.show(node, {
hideInfoBar: true,
hideGuides: true,
selector
});
}),
unhighlightSelector: Task.async(function*() {
let highlighter = yield this.getSelectorHighlighter();
if (!highlighter) {
return;
}
yield highlighter.hide();
}),
/**
* Update the context menu. This means enabling or disabling menuitems as
* appropriate.
@ -1644,6 +1725,8 @@ CssRuleView.prototype = {
* Clear the rule view.
*/
clear: function() {
this.lastSelectorIcon = null;
this._clearRules();
this._viewedElement = null;
@ -1836,6 +1919,7 @@ function RuleEditor(aRuleView, aRule) {
this.ruleView = aRuleView;
this.doc = this.ruleView.doc;
this.rule = aRule;
this.isEditable = !aRule.isSystem;
// Flag that blocks updates of the selector and properties when it is
// being edited
@ -1903,6 +1987,20 @@ RuleEditor.prototype = {
class: "ruleview-selectorcontainer"
});
if (this.rule.domRule.type !== Ci.nsIDOMCSSRule.KEYFRAME_RULE &&
this.rule.domRule.selectors) {
let selector = this.rule.domRule.selectors.join(", ");
let selectorHighlighter = createChild(header, "span", {
class: "ruleview-selectorhighlighter" +
(this.ruleView.highlightedSelector === selector ? " highlighted": ""),
title: CssLogic.l10n("rule.selectorHighlighter.tooltip")
});
selectorHighlighter.addEventListener("click", () => {
this.ruleView.toggleSelectorHighlighter(selectorHighlighter, selector);
});
}
this.selectorText = createChild(this.selectorContainer, "span", {
class: "ruleview-selector theme-fg-color3"
});

View File

@ -29,14 +29,6 @@ const PREF_IMAGE_TOOLTIP_SIZE = "devtools.inspector.imagePreviewTooltipSize";
const TOOLTIP_IMAGE_TYPE = "image";
const TOOLTIP_FONTFAMILY_TYPE = "font-family";
// Types of existing highlighters
const HIGHLIGHTER_TRANSFORM_TYPE = "CssTransformHighlighter";
const HIGHLIGHTER_SELECTOR_TYPE = "SelectorHighlighter";
const HIGHLIGHTER_TYPES = [
HIGHLIGHTER_TRANSFORM_TYPE,
HIGHLIGHTER_SELECTOR_TYPE
];
// Types of nodes in the rule/computed-view
const VIEW_NODE_SELECTOR_TYPE = exports.VIEW_NODE_SELECTOR_TYPE = 1;
const VIEW_NODE_PROPERTY_TYPE = exports.VIEW_NODE_PROPERTY_TYPE = 2;
@ -121,25 +113,17 @@ HighlightersOverlay.prototype = {
}
// Choose the type of highlighter required for the hovered node
let type, options;
let type;
if (this._isRuleViewTransform(nodeInfo) ||
this._isComputedViewTransform(nodeInfo)) {
type = HIGHLIGHTER_TRANSFORM_TYPE;
} else if (nodeInfo.type === VIEW_NODE_SELECTOR_TYPE) {
type = HIGHLIGHTER_SELECTOR_TYPE;
options = {
selector: nodeInfo.value,
hideInfoBar: true,
showOnly: "border",
region: "border"
};
type = "CssTransformHighlighter";
}
if (type) {
this.highlighterShown = type;
let node = this.view.inspector.selection.nodeFront;
this._getHighlighter(type).then(highlighter => {
highlighter.show(node, options);
highlighter.show(node);
});
}
},

View File

@ -232,3 +232,19 @@
.ruleview-selector-separator, .ruleview-selector-unmatched {
color: #888;
}
.ruleview-selectorhighlighter {
background: url("chrome://browser/skin/devtools/vview-open-inspector.png") no-repeat 0 0;
padding-left: 16px;
margin-left: 5px;
cursor: pointer;
}
.ruleview-selectorhighlighter:hover {
background-position: -32px 0;
}
.ruleview-selectorhighlighter:active,
.ruleview-selectorhighlighter.highlighted {
background-position: -16px 0;
}

View File

@ -68,6 +68,10 @@ rule.warning.title=Invalid property value
# first opened and there's no node selected in the rule view.
rule.empty=No element selected.
# LOCALIZATION NOTE (ruleView.selectorHighlighter.tooltip): Text displayed in a
# tooltip when the mouse is over a selector highlighter icon in the rule view.
rule.selectorHighlighter.tooltip=Highlight all elements matching this selector
# LOCALIZATION NOTE (ruleView.contextmenu.selectAll): Text displayed in the
# rule view context menu.
ruleView.contextmenu.selectAll=Select all