mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 825527 - Part 3: Move HTMLImageElement to WebIDL bindings; r=bzbarsky
This commit is contained in:
parent
4f58470032
commit
fd6ad89073
@ -550,7 +550,7 @@ public:
|
||||
template<class ElementType>
|
||||
void TexImage2D(WebGLenum target, WebGLint level,
|
||||
WebGLenum internalformat, WebGLenum format, WebGLenum type,
|
||||
ElementType* elt, ErrorResult& rv) {
|
||||
const ElementType& elt, ErrorResult& rv) {
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
nsRefPtr<gfxImageSurface> isurf;
|
||||
@ -587,7 +587,7 @@ public:
|
||||
template<class ElementType>
|
||||
void TexSubImage2D(WebGLenum target, WebGLint level,
|
||||
WebGLint xoffset, WebGLint yoffset, WebGLenum format,
|
||||
WebGLenum type, ElementType* elt, ErrorResult& rv) {
|
||||
WebGLenum type, const ElementType& elt, ErrorResult& rv) {
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
nsRefPtr<gfxImageSurface> isurf;
|
||||
@ -986,6 +986,10 @@ protected:
|
||||
flags |= nsLayoutUtils::SFE_NO_PREMULTIPLY_ALPHA;
|
||||
return nsLayoutUtils::SurfaceFromElement(aElement, flags);
|
||||
}
|
||||
template<class ElementType>
|
||||
nsLayoutUtils::SurfaceFromElementResult SurfaceFromElement(const dom::NonNull<ElementType>& aElement) {
|
||||
return SurfaceFromElement(aElement.get());
|
||||
}
|
||||
|
||||
nsresult SurfaceFromElementResultToImageSurface(nsLayoutUtils::SurfaceFromElementResult& res,
|
||||
gfxImageSurface **imageOut,
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "mozilla/Util.h"
|
||||
|
||||
#include "mozilla/dom/HTMLImageElement.h"
|
||||
#include "mozilla/dom/HTMLImageElementBinding.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
@ -139,21 +140,26 @@ HTMLImageElement::Draggable() const
|
||||
nsGkAtoms::_false, eIgnoreCase);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLImageElement::GetComplete(bool* aComplete)
|
||||
bool
|
||||
HTMLImageElement::Complete()
|
||||
{
|
||||
NS_PRECONDITION(aComplete, "Null out param!");
|
||||
*aComplete = true;
|
||||
|
||||
if (!mCurrentRequest) {
|
||||
return NS_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t status;
|
||||
mCurrentRequest->GetImageStatus(&status);
|
||||
*aComplete =
|
||||
return
|
||||
(status &
|
||||
(imgIRequest::STATUS_LOAD_COMPLETE | imgIRequest::STATUS_ERROR)) != 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLImageElement::GetComplete(bool* aComplete)
|
||||
{
|
||||
NS_PRECONDITION(aComplete, "Null out param!");
|
||||
|
||||
*aComplete = Complete();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -197,7 +203,7 @@ HTMLImageElement::GetY(int32_t* aY)
|
||||
NS_IMETHODIMP
|
||||
HTMLImageElement::GetHeight(uint32_t* aHeight)
|
||||
{
|
||||
*aHeight = GetWidthHeightForImage(mCurrentRequest).height;
|
||||
*aHeight = Height();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -211,7 +217,7 @@ HTMLImageElement::SetHeight(uint32_t aHeight)
|
||||
NS_IMETHODIMP
|
||||
HTMLImageElement::GetWidth(uint32_t* aWidth)
|
||||
{
|
||||
*aWidth = GetWidthHeightForImage(mCurrentRequest).width;
|
||||
*aWidth = Width();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -482,28 +488,54 @@ HTMLImageElement::Initialize(nsISupports* aOwner, JSContext* aContext,
|
||||
return rv;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
HTMLImageElement::NaturalHeight()
|
||||
{
|
||||
if (!mCurrentRequest) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<imgIContainer> image;
|
||||
mCurrentRequest->GetImage(getter_AddRefs(image));
|
||||
if (!image) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t height;
|
||||
if (NS_SUCCEEDED(image->GetHeight(&height))) {
|
||||
return height;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLImageElement::GetNaturalHeight(uint32_t* aNaturalHeight)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aNaturalHeight);
|
||||
|
||||
*aNaturalHeight = 0;
|
||||
*aNaturalHeight = NaturalHeight();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
HTMLImageElement::NaturalWidth()
|
||||
{
|
||||
if (!mCurrentRequest) {
|
||||
return NS_OK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
nsCOMPtr<imgIContainer> image;
|
||||
mCurrentRequest->GetImage(getter_AddRefs(image));
|
||||
if (!image) {
|
||||
return NS_OK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t height;
|
||||
if (NS_SUCCEEDED(image->GetHeight(&height))) {
|
||||
*aNaturalHeight = height;
|
||||
int32_t width;
|
||||
if (NS_SUCCEEDED(image->GetWidth(&width))) {
|
||||
return width;
|
||||
}
|
||||
return NS_OK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -511,22 +543,8 @@ HTMLImageElement::GetNaturalWidth(uint32_t* aNaturalWidth)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aNaturalWidth);
|
||||
|
||||
*aNaturalWidth = 0;
|
||||
*aNaturalWidth = NaturalWidth();
|
||||
|
||||
if (!mCurrentRequest) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<imgIContainer> image;
|
||||
mCurrentRequest->GetImage(getter_AddRefs(image));
|
||||
if (!image) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int32_t width;
|
||||
if (NS_SUCCEEDED(image->GetWidth(&width))) {
|
||||
*aNaturalWidth = width;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -545,5 +563,12 @@ HTMLImageElement::GetCORSMode()
|
||||
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
|
||||
}
|
||||
|
||||
JSObject*
|
||||
HTMLImageElement::WrapNode(JSContext* aCx, JSObject* aScope,
|
||||
bool* aTriedToWrap)
|
||||
{
|
||||
return HTMLImageElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "nsImageLoadingContent.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIJSNativeInitializer.h"
|
||||
#include "imgRequestProxy.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -87,10 +88,91 @@ public:
|
||||
void MaybeLoadImage();
|
||||
virtual nsXPCClassInfo* GetClassInfo();
|
||||
virtual nsIDOMNode* AsDOMNode() { return this; }
|
||||
|
||||
bool IsMap()
|
||||
{
|
||||
return GetBoolAttr(nsGkAtoms::ismap);
|
||||
}
|
||||
void SetIsMap(bool aIsMap, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLBoolAttr(nsGkAtoms::ismap, aIsMap, aError);
|
||||
}
|
||||
uint32_t Width()
|
||||
{
|
||||
return GetWidthHeightForImage(mCurrentRequest).width;
|
||||
}
|
||||
void SetWidth(uint32_t aWidth, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLUnsignedIntAttr(nsGkAtoms::width, aWidth, aError);
|
||||
}
|
||||
uint32_t Height()
|
||||
{
|
||||
return GetWidthHeightForImage(mCurrentRequest).height;
|
||||
}
|
||||
void SetHeight(uint32_t aHeight, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLUnsignedIntAttr(nsGkAtoms::height, aHeight, aError);
|
||||
}
|
||||
uint32_t NaturalWidth();
|
||||
uint32_t NaturalHeight();
|
||||
bool Complete();
|
||||
int32_t Hspace()
|
||||
{
|
||||
return GetIntAttr(nsGkAtoms::hspace, 0);
|
||||
}
|
||||
void SetHspace(int32_t aHspace, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLIntAttr(nsGkAtoms::hspace, aHspace, aError);
|
||||
}
|
||||
int32_t Vspace()
|
||||
{
|
||||
return GetIntAttr(nsGkAtoms::vspace, 0);
|
||||
}
|
||||
void SetVspace(int32_t aVspace, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLIntAttr(nsGkAtoms::vspace, aVspace, aError);
|
||||
}
|
||||
|
||||
// The XPCOM versions of the following getters work for Web IDL bindings as well
|
||||
void SetAlt(const nsAString& aAlt, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::alt, aAlt, aError);
|
||||
}
|
||||
void SetSrc(const nsAString& aSrc, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::src, aSrc, aError);
|
||||
}
|
||||
void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
|
||||
}
|
||||
void SetUseMap(const nsAString& aUseMap, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::usemap, aUseMap, aError);
|
||||
}
|
||||
void SetName(const nsAString& aName, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::name, aName, aError);
|
||||
}
|
||||
void SetAlign(const nsAString& aAlign, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
|
||||
}
|
||||
void SetLongDesc(const nsAString& aLongDesc, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::longdesc, aLongDesc, aError);
|
||||
}
|
||||
void SetBorder(const nsAString& aBorder, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::border, aBorder, aError);
|
||||
}
|
||||
|
||||
protected:
|
||||
nsIntPoint GetXY();
|
||||
virtual void GetItemValueText(nsAString& text);
|
||||
virtual void SetItemValueText(const nsAString& text);
|
||||
virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope,
|
||||
bool *aTriedToWrap) MOZ_OVERRIDE;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -829,6 +829,13 @@ protected:
|
||||
|
||||
SetHTMLAttr(aName, value, aError);
|
||||
}
|
||||
void SetHTMLUnsignedIntAttr(nsIAtom* aName, uint32_t aValue, mozilla::ErrorResult& aError)
|
||||
{
|
||||
nsAutoString value;
|
||||
value.AppendInt(aValue);
|
||||
|
||||
SetHTMLAttr(aName, value, aError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for NS_IMPL_STRING_ATTR macro.
|
||||
|
@ -56,7 +56,25 @@ function reflectString(aParameters)
|
||||
|
||||
element[idlAttr] = null;
|
||||
// TODO: remove this ugly hack when null stringification will work as expected.
|
||||
if (element.localName == "textarea" && idlAttr == "wrap") {
|
||||
var todoAttrs = {
|
||||
col: [ "align", "vAlign", "ch" ],
|
||||
colgroup: [ "align", "vAlign", "ch" ],
|
||||
form: [ "acceptCharset", "name", "target" ],
|
||||
img: [ "align" ],
|
||||
input: [ "accept", "alt", "formTarget", "max", "min", "name", "pattern", "placeholder", "step", "defaultValue" ],
|
||||
link: [ "crossOrigin" ],
|
||||
script: [ "crossOrigin" ],
|
||||
source: [ "media" ],
|
||||
table: [ "border", "width" ],
|
||||
tbody: [ "align", "vAlign", "ch" ],
|
||||
td: [ "align", "vAlign", "ch" ],
|
||||
textarea: [ "name", "placeholder" ],
|
||||
tfoot: [ "align", "vAlign", "ch" ],
|
||||
th: [ "align", "vAlign", "ch" ],
|
||||
thead: [ "align", "vAlign", "ch" ],
|
||||
tr: [ "align", "vAlign", "ch" ],
|
||||
};
|
||||
if (!(element.localName in todoAttrs) || todoAttrs[element.localName].indexOf(idlAttr) == -1) {
|
||||
is(element.getAttribute(contentAttr), "null",
|
||||
"null should have been stringified to 'null'");
|
||||
is(element[idlAttr], "null", "null should have been stringified to 'null'");
|
||||
|
53
dom/webidl/HTMLImageElement.webidl
Normal file
53
dom/webidl/HTMLImageElement.webidl
Normal file
@ -0,0 +1,53 @@
|
||||
/* -*- 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/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* http://www.whatwg.org/specs/web-apps/current-work/#htmlimageelement
|
||||
* http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
|
||||
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
|
||||
* Opera Software ASA. You are granted a license to use, reproduce
|
||||
* and create derivative works of this document.
|
||||
*/
|
||||
|
||||
[NamedConstructor=Image(),
|
||||
NamedConstructor=Image(unsigned long width),
|
||||
NamedConstructor=Image(unsigned long width, unsigned long height)]
|
||||
interface HTMLImageElement : HTMLElement {
|
||||
[SetterThrows]
|
||||
attribute DOMString alt;
|
||||
[SetterThrows]
|
||||
attribute DOMString src;
|
||||
// attribute DOMString srcset;
|
||||
[SetterThrows]
|
||||
attribute DOMString crossOrigin;
|
||||
[SetterThrows]
|
||||
attribute DOMString useMap;
|
||||
[SetterThrows]
|
||||
attribute boolean isMap;
|
||||
[SetterThrows]
|
||||
attribute unsigned long width;
|
||||
[SetterThrows]
|
||||
attribute unsigned long height;
|
||||
readonly attribute unsigned long naturalWidth;
|
||||
readonly attribute unsigned long naturalHeight;
|
||||
readonly attribute boolean complete;
|
||||
/*};
|
||||
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
|
||||
partial interface HTMLImageElement {
|
||||
*/
|
||||
[SetterThrows]
|
||||
attribute DOMString name;
|
||||
[SetterThrows]
|
||||
attribute DOMString align;
|
||||
[SetterThrows]
|
||||
attribute unsigned long hspace;
|
||||
[SetterThrows]
|
||||
attribute unsigned long vspace;
|
||||
[SetterThrows]
|
||||
attribute DOMString longDesc;
|
||||
|
||||
[TreatNullAs=EmptyString,SetterThrows] attribute DOMString border;
|
||||
};
|
Loading…
Reference in New Issue
Block a user