Index: Source/core/dom/Document.cpp |
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp |
index 27207a8de35eb20383e80ee5c5b0ce87fc6efed2..1569f4a58adb51987d25bcadd5babf58924b4e30 100644 |
--- a/Source/core/dom/Document.cpp |
+++ b/Source/core/dom/Document.cpp |
@@ -429,6 +429,7 @@ Document::Document(const DocumentInit& initializer, DocumentClassFlags documentC |
, m_weakFactory(this) |
, m_contextDocument(initializer.contextDocument()) |
, m_hasFullscreenElementStack(false) |
+ , m_activeModalDialog(0) |
, m_loadEventDelayCount(0) |
, m_loadEventDelayTimer(this, &Document::loadEventDelayTimerFired) |
, m_referrerPolicy(ReferrerPolicyDefault) |
@@ -4722,9 +4723,9 @@ void Document::addToTopLayer(Element* element, const Element* before) |
{ |
if (element->isInTopLayer()) |
return; |
- |
ASSERT(!m_topLayerElements.contains(element)); |
ASSERT(!before || m_topLayerElements.contains(before)); |
+ |
if (before) { |
size_t beforePosition = m_topLayerElements.find(before); |
m_topLayerElements.insert(beforePosition, element); |
@@ -4744,11 +4745,41 @@ void Document::removeFromTopLayer(Element* element) |
element->setIsInTopLayer(false); |
} |
+void Document::addToModalDialogStack(HTMLDialogElement* dialog) |
+{ |
+ if (dialog->isModal()) |
+ return; |
+ addToTopLayer(dialog); |
+ dialog->setModal(true); |
+ m_activeModalDialog = dialog; |
+} |
+ |
+void Document::removeFromModalDialogStack(HTMLDialogElement* dialog) |
+{ |
+ if (!dialog->isModal()) |
+ return; |
+ |
+ removeFromTopLayer(dialog); |
+ dialog->setModal(false); |
+ if (m_activeModalDialog != dialog) |
+ return; |
+ |
+ m_activeModalDialog = 0; |
+ Vector<RefPtr<Element> >::reverse_iterator end = m_topLayerElements.rend(); |
+ for (Vector<RefPtr<Element> >::reverse_iterator it = m_topLayerElements.rbegin(); it != end; ++it) { |
+ if (!it->get()->hasTagName(dialogTag)) |
+ continue; |
+ HTMLDialogElement* dialog = toHTMLDialogElement(it->get()); |
+ if (dialog->isModal()) { |
+ m_activeModalDialog = dialog; |
+ return; |
+ } |
+ } |
+} |
+ |
HTMLDialogElement* Document::activeModalDialog() const |
{ |
- if (m_topLayerElements.isEmpty()) |
- return 0; |
- return toHTMLDialogElement(m_topLayerElements.last().get()); |
+ return m_activeModalDialog; |
} |
void Document::webkitExitPointerLock() |