XMLElementImpl::XMLElementImpl(DocumentPtr *doc, DOMStringImpl *_qualifiedName, DOMStringImpl *_namespaceURI)
    : ElementImpl(doc)
{
    int colonpos = -1;
    for (uint i = 0; i < _qualifiedName->l; ++i)
        if (_qualifiedName->s[i] == ':') {
            colonpos = i;
            break;
        }

    if (colonpos >= 0) {
        // we have a prefix
        DOMStringImpl* localName = _qualifiedName->copy();
        localName->ref();
        localName->remove(0,colonpos+1);
        m_id = doc->document()->tagId(_namespaceURI, localName, false /* allocate */);
        localName->deref();
        m_prefix = _qualifiedName->copy();
        m_prefix->ref();
        m_prefix->truncate(colonpos);
    }
    else {
        // no prefix
        m_id = doc->document()->tagId(_namespaceURI, _qualifiedName, false /* allocate */);
        m_prefix = 0;
    }
}
void CharacterDataImpl::detachString()
{
    // make a copy of our string so as not to interfere with other texts that use it
    DOMStringImpl *newStr = str->copy();
    newStr->ref();
    str->deref();
    str = newStr;
}
Beispiel #3
0
void IDTableBase::addHiddenMapping(unsigned id, const DOMString& name)
{
    DOMStringImpl* nameImpl = name.implementation();
    if (nameImpl) nameImpl->ref();

    if (id >= m_mappings.size())
        m_mappings.resize(id + 1);
    m_mappings[id] = Mapping(nameImpl);
    m_mappings[id].refCount = 1; // Pin it.
}
Beispiel #4
0
void CharacterDataImpl::dispatchModifiedEvent(DOMStringImpl *prevValue)
{
    if (parentNode())
        parentNode()->childrenChanged();
    if (!getDocument()->hasListenerType(DocumentImpl::DOMCHARACTERDATAMODIFIED_LISTENER))
        return;

    DOMStringImpl *newValue = str->copy();
    newValue->ref();
    int exceptioncode = 0;
    MutationEventImpl* const evt = new MutationEventImpl(EventImpl::DOMCHARACTERDATAMODIFIED_EVENT,true,false,0,prevValue,newValue,DOMString(),0);
    evt->ref();
    dispatchEvent(evt,exceptioncode);
    evt->deref();
    newValue->deref();
    dispatchSubtreeModifiedEvent();
}
void RenderStyle::setContent(DOMStringImpl* s, bool add)
{
    if (!s)
        return; // The string is null. Nothing to do. Just bail.
    
    ContentData* lastContent = content;
    while (lastContent && lastContent->_nextContent)
        lastContent = lastContent->_nextContent;

    bool reuseContent = !add;
    if (add) {
        if (!lastContent)
            return; // Something's wrong.  We had no previous content, and we should have.

        if (lastContent->_contentType == CONTENT_TEXT) {
            // We can augment the existing string and share this ContentData node.
            DOMStringImpl* oldStr = lastContent->_content.text;
            DOMStringImpl* newStr = oldStr->copy();
            newStr->ref();
            oldStr->deref();
            newStr->append(s);
            lastContent->_content.text = newStr;
            return;
        }
    }

    ContentData* newContentData = 0;
    if (reuseContent && content) {
        content->clearContent();
        newContentData = content;
    }
    else
        newContentData = new ContentData;
    
    if (lastContent && !reuseContent)
        lastContent->_nextContent = newContentData;
    else
        content = newContentData;
    
    newContentData->_content.text = s;
    newContentData->_content.text->ref();
    newContentData->_contentType = CONTENT_TEXT;
}
Beispiel #6
0
void RenderStyle::addContent(DOM::DOMStringImpl *s)
{
    if(!s)
        return; // The string is null. Nothing to do. Just bail.

    StyleGeneratedData *t_generated = generated.access();

    ContentData *lastContent = t_generated->content;
    while(lastContent && lastContent->_nextContent)
        lastContent = lastContent->_nextContent;

    if(lastContent)
    {
        if(lastContent->_contentType == CONTENT_TEXT)
        {
            // We can augment the existing string and share this ContentData node.
            DOMStringImpl *oldStr = lastContent->_content.text;
            DOMStringImpl *newStr = oldStr->copy();
            newStr->ref();
            oldStr->deref();
            newStr->append(s);
            lastContent->_content.text = newStr;
            return;
        }
    }

    ContentData *newContentData = new ContentData;

    if(lastContent)
        lastContent->_nextContent = newContentData;
    else
        t_generated->content = newContentData;

    newContentData->_content.text = s;
    newContentData->_content.text->ref();
    newContentData->_contentType = CONTENT_TEXT;
}
Beispiel #7
0
void CharacterDataImpl::dispatchModifiedEvent(DOMStringImpl *prevValue)
{
    if (parentNode())
        parentNode()->childrenChanged();
    if ((str->length() == 0) != (prevValue->length() == 0)) {
       // changes in emptiness triggers changes in :empty selector
       if (parentNode() && parentNode()->isElementNode())
           parentNode()->backwardsStructureChanged();
       // ### to fully support dynamic changes to :contains selector
       // backwardsStructureChanged should be called for all changes
    }
    if (!document()->hasListenerType(DocumentImpl::DOMCHARACTERDATAMODIFIED_LISTENER))
        return;

    DOMStringImpl *newValue = str->copy();
    newValue->ref();
    int exceptioncode = 0;
    MutationEventImpl* const evt = new MutationEventImpl(EventImpl::DOMCHARACTERDATAMODIFIED_EVENT,true,false,0,prevValue,newValue,DOMString(),0);
    evt->ref();
    dispatchEvent(evt,exceptioncode);
    evt->deref();
    newValue->deref();
    dispatchSubtreeModifiedEvent();
}
Beispiel #8
0
unsigned short IDTableBase::grabId(DOMStringImpl* origName, CaseNormalizeMode cnm)
{
    unsigned short newId;

    // Check for existing one, ignoring case if needed
    IDTableBase::MappingKey::caseNormalizationMode = cnm;
    QHash<MappingKey, unsigned short>::const_iterator i = m_mappingLookup.constFind(origName);
    if (i != m_mappingLookup.constEnd()) {
        newId = *i;
        refId(newId);
        return newId;
    }

    // Nope. Allocate new ID. If there is normalization going on, we may now have to 
    // update our case so the canonical mapping is of the expected case. We
    // may also have to deep-copy 
    DOMStringImpl* name;
    switch (cnm) {
    case IDS_CaseSensitive:
        if (origName->m_shallowCopy) {
            // Create a new copy of the data since we may be extending its
            // lifetime indefinitely
            name = new DOMStringImpl(origName->s, origName->l);
            name->m_hash = origName->m_hash;
        } else {
            name = origName;
        }
        break;
    case IDS_NormalizeUpper:
        name = origName->upper();
        break;
    case IDS_NormalizeLower:
        name = origName->lower();
        break;
    }
    
    name->ref();

    if (!m_idFreeList.isEmpty()) {
        // Grab from freelist..
        newId = m_idFreeList.last();
        m_idFreeList.removeLast();
        m_mappings[newId].name = name;
    } else {
        // Make a new one --- if we can (we keep one spot for "last resort" mapping)
        if (m_mappings.size() < 0xFFFE) {
            m_mappings.append(Mapping(name));
            newId = m_mappings.size() - 1;
        } else {
            // We ran out of resources. Did we add a fallback mapping yet?
            // We use the same one for everything; and don't even keep track
            // of what it may go to, as we will have no way of freeing
            // the aliases. In particular, this means we no longer need the name..
            name->deref();
            
            if (m_mappings.size() == 0xFFFE) {
                // Need a new mapping..
                name = new DOMStringImpl("_khtml_fallback");
                m_mappings.append(Mapping(name));
                m_mappings[0xFFFF].refCount = 1; // pin it.
                name->ref();
            } else {
                name = m_mappings[0xFFFF].name; // No need to ref the name
                                                // here as the entry is eternal anyway
            }
            newId = 0xFFFF;
        }
    }

    m_mappingLookup[name] = newId;

    refId(newId);
    return newId;
}