diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2013-09-13 12:51:20 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-19 20:50:05 +0200 |
commit | d441d6f39bb846989d95bcf5caf387b42414718d (patch) | |
tree | e367e64a75991c554930278175d403c072de6bb8 /Source/WebCore/rendering/RenderTextTrackCue.cpp | |
parent | 0060b2994c07842f4c59de64b5e3e430525c4b90 (diff) | |
download | qtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz |
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit.
Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WebCore/rendering/RenderTextTrackCue.cpp')
-rw-r--r-- | Source/WebCore/rendering/RenderTextTrackCue.cpp | 154 |
1 files changed, 142 insertions, 12 deletions
diff --git a/Source/WebCore/rendering/RenderTextTrackCue.cpp b/Source/WebCore/rendering/RenderTextTrackCue.cpp index 4e9dc1552..fd88b77ad 100644 --- a/Source/WebCore/rendering/RenderTextTrackCue.cpp +++ b/Source/WebCore/rendering/RenderTextTrackCue.cpp @@ -30,12 +30,14 @@ #include "RenderTextTrackCue.h" #include "TextTrackCue.h" +#include "TextTrackCueGeneric.h" +#include <wtf/StackStats.h> namespace WebCore { -RenderTextTrackCue::RenderTextTrackCue(TextTrackCueBox* node) - : RenderBlock(static_cast<Node*>(node)) - , m_cue(node->getCue()) +RenderTextTrackCue::RenderTextTrackCue(TextTrackCueBox* element) + : RenderBlock(element) + , m_cue(element->getCue()) { } @@ -45,10 +47,15 @@ void RenderTextTrackCue::layout() RenderBlock::layout(); LayoutStateMaintainer statePusher(view(), this, locationOffset(), hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode()); - if (m_cue->snapToLines()) - repositionCueSnapToLinesSet(); - else - repositionCueSnapToLinesNotSet(); + + if (m_cue->cueType()== TextTrackCue::WebVTT) { + if (m_cue->snapToLines()) + repositionCueSnapToLinesSet(); + else + repositionCueSnapToLinesNotSet(); + } else + repositionGenericCue(); + statePusher.pop(); } @@ -117,19 +124,35 @@ void RenderTextTrackCue::placeBoxInDefaultPosition(LayoutUnit position, bool& sw bool RenderTextTrackCue::isOutside() const { - return !containingBlock()->absoluteBoundingBoxRect().contains(absoluteBoundingBoxRect()); + return !rectIsWithinContainer(absoluteContentBox()); +} + +bool RenderTextTrackCue::rectIsWithinContainer(const IntRect& rect) const +{ + return containingBlock()->absoluteBoundingBoxRect().contains(rect); } + bool RenderTextTrackCue::isOverlapping() const { + return overlappingObject(); +} + +RenderObject* RenderTextTrackCue::overlappingObject() const +{ + return overlappingObjectForRect(absoluteBoundingBoxRect()); +} + +RenderObject* RenderTextTrackCue::overlappingObjectForRect(const IntRect& rect) const +{ for (RenderObject* box = previousSibling(); box; box = box->previousSibling()) { IntRect boxRect = box->absoluteBoundingBoxRect(); - if (absoluteBoundingBoxRect().intersects(boxRect)) - return true; + if (rect.intersects(boxRect)) + return box; } - return false; + return 0; } bool RenderTextTrackCue::shouldSwitchDirection(InlineFlowBox* firstLineBox, LayoutUnit step) const @@ -195,6 +218,76 @@ bool RenderTextTrackCue::switchDirection(bool& switched, LayoutUnit& step) return true; } +void RenderTextTrackCue::moveIfNecessaryToKeepWithinContainer() +{ + IntRect containerRect = containingBlock()->absoluteBoundingBoxRect(); + IntRect cueRect = absoluteBoundingBoxRect(); + + int topOverflow = cueRect.y() - containerRect.y(); + int bottomOverflow = containerRect.maxY() - cueRect.maxY(); + + int verticalAdjustment = 0; + if (topOverflow < 0) + verticalAdjustment = -topOverflow; + else if (bottomOverflow < 0) + verticalAdjustment = bottomOverflow; + + if (verticalAdjustment) + setY(y() + verticalAdjustment); + + int leftOverflow = cueRect.x() - containerRect.x(); + int rightOverflow = containerRect.maxX() - cueRect.maxX(); + + int horizontalAdjustment = 0; + if (leftOverflow < 0) + horizontalAdjustment = -leftOverflow; + else if (rightOverflow < 0) + horizontalAdjustment = rightOverflow; + + if (horizontalAdjustment) + setX(x() + horizontalAdjustment); +} + +bool RenderTextTrackCue::findNonOverlappingPosition(int& newX, int& newY) const +{ + newX = x(); + newY = y(); + IntRect srcRect = absoluteBoundingBoxRect(); + IntRect destRect = srcRect; + + // Move the box up, looking for a non-overlapping position: + while (RenderObject* box = overlappingObjectForRect(destRect)) { + if (m_cue->getWritingDirection() == TextTrackCue::Horizontal) + destRect.setY(box->absoluteBoundingBoxRect().y() - destRect.height()); + else + destRect.setX(box->absoluteBoundingBoxRect().x() - destRect.width()); + } + + if (rectIsWithinContainer(destRect)) { + newX += destRect.x() - srcRect.x(); + newY += destRect.y() - srcRect.y(); + return true; + } + + destRect = srcRect; + + // Move the box down, looking for a non-overlapping position: + while (RenderObject* box = overlappingObjectForRect(destRect)) { + if (m_cue->getWritingDirection() == TextTrackCue::Horizontal) + destRect.setY(box->absoluteBoundingBoxRect().maxY()); + else + destRect.setX(box->absoluteBoundingBoxRect().maxX()); + } + + if (rectIsWithinContainer(destRect)) { + newX += destRect.x() - srcRect.x(); + newY += destRect.y() - srcRect.y(); + return true; + } + + return false; +} + void RenderTextTrackCue::repositionCueSnapToLinesSet() { InlineFlowBox* firstLineBox; @@ -219,11 +312,48 @@ void RenderTextTrackCue::repositionCueSnapToLinesSet() // 19. Jump back to the step labeled step loop. } + + // Acommodate extra top and bottom padding, border or margin. + // Note: this is supported only for internal UA styling, not through the cue selector. + if (hasInlineDirectionBordersPaddingOrMargin()) + moveIfNecessaryToKeepWithinContainer(); +} + +void RenderTextTrackCue::repositionGenericCue() +{ + ASSERT(firstChild()); + InlineFlowBox* firstLineBox = toRenderInline(firstChild())->firstLineBox(); + if (static_cast<TextTrackCueGeneric*>(m_cue)->useDefaultPosition() && firstLineBox) { + LayoutUnit parentWidth = containingBlock()->logicalWidth(); + LayoutUnit width = firstLineBox->width(); + LayoutUnit right = (parentWidth / 2) - (width / 2); + setX(right); + } + repositionCueSnapToLinesNotSet(); } void RenderTextTrackCue::repositionCueSnapToLinesNotSet() { - // FIXME: Implement overlapping detection when snap-to-lines is not set. http://wkb.ug/84296 + // 3. If none of the boxes in boxes would overlap any of the boxes in output, and all the boxes in + // output are within the video's rendering area, then jump to the step labeled done positioning below. + if (!isOutside() && !isOverlapping()) + return; + + // 4. If there is a position to which the boxes in boxes can be moved while maintaining the relative + // positions of the boxes in boxes to each other such that none of the boxes in boxes would overlap + // any of the boxes in output, and all the boxes in output would be within the video's rendering area, + // then move the boxes in boxes to the closest such position to their current position, and then jump + // to the step labeled done positioning below. If there are multiple such positions that are equidistant + // from their current position, use the highest one amongst them; if there are several at that height, + // then use the leftmost one amongst them. + moveIfNecessaryToKeepWithinContainer(); + int x = 0; + int y = 0; + if (!findNonOverlappingPosition(x, y)) + return; + + setX(x); + setY(y); } } // namespace WebCore |