Title: [295185] branches/safari-613-branch/Source/WebCore/html/track
Revision
295185
Author
[email protected]
Date
2022-06-02 23:45:32 -0700 (Thu, 02 Jun 2022)

Log Message

Cherry-pick 8cfadef7857b. rdar://problem/93512736

    TextTrackCue should get its document for its ActiveDOMObject base class
    https://bugs.webkit.org/show_bug.cgi?id=240660
    <rdar://93512736>

    Reviewed by Eric Carlson.

    TextTrackCue should get its document for its ActiveDOMObject base class instead
    of requiring an extra data member to store it.

    * Source/WebCore/html/track/TextTrackCue.cpp:
    (WebCore::TextTrackCue::TextTrackCue):
    (WebCore::TextTrackCue::scriptExecutionContext const):
    (WebCore::TextTrackCue::document const):
    (WebCore::TextTrackCue::getCueAsHTML):
    (WebCore::TextTrackCue::rebuildDisplayTree):
    * Source/WebCore/html/track/TextTrackCue.h:
    (WebCore::TextTrackCue::ownerDocument): Deleted.
    * Source/WebCore/html/track/TextTrackCueGeneric.cpp:
    (WebCore::TextTrackCueGeneric::createDisplayTree):
    (WebCore::TextTrackCueGeneric::setFontSize):
    * Source/WebCore/html/track/TextTrackCueGeneric.h:
    * Source/WebCore/html/track/VTTCue.cpp:
    (WebCore::VTTCue::VTTCue):
    (WebCore::VTTCue::initialize):
    (WebCore::VTTCue::createDisplayTree):
    (WebCore::VTTCue::displayTreeInternal):
    (WebCore::VTTCue::createWebVTTNodeTree):
    (WebCore::VTTCue::getCueAsHTML):
    (WebCore::VTTCue::createCueRenderingTree):
    (WebCore::VTTCue::getDisplayTree):
    (WebCore::VTTCue::removeDisplayTree):
    * Source/WebCore/html/track/VTTCue.h:

    Canonical link: https://commits.webkit.org/250757@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294498 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.cpp (295184 => 295185)


--- branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.cpp	2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.cpp	2022-06-03 06:45:32 UTC (rev 295185)
@@ -216,7 +216,6 @@
     : ActiveDOMObject(document)
     , m_startTime(start)
     , m_endTime(end)
-    , m_document(document)
     , m_cueNode(WTFMove(cueFragment))
 {
 }
@@ -225,15 +224,19 @@
     : ActiveDOMObject(document)
     , m_startTime(start)
     , m_endTime(end)
-    , m_document(document)
 {
 }
 
 ScriptExecutionContext* TextTrackCue::scriptExecutionContext() const
 {
-    return &m_document;
+    return ActiveDOMObject::scriptExecutionContext();
 }
 
