Bug 51950 - Word boundary finding code does not stop when entering or leaving a floating element
Summary: Word boundary finding code does not stop when entering or leaving a floating ...
Status: ASSIGNED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Justin Garcia
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2011-01-05 13:26 PST by Justin Garcia
Modified: 2024-04-10 07:27 PDT (History)
11 users (show)

See Also:


Attachments
test case (155 bytes, text/html)
2011-01-05 13:27 PST, Justin Garcia
no flags Details
patch (85.08 KB, patch)
2011-01-07 13:08 PST, Justin Garcia
no flags Details | Formatted Diff | Diff
updated patch (65.39 KB, patch)
2011-01-07 13:56 PST, Justin Garcia
no flags Details | Formatted Diff | Diff
patch (65.11 KB, patch)
2011-01-13 15:44 PST, Justin Garcia
no flags Details | Formatted Diff | Diff
patch (64.08 KB, patch)
2011-01-13 15:53 PST, Justin Garcia
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Garcia 2011-01-05 13:26:59 PST
Open the attached test case and double click on the word "hello".  The following word, "world", which is in a floating div, it also selected, as though it is part of "hello".
Comment 1 Justin Garcia 2011-01-05 13:27:50 PST
Created attachment 78035 [details]
test case
Comment 2 Justin Garcia 2011-01-05 13:33:24 PST
<rdar://problem/8824711>
Comment 3 Justin Garcia 2011-01-07 13:08:43 PST
Created attachment 78261 [details]
patch
Comment 4 Justin Garcia 2011-01-07 13:56:34 PST
Created attachment 78265 [details]
updated patch
Comment 5 mitz 2011-01-07 14:06:04 PST
Comment on attachment 78265 [details]
updated patch

Will this cause problems with “drop caps” done as
    <span style="font-size: x-large; float: left;">O</span>nce upon a time
?
Comment 6 Justin Garcia 2011-01-07 14:41:26 PST
(In reply to comment #5)
> (From update of attachment 78265 [details])
> Will this cause problems with “drop caps” done as
>     <span style="font-size: x-large; float: left;">O</span>nce upon a time
> ?

Yes the 'O' will be treated as a separate word when selecting by word and for spell checking, but getting that case right would require substantial changes to text iterators: they'll have to keep track of the previous chunk of text, and look ahead to the next chunk to know whether or not to emit for a floating element like that.  Those changes warrant a new bug I think.
Comment 7 Ryosuke Niwa 2011-01-10 13:50:19 PST
Comment on attachment 78265 [details]
updated patch

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

> WebCore/editing/TextIterator.cpp:766
> +        if (renderer->isRenderBlock())
> +            return ((RenderBlock*)renderer)->height();

I don't quite understand why we need to check the height here.  Also, does this work when writing mode is vertical?
Comment 8 Justin Garcia 2011-01-13 15:44:27 PST
Created attachment 78868 [details]
patch

> I don't quite understand why we need to check the height here.  Also, does this work when writing mode is vertical?

We don't emit for a floating or positioned element that doesn't take up any space.  This is demonstrated in:

editing/pasteboard/newlines-around-floating-or-positioned.html

I check the element's width(), too.  Yes, we will emit if regardless of the writing mode.
Comment 9 Justin Garcia 2011-01-13 15:53:00 PST
Created attachment 78870 [details]
patch

Updated patch.
Comment 10 mitz 2011-01-13 16:05:35 PST
(In reply to comment #6)
> (In reply to comment #5)
> > (From update of attachment 78265 [details] [details])
> > Will this cause problems with “drop caps” done as
> >     <span style="font-size: x-large; float: left;">O</span>nce upon a time
> > ?
> 
> Yes the 'O' will be treated as a separate word when selecting by word and for spell checking, but getting that case right would require substantial changes to text iterators: they'll have to keep track of the previous chunk of text, and look ahead to the next chunk to know whether or not to emit for a floating element like that.  Those changes warrant a new bug I think.

So this patch will fix one case but regress other known cases. In particular, Find in Page will no longer match the first word of a paragraph with a drop cap. Typically we try to avoid regressions of this sort. Can you exaplain why this is a good tradeoff?
Comment 11 Justin Garcia 2011-01-14 13:27:12 PST
Comment on attachment 78870 [details]
patch

> So this patch will fix one case but regress other known cases. In particular, Find in Page will no longer match the first word of a paragraph with a drop cap. 

I hadn't thought about that case.  I need to rethink this.
Comment 12 Leif Halvard Silli 2011-07-05 19:57:54 PDT
(In reply to comment #10)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > (From update of attachment 78265 [details] [details] [details])
> > > Will this cause problems with “drop caps” done as
> > >     <span style="font-size: x-large; float: left;">O</span>nce upon a time

> So this patch will fix one case but regress other known cases. In particular, Find in Page will no longer match the first word of a paragraph with a drop cap. Typically we try to avoid regressions of this sort. Can you exaplain why this is a good tradeoff?

An arguably better trade off proposal: Align with Opera and Firefox.

In this example, Firefox and Opera treat "Once" as two words:
<div><div style="font-size: x-large; float: left;">O</div>nce upon a time</div>

Even in this example, do Firefox and Opera treat "Once" as  two words:
<div><div display:inline;">O</div>nce upon a time</div>

Whereas in this example, Firefox and Opera treat "Once" as a single word:
<div><span style="font-size: x-large; float: left;">O</span>nce upon a time</div>

So you should not only look at the styling of the elements but also at their semantics. <div> has the semantics of a block element, hence even if it has an inline style, it should be seen as a word splitter. Whereas <span> is an inline element that could also be used inside words.
Comment 14 Karl Dubost 2024-04-10 01:41:27 PDT
fwiw, the behavior is identical in Safari and Chrome, both hello and world are selected. 
Firefox doesn't select the "world" word.
Comment 15 Darin Adler 2024-04-10 07:27:28 PDT
It would help to define what behavior we want before we make any code change.

I’m sure Chrome inherited this behavior from WebKit and I’m not sure anyone has thought through what we want. Understanding whether a floating element is expected to be perceived by the user as disjoint or not may be a challenge, so the choice here is likely to be arbitrary rather than obviously meeting user expectations.