1 2 3#include "config.h" 4#include "WebEdit.h" 5 6#include "CompositeEditCommand.h" 7#include "Document.h" 8#include "Frame.h" 9#include "HTMLNames.h" 10#include "QualifiedName.h" 11#include "StringImpl.h" 12 13#include "WebFrame.h" 14#include "WebDOMElement.h" 15#include <wtf/text/AtomicString.h> 16 17namespace WebCore { 18 19class WebCoreEditCommand: public CompositeEditCommand 20{ 21public: 22 WebCoreEditCommand(WebCore::Document* document) 23 : CompositeEditCommand(document) 24 { } 25 26 void setElementAttribute(PassRefPtr<Element> element, const QualifiedName& attribute, const AtomicString& value) 27 { 28 setNodeAttribute(element, attribute, value); 29 } 30 // composite commands are applied as they are added, so we don't 31 // need doApply to do anything. 32 virtual void doApply() {} 33}; 34 35} 36 37class WebCoreEditCommandPrivate { 38public: 39 WebCoreEditCommandPrivate() 40 : m_ptr(0) 41 { } 42 43 WebCoreEditCommandPrivate(WebCore::WebCoreEditCommand* ptr) 44 : m_ptr(adoptRef(ptr)) 45 { } 46 47 ~WebCoreEditCommandPrivate() { } 48 49 WebCore::WebCoreEditCommand* command() { return m_ptr.get(); } 50 51 RefPtr<WebCore::WebCoreEditCommand> m_ptr; 52}; 53 54wxWebEditCommand::wxWebEditCommand(wxWebFrame* webframe) 55{ 56 if (webframe) { 57 WebCore::Frame* frame = webframe->GetFrame(); 58 if (frame && frame->document()) 59 m_impl = new WebCoreEditCommandPrivate(new WebCore::WebCoreEditCommand(frame->document())); 60 } 61} 62 63wxWebEditCommand::~wxWebEditCommand() 64{ 65 // the impl. is ref-counted, so don't delete it as it may be in an undo/redo stack 66 delete m_impl; 67 m_impl = 0; 68} 69 70void wxWebEditCommand::SetNodeAttribute(WebDOMElement* element, const wxString& name, const wxString& value) 71{ 72 if (m_impl && m_impl->command()) 73 m_impl->command()->setElementAttribute(element->impl(), WebCore::QualifiedName(WTF::nullAtom, WTF::String(name), WTF::nullAtom), WTF::String(value)); 74} 75 76void wxWebEditCommand::Apply() 77{ 78 if (m_impl && m_impl->command()) 79 m_impl->command()->apply(); 80} 81