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

Unified Diff: Source/core/svg/graphics/SVGImage.cpp

Issue 208503002: Reduce rootElement access boilerplate in SVGImage (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/graphics/SVGImage.cpp
diff --git a/Source/core/svg/graphics/SVGImage.cpp b/Source/core/svg/graphics/SVGImage.cpp
index 136d923c531bc7daccf949761a0e53e128bc5c59..b58c885eaf61914e783e9d557bb2a6b5c29fb788 100644
--- a/Source/core/svg/graphics/SVGImage.cpp
+++ b/Source/core/svg/graphics/SVGImage.cpp
@@ -116,13 +116,20 @@ bool SVGImage::currentFrameHasSingleSecurityOrigin() const
return true;
}
+static SVGSVGElement* svgRootElement(Page* page)
+{
+ if (!page)
+ return 0;
+ LocalFrame* frame = page->mainFrame();
+ return toSVGDocument(frame->document())->rootElement();
+}
+
void SVGImage::setContainerSize(const IntSize& size)
{
- if (!m_page || !usesContainerSize())
+ if (!usesContainerSize())
return;
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement)
return;
@@ -137,10 +144,7 @@ void SVGImage::setContainerSize(const IntSize& size)
IntSize SVGImage::containerSize() const
{
- if (!m_page)
- return IntSize();
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement)
return IntSize();
@@ -291,10 +295,7 @@ void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl
RenderBox* SVGImage::embeddedContentBox() const
{
- if (!m_page)
- return 0;
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement)
return 0;
return toRenderBox(rootElement->renderer());
@@ -310,10 +311,7 @@ FrameView* SVGImage::frameView() const
bool SVGImage::hasRelativeWidth() const
{
- if (!m_page)
- return false;
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement)
return false;
return rootElement->intrinsicWidth().isPercent();
@@ -321,10 +319,7 @@ bool SVGImage::hasRelativeWidth() const
bool SVGImage::hasRelativeHeight() const
{
- if (!m_page)
- return false;
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement)
return false;
return rootElement->intrinsicHeight().isPercent();
@@ -332,10 +327,7 @@ bool SVGImage::hasRelativeHeight() const
void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
{
- if (!m_page)
- return;
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement)
return;
@@ -352,10 +344,7 @@ void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrin
// FIXME: support catchUpIfNecessary.
void SVGImage::startAnimation(bool /* catchUpIfNecessary */)
{
- if (!m_page)
- return;
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement || !rootElement->animationsPaused())
return;
rootElement->unpauseAnimations();
@@ -363,10 +352,7 @@ void SVGImage::startAnimation(bool /* catchUpIfNecessary */)
void SVGImage::stopAnimation()
{
- if (!m_page)
- return;
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement)
return;
rootElement->pauseAnimations();
@@ -374,10 +360,7 @@ void SVGImage::stopAnimation()
void SVGImage::resetAnimation()
{
- if (!m_page)
- return;
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement)
return;
rootElement->pauseAnimations();
@@ -386,13 +369,10 @@ void SVGImage::resetAnimation()
bool SVGImage::hasAnimations() const
{
- if (!m_page)
- return false;
- LocalFrame* frame = m_page->mainFrame();
- SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
+ SVGSVGElement* rootElement = svgRootElement(m_page.get());
if (!rootElement)
return false;
- return rootElement->timeContainer()->hasAnimations() || frame->document()->timeline().hasPendingUpdates();
+ return rootElement->timeContainer()->hasAnimations() || m_page->mainFrame()->document()->timeline().hasPendingUpdates();
}
bool SVGImage::dataChanged(bool allDataReceived)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698