Changeset 17052 in webkit


Ignore:
Timestamp:
Oct 13, 2006 6:12:32 PM (18 years ago)
Author:
bdakin
Message:

Patch written mostly by Ken Kraisler, but also by me.

Reviewed by Hyatt.

Fix for http://bugs.webkit.org/show_bug.cgi?id=10216 and <rdar://
problem/3391162> PDF created by printing should have live
hyperlinks

  • platform/GraphicsContext.cpp: (WebCore::GraphicsContext::focusRingBoundingRect):
  • platform/GraphicsContext.h:
  • platform/cairo/GraphicsContextCairo.cpp: (WebCore::GraphicsContext::setURLForRect):
  • platform/cg/GraphicsContextCG.cpp: (WebCore::GraphicsContext::setURLForRect): Implement method to add URL link to PDF document.
  • rendering/InlineFlowBox.cpp: (WebCore::InlineFlowBox::paint): Ask hasOutline() instead of querying the outline width
  • rendering/RenderBlock.cpp: (WebCore::RenderBlock::paintObject): Same as above.
  • rendering/RenderFlow.cpp: (WebCore::RenderFlow::paintLines): Call the new paintOutline() (WebCore::RenderFlow::paintOutline): Take care of focus ring and pdf url rects, and outline painting.
  • rendering/RenderFlow.h:
  • rendering/RenderObject.cpp: (WebCore::RenderObject::addPDFURLRect): Declaration to apply a PDF link to a rectanglular region. (WebCore::RenderObject::paintOutline): Take care of pdf rects as well as focus ring painting.
  • rendering/RenderObject.h: (WebCore::RenderObject::hasOutlineAnnotation): Returns true is the element is a link and we are printing. (WebCore::RenderObject::hasOutline): Returns true is the style has an outline and hasOutlineAnnotation() is true.
  • rendering/RenderStyle.h: (WebCore::RenderStyle::hasOutline): Returns true if outlineWidth is greater than 0 and outlineStyle is greater than BHIDDEN.
