Convert position:sticky to position:static upon copy and paste
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Feb 2014 19:32:54 +0000 (19:32 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Feb 2014 19:32:54 +0000 (19:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128982

Reviewed by NOBODY (OOPS!).

Source/WebCore:

This patch has two parts:

1. Make sure that position:absolute elements trigger the position:relative wrapping (as
well as position:fixed)
2. Now that we copy position:sticky, convert that to position:fixed

Tests: editing/pasteboard/copy-paste-converts-fixed.html
       editing/pasteboard/copy-paste-converts-sticky.html
       editing/pasteboard/copy-paste-wraps-position-absolute.html

* editing/EditingStyle.cpp:
(WebCore::EditingStyle::convertFixedAndStickyPosition):

LayoutTests:

* editing/pasteboard/copy-paste-converts-fixed-expected.txt: Copied from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed-expected.txt.
* editing/pasteboard/copy-paste-converts-fixed.html: Copied from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed.html.
* editing/pasteboard/copy-paste-converts-sticky-expected.txt: Copied from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed-expected.txt.
* editing/pasteboard/copy-paste-converts-sticky.html: Copied from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed.html.
* editing/pasteboard/copy-paste-wraps-position-absolute-expected.txt: Renamed from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed-expected.txt.
* editing/pasteboard/copy-paste-wraps-position-absolute.html: Renamed from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed.html.

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

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/copy-paste-converts-fixed-expected.txt [moved from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed-expected.txt with 78% similarity]
LayoutTests/editing/pasteboard/copy-paste-converts-fixed.html [moved from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed.html with 80% similarity]
LayoutTests/editing/pasteboard/copy-paste-converts-sticky-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-paste-converts-sticky.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-paste-wraps-position-absolute-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-paste-wraps-position-absolute.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/EditingStyle.cpp

index 5a1801c..ec8d114 100644 (file)
@@ -1,3 +1,17 @@
+2014-02-18  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Convert position:sticky to position:static upon copy and paste
+        https://bugs.webkit.org/show_bug.cgi?id=128982
+
+        Reviewed by Simon Fraser.
+
+        * editing/pasteboard/copy-paste-converts-fixed-expected.txt: Copied from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed-expected.txt.
+        * editing/pasteboard/copy-paste-converts-fixed.html: Copied from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed.html.
+        * editing/pasteboard/copy-paste-converts-sticky-expected.txt: Copied from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed-expected.txt.
+        * editing/pasteboard/copy-paste-converts-sticky.html: Copied from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed.html.
+        * editing/pasteboard/copy-paste-wraps-position-absolute-expected.txt: Renamed from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed-expected.txt.
+        * editing/pasteboard/copy-paste-wraps-position-absolute.html: Renamed from LayoutTests/editing/pasteboard/copy-paste-converts-sticky-and-fixed.html.
+
 2014-02-18  Mihai Tica  <mitica@adobe.com>
 
         [CSS Blending] Add -webkit-blend-mode support for SVG.
@@ -1,4 +1,4 @@
-These tests to see if position:sticky and position:fixed get converted to position:static and position:absolute upon copy/paste
+This tests to see if position:fixed gets converted to position:absolute upon copy/paste
 
 first test - before:
 | <html>
@@ -32,7 +32,7 @@ abc"
 |     <script>
 |       "
 
-Markup.description('These tests to see if position:sticky and position:fixed get converted to position:static and position:absolute upon copy/paste');
+Markup.description('This tests to see if position:fixed gets converted to position:absolute upon copy/paste');
 
 document.designMode = 'on';
 
@@ -80,7 +80,7 @@ first test - after:
 |     <script>
 |       "
 
-Markup.description('These tests to see if position:sticky and position:fixed get converted to position:static and position:absolute upon copy/paste');
+Markup.description('This tests to see if position:fixed gets converted to position:absolute upon copy/paste');
 
 document.designMode = 'on';
 
@@ -9,7 +9,7 @@ abc<div style="position: fixed; left: 0px; top: 0px;">def</div>ghi
 
 <script>
 
-Markup.description('These tests to see if position:sticky and position:fixed get converted to position:static and position:absolute upon copy/paste');
+Markup.description('This tests to see if position:fixed gets converted to position:absolute upon copy/paste');
 
 document.designMode = 'on';
 
diff --git a/LayoutTests/editing/pasteboard/copy-paste-converts-sticky-expected.txt b/LayoutTests/editing/pasteboard/copy-paste-converts-sticky-expected.txt
new file mode 100644 (file)
index 0000000..9e98c64
--- /dev/null
@@ -0,0 +1,95 @@
+This tests to see if position:sticky gets converted to position:static upon copy/paste
+
+first test - before:
+| <html>
+|   <head>
+|     "
+"
+|     <meta>
+|       content="text/html; charset=utf-8"
+|       http-equiv="Content-type"
+|     "
+"
+|     <script>
+|       src="../../resources/dump-as-markup.js"
+|       type="text/javascript"
+|     "
+"
+|   "
+"
+|   <body>
+|     "
+abc"
+|     <div>
+|       style="position: -webkit-sticky; left: 0px; top: 0px;"
+|       "def"
+|     "ghi
+"
+|     <br>
+|     "
+
+"
+|     <script>
+|       "
+
+Markup.description('This tests to see if position:sticky gets converted to position:static upon copy/paste');
+
+document.designMode = 'on';
+
+if (window.internals)
+    window.internals.settings.setShouldConvertPositionStyleOnCopy(true);
+
+var s = window.getSelection();
+
+Markup.dump('test1', 'first test - before');
+document.execCommand("SelectAll");
+document.execCommand("Cut");
+document.execCommand("Paste");
+Markup.dump('test1', 'first test - after');
+
+"
+
+first test - after:
+| <html>
+|   <head>
+|     "
+"
+|     <meta>
+|       content="text/html; charset=utf-8"
+|       http-equiv="Content-type"
+|     "
+"
+|     <script>
+|       src="../../resources/dump-as-markup.js"
+|       type="text/javascript"
+|     "
+"
+|   "
+"
+|   <body>
+|     "abc"
+|     <div>
+|       style="position: static; left: 0px; top: 0px;"
+|       "def"
+|     "ghi <#selection-caret>
+
+"
+|     <script>
+|       "
+
+Markup.description('This tests to see if position:sticky gets converted to position:static upon copy/paste');
+
+document.designMode = 'on';
+
+if (window.internals)
+    window.internals.settings.setShouldConvertPositionStyleOnCopy(true);
+
+var s = window.getSelection();
+
+Markup.dump('test1', 'first test - before');
+document.execCommand("SelectAll");
+document.execCommand("Cut");
+document.execCommand("Paste");
+Markup.dump('test1', 'first test - after');
+
+"
diff --git a/LayoutTests/editing/pasteboard/copy-paste-converts-sticky.html b/LayoutTests/editing/pasteboard/copy-paste-converts-sticky.html
new file mode 100644 (file)
index 0000000..d54b16d
--- /dev/null
@@ -0,0 +1,29 @@
+<html>
+<head>
+<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+<script type="text/javascript" src="../../resources/dump-as-markup.js"></script>
+</head>
+<body>
+abc<div style="position: -webkit-sticky; left: 0px; top: 0px;">def</div>ghi
+<br/>
+
+<script>
+
+Markup.description('This tests to see if position:sticky gets converted to position:static upon copy/paste');
+
+document.designMode = 'on';
+
+if (window.internals)
+    window.internals.settings.setShouldConvertPositionStyleOnCopy(true);
+
+var s = window.getSelection();
+
+Markup.dump('test1', 'first test - before');
+document.execCommand("SelectAll");
+document.execCommand("Cut");
+document.execCommand("Paste");
+Markup.dump('test1', 'first test - after');
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/editing/pasteboard/copy-paste-wraps-position-absolute-expected.txt b/LayoutTests/editing/pasteboard/copy-paste-wraps-position-absolute-expected.txt
new file mode 100644 (file)
index 0000000..7dd19bc
--- /dev/null
@@ -0,0 +1,98 @@
+This tests to see if position:absolute gets wrapped with a position:relative upon copy/paste
+
+first test - before:
+| <html>
+|   <head>
+|     "
+"
+|     <meta>
+|       content="text/html; charset=utf-8"
+|       http-equiv="Content-type"
+|     "
+"
+|     <script>
+|       src="../../resources/dump-as-markup.js"
+|       type="text/javascript"
+|     "
+"
+|   "
+"
+|   <body>
+|     "
+abc"
+|     <div>
+|       style="position: absolute; left: 0px; top: 0px;"
+|       "def"
+|     "ghi
+"
+|     <br>
+|     "
+
+"
+|     <script>
+|       "
+
+Markup.description('This tests to see if position:absolute gets wrapped with a position:relative upon copy/paste');
+
+document.designMode = 'on';
+
+if (window.internals)
+    window.internals.settings.setShouldConvertPositionStyleOnCopy(true);
+
+var s = window.getSelection();
+
+Markup.dump('test1', 'first test - before');
+document.execCommand("SelectAll");
+document.execCommand("Cut");
+document.execCommand("Paste");
+Markup.dump('test1', 'first test - after');
+
+"
+
+first test - after:
+| <html>
+|   <head>
+|     "
+"
+|     <meta>
+|       content="text/html; charset=utf-8"
+|       http-equiv="Content-type"
+|     "
+"
+|     <script>
+|       src="../../resources/dump-as-markup.js"
+|       type="text/javascript"
+|     "
+"
+|   "
+"
+|   <body>
+|     <div>
+|       style="position: relative;"
+|       "abc"
+|       <div>
+|         style="position: absolute; left: 0px; top: 0px;"
+|         "def"
+|       "ghi <#selection-caret>"
+|     "
+
+"
+|     <script>
+|       "
+
+Markup.description('This tests to see if position:absolute gets wrapped with a position:relative upon copy/paste');
+
+document.designMode = 'on';
+
+if (window.internals)
+    window.internals.settings.setShouldConvertPositionStyleOnCopy(true);
+
+var s = window.getSelection();
+
+Markup.dump('test1', 'first test - before');
+document.execCommand("SelectAll");
+document.execCommand("Cut");
+document.execCommand("Paste");
+Markup.dump('test1', 'first test - after');
+
+"
diff --git a/LayoutTests/editing/pasteboard/copy-paste-wraps-position-absolute.html b/LayoutTests/editing/pasteboard/copy-paste-wraps-position-absolute.html
new file mode 100644 (file)
index 0000000..1ceed4c
--- /dev/null
@@ -0,0 +1,29 @@
+<html>
+<head>
+<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+<script type="text/javascript" src="../../resources/dump-as-markup.js"></script>
+</head>
+<body>
+abc<div style="position: absolute; left: 0px; top: 0px;">def</div>ghi
+<br/>
+
+<script>
+
+Markup.description('This tests to see if position:absolute gets wrapped with a position:relative upon copy/paste');
+
+document.designMode = 'on';
+
+if (window.internals)
+    window.internals.settings.setShouldConvertPositionStyleOnCopy(true);
+
+var s = window.getSelection();
+
+Markup.dump('test1', 'first test - before');
+document.execCommand("SelectAll");
+document.execCommand("Cut");
+document.execCommand("Paste");
+Markup.dump('test1', 'first test - after');
+
+</script>
+</body>
+</html>
index 2c6c7ab..ba1d0ee 100644 (file)
@@ -1,3 +1,23 @@
+2014-02-18  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Convert position:sticky to position:static upon copy and paste
+        https://bugs.webkit.org/show_bug.cgi?id=128982
+
+        Reviewed by Simon Fraser.
+
+        This patch has two parts:
+
+        1. Make sure that position:absolute elements trigger the position:relative wrapping (as
+        well as position:fixed)
+        2. Now that we copy position:sticky, convert that to position:fixed
+
+        Tests: editing/pasteboard/copy-paste-converts-fixed.html
+               editing/pasteboard/copy-paste-converts-sticky.html
+               editing/pasteboard/copy-paste-wraps-position-absolute.html
+
+        * editing/EditingStyle.cpp:
+        (WebCore::EditingStyle::convertFixedAndStickyPosition):
+
 2014-02-18  David Kilzer  <ddkilzer@apple.com>
 
         Add type-checked casts for StyleImage and subclasses
index 7b6fad1..13cde05 100644 (file)
@@ -1227,11 +1227,18 @@ bool EditingStyle::convertFixedAndStickyPosition()
         return false;
 
     RefPtr<CSSPrimitiveValue> sticky = cssValuePool().createIdentifierValue(CSSValueWebkitSticky);
+    if (m_mutableStyle->propertyMatches(CSSPropertyPosition, sticky.get())) {
+        m_mutableStyle->setProperty(CSSPropertyPosition, cssValuePool().createIdentifierValue(CSSValueStatic), m_mutableStyle->propertyIsImportant(CSSPropertyPosition));
+        return false;
+    }
     RefPtr<CSSPrimitiveValue> fixed = cssValuePool().createIdentifierValue(CSSValueFixed);
     if (m_mutableStyle->propertyMatches(CSSPropertyPosition, fixed.get())) {
         m_mutableStyle->setProperty(CSSPropertyPosition, cssValuePool().createIdentifierValue(CSSValueAbsolute), m_mutableStyle->propertyIsImportant(CSSPropertyPosition));
         return true;
     }
+    RefPtr<CSSPrimitiveValue> absolute = cssValuePool().createIdentifierValue(CSSValueAbsolute);
+    if (m_mutableStyle->propertyMatches(CSSPropertyPosition, absolute.get()))
+        return true;
     return false;
 }