| OLD | NEW | 
 | (Empty) | 
|    1 /* |  | 
|    2  * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> |  | 
|    3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |  | 
|    4  * Copyright (C) 2009 Google, Inc.  All rights reserved. |  | 
|    5  * Copyright (C) Research In Motion Limited 2010. All rights reserved. |  | 
|    6  * |  | 
|    7  * This library is free software; you can redistribute it and/or |  | 
|    8  * modify it under the terms of the GNU Library General Public |  | 
|    9  * License as published by the Free Software Foundation; either |  | 
|   10  * version 2 of the License, or (at your option) any later version. |  | 
|   11  * |  | 
|   12  * This library is distributed in the hope that it will be useful, |  | 
|   13  * but WITHOUT ANY WARRANTY; without even the implied warranty of |  | 
|   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU |  | 
|   15  * Library General Public License for more details. |  | 
|   16  * |  | 
|   17  * You should have received a copy of the GNU Library General Public License |  | 
|   18  * along with this library; see the file COPYING.LIB.  If not, write to |  | 
|   19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |  | 
|   20  * Boston, MA 02110-1301, USA. |  | 
|   21  */ |  | 
|   22  |  | 
|   23 #include "config.h" |  | 
|   24 #include "core/svg/SVGLocatable.h" |  | 
|   25  |  | 
|   26 #include "SVGNames.h" |  | 
|   27 #include "bindings/v8/ExceptionState.h" |  | 
|   28 #include "core/dom/ExceptionCode.h" |  | 
|   29 #include "core/rendering/RenderObject.h" |  | 
|   30 #include "core/svg/SVGGraphicsElement.h" |  | 
|   31  |  | 
|   32 namespace WebCore { |  | 
|   33  |  | 
|   34 static bool isViewportElement(Node* node) |  | 
|   35 { |  | 
|   36     return (node->hasTagName(SVGNames::svgTag) |  | 
|   37         || node->hasTagName(SVGNames::symbolTag) |  | 
|   38         || node->hasTagName(SVGNames::foreignObjectTag) |  | 
|   39         || node->hasTagName(SVGNames::imageTag)); |  | 
|   40 } |  | 
|   41  |  | 
|   42 SVGElement* SVGLocatable::nearestViewportElement(const SVGElement* element) |  | 
|   43 { |  | 
|   44     ASSERT(element); |  | 
|   45     for (Element* current = element->parentOrShadowHostElement(); current; curre
     nt = current->parentOrShadowHostElement()) { |  | 
|   46         if (isViewportElement(current)) |  | 
|   47             return toSVGElement(current); |  | 
|   48     } |  | 
|   49  |  | 
|   50     return 0; |  | 
|   51 } |  | 
|   52  |  | 
|   53 SVGElement* SVGLocatable::farthestViewportElement(const SVGElement* element) |  | 
|   54 { |  | 
|   55     ASSERT(element); |  | 
|   56     SVGElement* farthest = 0; |  | 
|   57     for (Element* current = element->parentOrShadowHostElement(); current; curre
     nt = current->parentOrShadowHostElement()) { |  | 
|   58         if (isViewportElement(current)) |  | 
|   59             farthest = toSVGElement(current); |  | 
|   60     } |  | 
|   61     return farthest; |  | 
|   62 } |  | 
|   63  |  | 
|   64 AffineTransform SVGLocatable::computeCTM(SVGElement* element, CTMScope mode, Sty
     leUpdateStrategy styleUpdateStrategy) |  | 
|   65 { |  | 
|   66     ASSERT(element); |  | 
|   67     if (styleUpdateStrategy == AllowStyleUpdate) |  | 
|   68         element->document().updateLayoutIgnorePendingStylesheets(); |  | 
|   69  |  | 
|   70     AffineTransform ctm; |  | 
|   71  |  | 
|   72     SVGElement* stopAtElement = mode == NearestViewportScope ? nearestViewportEl
     ement(element) : 0; |  | 
|   73     for (Element* currentElement = element; currentElement; currentElement = cur
     rentElement->parentOrShadowHostElement()) { |  | 
|   74         if (!currentElement->isSVGElement()) |  | 
|   75             break; |  | 
|   76  |  | 
|   77         ctm = toSVGElement(currentElement)->localCoordinateSpaceTransform(mode).
     multiply(ctm); |  | 
|   78  |  | 
|   79         // For getCTM() computation, stop at the nearest viewport element |  | 
|   80         if (currentElement == stopAtElement) |  | 
|   81             break; |  | 
|   82     } |  | 
|   83  |  | 
|   84     return ctm; |  | 
|   85 } |  | 
|   86  |  | 
|   87 AffineTransform SVGLocatable::getTransformToElement(SVGElement* target, Exceptio
     nState& es, StyleUpdateStrategy styleUpdateStrategy) |  | 
|   88 { |  | 
|   89     AffineTransform ctm = getCTM(styleUpdateStrategy); |  | 
|   90  |  | 
|   91     if (target && target->isSVGGraphicsElement()) { |  | 
|   92         AffineTransform targetCTM = toSVGGraphicsElement(target)->getCTM(styleUp
     dateStrategy); |  | 
|   93         if (!targetCTM.isInvertible()) { |  | 
|   94             es.throwUninformativeAndGenericDOMException(InvalidStateError); |  | 
|   95             return ctm; |  | 
|   96         } |  | 
|   97         ctm = targetCTM.inverse() * ctm; |  | 
|   98     } |  | 
|   99  |  | 
|  100     return ctm; |  | 
|  101 } |  | 
|  102  |  | 
|  103 } |  | 
| OLD | NEW |