Clean up the difference between painting focus rings and adding PDF annotations
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 May 2014 02:58:39 +0000 (02:58 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 May 2014 02:58:39 +0000 (02:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=132638

Reviewed by Simon Fraser.

The code to add a PDF annotation when printing was called from
drawFocusRing, which is quite confusing. With just little movement
of code, we can detect an annotation and call addPDFURLRect in the
paint phase, and drawFocusRing becomes something that only
draws focus rings.

* rendering/RenderInline.cpp:
(WebCore::RenderInline::paintOutline): Split calls to drawFocusRing
and addPDFURLRect.
* rendering/RenderObject.cpp:
(WebCore::RenderObject::paintFocusRing): Get rid of call to PDF.
(WebCore::RenderObject::addPDFURLRect): Change the signature so it
can be called externally, and calculates the rectangle itself.
(WebCore::RenderObject::paintOutline): Split the calls.
* rendering/RenderObject.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168404 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderInline.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h

index 3e725cf..e1530fd 100644 (file)
@@ -1,3 +1,26 @@
+2014-05-06  Dean Jackson  <dino@apple.com>
+
+        Clean up the difference between painting focus rings and adding PDF annotations
+        https://bugs.webkit.org/show_bug.cgi?id=132638
+
+        Reviewed by Simon Fraser.
+
+        The code to add a PDF annotation when printing was called from
+        drawFocusRing, which is quite confusing. With just little movement
+        of code, we can detect an annotation and call addPDFURLRect in the
+        paint phase, and drawFocusRing becomes something that only
+        draws focus rings.
+
+        * rendering/RenderInline.cpp:
+        (WebCore::RenderInline::paintOutline): Split calls to drawFocusRing
+        and addPDFURLRect.
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::paintFocusRing): Get rid of call to PDF.
+        (WebCore::RenderObject::addPDFURLRect): Change the signature so it
+        can be called externally, and calculates the rectangle itself.
+        (WebCore::RenderObject::paintOutline): Split the calls.
+        * rendering/RenderObject.h:
+
 2014-05-06  Rik Cabanier  <cabanier@adobe.com>
 
         Calling createPattern with a broken image must throw an invalidstate error
index 7644d58..0867fd1 100644 (file)
@@ -1492,12 +1492,11 @@ void RenderInline::paintOutline(PaintInfo& paintInfo, const LayoutPoint& paintOf
         return;
     
     RenderStyle& styleToUse = style();
-    if (styleToUse.outlineStyleIsAuto() || hasOutlineAnnotation()) {
-        if (!theme().supportsFocusRing(&styleToUse)) {
-            // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
-            paintFocusRing(paintInfo, paintOffset, &styleToUse);
-        }
-    }
+    // Only paint the focus ring by hand if the theme isn't able to draw it.
+    if (styleToUse.outlineStyleIsAuto() && !theme().supportsFocusRing(&styleToUse))
+        paintFocusRing(paintInfo, paintOffset, &styleToUse);
+    else if (hasOutlineAnnotation() && !theme().supportsFocusRing(&styleToUse))
+        addPDFURLRect(paintInfo, paintOffset);
 
     GraphicsContext* graphicsContext = paintInfo.context;
     if (graphicsContext->paintingDisabled())
index d8e34fb..7e6b5fe 100644 (file)
@@ -999,9 +999,9 @@ void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, float x1
 
 void RenderObject::paintFocusRing(PaintInfo& paintInfo, const LayoutPoint& paintOffset, RenderStyle* style)
 {
-    Vector<IntRect> focusRingRects;
-    addFocusRingRects(focusRingRects, paintOffset, paintInfo.paintContainer);
     if (style->outlineStyleIsAuto()) {
+        Vector<IntRect> focusRingRects;
+        addFocusRingRects(focusRingRects, paintOffset, paintInfo.paintContainer);
 #if PLATFORM(MAC)
         bool needsRepaint;
         paintInfo.context->drawFocusRing(focusRingRects, style->outlineWidth(), style->outlineOffset(), document().page()->focusController().timeSinceFocusWasSet(), needsRepaint);
@@ -1010,12 +1010,15 @@ void RenderObject::paintFocusRing(PaintInfo& paintInfo, const LayoutPoint& paint
 #else
         paintInfo.context->drawFocusRing(focusRingRects, style->outlineWidth(), style->outlineOffset(), style->visitedDependentColor(CSSPropertyOutlineColor));
 #endif
-    } else
-        addPDFURLRect(paintInfo.context, unionRect(focusRingRects));
+    }
 }
 
-void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rect)
+void RenderObject::addPDFURLRect(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
 {
+    Vector<IntRect> focusRingRects;
+    addFocusRingRects(focusRingRects, paintOffset, paintInfo.paintContainer);
+    IntRect rect = unionRect(focusRingRects);
+
     if (rect.isEmpty())
         return;
     Node* n = node();
@@ -1024,7 +1027,7 @@ void RenderObject::addPDFURLRect(GraphicsContext* context, const LayoutRect& rec
     const AtomicString& href = toElement(n)->getAttribute(hrefAttr);
     if (href.isNull())
         return;
-    context->setURLForRect(n->document().completeURL(href), pixelSnappedIntRect(rect));
+    paintInfo.context->setURLForRect(n->document().completeURL(href), pixelSnappedIntRect(rect));
 }
 
 void RenderObject::paintOutline(PaintInfo& paintInfo, const LayoutRect& paintRect)
@@ -1037,12 +1040,11 @@ void RenderObject::paintOutline(PaintInfo& paintInfo, const LayoutRect& paintRec
 
     int outlineOffset = styleToUse.outlineOffset();
 
-    if (styleToUse.outlineStyleIsAuto() || hasOutlineAnnotation()) {
-        if (!theme().supportsFocusRing(&styleToUse)) {
-            // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
-            paintFocusRing(paintInfo, paintRect.location(), &styleToUse);
-        }
-    }
+    // Only paint the focus ring by hand if the theme isn't able to draw it.
+    if (styleToUse.outlineStyleIsAuto() && !theme().supportsFocusRing(&styleToUse))
+        paintFocusRing(paintInfo, paintRect.location(), &styleToUse);
+    else if (hasOutlineAnnotation() && !theme().supportsFocusRing(&styleToUse))
+        addPDFURLRect(paintInfo, paintRect.location());
 
     if (styleToUse.outlineStyleIsAuto() || styleToUse.outlineStyle() == BNONE)
         return;
index bc7a1a1..0112c4f 100644 (file)
@@ -871,7 +871,7 @@ public:
 protected:
     void paintFocusRing(PaintInfo&, const LayoutPoint&, RenderStyle*);
     void paintOutline(PaintInfo&, const LayoutRect&);
-    void addPDFURLRect(GraphicsContext*, const LayoutRect&);
+    void addPDFURLRect(PaintInfo&, const LayoutPoint&);
     Node& nodeForNonAnonymous() const { ASSERT(!isAnonymous()); return m_node; }
 
     void adjustRectForOutlineAndShadow(LayoutRect&) const;