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

Unified Diff: Source/core/html/track/vtt/VTTCue.cpp

Issue 1240433007: Separate VTTCue from VTTCueBox and LayoutVTTCue (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: empty constructor, explicit keyword Created 5 years, 5 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 | « Source/core/html/track/vtt/VTTCue.h ('k') | Source/core/layout/LayoutVTTCue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/track/vtt/VTTCue.cpp
diff --git a/Source/core/html/track/vtt/VTTCue.cpp b/Source/core/html/track/vtt/VTTCue.cpp
index 0a273bc84e4205bb80cd4b0201837f74c97dfa15..65111427675869134b04467afa3276760599e2c0 100644
--- a/Source/core/html/track/vtt/VTTCue.cpp
+++ b/Source/core/html/track/vtt/VTTCue.cpp
@@ -145,22 +145,18 @@ static void setInlineStylePropertyIfNotEmpty(Element& element,
element.setInlineStyleProperty(propertyID, value);
}
-VTTCueBox::VTTCueBox(Document& document, VTTCue* cue)
+VTTCueBox::VTTCueBox(Document& document)
: HTMLDivElement(document)
- , m_cue(cue)
+ , m_snapToLinesPosition(std::numeric_limits<float>::quiet_NaN())
{
setShadowPseudoId(AtomicString("-webkit-media-text-track-display", AtomicString::ConstructFromLiteral));
}
void VTTCueBox::applyCSSProperties(const VTTDisplayParameters& displayParameters)
{
- // FIXME: Apply all the initial CSS positioning properties. http://wkb.ug/79916
- if (!m_cue->regionId().isEmpty()) {
- setInlineStyleProperty(CSSPropertyPosition, CSSValueRelative);
- return;
- }
+ // http://dev.w3.org/html5/webvtt/#applying-css-properties-to-webvtt-node-objects
- // 3.5.1 On the (root) List of WebVTT Node Objects:
+ // Initialize the (root) list of WebVTT Node Objects with the following CSS settings:
// the 'position' property must be set to 'absolute'
setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
@@ -183,7 +179,7 @@ void VTTCueBox::applyCSSProperties(const VTTDisplayParameters& displayParameters
setInlineStyleProperty(CSSPropertyLeft, position.x(), CSSPrimitiveValue::CSS_PERCENTAGE);
// the 'width' property must be set to width, and the 'height' property must be set to height
- if (m_cue->vertical() == horizontalKeyword()) {
+ if (displayParameters.writingMode == CSSValueHorizontalTb) {
setInlineStyleProperty(CSSPropertyWidth, displayParameters.size, CSSPrimitiveValue::CSS_PERCENTAGE);
setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto);
} else {
@@ -195,9 +191,12 @@ void VTTCueBox::applyCSSProperties(const VTTDisplayParameters& displayParameters
// be set to the value in the second cell of the row of the table below
// whose first cell is the value of the corresponding cue's text track cue
// alignment:
- setInlineStyleProperty(CSSPropertyTextAlign, displayAlignmentMap[m_cue->cueAlignment()]);
+ setInlineStyleProperty(CSSPropertyTextAlign, displayParameters.textAlign);
- if (!m_cue->snapToLines()) {
+ // TODO(philipj): The position adjustment for non-snap-to-lines cues has
+ // been removed from the spec:
+ // https://www.w3.org/Bugs/Public/show_bug.cgi?id=19178
+ if (std::isnan(displayParameters.snapToLinesPosition)) {
// 10.13.1 Set up x and y:
// Note: x and y are set through the CSS left and top above.
@@ -213,17 +212,21 @@ void VTTCueBox::applyCSSProperties(const VTTDisplayParameters& displayParameters
setInlineStyleProperty(CSSPropertyWhiteSpace, CSSValuePre);
}
-}
-LayoutObject* VTTCueBox::createLayoutObject(const ComputedStyle&)
-{
- return new LayoutVTTCue(this);
+ // The snap-to-lines position is propagated to LayoutVTTCue.
+ m_snapToLinesPosition = displayParameters.snapToLinesPosition;
}
-DEFINE_TRACE(VTTCueBox)
+LayoutObject* VTTCueBox::createLayoutObject(const ComputedStyle& style)
{
- visitor->trace(m_cue);
- HTMLDivElement::trace(visitor);
+ // If WebVTT Regions are used, the regular WebVTT layout algorithm is no
+ // longer necessary, since cues having the region parameter set do not have
+ // any positioning parameters. Also, in this case, the regions themselves
+ // have positioning information.
+ if (style.position() == RelativePosition)
+ return HTMLDivElement::createLayoutObject(style);
+
+ return new LayoutVTTCue(this, m_snapToLinesPosition);
}
VTTCue::VTTCue(Document& document, double startTime, double endTime, const String& text)
@@ -245,15 +248,6 @@ VTTCue::VTTCue(Document& document, double startTime, double endTime, const Strin
VTTCue::~VTTCue()
{
- // Using oilpan, if m_displayTree is in the document it will strongly keep
- // the cue alive. Thus, if the cue is dead, either m_displayTree is not in
- // the document or the entire document is dead too.
-#if !ENABLE(OILPAN)
- // FIXME: This is scary, we should make the life cycle smarter so the destructor
- // doesn't need to do DOM mutations.
- if (m_displayTree)
- m_displayTree->remove(ASSERT_NO_EXCEPTION);
-#endif
}
#ifndef NDEBUG
@@ -645,19 +639,26 @@ VTTCue::CueAlignment VTTCue::calculateComputedCueAlignment() const
VTTDisplayParameters::VTTDisplayParameters()
: size(std::numeric_limits<float>::quiet_NaN())
, direction(CSSValueNone)
- , writingMode(CSSValueNone) { }
+ , textAlign(CSSValueNone)
+ , writingMode(CSSValueNone)
+ , snapToLinesPosition(std::numeric_limits<float>::quiet_NaN()) { }
VTTDisplayParameters VTTCue::calculateDisplayParameters() const
{
// http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings
VTTDisplayParameters displayParameters;
+
// Steps 1 and 2.
displayParameters.direction = determineTextDirection(m_vttNodeTree.get());
if (displayParameters.direction == CSSValueRtl)
UseCounter::count(document(), UseCounter::VTTCueRenderRtl);
+ // Note: The 'text-align' property is also determined here so that
+ // VTTCueBox::applyCSSProperties need not have access to a VTTCue.
+ displayParameters.textAlign = displayAlignmentMap[cueAlignment()];
+
// 3. If the text track cue writing direction is horizontal, then let
// block-flow be 'tb'. Otherwise, if the text track cue writing direction is
// vertical growing left, then let block-flow be 'lr'. Otherwise, the text
@@ -747,6 +748,11 @@ VTTDisplayParameters VTTCue::calculateDisplayParameters() const
// Step 9 not implemented (margin == 0).
+ // The snap-to-lines position is propagated to LayoutVTTCue.
+ displayParameters.snapToLinesPosition = m_snapToLines
+ ? computedLinePosition
+ : std::numeric_limits<float>::quiet_NaN();
+
ASSERT(std::isfinite(displayParameters.size));
ASSERT(displayParameters.direction != CSSValueNone);
ASSERT(displayParameters.writingMode != CSSValueNone);
@@ -800,7 +806,7 @@ PassRefPtrWillBeRawPtr<VTTCueBox> VTTCue::getDisplayTree()
ASSERT(track() && track()->isRendered() && isActive());
if (!m_displayTree) {
- m_displayTree = VTTCueBox::create(document(), this);
+ m_displayTree = VTTCueBox::create(document());
m_displayTree->appendChild(m_cueBackgroundBox);
}
@@ -819,8 +825,15 @@ PassRefPtrWillBeRawPtr<VTTCueBox> VTTCue::getDisplayTree()
m_cueBackgroundBox->removeChildren();
m_vttNodeTree->cloneChildNodes(m_cueBackgroundBox.get());
- VTTDisplayParameters displayParameters = calculateDisplayParameters();
- m_displayTree->applyCSSProperties(displayParameters);
+ // TODO(philipj): The region identifier may be non-empty without there being
+ // a corresponding region, in which case this VTTCueBox will be added
+ // directly to the text track container in updateDisplay().
+ if (regionId().isEmpty()) {
+ VTTDisplayParameters displayParameters = calculateDisplayParameters();
+ m_displayTree->applyCSSProperties(displayParameters);
+ } else {
+ m_displayTree->setInlineStyleProperty(CSSPropertyPosition, CSSValueRelative);
+ }
// Apply user override settings for text tracks
applyUserOverrideCSSProperties();
« no previous file with comments | « Source/core/html/track/vtt/VTTCue.h ('k') | Source/core/layout/LayoutVTTCue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698