summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/wx/WebEdit.cpp
blob: 33b4c8617ba4740172bf17f1dfe492144f7ee174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80


#include "config.h"
#include "WebEdit.h"

#include "CompositeEditCommand.h"
#include "Document.h"
#include "Frame.h"
#include "HTMLNames.h"
#include "QualifiedName.h"
#include "StringImpl.h"

#include "WebFrame.h"
#include "WebDOMElement.h"
#include <wtf/text/AtomicString.h>

namespace WebCore {

class WebCoreEditCommand: public CompositeEditCommand
{
public:
    WebCoreEditCommand(WebCore::Document* document)
        : CompositeEditCommand(document)
        { }
        
    void setElementAttribute(PassRefPtr<Element> element, const QualifiedName& attribute, const AtomicString& value) 
    { 
        setNodeAttribute(element, attribute, value); 
    }
    // composite commands are applied as they are added, so we don't
    // need doApply to do anything.
    virtual void doApply() {}
};

}

class WebCoreEditCommandPrivate {
public:
    WebCoreEditCommandPrivate()
        : m_ptr(0)
    { }
    
    WebCoreEditCommandPrivate(WebCore::WebCoreEditCommand* ptr)
        : m_ptr(adoptRef(ptr))
    { }
    
    ~WebCoreEditCommandPrivate() { }
    
    WebCore::WebCoreEditCommand* command() { return m_ptr.get(); }
        
    RefPtr<WebCore::WebCoreEditCommand> m_ptr;
};

wxWebEditCommand::wxWebEditCommand(wxWebFrame* webframe)
{
    if (webframe) {
        WebCore::Frame* frame = webframe->GetFrame();
        if (frame && frame->document())
            m_impl = new WebCoreEditCommandPrivate(new WebCore::WebCoreEditCommand(frame->document()));
    }
}

wxWebEditCommand::~wxWebEditCommand()
{
    // the impl. is ref-counted, so don't delete it as it may be in an undo/redo stack
    delete m_impl;
    m_impl = 0;
}

void wxWebEditCommand::SetNodeAttribute(WebDOMElement* element, const wxString& name, const wxString& value)
{
    if (m_impl && m_impl->command())
        m_impl->command()->setElementAttribute(element->impl(), WebCore::QualifiedName(WTF::nullAtom, WTF::String(name), WTF::nullAtom), WTF::String(value));
}

void wxWebEditCommand::Apply()
{
    if (m_impl && m_impl->command())
        m_impl->command()->apply();
}