Title: [172421] trunk/Source/WebCore
Revision
172421
Author
[email protected]
Date
2014-08-11 17:13:35 -0700 (Mon, 11 Aug 2014)

Log Message

Adjustments to CueBox CSS Width calculations Part 2.
https://bugs.webkit.org/show_bug.cgi?id=135820
<rdar://problem/17954473>.

Reviewed by Brent Fulgham.

Two adjustments made:
a) The default font size used was incorrect. It is not just 10px, 
but should be based off a percentage of the video size.
b) The top/left CSS property needs to be adjusted appropriately if the cue
is center aligned and we change the cue's size such that the cue remains centered.
* html/track/TextTrackCueGeneric.cpp:
(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties):
* html/track/VTTCue.cpp:
(WebCore::VTTCueBox::applyCSSProperties):
* html/track/VTTCue.h: Remove unnecessary constant.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (172420 => 172421)


--- trunk/Source/WebCore/ChangeLog	2014-08-11 23:41:15 UTC (rev 172420)
+++ trunk/Source/WebCore/ChangeLog	2014-08-12 00:13:35 UTC (rev 172421)
@@ -1,3 +1,22 @@
+2014-08-11  Roger Fong  <[email protected]>
+
+        Adjustments to CueBox CSS Width calculations Part 2.
+        https://bugs.webkit.org/show_bug.cgi?id=135820
+        <rdar://problem/17954473>.
+
+        Reviewed by Brent Fulgham.
+
+        Two adjustments made:
+        a) The default font size used was incorrect. It is not just 10px, 
+        but should be based off a percentage of the video size.
+        b) The top/left CSS property needs to be adjusted appropriately if the cue
+        is center aligned and we change the cue's size such that the cue remains centered.
+        * html/track/TextTrackCueGeneric.cpp:
+        (WebCore::TextTrackCueGenericBoxElement::applyCSSProperties):
+        * html/track/VTTCue.cpp:
+        (WebCore::VTTCueBox::applyCSSProperties):
+        * html/track/VTTCue.h: Remove unnecessary constant.
+
 2014-08-11  Beth Dakin  <[email protected]>
 
         Fixed backgrounds don't paint in blurred inset areas

Modified: trunk/Source/WebCore/html/track/TextTrackCueGeneric.cpp (172420 => 172421)


