Commit 0908653c authored by eric.carlson@apple.com's avatar eric.carlson@apple.com
Browse files

More updates to Caption user preferences

https://bugs.webkit.org/show_bug.cgi?id=108997

Reviewed by Dean Jackson.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::captionPreferencesChanged): Give the media controls a chance
    to update for a preferences change.
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlTextTrackContainerElement::updateSizes): Add optional "force update" 
    param to force font size recalc even when the video size hasn't changed.
* html/shadow/MediaControlElements.h:

* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::textTrackPreferencesChanged): New, force a font size recalc.
* html/shadow/MediaControls.h:

* html/track/TextTrackCueGeneric.cpp:
(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties): Don't set width/size of cues
    that use default positioning. Use "start" as the default alignment.

* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::captionsWindowCSS): Set padding when the window is visible
    so it shows around the cue background.
(WebCore::CaptionUserPreferencesMac::captionsBackgroundCSS): Set padding to 0 when the background
    is visible.
(WebCore::CaptionUserPreferencesMac::windowRoundedCornerRadiusCSS): Add "px" to the border radius
    so it actually works.
* rendering/RenderTextTrackCue.cpp:
(WebCore::RenderTextTrackCue::layout): Special case generic cues with default style.
(WebCore::RenderTextTrackCue::repositionGenericCue):
* rendering/RenderTextTrackCue.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@141966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent aafe4151
2013-02-05 Eric Carlson <eric.carlson@apple.com>
More updates to Caption user preferences
https://bugs.webkit.org/show_bug.cgi?id=108997
Reviewed by Dean Jackson.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::captionPreferencesChanged): Give the media controls a chance
to update for a preferences change.
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlTextTrackContainerElement::updateSizes): Add optional "force update"
param to force font size recalc even when the video size hasn't changed.
* html/shadow/MediaControlElements.h:
* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::textTrackPreferencesChanged): New, force a font size recalc.
* html/shadow/MediaControls.h:
* html/track/TextTrackCueGeneric.cpp:
(WebCore::TextTrackCueGenericBoxElement::applyCSSProperties): Don't set width/size of cues
that use default positioning. Use "start" as the default alignment.
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::captionsWindowCSS): Set padding when the window is visible
so it shows around the cue background.
(WebCore::CaptionUserPreferencesMac::captionsBackgroundCSS): Set padding to 0 when the background
is visible.
(WebCore::CaptionUserPreferencesMac::windowRoundedCornerRadiusCSS): Add "px" to the border radius
so it actually works.
* rendering/RenderTextTrackCue.cpp:
(WebCore::RenderTextTrackCue::layout): Special case generic cues with default style.
(WebCore::RenderTextTrackCue::repositionGenericCue):
* rendering/RenderTextTrackCue.h:
2013-02-05 Hayato Ito <hayato@chromium.org>
 
Split each RuleSet and feature out from StyleResolver into its own class.
......@@ -4374,6 +4374,9 @@ void HTMLMediaElement::captionPreferencesChanged()
if (!isVideo())
return;
if (hasMediaControls())
mediaControls()->textTrackPreferencesChanged();
markCaptionAndSubtitleTracksAsUnconfigured();
}
......
......@@ -1306,7 +1306,7 @@ void MediaControlTextTrackContainerElement::updateDisplay()
}
}
void MediaControlTextTrackContainerElement::updateSizes()
void MediaControlTextTrackContainerElement::updateSizes(bool forceUpdate)
{
HTMLMediaElement* mediaElement = toParentMediaElement(this);
if (!mediaElement)
......@@ -1325,7 +1325,7 @@ void MediaControlTextTrackContainerElement::updateSizes()
videoBox = toRenderVideo(mediaElement->renderer())->videoBox();
}
if (m_videoDisplaySize == videoBox)
if (!forceUpdate && m_videoDisplaySize == videoBox)
return;
m_videoDisplaySize = videoBox;
......
......@@ -438,7 +438,7 @@ public:
static PassRefPtr<MediaControlTextTrackContainerElement> create(Document*);
void updateDisplay();
void updateSizes();
void updateSizes(bool forceUpdate = false);
void createSubtrees(Document*);
private:
......
......@@ -407,6 +407,12 @@ void MediaControls::updateTextTrackDisplay()
m_textDisplayContainer->updateDisplay();
}
void MediaControls::textTrackPreferencesChanged()
{
if (m_textDisplayContainer)
m_textDisplayContainer->updateSizes(true);
}
#endif
}
......
......@@ -106,6 +106,7 @@ class MediaControls : public HTMLDivElement {
virtual void showTextTrackDisplay();
virtual void hideTextTrackDisplay();
virtual void updateTextTrackDisplay();
virtual void textTrackPreferencesChanged();
#endif
protected:
......
......@@ -66,23 +66,24 @@ void TextTrackCueGenericBoxElement::applyCSSProperties(const IntSize& videoSize)
TextTrackCueGeneric* cue = static_cast<TextTrackCueGeneric*>(getCue());
float size = static_cast<float>(cue->getCSSSize());
if (cue->useDefaultPosition()) {
setInlineStyleProperty(CSSPropertyBottom, "0");
setInlineStyleProperty(CSSPropertyMarginBottom, 1.0, CSSPrimitiveValue::CSS_PERCENTAGE);
} else {
setInlineStyleProperty(CSSPropertyLeft, static_cast<float>(cue->position()), CSSPrimitiveValue::CSS_PERCENTAGE);
setInlineStyleProperty(CSSPropertyTop, static_cast<float>(cue->line()), CSSPrimitiveValue::CSS_PERCENTAGE);
if (cue->getWritingDirection() == TextTrackCue::Horizontal)
setInlineStyleProperty(CSSPropertyWidth, size, CSSPrimitiveValue::CSS_PERCENTAGE);
else
setInlineStyleProperty(CSSPropertyHeight, size, CSSPrimitiveValue::CSS_PERCENTAGE);
}
float size = static_cast<float>(cue->getCSSSize());
if (cue->getWritingDirection() == TextTrackCue::Horizontal) {
setInlineStyleProperty(CSSPropertyDirection, CSSValueLtr);
setInlineStyleProperty(CSSPropertyWidth, size, CSSPrimitiveValue::CSS_PERCENTAGE);
if (cue->getWritingDirection() == TextTrackCue::Horizontal)
setInlineStyleProperty(CSSPropertyHeight, CSSValueAuto);
} else {
else
setInlineStyleProperty(CSSPropertyWidth, CSSValueAuto);
setInlineStyleProperty(CSSPropertyHeight, size, CSSPrimitiveValue::CSS_PERCENTAGE);
}
if (cue->baseFontSizeRelativeToVideoHeight()) {
double fontSize = videoSize.height() * cue->baseFontSizeRelativeToVideoHeight() / 100;
......@@ -91,12 +92,12 @@ void TextTrackCueGenericBoxElement::applyCSSProperties(const IntSize& videoSize)
setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px");
}
if (cue->getAlignment() == TextTrackCue::Start)
setInlineStyleProperty(CSSPropertyTextAlign, CSSValueStart);
if (cue->getAlignment() == TextTrackCue::Middle)
setInlineStyleProperty(CSSPropertyTextAlign, CSSValueCenter);
else if (cue->getAlignment() == TextTrackCue::End)
setInlineStyleProperty(CSSPropertyTextAlign, CSSValueEnd);
else
setInlineStyleProperty(CSSPropertyTextAlign, CSSValueCenter);
setInlineStyleProperty(CSSPropertyTextAlign, CSSValueStart);
setInlineStyleProperty(CSSPropertyWebkitWritingMode, cue->getCSSWritingMode(), false);
setInlineStyleProperty(CSSPropertyWhiteSpace, CSSValuePreWrap);
......
......@@ -140,7 +140,20 @@ String CaptionUserPreferencesMac::captionsWindowCSS() const
windowColor = Color::transparent;
CGFloat opacity = MACaptionAppearanceGetWindowOpacity(kMACaptionAppearanceDomainUser, &behavior);
return colorPropertyCSS(CSSPropertyBackgroundColor, Color(windowColor.red(), windowColor.green(), windowColor.blue(), static_cast<int>(opacity * 255)), behavior == kMACaptionAppearanceBehaviorUseValue);
String windowStyle = colorPropertyCSS(CSSPropertyBackgroundColor, Color(windowColor.red(), windowColor.green(), windowColor.blue(), static_cast<int>(opacity * 255)), behavior == kMACaptionAppearanceBehaviorUseValue);
if (!opacity)
return windowStyle;
StringBuilder builder;
builder.append(windowStyle);
builder.append(getPropertyNameString(CSSPropertyPadding));
builder.append(": .2em");
if (behavior == kMACaptionAppearanceBehaviorUseValue)
builder.append(" !important");
builder.append(';');
return builder.toString();
}
String CaptionUserPreferencesMac::captionsBackgroundCSS() const
......@@ -157,7 +170,20 @@ String CaptionUserPreferencesMac::captionsBackgroundCSS() const
backgroundColor = defaultBackgroundColor;
CGFloat opacity = MACaptionAppearanceGetBackgroundOpacity(kMACaptionAppearanceDomainUser, 0);
return colorPropertyCSS(CSSPropertyBackgroundColor, Color(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), static_cast<int>(opacity * 255)), behavior == kMACaptionAppearanceBehaviorUseValue);
String backgroundStyle = colorPropertyCSS(CSSPropertyBackgroundColor, Color(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), static_cast<int>(opacity * 255)), behavior == kMACaptionAppearanceBehaviorUseValue);
if (!opacity)
return backgroundStyle;
StringBuilder builder;
builder.append(backgroundStyle);
builder.append(getPropertyNameString(CSSPropertyPadding));
builder.append(": 0px");
if (behavior == kMACaptionAppearanceBehaviorUseValue)
builder.append(" !important");
builder.append(';');
return builder.toString();
}
Color CaptionUserPreferencesMac::captionsTextColor(bool& important) const
......@@ -194,8 +220,7 @@ String CaptionUserPreferencesMac::windowRoundedCornerRadiusCSS() const
StringBuilder builder;
builder.append(getPropertyNameString(CSSPropertyBorderRadius));
builder.append(':');
builder.append(String::format("%.02f", radius));
builder.append(String::format(":%.02fpx", radius));
if (behavior == kMACaptionAppearanceBehaviorUseValue)
builder.append(" !important");
builder.append(';');
......
......@@ -30,6 +30,7 @@
#include "RenderTextTrackCue.h"
#include "TextTrackCue.h"
#include "TextTrackCueGeneric.h"
namespace WebCore {
......@@ -45,10 +46,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();
}
......@@ -221,6 +227,24 @@ void RenderTextTrackCue::repositionCueSnapToLinesSet()
}
}
void RenderTextTrackCue::repositionGenericCue()
{
TextTrackCueGeneric* cue = static_cast<TextTrackCueGeneric*>(m_cue);
if (!cue->useDefaultPosition())
return;
ASSERT(firstChild());
InlineFlowBox* firstLineBox = toRenderInline(firstChild())->firstLineBox();
if (!firstLineBox)
return;
LayoutUnit parentWidth = containingBlock()->logicalWidth();
LayoutUnit width = firstLineBox->width();
LayoutUnit right = (parentWidth / 2) - (width / 2);
setX(right);
}
void RenderTextTrackCue::repositionCueSnapToLinesNotSet()
{
// FIXME: Implement overlapping detection when snap-to-lines is not set. http://wkb.ug/84296
......
......@@ -54,8 +54,8 @@ private:
bool initializeLayoutParameters(InlineFlowBox*&, LayoutUnit&, LayoutUnit&);
void placeBoxInDefaultPosition(LayoutUnit, bool&);
void repositionCueSnapToLinesSet();
void repositionCueSnapToLinesNotSet();
void repositionGenericCue();
TextTrackCue* m_cue;
FloatPoint m_fallbackPosition;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment