WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED INVALID
62849
Refactoring: Editor::selectionStartHasMarkerFor should be simplified
https://bugs.webkit.org/show_bug.cgi?id=62849
Summary
Refactoring: Editor::selectionStartHasMarkerFor should be simplified
Hajime Morrita
Reported
2011-06-17 01:42:58 PDT
This testing API has a code duplication, which should be eliminated.
Attachments
Patch
(2.77 KB, patch)
2011-06-17 01:45 PDT
,
Hajime Morrita
no flags
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Hajime Morrita
Comment 1
2011-06-17 01:45:59 PDT
Created
attachment 97560
[details]
Patch
Ryosuke Niwa
Comment 2
2011-06-17 02:12:44 PDT
Comment on
attachment 97560
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=97560&action=review
> Source/WebCore/editing/Editor.cpp:-3216 > - if (marker->startOffset() <= startOffset && endOffset <= marker->endOffset() && marker->type() == markerType) > - return true;
It seems like we used to return true and we now return false if we have a zero-width marker at from=length but I guess we don't have to worry about that in practice?
Hajime Morrita
Comment 3
2011-06-17 02:25:14 PDT
> It seems like we used to return true and we now return false if we have a zero-width marker at from=length but I guess we don't have to worry about that in practice?
Yes. And in theory, we need should have a way to detect zero-length marker.
Ryosuke Niwa
Comment 4
2011-06-17 02:42:36 PDT
Comment on
attachment 97560
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=97560&action=review
(In reply to
comment #3
)
> > It seems like we used to return true and we now return false if we have a zero-width marker at from=length but I guess we don't have to worry about that in practice? > Yes. And in theory, we need should have a way to detect zero-length marker.
Document markets aren't exposed to the Web, are they? We may want to assert somewhere that we're not adding a zero-length marker.
> Source/WebCore/editing/Editor.cpp:-3194 > - if (node->renderer()->isTextControl()) > - node = toRenderTextControl(node->renderer())->visiblePositionForIndex(1).deepEquivalent().deprecatedNode();
We're no longer looking for the text node, is that really fine? Do we have a test coverage for this?
> Source/WebCore/editing/Editor.cpp:-3198 > - else if (node->firstChild()) > - node = node->firstChild(); > - else > - node = node->nextSibling();
We don't do this either. Maybe you want to canonicalize the selection start using VisiblePosition and get the deepEquivalent? It seems like that's what this code is trying to do.
Hajime Morrita
Comment 5
2011-06-17 02:52:45 PDT
Comment on
attachment 97560
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=97560&action=review
>> Source/WebCore/editing/Editor.cpp:-3194 >> - node = toRenderTextControl(node->renderer())->visiblePositionForIndex(1).deepEquivalent().deprecatedNode(); > > We're no longer looking for the text node, is that really fine? Do we have a test coverage for this?
Traversing to text node is done by DocumentMarkerController. Our test case cannot handle this because our selection anchors always go to leaf if it has any text in the subtree.
>> Source/WebCore/editing/Editor.cpp:-3198 >> - node = node->nextSibling(); > > We don't do this either. Maybe you want to canonicalize the selection start using VisiblePosition and get the deepEquivalent? It seems like that's what this code is trying to do.
Yeah, that's another reason to remove this function. It's done by DocumentMarker anyway. Anyway, thank you much for taking a look at this on such a midnight!
Ryosuke Niwa
Comment 6
2011-06-17 02:56:00 PDT
Comment on
attachment 97560
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=97560&action=review
>>> Source/WebCore/editing/Editor.cpp:-3194 >>> - node = toRenderTextControl(node->renderer())->visiblePositionForIndex(1).deepEquivalent().deprecatedNode(); >> >> We're no longer looking for the text node, is that really fine? Do we have a test coverage for this? > > Traversing to text node is done by DocumentMarkerController. > Our test case cannot handle this because our > selection anchors always go to leaf if it has any text in the subtree.
I'm confused. DocumentMarkerController::hasMarkers doesn't contain any code that looks for text node.
Hajime Morrita
Comment 7
2011-06-17 03:11:17 PDT
> I'm confused. DocumentMarkerController::hasMarkers doesn't contain any code that looks for text node.
The marker is associated only for Text node. And hasMarker() uses traverseNextNode() for traversing, which walks up to leaf nodes. Text nodes appear only as leaf nodes. So we never misses marked text node. Sorry for unclear explanation. I think DocumentMarkerController should hold node refrences as Text*, instead of Node*.
Ryosuke Niwa
Comment 8
2011-06-17 03:18:11 PDT
(In reply to
comment #7
)
> > I'm confused. DocumentMarkerController::hasMarkers doesn't contain any code that looks for text node. > The marker is associated only for Text node. > And hasMarker() uses traverseNextNode() for traversing, which walks up to leaf nodes. > Text nodes appear only as leaf nodes. So we never misses marked text node. > Sorry for unclear explanation. > > I think DocumentMarkerController should hold node refrences as Text*, instead of Node*.
But selectionStartHasMarkerFor's from and to are now with respect to selection start's node instead of whatever text node we used to use, right? So it seems like we'll be including more markers. E.g. consider a case where we have |<b>hello</b> where | is the selection start. If we passed (from,to)=(0,1), we used to catch markekers on "h" but now we catch markers on "hello". Am I missing something?
Ryosuke Niwa
Comment 9
2011-06-17 03:22:11 PDT
To clarify, the selection start's deprecated node is b in this case.
Hajime Morrita
Comment 10
2011-06-17 03:34:54 PDT
> E.g. consider a case where we have |<b>hello</b> where | is the selection start. If we passed (from,to)=(0,1), we used to catch markekers on "h" but now we catch markers on "hello". Am I missing something?
Wow, you are right. I need to fix it using TextIterator or something....
Ryosuke Niwa
Comment 11
2011-06-17 03:37:47 PDT
(In reply to
comment #10
)
> > E.g. consider a case where we have |<b>hello</b> where | is the selection start. If we passed (from,to)=(0,1), we used to catch markekers on "h" but now we catch markers on "hello". Am I missing something? > Wow, you are right. I need to fix it using TextIterator or something....
I'm glad I pointed this out before giving r+ :)
Hajime Morrita
Comment 12
2011-06-17 03:42:48 PDT
> > I'm glad I pointed this out before giving r+ :)
Yeah, thanks for doing this ;-) Actually I'm confused the assumption about Positions which FrameSelection returns. I thought it's always Text. But it looks no longer (or hasn't been) true.
Ryosuke Niwa
Comment 13
2011-06-17 03:46:24 PDT
(In reply to
comment #12
)
> Yeah, thanks for doing this ;-) > Actually I'm confused the assumption about Positions which FrameSelection returns. > I thought it's always Text. But it looks no longer (or hasn't been) true.
It's not. FrameSelection's start and end are usually canonicalized but there are cases in which they're not validated. Take a look at VisibleSelection::setWithoutValidation. We'll really need to clean up the whole FrameSelection class at some point :(
Hajime Morrita
Comment 14
2011-11-22 00:59:04 PST
Original assumption for this refactoring was wrong. Closing.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug