Changeset 172224 in webkit


Ignore:
Timestamp:
Aug 7, 2014 12:34:10 PM (10 years ago)
Author:
roger_fong@apple.com
Message:

Increase width of caption container if a larger font size is selected from user prefs.
https://bugs.webkit.org/show_bug.cgi?id=135677.

Reviewed by Brent Fulgham.

  • html/shadow/MediaControlElements.cpp:

(WebCore::MediaControlTextTrackContainerElement::updateDisplay):
Upon creation of a VTTCueBox make sure to supply the font size set by the user prefs.

  • html/track/TextTrackCueGeneric.cpp:

(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties):
Increase the width of the cue box based on user prefs font size selection.

  • html/track/VTTCue.h:

Keep track of the font size set in the user prefs for use when the cue boxes are created.
(WebCore::VTTCueBox::setFontSizeFromCaptionUserPrefs):

  • html/track/VTTCue.cpp:

(WebCore::VTTCueBox::applyCSSProperties):
Increase the width of the cue box based on user prefs font size selection.
(WebCore::VTTCue::getDisplayTree):
(WebCore::VTTCue::setFontSize):
If the font size set is important then we don't want to use the font size set by user prefs, set it to 0.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r172221 r172224  
     12014-08-06  Roger Fong  <roger_fong@apple.com>
     2
     3        Increase width of caption container if a larger font size is selected from user prefs.
     4        https://bugs.webkit.org/show_bug.cgi?id=135677.
     5
     6        Reviewed by Brent Fulgham.
     7
     8        * html/shadow/MediaControlElements.cpp:
     9        (WebCore::MediaControlTextTrackContainerElement::updateDisplay):
     10        Upon creation of a VTTCueBox make sure to supply the font size set by the user prefs.
     11        * html/track/TextTrackCueGeneric.cpp:
     12        (WebCore::TextTrackCueGenericBoxElement::applyCSSProperties):
     13        Increase the width of the cue box based on user prefs font size selection.
     14
     15        * html/track/VTTCue.h:
     16        Keep track of the font size set in the user prefs for use when the cue boxes are created.
     17        (WebCore::VTTCueBox::setFontSizeFromCaptionUserPrefs):
     18        * html/track/VTTCue.cpp:
     19        (WebCore::VTTCueBox::applyCSSProperties):
     20        Increase the width of the cue box based on user prefs font size selection.
     21        (WebCore::VTTCue::getDisplayTree):
     22        (WebCore::VTTCue::setFontSize):
     23        If the font size set is important then we don't want to use the font size set by user prefs, set it to 0.
     24
    1252014-08-07  Alex Christensen  <achristensen@webkit.org>
    226
  • trunk/Source/WebCore/html/shadow/MediaControlElements.cpp

    r172213 r172224  
    11801180        LOG(Media, "MediaControlTextTrackContainerElement::updateDisplay(%p) - adding and positioning cue #%zu: \"%s\", start=%.2f, end=%.2f, line=%.2f", this, i, cue->text().utf8().data(), cue->startTime(), cue->endTime(), cue->line());
    11811181
    1182         RefPtr<VTTCueBox> displayBox = cue->getDisplayTree(m_videoDisplaySize.size());
     1182        RefPtr<VTTCueBox> displayBox = cue->getDisplayTree(m_videoDisplaySize.size(), m_fontSize);
    11831183#if ENABLE(WEBVTT_REGIONS)
    11841184        if (cue->track()->mode() == TextTrack::disabledKeyword())
  • trunk/Source/WebCore/html/track/TextTrackCueGeneric.cpp

    r172213 r172224  
    3131
    3232#include "CSSPropertyNames.h"
     33#include "CSSStyleDeclaration.h"
    3334#include "CSSValueKeywords.h"
    3435#include "HTMLNames.h"
     
    3839#include "RenderObject.h"
    3940#include "ScriptExecutionContext.h"
     41#include "StyleProperties.h"
    4042#include "TextTrackCue.h"
     43#include <wtf/MathExtras.h>
    4144
    4245namespace WebCore {
     
    7679        setInlineStyleProperty(CSSPropertyTop, static_cast<float>(cue->line()), CSSPrimitiveValue::CSS_PERCENTAGE);
    7780
     81        float authorFontSize = std::max(VTTCueBox::DEFAULTFONTSIZE, static_cast<float>(videoSize.height() * cue->baseFontSizeRelativeToVideoHeight() / 100));
     82        if (cue->fontSizeMultiplier())
     83            authorFontSize *= cue->fontSizeMultiplier() / 100;
     84
     85        float multiplier = std::max(1.0f, m_fontSizeFromCaptionUserPrefs / authorFontSize);
    7886        if (cue->getWritingDirection() == VTTCue::Horizontal)
    79             setInlineStyleProperty(CSSPropertyWidth, size, CSSPrimitiveValue::CSS_PERCENTAGE);
     87            setInlineStyleProperty(CSSPropertyWidth, size * multiplier, CSSPrimitiveValue::CSS_PERCENTAGE);
    8088        else
    81             setInlineStyleProperty(CSSPropertyHeight, size,  CSSPrimitiveValue::CSS_PERCENTAGE);
    82     }
    83 
    84     if (cue->getWritingDirection() == VTTCue::Horizontal)
     89            setInlineStyleProperty(CSSPropertyHeight, size * multiplier,  CSSPrimitiveValue::CSS_PERCENTAGE);
     90    }
     91
     92    std::pair<float, float> position = m_cue.getCSSPosition();
     93    if (cue->getWritingDirection() == VTTCue::Horizontal) {
    8594        setInlineStyleProperty(CSSPropertyMinWidth, "-webkit-min-content");
    86     else
     95        double maxWidth = videoSize.width() * (100.0 - position.first) / 100.0;
     96        setInlineStyleProperty(CSSPropertyMaxWidth, maxWidth, CSSPrimitiveValue::CSS_PX);
     97    } else {
    8798        setInlineStyleProperty(CSSPropertyMinHeight, "-webkit-min-content");
     99        double maxHeight = videoSize.height() * (100.0 - position.second) / 100.0;
     100        setInlineStyleProperty(CSSPropertyMaxHeight, maxHeight, CSSPrimitiveValue::CSS_PX);
     101    }
    88102
    89103    if (cue->foregroundColor().isValid())
  • trunk/Source/WebCore/html/track/VTTCue.cpp

    r171158 r172224  
    139139}
    140140
    141 void VTTCueBox::applyCSSProperties(const IntSize&)
     141void VTTCueBox::applyCSSProperties(const IntSize& videoSize)
    142142{
    143143    // FIXME: Apply all the initial CSS positioning properties. http://wkb.ug/79916
     
    171171    setInlineStyleProperty(CSSPropertyLeft, static_cast<double>(position.first), CSSPrimitiveValue::CSS_PERCENTAGE);
    172172
     173    float multiplier = std::max(1.0f, m_fontSizeFromCaptionUserPrefs / VTTCueBox::DEFAULTFONTSIZE);
    173174    // the 'width' property must be set to width, and the 'height' property  must be set to height
    174175    if (m_cue.vertical() == horizontalKeyword()) {
    175         setInlineStyleProperty(CSSPropertyWidth, static_cast<double>(m_cue.getCSSSize()), CSSPrimitiveValue::CSS_PERCENTAGE);
     176        setInlineStyleProperty(CSSPropertyWidth, static_cast<double>(m_cue.getCSSSize() * multiplier), CSSPrimitiveValue::CSS_PERCENTAGE);
    176177        setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto);
    177178        setInlineStyleProperty(CSSPropertyMinWidth, "-webkit-min-content");
     179        double maxWidth = videoSize.width() * (100.0 - position.first) / 100.0;
     180        setInlineStyleProperty(CSSPropertyMaxWidth, maxWidth, CSSPrimitiveValue::CSS_PX);
    178181    } else {
    179182        setInlineStyleProperty(CSSPropertyWidth, CSSValueAuto);
    180         setInlineStyleProperty(CSSPropertyHeight, static_cast<double>(m_cue.getCSSSize()),  CSSPrimitiveValue::CSS_PERCENTAGE);
     183        setInlineStyleProperty(CSSPropertyHeight, static_cast<double>(m_cue.getCSSSize() * multiplier),  CSSPrimitiveValue::CSS_PERCENTAGE);
    181184        setInlineStyleProperty(CSSPropertyMinHeight, "-webkit-min-content");
     185        double maxHeight = videoSize.height() * (100.0 - position.second) / 100.0;
     186        setInlineStyleProperty(CSSPropertyMaxHeight, maxHeight, CSSPrimitiveValue::CSS_PX);
    182187    }
    183188
     
    187192    // alignment:
    188193    setInlineStyleProperty(CSSPropertyTextAlign, m_cue.getCSSAlignment());
    189 
     194   
    190195    if (!m_cue.snapToLines()) {
    191196        // 10.13.1 Set up x and y:
     
    778783}
    779784
    780 VTTCueBox* VTTCue::getDisplayTree(const IntSize& videoSize)
     785VTTCueBox* VTTCue::getDisplayTree(const IntSize& videoSize, int fontSize)
    781786{
    782787    RefPtr<VTTCueBox> displayTree = displayTreeInternal();
     
    809814    // 'display' property has the value 'ruby-base'.
    810815
    811     // FIXME(BUG 79916): Text runs must be wrapped according to the CSS
    812     // line-wrapping rules, except that additionally, regardless of the value of
    813     // the 'white-space' property, lines must be wrapped at the edge of their
    814     // containing blocks, even if doing so requires splitting a word where there
    815     // is no line breaking opportunity. (Thus, normally text wraps as needed,
    816     // but if there is a particularly long word, it does not overflow as it
    817     // normally would in CSS, it is instead forcibly wrapped at the box's edge.)
     816    displayTree->setFontSizeFromCaptionUserPrefs(fontSize);
    818817    displayTree->applyCSSProperties(videoSize);
    819818
     
    11441143    LOG(Media, "TextTrackCue::setFontSize - setting cue font size to %i", fontSize);
    11451144
     1145    if (important)
     1146        displayTreeInternal()->setFontSizeFromCaptionUserPrefs(0);
     1147   
    11461148    displayTreeInternal()->setInlineStyleProperty(CSSPropertyFontSize, fontSize, CSSPrimitiveValue::CSS_PX, important);
    11471149}
  • trunk/Source/WebCore/html/track/VTTCue.h

    r171004 r172224  
    6060
    6161    static const AtomicString& vttCueBoxShadowPseudoId();
     62    virtual void setFontSizeFromCaptionUserPrefs(int fontSize) { m_fontSizeFromCaptionUserPrefs = fontSize; }
    6263
    6364protected:
     
    6768
    6869    VTTCue& m_cue;
     70    int m_fontSizeFromCaptionUserPrefs;
     71
     72    static const float DEFAULTFONTSIZE;
    6973};
     74
     75// This default value must be the same as the one specified in mediaControlsApple.css for -webkit-media-controls-closed-captions-container
     76const float VTTCueBox::DEFAULTFONTSIZE = 10;
    7077
    7178// ----------------------------
     
    116123
    117124    bool hasDisplayTree() const { return m_displayTree; }
    118     VTTCueBox* getDisplayTree(const IntSize& videoSize);
     125    VTTCueBox* getDisplayTree(const IntSize& videoSize, int fontSize);
    119126    HTMLSpanElement* element() const { return m_cueHighlightBox.get(); }
    120127
Note: See TracChangeset for help on using the changeset viewer.