Changeset 240328 in webkit
- Timestamp:
- Jan 22, 2019 10:10:45 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r240326 r240328 1 2019-01-22 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Introduce CustomUndoStep.h and CustomUndoStep.cpp 4 https://bugs.webkit.org/show_bug.cgi?id=193704 5 <rdar://problem/44807048> 6 7 Reviewed by Ryosuke Niwa. 8 9 This patch is more work in progress towards supporting `UndoManager.addItem()`. Here, we introduce a helper 10 class, CustomUndoStep, that holds a weak reference to a script-defined UndoItem. See below for more details. 11 12 No change in behavior. 13 14 * Sources.txt: 15 * WebCore.xcodeproj/project.pbxproj: 16 * editing/CustomUndoStep.cpp: 17 (WebCore::CustomUndoStep::CustomUndoStep): 18 19 Subclass UndoStep. 20 21 (WebCore::CustomUndoStep::unapply): 22 (WebCore::CustomUndoStep::reapply): 23 24 If possible, invoke the UndoItem's undo and redo handlers. 25 26 (WebCore::CustomUndoStep::isValid const): 27 * editing/CustomUndoStep.h: 28 * editing/EditingStyle.cpp: 29 * editing/InsertEditableImageCommand.cpp: 30 (WebCore::InsertEditableImageCommand::doApply): 31 32 Unified build fixes. 33 34 * page/UndoItem.h: 35 1 36 2019-01-22 Simon Fraser <simon.fraser@apple.com> 2 37 -
trunk/Source/WebCore/Sources.txt
r240315 r240328 953 953 editing/CompositeEditCommand.cpp 954 954 editing/CreateLinkCommand.cpp 955 editing/CustomUndoStep.cpp 955 956 editing/DeleteFromTextNodeCommand.cpp 956 957 editing/DeleteSelectionCommand.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r240315 r240328 15132 15132 F4E1965A21F2395000285078 /* JSUndoItemCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSUndoItemCustom.cpp; sourceTree = "<group>"; }; 15133 15133 F4E1965F21F26E4E00285078 /* UndoItem.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UndoItem.cpp; sourceTree = "<group>"; }; 15134 F4E1966121F27D3C00285078 /* CustomUndoStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomUndoStep.h; sourceTree = "<group>"; }; 15135 F4E1966221F27D3D00285078 /* CustomUndoStep.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomUndoStep.cpp; sourceTree = "<group>"; }; 15134 15136 F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributeChanges.h; sourceTree = "<group>"; }; 15135 15137 F4E57EDF213F434A004EA98E /* WebCoreNSFontManagerExtras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCoreNSFontManagerExtras.h; sourceTree = "<group>"; }; … … 21108 21110 D0B0556709C6700100307E43 /* CreateLinkCommand.cpp */, 21109 21111 D0B0556609C6700100307E43 /* CreateLinkCommand.h */, 21112 F4E1966221F27D3D00285078 /* CustomUndoStep.cpp */, 21113 F4E1966121F27D3C00285078 /* CustomUndoStep.h */, 21110 21114 93309D8F099E64910056E581 /* DeleteFromTextNodeCommand.cpp */, 21111 21115 93309D90099E64910056E581 /* DeleteFromTextNodeCommand.h */, -
trunk/Source/WebCore/editing/CustomUndoStep.cpp
r240327 r240328 24 24 */ 25 25 26 #pragma once 26 #include "config.h" 27 #include "CustomUndoStep.h" 27 28 29 #include "Document.h" 30 #include "UndoItem.h" 31 #include "UndoManager.h" 28 32 #include "VoidCallback.h" 29 #include <wtf/IsoMalloc.h>30 #include <wtf/RefCounted.h>31 #include <wtf/WeakPtr.h>32 #include <wtf/text/WTFString.h>33 33 34 34 namespace WebCore { 35 35 36 class Document; 37 class UndoManager; 36 CustomUndoStep::CustomUndoStep(UndoItem& item) 37 : m_undoItem(makeWeakPtr(item)) 38 { 39 } 38 40 39 class UndoItem : public RefCounted<UndoItem> { 40 WTF_MAKE_ISO_ALLOCATED(UndoItem); 41 public: 42 struct Init { 43 String label; 44 RefPtr<VoidCallback> undo; 45 RefPtr<VoidCallback> redo; 46 }; 41 void CustomUndoStep::unapply() 42 { 43 if (!isValid()) 44 return; 47 45 48 static Ref<UndoItem> create(Init&& init) 49 { 50 return adoptRef(*new UndoItem(WTFMove(init))); 51 } 46 // FIXME: It's currently unclear how input events should be dispatched when unapplying or reapplying custom 47 // edit commands. Should the page be allowed to specify a target in the DOM for undo and redo? 48 Ref<UndoItem> protectedUndoItem(*m_undoItem); 49 protectedUndoItem->document()->updateLayoutIgnorePendingStylesheets(); 50 protectedUndoItem->undoHandler().handleEvent(); 51 } 52 52 53 bool isValid() const; 54 void invalidate(); 53 void CustomUndoStep::reapply() 54 { 55 if (!isValid()) 56 return; 55 57 56 Document* document() const; 58 Ref<UndoItem> protectedUndoItem(*m_undoItem); 59 protectedUndoItem->document()->updateLayoutIgnorePendingStylesheets(); 60 protectedUndoItem->redoHandler().handleEvent(); 61 } 57 62 58 void setUndoManager(UndoManager*); 59 60 const String& label() const { return m_label; } 61 VoidCallback& undoHandler() const { return m_undoHandler.get(); } 62 VoidCallback& redoHandler() const { return m_redoHandler.get(); } 63 64 private: 65 UndoItem(Init&& init) 66 : m_label(WTFMove(init.label)) 67 , m_undoHandler(init.undo.releaseNonNull()) 68 , m_redoHandler(init.redo.releaseNonNull()) 69 { 70 } 71 72 String m_label; 73 Ref<VoidCallback> m_undoHandler; 74 Ref<VoidCallback> m_redoHandler; 75 WeakPtr<UndoManager> m_undoManager; 76 }; 63 bool CustomUndoStep::isValid() const 64 { 65 return m_undoItem && m_undoItem->isValid(); 66 } 77 67 78 68 } // namespace WebCore -
trunk/Source/WebCore/editing/CustomUndoStep.h
r240327 r240328 26 26 #pragma once 27 27 28 #include "VoidCallback.h" 29 #include <wtf/IsoMalloc.h> 30 #include <wtf/RefCounted.h> 28 #include "UndoStep.h" 29 #include <wtf/Ref.h> 31 30 #include <wtf/WeakPtr.h> 32 #include <wtf/text/WTFString.h>33 31 34 32 namespace WebCore { 35 33 36 34 class Document; 37 class Undo Manager;35 class UndoItem; 38 36 39 class UndoItem : public RefCounted<UndoItem> { 40 WTF_MAKE_ISO_ALLOCATED(UndoItem); 37 class CustomUndoStep final : public UndoStep { 41 38 public: 42 struct Init { 43 String label; 44 RefPtr<VoidCallback> undo; 45 RefPtr<VoidCallback> redo; 46 }; 47 48 static Ref<UndoItem> create(Init&& init) 39 static Ref<CustomUndoStep> create(UndoItem& item) 49 40 { 50 return adoptRef(*new UndoItem(WTFMove(init)));41 return adoptRef(*new CustomUndoStep(item)); 51 42 } 52 43 44 private: 45 CustomUndoStep(UndoItem&); 46 47 void unapply() final; 48 void reapply() final; 49 EditAction editingAction() const final { return EditAction::Unspecified; } 50 53 51 bool isValid() const; 54 void invalidate();55 52 56 Document* document() const; 57 58 void setUndoManager(UndoManager*); 59 60 const String& label() const { return m_label; } 61 VoidCallback& undoHandler() const { return m_undoHandler.get(); } 62 VoidCallback& redoHandler() const { return m_redoHandler.get(); } 63 64 private: 65 UndoItem(Init&& init) 66 : m_label(WTFMove(init.label)) 67 , m_undoHandler(init.undo.releaseNonNull()) 68 , m_redoHandler(init.redo.releaseNonNull()) 69 { 70 } 71 72 String m_label; 73 Ref<VoidCallback> m_undoHandler; 74 Ref<VoidCallback> m_redoHandler; 75 WeakPtr<UndoManager> m_undoManager; 53 WeakPtr<UndoItem> m_undoItem; 76 54 }; 77 55 -
trunk/Source/WebCore/editing/EditingStyle.cpp
r239535 r240328 46 46 #include "NodeTraversal.h" 47 47 #include "QualifiedName.h" 48 #include "RenderElement.h" 48 49 #include "RenderStyle.h" 49 50 #include "StyleFontSizeFunctions.h" -
trunk/Source/WebCore/editing/InsertEditableImageCommand.cpp
r238708 r240328 50 50 51 51 m_imageElement = HTMLImageElement::create(document()); 52 m_imageElement->setAttributeWithoutSynchronization( x_apple_editable_imageAttr, emptyAtom());53 m_imageElement->setAttributeWithoutSynchronization( widthAttr, AtomicString("100%", AtomicString::ConstructFromLiteral));54 m_imageElement->setAttributeWithoutSynchronization( heightAttr, AtomicString("300px", AtomicString::ConstructFromLiteral));55 m_imageElement->setAttributeWithoutSynchronization( styleAttr, AtomicString("display: block", AtomicString::ConstructFromLiteral));52 m_imageElement->setAttributeWithoutSynchronization(HTMLNames::x_apple_editable_imageAttr, emptyAtom()); 53 m_imageElement->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString("100%", AtomicString::ConstructFromLiteral)); 54 m_imageElement->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString("300px", AtomicString::ConstructFromLiteral)); 55 m_imageElement->setAttributeWithoutSynchronization(HTMLNames::styleAttr, AtomicString("display: block", AtomicString::ConstructFromLiteral)); 56 56 57 57 insertNodeAt(*m_imageElement, endingSelection().start()); -
trunk/Source/WebCore/page/UndoItem.h
r240315 r240328 37 37 class UndoManager; 38 38 39 class UndoItem : public RefCounted<UndoItem> {39 class UndoItem : public RefCounted<UndoItem>, public CanMakeWeakPtr<UndoItem> { 40 40 WTF_MAKE_ISO_ALLOCATED(UndoItem); 41 41 public:
Note: See TracChangeset
for help on using the changeset viewer.