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

Matt 'Murph' Finnicum mattfinn at gmail.com
Wed Jul 7 08:30:20 PDT 2010


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?

Thanks,
--Murph


More information about the webkit-dev mailing list