Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: Source/core/html/track/vtt/VTTCue.cpp

Issue 852233002: VTTCue: Simplify computation of direction-aware text position (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/track/vtt/VTTCue.cpp
diff --git a/Source/core/html/track/vtt/VTTCue.cpp b/Source/core/html/track/vtt/VTTCue.cpp
index 1715d96c85f71ccb74f8e5fe7f1279726fcc5e45..020324f9d70d6d7408003097def6fa016f12cd38 100644
--- a/Source/core/html/track/vtt/VTTCue.cpp
+++ b/Source/core/html/track/vtt/VTTCue.cpp
@@ -554,6 +554,19 @@ static CSSValueID determineTextDirection(DocumentFragment* vttRoot)
return isLeftToRightDirection(textDirection) ? CSSValueLtr : CSSValueRtl;
}
+static inline VTTCue::CueAlignment resolveCueAlignment(VTTCue::CueAlignment specifiedCueAlignment, CSSValueID direction)
+{
+ ASSERT(direction == CSSValueLtr || direction == CSSValueRtl);
+ switch (specifiedCueAlignment) {
+ case VTTCue::Start:
+ return direction == CSSValueLtr ? VTTCue::Left : VTTCue::Right;
+ case VTTCue::End:
+ return direction == CSSValueLtr ? VTTCue::Right : VTTCue::Left;
+ default:
+ return specifiedCueAlignment;
+ }
+}
+
void VTTCue::calculateDisplayParameters()
{
createVTTNodeTree();
@@ -604,36 +617,17 @@ void VTTCue::calculateDisplayParameters()
// 10.8 Determine the value of x-position or y-position for cue as per the
// appropriate rules from the following list:
if (m_writingDirection == Horizontal) {
- switch (m_cueAlignment) {
- case Start:
- if (m_displayDirection == CSSValueLtr)
- m_displayPosition.first = m_textPosition;
- else
- m_displayPosition.first = 100 - m_textPosition - m_displaySize;
- break;
- case End:
- if (m_displayDirection == CSSValueRtl)
- m_displayPosition.first = 100 - m_textPosition;
- else
- m_displayPosition.first = m_textPosition - m_displaySize;
- break;
+ int visualTextPosition = m_displayDirection == CSSValueLtr ? m_textPosition : 100 - m_textPosition;
+
+ switch (resolveCueAlignment(m_cueAlignment, m_displayDirection)) {
case Left:
- if (m_displayDirection == CSSValueLtr)
- m_displayPosition.first = m_textPosition;
- else
- m_displayPosition.first = 100 - m_textPosition;
+ m_displayPosition.first = visualTextPosition;
break;
case Right:
- if (m_displayDirection == CSSValueLtr)
- m_displayPosition.first = m_textPosition - m_displaySize;
- else
- m_displayPosition.first = 100 - m_textPosition - m_displaySize;
+ m_displayPosition.first = visualTextPosition - m_displaySize;
break;
case Middle:
- if (m_displayDirection == CSSValueLtr)
- m_displayPosition.first = m_textPosition - m_displaySize / 2;
- else
- m_displayPosition.first = 100 - m_textPosition - m_displaySize / 2;
+ m_displayPosition.first = visualTextPosition - m_displaySize / 2;
break;
default:
ASSERT_NOT_REACHED();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698