Closed Bug 1393419 Opened 7 years ago Closed 7 years ago

Implement nsIContent::As<T> to replace QI(nsIDOMHTML*Element)

Categories

(Core :: DOM: Core & HTML, enhancement, P3)

enhancement

Tracking

()

RESOLVED INVALID

People

(Reporter: emk, Assigned: emk)

References

Details

Attachments

(1 file, 1 obsolete file)

Attached patch Proof of concept (obsolete) — Splinter Review
This is inspired by JSObject::as<T>. This is safer than a bare static_cast and has no overhead such as virtual calls.

qdot, WDYT?
Attachment #8900698 - Flags: feedback?(kyle)
Assignee: nobody → VYV03354
Comment on attachment 8900698 [details] [diff] [review]
Proof of concept

Review of attachment 8900698 [details] [diff] [review]:
-----------------------------------------------------------------

This looks ok to me. The LocalName() lookup is a little awkward but I can't find anywhere else that we have easily accessible nsGkAtoms -> binding type lookups. I may ask bz about this once he's synced back up from vacation.

::: docshell/base/nsContextMenuInfo.cpp
@@ +85,5 @@
>        content = do_QueryInterface(curr);
>        if (!content) {
>          break;
>        }
> +      if (content->IsHTMLElement(nsGkAtoms::a)) {

I think we could just move the As<>() call here instead of having to check for HTML element type first?
Attachment #8900698 - Flags: feedback?(kyle) → feedback+
Attached patch Proof of conceptSplinter Review
> I think we could just move the As<>() call here instead of having to check for HTML element type first?

Good point, fixed.
Attachment #8900698 - Attachment is obsolete: true
Priority: -- → P3
Boris, do you have better idea to get binding types from nsGkAtoms?
Flags: needinfo?(bzbarsky)
Well, the first problem is that you can't do it, in general.  For example, both <q> and <blockquote> are HTMLQuoteElement, so if you wanted to do As<HTMLQuoteElement> you wouldn't be able to do it using the setup with T::LocalName() or any other setup that depends on a one-to-one mapping of localnames to types.  Similar for <col> and <colgroup>, and the fact that we have an HTMLSharedElement complicates things even further.

For the cases where tags map 1-1 to element types, we already have FromContent machinery, no?
Flags: needinfo?(bzbarsky)
Oh, I didn't notice FromContent. Thank you.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: