This source file includes following definitions.
- m_direction
- marqueeSpeed
- direction
- isHorizontal
- computePosition
- start
- suspend
- stop
- updateMarqueePosition
- renderName
- styleDidChange
- layoutBlock
- timerFired
#include "config.h"
#include "core/rendering/RenderMarquee.h"
#include "HTMLNames.h"
#include "core/html/HTMLMarqueeElement.h"
#include "core/frame/FrameView.h"
#include "core/frame/UseCounter.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderView.h"
#include "platform/LengthFunctions.h"
using namespace std;
namespace WebCore {
using namespace HTMLNames;
RenderMarquee::RenderMarquee(HTMLMarqueeElement* element)
: RenderBlockFlow(element)
, m_currentLoop(0)
, m_totalLoops(0)
, m_timer(element, &HTMLMarqueeElement::timerFired)
, m_start(0)
, m_end(0)
, m_speed(0)
, m_reset(false)
, m_suspended(false)
, m_stopped(false)
, m_direction(MAUTO)
{
UseCounter::count(document(), UseCounter::HTMLMarqueeElement);
}
RenderMarquee::~RenderMarquee()
{
}
int RenderMarquee::marqueeSpeed() const
{
int result = style()->marqueeSpeed();
if (Node* node = this->node())
result = std::max(result, toHTMLMarqueeElement(node)->minimumDelay());
return result;
}
EMarqueeDirection RenderMarquee::direction() const
{
EMarqueeDirection result = style()->marqueeDirection();
TextDirection dir = style()->direction();
if (result == MAUTO)
result = MBACKWARD;
if (result == MFORWARD)
result = (dir == LTR) ? MRIGHT : MLEFT;
if (result == MBACKWARD)
result = (dir == LTR) ? MLEFT : MRIGHT;
Length increment = style()->marqueeIncrement();
if (increment.isNegative())
result = static_cast<EMarqueeDirection>(-result);
return result;
}
bool RenderMarquee::isHorizontal() const
{
return direction() == MLEFT || direction() == MRIGHT;
}
int RenderMarquee::computePosition(EMarqueeDirection dir, bool stopAtContentEdge)
{
if (isHorizontal()) {
bool ltr = style()->isLeftToRightDirection();
LayoutUnit clientWidth = this->clientWidth();
LayoutUnit contentWidth = ltr ? maxPreferredLogicalWidth() : minPreferredLogicalWidth();
if (ltr)
contentWidth += (paddingRight() - borderLeft());
else {
contentWidth = width() - contentWidth;
contentWidth += (paddingLeft() - borderRight());
}
if (dir == MRIGHT) {
if (stopAtContentEdge)
return max<LayoutUnit>(0, ltr ? (contentWidth - clientWidth) : (clientWidth - contentWidth));
else
return ltr ? contentWidth : clientWidth;
}
else {
if (stopAtContentEdge)
return min<LayoutUnit>(0, ltr ? (contentWidth - clientWidth) : (clientWidth - contentWidth));
else
return ltr ? -clientWidth : -contentWidth;
}
}
else {
int contentHeight = layoutOverflowRect().maxY() - borderTop() + paddingBottom();
int clientHeight = this->clientHeight();
if (dir == MUP) {
if (stopAtContentEdge)
return min(contentHeight - clientHeight, 0);
else
return -clientHeight;
}
else {
if (stopAtContentEdge)
return max(contentHeight - clientHeight, 0);
else
return contentHeight;
}
}
}
void RenderMarquee::start()
{
if (m_timer.isActive() || style()->marqueeIncrement().isZero())
return;
if (!m_suspended && !m_stopped) {
if (isHorizontal())
layer()->scrollableArea()->scrollToOffset(IntSize(m_start, 0));
else
layer()->scrollableArea()->scrollToOffset(IntSize(0, m_start));
} else {
m_suspended = false;
m_stopped = false;
}
m_timer.startRepeating(speed() * 0.001, FROM_HERE);
}
void RenderMarquee::suspend()
{
m_timer.stop();
m_suspended = true;
}
void RenderMarquee::stop()
{
m_timer.stop();
m_stopped = true;
}
void RenderMarquee::updateMarqueePosition()
{
bool activate = (m_totalLoops <= 0 || m_currentLoop < m_totalLoops);
if (activate) {
EMarqueeBehavior behavior = style()->marqueeBehavior();
m_start = computePosition(direction(), behavior == MALTERNATE);
m_end = computePosition(reverseDirection(), behavior == MALTERNATE || behavior == MSLIDE);
if (!m_stopped) {
DisableCompositingQueryAsserts disabler;
start();
}
}
}
const char* RenderMarquee::renderName() const
{
if (isFloating())
return "RenderMarquee (floating)";
if (isOutOfFlowPositioned())
return "RenderMarquee (positioned)";
if (isAnonymous())
return "RenderMarquee (generated)";
if (isRelPositioned())
return "RenderMarquee (relative positioned)";
return "RenderMarquee";
}
void RenderMarquee::styleDidChange(StyleDifference difference, const RenderStyle* oldStyle)
{
RenderBlockFlow::styleDidChange(difference, oldStyle);
RenderStyle* s = style();
if (m_direction != s->marqueeDirection() || (m_totalLoops != s->marqueeLoopCount() && m_currentLoop >= m_totalLoops))
m_currentLoop = 0;
m_totalLoops = s->marqueeLoopCount();
m_direction = s->marqueeDirection();
if (m_totalLoops <= 0 && s->marqueeBehavior() == MSLIDE)
m_totalLoops = 1;
if (isHorizontal() && childrenInline()) {
s->setWhiteSpace(NOWRAP);
s->setTextAlign(TASTART);
}
if (!isHorizontal() && s->height().isAuto())
s->setHeight(Length(200, Fixed));
if (speed() != marqueeSpeed()) {
m_speed = marqueeSpeed();
if (m_timer.isActive())
m_timer.startRepeating(speed() * 0.001, FROM_HERE);
}
bool activate = (m_totalLoops <= 0 || m_currentLoop < m_totalLoops);
if (activate && !m_timer.isActive())
setNeedsLayout();
else if (!activate && m_timer.isActive())
m_timer.stop();
}
void RenderMarquee::layoutBlock(bool relayoutChildren)
{
RenderBlockFlow::layoutBlock(relayoutChildren);
updateMarqueePosition();
}
void RenderMarquee::timerFired()
{
if (view()->needsLayout())
return;
if (m_reset) {
m_reset = false;
if (isHorizontal())
layer()->scrollableArea()->scrollToXOffset(m_start);
else
layer()->scrollableArea()->scrollToYOffset(m_start);
return;
}
RenderStyle* s = style();
int endPoint = m_end;
int range = m_end - m_start;
int newPos;
if (range == 0)
newPos = m_end;
else {
bool addIncrement = direction() == MUP || direction() == MLEFT;
bool isReversed = s->marqueeBehavior() == MALTERNATE && m_currentLoop % 2;
if (isReversed) {
endPoint = m_start;
range = -range;
addIncrement = !addIncrement;
}
bool positive = range > 0;
int clientSize = (isHorizontal() ? clientWidth() : clientHeight());
int increment = abs(intValueForLength(style()->marqueeIncrement(), clientSize));
int currentPos = (isHorizontal() ? layer()->scrollableArea()->scrollXOffset() : layer()->scrollableArea()->scrollYOffset());
newPos = currentPos + (addIncrement ? increment : -increment);
if (positive)
newPos = min(newPos, endPoint);
else
newPos = max(newPos, endPoint);
}
if (newPos == endPoint) {
m_currentLoop++;
if (m_totalLoops > 0 && m_currentLoop >= m_totalLoops)
m_timer.stop();
else if (s->marqueeBehavior() != MALTERNATE)
m_reset = true;
}
if (isHorizontal())
layer()->scrollableArea()->scrollToXOffset(newPos);
else
layer()->scrollableArea()->scrollToYOffset(newPos);
}
}