Bug 62478 - RenderText::absoluteRectsForRange() and absoluteQuadsForRange() have nearly duplicate code
Summary: RenderText::absoluteRectsForRange() and absoluteQuadsForRange() have nearly d...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Emil A Eklund
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-10 14:16 PDT by David Kilzer (:ddkilzer)
Modified: 2011-08-04 14:58 PDT (History)
9 users (show)

See Also:


Attachments
Patch (8.41 KB, patch)
2011-07-25 17:30 PDT, Emil A Eklund
no flags Details | Formatted Diff | Diff
Patch for landing (9.19 KB, patch)
2011-07-26 10:05 PDT, Emil A Eklund
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2011-06-10 14:16:03 PDT
* SUMMARY
In RenderText::absoluteRectsForRange(), the following code is used in an else clause:

            IntRect r = box->selectionRect(0, 0, start, realEnd);
            if (!r.isEmpty()) {
                if (!useSelectionHeight) {

In RenderText::absoluteQuadsForRange(), the same code uses a slightly different check:

            IntRect r = box->selectionRect(0, 0, start, realEnd);
            if (r.height()) {
                if (!useSelectionHeight) {

It seems like these methods should be using the same check, and it would be great if the duplicate code could be extracted into a local static method.
Comment 1 Simon Fraser (smfr) 2011-06-10 14:17:00 PDT
From bug 34239
Comment 2 Emil A Eklund 2011-07-25 17:30:30 PDT
Created attachment 101949 [details]
Patch
Comment 3 Simon Fraser (smfr) 2011-07-25 17:33:00 PDT
Comment on attachment 101949 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=101949&action=review

> Source/WebCore/rendering/RenderText.cpp:281
> +            // change the height and y position because selectionRect uses selection-specific values

Please change this to use sentence case and end with a period.

> Source/WebCore/rendering/RenderText.cpp:324
> +            if (!rect.size().isZero())

Don't we have rect.isEmpty()?

> Source/WebCore/rendering/RenderText.cpp:405
> +            if (!rect.size().isZero())

Ditto.
Comment 4 Emil A Eklund 2011-07-26 10:05:36 PDT
Created attachment 102019 [details]
Patch for landing
Comment 5 Emil A Eklund 2011-07-26 10:07:58 PDT
Thanks for the quick review.

(In reply to comment #3)
> (From update of attachment 101949 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=101949&action=review
> 
> > Source/WebCore/rendering/RenderText.cpp:281
> > +            // change the height and y position because selectionRect uses selection-specific values
> 
> Please change this to use sentence case and end with a period.

Done.

> 
> > Source/WebCore/rendering/RenderText.cpp:324
> > +            if (!rect.size().isZero())
> 
> Don't we have rect.isEmpty()?

We do but I want to check for zero as opposed to empty here as we have a couple of tests that expect getClientRects to return a rect with a zero width.

Added FloatRect::isZero that calls FloatSize::isZero and changed the code in RenderText to use that method.
Comment 6 WebKit Review Bot 2011-07-26 10:47:19 PDT
Comment on attachment 102019 [details]
Patch for landing

Clearing flags on attachment: 102019

Committed r91763: <http://trac.webkit.org/changeset/91763>
Comment 7 WebKit Review Bot 2011-07-26 10:47:26 PDT
All reviewed patches have been landed.  Closing bug.
Comment 9 Simon Fraser (smfr) 2011-08-04 14:58:44 PDT
Comment on attachment 102019 [details]
Patch for landing

View in context: https://bugs.webkit.org/attachment.cgi?id=102019&action=review

> Source/WebCore/rendering/RenderText.cpp:407
> +            FloatRect rect = absoluteQuadForTextBox(box, start, end, useSelectionHeight);
> +            if (!rect.isZero())
> +                quads.append(localToAbsoluteQuad(rect));

This is wrong. It converts local to absolute twice.