Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: Source/core/svg/SVGSVGElement.cpp

Issue 132233010: [SVG] SVGAnimatedRect migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebsaed Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/svg/SVGSVGElement.h ('k') | Source/core/svg/SVGSVGElement.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 29 matching lines...) Expand all
40 #include "core/frame/UseCounter.h" 40 #include "core/frame/UseCounter.h"
41 #include "core/rendering/RenderObject.h" 41 #include "core/rendering/RenderObject.h"
42 #include "core/rendering/RenderPart.h" 42 #include "core/rendering/RenderPart.h"
43 #include "core/rendering/svg/RenderSVGModelObject.h" 43 #include "core/rendering/svg/RenderSVGModelObject.h"
44 #include "core/rendering/svg/RenderSVGResource.h" 44 #include "core/rendering/svg/RenderSVGResource.h"
45 #include "core/rendering/svg/RenderSVGRoot.h" 45 #include "core/rendering/svg/RenderSVGRoot.h"
46 #include "core/rendering/svg/RenderSVGViewportContainer.h" 46 #include "core/rendering/svg/RenderSVGViewportContainer.h"
47 #include "core/svg/SVGAngle.h" 47 #include "core/svg/SVGAngle.h"
48 #include "core/svg/SVGElementInstance.h" 48 #include "core/svg/SVGElementInstance.h"
49 #include "core/svg/SVGPreserveAspectRatio.h" 49 #include "core/svg/SVGPreserveAspectRatio.h"
50 #include "core/svg/SVGRectTearOff.h"
50 #include "core/svg/SVGTransform.h" 51 #include "core/svg/SVGTransform.h"
51 #include "core/svg/SVGTransformList.h" 52 #include "core/svg/SVGTransformList.h"
52 #include "core/svg/SVGViewElement.h" 53 #include "core/svg/SVGViewElement.h"
53 #include "core/svg/SVGViewSpec.h" 54 #include "core/svg/SVGViewSpec.h"
54 #include "core/svg/animation/SMILTimeContainer.h" 55 #include "core/svg/animation/SMILTimeContainer.h"
55 #include "platform/FloatConversion.h" 56 #include "platform/FloatConversion.h"
56 #include "platform/LengthFunctions.h" 57 #include "platform/LengthFunctions.h"
57 #include "platform/geometry/FloatRect.h" 58 #include "platform/geometry/FloatRect.h"
58 #include "platform/transforms/AffineTransform.h" 59 #include "platform/transforms/AffineTransform.h"
59 #include "wtf/StdLibExtras.h" 60 #include "wtf/StdLibExtras.h"
60 61
61 namespace WebCore { 62 namespace WebCore {
62 63
63 // Animated property definitions 64 // Animated property definitions
64 DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSVGElement, SVGNames::preserveAspectRatio Attr, PreserveAspectRatio, preserveAspectRatio) 65 DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSVGElement, SVGNames::preserveAspectRatio Attr, PreserveAspectRatio, preserveAspectRatio)
65 DEFINE_ANIMATED_RECT(SVGSVGElement, SVGNames::viewBoxAttr, ViewBox, viewBox)
66 66
67 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSVGElement) 67 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSVGElement)
68 REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox)
69 REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio) 68 REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio)
70 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) 69 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
71 END_REGISTER_ANIMATED_PROPERTIES 70 END_REGISTER_ANIMATED_PROPERTIES
72 71
73 inline SVGSVGElement::SVGSVGElement(Document& doc) 72 inline SVGSVGElement::SVGSVGElement(Document& doc)
74 : SVGGraphicsElement(SVGNames::svgTag, doc) 73 : SVGGraphicsElement(SVGNames::svgTag, doc)
75 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(Len gthModeWidth))) 74 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(Len gthModeWidth)))
76 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(Len gthModeHeight))) 75 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(Len gthModeHeight)))
77 , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::cr eate(LengthModeWidth))) 76 , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::cr eate(LengthModeWidth)))
78 , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength:: create(LengthModeHeight))) 77 , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength:: create(LengthModeHeight)))
78 , m_viewBox(SVGAnimatedRect::create(this, SVGNames::viewBoxAttr))
79 , m_useCurrentView(false) 79 , m_useCurrentView(false)
80 , m_zoomAndPan(SVGZoomAndPanMagnify) 80 , m_zoomAndPan(SVGZoomAndPanMagnify)
81 , m_timeContainer(SMILTimeContainer::create(this)) 81 , m_timeContainer(SMILTimeContainer::create(this))
82 , m_weakFactory(this) 82 , m_weakFactory(this)
83 { 83 {
84 ScriptWrappable::init(this); 84 ScriptWrappable::init(this);
85 85
86 m_width->setDefaultValueAsString("100%"); 86 m_width->setDefaultValueAsString("100%");
87 m_height->setDefaultValueAsString("100%"); 87 m_height->setDefaultValueAsString("100%");
88 88
89 addToPropertyMap(m_x); 89 addToPropertyMap(m_x);
90 addToPropertyMap(m_y); 90 addToPropertyMap(m_y);
91 addToPropertyMap(m_width); 91 addToPropertyMap(m_width);
92 addToPropertyMap(m_height); 92 addToPropertyMap(m_height);
93 addToPropertyMap(m_viewBox);
93 registerAnimatedPropertiesForSVGSVGElement(); 94 registerAnimatedPropertiesForSVGSVGElement();
94 95
95 UseCounter::count(doc, UseCounter::SVGSVGElement); 96 UseCounter::count(doc, UseCounter::SVGSVGElement);
96 } 97 }
97 98
98 PassRefPtr<SVGSVGElement> SVGSVGElement::create(Document& document) 99 PassRefPtr<SVGSVGElement> SVGSVGElement::create(Document& document)
99 { 100 {
100 return adoptRef(new SVGSVGElement(document)); 101 return adoptRef(new SVGSVGElement(document));
101 } 102 }
102 103
(...skipping 23 matching lines...) Expand all
126 DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css", AtomicStr ing::ConstructFromLiteral)); 127 DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css", AtomicStr ing::ConstructFromLiteral));
127 const AtomicString& n = fastGetAttribute(SVGNames::contentStyleTypeAttr); 128 const AtomicString& n = fastGetAttribute(SVGNames::contentStyleTypeAttr);
128 return n.isNull() ? defaultValue : n; 129 return n.isNull() ? defaultValue : n;
129 } 130 }
130 131
131 void SVGSVGElement::setContentStyleType(const AtomicString& type) 132 void SVGSVGElement::setContentStyleType(const AtomicString& type)
132 { 133 {
133 setAttribute(SVGNames::contentStyleTypeAttr, type); 134 setAttribute(SVGNames::contentStyleTypeAttr, type);
134 } 135 }
135 136
136 SVGRect SVGSVGElement::viewport() const 137 PassRefPtr<SVGRectTearOff> SVGSVGElement::viewport() const
137 { 138 {
138 // FIXME: This method doesn't follow the spec and is basically untested. Par ent documents are not considered here. 139 // FIXME: This method doesn't follow the spec and is basically untested. Par ent documents are not considered here.
139 // As we have no test coverage for this, we're going to disable it completly for now. 140 // As we have no test coverage for this, we're going to disable it completly for now.
140 return SVGRect(); 141 return SVGRectTearOff::create(SVGRect::create(), 0, PropertyIsNotAnimVal);
141 } 142 }
142 143
143 float SVGSVGElement::pixelUnitToMillimeterX() const 144 float SVGSVGElement::pixelUnitToMillimeterX() const
144 { 145 {
145 return 1 / cssPixelsPerMillimeter; 146 return 1 / cssPixelsPerMillimeter;
146 } 147 }
147 148
148 float SVGSVGElement::pixelUnitToMillimeterY() const 149 float SVGSVGElement::pixelUnitToMillimeterY() const
149 { 150 {
150 return 1 / cssPixelsPerMillimeter; 151 return 1 / cssPixelsPerMillimeter;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 void SVGSVGElement::unsuspendRedrawAll() 316 void SVGSVGElement::unsuspendRedrawAll()
316 { 317 {
317 // FIXME: Implement me (see bug 11275) 318 // FIXME: Implement me (see bug 11275)
318 } 319 }
319 320
320 void SVGSVGElement::forceRedraw() 321 void SVGSVGElement::forceRedraw()
321 { 322 {
322 // FIXME: Implement me (see bug 11275) 323 // FIXME: Implement me (see bug 11275)
323 } 324 }
324 325
325 PassRefPtr<NodeList> SVGSVGElement::collectIntersectionOrEnclosureList(const SVG Rect& rect, SVGElement* referenceElement, CollectIntersectionOrEnclosure collect ) const 326 PassRefPtr<NodeList> SVGSVGElement::collectIntersectionOrEnclosureList(const Flo atRect& rect, SVGElement* referenceElement, CollectIntersectionOrEnclosure colle ct) const
326 { 327 {
327 Vector<RefPtr<Node> > nodes; 328 Vector<RefPtr<Node> > nodes;
328 Element* element = ElementTraversal::next(*(referenceElement ? referenceElem ent : this)); 329 Element* element = ElementTraversal::next(*(referenceElement ? referenceElem ent : this));
329 while (element) { 330 while (element) {
330 if (element->isSVGElement()) { 331 if (element->isSVGElement()) {
331 SVGElement* svgElement = toSVGElement(element); 332 SVGElement* svgElement = toSVGElement(element);
332 if (collect == CollectIntersectionList) { 333 if (collect == CollectIntersectionList) {
333 if (checkIntersection(svgElement, rect)) 334 if (RenderSVGModelObject::checkIntersection(svgElement->renderer (), rect))
334 nodes.append(element); 335 nodes.append(element);
335 } else { 336 } else {
336 if (checkEnclosure(svgElement, rect)) 337 if (RenderSVGModelObject::checkEnclosure(svgElement->renderer(), rect))
337 nodes.append(element); 338 nodes.append(element);
338 } 339 }
339 } 340 }
340 341
341 element = ElementTraversal::next(*element, referenceElement ? referenceE lement : this); 342 element = ElementTraversal::next(*element, referenceElement ? referenceE lement : this);
342 } 343 }
343 return StaticNodeList::adopt(nodes); 344 return StaticNodeList::adopt(nodes);
344 } 345 }
345 346
346 PassRefPtr<NodeList> SVGSVGElement::getIntersectionList(const SVGRect& rect, SVG Element* referenceElement) const 347 PassRefPtr<NodeList> SVGSVGElement::getIntersectionList(PassRefPtr<SVGRectTearOf f> passRect, SVGElement* referenceElement) const
347 { 348 {
348 return collectIntersectionOrEnclosureList(rect, referenceElement, CollectInt ersectionList); 349 RefPtr<SVGRectTearOff> rect = passRect;
350 return collectIntersectionOrEnclosureList(rect->target()->value(), reference Element, CollectIntersectionList);
349 } 351 }
350 352
351 PassRefPtr<NodeList> SVGSVGElement::getEnclosureList(const SVGRect& rect, SVGEle ment* referenceElement) const 353 PassRefPtr<NodeList> SVGSVGElement::getEnclosureList(PassRefPtr<SVGRectTearOff> passRect, SVGElement* referenceElement) const
352 { 354 {
353 return collectIntersectionOrEnclosureList(rect, referenceElement, CollectEnc losureList); 355 RefPtr<SVGRectTearOff> rect = passRect;
356 return collectIntersectionOrEnclosureList(rect->target()->value(), reference Element, CollectEnclosureList);
354 } 357 }
355 358
356 bool SVGSVGElement::checkIntersection(SVGElement* element, const SVGRect& rect) const 359 bool SVGSVGElement::checkIntersection(SVGElement* element, PassRefPtr<SVGRectTea rOff> passRect) const
357 { 360 {
358 if (!element) 361 if (!element)
359 return false; 362 return false;
360 return RenderSVGModelObject::checkIntersection(element->renderer(), rect); 363 RefPtr<SVGRectTearOff> rect = passRect;
364 return RenderSVGModelObject::checkIntersection(element->renderer(), rect->ta rget()->value());
361 } 365 }
362 366
363 bool SVGSVGElement::checkEnclosure(SVGElement* element, const SVGRect& rect) con st 367 bool SVGSVGElement::checkEnclosure(SVGElement* element, PassRefPtr<SVGRectTearOf f> passRect) const
364 { 368 {
365 if (!element) 369 if (!element)
366 return false; 370 return false;
367 return RenderSVGModelObject::checkEnclosure(element->renderer(), rect); 371 RefPtr<SVGRectTearOff> rect = passRect;
372 return RenderSVGModelObject::checkEnclosure(element->renderer(), rect->targe t()->value());
368 } 373 }
369 374
370 void SVGSVGElement::deselectAll() 375 void SVGSVGElement::deselectAll()
371 { 376 {
372 if (Frame* frame = document().frame()) 377 if (Frame* frame = document().frame())
373 frame->selection().clear(); 378 frame->selection().clear();
374 } 379 }
375 380
376 float SVGSVGElement::createSVGNumber() 381 float SVGSVGElement::createSVGNumber()
377 { 382 {
(...skipping 13 matching lines...) Expand all
391 SVGPoint SVGSVGElement::createSVGPoint() 396 SVGPoint SVGSVGElement::createSVGPoint()
392 { 397 {
393 return SVGPoint(); 398 return SVGPoint();
394 } 399 }
395 400
396 SVGMatrix SVGSVGElement::createSVGMatrix() 401 SVGMatrix SVGSVGElement::createSVGMatrix()
397 { 402 {
398 return SVGMatrix(); 403 return SVGMatrix();
399 } 404 }
400 405
401 SVGRect SVGSVGElement::createSVGRect() 406 PassRefPtr<SVGRectTearOff> SVGSVGElement::createSVGRect()
402 { 407 {
403 return SVGRect(); 408 return SVGRectTearOff::create(SVGRect::create(), 0, PropertyIsNotAnimVal);
404 } 409 }
405 410
406 SVGTransform SVGSVGElement::createSVGTransform() 411 SVGTransform SVGSVGElement::createSVGTransform()
407 { 412 {
408 return SVGTransform(SVGTransform::SVG_TRANSFORM_MATRIX); 413 return SVGTransform(SVGTransform::SVG_TRANSFORM_MATRIX);
409 } 414 }
410 415
411 SVGTransform SVGSVGElement::createSVGTransformFromMatrix(const SVGMatrix& matrix ) 416 SVGTransform SVGSVGElement::createSVGTransformFromMatrix(const SVGMatrix& matrix )
412 { 417 {
413 return SVGTransform(static_cast<const AffineTransform&>(matrix)); 418 return SVGTransform(static_cast<const AffineTransform&>(matrix));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 541
537 bool SVGSVGElement::selfHasRelativeLengths() const 542 bool SVGSVGElement::selfHasRelativeLengths() const
538 { 543 {
539 return m_x->currentValue()->isRelative() 544 return m_x->currentValue()->isRelative()
540 || m_y->currentValue()->isRelative() 545 || m_y->currentValue()->isRelative()
541 || m_width->currentValue()->isRelative() 546 || m_width->currentValue()->isRelative()
542 || m_height->currentValue()->isRelative() 547 || m_height->currentValue()->isRelative()
543 || hasAttribute(SVGNames::viewBoxAttr); 548 || hasAttribute(SVGNames::viewBoxAttr);
544 } 549 }
545 550
546 SVGRect SVGSVGElement::currentViewBoxRect() const 551 FloatRect SVGSVGElement::currentViewBoxRect() const
547 { 552 {
548 if (m_useCurrentView) 553 if (m_useCurrentView)
549 return m_viewSpec ? m_viewSpec->viewBoxCurrentValue() : SVGRect(); 554 return m_viewSpec ? m_viewSpec->viewBox()->currentValue()->value() : Flo atRect();
550 555
551 FloatRect useViewBox = viewBoxCurrentValue(); 556 FloatRect useViewBox = m_viewBox->currentValue()->value();
552 if (!useViewBox.isEmpty()) 557 if (!useViewBox.isEmpty())
553 return useViewBox; 558 return useViewBox;
554 if (!renderer() || !renderer()->isSVGRoot()) 559 if (!renderer() || !renderer()->isSVGRoot())
555 return SVGRect(); 560 return FloatRect();
556 if (!toRenderSVGRoot(renderer())->isEmbeddedThroughSVGImage()) 561 if (!toRenderSVGRoot(renderer())->isEmbeddedThroughSVGImage())
557 return SVGRect(); 562 return FloatRect();
558 563
559 Length intrinsicWidth = this->intrinsicWidth(); 564 Length intrinsicWidth = this->intrinsicWidth();
560 Length intrinsicHeight = this->intrinsicHeight(); 565 Length intrinsicHeight = this->intrinsicHeight();
561 if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed()) 566 if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed())
562 return SVGRect(); 567 return FloatRect();
563 568
564 // If no viewBox is specified but non-relative width/height values, then we 569 // If no viewBox is specified but non-relative width/height values, then we
565 // should always synthesize a viewBox if we're embedded through a SVGImage. 570 // should always synthesize a viewBox if we're embedded through a SVGImage.
566 return SVGRect(FloatPoint(), FloatSize(floatValueForLength(intrinsicWidth, 0 ), floatValueForLength(intrinsicHeight, 0))); 571 return FloatRect(FloatPoint(), FloatSize(floatValueForLength(intrinsicWidth, 0), floatValueForLength(intrinsicHeight, 0)));
567 } 572 }
568 573
569 FloatSize SVGSVGElement::currentViewportSize() const 574 FloatSize SVGSVGElement::currentViewportSize() const
570 { 575 {
571 Length intrinsicWidth = this->intrinsicWidth(); 576 Length intrinsicWidth = this->intrinsicWidth();
572 Length intrinsicHeight = this->intrinsicHeight(); 577 Length intrinsicHeight = this->intrinsicHeight();
573 if (intrinsicWidth.isFixed() && intrinsicHeight.isFixed()) 578 if (intrinsicWidth.isFixed() && intrinsicHeight.isFixed())
574 return FloatSize(floatValueForLength(intrinsicWidth, 0), floatValueForLe ngth(intrinsicHeight, 0)); 579 return FloatSize(floatValueForLength(intrinsicWidth, 0), floatValueForLe ngth(intrinsicHeight, 0));
575 580
576 if (!renderer()) 581 if (!renderer())
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 // FIXME: We need to decide which <svg> to focus on, and zoom to it. 734 // FIXME: We need to decide which <svg> to focus on, and zoom to it.
730 // FIXME: We need to actually "highlight" the viewTarget(s). 735 // FIXME: We need to actually "highlight" the viewTarget(s).
731 } 736 }
732 737
733 void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement) 738 void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement)
734 { 739 {
735 SVGViewSpec* view = currentView(); 740 SVGViewSpec* view = currentView();
736 m_useCurrentView = true; 741 m_useCurrentView = true;
737 742
738 if (viewElement->hasAttribute(SVGNames::viewBoxAttr)) 743 if (viewElement->hasAttribute(SVGNames::viewBoxAttr))
739 view->setViewBoxBaseValue(viewElement->viewBoxCurrentValue()); 744 view->viewBox()->baseValue()->setValue(viewElement->viewBox()->currentVa lue()->value());
740 else 745 else
741 view->setViewBoxBaseValue(viewBoxCurrentValue()); 746 view->viewBox()->baseValue()->setValue(m_viewBox->currentValue()->value( ));
742 747
743 if (viewElement->hasAttribute(SVGNames::preserveAspectRatioAttr)) 748 if (viewElement->hasAttribute(SVGNames::preserveAspectRatioAttr))
744 view->setPreserveAspectRatioBaseValue(viewElement->preserveAspectRatioBa seValue()); 749 view->setPreserveAspectRatioBaseValue(viewElement->preserveAspectRatioBa seValue());
745 else 750 else
746 view->setPreserveAspectRatioBaseValue(preserveAspectRatioBaseValue()); 751 view->setPreserveAspectRatioBaseValue(preserveAspectRatioBaseValue());
747 752
748 if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr)) 753 if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr))
749 view->setZoomAndPanBaseValue(viewElement->zoomAndPan()); 754 view->setZoomAndPanBaseValue(viewElement->zoomAndPan());
750 else 755 else
751 view->setZoomAndPanBaseValue(zoomAndPan()); 756 view->setZoomAndPanBaseValue(zoomAndPan());
(...skipping 14 matching lines...) Expand all
766 continue; 771 continue;
767 772
768 Element* element = toElement(node); 773 Element* element = toElement(node);
769 if (element->getIdAttribute() == id) 774 if (element->getIdAttribute() == id)
770 return element; 775 return element;
771 } 776 }
772 return 0; 777 return 0;
773 } 778 }
774 779
775 } 780 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGSVGElement.h ('k') | Source/core/svg/SVGSVGElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698