Bug 51566 - TextMetrics::width is an integer, but the member is a float
Summary: TextMetrics::width is an integer, but the member is a float
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
Depends on:
Blocks: 51551
  Show dependency treegraph
Reported: 2010-12-23 15:20 PST by Evan Martin
Modified: 2010-12-24 03:50 PST (History)
4 users (show)

See Also:

Patch (1.45 KB, patch)
2010-12-23 16:43 PST, Evan Martin
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Evan Martin 2010-12-23 15:20:43 PST
In WebCore/html/TextMetrics.idl it says:
    readonly attribute float width;
in .../TextMetrics.h:
    float m_width;

But there's a getter with this confusing comment:

    // FIXME: Is coercing to an integer value intentional? If so, there should be a static_cast<unsigned>() here.
    unsigned width() const { return m_width; }

From my greps around, it appears this getter is unused, but I unsure how the idl interacts with this (perhaps the idl generates code that calls width().)
Comment 1 Evan Martin 2010-12-23 15:26:15 PST
CC hyatt, original author of the code (correct bug this time)
Comment 2 Evan Martin 2010-12-23 15:28:41 PST
in LayoutTests/fast/canvas/canvas-text-baseline.html
if I dump out all the widths found by ctx.measureText(text).width
they are always integers.  Not sure if it's intentional (or perhaps in Chrome we always have integer width fonts for other reasons)
Comment 3 Evan Martin 2010-12-23 16:26:23 PST
I tried changing it to a float and still got integers out.

Spec says the width should be "CSS pixels", which I think can be floating point.  I'll upload a patch and see what y'all think.

Comment 4 Evan Martin 2010-12-23 16:43:13 PST
Created attachment 77385 [details]
Comment 5 Evan Martin 2010-12-23 16:44:34 PST
I tried modifying the test to use text of width 32.1 pixels, but even after this change the "width" field came out as an integer.  Again, this could be due to some other code in Chrome rounding text widths.
Comment 6 WebKit Commit Bot 2010-12-24 03:49:32 PST
The commit-queue encountered the following flaky tests while processing attachment 77385 [details]:

inspector/elements-panel-styles.html bug 50987 (author: pfeldman@chromium.org)
The commit-queue is continuing to process your patch.
Comment 7 WebKit Commit Bot 2010-12-24 03:50:48 PST
Comment on attachment 77385 [details]

Clearing flags on attachment: 77385

Committed r74628: <http://trac.webkit.org/changeset/74628>
Comment 8 WebKit Commit Bot 2010-12-24 03:50:55 PST
All reviewed patches have been landed.  Closing bug.