diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-03 18:26:08 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-03 18:26:08 +0000 |
commit | 3acb7453d8ab3234cbf005176d4c36e19cdc2cc4 (patch) | |
tree | 20fb06a3f4f5272ca90174f6d394f3fdbb3724f2 /app/clipboard/clipboard_util_win.cc | |
parent | a493faf3fe87e23bcd4baa659427b06b90dff0d5 (diff) | |
download | chromium_src-3acb7453d8ab3234cbf005176d4c36e19cdc2cc4.zip chromium_src-3acb7453d8ab3234cbf005176d4c36e19cdc2cc4.tar.gz chromium_src-3acb7453d8ab3234cbf005176d4c36e19cdc2cc4.tar.bz2 |
Fix bug 17333: Can't copy-paste text from OpenOffice to a contenteditable DIV
BUG=17333
TEST=ClipboardTest.HtmlTest
Review URL: http://codereview.chromium.org/661429
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40523 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/clipboard/clipboard_util_win.cc')
-rw-r--r-- | app/clipboard/clipboard_util_win.cc | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/app/clipboard/clipboard_util_win.cc b/app/clipboard/clipboard_util_win.cc index 870d789..37b78f7 100644 --- a/app/clipboard/clipboard_util_win.cc +++ b/app/clipboard/clipboard_util_win.cc @@ -488,14 +488,36 @@ void ClipboardUtil::CFHtmlToHtml(const std::string& cf_html, } } - // Find the markup between "<!--StartFragment -->" and "<!--EndFragment-->". + // Find the markup between "<!--StartFragment-->" and "<!--EndFragment-->". + // If the comments cannot be found, like copying from OpenOffice Writer, + // we simply fall back to using StartFragment/EndFragment bytecount values + // to get the markup. if (html) { + size_t fragment_start = std::string::npos; + size_t fragment_end = std::string::npos; + std::string cf_html_lower = StringToLowerASCII(cf_html); size_t markup_start = cf_html_lower.find("<html", 0); - size_t tag_start = cf_html.find("StartFragment", markup_start); - size_t fragment_start = cf_html.find('>', tag_start) + 1; - size_t tag_end = cf_html.rfind("EndFragment", std::string::npos); - size_t fragment_end = cf_html.rfind('<', tag_end); + size_t tag_start = cf_html.find("<!--StartFragment", markup_start); + if (tag_start == std::string::npos) { + static std::string start_fragment_str("StartFragment:"); + size_t start_fragment_start = cf_html.find(start_fragment_str); + if (start_fragment_start != std::string::npos) { + fragment_start = static_cast<size_t>(atoi(cf_html.c_str() + + start_fragment_start + start_fragment_str.length())); + } + + static std::string end_fragment_str("EndFragment:"); + size_t end_fragment_start = cf_html.find(end_fragment_str); + if (end_fragment_start != std::string::npos) { + fragment_end = static_cast<size_t>(atoi(cf_html.c_str() + + end_fragment_start + end_fragment_str.length())); + } + } else { + fragment_start = cf_html.find('>', tag_start) + 1; + size_t tag_end = cf_html.rfind("<!--EndFragment", std::string::npos); + fragment_end = cf_html.rfind('<', tag_end); + } if (fragment_start != std::string::npos && fragment_end != std::string::npos) { *html = cf_html.substr(fragment_start, fragment_end - fragment_start); |