Changeset 95621 in webkit


Ignore:
Timestamp:
Sep 21, 2011 6:33:10 AM (13 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: paint box model colors in Metrics sidebar at all times, do not draw box outlines.
https://bugs.webkit.org/show_bug.cgi?id=68240

Today we paint backgrounds in Metrics box model on hover only - should be painted at all
times for the reference. Outlining boxes is highlight is wrong since outlines are outside
the corresponding box regions. We've seen few reports on that + Firebug does not do borders
for that reason.

Reviewed by Yury Semikhatsky.

  • inspector/DOMNodeHighlighter.cpp:
  • inspector/DOMNodeHighlighter.h:
  • inspector/Inspector.json:
  • inspector/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::setHighlightDataFromConfig):

  • inspector/front-end/Color.js:
  • inspector/front-end/MetricsSidebarPane.js:

(WebInspector.MetricsSidebarPane.prototype._highlightDOMNode):
(WebInspector.MetricsSidebarPane.prototype._updateMetrics):

  • inspector/front-end/inspector.css:

(.metrics .label):

  • inspector/front-end/inspector.js:

(WebInspector.buildHighlightConfig):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r95619 r95621  
     12011-09-21  Pavel Feldman  <pfeldman@google.com>
     2
     3        Web Inspector: paint box model colors in Metrics sidebar at all times, do not draw box outlines.
     4        https://bugs.webkit.org/show_bug.cgi?id=68240
     5
     6        Today we paint backgrounds in Metrics box model on hover only - should be painted at all
     7        times for the reference. Outlining boxes is highlight is wrong since outlines are outside
     8        the corresponding box regions. We've seen few reports on that + Firebug does not do borders
     9        for that reason.
     10
     11        Reviewed by Yury Semikhatsky.
     12
     13        * inspector/DOMNodeHighlighter.cpp:
     14        * inspector/DOMNodeHighlighter.h:
     15        * inspector/Inspector.json:
     16        * inspector/InspectorDOMAgent.cpp:
     17        (WebCore::InspectorDOMAgent::setHighlightDataFromConfig):
     18        * inspector/front-end/Color.js:
     19        * inspector/front-end/MetricsSidebarPane.js:
     20        (WebInspector.MetricsSidebarPane.prototype._highlightDOMNode):
     21        (WebInspector.MetricsSidebarPane.prototype._updateMetrics):
     22        * inspector/front-end/inspector.css:
     23        (.metrics .label):
     24        * inspector/front-end/inspector.js:
     25        (WebInspector.buildHighlightConfig):
     26
    1272011-09-21  Andreas Kling  <kling@webkit.org>
    228
  • trunk/Source/WebCore/inspector/DOMNodeHighlighter.cpp

    r93772 r95621  
    100100}
    101101
    102 void drawOutlinedQuadWithClip(GraphicsContext& context, const FloatQuad& quad, const FloatQuad& clipQuad, const Color& fillColor, const Color& outlineColor)
     102void drawOutlinedQuadWithClip(GraphicsContext& context, const FloatQuad& quad, const FloatQuad& clipQuad, const Color& fillColor)
    103103{
    104104    context.save();
    105105    Path clipQuadPath = quadToPath(clipQuad);
    106106    context.clipOut(clipQuadPath);
    107     drawOutlinedQuad(context, quad, fillColor, outlineColor);
     107    drawOutlinedQuad(context, quad, fillColor, Color::transparent);
    108108    context.restore();
    109109}
     
    111111void drawHighlightForBox(GraphicsContext& context, const FloatQuad& contentQuad, const FloatQuad& paddingQuad, const FloatQuad& borderQuad, const FloatQuad& marginQuad, HighlightData* highlightData)
    112112{
    113     bool hasMargin = highlightData->margin != Color::transparent || highlightData->marginOutline != Color::transparent;
    114     bool hasBorder = highlightData->border != Color::transparent || highlightData->borderOutline != Color::transparent;
    115     bool hasPadding = highlightData->padding != Color::transparent || highlightData->paddingOutline != Color::transparent;
     113    bool hasMargin = highlightData->margin != Color::transparent;
     114    bool hasBorder = highlightData->border != Color::transparent;
     115    bool hasPadding = highlightData->padding != Color::transparent;
    116116    bool hasContent = highlightData->content != Color::transparent || highlightData->contentOutline != Color::transparent;
    117117
     
    119119    Color clipColor;
    120120    if (hasMargin && (!hasBorder || marginQuad != borderQuad)) {
    121         drawOutlinedQuadWithClip(context, marginQuad, borderQuad, highlightData->margin, highlightData->marginOutline);
     121        drawOutlinedQuadWithClip(context, marginQuad, borderQuad, highlightData->margin);
    122122        clipQuad = borderQuad;
    123         clipColor = highlightData->marginOutline;
    124123    }
    125124    if (hasBorder && (!hasPadding || borderQuad != paddingQuad)) {
    126         drawOutlinedQuadWithClip(context, borderQuad, paddingQuad, highlightData->border, highlightData->borderOutline);
     125        drawOutlinedQuadWithClip(context, borderQuad, paddingQuad, highlightData->border);
    127126        clipQuad = paddingQuad;
    128         clipColor = highlightData->borderOutline;
    129127    }
    130128    if (hasPadding && (!hasContent || paddingQuad != contentQuad)) {
    131         drawOutlinedQuadWithClip(context, paddingQuad, contentQuad, highlightData->padding, highlightData->paddingOutline);
     129        drawOutlinedQuadWithClip(context, paddingQuad, contentQuad, highlightData->padding);
    132130        clipQuad = contentQuad;
    133         clipColor = highlightData->paddingOutline;
    134131    }
    135132    if (hasContent)
    136133        drawOutlinedQuad(context, contentQuad, highlightData->content, highlightData->contentOutline);
    137     else {
    138         if (clipColor.isValid())
    139             drawOutlinedQuadWithClip(context, clipQuad, clipQuad, clipColor, clipColor);
    140     }
    141134}
    142135
     
    144137{
    145138    for (size_t i = 0; i < lineBoxQuads.size(); ++i)
    146         drawOutlinedQuad(context, lineBoxQuads[i], highlightData->content, highlightData->contentOutline);
     139        drawOutlinedQuad(context, lineBoxQuads[i], highlightData->content, Color::transparent);
    147140}
    148141
  • trunk/Source/WebCore/inspector/DOMNodeHighlighter.h

    r93603 r95621  
    4747    Color contentOutline;
    4848    Color padding;
    49     Color paddingOutline;
    5049    Color border;
    51     Color borderOutline;
    5250    Color margin;
    53     Color marginOutline;
    5451    bool showInfo;
    5552
  • trunk/Source/WebCore/inspector/Inspector.json

    r95614 r95621  
    891891            },
    892892            {
    893                 "id": "BoxHighlightConfig",
     893                "id": "HighlightConfig",
    894894                "type": "object",
    895895                "properties": [
    896896                    { "name": "showInfo", "type": "boolean", "optional": true, "description": "Whether the node info tooltip should be shown (default: false)." },
    897897                    { "name": "contentColor", "$ref": "RGBA", "optional": true, "description": "The content box highlight fill color (default: transparent)." },
    898                     { "name": "contentOutlineColor", "$ref": "RGBA", "optional": true, "description": "The content box highlight outline color (default: transparent)." },
    899898                    { "name": "paddingColor", "$ref": "RGBA", "optional": true, "description": "The padding highlight fill color (default: transparent)." },
    900                     { "name": "paddingOutlineColor", "$ref": "RGBA", "optional": true, "description": "The padding highlight outline color (default: transparent)." },
    901899                    { "name": "borderColor", "$ref": "RGBA", "optional": true, "description": "The border highlight fill color (default: transparent)." },
    902                     { "name": "borderOutlineColor", "$ref": "RGBA", "optional": true, "description": "The border highlight outline color (default: transparent)." },
    903900                    { "name": "marginColor", "$ref": "RGBA", "optional": true, "description": "The margin highlight fill color (default: transparent)." },
    904                     { "name": "marginOutlineColor", "$ref": "RGBA", "optional": true, "description": "The margin highlight outline color (default: transparent)." }
    905901                ],
    906902                "description": "Configuration data for the highlighting of page elements."
     
    931927                    { "name": "nodeId", "$ref": "NodeId", "description": "Query selector result." }
    932928                ],
    933                 "description": "Executes <code>querySelector</code> on a given node. Setting <code>documentWide</code> to true starts selecting from the document node."
     929                "description": "Executes <code>querySelector</code> on a given node."
    934930            },
    935931            {
     
    942938                    { "name": "nodeIds", "type": "array", "items": { "$ref": "NodeId" }, "description": "Query selector result." }
    943939                ],
    944                 "description": "Executes <code>querySelectorAll</code> on a given node. Setting <code>documentWide</code> to true starts selecting from the document node."
     940                "description": "Executes <code>querySelectorAll</code> on a given node."
    945941            },
    946942            {
     
    10651061                "parameters": [
    10661062                    { "name": "enabled", "type": "boolean", "description": "True to enable inspection mode, false to disable it." },
    1067                     { "name": "highlightConfig", "$ref": "BoxHighlightConfig", "optional": true, "description": "A descriptor for the highlight appearance of hovered-over nodes. May be omitted if <code>enabled == false</code>." }
     1063                    { "name": "highlightConfig", "$ref": "HighlightConfig", "optional": true, "description": "A descriptor for the highlight appearance of hovered-over nodes. May be omitted if <code>enabled == false</code>." }
    10681064                ],
    10691065                "description": "Enters the 'inspect' mode. In this mode, elements that user is hovering over are highlighted. Backend then generates 'inspect' command upon element selection."
     
    10851081                "parameters": [
    10861082                    { "name": "nodeId", "$ref": "NodeId", "description": "Identifier of the node to highlight." },
    1087                     { "name": "highlightConfig", "$ref": "BoxHighlightConfig", "description": "A descriptor for the highlight appearance." }
     1083                    { "name": "highlightConfig", "$ref": "HighlightConfig", "description": "A descriptor for the highlight appearance." }
    10881084                ],
    10891085                "description": "Highlights DOM node with given id."
  • trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp

    r95614 r95621  
    10581058    m_highlightData->contentOutline = parseConfigColor("contentOutlineColor", highlightConfig);
    10591059    m_highlightData->padding = parseConfigColor("paddingColor", highlightConfig);
    1060     m_highlightData->paddingOutline = parseConfigColor("paddingOutlineColor", highlightConfig);
    10611060    m_highlightData->border = parseConfigColor("borderColor", highlightConfig);
    1062     m_highlightData->borderOutline = parseConfigColor("borderOutlineColor", highlightConfig);
    10631061    m_highlightData->margin = parseConfigColor("marginColor", highlightConfig);
    1064     m_highlightData->marginOutline = parseConfigColor("marginOutlineColor", highlightConfig);
    10651062    return true;
    10661063}
  • trunk/Source/WebCore/inspector/front-end/Color.js

    r93603 r95621  
    685685WebInspector.Color.PageHighlight = {
    686686    Content: WebInspector.Color.fromRGBA(111, 168, 220, .66),
     687    ContentLight: WebInspector.Color.fromRGBA(111, 168, 220, .5),
    687688    ContentOutline: WebInspector.Color.fromRGBA(9, 83, 148),
    688689    Padding: WebInspector.Color.fromRGBA(147, 196, 125, .55),
    689     PaddingOutline: WebInspector.Color.fromRGBA(55, 118, 28),
     690    PaddingLight: WebInspector.Color.fromRGBA(147, 196, 125, .4),
    690691    Border: WebInspector.Color.fromRGBA(255, 229, 153, .66),
    691     BorderOutline: WebInspector.Color.fromRGBA(127, 96, 0),
     692    BorderLight: WebInspector.Color.fromRGBA(255, 229, 153, .5),
    692693    Margin: WebInspector.Color.fromRGBA(246, 178, 107, .66),
    693     MarginOutline: WebInspector.Color.fromRGBA(180, 95, 4)
     694    MarginLight: WebInspector.Color.fromRGBA(246, 178, 107, .5)
    694695}
  • trunk/Source/WebCore/inspector/front-end/MetricsSidebarPane.js

    r94754 r95621  
    102102    _highlightDOMNode: function(showHighlight, mode, event)
    103103    {
    104         function enclosingOrSelfWithClassInArray(element, classNames)
    105         {
    106             for (var node = element; node && node !== element.ownerDocument; node = node.parentNode) {
    107                 if (node.nodeType === Node.ELEMENT_NODE) {
    108                     for (var i = 0; i < classNames.length; ++i) {
    109                         if (node.hasStyleClass(classNames[i]))
    110                             return node;
    111                     }
    112                 }
    113             }
    114             return null;
    115         }
    116 
    117         function getBoxRectangleElement(element)
    118         {
    119             if (!element)
    120                 return null;
    121             return enclosingOrSelfWithClassInArray(element, ["metrics", "margin", "border", "padding", "content"]);
    122         }
    123 
    124104        event.stopPropagation();
    125         var fromElement = getBoxRectangleElement(event.fromElement);
    126         var toElement = getBoxRectangleElement(event.toElement);
    127 
    128         if (fromElement === toElement)
    129             return;
    130 
    131         function handleMouseOver(element)
    132         {
    133             element.addStyleClass("hovered");
    134 
    135             var bgColor;
    136             if (element.hasStyleClass("margin"))
    137                 bgColor = WebInspector.Color.PageHighlight.Margin.toString("original");
    138             else if (element.hasStyleClass("border"))
    139                 bgColor = WebInspector.Color.PageHighlight.Border.toString("original");
    140             else if (element.hasStyleClass("padding"))
    141                 bgColor = WebInspector.Color.PageHighlight.Padding.toString("original");
    142             else if (element.hasStyleClass("content"))
    143                 bgColor = WebInspector.Color.PageHighlight.Content.toString("original");
    144             if (bgColor)
    145                 element.style.backgroundColor = bgColor;
    146         }
    147 
    148         function handleMouseOut(element)
    149         {
    150             element.style.backgroundColor = "";
    151             element.removeStyleClass("hovered");
    152         }
    153 
    154         if (showHighlight) {
    155             // Into element.
    156             if (this.node && toElement)
    157                 handleMouseOver(toElement);
    158             var nodeId = this.node ? this.node.id : 0;
    159         } else {
    160             // Out of element.
    161             if (fromElement)
    162                 handleMouseOut(fromElement);
    163             var nodeId = 0;
    164         }
     105        var nodeId = showHighlight && this.node ? this.node.id : 0;
    165106        if (nodeId) {
    166107            if (this._highlightMode === mode)
    167108                return;
    168109            this._highlightMode = mode;
    169         } else
     110            WebInspector.highlightDOMNode(nodeId, mode);
     111        } else {
    170112            delete this._highlightMode;
    171         WebInspector.highlightDOMNode(nodeId, mode);
     113            WebInspector.highlightDOMNode(0, "");
     114        }
     115
     116        for (var i = 0; this._boxElements && i < this._boxElements.length; ++i) {
     117            var element = this._boxElements[i];
     118            if (!nodeId || mode === "all" || element._name === mode)
     119                element.style.backgroundColor = element._backgroundColor;
     120            else
     121                element.style.backgroundColor = "";
     122        }
    172123    },
    173124
     
    249200
    250201        var boxes = ["content", "padding", "border", "margin", "position"];
     202        var boxColors = [
     203            WebInspector.Color.PageHighlight.Content,
     204            WebInspector.Color.PageHighlight.Padding,
     205            WebInspector.Color.PageHighlight.Border,
     206            WebInspector.Color.PageHighlight.Margin,
     207            WebInspector.Color.fromRGBA(0, 0, 0, 0)
     208        ];
    251209        var boxLabels = [WebInspector.UIString("content"), WebInspector.UIString("padding"), WebInspector.UIString("border"), WebInspector.UIString("margin"), WebInspector.UIString("position")];
    252210        var previousBox;
     211        this._boxElements = [];
    253212        for (var i = 0; i < boxes.length; ++i) {
    254213            var name = boxes[i];
     
    263222            var boxElement = document.createElement("div");
    264223            boxElement.className = name;
     224            boxElement._backgroundColor = boxColors[i].toString("original");
     225            boxElement._name = name;
     226            boxElement.style.backgroundColor = boxElement._backgroundColor;
    265227            boxElement.addEventListener("mouseover", this._highlightDOMNode.bind(this, true, name === "position" ? "all" : name), false);
    266             boxElement.addEventListener("mouseout", this._highlightDOMNode.bind(this, false, ""), false);
     228            this._boxElements.push(boxElement);
    267229
    268230            if (name === "content") {
     
    302264
    303265        metricsElement.appendChild(previousBox);
    304         metricsElement.addEventListener("mouseover", this._highlightDOMNode.bind(this, true, ""), false);
    305         metricsElement.addEventListener("mouseout", this._highlightDOMNode.bind(this, false, ""), false);
     266        metricsElement.addEventListener("mouseover", this._highlightDOMNode.bind(this, false, ""), false);
    306267        this.bodyElement.removeChildren();
    307268        this.bodyElement.appendChild(metricsElement);
     
    456417            if (!("originalPropertyData" in self))
    457418                self.originalPropertyData = self.previousPropertyDataCandidate;
    458             if ("_highlightMode" in self) {
     419
     420            if (typeof self._highlightMode !== "undefined") {
    459421                WebInspector.highlightDOMNode(0, "");
    460422                WebInspector.highlightDOMNode(self.node.id, self._highlightMode);
    461423            }
     424
    462425            if (commitEditor) {
    463426                self.dispatchEventToListeners("metrics edited");
  • trunk/Source/WebCore/inspector/front-end/inspector.css

    r95611 r95621  
    18701870.metrics .label {
    18711871    position: absolute;
    1872     margin-top: -10px;
    1873     font-size: 9px;
    1874     color: grey;
    1875     background-color: white;
     1872    font-size: 10px;
     1873    color: black;
    18761874    margin-left: 3px;
    18771875    padding-left: 2px;
    18781876    padding-right: 2px;
    1879 }
    1880 
    1881 .metrics .hovered > .label {
    1882     border: 1px solid black;
    18831877}
    18841878
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r95553 r95621  
    369369        mode = mode || "all";
    370370        var highlightConfig = { showInfo: mode === "all" };
    371         if (mode === "all" || mode === "content") {
     371        if (mode === "all" || mode === "content")
    372372            highlightConfig.contentColor = WebInspector.Color.PageHighlight.Content.toProtocolRGBA();
    373             highlightConfig.contentOutlineColor = WebInspector.Color.PageHighlight.ContentOutline.toProtocolRGBA();
    374         }
    375 
    376         if (mode === "all" || mode === "padding") {
     373
     374        if (mode === "all" || mode === "padding")
    377375            highlightConfig.paddingColor = WebInspector.Color.PageHighlight.Padding.toProtocolRGBA();
    378             highlightConfig.paddingOutlineColor = WebInspector.Color.PageHighlight.PaddingOutline.toProtocolRGBA();
    379         }
    380 
    381         if (mode === "all" || mode === "border") {
     376
     377        if (mode === "all" || mode === "border")
    382378            highlightConfig.borderColor = WebInspector.Color.PageHighlight.Border.toProtocolRGBA();
    383             highlightConfig.borderOutlineColor = WebInspector.Color.PageHighlight.BorderOutline.toProtocolRGBA();
    384         }
    385 
    386         if (mode === "all" || mode === "margin") {
     379
     380        if (mode === "all" || mode === "margin")
    387381            highlightConfig.marginColor = WebInspector.Color.PageHighlight.Margin.toProtocolRGBA();
    388             highlightConfig.marginOutlineColor = WebInspector.Color.PageHighlight.MarginOutline.toProtocolRGBA();
    389         }
    390382
    391383        return highlightConfig;
     
    398390            delete this._hideDOMNodeHighlightTimeout;
    399391        }
    400 
    401         if (this._highlightedDOMNodeId === nodeId)
    402             return;
    403392
    404393        this._highlightedDOMNodeId = nodeId;
Note: See TracChangeset for help on using the changeset viewer.