void VTTCue::determineTextDirection() { DEPRECATED_DEFINE_STATIC_LOCAL(const String, rtTag, (ASCIILiteral("rt"))); createWebVTTNodeTree(); if (!m_webVTTNodeTree) return; // Apply the Unicode Bidirectional Algorithm's Paragraph Level steps to the // concatenation of the values of each WebVTT Text Object in nodes, in a // pre-order, depth-first traversal, excluding WebVTT Ruby Text Objects and // their descendants. StringBuilder paragraphBuilder; for (Node* node = m_webVTTNodeTree->firstChild(); node; node = NodeTraversal::next(node, m_webVTTNodeTree.get())) { // FIXME: The code does not match the comment above. This does not actually exclude Ruby Text Object descendant. if (!node->isTextNode() || node->localName() == rtTag) continue; paragraphBuilder.append(node->nodeValue()); } String paragraph = paragraphBuilder.toString(); if (!paragraph.length()) return; for (size_t i = 0; i < paragraph.length(); ++i) { UChar current = paragraph[i]; if (!current || isCueParagraphSeparator(current)) return; if (UChar current = paragraph[i]) { UCharDirection charDirection = u_charDirection(current); if (charDirection == U_LEFT_TO_RIGHT) { m_displayDirection = CSSValueLtr; return; } if (charDirection == U_RIGHT_TO_LEFT || charDirection == U_RIGHT_TO_LEFT_ARABIC) { m_displayDirection = CSSValueRtl; return; } } } }
void TextTrackCue::determineTextDirection() { DEFINE_STATIC_LOCAL(const String, rtTag, (ASCIILiteral("rt"))); createWebVTTNodeTree(); if (!m_webVTTNodeTree) return; // Apply the Unicode Bidirectional Algorithm's Paragraph Level steps to the // concatenation of the values of each WebVTT Text Object in nodes, in a // pre-order, depth-first traversal, excluding WebVTT Ruby Text Objects and // their descendants. StringBuilder paragraphBuilder; for (Node* node = m_webVTTNodeTree->firstChild(); node; node = NodeTraversal::next(node, m_webVTTNodeTree.get())) { if (!node->isTextNode() || node->localName() == rtTag) continue; paragraphBuilder.append(node->nodeValue()); } String paragraph = paragraphBuilder.toString(); if (!paragraph.length()) return; for (size_t i = 0; i < paragraph.length(); ++i) { UChar current = paragraph[i]; if (!current || isCueParagraphSeparator(current)) return; if (UChar current = paragraph[i]) { WTF::Unicode::Direction charDirection = WTF::Unicode::direction(current); if (charDirection == WTF::Unicode::LeftToRight) { m_displayDirection = CSSValueLtr; return; } if (charDirection == WTF::Unicode::RightToLeft || charDirection == WTF::Unicode::RightToLeftArabic) { m_displayDirection = CSSValueRtl; return; } } } }