Closed Bug 338954 Opened 19 years ago Closed 19 years ago

Make .innerHTML to work without DOM Ranges

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: smaug, Assigned: smaug)

Details

Attachments

(2 files, 2 obsolete files)

Currently .innerHTML getter and setter use DOM ranges. But if ranges are fixed to work only when nodes are in document/document fragment/attr .innerHTML stops working for elements which aren't in the document.
Attached file Few tests (obsolete) —
Attached patch proposed patch (obsolete) — Splinter Review
The biggest change here is to move the implementation of CreateContextualFragment from nsRange to nsContentUtils. The scariest change is to use docEncoder->SetContainerNode (not ->SetRange())
Attachment #223023 - Flags: review?(bugmail)
The "scary" part is that dom gets serialized in a simpler way. No need to handle start/endContainer of the range because they are anyway always the same node (which is why there is no need to use range at all). I tested the patch also with some test cases found in bugzilla and couldn't see any regressions.
Status: NEW → ASSIGNED
Comment on attachment 223023 [details] [diff] [review] proposed patch >+nsContentUtils::CreateContextualFragment(nsIDOMNode* aContextNode, ... >+ while (parent && (parent != domDocument) && NS_SUCCEEDED(rv)) { Please |break| in all places where rv could become an error and remove the last condition here. The rv variable is really volitile so it should be checked asap to avoid future code from clamping all over it. >+ PRUint16 nodeType; >+ parent->GetNodeType(&nodeType); >+ if (nsIDOMNode::ELEMENT_NODE == nodeType) { >+ nsAutoString tagName, uriStr; >+ parent->GetNodeName(tagName); >+ >+ // see if we need to add xmlns declarations >+ nsCOMPtr<nsIContent> content = do_QueryInterface(parent, &rv); >+ if (NS_FAILED(rv)) { >+ break; >+ } Don't use nsresults with QI, instead just nullcheck the return. >Index: content/base/src/nsDocumentEncoder.cpp > nsresult SerializeToStringRecursive(nsIDOMNode* aNode, >- nsAString& aStr); >+ nsAString& aStr, >+ PRBool aNodeIsContainer = PR_FALSE); Something like |aDontSerializeRoot| or |aJustSerializeChildren| might be more descriptive, up to you. Don't use default parameters though, please just change all call sites. Default params just make further signature changes harder. With that, r=me
Attachment #223023 - Flags: review?(bugmail) → review+
Attached patch v2Splinter Review
Attachment #223023 - Attachment is obsolete: true
Attachment #223895 - Flags: superreview?(jst)
Attachment #223895 - Flags: superreview?(jst) → superreview+
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
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: