Changeset 58160 in webkit


Ignore:
Timestamp:
Apr 23, 2010 2:31:53 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-04-23 Jeff Schiller <codedread@gmail.com>

Reviewed by Nikolas Zimmermann.

Display tooltips when hovering over SVG elements, Bug 16854
https://bugs.webkit.org/show_bug.cgi?id=16854

Manual test added for verifying tooltips.

  • manual-tests/svg-tooltip.svg: Added.
  • svg/SVGAElement.cpp: (WebCore::SVGAElement::title): xlink:title takes precedence, otherwise SVGStyledElement::title() is used
  • svg/SVGStyledElement.cpp: (WebCore::SVGStyledElement::title): checks for a shadow parent and uses that title, otherwise uses the content's title
  • svg/SVGStyledElement.h: add title() method declaration
Location:
trunk/WebCore
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r58158 r58160  
     12010-04-23  Jeff Schiller  <codedread@gmail.com>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Display tooltips when hovering over SVG elements, Bug 16854
     6        https://bugs.webkit.org/show_bug.cgi?id=16854
     7
     8        Manual test added for verifying tooltips.
     9
     10        * manual-tests/svg-tooltip.svg: Added.
     11        * svg/SVGAElement.cpp:
     12        (WebCore::SVGAElement::title): xlink:title takes precedence, otherwise SVGStyledElement::title() is used
     13        * svg/SVGStyledElement.cpp:
     14        (WebCore::SVGStyledElement::title): checks for a shadow parent and uses that title, otherwise uses the content's title
     15        * svg/SVGStyledElement.h: add title() method declaration
     16
    1172010-04-23  David Kilzer  <ddkilzer@apple.com>
    218
  • trunk/WebCore/svg/SVGAElement.cpp

    r53879 r58160  
    6161String SVGAElement::title() const
    6262{
    63     return getAttribute(XLinkNames::titleAttr);
     63    // If the xlink:title is set (non-empty string), use it.
     64    const AtomicString& title = getAttribute(XLinkNames::titleAttr);
     65    if (!title.isEmpty())
     66        return title;
     67
     68    // Otherwise, use the title of this element.
     69    return SVGStyledElement::title();
    6470}
    6571
  • trunk/WebCore/svg/SVGStyledElement.cpp

    r57886 r58160  
    4444#include "SVGResource.h"
    4545#include "SVGSVGElement.h"
     46#include "SVGUseElement.h"
    4647#include <wtf/Assertions.h>
    4748
     
    6566{
    6667    SVGResource::removeClient(this);
     68}
     69
     70String SVGStyledElement::title() const
     71{
     72    // According to spec, we should not return titles when hovering over <svg> elements (those
     73    // <title> elements are the title of the document, not a tooltip) so we instantly return.
     74    if (hasTagName(SVGNames::svgTag))
     75        return String();
     76   
     77    // Walk up the tree, to find out whether we're inside a <use> shadow tree, to find the right title.
     78    Node* parent = const_cast<SVGStyledElement*>(this);
     79    while (parent) {
     80        if (!parent->isShadowNode()) {
     81            parent = parent->parentNode();
     82            continue;
     83        }
     84       
     85        // Get the <use> element.
     86        Node* shadowParent = parent->shadowParentNode();
     87        if (shadowParent && shadowParent->isSVGElement() && shadowParent->hasTagName(SVGNames::useTag)) {
     88            SVGUseElement* useElement = static_cast<SVGUseElement*>(shadowParent);
     89            // If the <use> title is not empty we found the title to use.
     90            String useTitle(useElement->title());
     91            if (useTitle.isEmpty())
     92                break;
     93            return useTitle;
     94        }
     95        parent = parent->parentNode();
     96    }
     97   
     98    // If we aren't an instance in a <use> or the <use> title was not found, then find the first
     99    // <title> child of this element.
     100    Element* titleElement = firstElementChild();
     101    for (; titleElement; titleElement = titleElement->nextElementSibling()) {
     102        if (titleElement->hasTagName(SVGNames::titleTag) && titleElement->isSVGElement())
     103            break;
     104    }
     105
     106    // If a title child was found, return the text contents.
     107    if (titleElement)
     108        return titleElement->innerText();
     109   
     110    // Otherwise return a null/empty string.
     111    return String();
    67112}
    68113
  • trunk/WebCore/svg/SVGStyledElement.h

    r56905 r58160  
    3939        SVGStyledElement(const QualifiedName&, Document*);
    4040        virtual ~SVGStyledElement();
     41
     42        virtual String title() const;
    4143
    4244        virtual bool hasRelativeValues() const { return false; }
Note: See TracChangeset for help on using the changeset viewer.