+Document* TextTrackCue::document() const
+{
+    return downcast<Document>(scriptExecutionContext());
+}
+
 void TextTrackCue::willChange()
 {
     if (++m_processingCueChanges > 1)
@@ -436,7 +439,11 @@
     if (!m_cueNode)
         return nullptr;
 
-    auto clonedFragment = DocumentFragment::create(ownerDocument());
+    auto* document = this->document();
+    if (!document)
+        return nullptr;
+
+    auto clonedFragment = DocumentFragment::create(*document);
     m_cueNode->cloneChildNodes(clonedFragment);
 
     for (Node* node = clonedFragment->firstChild(); node; node = node->nextSibling())
@@ -485,21 +492,25 @@
     if (!m_cueNode)
         return;
 
+    RefPtr document = this->document();
+    if (!document)
+        return;
+
     ScriptDisallowedScope::EventAllowedScope allowedScopeForReferenceTree(*m_cueNode);
 
     if (!m_displayTree) {
-        m_displayTree = TextTrackCueBox::create(ownerDocument(), *this);
+        m_displayTree = TextTrackCueBox::create(*document, *this);
         m_displayTree->setPseudo(ShadowPseudoIds::webkitGenericCueRoot());
     }
 
     m_displayTree->removeChildren();
-    auto clonedFragment = DocumentFragment::create(ownerDocument());
+    auto clonedFragment = DocumentFragment::create(*document);
     m_cueNode->cloneChildNodes(clonedFragment);
     m_displayTree->appendChild(clonedFragment);
 
     if (m_fontSize) {
-        if (auto page = ownerDocument().page()) {
-            auto style = HTMLStyleElement::create(HTMLNames::styleTag, ownerDocument(), false);
+        if (auto page = document->page()) {
+            auto style = HTMLStyleElement::create(HTMLNames::styleTag, *document, false);
             style->setTextContent(makeString(page->captionUserPreferencesStyleSheet(),
                 " ::", ShadowPseudoIds::cue(), "{font-size:", m_fontSize, m_fontSizeIsImportant ? "px !important}" : "px}"));
             m_displayTree->appendChild(style);

Modified: branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.h (295184 => 295185)


--- branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.h	2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.h	2022-06-03 06:45:32 UTC (rev 295185)
@@ -126,7 +126,7 @@
 protected:
     TextTrackCue(Document&, const MediaTime& start, const MediaTime& end);
 
-    Document& ownerDocument() { return m_document; }
+    Document* document() const;
 
     virtual bool cueContentsMatch(const TextTrackCue&) const;
     virtual void toJSON(JSON::Object&) const;
@@ -154,8 +154,6 @@
 
     TextTrack* m_track { nullptr };
 
-    Document& m_document;
-
     RefPtr<DocumentFragment> m_cueNode;
     RefPtr<TextTrackCueBox> m_displayTree;
 

Modified: branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.cpp (295184 => 295185)


--- branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.cpp	2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.cpp	2022-06-03 06:45:32 UTC (rev 295185)
@@ -171,9 +171,11 @@
 {
 }
 
-Ref<VTTCueBox> TextTrackCueGeneric::createDisplayTree()
+RefPtr<VTTCueBox> TextTrackCueGeneric::createDisplayTree()
 {
-    return TextTrackCueGenericBoxElement::create(ownerDocument(), *this);
+    if (auto* document = this->document())
+        return TextTrackCueGenericBoxElement::create(*document, *this);
+    return nullptr;
 }
 
 ExceptionOr<void> TextTrackCueGeneric::setLine(const LineAndPositionSetting& line)
@@ -205,7 +207,8 @@
     double size = videoSize.height() * baseFontSizeRelativeToVideoHeight() / 100;
     if (fontSizeMultiplier())
         size *= fontSizeMultiplier() / 100;
-    displayTreeInternal().setInlineStyleProperty(CSSPropertyFontSize, lround(size), CSSUnitType::CSS_PX);
+    if (auto* displayTree = displayTreeInternal())
+        displayTree->setInlineStyleProperty(CSSPropertyFontSize, lround(size), CSSUnitType::CSS_PX);
 }
 
 bool TextTrackCueGeneric::cueContentsMatch(const TextTrackCue& otherTextTrackCue) const

Modified: branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.h (295184 => 295185)


--- branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.h	2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.h	2022-06-03 06:45:32 UTC (rev 295185)
@@ -69,7 +69,7 @@
     bool isOrderedBefore(const TextTrackCue*) const final;
     bool isPositionedAbove(const TextTrackCue*) const final;
 
-    Ref<VTTCueBox> createDisplayTree() final;
+    RefPtr<VTTCueBox> createDisplayTree() final;
 
     bool cueContentsMatch(const TextTrackCue&) const final;
 

Modified: branches/safari-613-branch/Source/WebCore/html/track/VTTCue.cpp (295184 => 295185)


--- branches/safari-613-branch/Source/WebCore/html/track/VTTCue.cpp	2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/VTTCue.cpp	2022-06-03 06:45:32 UTC (rev 295185)
@@ -271,7 +271,7 @@
     , m_content(WTFMove(content))
     , m_originalStartTime(MediaTime::zeroTime())
 {
-    initialize();
+    initialize(document);
 }
 
 VTTCue::VTTCue(Document& document, const WebVTTCueData& cueData)
@@ -278,7 +278,7 @@
     : TextTrackCue(document, MediaTime::zeroTime(), MediaTime::zeroTime())
     , m_originalStartTime(cueData.originalStartTime())
 {
-    initialize();
+    initialize(document);
     setText(cueData.content());
     setStartTime(cueData.startTime());
     setEndTime(cueData.endTime());
@@ -290,25 +290,27 @@
 {
 }
 
-void VTTCue::initialize()
+void VTTCue::initialize(Document& document)
 {
-    m_cueBackdropBox = HTMLDivElement::create(ownerDocument());
-    m_cueHighlightBox = HTMLSpanElement::create(spanTag, ownerDocument());
+    m_cueBackdropBox = HTMLDivElement::create(document);
+    m_cueHighlightBox = HTMLSpanElement::create(spanTag, document);
     m_snapToLines = true;
     m_displayTreeShouldChange = true;
     m_notifyRegion = true;
 }
 
-Ref<VTTCueBox> VTTCue::createDisplayTree()
+RefPtr<VTTCueBox> VTTCue::createDisplayTree()
 {
-    return VTTCueBox::create(ownerDocument(), *this);
+    if (auto* document = this->document())
+        return VTTCueBox::create(*document, *this);
+    return nullptr;
 }
 
-VTTCueBox& VTTCue::displayTreeInternal()
+VTTCueBox* VTTCue::displayTreeInternal()
 {
     if (!m_displayTree)
         m_displayTree = createDisplayTree();
-    return *m_displayTree;
+    return m_displayTree.get();
 }
 
 void VTTCue::didChange()
@@ -593,8 +595,8 @@
 
 void VTTCue::createWebVTTNodeTree()
 {
-    if (!m_webVTTNodeTree)
-        m_webVTTNodeTree = WebVTTParser::createDocumentFragmentFromCueText(ownerDocument(), m_content);
+    if (!m_webVTTNodeTree && document())
+        m_webVTTNodeTree = WebVTTParser::createDocumentFragmentFromCueText(*document(), m_content);
 }
 
 static void copyWebVTTNodeToDOMTree(ContainerNode& webVTTNode, Node& parent)
@@ -617,7 +619,11 @@
     if (!m_webVTTNodeTree)
         return nullptr;
 
-    auto clonedFragment = DocumentFragment::create(ownerDocument());
+    auto* document = this->document();
+    if (!document)
+        return nullptr;
+
+    auto clonedFragment = DocumentFragment::create(*document);
     copyWebVTTNodeToDOMTree(*m_webVTTNodeTree, clonedFragment);
     return clonedFragment;
 }
@@ -628,8 +634,12 @@
     if (!m_webVTTNodeTree)
         return nullptr;
 
-    auto clonedFragment = DocumentFragment::create(ownerDocument());
+    auto* document = this->document();
+    if (!document)
+        return nullptr;
 
+    auto clonedFragment = DocumentFragment::create(*document);
+
     // The cloned fragment is never exposed to author scripts so it's safe to dispatch events here.
     ScriptDisallowedScope::EventAllowedScope allowedScope(clonedFragment);
 
@@ -966,8 +976,8 @@
 
 RefPtr<TextTrackCueBox> VTTCue::getDisplayTree(const IntSize& videoSize, int fontSize)
 {
-    Ref<VTTCueBox> displayTree = displayTreeInternal();
-    if (!m_displayTreeShouldChange || !track()->isRendered())
+    RefPtr displayTree = displayTreeInternal();
+    if (!displayTree || !m_displayTreeShouldChange || !track()->isRendered())
         return displayTree;
 
     // 10.1 - 10.10
@@ -1040,9 +1050,13 @@
             m_region->willRemoveTextTrackCueBox(m_displayTree.get());
     }
 
+    RefPtr displayTree = displayTreeInternal();
+    if (!displayTree)
+        return;
+
     // The display tree is never exposed to author scripts so it's safe to dispatch events here.
-    ScriptDisallowedScope::EventAllowedScope allowedScope(displayTreeInternal());
-    displayTreeInternal().remove();
+    ScriptDisallowedScope::EventAllowedScope allowedScope(*displayTree);
+    displayTree->remove();
 }
 
 std::pair<double, double> VTTCue::getPositionCoordinates() const

Modified: branches/safari-613-branch/Source/WebCore/html/track/VTTCue.h (295184 => 295185)


--- branches/safari-613-branch/Source/WebCore/html/track/VTTCue.h	2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/VTTCue.h	2022-06-03 06:45:32 UTC (rev 295185)
@@ -195,8 +195,8 @@
 
     bool cueContentsMatch(const TextTrackCue&) const override;
 
-    virtual Ref<VTTCueBox> createDisplayTree();
-    VTTCueBox& displayTreeInternal();
+    virtual RefPtr<VTTCueBox> createDisplayTree();
+    VTTCueBox* displayTreeInternal();
 
     void toJSON(JSON::Object&) const override;
 
@@ -203,7 +203,7 @@
 private:
     VTTCue(Document&, const WebVTTCueData&);
 
-    void initialize();
+    void initialize(Document&);
     void createWebVTTNodeTree();
 
     void parseSettings(const String&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to