Bug 42999 - Add a Chromium WebKit API for drawing text
Summary: Add a Chromium WebKit API for drawing text
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC All
: P2 Normal
Assignee: Brett Wilson (Google)
Depends on:
Reported: 2010-07-26 14:00 PDT by Brett Wilson (Google)
Modified: 2010-07-27 14:31 PDT (History)
2 users (show)

See Also:

First patch (23.48 KB, patch)
2010-07-26 14:02 PDT, Brett Wilson (Google)
no flags Details | Formatted Diff | Diff
Patch v2 w/ ChangeLog (33.84 KB, patch)
2010-07-27 12:31 PDT, Brett Wilson (Google)
fishd: review-
Details | Formatted Diff | Diff
Patch v3 (35.73 KB, patch)
2010-07-27 13:46 PDT, Brett Wilson (Google)
no flags Details | Formatted Diff | Diff
Patch v4 (35.72 KB, patch)
2010-07-27 13:51 PDT, Brett Wilson (Google)
fishd: review+
fishd: commit-queue-
Details | Formatted Diff | Diff
Final patch for reference (35.75 KB, patch)
2010-07-27 14:11 PDT, Brett Wilson (Google)
brettw: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brett Wilson (Google) 2010-07-26 14:00:40 PDT
We would like to hook up the WebKit port's text drawing to random canvases, so we should expose something in the Chromium WebKit API to do this.
Comment 1 Brett Wilson (Google) 2010-07-26 14:02:09 PDT
Created attachment 62603 [details]
First patch

This is missing a ChangeLog (currently fixing my checkout and can't run prepare-Changelog) but I'm hoping to get some initial feedback to get this started.
Comment 2 Darin Fisher (:fishd, Google) 2010-07-26 14:16:25 PDT
unlike webcore, the style for enums at the webkit layer is of the form:

  enum Foo {

so, ...

  enum Family {
  enum Smoothing {
  enum Weight {

i would probably just create WebTextRun instead of making it be an inner class of WebFont.  it seems like it need not be specific to WebFont.

i have some more nits, but the review tool is not letting me annotate the patch right now.
Comment 3 Brett Wilson (Google) 2010-07-27 12:31:42 PDT
Created attachment 62727 [details]
Patch v2 w/ ChangeLog

This renames the enums, adds letter and word spacing, and adds assertions that make sure the WebKit API matches WebCore's enums
Comment 4 Darin Fisher (:fishd, Google) 2010-07-27 12:46:29 PDT
Comment on attachment 62727 [details]
Patch v2 w/ ChangeLog

 +      WEBKIT_API static WebFont* Create(const WebFontDescription&);
nit: Create -> create

how do I destroy a WebFont?  i don't see a virtual destructor.

comments below on the interface are made with ignorance about
what the .cpp file looks like.  i wanted to see if the API made
sense to me without knowledge of how it is implemented.

 +      virtual void drawText(WebCanvas*, const WebTextRun&, const WebFloatPoint&, WebColor, const WebRect& clip, bool canvasIsOpaque,
it might be helpful to document some of these parameters.  it is not clear
to me what from and to mean.  are they specifying subranges of WebTextRun?
in which case fromChar, toChar might be better.

maybe you should give a name to the WebFloatPoint parameter, or at least
describe what it is.  i'm guessing it is the origin of the text run, but
does that mean top-left?

 +      virtual int width(const WebTextRun&) const = 0;
nit: calculateWidth might be a nicer name

 +      virtual int offsetForPosition(const WebTextRun&, float position, bool includePartialGlyphs) const = 0;
i think this method could use some documentation.  is this identifying
the character offset?

nit: we have a convention of making the WEBKIT_IMPLEMENTATION
section be the last part of the public section (or private
section if there is one).  i would just group this one with
the conversion operator.

 +      // Not members of WebCore::FontDescription, but used in the places where we
nit: i tend to avoid comments in the WebKit API headers that refer to
WebCore since they can get out-of-date easily.  no one making changes
to WebCore will ever think to update WebKit API headers.  it is better
to just make the comments standalone and make sense without knowledge
of WebCore.

 +      WebTextRun(const WebString& t, bool isRtl, bool hasDirectionalOverride)
style-nit: isRTL <- webkit style is to capitalize acronyms unless
they are at the start of a term.

same nit about moving this to the end of the "public" section.

 +  COMPILE_ASSERT_MATCHING_ENUM(WebFontDescription::GenericFamilyNone, FontDescription::NoFamily);
nit: insert in sorted order.  it makes it easier to keep this
file organized.

 +  WebFontDescription::operator WebCore::FontDescription() const {
nit: opening bracket on the next line

we usually add a 'using namespace WebCore' so that we can avoid
the WebCore:: prefix down below.

 +      // FIXME(brettw) hook canvasIsOpaque up to the platform-specific indicators
nit: FIXME(foo) -> FIXME

 +      return WebCore::TextRun(text, false, 0, 0, rtl, directionalOverride);
nit: you can drop the WebCore:: prefix
Comment 5 Brett Wilson (Google) 2010-07-27 13:46:25 PDT
Created attachment 62740 [details]
Patch v3

Comments addressed.
Comment 6 WebKit Review Bot 2010-07-27 13:49:04 PDT
Attachment 62740 [details] did not pass style-queue:

Failed to run "['WebKitTools/Scripts/check-webkit-style']" exit_code: 1
WebKit/chromium/public/WebFontDescription.h:104:  One space before end of line comments  [whitespace/comments] [5]
WebKit/chromium/src/WebFontDescription.cpp:56:  font_family is incorrectly named. Don't use underscores in your identifier names.  [readability/naming] [4]
Total errors found: 2 in 12 files

If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Brett Wilson (Google) 2010-07-27 13:51:38 PDT
Created attachment 62741 [details]
Patch v4

Pacify the style bot
Comment 8 Darin Fisher (:fishd, Google) 2010-07-27 14:06:29 PDT
Comment on attachment 62741 [details]
Patch v4

 +      WEBKIT_API static WebFont* Create(const WebFontDescription&);
nit: Create -> create

 +      // run to draw. If |to| is -1, the enture run will be drawn.
nit: enture -> entire

 +      // |leftBaseline| position. |h| indicates the height of the selection rect
nit: h -> height

 +      WebTextRun(const WebString& t, bool isRtl, bool hasDirectionalOverride)
nit: isRtl -> isRTL so this can compile :-)

 +  WebTextRun::operator WebCore::TextRun() const
nit: no need for WebCore:: prefix

R=me with those nits fixed
Comment 9 Brett Wilson (Google) 2010-07-27 14:11:12 PDT
Created attachment 62744 [details]
Final patch for reference
Comment 10 Brett Wilson (Google) 2010-07-27 14:31:57 PDT
Fixed in r64160