Cannot select a canvas element at the beginning or the end of a document
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2013 06:52:33 +0000 (06:52 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2013 06:52:33 +0000 (06:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112319

Reviewed by Eric Seidel.

Source/WebCore:

The bug was caused by the editing code treating canvas element as if an empty inline element.
Treat it as an "atomic" element for the purpose of determining whether selection can have
an end point in it or not.

Test: editing/pasteboard/copy-paste-content-starting-and-ending-canvas.html

* html/HTMLCanvasElement.h:
(WebCore::HTMLCanvasElement::canContainRangeEndPoint): Added.

LayoutTests:

Add a regression test to copy and paste a content with canvas elements.

* editing/pasteboard/copy-paste-content-starting-and-ending-canvas-expected.txt: Added.
* editing/pasteboard/copy-paste-content-starting-and-ending-canvas.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/copy-paste-content-starting-and-ending-canvas-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-paste-content-starting-and-ending-canvas.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLCanvasElement.h

index 673e90a..38cc80d 100644 (file)
@@ -1,3 +1,15 @@
+2013-03-13  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Cannot select a canvas element at the beginning or the end of a document
+        https://bugs.webkit.org/show_bug.cgi?id=112319
+
+        Reviewed by Eric Seidel.
+
+        Add a regression test to copy and paste a content with canvas elements.
+
+        * editing/pasteboard/copy-paste-content-starting-and-ending-canvas-expected.txt: Added.
+        * editing/pasteboard/copy-paste-content-starting-and-ending-canvas.html: Added.
+
 2013-03-13  Kunihiko Sakamoto  <ksakamoto@chromium.org>
 
         Implement FontLoader interface
diff --git a/LayoutTests/editing/pasteboard/copy-paste-content-starting-and-ending-canvas-expected.txt b/LayoutTests/editing/pasteboard/copy-paste-content-starting-and-ending-canvas-expected.txt
new file mode 100644 (file)
index 0000000..03edc7b
--- /dev/null
@@ -0,0 +1,47 @@
+This tests selecting all, copying, and pasting a content that starts and ends with canvas elements.
+To manually test, copy and paste the content below:
+
+Before paste:
+| "
+"
+| <canvas>
+|   height="100"
+|   style="border: 1px solid black"
+|   width="100"
+| "
+some text
+"
+| <canvas>
+|   height="100"
+|   style="border: 1px solid black"
+|   width="100"
+| "
+some more text
+"
+| <canvas>
+|   height="100"
+|   style="border: 1px solid black"
+|   width="100"
+| "
+"
+
+After paste:
+| <canvas>
+|   height="100"
+|   style="border: 1px solid black;"
+|   width="100"
+| " "
+| "some text"
+| " "
+| <canvas>
+|   height="100"
+|   style="border: 1px solid black;"
+|   width="100"
+| " "
+| "some more text"
+| " "
+| <canvas>
+|   height="100"
+|   style="border: 1px solid black;"
+|   width="100"
+| <br>
diff --git a/LayoutTests/editing/pasteboard/copy-paste-content-starting-and-ending-canvas.html b/LayoutTests/editing/pasteboard/copy-paste-content-starting-and-ending-canvas.html
new file mode 100644 (file)
index 0000000..6307d93
--- /dev/null
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p id="description">This tests selecting all, copying, and pasting a content that starts and ends with canvas elements.
+To manually test, copy and paste the content below:</p>
+<div id="editor" contenteditable>
+<canvas width="100" height="100" style="border: 1px solid black"></canvas>
+some text
+<canvas width="100" height="100" style="border: 1px solid black"></canvas>
+some more text
+<canvas width="100" height="100" style="border: 1px solid black"></canvas>
+</div>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+
+Markup.description(document.getElementById('description').textContent);
+
+var editor = document.getElementById('editor');
+editor.focus();
+document.execCommand('selectAll');
+
+document.execCommand('copy');
+Markup.dump(editor, 'Before paste');
+
+if (document.queryCommandSupported('copy') && document.queryCommandSupported('paste')) {
+    document.execCommand('paste');
+    Markup.dump(editor, 'After paste');
+} else
+    editor.onpaste = function () { setTimeout(function () { Markup.dump(editor, 'After paste'); }, 0); }
+
+</script>
+</body>
+</html>
index 9a2a8ca..bc26279 100644 (file)
@@ -1,3 +1,19 @@
+2013-03-13  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Cannot select a canvas element at the beginning or the end of a document
+        https://bugs.webkit.org/show_bug.cgi?id=112319
+
+        Reviewed by Eric Seidel.
+
+        The bug was caused by the editing code treating canvas element as if an empty inline element.
+        Treat it as an "atomic" element for the purpose of determining whether selection can have
+        an end point in it or not.
+
+        Test: editing/pasteboard/copy-paste-content-starting-and-ending-canvas.html
+
+        * html/HTMLCanvasElement.h:
+        (WebCore::HTMLCanvasElement::canContainRangeEndPoint): Added.
+
 2013-03-13  Kunihiko Sakamoto  <ksakamoto@chromium.org>
 
         Implement FontLoader interface
index 40067ee..cd9821c 100644 (file)
@@ -139,6 +139,8 @@ public:
 
     float deviceScaleFactor() const { return m_deviceScaleFactor; }
 
+    virtual bool canContainRangeEndPoint() const { return false; }
+
     virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
 
 private: