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

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

Issue 112003003: [SVG] SVGLength{,List} migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaselined Created 7 years 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
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "core/svg/animation/SMILTimeContainer.h" 54 #include "core/svg/animation/SMILTimeContainer.h"
55 #include "platform/FloatConversion.h" 55 #include "platform/FloatConversion.h"
56 #include "platform/LengthFunctions.h" 56 #include "platform/LengthFunctions.h"
57 #include "platform/geometry/FloatRect.h" 57 #include "platform/geometry/FloatRect.h"
58 #include "platform/transforms/AffineTransform.h" 58 #include "platform/transforms/AffineTransform.h"
59 #include "wtf/StdLibExtras.h" 59 #include "wtf/StdLibExtras.h"
60 60
61 namespace WebCore { 61 namespace WebCore {
62 62
63 // Animated property definitions 63 // Animated property definitions
64 DEFINE_ANIMATED_LENGTH(SVGSVGElement, SVGNames::xAttr, X, x)
65 DEFINE_ANIMATED_LENGTH(SVGSVGElement, SVGNames::yAttr, Y, y)
66 DEFINE_ANIMATED_LENGTH(SVGSVGElement, SVGNames::widthAttr, Width, width)
67 DEFINE_ANIMATED_LENGTH(SVGSVGElement, SVGNames::heightAttr, Height, height)
68 DEFINE_ANIMATED_BOOLEAN(SVGSVGElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) 64 DEFINE_ANIMATED_BOOLEAN(SVGSVGElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
69 DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSVGElement, SVGNames::preserveAspectRatio Attr, PreserveAspectRatio, preserveAspectRatio) 65 DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSVGElement, SVGNames::preserveAspectRatio Attr, PreserveAspectRatio, preserveAspectRatio)
70 DEFINE_ANIMATED_RECT(SVGSVGElement, SVGNames::viewBoxAttr, ViewBox, viewBox) 66 DEFINE_ANIMATED_RECT(SVGSVGElement, SVGNames::viewBoxAttr, ViewBox, viewBox)
71 67
72 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSVGElement) 68 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSVGElement)
73 REGISTER_LOCAL_ANIMATED_PROPERTY(x)
74 REGISTER_LOCAL_ANIMATED_PROPERTY(y)
75 REGISTER_LOCAL_ANIMATED_PROPERTY(width)
76 REGISTER_LOCAL_ANIMATED_PROPERTY(height)
77 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) 69 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
78 REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox) 70 REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox)
79 REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio) 71 REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio)
80 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) 72 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
81 END_REGISTER_ANIMATED_PROPERTIES 73 END_REGISTER_ANIMATED_PROPERTIES
82 74
83 inline SVGSVGElement::SVGSVGElement(Document& doc) 75 inline SVGSVGElement::SVGSVGElement(Document& doc)
84 : SVGGraphicsElement(SVGNames::svgTag, doc) 76 : SVGGraphicsElement(SVGNames::svgTag, doc)
85 , m_x(LengthModeWidth) 77 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(Len gthModeWidth)))
86 , m_y(LengthModeHeight) 78 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(Len gthModeHeight)))
87 , m_width(LengthModeWidth, "100%") 79 , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::cr eate(LengthModeWidth)))
88 , m_height(LengthModeHeight, "100%") 80 , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength:: create(LengthModeHeight)))
89 , m_useCurrentView(false) 81 , m_useCurrentView(false)
90 , m_zoomAndPan(SVGZoomAndPanMagnify) 82 , m_zoomAndPan(SVGZoomAndPanMagnify)
91 , m_timeContainer(SMILTimeContainer::create(this)) 83 , m_timeContainer(SMILTimeContainer::create(this))
92 , m_weakFactory(this) 84 , m_weakFactory(this)
93 { 85 {
94 ScriptWrappable::init(this); 86 ScriptWrappable::init(this);
87
88 m_width->setDefaultValueAsString("100%");
89 m_height->setDefaultValueAsString("100%");
90
91 addToPropertyMap(m_x);
92 addToPropertyMap(m_y);
93 addToPropertyMap(m_width);
94 addToPropertyMap(m_height);
95 registerAnimatedPropertiesForSVGSVGElement(); 95 registerAnimatedPropertiesForSVGSVGElement();
96 96
97 UseCounter::count(doc, UseCounter::SVGSVGElement); 97 UseCounter::count(doc, UseCounter::SVGSVGElement);
98 } 98 }
99 99
100 PassRefPtr<SVGSVGElement> SVGSVGElement::create(Document& document) 100 PassRefPtr<SVGSVGElement> SVGSVGElement::create(Document& document)
101 { 101 {
102 return adoptRef(new SVGSVGElement(document)); 102 return adoptRef(new SVGSVGElement(document));
103 } 103 }
104 104
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 242
243 if (setListener) 243 if (setListener)
244 return; 244 return;
245 } 245 }
246 246
247 if (name == HTMLNames::onabortAttr) 247 if (name == HTMLNames::onabortAttr)
248 document().setWindowAttributeEventListener(EventTypeNames::abort, create AttributeEventListener(document().frame(), name, value)); 248 document().setWindowAttributeEventListener(EventTypeNames::abort, create AttributeEventListener(document().frame(), name, value));
249 else if (name == HTMLNames::onerrorAttr) 249 else if (name == HTMLNames::onerrorAttr)
250 document().setWindowAttributeEventListener(EventTypeNames::error, create AttributeEventListener(document().frame(), name, value)); 250 document().setWindowAttributeEventListener(EventTypeNames::error, create AttributeEventListener(document().frame(), name, value));
251 else if (name == SVGNames::xAttr) 251 else if (name == SVGNames::xAttr)
252 setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError)); 252 m_x->setBaseValueAsString(value, AllowNegativeLengths, parseError);
253 else if (name == SVGNames::yAttr) 253 else if (name == SVGNames::yAttr)
254 setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError)) ; 254 m_y->setBaseValueAsString(value, AllowNegativeLengths, parseError);
255 else if (name == SVGNames::widthAttr) 255 else if (name == SVGNames::widthAttr)
256 setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseErro r, ForbidNegativeLengths)); 256 m_width->setBaseValueAsString(value, ForbidNegativeLengths, parseError);
257 else if (name == SVGNames::heightAttr) 257 else if (name == SVGNames::heightAttr)
258 setHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseEr ror, ForbidNegativeLengths)); 258 m_height->setBaseValueAsString(value, ForbidNegativeLengths, parseError) ;
259 else if (SVGExternalResourcesRequired::parseAttribute(name, value) 259 else if (SVGExternalResourcesRequired::parseAttribute(name, value)
260 || SVGFitToViewBox::parseAttribute(this, name, value) 260 || SVGFitToViewBox::parseAttribute(this, name, value)
261 || SVGZoomAndPan::parseAttribute(this, name, value)) { 261 || SVGZoomAndPan::parseAttribute(this, name, value)) {
262 } else 262 } else
263 SVGGraphicsElement::parseAttribute(name, value); 263 SVGGraphicsElement::parseAttribute(name, value);
264 264
265 reportAttributeParsingError(parseError, name, value); 265 reportAttributeParsingError(parseError, name, value);
266 } 266 }
267 267
268 void SVGSVGElement::svgAttributeChanged(const QualifiedName& attrName) 268 void SVGSVGElement::svgAttributeChanged(const QualifiedName& attrName)
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 { 375 {
376 if (Frame* frame = document().frame()) 376 if (Frame* frame = document().frame())
377 frame->selection().clear(); 377 frame->selection().clear();
378 } 378 }
379 379
380 float SVGSVGElement::createSVGNumber() 380 float SVGSVGElement::createSVGNumber()
381 { 381 {
382 return 0.0f; 382 return 0.0f;
383 } 383 }
384 384
385 SVGLength SVGSVGElement::createSVGLength() 385 PassRefPtr<SVGLengthTearOff> SVGSVGElement::createSVGLength()
386 { 386 {
387 return SVGLength(); 387 return SVGLengthTearOff::create(SVGLength::create(), 0, PropertyIsNotAnimVal );
388 } 388 }
389 389
390 SVGAngle SVGSVGElement::createSVGAngle() 390 SVGAngle SVGSVGElement::createSVGAngle()
391 { 391 {
392 return SVGAngle(); 392 return SVGAngle();
393 } 393 }
394 394
395 SVGPoint SVGSVGElement::createSVGPoint() 395 SVGPoint SVGSVGElement::createSVGPoint()
396 { 396 {
397 return SVGPoint(); 397 return SVGPoint();
(...skipping 23 matching lines...) Expand all
421 { 421 {
422 AffineTransform viewBoxTransform; 422 AffineTransform viewBoxTransform;
423 if (!hasEmptyViewBox()) { 423 if (!hasEmptyViewBox()) {
424 FloatSize size = currentViewportSize(); 424 FloatSize size = currentViewportSize();
425 viewBoxTransform = viewBoxToViewTransform(size.width(), size.height()); 425 viewBoxTransform = viewBoxToViewTransform(size.width(), size.height());
426 } 426 }
427 427
428 AffineTransform transform; 428 AffineTransform transform;
429 if (!isOutermostSVGSVGElement()) { 429 if (!isOutermostSVGSVGElement()) {
430 SVGLengthContext lengthContext(this); 430 SVGLengthContext lengthContext(this);
431 transform.translate(xCurrentValue().value(lengthContext), yCurrentValue( ).value(lengthContext)); 431 transform.translate(m_x->currentValue()->value(lengthContext), m_y->curr entValue()->value(lengthContext));
432 } else if (mode == SVGElement::ScreenScope) { 432 } else if (mode == SVGElement::ScreenScope) {
433 if (RenderObject* renderer = this->renderer()) { 433 if (RenderObject* renderer = this->renderer()) {
434 FloatPoint location; 434 FloatPoint location;
435 float zoomFactor = 1; 435 float zoomFactor = 1;
436 436
437 // At the SVG/HTML boundary (aka RenderSVGRoot), we apply the localT oBorderBoxTransform 437 // At the SVG/HTML boundary (aka RenderSVGRoot), we apply the localT oBorderBoxTransform
438 // to map an element from SVG viewport coordinates to CSS box coordi nates. 438 // to map an element from SVG viewport coordinates to CSS box coordi nates.
439 // RenderSVGRoot's localToAbsolute method expects CSS box coordinate s. 439 // RenderSVGRoot's localToAbsolute method expects CSS box coordinate s.
440 // We also need to adjust for the zoom level factored into CSS coord inates (bug #96361). 440 // We also need to adjust for the zoom level factored into CSS coord inates (bug #96361).
441 if (renderer->isSVGRoot()) { 441 if (renderer->isSVGRoot()) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 void SVGSVGElement::setCurrentTime(float seconds) 533 void SVGSVGElement::setCurrentTime(float seconds)
534 { 534 {
535 if (std::isnan(seconds)) 535 if (std::isnan(seconds))
536 return; 536 return;
537 seconds = max(seconds, 0.0f); 537 seconds = max(seconds, 0.0f);
538 m_timeContainer->setElapsed(seconds); 538 m_timeContainer->setElapsed(seconds);
539 } 539 }
540 540
541 bool SVGSVGElement::selfHasRelativeLengths() const 541 bool SVGSVGElement::selfHasRelativeLengths() const
542 { 542 {
543 return xCurrentValue().isRelative() 543 return m_x->currentValue()->isRelative()
544 || yCurrentValue().isRelative() 544 || m_y->currentValue()->isRelative()
545 || widthCurrentValue().isRelative() 545 || m_width->currentValue()->isRelative()
546 || heightCurrentValue().isRelative() 546 || m_height->currentValue()->isRelative()
547 || hasAttribute(SVGNames::viewBoxAttr); 547 || hasAttribute(SVGNames::viewBoxAttr);
548 } 548 }
549 549
550 SVGRect SVGSVGElement::currentViewBoxRect() const 550 SVGRect SVGSVGElement::currentViewBoxRect() const
551 { 551 {
552 if (m_useCurrentView) 552 if (m_useCurrentView)
553 return m_viewSpec ? m_viewSpec->viewBoxCurrentValue() : SVGRect(); 553 return m_viewSpec ? m_viewSpec->viewBoxCurrentValue() : SVGRect();
554 554
555 FloatRect useViewBox = viewBoxCurrentValue(); 555 FloatRect useViewBox = viewBoxCurrentValue();
556 if (!useViewBox.isEmpty()) 556 if (!useViewBox.isEmpty())
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // SVG embedded via SVGImage (background-image/border-image/etc) / Inline SV G. 633 // SVG embedded via SVGImage (background-image/border-image/etc) / Inline SV G.
634 if (root->isEmbeddedThroughSVGImage() || document().documentElement() != thi s) 634 if (root->isEmbeddedThroughSVGImage() || document().documentElement() != thi s)
635 return !root->hasReplacedLogicalHeight(); 635 return !root->hasReplacedLogicalHeight();
636 636
637 return true; 637 return true;
638 } 638 }
639 639
640 Length SVGSVGElement::intrinsicWidth(ConsiderCSSMode mode) const 640 Length SVGSVGElement::intrinsicWidth(ConsiderCSSMode mode) const
641 { 641 {
642 if (widthAttributeEstablishesViewport() || mode == IgnoreCSSProperties) { 642 if (widthAttributeEstablishesViewport() || mode == IgnoreCSSProperties) {
643 if (widthCurrentValue().unitType() == LengthTypePercentage) 643 if (m_width->currentValue()->unitType() == LengthTypePercentage)
644 return Length(widthCurrentValue().valueAsPercentage() * 100, Percent ); 644 return Length(m_width->currentValue()->valueAsPercentage() * 100, Pe rcent);
645 645
646 SVGLengthContext lengthContext(this); 646 SVGLengthContext lengthContext(this);
647 return Length(widthCurrentValue().value(lengthContext), Fixed); 647 return Length(m_width->currentValue()->value(lengthContext), Fixed);
648 } 648 }
649 649
650 ASSERT(renderer()); 650 ASSERT(renderer());
651 return renderer()->style()->width(); 651 return renderer()->style()->width();
652 } 652 }
653 653
654 Length SVGSVGElement::intrinsicHeight(ConsiderCSSMode mode) const 654 Length SVGSVGElement::intrinsicHeight(ConsiderCSSMode mode) const
655 { 655 {
656 if (heightAttributeEstablishesViewport() || mode == IgnoreCSSProperties) { 656 if (heightAttributeEstablishesViewport() || mode == IgnoreCSSProperties) {
657 if (heightCurrentValue().unitType() == LengthTypePercentage) 657 if (m_height->currentValue()->unitType() == LengthTypePercentage)
658 return Length(heightCurrentValue().valueAsPercentage() * 100, Percen t); 658 return Length(m_height->currentValue()->valueAsPercentage() * 100, P ercent);
659 659
660 SVGLengthContext lengthContext(this); 660 SVGLengthContext lengthContext(this);
661 return Length(heightCurrentValue().value(lengthContext), Fixed); 661 return Length(m_height->currentValue()->value(lengthContext), Fixed);
662 } 662 }
663 663
664 ASSERT(renderer()); 664 ASSERT(renderer());
665 return renderer()->style()->height(); 665 return renderer()->style()->height();
666 } 666 }
667 667
668 AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float vie wHeight) const 668 AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float vie wHeight) const
669 { 669 {
670 if (!m_useCurrentView || !m_viewSpec) 670 if (!m_useCurrentView || !m_viewSpec)
671 return SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), pre serveAspectRatioCurrentValue(), viewWidth, viewHeight); 671 return SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), pre serveAspectRatioCurrentValue(), viewWidth, viewHeight);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 continue; 770 continue;
771 771
772 Element* element = toElement(node); 772 Element* element = toElement(node);
773 if (element->getIdAttribute() == id) 773 if (element->getIdAttribute() == id)
774 return element; 774 return element;
775 } 775 }
776 return 0; 776 return 0;
777 } 777 }
778 778
779 } 779 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698