Changeset 245728 in webkit
- Timestamp:
- May 23, 2019, 5:10:09 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
inspector/InspectorOverlay.cpp (modified) (19 diffs)
-
inspector/InspectorOverlay.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r245727 r245728 1 2019-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 1 27 2019-05-23 Saam barati <sbarati@apple.com> 2 28 -
trunk/Source/WebCore/inspector/InspectorOverlay.cpp
r242713 r245728 199 199 } 200 200 201 static Path quadToPath(const FloatQuad& quad, FloatRect& bounds)201 static Path quadToPath(const FloatQuad& quad, Highlight::Bounds& bounds) 202 202 { 203 203 Path path; … … 213 213 } 214 214 215 static void drawOutlinedQuadWithClip(GraphicsContext& context, const FloatQuad& quad, const FloatQuad& clipQuad, const Color& fillColor, FloatRect& bounds)215 static void drawOutlinedQuadWithClip(GraphicsContext& context, const FloatQuad& quad, const FloatQuad& clipQuad, const Color& fillColor, Highlight::Bounds& bounds) 216 216 { 217 217 GraphicsContextStateSaver stateSaver(context); … … 226 226 } 227 227 228 static void drawOutlinedQuad(GraphicsContext& context, const FloatQuad& quad, const Color& fillColor, const Color& outlineColor, FloatRect& bounds)228 static void drawOutlinedQuad(GraphicsContext& context, const FloatQuad& quad, const Color& fillColor, const Color& outlineColor, Highlight::Bounds& bounds) 229 229 { 230 230 Path path = quadToPath(quad, bounds); … … 243 243 } 244 244 245 static void drawFragmentHighlight(GraphicsContext& context, Node& node, const HighlightConfig& highlightConfig, FloatRect& bounds)245 static void drawFragmentHighlight(GraphicsContext& context, Node& node, const HighlightConfig& highlightConfig, Highlight::Bounds& bounds) 246 246 { 247 247 Highlight highlight; … … 276 276 } 277 277 278 static void drawShapeHighlight(GraphicsContext& context, Node& node, FloatRect& bounds)278 static void drawShapeHighlight(GraphicsContext& context, Node& node, Highlight::Bounds& bounds) 279 279 { 280 280 Element* element = effectiveElementForNode(node); … … 388 388 } 389 389 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 } 392 396 393 397 if (m_highlightNodeList) { 394 398 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 } 397 403 } 398 404 } 399 405 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 } 402 410 403 411 if (!m_paintRects.isEmpty()) … … 405 413 406 414 if (m_showRulers) 407 drawRulers(context );415 drawRulers(context, bounds); 408 416 } 409 417 … … 561 569 } 562 570 563 voidInspectorOverlay::drawNodeHighlight(GraphicsContext& context, Node& node)564 { 565 FloatRectbounds;571 Highlight::Bounds InspectorOverlay::drawNodeHighlight(GraphicsContext& context, Node& node) 572 { 573 Highlight::Bounds bounds; 566 574 567 575 drawFragmentHighlight(context, node, m_nodeHighlightConfig, bounds); … … 576 584 if (m_nodeHighlightConfig.showInfo) 577 585 drawElementTitle(context, node, bounds); 578 } 579 580 void InspectorOverlay::drawQuadHighlight(GraphicsContext& context, const FloatQuad& quad) 581 { 586 587 return bounds; 588 } 589 590 Highlight::Bounds InspectorOverlay::drawQuadHighlight(GraphicsContext& context, const FloatQuad& quad) 591 { 592 Highlight::Bounds bounds; 593 582 594 Highlight highlight; 583 595 buildQuadHighlight(quad, m_quadHighlightConfig, highlight); 584 596 585 597 if (highlight.quads.size() >= 1) { 586 FloatRect bounds;587 588 598 drawOutlinedQuad(context, highlight.quads[0], highlight.contentColor, highlight.contentOutlineColor, bounds); 589 599 … … 591 601 drawBounds(context, bounds); 592 602 } 603 604 return bounds; 593 605 } 594 606 … … 604 616 } 605 617 606 void InspectorOverlay::drawBounds(GraphicsContext& context, const FloatRect& bounds)618 void InspectorOverlay::drawBounds(GraphicsContext& context, const Highlight::Bounds& bounds) 607 619 { 608 620 FrameView* pageView = m_page.mainFrame().view(); … … 654 666 } 655 667 656 void InspectorOverlay::drawRulers(GraphicsContext& context )668 void InspectorOverlay::drawRulers(GraphicsContext& context, const Highlight::Bounds& bounds) 657 669 { 658 670 const Color rulerBackgroundColor(1.0f, 1.0f, 1.0f, 0.6f); … … 694 706 float maxY = minY + height; 695 707 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 696 725 // Draw backgrounds. 697 726 { 698 727 GraphicsContextStateSaver backgroundStateSaver(context); 699 728 700 float offsetX = contentInset.width() + rulerSize;701 float offsetY = contentInset.height() + rulerSize;702 703 729 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() }); 707 742 } 708 743 709 744 // Draw lines. 710 745 { 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 711 753 GraphicsContextStateSaver lineStateSaver(context); 712 754 … … 718 760 GraphicsContextStateSaver horizontalRulerStateSaver(context); 719 761 720 context.translate(contentInset.width() - scrollX + 0.5f, co ntentInset.height()- scrollY);762 context.translate(contentInset.width() - scrollX + 0.5f, cornerY - scrollY); 721 763 722 764 for (float x = multipleBelow(minX, rulerSubStepIncrement); x < maxX; x += rulerSubStepIncrement) { … … 725 767 726 768 Path path; 727 path.moveTo({ zoom(x), scrollY }); 728 769 path.moveTo({ zoom(x), drawTopEdge ? scrollY : scrollY + rulerSize }); 770 771 float lineLength = 0.0f; 729 772 if (std::fmod(x, rulerStepIncrement)) { 773 lineLength = rulerSubStepLength; 730 774 context.setStrokeColor(lightRulerColor); 731 path.addLineTo({ zoom(x), scrollY + rulerSubStepLength });732 775 } else { 776 lineLength = std::fmod(x, rulerStepIncrement * 2) ? rulerSubStepLength : rulerStepLength; 733 777 context.setStrokeColor(darkRulerColor); 734 path.addLineTo({ zoom(x), scrollY + (std::fmod(x, rulerStepIncrement * 2) ? rulerSubStepLength : rulerStepLength) });735 778 } 779 path.addLineTo({ zoom(x), scrollY + (drawTopEdge ? lineLength : rulerSize - lineLength) }); 736 780 737 781 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 }); 738 792 } 739 793 } … … 743 797 GraphicsContextStateSaver veritcalRulerStateSaver(context); 744 798 745 context.translate(co ntentInset.width()- scrollX, contentInset.height() - scrollY + 0.5f);799 context.translate(cornerX - scrollX, contentInset.height() - scrollY + 0.5f); 746 800 747 801 for (float y = multipleBelow(minY, rulerSubStepIncrement); y < maxY; y += rulerSubStepIncrement) { … … 750 804 751 805 Path path; 752 path.moveTo({ scrollX, zoom(y) }); 753 806 path.moveTo({ drawLeftEdge ? scrollX : scrollX + rulerSize, zoom(y) }); 807 808 float lineLength = 0.0f; 754 809 if (std::fmod(y, rulerStepIncrement)) { 810 lineLength = rulerSubStepLength; 755 811 context.setStrokeColor(lightRulerColor); 756 path.addLineTo({ scrollX + rulerSubStepLength, zoom(y) });757 812 } else { 813 lineLength = std::fmod(y, rulerStepIncrement * 2) ? rulerSubStepLength : rulerStepLength; 758 814 context.setStrokeColor(darkRulerColor); 759 path.addLineTo({ scrollX + (std::fmod(y, rulerStepIncrement * 2) ? rulerSubStepLength : rulerStepLength), zoom(y) });760 815 } 816 path.addLineTo({ scrollX + (drawLeftEdge ? lineLength : rulerSize - lineLength), zoom(y) }); 761 817 762 818 context.strokePath(path); 763 819 } 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. 788 822 for (float y = multipleBelow(minY, rulerStepIncrement * 2); y < maxY; y += rulerStepIncrement * 2) { 789 823 if (!y && !scrollY) … … 792 826 GraphicsContextStateSaver horizontalLabelStateSaver(context); 793 827 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 }); 796 830 } 797 831 } … … 799 833 } 800 834 801 void InspectorOverlay::drawElementTitle(GraphicsContext& context, Node& node, const FloatRect& bounds)835 void InspectorOverlay::drawElementTitle(GraphicsContext& context, Node& node, const Highlight::Bounds& bounds) 802 836 { 803 837 if (bounds.isEmpty()) -
trunk/Source/WebCore/inspector/InspectorOverlay.h
r242019 r245728 88 88 Vector<FloatQuad> quads; 89 89 bool usePageCoordinates {true}; 90 91 using Bounds = FloatRect; 90 92 }; 91 93 … … 126 128 bool shouldShowOverlay() const; 127 129 128 voiddrawNodeHighlight(GraphicsContext&, Node&);129 voiddrawQuadHighlight(GraphicsContext&, const FloatQuad&);130 Highlight::Bounds drawNodeHighlight(GraphicsContext&, Node&); 131 Highlight::Bounds drawQuadHighlight(GraphicsContext&, const FloatQuad&); 130 132 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&); 133 135 134 void drawElementTitle(GraphicsContext&, Node&, const FloatRect& bounds);136 void drawElementTitle(GraphicsContext&, Node&, const Highlight::Bounds&); 135 137 136 138 void updatePaintRectsTimerFired();
Note:
See TracChangeset
for help on using the changeset viewer.