Commit 05aa84ce authored by fs@opera.com's avatar fs@opera.com

Reduce rootElement access boilerplate in SVGImage

Add a helper function 'svgRootElement' and use that where appropriate.

Review URL: https://codereview.chromium.org/208503002

git-svn-id: svn://svn.chromium.org/blink/trunk@169751 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 7402f9c1
...@@ -116,13 +116,20 @@ bool SVGImage::currentFrameHasSingleSecurityOrigin() const ...@@ -116,13 +116,20 @@ bool SVGImage::currentFrameHasSingleSecurityOrigin() const
return true; 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) void SVGImage::setContainerSize(const IntSize& size)
{ {
if (!m_page || !usesContainerSize()) if (!usesContainerSize())
return; return;
LocalFrame* frame = m_page->mainFrame(); SVGSVGElement* rootElement = svgRootElement(m_page.get());
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement) if (!rootElement)
return; return;
...@@ -137,10 +144,7 @@ void SVGImage::setContainerSize(const IntSize& size) ...@@ -137,10 +144,7 @@ void SVGImage::setContainerSize(const IntSize& size)
IntSize SVGImage::containerSize() const IntSize SVGImage::containerSize() const
{ {
if (!m_page) SVGSVGElement* rootElement = svgRootElement(m_page.get());
return IntSize();
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement) if (!rootElement)
return IntSize(); return IntSize();
...@@ -291,10 +295,7 @@ void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl ...@@ -291,10 +295,7 @@ void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl
RenderBox* SVGImage::embeddedContentBox() const RenderBox* SVGImage::embeddedContentBox() const
{ {
if (!m_page) SVGSVGElement* rootElement = svgRootElement(m_page.get());
return 0;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement) if (!rootElement)
return 0; return 0;
return toRenderBox(rootElement->renderer()); return toRenderBox(rootElement->renderer());
...@@ -310,10 +311,7 @@ FrameView* SVGImage::frameView() const ...@@ -310,10 +311,7 @@ FrameView* SVGImage::frameView() const
bool SVGImage::hasRelativeWidth() const bool SVGImage::hasRelativeWidth() const
{ {
if (!m_page) SVGSVGElement* rootElement = svgRootElement(m_page.get());
return false;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement) if (!rootElement)
return false; return false;
return rootElement->intrinsicWidth().isPercent(); return rootElement->intrinsicWidth().isPercent();
...@@ -321,10 +319,7 @@ bool SVGImage::hasRelativeWidth() const ...@@ -321,10 +319,7 @@ bool SVGImage::hasRelativeWidth() const
bool SVGImage::hasRelativeHeight() const bool SVGImage::hasRelativeHeight() const
{ {
if (!m_page) SVGSVGElement* rootElement = svgRootElement(m_page.get());
return false;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement) if (!rootElement)
return false; return false;
return rootElement->intrinsicHeight().isPercent(); return rootElement->intrinsicHeight().isPercent();
...@@ -332,10 +327,7 @@ bool SVGImage::hasRelativeHeight() const ...@@ -332,10 +327,7 @@ bool SVGImage::hasRelativeHeight() const
void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
{ {
if (!m_page) SVGSVGElement* rootElement = svgRootElement(m_page.get());
return;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement) if (!rootElement)
return; return;
...@@ -352,10 +344,7 @@ void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrin ...@@ -352,10 +344,7 @@ void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrin
// FIXME: support catchUpIfNecessary. // FIXME: support catchUpIfNecessary.
void SVGImage::startAnimation(bool /* catchUpIfNecessary */) void SVGImage::startAnimation(bool /* catchUpIfNecessary */)
{ {
if (!m_page) SVGSVGElement* rootElement = svgRootElement(m_page.get());
return;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement || !rootElement->animationsPaused()) if (!rootElement || !rootElement->animationsPaused())
return; return;
rootElement->unpauseAnimations(); rootElement->unpauseAnimations();
...@@ -363,10 +352,7 @@ void SVGImage::startAnimation(bool /* catchUpIfNecessary */) ...@@ -363,10 +352,7 @@ void SVGImage::startAnimation(bool /* catchUpIfNecessary */)
void SVGImage::stopAnimation() void SVGImage::stopAnimation()
{ {
if (!m_page) SVGSVGElement* rootElement = svgRootElement(m_page.get());
return;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement) if (!rootElement)
return; return;
rootElement->pauseAnimations(); rootElement->pauseAnimations();
...@@ -374,10 +360,7 @@ void SVGImage::stopAnimation() ...@@ -374,10 +360,7 @@ void SVGImage::stopAnimation()
void SVGImage::resetAnimation() void SVGImage::resetAnimation()
{ {
if (!m_page) SVGSVGElement* rootElement = svgRootElement(m_page.get());
return;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement) if (!rootElement)
return; return;
rootElement->pauseAnimations(); rootElement->pauseAnimations();
...@@ -386,13 +369,10 @@ void SVGImage::resetAnimation() ...@@ -386,13 +369,10 @@ void SVGImage::resetAnimation()
bool SVGImage::hasAnimations() const bool SVGImage::hasAnimations() const
{ {
if (!m_page) SVGSVGElement* rootElement = svgRootElement(m_page.get());
return false;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement) if (!rootElement)
return false; 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) bool SVGImage::dataChanged(bool allDataReceived)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment