(In reply to Emilio Cobos Álvarez (:emilio) from comment #5)
The real regressor here is bug 1744009.
The main issue is that this code doesn't account for letter/word-spacing.
We could most definitely pass down that information all the way through
nsFontMetrics::GetWidth, which uses a
StubPropertyProvider here where we could enable spacing.
Jonathan, is that the best path forward? I see the Canvas2d provider already has some support for letter / word-spacing. Do you have a better idea to avoid duplicating that code?
I guess that'd probably be the most straightforward, though it's a bit sad to duplicate more and more of the functionality between HTML reflow (nsTextFrame), canvas2d text, and now the nsFontMetrics utilities. (If we add spacing support to GetWidth, we should add it to DrawString as well for consistency.)
In theory, it seems like a cleaner method would be to create an nsTextFrame for the option, with the appropriate style, and query its intrinsic width, but that might be a significantly more heavyweight approach; if there are lots of options, that'd mean an awful lot of temporary frame-munging just to measure the longest one.