Skip to content

Commit 8a89e39

Browse files
committed
Bug 1514074 - Retarget results of offset* DOM APIs. r=smaug
Per w3c/csswg-drafts#159. The test is imported from WebKit, who has already implemented this, with a few fixes to avoid duplicate test names and non-undefined return values from add_cleanup. See the diff attached to the bug. Differential Revision: https://phabricator.services.mozilla.com/D15938 UltraBlame original commit: e0a5cb126f2f084e5f7f3d5f0be0222a7fd67479
1 parent f9ca91a commit 8a89e39

File tree

2 files changed

+2328
-23
lines changed

2 files changed

+2328
-23
lines changed

dom/html/nsGenericHTMLElement.cpp

+210-23
Original file line numberDiff line numberDiff line change
@@ -1591,34 +1591,38 @@ return
15911591
false
15921592
;
15931593
}
1594+
struct
1595+
OffsetResult
1596+
{
15941597
Element
15951598
*
1596-
nsGenericHTMLElement
1597-
:
1598-
:
1599-
GetOffsetRect
1600-
(
1601-
CSSIntRect
1602-
&
1603-
aRect
1604-
)
1605-
{
1606-
aRect
1599+
mParent
16071600
=
1601+
nullptr
1602+
;
16081603
CSSIntRect
1604+
mRect
1605+
;
1606+
}
1607+
;
1608+
static
1609+
OffsetResult
1610+
GetUnretargetedOffsetsFor
16091611
(
1612+
const
1613+
Element
1614+
&
1615+
aElement
16101616
)
1611-
;
1617+
{
16121618
nsIFrame
16131619
*
16141620
frame
16151621
=
1622+
aElement
1623+
.
16161624
GetPrimaryFrame
16171625
(
1618-
FlushType
1619-
:
1620-
:
1621-
Layout
16221626
)
16231627
;
16241628
if
@@ -1628,7 +1632,8 @@ frame
16281632
)
16291633
{
16301634
return
1631-
nullptr
1635+
{
1636+
}
16321637
;
16331638
}
16341639
nsIFrame
@@ -1671,6 +1676,8 @@ Element
16711676
*
16721677
docElement
16731678
=
1679+
aElement
1680+
.
16741681
GetComposedDoc
16751682
(
16761683
)
@@ -2085,6 +2092,8 @@ here
20852092
.
20862093
offsetParent
20872094
=
2095+
aElement
2096+
.
20882097
GetComposedDoc
20892098
(
20902099
)
@@ -2266,29 +2275,207 @@ MoveTo
22662275
origin
22672276
)
22682277
;
2269-
aRect
2270-
=
2278+
return
2279+
{
2280+
Element
2281+
:
2282+
:
2283+
FromNodeOrNull
2284+
(
2285+
offsetParent
2286+
)
22712287
CSSIntRect
22722288
:
22732289
:
22742290
FromAppUnitsRounded
22752291
(
22762292
rcFrame
22772293
)
2294+
}
2295+
;
2296+
}
2297+
static
2298+
bool
2299+
ShouldBeRetargeted
2300+
(
2301+
const
2302+
Element
2303+
&
2304+
aReferenceElement
2305+
const
2306+
Element
2307+
&
2308+
aElementToMaybeRetarget
2309+
)
2310+
{
2311+
ShadowRoot
2312+
*
2313+
shadow
2314+
=
2315+
aElementToMaybeRetarget
2316+
.
2317+
GetContainingShadow
2318+
(
2319+
)
22782320
;
2321+
if
2322+
(
2323+
!
2324+
shadow
2325+
)
2326+
{
22792327
return
2280-
offsetParent
2281-
?
2282-
offsetParent
2328+
false
2329+
;
2330+
}
2331+
for
2332+
(
2333+
ShadowRoot
2334+
*
2335+
scope
2336+
=
2337+
aReferenceElement
2338+
.
2339+
GetContainingShadow
2340+
(
2341+
)
2342+
;
2343+
scope
2344+
;
2345+
scope
2346+
=
2347+
scope
22832348
-
22842349
>
2285-
AsElement
2350+
Host
2351+
(
2352+
)
2353+
-
2354+
>
2355+
GetContainingShadow
22862356
(
22872357
)
2358+
)
2359+
{
2360+
if
2361+
(
2362+
scope
2363+
=
2364+
=
2365+
shadow
2366+
)
2367+
{
2368+
return
2369+
false
2370+
;
2371+
}
2372+
}
2373+
return
2374+
true
2375+
;
2376+
}
2377+
Element
2378+
*
2379+
nsGenericHTMLElement
2380+
:
22882381
:
2382+
GetOffsetRect
2383+
(
2384+
CSSIntRect
2385+
&
2386+
aRect
2387+
)
2388+
{
2389+
aRect
2390+
=
2391+
CSSIntRect
2392+
(
2393+
)
2394+
;
2395+
if
2396+
(
2397+
!
2398+
GetPrimaryFrame
2399+
(
2400+
FlushType
2401+
:
2402+
:
2403+
Layout
2404+
)
2405+
)
2406+
{
2407+
return
22892408
nullptr
22902409
;
22912410
}
2411+
OffsetResult
2412+
thisResult
2413+
=
2414+
GetUnretargetedOffsetsFor
2415+
(
2416+
*
2417+
this
2418+
)
2419+
;
2420+
aRect
2421+
=
2422+
thisResult
2423+
.
2424+
mRect
2425+
;
2426+
Element
2427+
*
2428+
parent
2429+
=
2430+
thisResult
2431+
.
2432+
mParent
2433+
;
2434+
while
2435+
(
2436+
parent
2437+
&
2438+
&
2439+
ShouldBeRetargeted
2440+
(
2441+
*
2442+
this
2443+
*
2444+
parent
2445+
)
2446+
)
2447+
{
2448+
OffsetResult
2449+
result
2450+
=
2451+
GetUnretargetedOffsetsFor
2452+
(
2453+
*
2454+
parent
2455+
)
2456+
;
2457+
aRect
2458+
+
2459+
=
2460+
result
2461+
.
2462+
mRect
2463+
.
2464+
TopLeft
2465+
(
2466+
)
2467+
;
2468+
parent
2469+
=
2470+
result
2471+
.
2472+
mParent
2473+
;
2474+
}
2475+
return
2476+
parent
2477+
;
2478+
}
22922479
bool
22932480
nsGenericHTMLElement
22942481
:

0 commit comments

Comments
 (0)