Bug 193111 - [Cocoa] Allow the page to add to the platform undo stack via UndoManager.addItem()
Summary: [Cocoa] Allow the page to add to the platform undo stack via UndoManager.addI...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: InRadar
Depends on: 193109
Blocks:
  Show dependency treegraph
 
Reported: 2019-01-03 10:23 PST by Wenson Hsieh
Modified: 2019-01-22 19:44 PST (History)
19 users (show)

See Also:


Attachments
WIP (with tests) (62.94 KB, patch)
2019-01-04 20:45 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Part 1 (22.68 KB, patch)
2019-01-18 09:34 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch (32.88 KB, patch)
2019-01-18 23:43 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Part 1 (18.17 KB, patch)
2019-01-18 23:52 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Part 1 (w/ unified build fix) (18.71 KB, patch)
2019-01-19 00:15 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Part 1 (fix typo in title) (18.70 KB, patch)
2019-01-19 00:29 PST, Wenson Hsieh
rniwa: review+
Details | Formatted Diff | Diff
Part 2 (CustomUndoStep) (13.25 KB, patch)
2019-01-19 00:34 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Part 3 (56.45 KB, patch)
2019-01-19 20:41 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Part 3 (56.39 KB, patch)
2019-01-19 20:54 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch for landing (18.77 KB, patch)
2019-01-22 17:30 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Part 2 (rebase on trunk) (13.42 KB, patch)
2019-01-22 18:38 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Part 2 (fix GTK/WPE builds) (13.55 KB, patch)
2019-01-22 18:53 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wenson Hsieh 2019-01-03 10:23:29 PST
<rdar://problem/44807048>
Comment 1 Wenson Hsieh 2019-01-04 20:45:23 PST Comment hidden (obsolete)
Comment 2 Wenson Hsieh 2019-01-18 09:34:59 PST Comment hidden (obsolete)
Comment 3 Wenson Hsieh 2019-01-18 23:43:24 PST Comment hidden (obsolete)
Comment 4 Wenson Hsieh 2019-01-18 23:52:05 PST Comment hidden (obsolete)
Comment 5 Wenson Hsieh 2019-01-19 00:15:42 PST Comment hidden (obsolete)
Comment 6 Wenson Hsieh 2019-01-19 00:29:10 PST
Created attachment 359593 [details]
Part 1 (fix typo in title)
Comment 7 Wenson Hsieh 2019-01-19 00:34:29 PST
Created attachment 359594 [details]
Part 2 (CustomUndoStep)
Comment 8 Wenson Hsieh 2019-01-19 20:41:14 PST Comment hidden (obsolete)
Comment 9 Wenson Hsieh 2019-01-19 20:54:05 PST
Created attachment 359632 [details]
Part 3
Comment 10 Ryosuke Niwa 2019-01-22 14:32:08 PST
Comment on attachment 359593 [details]
Part 1 (fix typo in title)

View in context: https://bugs.webkit.org/attachment.cgi?id=359593&action=review

> Source/WebCore/bindings/js/JSUndoItemCustom.cpp:47
> +    if (UNLIKELY(reason))
> +        *reason = "Document is an opaque root.";

You can always set the reason even if you were to return false.
So the idiomatic way of writing isReachableFromOpaqueRoots is to put this code at the beginning of the function.

> Source/WebCore/page/UndoItem.cpp:55
> +    return isValid() ? &m_undoManager->document() : nullptr;

I'd prefer clearing m_undoManager in invalidate() instead.
That way, UndoItem would be destructed even after it had been removed from UndoManager
e.g. via some kind of clear() operation in the future.

> Source/WebCore/page/UndoManager.cpp:59
> +    auto items = std::exchange(m_items, { });

I think you can just iterate over m_items and call clear at the end.
There is no reentrancy concern here.
Comment 11 Wenson Hsieh 2019-01-22 16:12:06 PST
Comment on attachment 359593 [details]
Part 1 (fix typo in title)

View in context: https://bugs.webkit.org/attachment.cgi?id=359593&action=review

>> Source/WebCore/bindings/js/JSUndoItemCustom.cpp:47
>> +        *reason = "Document is an opaque root.";
> 
> You can always set the reason even if you were to return false.
> So the idiomatic way of writing isReachableFromOpaqueRoots is to put this code at the beginning of the function.

Ah, I see! Fixed.

>> Source/WebCore/page/UndoItem.cpp:55
>> +    return isValid() ? &m_undoManager->document() : nullptr;
> 
> I'd prefer clearing m_undoManager in invalidate() instead.
> That way, UndoItem would be destructed even after it had been removed from UndoManager
> e.g. via some kind of clear() operation in the future.

So in my patch, UndoItem::invalidate() already does null out m_undoManager by using std::exchange(m_undoManager, nullptr). But maybe this was too subtle :/

I'll change this to set m_undoManager to nullptr instead, to make it more obvious...

>> Source/WebCore/page/UndoManager.cpp:59
>> +    auto items = std::exchange(m_items, { });
> 
> I think you can just iterate over m_items and call clear at the end.
> There is no reentrancy concern here.

The reason I used std::exchange here is that UndoItem::invalidate calls back into UndoManager::removeItem to actually remove the UndoItem from the UndoManager, and so iterating over m_items while invalidating each item is going to cause m_items to mutate during iteration.

On second thought, this code is unnecessarily convoluted; I'll refactor this...
Comment 12 Wenson Hsieh 2019-01-22 17:30:04 PST
Created attachment 359819 [details]
Patch for landing
Comment 13 WebKit Commit Bot 2019-01-22 18:06:58 PST
Comment on attachment 359819 [details]
Patch for landing

Clearing flags on attachment: 359819

Committed r240315: <https://trac.webkit.org/changeset/240315>
Comment 14 WebKit Commit Bot 2019-01-22 18:07:00 PST
All reviewed patches have been landed.  Closing bug.
Comment 15 Wenson Hsieh 2019-01-22 18:38:00 PST
Reopening to attach new patch.
Comment 16 Wenson Hsieh 2019-01-22 18:38:01 PST
Created attachment 359832 [details]
Part 2 (rebase on trunk)
Comment 17 Wenson Hsieh 2019-01-22 18:53:45 PST
Created attachment 359834 [details]
Part 2 (fix GTK/WPE builds)
Comment 18 Ryosuke Niwa 2019-01-22 19:42:13 PST
Can we file a separate bug for part 2? It's confusing to post multiple patches per Bugzilla bug like this.
Comment 19 Wenson Hsieh 2019-01-22 19:43:59 PST
(In reply to Ryosuke Niwa from comment #18)
> Can we file a separate bug for part 2? It's confusing to post multiple
> patches per Bugzilla bug like this.

Sure thing — filed <https://bugs.webkit.org/show_bug.cgi?id=193704>.