OLD | NEW |
---|---|
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 * Copyright (C) 2014 Google, Inc. | 5 * Copyright (C) 2014 Google, Inc. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 } | 560 } |
561 | 561 |
562 bool SVGSVGElement::selfHasRelativeLengths() const | 562 bool SVGSVGElement::selfHasRelativeLengths() const |
563 { | 563 { |
564 return m_x->currentValue()->isRelative() | 564 return m_x->currentValue()->isRelative() |
565 || m_y->currentValue()->isRelative() | 565 || m_y->currentValue()->isRelative() |
566 || m_width->currentValue()->isRelative() | 566 || m_width->currentValue()->isRelative() |
567 || m_height->currentValue()->isRelative(); | 567 || m_height->currentValue()->isRelative(); |
568 } | 568 } |
569 | 569 |
570 bool SVGSVGElement::shouldSynthesizeViewBox() const | |
571 { | |
572 return layoutObject() | |
573 && layoutObject()->isSVGRoot() | |
574 && toLayoutSVGRoot(layoutObject())->isEmbeddedThroughSVGImage(); | |
575 } | |
576 | |
570 FloatRect SVGSVGElement::currentViewBoxRect() const | 577 FloatRect SVGSVGElement::currentViewBoxRect() const |
davve
2016/09/01 17:46:42
I bothers me a bit that currentViewBoxRect() may r
fs
2016/09/01 17:57:24
Yeah, I noticed this too... Did feel that I should
| |
571 { | 578 { |
572 if (m_useCurrentView) { | 579 if (m_useCurrentView) { |
573 DCHECK(m_viewSpec); | 580 DCHECK(m_viewSpec); |
574 return m_viewSpec->viewBox()->currentValue()->value(); | 581 return m_viewSpec->viewBox()->currentValue()->value(); |
575 } | 582 } |
576 | 583 |
577 FloatRect useViewBox = viewBox()->currentValue()->value(); | 584 FloatRect useViewBox = viewBox()->currentValue()->value(); |
578 if (!useViewBox.isEmpty()) | 585 if (!useViewBox.isEmpty()) |
579 return useViewBox; | 586 return useViewBox; |
580 if (!layoutObject() || !layoutObject()->isSVGRoot()) | 587 if (!shouldSynthesizeViewBox()) |
581 return FloatRect(); | |
582 if (!toLayoutSVGRoot(layoutObject())->isEmbeddedThroughSVGImage()) | |
583 return FloatRect(); | 588 return FloatRect(); |
584 | 589 |
585 // If no viewBox is specified but non-relative width/height values, then we | 590 // If no viewBox is specified but non-relative width/height values, then we |
586 // should always synthesize a viewBox if we're embedded through a SVGImage. | 591 // should always synthesize a viewBox if we're embedded through a SVGImage. |
587 return FloatRect(FloatPoint(), FloatSize(intrinsicWidth(), intrinsicHeight() )); | 592 FloatSize synthesizedViewBoxSize(intrinsicWidth(), intrinsicHeight()); |
593 if (!hasIntrinsicWidth()) | |
594 synthesizedViewBoxSize.setWidth(width()->currentValue()->scaleByPercenta ge(currentViewportSize().width())); | |
davve
2016/09/01 17:46:42
So a <svg .. width="50%" height="50%"> would produ
fs
2016/09/01 17:57:24
Yeah, maybe a bit odd, but I guess it could make s
| |
595 if (!hasIntrinsicHeight()) | |
596 synthesizedViewBoxSize.setHeight(height()->currentValue()->scaleByPercen tage(currentViewportSize().height())); | |
597 return FloatRect(FloatPoint(), synthesizedViewBoxSize); | |
598 } | |
599 | |
600 SVGPreserveAspectRatio* SVGSVGElement::currentPreserveAspectRatio() const | |
601 { | |
602 if (m_useCurrentView) { | |
603 DCHECK(m_viewSpec); | |
604 return m_viewSpec->preserveAspectRatio()->currentValue(); | |
605 } | |
606 if (!viewBox()->currentValue()->isValid() && shouldSynthesizeViewBox()) { | |
607 // If no viewBox is specified and we're embedded through SVGImage, then | |
608 // synthesize a pAR with the value 'none'. | |
609 SVGPreserveAspectRatio* synthesizedPAR = SVGPreserveAspectRatio::create( ); | |
610 synthesizedPAR->setAlign(SVGPreserveAspectRatio::kSvgPreserveaspectratio None); | |
611 return synthesizedPAR; | |
612 } | |
613 return preserveAspectRatio()->currentValue(); | |
588 } | 614 } |
589 | 615 |
590 FloatSize SVGSVGElement::currentViewportSize() const | 616 FloatSize SVGSVGElement::currentViewportSize() const |
591 { | 617 { |
592 if (!layoutObject()) | 618 if (!layoutObject()) |
593 return FloatSize(); | 619 return FloatSize(); |
594 | 620 |
595 if (layoutObject()->isSVGRoot()) { | 621 if (layoutObject()->isSVGRoot()) { |
596 LayoutRect contentBoxRect = toLayoutSVGRoot(layoutObject())->contentBoxR ect(); | 622 LayoutRect contentBoxRect = toLayoutSVGRoot(layoutObject())->contentBoxR ect(); |
597 return FloatSize(contentBoxRect.width() / layoutObject()->style()->effec tiveZoom(), contentBoxRect.height() / layoutObject()->style()->effectiveZoom()); | 623 return FloatSize(contentBoxRect.width() / layoutObject()->style()->effec tiveZoom(), contentBoxRect.height() / layoutObject()->style()->effectiveZoom()); |
(...skipping 26 matching lines...) Expand all Loading... | |
624 { | 650 { |
625 if (height()->currentValue()->typeWithCalcResolved() == CSSPrimitiveValue::U nitType::Percentage) | 651 if (height()->currentValue()->typeWithCalcResolved() == CSSPrimitiveValue::U nitType::Percentage) |
626 return 0; | 652 return 0; |
627 | 653 |
628 SVGLengthContext lengthContext(this); | 654 SVGLengthContext lengthContext(this); |
629 return height()->currentValue()->value(lengthContext); | 655 return height()->currentValue()->value(lengthContext); |
630 } | 656 } |
631 | 657 |
632 AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float vie wHeight) const | 658 AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float vie wHeight) const |
633 { | 659 { |
660 AffineTransform ctm = SVGFitToViewBox::viewBoxToViewTransform(currentViewBox Rect(), currentPreserveAspectRatio(), viewWidth, viewHeight); | |
634 if (!m_useCurrentView) | 661 if (!m_useCurrentView) |
635 return SVGFitToViewBox::viewBoxToViewTransform(currentViewBoxRect(), pre serveAspectRatio()->currentValue(), viewWidth, viewHeight); | 662 return ctm; |
636 DCHECK(m_viewSpec); | 663 DCHECK(m_viewSpec); |
637 | 664 |
638 AffineTransform ctm = SVGFitToViewBox::viewBoxToViewTransform(currentViewBox Rect(), m_viewSpec->preserveAspectRatio()->currentValue(), viewWidth, viewHeight ); | |
639 SVGTransformList* transformList = m_viewSpec->transform(); | 665 SVGTransformList* transformList = m_viewSpec->transform(); |
640 if (transformList->isEmpty()) | 666 if (transformList->isEmpty()) |
641 return ctm; | 667 return ctm; |
642 | 668 |
643 AffineTransform transform; | 669 AffineTransform transform; |
644 if (transformList->concatenate(transform)) | 670 if (transformList->concatenate(transform)) |
645 ctm *= transform; | 671 ctm *= transform; |
646 | 672 |
647 return ctm; | 673 return ctm; |
648 } | 674 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 visitor->trace(m_width); | 762 visitor->trace(m_width); |
737 visitor->trace(m_height); | 763 visitor->trace(m_height); |
738 visitor->trace(m_translation); | 764 visitor->trace(m_translation); |
739 visitor->trace(m_timeContainer); | 765 visitor->trace(m_timeContainer); |
740 visitor->trace(m_viewSpec); | 766 visitor->trace(m_viewSpec); |
741 SVGGraphicsElement::trace(visitor); | 767 SVGGraphicsElement::trace(visitor); |
742 SVGFitToViewBox::trace(visitor); | 768 SVGFitToViewBox::trace(visitor); |
743 } | 769 } |
744 | 770 |
745 } // namespace blink | 771 } // namespace blink |
OLD | NEW |