When a selected node in nested ShadowDOM is deleted, selection have wrong range.
https://bugs.webkit.org/show_bug.cgi?id=106526

Reviewed by Ryosuke Niwa.

Source/WebCore:

Since FrameSelection and htmlediting did not consider nested Shadow DOM, the FrameSelection still selects
removed elements if selected nodes in nested Shadow DOM are removed.

We have to use containsIncludingShadowDOM to handle with nested Shadow DOM correctly.

Test: fast/dom/shadow/selection-in-nested-shadow.html

* editing/FrameSelection.cpp:
(WebCore::removingNodeRemovesPosition):
* editing/htmlediting.cpp:
(WebCore::updatePositionForNodeRemoval):

LayoutTests:

* fast/dom/shadow/selection-in-nested-shadow-expected.txt: Added.
* fast/dom/shadow/selection-in-nested-shadow.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@139401 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Elements must be reattached when inserted/removed from top layer
https://bugs.webkit.org/show_bug.cgi?id=105489

Reviewed by Julien Chaffraix.

Source/WebCore:

Ensure a reattach occurs when an element is inserted/removed from top layer, so its renderer can be inserted correctly:
as a child of RenderView in top layer sibling order if it's in the top layer, and in the usual place otherwise.

We previously relied on style recalc to catch when an element is inserted/removed from the top layer, because it
only happens on dialog.show/close which toggle display: none. But that is incorrect because, for example, close()
followed immediately by show() results in no style change.

Tests: fast/dom/HTMLDialogElement/removed-element-is-removed-from-top-layer.html
       fast/dom/HTMLDialogElement/top-layer-stacking-correct-order-remove-readd.html

* dom/Element.cpp:
(WebCore::Element::removedFrom): Call Document::removeFromTopLayer to let the element be removed from the top layer vector.
removeFromTopLayer calls Element::setIsInTopLayer(false) itself if needed.
(WebCore::Element::setIsInTopLayer): Ensure a reattach occurs if the element is already attached.

LayoutTests:

* fast/dom/HTMLDialogElement/removed-element-is-removed-from-top-layer-expected.html: Added.
* fast/dom/HTMLDialogElement/removed-element-is-removed-from-top-layer.html: Added.
This tests that a top layer element removed from the document does not reappear in the top layer if readded.
This test actually would pass before this patch, but just by good fortune (see bug).
* fast/dom/HTMLDialogElement/top-layer-stacking-correct-order-remove-readd-expected.html: Added.
* fast/dom/HTMLDialogElement/top-layer-stacking-correct-order-remove-readd.html: Added.
This tests that top layer ordering is correct after removing and readding an element to the top layer.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@139402 268f45cc-cd09-0410-ab3c-d52691b4dbfc