Ejemplo n.º 1
0
void LayoutVTTCue::layout()
{
    LayoutBlockFlow::layout();

    // 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 (!m_cue->regionId().isEmpty())
        return;

    ASSERT(firstChild());

    LayoutState state(*this, locationOffset());

    // Determine the area covered by the media controls, if any. If the controls
    // are present, they are the next sibling of the text track container, which
    // is our parent. (LayoutMedia ensures that the media controls are laid out
    // before text tracks, so that the layout is up-to-date here.)
    ASSERT(parent()->node()->isTextTrackContainer());
    IntRect controlsRect;
    if (LayoutObject* parentSibling = parent()->nextSibling()) {
        // Only a part of the media controls is used for overlap avoidance.
        MediaControls* controls = toMediaControls(parentSibling->node());
        if (LayoutObject* controlsLayout = controls->layoutObjectForTextTrackLayout())
            controlsRect = controlsLayout->absoluteBoundingBoxRect();
    }

    // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings - step 13.
    if (m_cue->snapToLines()) {
        SnapToLinesLayouter(*this, controlsRect, m_cue->calculateComputedLinePosition()).layout();

        adjustForTopAndBottomMarginBorderAndPadding();
    } else {
        repositionCueSnapToLinesNotSet();
    }
}
Ejemplo n.º 2
0
IntRect LayoutVTTCue::computeControlsRect() const {
  // Determine the area covered by the media controls, if any. If the controls
  // are present, they are the next sibling of the text track container, which
  // is our parent. (LayoutMedia ensures that the media controls are laid out
  // before text tracks, so that the layout is up to date here.)
  DCHECK(parent()->node()->isTextTrackContainer());
  LayoutObject* controlsContainer = parent()->nextSibling();
  if (!controlsContainer)
    return IntRect();
  // Only a part of the media controls is used for overlap avoidance.
  MediaControls* controls = toMediaControls(controlsContainer->node());
  LayoutObject* controlsLayout = controls->layoutObjectForTextTrackLayout();
  // The (second part of the) following is mostly defensive - in general
  // there should be a LayoutBox representing the part of the controls that
  // are relevant for overlap avoidance. (The controls pseudo elements are
  // generally reachable from outside the shadow tree though, hence the
  // "mostly".)
  if (!controlsLayout || !controlsLayout->isBox())
    return IntRect();
  // Assume that the controls container are positioned in the same relative
  // position as the text track container. (LayoutMedia::layout ensures this.)
  return contentBoxRelativeToAncestor(toLayoutBox(*controlsLayout),
                                      toLayoutBox(*controlsContainer));
}