mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
bug 683855 implement width and height attributes for html inputs r=bz
This commit is contained in:
parent
af3b8ecbfc
commit
b3d3815263
@ -4286,3 +4286,41 @@ nsGenericHTMLElement::GetProperties(nsIDOMHTMLPropertiesCollection** aReturn)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsSize
|
||||
nsGenericHTMLElement::GetWidthHeightForImage(imgIRequest *aImageRequest)
|
||||
{
|
||||
nsSize size(0,0);
|
||||
|
||||
nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
|
||||
|
||||
if (frame) {
|
||||
size = frame->GetContentRect().Size();
|
||||
|
||||
size.width = nsPresContext::AppUnitsToIntCSSPixels(size.width);
|
||||
size.height = nsPresContext::AppUnitsToIntCSSPixels(size.height);
|
||||
} else {
|
||||
const nsAttrValue* value;
|
||||
nsCOMPtr<imgIContainer> image;
|
||||
if (aImageRequest) {
|
||||
aImageRequest->GetImage(getter_AddRefs(image));
|
||||
}
|
||||
|
||||
if ((value = GetParsedAttr(nsGkAtoms::width)) &&
|
||||
value->Type() == nsAttrValue::eInteger) {
|
||||
size.width = value->GetIntegerValue();
|
||||
} else if (image) {
|
||||
image->GetWidth(&size.width);
|
||||
}
|
||||
|
||||
if ((value = GetParsedAttr(nsGkAtoms::height)) &&
|
||||
value->Type() == nsAttrValue::eInteger) {
|
||||
size.height = value->GetIntegerValue();
|
||||
} else if (image) {
|
||||
image->GetHeight(&size.height);
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(size.width >= 0, "negative width");
|
||||
NS_ASSERTION(size.height >= 0, "negative height");
|
||||
return size;
|
||||
}
|
||||
|
@ -147,6 +147,11 @@ public:
|
||||
nsresult ClearDataset();
|
||||
nsresult GetContextMenu(nsIDOMHTMLMenuElement** aContextMenu);
|
||||
|
||||
/**
|
||||
* Get width and height, using given image request if attributes are unset.
|
||||
*/
|
||||
nsSize GetWidthHeightForImage(imgIRequest *aImageRequest);
|
||||
|
||||
protected:
|
||||
nsresult GetMarkup(bool aIncludeSelf, nsAString& aMarkup);
|
||||
|
||||
|
@ -196,49 +196,10 @@ nsHTMLImageElement::GetY(PRInt32* aY)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsSize
|
||||
nsHTMLImageElement::GetWidthHeight()
|
||||
{
|
||||
nsSize size(0,0);
|
||||
|
||||
nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
|
||||
|
||||
if (frame) {
|
||||
size = frame->GetContentRect().Size();
|
||||
|
||||
size.width = nsPresContext::AppUnitsToIntCSSPixels(size.width);
|
||||
size.height = nsPresContext::AppUnitsToIntCSSPixels(size.height);
|
||||
} else {
|
||||
const nsAttrValue* value;
|
||||
nsCOMPtr<imgIContainer> image;
|
||||
if (mCurrentRequest) {
|
||||
mCurrentRequest->GetImage(getter_AddRefs(image));
|
||||
}
|
||||
|
||||
if ((value = GetParsedAttr(nsGkAtoms::width)) &&
|
||||
value->Type() == nsAttrValue::eInteger) {
|
||||
size.width = value->GetIntegerValue();
|
||||
} else if (image) {
|
||||
image->GetWidth(&size.width);
|
||||
}
|
||||
|
||||
if ((value = GetParsedAttr(nsGkAtoms::height)) &&
|
||||
value->Type() == nsAttrValue::eInteger) {
|
||||
size.height = value->GetIntegerValue();
|
||||
} else if (image) {
|
||||
image->GetHeight(&size.height);
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(size.width >= 0, "negative width");
|
||||
NS_ASSERTION(size.height >= 0, "negative height");
|
||||
return size;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::GetHeight(PRUint32* aHeight)
|
||||
{
|
||||
*aHeight = GetWidthHeight().height;
|
||||
*aHeight = GetWidthHeightForImage(mCurrentRequest).height;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -246,17 +207,13 @@ nsHTMLImageElement::GetHeight(PRUint32* aHeight)
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::SetHeight(PRUint32 aHeight)
|
||||
{
|
||||
nsAutoString val;
|
||||
val.AppendInt(aHeight);
|
||||
|
||||
return nsGenericHTMLElement::SetAttr(kNameSpaceID_None, nsGkAtoms::height,
|
||||
val, true);
|
||||
return nsGenericHTMLElement::SetUnsignedIntAttr(nsGkAtoms::height, aHeight);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::GetWidth(PRUint32* aWidth)
|
||||
{
|
||||
*aWidth = GetWidthHeight().width;
|
||||
*aWidth = GetWidthHeightForImage(mCurrentRequest).width;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -264,11 +221,7 @@ nsHTMLImageElement::GetWidth(PRUint32* aWidth)
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::SetWidth(PRUint32 aWidth)
|
||||
{
|
||||
nsAutoString val;
|
||||
val.AppendInt(aWidth);
|
||||
|
||||
return nsGenericHTMLElement::SetAttr(kNameSpaceID_None, nsGkAtoms::width,
|
||||
val, true);
|
||||
return nsGenericHTMLElement::SetUnsignedIntAttr(nsGkAtoms::width, aWidth);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -102,7 +102,6 @@ public:
|
||||
virtual nsIDOMNode* AsDOMNode() { return this; }
|
||||
protected:
|
||||
nsIntPoint GetXY();
|
||||
nsSize GetWidthHeight();
|
||||
virtual void GetItemValueText(nsAString& text);
|
||||
virtual void SetItemValueText(const nsAString& text);
|
||||
};
|
||||
|
@ -858,6 +858,19 @@ NS_IMPL_STRING_ATTR(nsHTMLInputElement, Placeholder, placeholder)
|
||||
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLInputElement, Type, type,
|
||||
kInputDefaultType->tag)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::GetHeight(PRUint32 *aHeight)
|
||||
{
|
||||
*aHeight = GetWidthHeightForImage(mCurrentRequest).height;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::SetHeight(PRUint32 aHeight)
|
||||
{
|
||||
return nsGenericHTMLElement::SetUnsignedIntAttr(nsGkAtoms::height, aHeight);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::GetIndeterminate(bool* aValue)
|
||||
{
|
||||
@ -889,6 +902,19 @@ nsHTMLInputElement::SetIndeterminate(bool aValue)
|
||||
return SetIndeterminateInternal(aValue, true);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::GetWidth(PRUint32 *aWidth)
|
||||
{
|
||||
*aWidth = GetWidthHeightForImage(mCurrentRequest).width;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::SetWidth(PRUint32 aWidth)
|
||||
{
|
||||
return nsGenericHTMLElement::SetUnsignedIntAttr(nsGkAtoms::width, aWidth);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::GetValue(nsAString& aValue)
|
||||
{
|
||||
|
@ -99,7 +99,12 @@ reflectString({
|
||||
otherValues: [ "_blank", "_self", "_parent", "_top" ],
|
||||
});
|
||||
|
||||
// TODO: height (non-negative integer)
|
||||
// .height
|
||||
reflectUnsignedInt({
|
||||
element: document.createElement("input"),
|
||||
attribute: "height",
|
||||
nonZero: false
|
||||
});
|
||||
|
||||
// .indeterminate doesn't reflect a content attribute.
|
||||
|
||||
@ -204,7 +209,12 @@ todo("valueAsNumber" in document.createElement("input"),
|
||||
todo("selectedOption" in document.createElement("input"),
|
||||
"selectedOption isn't implemented yet");
|
||||
|
||||
// TODO: width (non-negative integer)
|
||||
// .width
|
||||
reflectUnsignedInt({
|
||||
element: document.createElement("input"),
|
||||
attribute: "width",
|
||||
nonZero: false
|
||||
});
|
||||
|
||||
// .willValidate doesn't reflect a content attribute.
|
||||
// .validity doesn't reflect a content attribute.
|
||||
|
@ -20,7 +20,7 @@ interface nsIDOMValidityState;
|
||||
* http://www.whatwg.org/specs/web-apps/current-work/
|
||||
*/
|
||||
|
||||
[scriptable, uuid(05FEDF7E-3050-4143-AB97-B994F3CC9329)]
|
||||
[scriptable, uuid(ac2e2b14-b987-452c-a071-5823b2406b85)]
|
||||
interface nsIDOMHTMLInputElement : nsIDOMHTMLElement
|
||||
{
|
||||
attribute DOMString accept;
|
||||
@ -40,6 +40,7 @@ interface nsIDOMHTMLInputElement : nsIDOMHTMLElement
|
||||
|
||||
readonly attribute nsIDOMFileList files;
|
||||
|
||||
attribute unsigned long height;
|
||||
attribute boolean indeterminate;
|
||||
|
||||
readonly attribute nsIDOMHTMLElement list;
|
||||
@ -56,6 +57,7 @@ interface nsIDOMHTMLInputElement : nsIDOMHTMLElement
|
||||
attribute DOMString align;
|
||||
|
||||
attribute unsigned long size;
|
||||
attribute unsigned long width;
|
||||
attribute DOMString src;
|
||||
|
||||
attribute DOMString type;
|
||||
|
Loading…
Reference in New Issue
Block a user