Commit 05cb5205 authored by dcheng@chromium.org's avatar dcheng@chromium.org

Adjust fragment indices appropriately when pasting HTML on Windows.

BUG=102406
TEST=Copy a long, complex document from docs.google.com and paste into a Gmail compose window.


Review URL: http://codereview.chromium.org/8429022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108050 0039d316-1c4b-4281-b951-d872f2087c98
parent cc246076
......@@ -143,6 +143,33 @@ TEST_F(ClipboardTest, TrickyHTMLTest) {
#endif // defined(OS_WIN)
}
#if defined(OS_WIN)
TEST_F(ClipboardTest, UniodeHTMLTest) {
Clipboard clipboard;
string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")),
markup_result;
std::string url, url_result;
{
ScopedClipboardWriter clipboard_writer(&clipboard);
clipboard_writer.WriteHTML(markup, url);
}
EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
Clipboard::BUFFER_STANDARD));
uint32 fragment_start;
uint32 fragment_end;
clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result,
&fragment_start, &fragment_end);
EXPECT_PRED2(MarkupMatches, markup, markup_result);
EXPECT_EQ(url, url_result);
// Make sure that fragment indices were adjusted when converting.
EXPECT_EQ(36, fragment_start);
EXPECT_EQ(56, fragment_end);
}
#endif // defined(OS_WIN)
#if defined(TOOLKIT_USES_GTK)
// Regression test for crbug.com/56298 (pasting empty HTML crashes Linux).
TEST_F(ClipboardTest, EmptyHTMLTest) {
......
......@@ -17,6 +17,7 @@
#include "base/stl_util.h"
#include "base/string_util.h"
#include "base/string_number_conversions.h"
#include "base/utf_offset_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/win/scoped_gdi_object.h"
#include "base/win/scoped_hdc.h"
......@@ -466,9 +467,13 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup,
DCHECK((start_index - html_start) <= kuint32max);
DCHECK((end_index - html_start) <= kuint32max);
markup->assign(UTF8ToWide(cf_html.data() + html_start));
*fragment_start = static_cast<uint32>(start_index - html_start);
*fragment_end = static_cast<uint32>(end_index - html_start);
std::vector<size_t> offsets;
offsets.push_back(start_index - html_start);
offsets.push_back(end_index - html_start);
markup->assign(UTF8ToUTF16AndAdjustOffsets(cf_html.data() + html_start,
&offsets));
*fragment_start = static_cast<uint32>(offsets[0]);
*fragment_end = static_cast<uint32>(offsets[1]);
}
SkBitmap Clipboard::ReadImage(Buffer buffer) const {
......
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