Bug 24576 - Selection rendering code uses DOM offsets as if they were render tree offsets
Summary: Selection rendering code uses DOM offsets as if they were render tree offsets
Status: ASSIGNED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Darin Adler
URL:
Keywords:
Depends on: 24621
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-13 07:16 PDT by Darin Adler
Modified: 2012-05-31 11:02 PDT (History)
6 users (show)

See Also:


Attachments
work in process -- can't land until after PositionIterator issues are fixed (10.28 KB, patch)
2009-03-16 09:10 PDT, Darin Adler
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 2009-03-13 07:16:10 PDT
I noticed that the selection code uses DOM offsets as if they were render tree child offsets. I will be fixing this.
Comment 1 Darin Adler 2009-03-13 10:10:42 PDT
There is one case of this in Range.cpp and a few in RenderView.cpp.

I've got a patch underway for this now; it's going well. What I知 not so sure about yet is what regression tests I知 going to write to demonstrate the bug.
Comment 2 Justin Garcia 2009-03-13 10:57:19 PDT
This can only be a problem if the DOM position is [container, n] where n is not zero but we have very few editing positions like that (which is what is used to feed RenderView::setSelection).  

It would be easier to write a regression test for the fix in Range::addLineBox rects (assuming you exposed that function) since you can use whatever end position you want.
Comment 3 Alexey Proskuryakov 2009-03-14 00:22:02 PDT
Will fix fix bug 8855? It has a test case that triggers (used to trigger?) an assertion in debug builds, and caused some weird behavior in release.
Comment 4 Darin Adler 2009-03-14 07:50:21 PDT
(In reply to comment #3)
> Will fix fix bug 8855? It has a test case that triggers (used to trigger?) an
> assertion in debug builds, and caused some weird behavior in release.

I'll check.
Comment 5 Darin Adler 2009-03-16 09:10:53 PDT
Created attachment 28649 [details]
work in process -- can't land until after PositionIterator issues are fixed

This is a work in progress. I think the changes are all correct, but they are causing regression test failures. Some of those failures are progressions. But at least one of them is a problem, caused by the PositionIterator problem in the blocking bug.
Comment 6 Justin Garcia 2009-04-10 12:27:20 PDT
-    RenderObject* stop = end->childAt(m_end.offset());
-    if (!stop)
-        stop = end->nextInPreOrderAfterChildren();
+    RenderObject* stop = 0;
+    for (Node* stopNode = pastLastNode(); stopNode; stopNode = stopNode->traverseNextNode()) {
+        if ((stop = stopNode->renderer()))
+            break;
+    }

we tried this and ran into a problem when the range we were iterating over ended in the last text node inside a form element (or in some other shadow tree).  

in this case pastLastNode() is null, so both stopNode and stop are null.  since shadow trees are in the main document's render tree, we iterate all the way to the end of the document w/o stopping.
Comment 7 Darin Adler 2009-04-10 13:10:38 PDT
(In reply to comment #6)
> -    RenderObject* stop = end->childAt(m_end.offset());
> -    if (!stop)
> -        stop = end->nextInPreOrderAfterChildren();
> +    RenderObject* stop = 0;
> +    for (Node* stopNode = pastLastNode(); stopNode; stopNode =
> stopNode->traverseNextNode()) {
> +        if ((stop = stopNode->renderer()))
> +            break;
> +    }
> 
> we tried this and ran into a problem when the range we were iterating over
> ended in the last text node inside a form element (or in some other shadow
> tree).  
> 
> in this case pastLastNode() is null, so both stopNode and stop are null.  since
> shadow trees are in the main document's render tree, we iterate all the way to
> the end of the document w/o stopping.

OK. Simple to solve. We'll need to add code that knows how to go out of the shadow tree since the render tree covers both the shadow DOM and the real DOM.
Comment 8 Darin Adler 2012-05-27 21:50:57 PDT
Thought the modern day editing experts might be interested in my struggle from three years ago. This was never resolved.