From 6a4d37f8bbccae46eda41cc208a4221f97c99f01 Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Thu, 28 Sep 2017 12:17:07 -0700 Subject: [PATCH] Bug 1403819 - Remove nsIDOMHTMLCanvasElement; r=bz Removes the XPCOM interface for nsIDOMHTMLCanvasElement, replacing it with binding class usage. MozReview-Commit-ID: DQJhqGlY8U6 --- dom/base/nsDOMWindowUtils.cpp | 32 ++++++++++--------- dom/canvas/WebGLContext.cpp | 4 +-- dom/html/HTMLCanvasElement.cpp | 8 +---- dom/html/HTMLCanvasElement.h | 5 --- dom/interfaces/base/nsIDOMWindowUtils.idl | 5 ++- dom/interfaces/html/moz.build | 1 - .../html/nsIDOMHTMLCanvasElement.idl | 29 ----------------- widget/windows/TaskbarPreview.cpp | 4 +-- xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp | 3 -- 9 files changed, 24 insertions(+), 67 deletions(-) delete mode 100644 dom/interfaces/html/nsIDOMHTMLCanvasElement.idl diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index d5742995252c..218767e9c23e 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -50,7 +50,6 @@ #include "nsViewManager.h" -#include "nsIDOMHTMLCanvasElement.h" #include "nsLayoutUtils.h" #include "nsComputedDOMStyle.h" #include "nsIPresShell.h" @@ -106,6 +105,7 @@ #include "nsNetUtil.h" #include "nsDocument.h" #include "HTMLImageElement.h" +#include "HTMLCanvasElement.h" #include "mozilla/css/ImageLoader.h" #include "mozilla/layers/APZCTreeManager.h" // for layers::ZoomToRectBehavior #include "mozilla/dom/Promise.h" @@ -1624,26 +1624,19 @@ nsDOMWindowUtils::GetTranslationNodes(nsIDOMNode* aRoot, } static already_AddRefed -CanvasToDataSourceSurface(nsIDOMHTMLCanvasElement* aCanvas) +CanvasToDataSourceSurface(HTMLCanvasElement* aCanvas) { - nsCOMPtr node = do_QueryInterface(aCanvas); - if (!node) { - return nullptr; - } - - MOZ_ASSERT(node->IsElement(), - "An nsINode that implements nsIDOMHTMLCanvasElement should " - "be an element."); + MOZ_ASSERT(aCanvas); nsLayoutUtils::SurfaceFromElementResult result = - nsLayoutUtils::SurfaceFromElement(node->AsElement()); + nsLayoutUtils::SurfaceFromElement(aCanvas); MOZ_ASSERT(result.GetSourceSurface()); return result.GetSourceSurface()->GetDataSurface(); } NS_IMETHODIMP -nsDOMWindowUtils::CompareCanvases(nsIDOMHTMLCanvasElement *aCanvas1, - nsIDOMHTMLCanvasElement *aCanvas2, +nsDOMWindowUtils::CompareCanvases(nsISupports *aCanvas1, + nsISupports *aCanvas2, uint32_t* aMaxDifference, uint32_t* retVal) { @@ -1652,8 +1645,17 @@ nsDOMWindowUtils::CompareCanvases(nsIDOMHTMLCanvasElement *aCanvas1, retVal == nullptr) return NS_ERROR_FAILURE; - RefPtr img1 = CanvasToDataSourceSurface(aCanvas1); - RefPtr img2 = CanvasToDataSourceSurface(aCanvas2); + nsCOMPtr contentCanvas1 = do_QueryInterface(aCanvas1); + nsCOMPtr contentCanvas2 = do_QueryInterface(aCanvas2); + auto canvas1 = HTMLCanvasElement::FromContentOrNull(contentCanvas1); + auto canvas2 = HTMLCanvasElement::FromContentOrNull(contentCanvas2); + + if (!canvas1 || !canvas2) { + return NS_ERROR_FAILURE; + } + + RefPtr img1 = CanvasToDataSourceSurface(canvas1); + RefPtr img2 = CanvasToDataSourceSurface(canvas2); DataSourceSurface::ScopedMap map1(img1, DataSourceSurface::READ); DataSourceSurface::ScopedMap map2(img2, DataSourceSurface::READ); diff --git a/dom/canvas/WebGLContext.cpp b/dom/canvas/WebGLContext.cpp index b1237feb79d0..c4feee96ac9c 100644 --- a/dom/canvas/WebGLContext.cpp +++ b/dom/canvas/WebGLContext.cpp @@ -1819,7 +1819,7 @@ WebGLContext::UpdateContextLossStatus() if (mCanvasElement) { nsContentUtils::DispatchTrustedEvent( mCanvasElement->OwnerDoc(), - static_cast(mCanvasElement), + static_cast(mCanvasElement), kEventName, kCanBubble, kIsCancelable, @@ -1887,7 +1887,7 @@ WebGLContext::UpdateContextLossStatus() if (mCanvasElement) { nsContentUtils::DispatchTrustedEvent( mCanvasElement->OwnerDoc(), - static_cast(mCanvasElement), + static_cast(mCanvasElement), NS_LITERAL_STRING("webglcontextrestored"), true, true); diff --git a/dom/html/HTMLCanvasElement.cpp b/dom/html/HTMLCanvasElement.cpp index 2f197a206340..91221d6da465 100644 --- a/dom/html/HTMLCanvasElement.cpp +++ b/dom/html/HTMLCanvasElement.cpp @@ -403,9 +403,7 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLCanvasElement, nsGenericHTMLElement, mPrintState, mOriginalCanvas, mOffscreenCanvas) -NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLCanvasElement, - nsGenericHTMLElement, - nsIDOMHTMLCanvasElement) +NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLCanvasElement, nsGenericHTMLElement) NS_IMPL_ELEMENT_CLONE(HTMLCanvasElement) @@ -459,10 +457,6 @@ HTMLCanvasElement::GetWidthHeight() return size; } -NS_IMPL_UINT_ATTR_DEFAULT_VALUE(HTMLCanvasElement, Width, width, DEFAULT_CANVAS_WIDTH) -NS_IMPL_UINT_ATTR_DEFAULT_VALUE(HTMLCanvasElement, Height, height, DEFAULT_CANVAS_HEIGHT) -NS_IMPL_BOOL_ATTR(HTMLCanvasElement, MozOpaque, moz_opaque) - nsresult HTMLCanvasElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, diff --git a/dom/html/HTMLCanvasElement.h b/dom/html/HTMLCanvasElement.h index a3e3556c87c9..e87492ee6268 100644 --- a/dom/html/HTMLCanvasElement.h +++ b/dom/html/HTMLCanvasElement.h @@ -9,7 +9,6 @@ #include "mozilla/Attributes.h" #include "mozilla/WeakPtr.h" #include "nsIDOMEventListener.h" -#include "nsIDOMHTMLCanvasElement.h" #include "nsIObserver.h" #include "nsGenericHTMLElement.h" #include "nsGkAtoms.h" @@ -116,7 +115,6 @@ protected: }; class HTMLCanvasElement final : public nsGenericHTMLElement, - public nsIDOMHTMLCanvasElement, public CanvasRenderingContextHelper { enum { @@ -138,9 +136,6 @@ public: // nsISupports NS_DECL_ISUPPORTS_INHERITED - // nsIDOMHTMLCanvasElement - NS_DECL_NSIDOMHTMLCANVASELEMENT - // CC NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLCanvasElement, nsGenericHTMLElement) diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 4e25ca24114d..5d4b2f2ddc2d 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -34,7 +34,6 @@ interface nsICycleCollectorListener; interface nsIDOMNode; interface nsIDOMNodeList; interface nsIDOMElement; -interface nsIDOMHTMLCanvasElement; interface nsIDOMEvent; interface nsIPreloadedStyleSheet; interface nsITransferable; @@ -928,8 +927,8 @@ interface nsIDOMWindowUtils : nsISupports { * * This method requires chrome privileges. */ - uint32_t compareCanvases(in nsIDOMHTMLCanvasElement aCanvas1, - in nsIDOMHTMLCanvasElement aCanvas2, + uint32_t compareCanvases(in nsISupports aCanvas1, + in nsISupports aCanvas2, out unsigned long aMaxDifference); /** diff --git a/dom/interfaces/html/moz.build b/dom/interfaces/html/moz.build index 8beba45802ed..3f2889fb6c81 100644 --- a/dom/interfaces/html/moz.build +++ b/dom/interfaces/html/moz.build @@ -9,7 +9,6 @@ with Files("**"): XPIDL_SOURCES += [ 'nsIDOMHTMLBaseElement.idl', - 'nsIDOMHTMLCanvasElement.idl', 'nsIDOMHTMLCollection.idl', 'nsIDOMHTMLDocument.idl', 'nsIDOMHTMLElement.idl', diff --git a/dom/interfaces/html/nsIDOMHTMLCanvasElement.idl b/dom/interfaces/html/nsIDOMHTMLCanvasElement.idl deleted file mode 100644 index c577e12e3797..000000000000 --- a/dom/interfaces/html/nsIDOMHTMLCanvasElement.idl +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsIDOMHTMLElement.idl" - -/** - * The nsIDOMHTMLCanvasElement interface is the interface to a HTML - * element. - * - * For more information on this interface, please see - * http://www.whatwg.org/specs/web-apps/current-work/#graphics - * - * @status UNDER_DEVELOPMENT - */ - -interface nsIDOMBlob; -interface nsIVariant; -interface nsIInputStreamCallback; - -[uuid(4e8f1316-b601-471d-8f44-3c650d91ee9b)] -interface nsIDOMHTMLCanvasElement : nsISupports -{ - attribute unsigned long width; - attribute unsigned long height; - attribute boolean mozOpaque; -}; - diff --git a/widget/windows/TaskbarPreview.cpp b/widget/windows/TaskbarPreview.cpp index b07b8039fa43..8b7c3f1eb9eb 100644 --- a/widget/windows/TaskbarPreview.cpp +++ b/widget/windows/TaskbarPreview.cpp @@ -347,8 +347,8 @@ TaskbarPreviewCallback::Done(nsISupports *aCanvas, bool aDrawBorder) { return NS_ERROR_FAILURE; } - nsCOMPtr domcanvas(do_QueryInterface(aCanvas)); - dom::HTMLCanvasElement * canvas = ((dom::HTMLCanvasElement*)domcanvas.get()); + nsCOMPtr content(do_QueryInterface(aCanvas)); + auto canvas = dom::HTMLCanvasElement::FromContentOrNull(content); if (!canvas) { return NS_ERROR_FAILURE; } diff --git a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp index 2b8caf837919..a2c22159647e 100644 --- a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp @@ -46,7 +46,6 @@ #include "nsIDOMGeoPositionError.h" #include "nsIDOMHistory.h" #include "nsIDOMHTMLBaseElement.h" -#include "nsIDOMHTMLCanvasElement.h" #include "nsIDOMHTMLCollection.h" #include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLElement.h" @@ -154,7 +153,6 @@ #include "mozilla/dom/HTMLAreaElementBinding.h" #include "mozilla/dom/HTMLBaseElementBinding.h" #include "mozilla/dom/HTMLButtonElementBinding.h" -#include "mozilla/dom/HTMLCanvasElementBinding.h" #include "mozilla/dom/HTMLCollectionBinding.h" #include "mozilla/dom/HTMLDocumentBinding.h" #include "mozilla/dom/HTMLElementBinding.h" @@ -317,7 +315,6 @@ const ComponentsInterfaceShimEntry kComponentsInterfaceShimMap[] = DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMGeoPositionError, PositionError), DEFINE_SHIM(History), DEFINE_SHIM(HTMLBaseElement), - DEFINE_SHIM(HTMLCanvasElement), DEFINE_SHIM(HTMLCollection), DEFINE_SHIM(HTMLDocument), DEFINE_SHIM(HTMLElement),