From 13cb33fda33616cbe4132e3cd0290229b4c649eb Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Thu, 26 Feb 2009 20:04:42 +1300 Subject: [PATCH] Bug 479936 - Correctly handle sizing of video elements --- .../html/content/public/nsHTMLVideoElement.h | 7 +++ .../html/content/src/nsHTMLVideoElement.cpp | 45 +++++++++++++++++++ layout/generic/nsVideoFrame.cpp | 14 ------ .../ogg-video/aspect-ratio-3-ref.html | 8 ++++ .../reftests/ogg-video/aspect-ratio-3a.html | 7 +++ .../reftests/ogg-video/aspect-ratio-3b.html | 7 +++ layout/reftests/ogg-video/reftest.list | 2 + 7 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 layout/reftests/ogg-video/aspect-ratio-3-ref.html create mode 100644 layout/reftests/ogg-video/aspect-ratio-3a.html create mode 100644 layout/reftests/ogg-video/aspect-ratio-3b.html diff --git a/content/html/content/public/nsHTMLVideoElement.h b/content/html/content/public/nsHTMLVideoElement.h index 9dba6b83c0b6..b6d6ad7e3cd3 100644 --- a/content/html/content/public/nsHTMLVideoElement.h +++ b/content/html/content/public/nsHTMLVideoElement.h @@ -63,6 +63,13 @@ public: // nsIDOMHTMLVideoElement NS_DECL_NSIDOMHTMLVIDEOELEMENT + virtual PRBool ParseAttribute(PRInt32 aNamespaceID, + nsIAtom* aAttribute, + const nsAString& aValue, + nsAttrValue& aResult); + NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const; + virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const; + virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; // Returns the current video frame width and height. diff --git a/content/html/content/src/nsHTMLVideoElement.cpp b/content/html/content/src/nsHTMLVideoElement.cpp index 11ee9638bfd9..57542914c114 100644 --- a/content/html/content/src/nsHTMLVideoElement.cpp +++ b/content/html/content/src/nsHTMLVideoElement.cpp @@ -113,3 +113,48 @@ nsIntSize nsHTMLVideoElement::GetVideoSize(nsIntSize aDefaultSize) { return mMediaSize.width == -1 && mMediaSize.height == -1 ? aDefaultSize : mMediaSize; } + +PRBool +nsHTMLVideoElement::ParseAttribute(PRInt32 aNamespaceID, + nsIAtom* aAttribute, + const nsAString& aValue, + nsAttrValue& aResult) +{ + if (aAttribute == nsGkAtoms::width || aAttribute == nsGkAtoms::height) { + return aResult.ParseSpecialIntValue(aValue, PR_TRUE); + } + + return nsHTMLMediaElement::ParseAttribute(aNamespaceID, aAttribute, aValue, + aResult); +} + +static void +MapAttributesIntoRule(const nsMappedAttributes* aAttributes, + nsRuleData* aData) +{ + nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData); +} + +NS_IMETHODIMP_(PRBool) +nsHTMLVideoElement::IsAttributeMapped(const nsIAtom* aAttribute) const +{ + static const MappedAttributeEntry attributes[] = { + { &nsGkAtoms::width }, + { &nsGkAtoms::height }, + { nsnull } + }; + + static const MappedAttributeEntry* const map[] = { + attributes, + sCommonAttributeMap + }; + + return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map)); +} + +nsMapRuleToAttributesFunc +nsHTMLVideoElement::GetAttributeMappingFunction() const +{ + return &MapAttributesIntoRule; +} diff --git a/layout/generic/nsVideoFrame.cpp b/layout/generic/nsVideoFrame.cpp index 48194394e515..69d6092e53e6 100644 --- a/layout/generic/nsVideoFrame.cpp +++ b/layout/generic/nsVideoFrame.cpp @@ -330,20 +330,6 @@ nsSize nsVideoFrame::GetIntrinsicSize(nsIRenderingContext *aRenderingContext) nsresult rv; size = element->GetVideoSize(size); - if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::width)) { - PRInt32 width = -1; - rv = element->GetWidth(&width); - if (NS_SUCCEEDED(rv)) { - size.width = width; - } - } - if (element->HasAttr(kNameSpaceID_None, nsGkAtoms::height)) { - PRInt32 height = -1; - rv = element->GetHeight(&height); - if (NS_SUCCEEDED(rv)) { - size.height = height; - } - } } return nsSize(nsPresContext::CSSPixelsToAppUnits(size.width), diff --git a/layout/reftests/ogg-video/aspect-ratio-3-ref.html b/layout/reftests/ogg-video/aspect-ratio-3-ref.html new file mode 100644 index 000000000000..60fe29702fb1 --- /dev/null +++ b/layout/reftests/ogg-video/aspect-ratio-3-ref.html @@ -0,0 +1,8 @@ + + + + + + diff --git a/layout/reftests/ogg-video/aspect-ratio-3a.html b/layout/reftests/ogg-video/aspect-ratio-3a.html new file mode 100644 index 000000000000..eea353e9898d --- /dev/null +++ b/layout/reftests/ogg-video/aspect-ratio-3a.html @@ -0,0 +1,7 @@ + + + + + + diff --git a/layout/reftests/ogg-video/aspect-ratio-3b.html b/layout/reftests/ogg-video/aspect-ratio-3b.html new file mode 100644 index 000000000000..bfcd34ad6f6a --- /dev/null +++ b/layout/reftests/ogg-video/aspect-ratio-3b.html @@ -0,0 +1,7 @@ + + + + + + diff --git a/layout/reftests/ogg-video/reftest.list b/layout/reftests/ogg-video/reftest.list index 295f5b174e75..25829ed1ed03 100644 --- a/layout/reftests/ogg-video/reftest.list +++ b/layout/reftests/ogg-video/reftest.list @@ -2,6 +2,8 @@ == aspect-ratio-1b.html aspect-ratio-1-ref.html == aspect-ratio-2a.html aspect-ratio-2-ref.html == aspect-ratio-2b.html aspect-ratio-2-ref.html +== aspect-ratio-3a.html aspect-ratio-3-ref.html +== aspect-ratio-3b.html aspect-ratio-3-ref.html == basic-1.html basic-1-ref.html == canvas-1a.html basic-1-ref.html == canvas-1b.html basic-1-ref.html