--- trunk/Source/WebCore/html/track/TextTrackCueGeneric.cpp	2014-08-11 23:41:15 UTC (rev 172420)
+++ trunk/Source/WebCore/html/track/TextTrackCueGeneric.cpp	2014-08-12 00:13:35 UTC (rev 172421)
@@ -44,6 +44,9 @@
 
 namespace WebCore {
 
+// This default value must be the same as the one specified in mediaControlsApple.css for -webkit-media-controls-closed-captions-container
+const static int DEFAULTCAPTIONFONTSIZE = 10;
+
 class TextTrackCueGenericBoxElement final : public VTTCueBox {
 public:
     static PassRefPtr<TextTrackCueGenericBoxElement> create(Document& document, TextTrackCueGeneric& cue)
@@ -70,6 +73,7 @@
     TextTrackCueGeneric* cue = static_cast<TextTrackCueGeneric*>(getCue());
     RefPtr<HTMLSpanElement> cueElement = cue->element();
 
+    CSSValueID alignment = cue->getCSSAlignment();
     float size = static_cast<float>(cue->getCSSSize());
     if (cue->useDefaultPosition()) {
         setInlineStyleProperty(CSSPropertyBottom, 0, CSSPrimitiveValue::CSS_PX);
@@ -78,15 +82,24 @@
         setInlineStyleProperty(CSSPropertyLeft, static_cast<float>(cue->position()), CSSPrimitiveValue::CSS_PERCENTAGE);
         setInlineStyleProperty(CSSPropertyTop, static_cast<float>(cue->line()), CSSPrimitiveValue::CSS_PERCENTAGE);
 
-        double authorFontSize = std::max(DEFAULTCAPTIONFONTSIZE, videoSize.height() * cue->baseFontSizeRelativeToVideoHeight() / 100.0);
+        double authorFontSize = videoSize.height() * cue->baseFontSizeRelativeToVideoHeight() / 100.0;
+        if (!authorFontSize)
+            authorFontSize = DEFAULTCAPTIONFONTSIZE;
+
         if (cue->fontSizeMultiplier())
             authorFontSize *= cue->fontSizeMultiplier() / 100;
 
-        double multiplier = std::max(1.0, m_fontSizeFromCaptionUserPrefs / authorFontSize);
-        if (cue->getWritingDirection() == VTTCue::Horizontal)
-            setInlineStyleProperty(CSSPropertyWidth, std::min(size * multiplier, 100.0), CSSPrimitiveValue::CSS_PERCENTAGE);
-        else
-            setInlineStyleProperty(CSSPropertyHeight, std::min(size * multiplier, 100.0),  CSSPrimitiveValue::CSS_PERCENTAGE);
+        double multiplier = m_fontSizeFromCaptionUserPrefs / authorFontSize;
+        double newCueSize = std::min(size * multiplier, 100.0);
+        if (cue->getWritingDirection() == VTTCue::Horizontal) {
+            setInlineStyleProperty(CSSPropertyWidth, newCueSize, CSSPrimitiveValue::CSS_PERCENTAGE);
+            if ((alignment == CSSValueMiddle || alignment == CSSValueCenter) && multiplier != 1.0)
+                setInlineStyleProperty(CSSPropertyLeft, static_cast<double>(cue->position() - (newCueSize - m_cue.getCSSSize()) / 2), CSSPrimitiveValue::CSS_PERCENTAGE);
+        } else {
+            setInlineStyleProperty(CSSPropertyHeight, newCueSize,  CSSPrimitiveValue::CSS_PERCENTAGE);
+            if ((alignment == CSSValueMiddle || alignment == CSSValueCenter) && multiplier != 1.0)
+                setInlineStyleProperty(CSSPropertyTop, static_cast<double>(cue->line() - (newCueSize - m_cue.getCSSSize()) / 2), CSSPrimitiveValue::CSS_PERCENTAGE);
+        }
     }
 
     std::pair<float, float> position = m_cue.getCSSPosition();

Modified: trunk/Source/WebCore/html/track/VTTCue.cpp (172420 => 172421)


--- trunk/Source/WebCore/html/track/VTTCue.cpp	2014-08-11 23:41:15 UTC (rev 172420)
+++ trunk/Source/WebCore/html/track/VTTCue.cpp	2014-08-12 00:13:35 UTC (rev 172421)
@@ -58,6 +58,9 @@
 
 namespace WebCore {
 
+// This constant should correspond with the percentage returned by CaptionUserPreferences::captionFontSizeScaleAndImportance.
+const static double DEFAULTCAPTIONFONTSIZEPERCENTAGE = 5;
+
 static const int undefinedPosition = -1;
 
 static const CSSValueID displayWritingModeMap[] = {
@@ -138,7 +141,7 @@
     return &m_cue;
 }
 
-void VTTCueBox::applyCSSProperties(const IntSize&)
+void VTTCueBox::applyCSSProperties(const IntSize& videoSize)
 {
     // FIXME: Apply all the initial CSS positioning properties. http://wkb.ug/79916
 #if ENABLE(WEBVTT_REGIONS)
@@ -170,18 +173,28 @@
     // the 'left' property must be set to left
     setInlineStyleProperty(CSSPropertyLeft, static_cast<double>(position.first), CSSPrimitiveValue::CSS_PERCENTAGE);
 
-    double multiplier = std::max(1.0, m_fontSizeFromCaptionUserPrefs / DEFAULTCAPTIONFONTSIZE);
+    double authorFontSize = std::min(videoSize.width(), videoSize.height()) * DEFAULTCAPTIONFONTSIZEPERCENTAGE / 100.0;
+    double multiplier = 1.0;
+    if (authorFontSize)
+        multiplier = m_fontSizeFromCaptionUserPrefs / authorFontSize;
+
+    double newCueSize = std::min(m_cue.getCSSSize() * multiplier, 100.0);
+    CSSValueID alignment = m_cue.getCSSAlignment();
     // the 'width' property must be set to width, and the 'height' property  must be set to height
     if (m_cue.vertical() == horizontalKeyword()) {
-        setInlineStyleProperty(CSSPropertyWidth, std::min(m_cue.getCSSSize() * multiplier, 100.0), CSSPrimitiveValue::CSS_PERCENTAGE);
+        setInlineStyleProperty(CSSPropertyWidth, newCueSize, CSSPrimitiveValue::CSS_PERCENTAGE);
         setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto);
         setInlineStyleProperty(CSSPropertyMinWidth, "-webkit-min-content");
         setInlineStyleProperty(CSSPropertyMaxWidth, 100.0 - position.first, CSSPrimitiveValue::CSS_PERCENTAGE);
+        if ((alignment == CSSValueMiddle || alignment == CSSValueCenter) && multiplier != 1.0)
+            setInlineStyleProperty(CSSPropertyLeft, static_cast<double>(position.first - (newCueSize - m_cue.getCSSSize()) / 2), CSSPrimitiveValue::CSS_PERCENTAGE);
     } else {
         setInlineStyleProperty(CSSPropertyWidth, CSSValueAuto);
-        setInlineStyleProperty(CSSPropertyHeight, std::min(m_cue.getCSSSize() * multiplier, 100.0), CSSPrimitiveValue::CSS_PERCENTAGE);
+        setInlineStyleProperty(CSSPropertyHeight, newCueSize, CSSPrimitiveValue::CSS_PERCENTAGE);
         setInlineStyleProperty(CSSPropertyMinHeight, "-webkit-min-content");
         setInlineStyleProperty(CSSPropertyMaxHeight, 100.0 - position.second, CSSPrimitiveValue::CSS_PERCENTAGE);
+        if ((alignment == CSSValueMiddle || alignment == CSSValueCenter) && multiplier != 1.0)
+            setInlineStyleProperty(CSSPropertyTop, static_cast<double>(position.second - (newCueSize - m_cue.getCSSSize()) / 2), CSSPrimitiveValue::CSS_PERCENTAGE);
     }
 
     // The 'text-align' property on the (root) List of WebVTT Node Objects must

Modified: trunk/Source/WebCore/html/track/VTTCue.h (172420 => 172421)


--- trunk/Source/WebCore/html/track/VTTCue.h	2014-08-11 23:41:15 UTC (rev 172420)
+++ trunk/Source/WebCore/html/track/VTTCue.h	2014-08-12 00:13:35 UTC (rev 172421)
@@ -49,9 +49,6 @@
 class VTTScanner;
 class WebVTTCueData;
 
-// This default value must be the same as the one specified in mediaControlsApple.css for -webkit-media-controls-closed-captions-container
-const static double DEFAULTCAPTIONFONTSIZE = 10;
-
 // ----------------------------
 
 class VTTCueBox : public HTMLElement {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to