Closed Bug 344050 Opened 18 years ago Closed 18 years ago

Kill nsITextContent

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: sicking, Assigned: sicking)

References

Details

Attachments

(2 files, 4 obsolete files)

There's no real reason to have separate interfaces for nsITextContent and nsIContent. We should just move the text-access methods to nsIContent, all attribute related methods live there anyway, so why not text-related?

I have a working patch, but I need to rename nsIContent::Text() to nsIContent::GetText() since it can return null for elements.
Attached patch WIP (obsolete) — Splinter Review
This only misses the Text() -> GetText() renaming.
Attached patch Patch to fix (obsolete) — Splinter Review
This one's good. The patch does change behaviour in a few case. An old QI to nsITextContent would succeed for comment nodes and text nodes, whereas i've replaced the QIs with IsNodeOfType tests for either nsINode::eTEXT or nsINode::eDATA_NODE. eDATA_NODE is set for comments, text and PIs.

I suspect that pretty much all eDATA_NODE tests should be replaced with eTEXT tests, but i'm worried about modifying code I don't know.
Attachment #228618 - Attachment is obsolete: true
Attached patch Same as above with -w (obsolete) — Splinter Review
Attachment #228732 - Flags: superreview?(jst)
Attachment #228732 - Flags: review?(jst)
Aaron: Could you take a look at the changes to nsHyperTextAccessible.cpp and let me know if the code should only check for text-nodes, or if it actually wants to find comments and/or processing instructions as well.
r=aaronlev on the accessibility changes, although you can assume we only care about eTEXT. Don't need to check it if the role == ROLE_TEXT_LEAF, because then we know it's eTEXT. You can assert that if you want.
Comment on attachment 228732 [details] [diff] [review]
Same as above with -w

+PRBool
+nsGenericElement::TextIsOnlyWhitespace()
+{
+  return PR_FALSE;
+}
+
+void
+nsGenericElement::AppendTextTo(nsAString& aResult)
+{
+}

Would we want to make those two methods warn if they're called? I don't see any reason for anyone to ever get into a situation where those would be called w/o a developer doing something unintended.

r+sr=jst
Attachment #228732 - Flags: superreview?(jst)
Attachment #228732 - Flags: superreview+
Attachment #228732 - Flags: review?(jst)
Attachment #228732 - Flags: review+
We should probably assert, not just warn.  Imo...
In this patch there are actually places where I do use the fact that those methods return what they return.

For example in nsHTMLCopyEncoder::IsEmptyTextContent and nsHTMLEditor::StripFormattingNodes (and probably nsCSSFrameConstructor, TextIsOnlyWhitespace) we want to skip textnodes that are whitespace-only, but not other types of nodes. Here we won't have to first check for text-ness and then check only-whitespace. But rather we can check only-whitespace directly.

Same thing almost applies to AppendTextTo. However it turns out that most, if not all, places need to check for eTEXT (to avoid getting comments and PIs) anyway, so maybe we could warn or assert. But it feels a bit strange that all other text-related methods should be allowed with AppendTextTo being the only exception.

Let me know what you think.

So where do we use SetText() on elements?  Or for that matter GetText() or TextLength()?  I'll buy that TextIsOnlyWhitespace() is useful for elements if we're using it, but all the other methods don't seem that useful.

Oh, and a comment nit: "concatenation", not "concatination".
SetText() should not be used, i agree that that should assert no matter what.

GetText() is used as an alternative way of doing IsNodeOfType(eDATA_NODE) which is more convinient when you want to get the fragment first thing you do anyway.

TextLength() is currently used in nsAccessible::AppendFlatStringFromContentNode and nsCSSFrameConstructor,IsFirstLetterContent to for lengths greater than 0.
nsAccessible::AppendFlatStringFromContentNode already checks for IsNodeOfType(nsINode::eTEXT), so that' ok.  In the frame constructor, the only caller is passing in the GetContent of an nsTextFrame.  So I'd be happy to just assert IsNodeOfType(nsINode::eTEXT) in IsFirstLetterContent() and make TextLength() assert...
This patch addresses the comment from jst and bz by adding the assertion, but also adding a comment saying that we can remove the assertion if it turns out that it'd be useful to be able to call those methods.
Checked in, there was an inverted test in nsComboboxControlFrame.cpp (== should be !=).

It was about a 1% win in Tp on btek.
The patch is checked in, so should it be marked fixed now?
Would the following TB be related to this checkin: TB21266540E ?
Attached patch Make metrics compile too (obsolete) — Splinter Review
Attachment #230348 - Flags: superreview?(bugmail)
Attachment #230348 - Flags: review?
Attachment #230348 - Flags: review? → review?(bryner)
Ian, that does look like a regression from this bug.  Please file a bug on it and mark it blocking this one?
Depends on: 345342
Depends on: 345670
Attachment #230348 - Flags: review?(bryner) → review+
Comment on attachment 230348 [details] [diff] [review]
Make metrics compile too

Why change the hash to hold nsINodes instead of nsIDocuments?
...I'd rather that you cast in NodeWillBeDestroyed instead since you'll have to make an unsafe cast somewhere no matter what.
Attachment #230348 - Attachment is obsolete: true
Attachment #230532 - Flags: superreview?(bugmail)
Attachment #230348 - Flags: superreview?(bugmail)
Comment on attachment 230532 [details] [diff] [review]
With the other cast

Though I just realized, this isn't related to this bug, is it. It's bug 342062 :)
Attachment #230532 - Flags: superreview?(bugmail) → superreview+
Er.... yes, it is.  One sicking bug is much like another, or something.  ;)

Checked that in.
This was checked in some time ago
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Status: RESOLVED → VERIFIED
Flags: in-testsuite-
Depends on: 405069
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: