⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245728 in webkit


Ignore:
Timestamp:
May 23, 2019, 5:10:09 PM (7 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Overlay: rulers should switch sides if they intersect the highlighted node(s) so they don't obstruct any content
https://bugs.webkit.org/show_bug.cgi?id=198165

Reviewed by Timothy Hatcher.

If the highlighted node is against the top edge of the screen, the top ruler should shift to
the bottom, unless the highlighted node is also against the bottom edge of the screen.

If the highlighted node is against the left edge of the screen, the left ruler should shift
to the right, unless the highlighted node is also against the right edge of the screen.

This way, unless the node is very wide/tall, the rulers won't be drawn on top of anything
being highlighted.

  • inspector/InspectorOverlay.h:
  • inspector/InspectorOverlay.cpp:

(WebCore::InspectorOverlay::paint):
(WebCore::InspectorOverlay::drawNodeHighlight):
(WebCore::InspectorOverlay::drawQuadHighlight):
(WebCore::InspectorOverlay::drawBounds):
(WebCore::InspectorOverlay::drawRulers):
Drive-by: create an alias for the type (FloatRect) used when calculating the bounds of

everything that's highlighted.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r245727 r245728  
     12019-05-23  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Overlay: rulers should switch sides if they intersect the highlighted node(s) so they don't obstruct any content
     4        https://bugs.webkit.org/show_bug.cgi?id=198165
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        If the highlighted node is against the top edge of the screen, the top ruler should shift to
     9        the bottom, unless the highlighted node is also against the bottom edge of the screen.
     10
     11        If the highlighted node is against the left edge of the screen, the left ruler should shift
     12        to the right, unless the highlighted node is also against the right edge of the screen.
     13
     14        This way, unless the node is very wide/tall, the rulers won't be drawn on top of anything
     15        being highlighted.
     16
     17        * inspector/InspectorOverlay.h:
     18        * inspector/InspectorOverlay.cpp:
     19        (WebCore::InspectorOverlay::paint):
     20        (WebCore::InspectorOverlay::drawNodeHighlight):
     21        (WebCore::InspectorOverlay::drawQuadHighlight):
     22        (WebCore::InspectorOverlay::drawBounds):
     23        (WebCore::InspectorOverlay::drawRulers):
     24        Drive-by: create an alias for the type (`FloatRect`) used when calculating the bounds of
     25                  everything that's highlighted.
     26
    1272019-05-23  Saam barati  <sbarati@apple.com>
    228
  • trunk/Source/WebCore/inspector/InspectorOverlay.cpp

    r242713 r245728  
    199199}
    200200
    201 static Path quadToPath(const FloatQuad& quad, FloatRect& bounds)
     201static Path quadToPath(const FloatQuad& quad, Highlight::Bounds& bounds)
    202202{
    203203    Path path;
     
    213213}
    214214
    215 static void drawOutlinedQuadWithClip(GraphicsContext& context, const FloatQuad& quad, const FloatQuad& clipQuad, const Color& fillColor, FloatRect& bounds)
     215static void drawOutlinedQuadWithClip(GraphicsContext& context, const FloatQuad& quad, const FloatQuad& clipQuad, const Color& fillColor, Highlight::Bounds& bounds)
    216216{
    217217    GraphicsContextStateSaver stateSaver(context);
     
    226226}
    227227
    228 static void drawOutlinedQuad(GraphicsContext& context, const FloatQuad& quad, const Color& fillColor, const Color& outlineColor, FloatRect& bounds)
     228static void drawOutlinedQuad(GraphicsContext& context, const FloatQuad& quad, const Color& fillColor, const Color& outlineColor, Highlight::Bounds& bounds)
    229229{
    230230    Path path = quadToPath(quad, bounds);
     
    243243}
    244244
    245 static void drawFragmentHighlight(GraphicsContext& context, Node& node, const HighlightConfig& highlightConfig, FloatRect& bounds)
     245static void drawFragmentHighlight(GraphicsContext& context, Node& node, const HighlightConfig& highlightConfig, Highlight::Bounds& bounds)
    246246{
    247247    Highlight highlight;
     
    276276}
    277277
    278 static void drawShapeHighlight(GraphicsContext& context, Node& node, FloatRect& bounds)
     278static void drawShapeHighlight(GraphicsContext& context, Node& node, Highlight::Bounds& bounds)
    279279{
    280280    Element* element = effectiveElementForNode(node);
     
    388388    }
    389389
    390     if (m_highlightQuad)
    391         drawQuadHighlight(context, *m_highlightQuad);
     390    Highlight::Bounds bounds;
     391
     392    if (m_highlightQuad) {
     393        auto quadBounds = drawQuadHighlight(context, *m_highlightQuad);
     394        bounds.unite(quadBounds);
     395    }
    392396
    393397    if (m_highlightNodeList) {
    394398        for (unsigned i = 0; i < m_highlightNodeList->length(); ++i) {
    395             if (Node* node = m_highlightNodeList->item(i))
    396                 drawNodeHighlight(context, *node);
     399            if (Node* node = m_highlightNodeList->item(i)) {
     400                auto nodeBounds = drawNodeHighlight(context, *node);
     401                bounds.unite(nodeBounds);
     402            }
    397403        }
    398404    }
    399405
    400     if (m_highlightNode)
    401         drawNodeHighlight(context, *m_highlightNode);
     406    if (m_highlightNode) {
     407        auto nodeBounds = drawNodeHighlight(context, *m_highlightNode);
     408        bounds.unite(nodeBounds);
     409    }
    402410
    403411    if (!m_paintRects.isEmpty())
     
    405413
    406414    if (m_showRulers)
    407         drawRulers(context);
     415        drawRulers(context, bounds);
    408416}
    409417
     
    561569}
    562570
    563 void InspectorOverlay::drawNodeHighlight(GraphicsContext& context, Node& node)
    564 {
    565     FloatRect bounds;
     571Highlight::Bounds InspectorOverlay::drawNodeHighlight(GraphicsContext& context, Node& node)
     572{
     573    Highlight::Bounds bounds;
    566574
    567575    drawFragmentHighlight(context, node, m_nodeHighlightConfig, bounds);
     
    576584    if (m_nodeHighlightConfig.showInfo)
    577585        drawElementTitle(context, node, bounds);
    578 }
    579 
    580 void InspectorOverlay::drawQuadHighlight(GraphicsContext& context, const FloatQuad& quad)
    581 {
     586
     587    return bounds;
     588}
     589
     590Highlight::Bounds InspectorOverlay::drawQuadHighlight(GraphicsContext& context, const FloatQuad& quad)
     591{
     592    Highlight::Bounds bounds;
     593
    582594    Highlight highlight;
    583595    buildQuadHighlight(quad, m_quadHighlightConfig, highlight);
    584596
    585597    if (highlight.quads.size() >= 1) {
    586         FloatRect bounds;
    587 
    588598        drawOutlinedQuad(context, highlight.quads[0], highlight.contentColor, highlight.contentOutlineColor, bounds);
    589599
     
    591601            drawBounds(context, bounds);
    592602    }
     603
     604    return bounds;
    593605}
    594606
     
    604616}
    605617
    606 void InspectorOverlay::drawBounds(GraphicsContext& context, const FloatRect& bounds)
     618void InspectorOverlay::drawBounds(GraphicsContext& context, const Highlight::Bounds& bounds)
    607619{
    608620    FrameView* pageView = m_page.mainFrame().view();
     
    654666}
    655667
    656 void InspectorOverlay::drawRulers(GraphicsContext& context)
     668void InspectorOverlay::drawRulers(GraphicsContext& context, const Highlight::Bounds& bounds)
    657669{
    658670    const Color rulerBackgroundColor(1.0f, 1.0f, 1.0f, 0.6f);
     
    694706    float maxY = minY + height;
    695707
     708    bool drawTopEdge = true;
     709    bool drawLeftEdge = true;
     710
     711    // Determine which side (top/bottom and left/right) to draw the rulers.
     712    {
     713        FloatRect topEdge(contentInset.width(), contentInset.height(), zoom(width) - contentInset.width(), rulerSize);
     714        FloatRect bottomEdge(contentInset.width(), zoom(height) - rulerSize, zoom(width) - contentInset.width(), rulerSize);
     715        drawTopEdge = !bounds.intersects(topEdge) || bounds.intersects(bottomEdge);
     716
     717        FloatRect rightEdge(zoom(width) - rulerSize, contentInset.height(), rulerSize, zoom(height) - contentInset.height());
     718        FloatRect leftEdge(contentInset.width(), contentInset.height(), rulerSize, zoom(height) - contentInset.height());
     719        drawLeftEdge = !bounds.intersects(leftEdge) || bounds.intersects(rightEdge);
     720    }
     721
     722    float cornerX = drawLeftEdge ? contentInset.width() : zoom(width) - rulerSize;
     723    float cornerY = drawTopEdge ? contentInset.height() : zoom(height) - rulerSize;
     724
    696725    // Draw backgrounds.
    697726    {
    698727        GraphicsContextStateSaver backgroundStateSaver(context);
    699728
    700         float offsetX = contentInset.width() + rulerSize;
    701         float offsetY = contentInset.height() + rulerSize;
    702 
    703729        context.setFillColor(rulerBackgroundColor);
    704         context.fillRect({ contentInset.width(), contentInset.height(), rulerSize, rulerSize });
    705         context.fillRect({ offsetX, contentInset.height(), zoom(width) - offsetX, rulerSize });
    706         context.fillRect({ contentInset.width(), offsetY, rulerSize, zoom(height) - offsetY });
     730
     731        context.fillRect({ cornerX, cornerY, rulerSize, rulerSize });
     732
     733        if (drawLeftEdge)
     734            context.fillRect({ cornerX + rulerSize, cornerY, zoom(width) - cornerX - rulerSize, rulerSize });
     735        else
     736            context.fillRect({ contentInset.width(), cornerY, cornerX - contentInset.width(), rulerSize });
     737
     738        if (drawTopEdge)
     739            context.fillRect({ cornerX, cornerY + rulerSize, rulerSize, zoom(height) - cornerY - rulerSize }); 
     740        else
     741            context.fillRect({ cornerX, contentInset.height(), rulerSize, cornerY - contentInset.height() });
    707742    }
    708743
    709744    // Draw lines.
    710745    {
     746        FontCascadeDescription fontDescription;
     747        fontDescription.setOneFamily(m_page.settings().sansSerifFontFamily());
     748        fontDescription.setComputedSize(10);
     749
     750        FontCascade font(WTFMove(fontDescription), 0, 0);
     751        font.update(nullptr);
     752
    711753        GraphicsContextStateSaver lineStateSaver(context);
    712754
     
    718760            GraphicsContextStateSaver horizontalRulerStateSaver(context);
    719761
    720             context.translate(contentInset.width() - scrollX + 0.5f, contentInset.height() - scrollY);
     762            context.translate(contentInset.width() - scrollX + 0.5f, cornerY - scrollY);
    721763
    722764            for (float x = multipleBelow(minX, rulerSubStepIncrement); x < maxX; x += rulerSubStepIncrement) {
     
    725767
    726768                Path path;
    727                 path.moveTo({ zoom(x), scrollY });
    728 
     769                path.moveTo({ zoom(x), drawTopEdge ? scrollY : scrollY + rulerSize });
     770
     771                float lineLength = 0.0f;
    729772                if (std::fmod(x, rulerStepIncrement)) {
     773                    lineLength = rulerSubStepLength;
    730774                    context.setStrokeColor(lightRulerColor);
    731                     path.addLineTo({ zoom(x), scrollY + rulerSubStepLength });
    732775                } else {
     776                    lineLength = std::fmod(x, rulerStepIncrement * 2) ? rulerSubStepLength : rulerStepLength;
    733777                    context.setStrokeColor(darkRulerColor);
    734                     path.addLineTo({ zoom(x), scrollY + (std::fmod(x, rulerStepIncrement * 2) ? rulerSubStepLength : rulerStepLength) });
    735778                }
     779                path.addLineTo({ zoom(x), scrollY + (drawTopEdge ? lineLength : rulerSize - lineLength) });
    736780
    737781                context.strokePath(path);
     782            }
     783
     784            // Draw labels.
     785            for (float x = multipleBelow(minX, rulerStepIncrement * 2); x < maxX; x += rulerStepIncrement * 2) {
     786                if (!x && !scrollX)
     787                    continue;
     788
     789                GraphicsContextStateSaver verticalLabelStateSaver(context);
     790                context.translate(zoom(x) + 0.5f, scrollY);
     791                context.drawText(font, TextRun(String::numberToStringFixedPrecision(x)), { 2, drawTopEdge ? rulerLabelSize : rulerLabelSize - rulerSize + font.fontMetrics().height() - 1.0f });
    738792            }
    739793        }
     
    743797            GraphicsContextStateSaver veritcalRulerStateSaver(context);
    744798
    745             context.translate(contentInset.width() - scrollX, contentInset.height() - scrollY + 0.5f);
     799            context.translate(cornerX - scrollX, contentInset.height() - scrollY + 0.5f);
    746800
    747801            for (float y = multipleBelow(minY, rulerSubStepIncrement); y < maxY; y += rulerSubStepIncrement) {
     
    750804
    751805                Path path;
    752                 path.moveTo({ scrollX, zoom(y) });
    753 
     806                path.moveTo({ drawLeftEdge ? scrollX : scrollX + rulerSize, zoom(y) });
     807
     808                float lineLength = 0.0f;
    754809                if (std::fmod(y, rulerStepIncrement)) {
     810                    lineLength = rulerSubStepLength;
    755811                    context.setStrokeColor(lightRulerColor);
    756                     path.addLineTo({ scrollX + rulerSubStepLength, zoom(y) });
    757812                } else {
     813                    lineLength = std::fmod(y, rulerStepIncrement * 2) ? rulerSubStepLength : rulerStepLength;
    758814                    context.setStrokeColor(darkRulerColor);
    759                     path.addLineTo({ scrollX + (std::fmod(y, rulerStepIncrement * 2) ? rulerSubStepLength : rulerStepLength), zoom(y) });
    760815                }
     816                path.addLineTo({ scrollX + (drawLeftEdge ? lineLength : rulerSize - lineLength), zoom(y) });
    761817
    762818                context.strokePath(path);
    763819            }
    764         }
    765 
    766         // Draw labels.
    767         {
    768             GraphicsContextStateSaver labelStateSaver(context);
    769 
    770             FontCascadeDescription fontDescription;
    771             fontDescription.setOneFamily(m_page.settings().sansSerifFontFamily());
    772             fontDescription.setComputedSize(10);
    773 
    774             FontCascade font(WTFMove(fontDescription), 0, 0);
    775             font.update(nullptr);
    776 
    777             context.translate(contentInset.width() - scrollX, contentInset.height() - scrollY);
    778 
    779             for (float x = multipleBelow(minX, rulerStepIncrement * 2); x < maxX; x += rulerStepIncrement * 2) {
    780                 if (!x && !scrollX)
    781                     continue;
    782 
    783                 GraphicsContextStateSaver verticalLabelStateSaver(context);
    784                 context.translate(zoom(x) + 0.5f, scrollY);
    785                 context.drawText(font, TextRun(String::numberToStringFixedPrecision(x)), { 2, rulerLabelSize });
    786             }
    787 
     820
     821            // Draw labels.
    788822            for (float y = multipleBelow(minY, rulerStepIncrement * 2); y < maxY; y += rulerStepIncrement * 2) {
    789823                if (!y && !scrollY)
     
    792826                GraphicsContextStateSaver horizontalLabelStateSaver(context);
    793827                context.translate(scrollX, zoom(y) + 0.5f);
    794                 context.rotate(-piOverTwoFloat);
    795                 context.drawText(font, TextRun(String::numberToStringFixedPrecision(y)), { 2, rulerLabelSize });
     828                context.rotate(drawLeftEdge ? -piOverTwoFloat : piOverTwoFloat);
     829                context.drawText(font, TextRun(String::numberToStringFixedPrecision(y)), { 2, drawLeftEdge ? rulerLabelSize : rulerLabelSize - rulerSize });
    796830            }
    797831        }
     
    799833}
    800834
    801 void InspectorOverlay::drawElementTitle(GraphicsContext& context, Node& node, const FloatRect& bounds)
     835void InspectorOverlay::drawElementTitle(GraphicsContext& context, Node& node, const Highlight::Bounds& bounds)
    802836{
    803837    if (bounds.isEmpty())
  • trunk/Source/WebCore/inspector/InspectorOverlay.h

    r242019 r245728  
    8888    Vector<FloatQuad> quads;
    8989    bool usePageCoordinates {true};
     90
     91    using Bounds = FloatRect;
    9092};
    9193
     
    126128    bool shouldShowOverlay() const;
    127129
    128     void drawNodeHighlight(GraphicsContext&, Node&);
    129     void drawQuadHighlight(GraphicsContext&, const FloatQuad&);
     130    Highlight::Bounds drawNodeHighlight(GraphicsContext&, Node&);
     131    Highlight::Bounds drawQuadHighlight(GraphicsContext&, const FloatQuad&);
    130132    void drawPaintRects(GraphicsContext&, const Deque<TimeRectPair>&);
    131     void drawBounds(GraphicsContext&, const FloatRect&);
    132     void drawRulers(GraphicsContext&);
     133    void drawBounds(GraphicsContext&, const Highlight::Bounds&);
     134    void drawRulers(GraphicsContext&, const Highlight::Bounds&);
    133135
    134     void drawElementTitle(GraphicsContext&, Node&, const FloatRect& bounds);
     136    void drawElementTitle(GraphicsContext&, Node&, const Highlight::Bounds&);
    135137
    136138    void updatePaintRectsTimerFired();
Note: See TracChangeset for help on using the changeset viewer.