Bug 26827 - Improve InlineBox::first/lastLeafChild methods
Summary: Improve InlineBox::first/lastLeafChild methods
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P4 Minor
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-29 21:54 PDT by Roland Steiner
Modified: 2009-07-09 22:28 PDT (History)
1 user (show)

See Also:


Attachments
patch fixing the issues in the bug description (6.82 KB, patch)
2009-06-29 21:56 PDT, Roland Steiner
no flags Details | Formatted Diff | Diff
updated patch (7.10 KB, patch)
2009-06-30 18:30 PDT, Roland Steiner
mjs: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roland Steiner 2009-06-29 21:54:59 PDT
The current methods have some peculiarities (the following also all apply to the corresponding lastLeafChild[BeforeBox]() method):

.) someBasePtr->firstLeafChild() may return the same node rather than a child node

.) someBasePtr->firstLeafChild[AfterBox]() may return a node outside of the subtree

.) the meaning of someBasePtr->firstLeafChildAfterBox(), i.e., without parameter, is unclear without reading the code. It's also synonymous with firstLeafChild. It's also unclear why the method would need both a 'this' pointer AND a parameter (both issues are likely just artifacts of the implementation). 

.) from an interface POV there doesn't seem to be a reason why firstLeafChildAfterBox() should be restricted to InlineFlowBox (rather than be available on InlineBox)

.) The behavior of firstLeafChild[AfterBox]() is quadratic if the remaining nodes in the tree after the given box are all just empty InlineFlowBoxes
Comment 1 Roland Steiner 2009-06-29 21:56:07 PDT
Created attachment 32031 [details]
patch fixing the issues in the bug description
Comment 2 Eric Seidel (no email) 2009-06-30 00:45:27 PDT
Comment on attachment 32031 [details]
patch fixing the issues in the bug description

Are any of these behavior changes testable?  If not, there should be a note in the ChangeLog explaining why not.  If they are, we should have LayoutTests.
Comment 3 Roland Steiner 2009-06-30 18:30:48 PDT
Created attachment 32103 [details]
updated patch

Currently, the methods in question are called on RootInlineBox objects only, AFAICT, so there should not be any observable effects (the mentioned behavior can only happen if called on InlineFlowBox objects, basically).

Only the removal of the square runtime behavior when the remaining nodes in a tree are all empty InlineFlowBox objects could be effective, but the conditions for that are more theoretical in nature (i.e., would probably require to have a pathological case to have any measurable impact).

Updated the ChangeLog accordingly.
Comment 4 Maciej Stachowiak 2009-07-06 00:47:44 PDT
Comment on attachment 32103 [details]
updated patch

Most of the refactoring looks good. One part I don't undestand.

InlineFlowBox::firstLeafChildBeforeBox looks like it used to sometimes look in the parent, if no leaf box was found:

     if (start && !leaf && parent())
         return parent()->firstLeafChildAfterBox(this);

Likewise for lastLeafChildBeforeBox. 

It's documented that these won't return nodes outside the subtree any more, but as a non-expert it's not clear to me why this is right. Explanation would be appreciated.
Comment 5 Maciej Stachowiak 2009-07-06 00:49:23 PDT
Comment on attachment 32103 [details]
updated patch

Most of the refactoring looks good. One part I don't undestand.

InlineFlowBox::firstLeafChildBeforeBox looks like it used to sometimes look in the parent, if no leaf box was found:

     if (start && !leaf && parent())
         return parent()->firstLeafChildAfterBox(this);

Likewise for lastLeafChildBeforeBox. 

It's documented that these won't return nodes outside the subtree any more, but as a non-expert it's not clear to me why this is right. Explanation would be appreciated.
Comment 6 Roland Steiner 2009-07-06 04:31:36 PDT
(In reply to comment #5)

[recapping our discussion on IRC]

Note: all of the following is rather theoretical, since those function currently are only called on RootInlineBox objects, while the issues would only manifest if called on InlineFlowBox objects.

From the name "firstLeafChild" it struck me as odd that the function would potentially return a node outside the current subtree, i.e., not a child of the current node.
The reason for this seems that the functions firstLeafChildAfterBox/lastLeafChildBeforeBox are mainly for implementation purposes, and used to implement both for first/lastLeafChild() and next/prevLeafChild(). For the latter it makes sense that a node outside of the current subtree can be returned, for the former not so much (IMHO).
Comment 7 Maciej Stachowiak 2009-07-09 20:17:46 PDT
Comment on attachment 32103 [details]
updated patch

All right, the code looks correct, and since it doesn't fail any tests, I'm going to assume the assumptions about looking at parents (that it's accidentally there and no longer needed) are right. If not, we'll find out soon enough.
Comment 8 Brent Fulgham 2009-07-09 22:28:13 PDT
Landed in http://trac.webkit.org/changeset/45702.