[webkit-dev] How to properly create some element nodes within webcore?

Sam Weinig sam.weinig at gmail.com
Wed Jul 7 10:34:22 PDT 2010


On Wed, Jul 7, 2010 at 8:30 AM, Matt 'Murph' Finnicum <mattfinn at gmail.com>wrote:

> I know this sounds a bit silly, but it's a simplified version of what i'm
> doing.
>
> Let's say I decided to replace every webpage with "hello world". I
> decided to do this from finishedParsing() within dom/Document.cpp:
>
> void Document::finishedParsing()
> {
>    ExceptionCode ec = 0;
>    HTMLBodyElement* body_node = new HTMLBodyElement(bodyTag, this);
>    setBody(body_node, ec);
>
>    RefPtr<Node> new_node = Text::create(this, "Hello, World");
>    body_node -> appendChild(new_node,ec);
>
>    -- rest of finishedParsing as usual --
>
> That works fine.
>
> Now lets say I want it to be blue:
>
> void Document::finishedParsing()
> {
>    ExceptionCode ec = 0;
>    HTMLBodyElement* body_node = new HTMLBodyElement(bodyTag, this);
>    setBody(body_node, ec);
>
>    RefPtr<Node> new_font_node =
> HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom,
> String("font"),nullAtom), this, 0, false);
>
>  static_cast<Element*>(new_font_node.get())->setAttribute(String("bolor"),String("blue"),ec);
>    RefPtr<Node> new_text_node = Text::create(this, "Hello, World");
>    new_font_node -> appendChild(new_text_node,ec);
>    body_node -> appendChild(new_font_node,ec);
>
>    --rest of finshedParsing as usual --
>
> Again, this works fine.
>
> But blue is too flashy for my taste, and I now want it to just be bolded.
> void Document::finishedParsing()
> {
>    ExceptionCode ec = 0;
>    HTMLBodyElement* body_node = new HTMLBodyElement(bodyTag, this);
>    setBody(body_node, ec);
>
>    RefPtr<Node> new_bold_node =
> HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom,
> String("b"),nullAtom), this, 0, false);
>    RefPtr<Node> new_text_node = Text::create(this, "Hello, World");
>    new_bold_node -> appendChild(new_text_node,ec);
>    body_node -> appendChild(new_bold_node,ec);
>
>    --rest of finishedParsing as usual --
>
> ... nothing is bold. Other, similar elements like 'strong' 'em' 'u'
> 'i' don't do anything.
>
> What am I doing wrong?
>
>
This is probably not working because you are not creating an Element with
the HTML namespace.

One thing you could try is instead of using
 "QualifiedName(nullAtom, String("b"),nullAtom)", use HTMLNames::bTag.

-Sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20100707/3e928dc2/attachment.html>


More information about the webkit-dev mailing list