Commit bda228c6 authored by eric@webkit.org's avatar eric@webkit.org

2010-02-03 Nicholas Young <nicholas.young@nokia.com>

        Reviewed by Eric Carlson.

        Defer formatting of times displayed on media controls to the current theme.
        https://bugs.webkit.org/show_bug.cgi?id=34405

        No new tests needed. Refactoring Only.

        * rendering/MediaControlElements.cpp: Removed formatTime()
        (WebCore::MediaControlTimeDisplayElement::setCurrentValue): No longer sets inner text
        * rendering/MediaControlElements.h:
        * rendering/RenderMedia.cpp:
        (WebCore::RenderMedia::updateTimeDisplay): Asks the theme to format the time display elements
        * rendering/RenderTheme.cpp:
        (WebCore::RenderTheme::formatMediaControlsTime): new virtual method
        (WebCore::RenderTheme::formatMediaControlsCurrentTime): new virtual method
        (WebCore::RenderTheme::formatMediaControlsRemainingTime): new virtual method
        * rendering/RenderTheme.h:

git-svn-id: svn://svn.chromium.org/blink/trunk@54326 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent de487704
2010-02-03 Nicholas Young <nicholas.young@nokia.com>
Reviewed by Eric Carlson.
Defer formatting of times displayed on media controls to the current theme.
https://bugs.webkit.org/show_bug.cgi?id=34405
No new tests needed. Refactoring Only.
* rendering/MediaControlElements.cpp: Removed formatTime()
(WebCore::MediaControlTimeDisplayElement::setCurrentValue): No longer sets inner text
* rendering/MediaControlElements.h:
* rendering/RenderMedia.cpp:
(WebCore::RenderMedia::updateTimeDisplay): Asks the theme to format the time display elements
* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::formatMediaControlsTime): new virtual method
(WebCore::RenderTheme::formatMediaControlsCurrentTime): new virtual method
(WebCore::RenderTheme::formatMediaControlsRemainingTime): new virtual method
* rendering/RenderTheme.h:
2010-02-03 Steve Falkenburg <sfalken@apple.com> 2010-02-03 Steve Falkenburg <sfalken@apple.com>
Windows Debug_All build fix. Windows Debug_All build fix.
......
...@@ -731,30 +731,9 @@ void MediaControlTimeDisplayElement::setVisible(bool visible) ...@@ -731,30 +731,9 @@ void MediaControlTimeDisplayElement::setVisible(bool visible)
renderer()->setStyle(style.get()); renderer()->setStyle(style.get());
} }
String MediaControlTimeDisplayElement::formatTime(float time)
{
if (!isfinite(time))
time = 0;
int seconds = (int)fabsf(time);
int hours = seconds / (60 * 60);
int minutes = (seconds / 60) % 60;
seconds %= 60;
if (hours) {
if (hours > 9)
return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
}
return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
}
void MediaControlTimeDisplayElement::setCurrentValue(float time) void MediaControlTimeDisplayElement::setCurrentValue(float time)
{ {
m_currentValue = time; m_currentValue = time;
ExceptionCode ec;
setInnerText(formatTime(m_currentValue), ec);
} }
......
...@@ -268,8 +268,6 @@ public: ...@@ -268,8 +268,6 @@ public:
float currentValue() const { return m_currentValue; } float currentValue() const { return m_currentValue; }
private: private:
String formatTime(float time);
float m_currentValue; float m_currentValue;
bool m_isVisible; bool m_isVisible;
}; };
......
...@@ -412,10 +412,15 @@ void RenderMedia::updateTimeDisplay() ...@@ -412,10 +412,15 @@ void RenderMedia::updateTimeDisplay()
{ {
if (!m_currentTimeDisplay || !m_currentTimeDisplay->renderer() || m_currentTimeDisplay->renderer()->style()->display() == NONE || style()->visibility() != VISIBLE) if (!m_currentTimeDisplay || !m_currentTimeDisplay->renderer() || m_currentTimeDisplay->renderer()->style()->display() == NONE || style()->visibility() != VISIBLE)
return; return;
float now = mediaElement()->currentTime(); float now = mediaElement()->currentTime();
float duration = mediaElement()->duration(); float duration = mediaElement()->duration();
// Allow the theme to format the time
ExceptionCode ec;
m_currentTimeDisplay->setInnerText(theme()->formatMediaControlsCurrentTime(now, duration), ec);
m_currentTimeDisplay->setCurrentValue(now); m_currentTimeDisplay->setCurrentValue(now);
m_timeRemainingDisplay->setInnerText(theme()->formatMediaControlsRemainingTime(now, duration), ec);
m_timeRemainingDisplay->setCurrentValue(now - duration); m_timeRemainingDisplay->setCurrentValue(now - duration);
} }
......
...@@ -436,6 +436,35 @@ bool RenderTheme::shouldRenderMediaControlPart(ControlPart part, Element* e) ...@@ -436,6 +436,35 @@ bool RenderTheme::shouldRenderMediaControlPart(ControlPart part, Element* e)
return true; return true;
} }
} }
String RenderTheme::formatMediaControlsTime(float time) const
{
if (!isfinite(time))
time = 0;
int seconds = (int)fabsf(time);
int hours = seconds / (60 * 60);
int minutes = (seconds / 60) % 60;
seconds %= 60;
if (hours) {
if (hours > 9)
return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
}
return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
}
String RenderTheme::formatMediaControlsCurrentTime(float currentTime, float /*duration*/) const
{
return formatMediaControlsTime(currentTime);
}
String RenderTheme::formatMediaControlsRemainingTime(float currentTime, float duration) const
{
return formatMediaControlsTime(currentTime - duration);
}
#endif #endif
Color RenderTheme::activeSelectionBackgroundColor() const Color RenderTheme::activeSelectionBackgroundColor() const
......
...@@ -175,6 +175,9 @@ public: ...@@ -175,6 +175,9 @@ public:
virtual bool shouldRenderMediaControlPart(ControlPart, Element*); virtual bool shouldRenderMediaControlPart(ControlPart, Element*);
virtual double mediaControlsFadeInDuration() { return 0.1; } virtual double mediaControlsFadeInDuration() { return 0.1; }
virtual double mediaControlsFadeOutDuration() { return 0.3; } virtual double mediaControlsFadeOutDuration() { return 0.3; }
virtual String formatMediaControlsTime(float time) const;
virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
virtual String formatMediaControlsRemainingTime(float currentTime, float duration) const;
#endif #endif
protected: protected:
......
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