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

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: revert aggressive svgAttributeChanged, add NeedsRebaseline 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/SVGTextContentElement.h » ('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 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_PRESERVEASPECTRATIO(SVGSVGElement, SVGNames::preserveAspectRatio Attr, PreserveAspectRatio, preserveAspectRatio) 64 DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSVGElement, SVGNames::preserveAspectRatio Attr, PreserveAspectRatio, preserveAspectRatio)
69 DEFINE_ANIMATED_RECT(SVGSVGElement, SVGNames::viewBoxAttr, ViewBox, viewBox) 65 DEFINE_ANIMATED_RECT(SVGSVGElement, SVGNames::viewBoxAttr, ViewBox, viewBox)
70 66
71 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSVGElement) 67 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSVGElement)
72 REGISTER_LOCAL_ANIMATED_PROPERTY(x)
73 REGISTER_LOCAL_ANIMATED_PROPERTY(y)
74 REGISTER_LOCAL_ANIMATED_PROPERTY(width)
75 REGISTER_LOCAL_ANIMATED_PROPERTY(height)
76 REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox) 68 REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox)
77 REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio) 69 REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio)
78 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) 70 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
79 END_REGISTER_ANIMATED_PROPERTIES 71 END_REGISTER_ANIMATED_PROPERTIES
80 72
81 inline SVGSVGElement::SVGSVGElement(Document& doc) 73 inline SVGSVGElement::SVGSVGElement(Document& doc)
82 : SVGGraphicsElement(SVGNames::svgTag, doc) 74 : SVGGraphicsElement(SVGNames::svgTag, doc)
83 , m_x(LengthModeWidth) 75 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(Len gthModeWidth)))
84 , m_y(LengthModeHeight) 76 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(Len gthModeHeight)))
85 , m_width(LengthModeWidth, "100%") 77 , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::cr eate(LengthModeWidth)))
86 , m_height(LengthModeHeight, "100%") 78 , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength:: create(LengthModeHeight)))
87 , m_useCurrentView(false) 79 , m_useCurrentView(false)
88 , m_zoomAndPan(SVGZoomAndPanMagnify) 80 , m_zoomAndPan(SVGZoomAndPanMagnify)
89 , m_timeContainer(SMILTimeContainer::create(this)) 81 , m_timeContainer(SMILTimeContainer::create(this))
90 , m_weakFactory(this) 82 , m_weakFactory(this)
91 { 83 {
92 ScriptWrappable::init(this); 84 ScriptWrappable::init(this);
85
86 m_width->setDefaultValueAsString("100%");
87 m_height->setDefaultValueAsString("100%");
88
89 addToPropertyMap(m_x);
90 addToPropertyMap(m_y);
91 addToPropertyMap(m_width);
92 addToPropertyMap(m_height);
93 registerAnimatedPropertiesForSVGSVGElement(); 93 registerAnimatedPropertiesForSVGSVGElement();
94 94
95 UseCounter::count(doc, UseCounter::SVGSVGElement); 95 UseCounter::count(doc, UseCounter::SVGSVGElement);
96 } 96 }
97 97
98 PassRefPtr<SVGSVGElement> SVGSVGElement::create(Document& document) 98 PassRefPtr<SVGSVGElement> SVGSVGElement::create(Document& document)
99 { 99 {
100 return adoptRef(new SVGSVGElement(document)); 100 return adoptRef(new SVGSVGElement(document));
101 } 101 }
102 102
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 240
241 if (setListener) 241 if (setListener)
242 return; 242 return;
243 } 243 }
244 244
245 if (name == HTMLNames::onabortAttr) 245 if (name == HTMLNames::onabortAttr)
246 document().setWindowAttributeEventListener(EventTypeNames::abort, create AttributeEventListener(document().frame(), name, value)); 246 document().setWindowAttributeEventListener(EventTypeNames::abort, create AttributeEventListener(document().frame(), name, value));
247 else if (name == HTMLNames::onerrorAttr) 247 else if (name == HTMLNames::onerrorAttr)
248 document().setWindowAttributeEventListener(EventTypeNames::error, create AttributeEventListener(document().frame(), name, value)); 248 document().setWindowAttributeEventListener(EventTypeNames::error, create AttributeEventListener(document().frame(), name, value));
249 else if (name == SVGNames::xAttr) 249 else if (name == SVGNames::xAttr)
250 setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError)); 250 m_x->setBaseValueAsString(value, AllowNegativeLengths, parseError);
251 else if (name == SVGNames::yAttr) 251 else if (name == SVGNames::yAttr)
252 setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError)) ; 252 m_y->setBaseValueAsString(value, AllowNegativeLengths, parseError);
253 else if (name == SVGNames::widthAttr) 253 else if (name == SVGNames::widthAttr)
254 setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseErro r, ForbidNegativeLengths)); 254 m_width->setBaseValueAsString(value, ForbidNegativeLengths, parseError);
255 else if (name == SVGNames::heightAttr) 255 else if (name == SVGNames::heightAttr)
256 setHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseEr ror, ForbidNegativeLengths)); 256 m_height->setBaseValueAsString(value, ForbidNegativeLengths, parseError) ;
257 else if (SVGFitToViewBox::parseAttribute(this, name, value) 257 else if (SVGFitToViewBox::parseAttribute(this, name, value)
258 || SVGZoomAndPan::parseAttribute(this, name, value)) { 258 || SVGZoomAndPan::parseAttribute(this, name, value)) {
259 } else 259 } else
260 SVGGraphicsElement::parseAttribute(name, value); 260 SVGGraphicsElement::parseAttribute(name, value);
261 261
262 reportAttributeParsingError(parseError, name, value); 262 reportAttributeParsingError(parseError, name, value);
263 } 263 }
264 264
265 void SVGSVGElement::svgAttributeChanged(const QualifiedName& attrName) 265 void SVGSVGElement::svgAttributeChanged(const QualifiedName& attrName)
266 { 266 {
267 bool updateRelativeLengthsOrViewBox = false; 267 bool updateRelativeLengthsOrViewBox = false;
268 bool widthChanged = attrName == SVGNames::widthAttr; 268 bool widthChanged = attrName == SVGNames::widthAttr;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 { 371 {
372 if (Frame* frame = document().frame()) 372 if (Frame* frame = document().frame())
373 frame->selection().clear(); 373 frame->selection().clear();
374 } 374 }
375 375
376 float SVGSVGElement::createSVGNumber() 376 float SVGSVGElement::createSVGNumber()
377 { 377 {
378 return 0.0f; 378 return 0.0f;
379 } 379 }
380 380
381 SVGLength SVGSVGElement::createSVGLength() 381 PassRefPtr<SVGLengthTearOff> SVGSVGElement::createSVGLength()
382 { 382 {
383 return SVGLength(); 383 return SVGLengthTearOff::create(SVGLength::create(), 0, PropertyIsNotAnimVal );
384 } 384 }
385 385
386 SVGAngle SVGSVGElement::createSVGAngle() 386 SVGAngle SVGSVGElement::createSVGAngle()
387 { 387 {
388 return SVGAngle(); 388 return SVGAngle();
389 } 389 }
390 390
391 SVGPoint SVGSVGElement::createSVGPoint() 391 SVGPoint SVGSVGElement::createSVGPoint()
392 { 392 {
393 return SVGPoint(); 393 return SVGPoint();
(...skipping 23 matching lines...) Expand all
417 { 417 {
418 AffineTransform viewBoxTransform; 418 AffineTransform viewBoxTransform;
419 if (!hasEmptyViewBox()) { 419 if (!hasEmptyViewBox()) {
420 FloatSize size = currentViewportSize(); 420 FloatSize size = currentViewportSize();
421 viewBoxTransform = viewBoxToViewTransform(size.width(), size.height()); 421 viewBoxTransform = viewBoxToViewTransform(size.width(), size.height());
422 } 422 }
423 423
424 AffineTransform transform; 424 AffineTransform transform;
425 if (!isOutermostSVGSVGElement()) { 425 if (!isOutermostSVGSVGElement()) {
426 SVGLengthContext lengthContext(this); 426 SVGLengthContext lengthContext(this);
427 transform.translate(xCurrentValue().value(lengthContext), yCurrentValue( ).value(lengthContext)); 427 transform.translate(m_x->currentValue()->value(lengthContext), m_y->curr entValue()->value(lengthContext));
428 } else if (mode == SVGElement::ScreenScope) { 428 } else if (mode == SVGElement::ScreenScope) {
429 if (RenderObject* renderer = this->renderer()) { 429 if (RenderObject* renderer = this->renderer()) {
430 FloatPoint location; 430 FloatPoint location;
431 float zoomFactor = 1; 431 float zoomFactor = 1;
432 432
433 // At the SVG/HTML boundary (aka RenderSVGRoot), we apply the localT oBorderBoxTransform 433 // At the SVG/HTML boundary (aka RenderSVGRoot), we apply the localT oBorderBoxTransform
434 // to map an element from SVG viewport coordinates to CSS box coordi nates. 434 // to map an element from SVG viewport coordinates to CSS box coordi nates.
435 // RenderSVGRoot's localToAbsolute method expects CSS box coordinate s. 435 // RenderSVGRoot's localToAbsolute method expects CSS box coordinate s.
436 // We also need to adjust for the zoom level factored into CSS coord inates (bug #96361). 436 // We also need to adjust for the zoom level factored into CSS coord inates (bug #96361).
437 if (renderer->isSVGRoot()) { 437 if (renderer->isSVGRoot()) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 void SVGSVGElement::setCurrentTime(float seconds) 529 void SVGSVGElement::setCurrentTime(float seconds)
530 { 530 {
531 if (std::isnan(seconds)) 531 if (std::isnan(seconds))
532 return; 532 return;
533 seconds = max(seconds, 0.0f); 533 seconds = max(seconds, 0.0f);
534 m_timeContainer->setElapsed(seconds); 534 m_timeContainer->setElapsed(seconds);
535 } 535 }
536 536
537 bool SVGSVGElement::selfHasRelativeLengths() const 537 bool SVGSVGElement::selfHasRelativeLengths() const
538 { 538 {
539 return xCurrentValue().isRelative() 539 return m_x->currentValue()->isRelative()
540 || yCurrentValue().isRelative() 540 || m_y->currentValue()->isRelative()
541 || widthCurrentValue().isRelative() 541 || m_width->currentValue()->isRelative()
542 || heightCurrentValue().isRelative() 542 || m_height->currentValue()->isRelative()
543 || hasAttribute(SVGNames::viewBoxAttr); 543 || hasAttribute(SVGNames::viewBoxAttr);
544 } 544 }
545 545
546 SVGRect SVGSVGElement::currentViewBoxRect() const 546 SVGRect SVGSVGElement::currentViewBoxRect() const
547 { 547 {
548 if (m_useCurrentView) 548 if (m_useCurrentView)
549 return m_viewSpec ? m_viewSpec->viewBoxCurrentValue() : SVGRect(); 549 return m_viewSpec ? m_viewSpec->viewBoxCurrentValue() : SVGRect();
550 550
551 FloatRect useViewBox = viewBoxCurrentValue(); 551 FloatRect useViewBox = viewBoxCurrentValue();
552 if (!useViewBox.isEmpty()) 552 if (!useViewBox.isEmpty())
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 // SVG embedded via SVGImage (background-image/border-image/etc) / Inline SV G. 629 // SVG embedded via SVGImage (background-image/border-image/etc) / Inline SV G.
630 if (root->isEmbeddedThroughSVGImage() || document().documentElement() != thi s) 630 if (root->isEmbeddedThroughSVGImage() || document().documentElement() != thi s)
631 return !root->hasReplacedLogicalHeight(); 631 return !root->hasReplacedLogicalHeight();
632 632
633 return true; 633 return true;
634 } 634 }
635 635
636 Length SVGSVGElement::intrinsicWidth(ConsiderCSSMode mode) const 636 Length SVGSVGElement::intrinsicWidth(ConsiderCSSMode mode) const
637 { 637 {
638 if (widthAttributeEstablishesViewport() || mode == IgnoreCSSProperties) { 638 if (widthAttributeEstablishesViewport() || mode == IgnoreCSSProperties) {
639 if (widthCurrentValue().unitType() == LengthTypePercentage) 639 if (m_width->currentValue()->unitType() == LengthTypePercentage)
640 return Length(widthCurrentValue().valueAsPercentage() * 100, Percent ); 640 return Length(m_width->currentValue()->valueAsPercentage() * 100, Pe rcent);
641 641
642 SVGLengthContext lengthContext(this); 642 SVGLengthContext lengthContext(this);
643 return Length(widthCurrentValue().value(lengthContext), Fixed); 643 return Length(m_width->currentValue()->value(lengthContext), Fixed);
644 } 644 }
645 645
646 ASSERT(renderer()); 646 ASSERT(renderer());
647 return renderer()->style()->width(); 647 return renderer()->style()->width();
648 } 648 }
649 649
650 Length SVGSVGElement::intrinsicHeight(ConsiderCSSMode mode) const 650 Length SVGSVGElement::intrinsicHeight(ConsiderCSSMode mode) const
651 { 651 {
652 if (heightAttributeEstablishesViewport() || mode == IgnoreCSSProperties) { 652 if (heightAttributeEstablishesViewport() || mode == IgnoreCSSProperties) {
653 if (heightCurrentValue().unitType() == LengthTypePercentage) 653 if (m_height->currentValue()->unitType() == LengthTypePercentage)
654 return Length(heightCurrentValue().valueAsPercentage() * 100, Percen t); 654 return Length(m_height->currentValue()->valueAsPercentage() * 100, P ercent);
655 655
656 SVGLengthContext lengthContext(this); 656 SVGLengthContext lengthContext(this);
657 return Length(heightCurrentValue().value(lengthContext), Fixed); 657 return Length(m_height->currentValue()->value(lengthContext), Fixed);
658 } 658 }
659 659
660 ASSERT(renderer()); 660 ASSERT(renderer());
661 return renderer()->style()->height(); 661 return renderer()->style()->height();
662 } 662 }
663 663
664 AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float vie wHeight) const 664 AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float vie wHeight) const
665 { 665 {
666 if (!m_useCurrentView || !m_viewSpec) 666 if (!m_useCurrentView || !m_viewSpec)
667 return SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), pre serveAspectRatioCurrentValue(), viewWidth, viewHeight); 667 return SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), pre serveAspectRatioCurrentValue(), viewWidth, viewHeight);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 continue; 766 continue;
767 767
768 Element* element = toElement(node); 768 Element* element = toElement(node);
769 if (element->getIdAttribute() == id) 769 if (element->getIdAttribute() == id)
770 return element; 770 return element;
771 } 771 }
772 return 0; 772 return 0;
773 } 773 }
774 774
775 } 775 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGSVGElement.h ('k') | Source/core/svg/SVGTextContentElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698