Commit 67a06f94 authored by rniwa@webkit.org's avatar rniwa@webkit.org

2011-05-12 Ryosuke Niwa <rniwa@webkit.org>

        Reviewed by Darin Adler.

        WebKit inserts base, link, meta, style, and title elements into an editable region
        when pasting table cells from Excel
        https://bugs.webkit.org/show_bug.cgi?id=60644

        Added a test to ensure WebKit strips the said elements prior to inserting HTML.

        * editing/pasteboard/paste-head-contents-expected.txt: Added.
        * editing/pasteboard/paste-head-contents.html: Added.
2011-05-12  Ryosuke Niwa  <rniwa@webkit.org>

        Reviewed by Darin Adler.

        WebKit inserts base, link, meta, style, and title elements into an editable region
        when pasting table cells from Excel
        https://bugs.webkit.org/show_bug.cgi?id=60644

        Strip base, link, meta, style, and tile elements from the fragment to be pasted prior
        to the merge. We don't have to strip these elements in performTrivialReplace because
        the function only handles a fragment that consists of exactly one text node.

        Test: editing/pasteboard/paste-head-contents.html

        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::removeHeadContents): Added.
        (WebCore::ReplaceSelectionCommand::doApply): Calls removeHeadContents before handing
        style spans.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@86360 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 61516486
2011-05-12 Ryosuke Niwa <rniwa@webkit.org>
Reviewed by Darin Adler.
WebKit inserts base, link, meta, style, and title elements into an editable region
when pasting table cells from Excel
https://bugs.webkit.org/show_bug.cgi?id=60644
Added a test to ensure WebKit strips the said elements prior to inserting HTML.
* editing/pasteboard/paste-head-contents-expected.txt: Added.
* editing/pasteboard/paste-head-contents.html: Added.
2011-05-08 Abhishek Arya <inferno@chromium.org> and Carol Szabo <carol@webkit.org>
Reviewed by David Hyatt.
This test ensures WebKit strips away base, link, meta, style, and title elements before inserting HTML.
PASS
<!DOCTYPE html>
<html>
<body>
<script type="data:text/html">
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 14">
<link id=Main-File rel=Main-File href="dummy_path">
<link rel=File-List href="dummy_path2">
<base href="dummy-base">
<title>Dummy Title</title>
<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
@page
{margin:1.0in .75in 1.0in .75in;
mso-header-margin:.5in;
mso-footer-margin:.5in;}
td
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:none;
mso-background-source:auto;
mso-pattern:auto;
mso-protection:locked visible;
white-space:nowrap;
mso-rotate:0;}
-->
</style>
</head>
<body link=blue vlink=purple>
<table border=0 cellpadding=0 cellspacing=0 width=130 style='border-collapse:
collapse;width:130pt'>
<!--StartFragment-->
<col width=65 span=2 style='width:65pt'>
<tr height=15 style='height:15.0pt'>
<td height=15 width=65 style='height:15.0pt;width:65pt'>hello</td>
<td width=65 style='width:65pt'>world</td>
</tr>
<tr height=15 style='height:15.0pt'>
<td height=15 style='height:15.0pt'></td>
<td>webkit</td>
</tr>
<!--EndFragment-->
</table>
</body>
</html>
</script>
<p>This test ensures WebKit strips away base, link, meta, style, and title elements before inserting HTML.</p>
<div id="test" contenteditable></div>
<pre><script type="text/javascript">
var htmlInPasteboard = document.getElementsByTagName('script')[0].firstChild.textContent;
document.getElementById('test').focus();
document.execCommand('InsertHTML', false, htmlInPasteboard);
var passed = true;
function expectNoInstanceOf(elementName) {
var elements = document.body.getElementsByTagName(elementName);
if (elements.length <= 0)
return;
document.write('FAIL - found ' + elements.length + ' ');
document.write(elements.length == 1 ? 'instance' : 'instances');
document.writeln(' of ' + elementName + ' element');
passed = false;
}
if (window.layoutTestController)
layoutTestController.dumpAsText();
expectNoInstanceOf('base');
expectNoInstanceOf('meta');
expectNoInstanceOf('link');
expectNoInstanceOf('title');
expectNoInstanceOf('style');
if (passed)
document.writeln('PASS');
document.getElementById('test').innerHTML = '';
</script></pre>
</body>
</html>
\ No newline at end of file
2011-05-12 Ryosuke Niwa <rniwa@webkit.org>
Reviewed by Darin Adler.
WebKit inserts base, link, meta, style, and title elements into an editable region
when pasting table cells from Excel
https://bugs.webkit.org/show_bug.cgi?id=60644
Strip base, link, meta, style, and tile elements from the fragment to be pasted prior
to the merge. We don't have to strip these elements in performTrivialReplace because
the function only handles a fragment that consists of exactly one text node.
Test: editing/pasteboard/paste-head-contents.html
* editing/ReplaceSelectionCommand.cpp:
(WebCore::removeHeadContents): Added.
(WebCore::ReplaceSelectionCommand::doApply): Calls removeHeadContents before handing
style spans.
2011-05-12 Levi Weintraub <leviw@chromium.org>
Reviewed by Simon Fraser.
......@@ -551,6 +551,22 @@ VisiblePosition ReplaceSelectionCommand::positionAtStartOfInsertedContent()
return VisiblePosition(nextCandidate(positionInParentBeforeNode(m_firstNodeInserted.get())));
}
static void removeHeadContents(ReplacementFragment& fragment)
{
Node* next = 0;
for (Node* node = fragment.firstChild(); node; node = next) {
if (node->hasTagName(baseTag)
|| node->hasTagName(linkTag)
|| node->hasTagName(metaTag)
|| node->hasTagName(styleTag)
|| node->hasTagName(titleTag)) {
next = node->traverseNextSibling();
fragment.removeNode(node);
} else
next = node->traverseNextNode();
}
}
// Remove style spans before insertion if they are unnecessary. It's faster because we'll
// avoid doing a layout.
static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const Position& insertionPos)
......@@ -937,7 +953,9 @@ void ReplaceSelectionCommand::doApply()
// any work performed after this that queries or uses the typing style.
if (Frame* frame = document()->frame())
frame->selection()->clearTypingStyle();
removeHeadContents(fragment);
bool handledStyleSpans = handleStyleSpansBeforeInsertion(fragment, insertionPos);
// We don't want the destination to end up inside nodes that weren't selected. To avoid that, we move the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment