Bug 1676952 - Fix HTMLImageElement.x/y to match the spec. r=emilio

Per https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlimageelement-interface:

> The x attribute, on getting, must return the x-coordinate of the left
> border edge of the first CSS layout box associated with the element,
> relative to the initial containing block origin, ignoring any
> transforms that apply to the element and its ancestors, or zero if
> there is no CSS layout box.

But we were using GetClosestLayer which stops at the first abspos
containing block or scroll frame.

Differential Revision: https://phabricator.services.mozilla.com/D151263
This commit is contained in:
Emilio Cobos Álvarez
2022-07-07 16:28:51 +00:00
parent 5e6230a45e
commit 693130c052
4 changed files with 39 additions and 12 deletions

View File

@@ -5,9 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/HTMLImageElement.h"
#include "mozilla/PresShell.h"
#include "mozilla/dom/BindContext.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/HTMLImageElementBinding.h"
#include "mozilla/dom/BindContext.h"
#include "mozilla/dom/NameSpaceConstants.h"
#include "nsGenericHTMLElement.h"
#include "nsGkAtoms.h"
@@ -189,9 +190,8 @@ CSSIntPoint HTMLImageElement::GetXY() {
if (!frame) {
return CSSIntPoint(0, 0);
}
nsIFrame* layer = nsLayoutUtils::GetClosestLayer(frame->GetParent());
return CSSIntPoint::FromAppUnitsRounded(frame->GetOffsetTo(layer));
return CSSIntPoint::FromAppUnitsRounded(
frame->GetOffsetTo(frame->PresShell()->GetRootFrame()));
}
int32_t HTMLImageElement::X() { return GetXY().x; }