https://bugs.webkit.org/show_bug.cgi?id=137169
Reviewed by Darin Adler.
Source/WebCore:
Make is<>() / downcast<>() work for HTMLDocument and its subclasses by
using the SPECIALIZE_TYPE_TRAITS_*() macro. Drop the DOCUMENT_TYPE_CASTS()
macro as it is no longer needed.
No new tests, no behavior change.
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::namedItemGetter):
(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
* dom/Document.cpp:
(WebCore::Document::prepareForDestruction):
(WebCore::Document::processHttpEquiv):
(WebCore::eventTargetElementForDocument):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::insertedInto):
(WebCore::Element::removedFrom):
(WebCore::Element::updateName):
(WebCore::Element::updateId):
* html/HTMLDocument.h:
(WebCore::isHTMLDocument):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::matchesReadWritePseudoClass):
* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::updateWidget):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseAttribute):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::parseAttribute):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::updateDocNamedItem):
* html/ImageDocument.cpp:
(WebCore::ImageDocumentParser::document):
* html/ImageDocument.h:
(WebCore::isImageDocument):
* html/MediaDocument.h:
(WebCore::isMediaDocument):
* html/PluginDocument.cpp:
(WebCore::PluginDocumentParser::createDocumentStructure):
* html/PluginDocument.h:
(WebCore::isPluginDocument):
* loader/SubframeLoader.cpp:
(WebCore::SubframeLoader::loadPlugin):
* page/DragController.cpp:
(WebCore::DragController::operationForLoad):
* page/FrameView.cpp:
(WebCore::determineLayerFlushThrottleState):
Source/WebKit/win:
Use is<>() / downcast<>() for HTMLDocument and its subclasses.
* DOMHTMLClasses.cpp:
(DOMHTMLDocument::URL):
(DOMHTMLDocument::body):
(DOMHTMLDocument::forms):
Source/WebKit2:
Use is<>() / downcast<>() for HTMLDocument and its subclasses.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::pdfDocumentForPrintingFrame):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174065
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2014-09-29 Christophe Dumez <cdumez@apple.com>
+
+ Make is<>() / downcast<>() work for HTMLDocument and its subclasses
+ https://bugs.webkit.org/show_bug.cgi?id=137169
+
+ Reviewed by Darin Adler.
+
+ Make is<>() / downcast<>() work for HTMLDocument and its subclasses by
+ using the SPECIALIZE_TYPE_TRAITS_*() macro. Drop the DOCUMENT_TYPE_CASTS()
+ macro as it is no longer needed.
+
+ No new tests, no behavior change.
+
+ * bindings/js/JSDOMWindowCustom.cpp:
+ (WebCore::namedItemGetter):
+ (WebCore::JSDOMWindow::getOwnPropertySlot):
+ (WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
+ * dom/Document.cpp:
+ (WebCore::Document::prepareForDestruction):
+ (WebCore::Document::processHttpEquiv):
+ (WebCore::eventTargetElementForDocument):
+ * dom/Document.h:
+ * dom/Element.cpp:
+ (WebCore::Element::insertedInto):
+ (WebCore::Element::removedFrom):
+ (WebCore::Element::updateName):
+ (WebCore::Element::updateId):
+ * html/HTMLDocument.h:
+ (WebCore::isHTMLDocument):
+ * html/HTMLElement.cpp:
+ (WebCore::HTMLElement::matchesReadWritePseudoClass):
+ * html/HTMLEmbedElement.cpp:
+ (WebCore::HTMLEmbedElement::updateWidget):
+ * html/HTMLImageElement.cpp:
+ (WebCore::HTMLImageElement::parseAttribute):
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::parseAttribute):
+ * html/HTMLObjectElement.cpp:
+ (WebCore::HTMLObjectElement::updateDocNamedItem):
+ * html/ImageDocument.cpp:
+ (WebCore::ImageDocumentParser::document):
+ * html/ImageDocument.h:
+ (WebCore::isImageDocument):
+ * html/MediaDocument.h:
+ (WebCore::isMediaDocument):
+ * html/PluginDocument.cpp:
+ (WebCore::PluginDocumentParser::createDocumentStructure):
+ * html/PluginDocument.h:
+ (WebCore::isPluginDocument):
+ * loader/SubframeLoader.cpp:
+ (WebCore::SubframeLoader::loadPlugin):
+ * page/DragController.cpp:
+ (WebCore::DragController::operationForLoad):
+ * page/FrameView.cpp:
+ (WebCore::determineLayerFlushThrottleState):
+
2014-09-29 Bruno de Oliveira Abinader <bruno.d@partner.samsung.com>
Revert "Support for :enabled selector on Anchor & Area elements"
ASSERT(BindingSecurity::shouldAllowAccessToDOMWindow(exec, thisObj->impl()));
ASSERT(document);
- ASSERT(document->isHTMLDocument());
+ ASSERT(is<HTMLDocument>(document));
AtomicStringImpl* atomicPropertyName = propertyName.publicName();
- if (!atomicPropertyName || !toHTMLDocument(*document).hasWindowNamedItem(*atomicPropertyName))
+ if (!atomicPropertyName || !downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName))
return JSValue::encode(jsUndefined());
- if (UNLIKELY(toHTMLDocument(*document).windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
+ if (UNLIKELY(downcast<HTMLDocument>(*document).windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
RefPtr<HTMLCollection> collection = document->windowNamedItems(atomicPropertyName);
ASSERT(collection->length() > 1);
return JSValue::encode(toJS(exec, thisObj->globalObject(), WTF::getPtr(collection)));
}
- return JSValue::encode(toJS(exec, thisObj->globalObject(), toHTMLDocument(*document).windowNamedItem(*atomicPropertyName)));
+ return JSValue::encode(toJS(exec, thisObj->globalObject(), downcast<HTMLDocument>(*document).windowNamedItem(*atomicPropertyName)));
}
#if ENABLE(USER_MESSAGE_HANDLERS)
// Allow shortcuts like 'Image1' instead of document.images.Image1
Document* document = thisObject->impl().frame()->document();
- if (document->isHTMLDocument()) {
+ if (is<HTMLDocument>(document)) {
AtomicStringImpl* atomicPropertyName = propertyName.publicName();
- if (atomicPropertyName && toHTMLDocument(*document).hasWindowNamedItem(*atomicPropertyName)) {
+ if (atomicPropertyName && downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName)) {
slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
return true;
}
// Allow shortcuts like 'Image1' instead of document.images.Image1
Document* document = thisObject->impl().frame()->document();
- if (document->isHTMLDocument()) {
+ if (is<HTMLDocument>(document)) {
AtomicStringImpl* atomicPropertyName = propertyName.publicName();
- if (atomicPropertyName && toHTMLDocument(*document).hasWindowNamedItem(*atomicPropertyName)) {
+ if (atomicPropertyName && downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName)) {
slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
return true;
}
if (hasLivingRenderTree())
destroyRenderTree();
- if (isPluginDocument())
- toPluginDocument(this)->detachFromPluginElement();
+ if (is<PluginDocument>(*this))
+ downcast<PluginDocument>(*this).detachFromPluginElement();
#if ENABLE(POINTER_LOCK)
if (page())
case HTTPHeaderName::SetCookie:
// FIXME: make setCookie work on XML documents too; e.g. in case of <html:meta .....>
- if (isHTMLDocument()) {
+ if (is<HTMLDocument>(*this)) {
// Exception (for sandboxed documents) ignored.
- toHTMLDocument(*this).setCookie(content, IGNORE_EXCEPTION);
+ downcast<HTMLDocument>(*this).setCookie(content, IGNORE_EXCEPTION);
}
break;
}
#endif
-Element* eventTargetElementForDocument(Document* doc)
+Element* eventTargetElementForDocument(Document* document)
{
- if (!doc)
+ if (!document)
return nullptr;
- Element* element = doc->focusedElement();
- if (!element && doc->isPluginDocument()) {
- PluginDocument* pluginDocument = toPluginDocument(doc);
- element = pluginDocument->pluginElement();
- }
- if (!element && doc->isHTMLDocument())
- element = doc->body();
+ Element* element = document->focusedElement();
+ if (!element && is<PluginDocument>(document))
+ element = downcast<PluginDocument>(*document).pluginElement();
+ if (!element && is<HTMLDocument>(document))
+ element = document->body();
if (!element)
- element = doc->documentElement();
+ element = document->documentElement();
return element;
}
NODE_TYPE_CASTS(Document)
-#define DOCUMENT_TYPE_CASTS(ToClassName) \
- TYPE_CASTS_BASE(ToClassName, Document, document, WebCore::is##ToClassName(*document), WebCore::is##ToClassName(document))
-
} // namespace WebCore
namespace WTF {
elementRareData()->clearClassListValueForQuirksMode();
TreeScope* newScope = &insertionPoint.treeScope();
- HTMLDocument* newDocument = !wasInDocument && inDocument() && newScope->documentScope().isHTMLDocument() ? toHTMLDocument(&newScope->documentScope()) : nullptr;
+ HTMLDocument* newDocument = !wasInDocument && inDocument() && is<HTMLDocument>(newScope->documentScope()) ? &downcast<HTMLDocument>(newScope->documentScope()) : nullptr;
if (newScope != &treeScope())
newScope = nullptr;
if (insertionPoint.isInTreeScope()) {
TreeScope* oldScope = &insertionPoint.treeScope();
- HTMLDocument* oldDocument = inDocument() && oldScope->documentScope().isHTMLDocument() ? toHTMLDocument(&oldScope->documentScope()) : nullptr;
+ HTMLDocument* oldDocument = inDocument() && is<HTMLDocument>(oldScope->documentScope()) ? &downcast<HTMLDocument>(oldScope->documentScope()) : nullptr;
if (oldScope != &treeScope() || !isInTreeScope())
oldScope = nullptr;
if (!inDocument())
return;
- if (!document().isHTMLDocument())
+ if (!is<HTMLDocument>(document()))
return;
- updateNameForDocument(toHTMLDocument(document()), oldName, newName);
+ updateNameForDocument(downcast<HTMLDocument>(document()), oldName, newName);
}
void Element::updateNameForTreeScope(TreeScope& scope, const AtomicString& oldName, const AtomicString& newName)
if (!inDocument())
return;
- if (!document().isHTMLDocument())
+ if (!is<HTMLDocument>(document()))
return;
- updateIdForDocument(toHTMLDocument(document()), oldId, newId, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute);
+ updateIdForDocument(downcast<HTMLDocument>(document()), oldId, newId, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute);
}
void Element::updateIdForTreeScope(TreeScope& scope, const AtomicString& oldId, const AtomicString& newId)
DocumentOrderedMap m_windowNamedItem;
};
-inline bool isHTMLDocument(const Document& document) { return document.isHTMLDocument(); }
-void isHTMLDocument(const HTMLDocument&); // Catch unnecessary runtime check of type known at compile time.
-
-DOCUMENT_TYPE_CASTS(HTMLDocument)
+SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLDocument)
+ static bool isHTMLDocument(const Document& document) { return document.isHTMLDocument(); }
+ static bool isHTMLDocument(const Node& node) { return node.isDocumentNode() && isHTMLDocument(toDocument(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
} // namespace WebCore
} while (currentElement);
const Document& document = this->document();
- if (document.isHTMLDocument()) {
- const HTMLDocument& htmlDocument = toHTMLDocument(document);
- return htmlDocument.inDesignMode();
- }
+ if (is<HTMLDocument>(document))
+ return downcast<HTMLDocument>(document).inDesignMode();
return false;
}
Ref<HTMLEmbedElement> protect(*this); // Loading the plugin might remove us from the document.
bool beforeLoadAllowedLoad = guardedDispatchBeforeLoadEvent(m_url);
if (!beforeLoadAllowedLoad) {
- if (document().isPluginDocument()) {
+ if (is<PluginDocument>(document())) {
// Plugins inside plugin documents load differently than other plugins. By the time
// we are here in a plugin document, the load of the plugin (which is the plugin document's
// main resource) has already started. We need to explicitly cancel the main resource load here.
- toPluginDocument(&document())->cancelManualPluginLoad();
+ downcast<PluginDocument>(document()).cancelManualPluginLoad();
}
return;
}
} else {
if (name == nameAttr) {
bool willHaveName = !value.isNull();
- if (hasName() != willHaveName && inDocument() && document().isHTMLDocument()) {
- HTMLDocument& document = toHTMLDocument(this->document());
+ if (hasName() != willHaveName && inDocument() && is<HTMLDocument>(document())) {
+ HTMLDocument& document = downcast<HTMLDocument>(this->document());
const AtomicString& id = getIdAttribute();
if (!id.isEmpty() && id != getNameAttribute()) {
if (willHaveName)
setShouldDelayLoadEvent(false);
// 6 - Abort the overall resource selection algorithm.
- m_currentSourceNode = 0;
+ m_currentSourceNode = nullptr;
#if PLATFORM(COCOA)
- if (document().isMediaDocument())
- toMediaDocument(document()).mediaElementSawUnsupportedTracks();
+ if (is<MediaDocument>(document()))
+ downcast<MediaDocument>(document()).mediaElementSawUnsupportedTracks();
#endif
}
// The MediaPlayer came across content it cannot completely handle.
// This is normally acceptable except when we are in a standalone
// MediaDocument. If so, tell the document what has happened.
- if (document().isMediaDocument())
- toMediaDocument(document()).mediaElementSawUnsupportedTracks();
+ if (is<MediaDocument>(document()))
+ downcast<MediaDocument>(document()).mediaElementSawUnsupportedTracks();
}
void HTMLMediaElement::mediaPlayerResourceNotSupported(MediaPlayer*)
isNamedItem = false;
child = child->nextSibling();
}
- if (isNamedItem != wasNamedItem && inDocument() && document().isHTMLDocument()) {
- HTMLDocument& document = toHTMLDocument(this->document());
+ if (isNamedItem != wasNamedItem && inDocument() && is<HTMLDocument>(document())) {
+ HTMLDocument& document = downcast<HTMLDocument>(this->document());
const AtomicString& id = getIdAttribute();
if (!id.isEmpty()) {
{
// Only used during parsing, so document is guaranteed to be non-null.
ASSERT(RawDataDocumentParser::document());
- return toImageDocument(*RawDataDocumentParser::document());
+ return downcast<ImageDocument>(*RawDataDocumentParser::document());
}
void ImageDocumentParser::appendBytes(DocumentWriter&, const char*, size_t)
bool m_shouldShrinkImage;
};
-inline bool isImageDocument(const Document& document) { return document.isImageDocument(); }
-void isImageDocument(const ImageDocument&); // Catch unnecessary runtime check of type known at compile time.
-
-DOCUMENT_TYPE_CASTS(ImageDocument)
+SPECIALIZE_TYPE_TRAITS_BEGIN(ImageDocument)
+ static bool isImageDocument(const Document& document) { return document.isImageDocument(); }
+ static bool isImageDocument(const Node& node) { return node.isDocumentNode() && isImageDocument(toDocument(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
}
String m_outgoingReferrer;
};
-inline bool isMediaDocument(const Document& document) { return document.isMediaDocument(); }
-void isMediaDocument(const MediaDocument&); // Catch unnecessary runtime check of type known at compile time.
-
-DOCUMENT_TYPE_CASTS(MediaDocument)
+SPECIALIZE_TYPE_TRAITS_BEGIN(MediaDocument)
+ static bool isMediaDocument(const Document& document) { return document.isMediaDocument(); }
+ static bool isMediaDocument(const Node& node) { return node.isDocumentNode() && isMediaDocument(toDocument(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
}
if (loader)
m_embedElement->setAttribute(typeAttr, loader->writer().mimeType());
- toPluginDocument(document())->setPluginElement(m_embedElement);
+ downcast<PluginDocument>(*document()).setPluginElement(m_embedElement);
body->appendChild(embedElement, IGNORE_EXCEPTION);
}
RefPtr<HTMLPlugInElement> m_pluginElement;
};
-inline bool isPluginDocument(const Document& document) { return document.isPluginDocument(); }
-void isPluginDocument(const PluginDocument&); // Catch unnecessary runtime check of type known at compile time.
-
-DOCUMENT_TYPE_CASTS(PluginDocument)
+SPECIALIZE_TYPE_TRAITS_BEGIN(PluginDocument)
+ static bool isPluginDocument(const Document& document) { return document.isPluginDocument(); }
+ static bool isPluginDocument(const Node& node) { return node.isDocumentNode() && isPluginDocument(toDocument(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
}
pluginElement.subframeLoaderWillCreatePlugIn(url);
IntSize contentSize = roundedIntSize(LayoutSize(renderer->contentWidth(), renderer->contentHeight()));
- bool loadManually = document()->isPluginDocument() && !m_containsPlugins && toPluginDocument(document())->shouldLoadPluginManually();
+ bool loadManually = is<PluginDocument>(document()) && !m_containsPlugins && downcast<PluginDocument>(*document()).shouldLoadPluginManually();
#if PLATFORM(IOS)
// On iOS, we only tell the plugin to be in full page mode if the containing plugin document is the top level document.
bool pluginDocumentAcceptsDrags = false;
- if (doc && doc->isPluginDocument()) {
- const Widget* widget = toPluginDocument(doc)->pluginWidget();
+ if (doc && is<PluginDocument>(doc)) {
+ const Widget* widget = downcast<PluginDocument>(*doc).pluginWidget();
const PluginViewBase* pluginView = (widget && widget->isPluginViewBase()) ? toPluginViewBase(widget) : nullptr;
if (pluginView)
return 0;
// Disable for image documents so large GIF animations don't get throttled during loading.
auto* document = page.mainFrame().document();
- if (!document || isImageDocument(*document))
+ if (!document || is<ImageDocument>(*document))
return 0;
return LayerFlushThrottleState::Enabled;
}
+2014-09-29 Christophe Dumez <cdumez@apple.com>
+
+ Make is<>() / downcast<>() work for HTMLDocument and its subclasses
+ https://bugs.webkit.org/show_bug.cgi?id=137169
+
+ Reviewed by Darin Adler.
+
+ Use is<>() / downcast<>() for HTMLDocument and its subclasses.
+
+ * DOMHTMLClasses.cpp:
+ (DOMHTMLDocument::URL):
+ (DOMHTMLDocument::body):
+ (DOMHTMLDocument::forms):
+
2014-09-28 Gyuyoung Kim <gyuyoung.kim@samsung.com>
Use std::unique_ptr for ContextMenuController
if (!result)
return E_POINTER;
- *result = BString(toHTMLDocument(m_document)->url()).release();
+ *result = BString(downcast<HTMLDocument>(*m_document).url()).release();
return S_OK;
}
HRESULT STDMETHODCALLTYPE DOMHTMLDocument::body(
/* [retval][out] */ IDOMHTMLElement** bodyElement)
{
- *bodyElement = 0;
- if (!m_document || !m_document->isHTMLDocument())
+ *bodyElement = nullptr;
+ if (!m_document || !is<HTMLDocument>(m_document))
return E_FAIL;
- HTMLDocument& htmlDoc = toHTMLDocument(*m_document);
+ HTMLDocument& htmlDoc = downcast<HTMLDocument>(*m_document);
COMPtr<IDOMElement> domElement;
domElement.adoptRef(DOMHTMLElement::createInstance(htmlDoc.body()));
if (domElement)
HRESULT STDMETHODCALLTYPE DOMHTMLDocument::forms(
/* [retval][out] */ IDOMHTMLCollection** collection)
{
- *collection = 0;
- if (!m_document || !m_document->isHTMLDocument())
+ *collection = nullptr;
+ if (!m_document || !is<HTMLDocument>(m_document))
return E_FAIL;
- HTMLDocument& htmlDoc = toHTMLDocument(*m_document);
+ HTMLDocument& htmlDoc = downcast<HTMLDocument>(*m_document);
RefPtr<HTMLCollection> forms = htmlDoc.forms();
*collection = DOMHTMLCollection::createInstance(forms.get());
return S_OK;
+2014-09-29 Christophe Dumez <cdumez@apple.com>
+
+ Make is<>() / downcast<>() work for HTMLDocument and its subclasses
+ https://bugs.webkit.org/show_bug.cgi?id=137169
+
+ Reviewed by Darin Adler.
+
+ Use is<>() / downcast<>() for HTMLDocument and its subclasses.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::pdfDocumentForPrintingFrame):
+
2014-09-29 Tibor Meszaros <tmeszaros.u-szeged@partner.samsung.com>
Fix !ENABLE(INSPECTOR) build after r173929
{
Document* document = coreFrame->document();
if (!document)
- return 0;
+ return nullptr;
- if (!document->isPluginDocument())
- return 0;
+ if (!is<PluginDocument>(document))
+ return nullptr;
- PluginView* pluginView = static_cast<PluginView*>(toPluginDocument(document)->pluginWidget());
+ PluginView* pluginView = static_cast<PluginView*>(downcast<PluginDocument>(*document).pluginWidget());
if (!pluginView)
- return 0;
+ return nullptr;
return pluginView->pdfDocumentForPrinting();
}