Location:
trunk/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r17051 r17052  
     12006-10-13  Beth Dakin  <bdakin@apple.com>
     2
     3        Patch written mostly by Ken Kraisler, but also by me.
     4
     5        Reviewed by Hyatt.
     6
     7        Fix for http://bugs.webkit.org/show_bug.cgi?id=10216 and <rdar://
     8        problem/3391162> PDF created by printing should have live
     9        hyperlinks
     10
     11        * platform/GraphicsContext.cpp:
     12        (WebCore::GraphicsContext::focusRingBoundingRect):
     13        * platform/GraphicsContext.h:
     14        * platform/cairo/GraphicsContextCairo.cpp:
     15        (WebCore::GraphicsContext::setURLForRect):
     16        * platform/cg/GraphicsContextCG.cpp:
     17        (WebCore::GraphicsContext::setURLForRect): Implement method to add
     18        URL link to PDF document.
     19        * rendering/InlineFlowBox.cpp:
     20        (WebCore::InlineFlowBox::paint): Ask hasOutline() instead of
     21        querying the outline width
     22        * rendering/RenderBlock.cpp:
     23        (WebCore::RenderBlock::paintObject): Same as above.
     24        * rendering/RenderFlow.cpp:
     25        (WebCore::RenderFlow::paintLines): Call the new paintOutline()
     26        (WebCore::RenderFlow::paintOutline): Take care of focus ring and
     27        pdf url rects, and outline painting.
     28        * rendering/RenderFlow.h:
     29        * rendering/RenderObject.cpp:
     30        (WebCore::RenderObject::addPDFURLRect): Declaration to apply a PDF
     31        link to a rectanglular region.
     32        (WebCore::RenderObject::paintOutline): Take care of pdf rects as
     33        well as focus ring painting.
     34        * rendering/RenderObject.h:
     35        (WebCore::RenderObject::hasOutlineAnnotation): Returns true is the
     36        element is a link and we are printing.
     37        (WebCore::RenderObject::hasOutline): Returns true is the style has
     38        an outline and hasOutlineAnnotation() is true.
     39        * rendering/RenderStyle.h:
     40        (WebCore::RenderStyle::hasOutline): Returns true if outlineWidth is
     41        greater than 0 and outlineStyle is greater than BHIDDEN.
     42
    1432006-10-13  Justin Garcia  <justin.garcia@apple.com>
    244
  • trunk/WebCore/platform/GraphicsContext.cpp

    r16250 r17052  
    217217}
    218218
     219IntRect GraphicsContext::focusRingBoundingRect()
     220{
     221    IntRect result = IntRect(0, 0, 0, 0);
     222   
     223    const Vector<IntRect>& rects = focusRingRects();
     224    unsigned rectCount = rects.size();
     225    for (unsigned i = 0; i < rectCount; i++)
     226        result.unite(rects[i]);
     227       
     228    return result;
     229}
     230
    219231void GraphicsContext::addFocusRingRect(const IntRect& rect)
    220232{
  • trunk/WebCore/platform/GraphicsContext.h

    r17046 r17052  
    6161    class GraphicsContextPrivate;
    6262    class GraphicsContextPlatformPrivate;
     63    class KURL;
    6364    class Path;
    6465    class TextRun;
     
    146147        void drawFocusRing(const Color&);
    147148        void clearFocusRing();
     149        IntRect focusRingBoundingRect();
    148150
    149151        void setLineWidth(float);
     
    162164        void translate(float x, float y);
    163165        IntPoint origin();
     166       
     167        void setURLForRect(const KURL&, const IntRect&);
    164168
    165169        void concatCTM(const AffineTransform&);
  • trunk/WebCore/platform/cairo/GraphicsContextCairo.cpp

    r16826 r17052  
    461461}
    462462
     463void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
     464{
     465}
     466
    463467} // namespace WebCore
    464468
  • trunk/WebCore/platform/cg/GraphicsContextCG.cpp

    r17046 r17052  
    3131
    3232#include "AffineTransform.h"
     33#include "KURL.h"
    3334#include "Path.h"
    3435#include <wtf/MathExtras.h>
     
    778779}
    779780
     781void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
     782{
     783    if (paintingDisabled())
     784        return;
     785       
     786    CFURLRef urlRef = link.createCFURL();
     787    if (urlRef) {
     788        CGContextRef context = platformContext();
     789       
     790        // Get the bounding box to handle clipping.
     791        CGRect box = CGContextGetClipBoundingBox(context);
     792
     793        IntRect intBox((int)box.origin.x, (int)box.origin.y, (int)box.size.width, (int)box.size.height);
     794        IntRect rect = destRect;
     795        rect.intersect(intBox);
     796
     797        CGPDFContextSetURLForRect(context, urlRef,
     798            CGRectApplyAffineTransform(rect, CGContextGetCTM(context)));
     799
     800        CFRelease(urlRef);
     801    }
     802}
     803
    780804}
    781805
  • trunk/WebCore/rendering/InlineFlowBox.cpp

    r16826 r17052  
    551551            // Add ourselves to the paint info struct's list of inlines that need to paint their
    552552            // outlines.
    553             if (object()->style()->visibility() == VISIBLE && object()->style()->outlineWidth() > 0 &&
     553            if (object()->style()->visibility() == VISIBLE && object()->hasOutline() &&
    554554                !object()->isInlineContinuation() && !isRootInlineBox()) {
    555555                i.outlineObjects->add(flowObject());
  • trunk/WebCore/rendering/RenderBlock.cpp

    r16815 r17052  
    13641364    // 5. paint outline.
    13651365    if (!inlineFlow && (paintPhase == PaintPhaseOutline || paintPhase == PaintPhaseSelfOutline)
    1366         && style()->outlineWidth() && style()->visibility() == VISIBLE)
    1367         paintOutline(i.p, _tx, _ty, width(), height(), style());
     1366        && hasOutline() && style()->visibility() == VISIBLE)
     1367        RenderObject::paintOutline(i.p, _tx, _ty, width(), height(), style());
    13681368
    13691369    // 6. paint caret.
  • trunk/WebCore/rendering/RenderFlow.cpp

    r16044 r17052  
    411411        for (RenderFlowSequencedSet::iterator it = info.outlineObjects->begin(); it != end; ++it) {
    412412            RenderFlow* flow = *it;
    413             if (flow->style()->outlineStyleIsAuto())
    414                 flow->paintFocusRing(info.p, _tx, _ty);
    415             else
    416                 flow->paintOutlines(info.p, _tx, _ty);
     413            flow->paintOutline(info.p, _tx, _ty);
    417414        }
    418415        info.outlineObjects->clear();
     
    688685}
    689686
    690 void RenderFlow::paintFocusRing(GraphicsContext* p, int tx, int ty)
    691 {
    692     int ow = style()->outlineWidth();
    693     Color oc = style()->outlineColor();
    694     if (!oc.isValid())
    695         oc = style()->color();
    696    
    697     p->initFocusRing(ow, style()->outlineOffset());
    698     addFocusRingRects(p, tx, ty);
    699     p->drawFocusRing(oc);
    700     p->clearFocusRing();
    701 }
    702 
    703 void RenderFlow::paintOutlines(GraphicsContext* p, int _tx, int _ty)
    704 {
    705     if (style()->outlineStyle() <= BHIDDEN)
     687void RenderFlow::paintOutline(GraphicsContext* p, int _tx, int _ty)
     688{
     689    if (!hasOutline())
    706690        return;
    707691   
     692    if (style()->outlineStyleIsAuto() || hasOutlineAnnotation()) {
     693        int ow = style()->outlineWidth();
     694        Color oc = style()->outlineColor();
     695        if (!oc.isValid())
     696            oc = style()->color();
     697       
     698        p->initFocusRing(ow, style()->outlineOffset());
     699        addFocusRingRects(p, _tx, _ty);
     700        if (style()->outlineStyleIsAuto())
     701            p->drawFocusRing(oc);
     702        else
     703            addPDFURLRect(p, p->focusRingBoundingRect());
     704        p->clearFocusRing();
     705    }
     706
     707    if (style()->outlineStyleIsAuto() || style()->outlineStyle() <= BHIDDEN)
     708        return;
     709
    708710    DeprecatedPtrList <IntRect> rects;
    709711    rects.setAutoDelete(true);
    710    
     712
    711713    rects.append(new IntRect);
    712     for (InlineRunBox* curr = firstLineBox(); curr; curr = curr->nextLineBox()) {
     714    for (InlineRunBox* curr = firstLineBox(); curr; curr = curr->nextLineBox())
    713715        rects.append(new IntRect(curr->xPos(), curr->yPos(), curr->width(), curr->height()));
    714     }
     716
    715717    rects.append(new IntRect);
    716    
     718
    717719    for (unsigned int i = 1; i < rects.count() - 1; i++)
    718720        paintOutlineForLine(p, _tx, _ty, *rects.at(i-1), *rects.at(i), *rects.at(i+1));
  • trunk/WebCore/rendering/RenderFlow.h

    r15696 r17052  
    8888
    8989    virtual void addFocusRingRects(GraphicsContext*, int _tx, int _ty);
    90     void paintFocusRing(GraphicsContext*, int tx, int ty);
    9190    void paintOutlineForLine(GraphicsContext*, int tx, int ty, const IntRect &prevLine, const IntRect &thisLine, const IntRect &nextLine);
    92     void paintOutlines(GraphicsContext*, int tx, int ty);
     91    void paintOutline(GraphicsContext*, int tx, int ty);
    9392
    9493protected:
  • trunk/WebCore/rendering/RenderObject.cpp

    r17018 r17052  
    3434#include "CounterResetNode.h"
    3535#include "Decoder.h"
    36 #include "Document.h"
    3736#include "Element.h"
    3837#include "EventNames.h"
     
    4241#include "HTMLNames.h"
    4342#include "HTMLOListElement.h"
     43#include "KURL.h"
    4444#include "Position.h"
    4545#include "RenderArena.h"
     
    16401640}
    16411641
     1642void RenderObject::addPDFURLRect(GraphicsContext* p, IntRect rect)
     1643{
     1644    Node* node = element();
     1645    if (node) {
     1646        if (p) {
     1647            if (rect.width() > 0 && rect.height() > 0) {
     1648                Element* element = static_cast<Element*>(node);
     1649                String href;
     1650                if (element->isLink())
     1651                    href = element->getAttribute(hrefAttr);
     1652                   
     1653                if (!href.isNull()) {
     1654                    KURL link = element->document()->completeURL(href.deprecatedString());
     1655                    if (link.isValid())
     1656                        p->setURLForRect(link, rect);
     1657                }
     1658            }
     1659        }
     1660    }
     1661}
     1662
     1663
    16421664void RenderObject::addFocusRingRects(GraphicsContext* p, int _tx, int _ty)
    16431665{
     
    16571679void RenderObject::paintOutline(GraphicsContext* p, int _tx, int _ty, int w, int h, const RenderStyle* style)
    16581680{
     1681    if (!hasOutline())
     1682        return;
     1683   
    16591684    int ow = style->outlineWidth();
    1660     if(!ow) return;
    16611685
    16621686    EBorderStyle os = style->outlineStyle();
    1663     if (os <= BHIDDEN)
    1664         return;
    16651687   
    16661688    Color oc = style->outlineColor();
     
    16701692    int offset = style->outlineOffset();
    16711693   
    1672     if (style->outlineStyleIsAuto()) {
     1694    if (style->outlineStyleIsAuto() || hasOutlineAnnotation()) {
    16731695        if (!theme()->supportsFocusRing(style)) {
    16741696            // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
    16751697            p->initFocusRing(ow, offset);
    1676             addFocusRingRects(p, _tx, _ty);
     1698            if (style->outlineStyleIsAuto())
     1699                addFocusRingRects(p, _tx, _ty);
     1700            else
     1701                addPDFURLRect(p, p->focusRingBoundingRect());
    16771702            p->drawFocusRing(oc);
    16781703            p->clearFocusRing();
    16791704        }
     1705    }
     1706
     1707    if (style->outlineStyleIsAuto() || style->outlineStyle() <= BHIDDEN)
    16801708        return;
    1681     }
    16821709
    16831710    _tx -= offset;
  • trunk/WebCore/rendering/RenderObject.h

    r17002 r17052  
    3030#include "CachedResourceClient.h"
    3131#include "DeprecatedValueList.h"
     32#include "Document.h"
    3233#include "RenderStyle.h"
    3334#include "ScrollBar.h"
     
    347348    Node* node() const { return m_node; }
    348349   
     350    bool hasOutlineAnnotation() { return element() && element()->isLink() && document()->printing(); }
     351    bool hasOutline() { return style()->hasOutline() || hasOutlineAnnotation(); }
     352   
    349353   /**
    350354     * returns the object containing this one. can be different from parent for
     
    703707    IntRect paintingRootRect(IntRect& topLevelRect);
    704708
     709    void addPDFURLRect(GraphicsContext* p, IntRect rect);
     710
    705711    virtual void addFocusRingRects(GraphicsContext*, int tx, int ty);
    706712
  • trunk/WebCore/rendering/RenderStyle.h

    r16721 r17052  
    12501250        return background->m_outline.width;
    12511251    }
     1252    bool hasOutline() const { return outlineWidth() > 0 && outlineStyle() > BHIDDEN; }
    12521253    EBorderStyle   outlineStyle() const {  return background->m_outline.style(); }
    12531254    bool outlineStyleIsAuto() const { return background->m_outline._auto; }
Note: See TracChangeset for help on using the changeset viewer.