diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 21:50:53 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 21:50:53 +0000 |
commit | a8f914871101974a4856248630c08454b7a7d294 (patch) | |
tree | 322d2cf9c312b7ad60103c59bad660fab187e204 /webkit | |
parent | b38f85b26762e22775e63618f005d6c55a29ef43 (diff) | |
download | chromium_src-a8f914871101974a4856248630c08454b7a7d294.zip chromium_src-a8f914871101974a4856248630c08454b7a7d294.tar.gz chromium_src-a8f914871101974a4856248630c08454b7a7d294.tar.bz2 |
Properly convert from UTF8 to UTF16 in WebTextInputImpl.
String util changes by darin@chromium.org.
BUG=11699
Review URL: http://codereview.chromium.org/115215
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webtextinput.h | 7 | ||||
-rw-r--r-- | webkit/glue/webtextinput_impl.cc | 24 | ||||
-rw-r--r-- | webkit/glue/webtextinput_impl.h | 16 | ||||
-rw-r--r-- | webkit/tools/test_shell/text_input_controller.cc | 7 |
4 files changed, 29 insertions, 25 deletions
diff --git a/webkit/glue/webtextinput.h b/webkit/glue/webtextinput.h index 60dfa7a..2e69874 100644 --- a/webkit/glue/webtextinput.h +++ b/webkit/glue/webtextinput.h @@ -7,6 +7,7 @@ #include <string> #include "base/basictypes.h" +#include "base/string16.h" class WebTextInput { public: @@ -14,13 +15,13 @@ class WebTextInput { virtual ~WebTextInput() {} // Inserts text to the associated frame. - virtual void InsertText(const std::string& text) = 0; + virtual void InsertText(const string16& text) = 0; // Executes the given editing command on the frame. - virtual void DoCommand(const std::string& command) = 0; + virtual void DoCommand(const string16& command) = 0; // Sets marked text region on the frame. - virtual void SetMarkedText(const std::string& text, + virtual void SetMarkedText(const string16& text, int32_t location, int32_t length) = 0; // Clears the marked text region on the frame. diff --git a/webkit/glue/webtextinput_impl.cc b/webkit/glue/webtextinput_impl.cc index 964a01e..84dcb9b 100644 --- a/webkit/glue/webtextinput_impl.cc +++ b/webkit/glue/webtextinput_impl.cc @@ -14,7 +14,9 @@ MSVC_POP_WARNING(); #undef LOG +#include "base/string16.h" #include "base/string_util.h" +#include "webkit/glue/glue_util.h" #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webtextinput_impl.h" @@ -34,18 +36,18 @@ WebCore::Editor* WebTextInputImpl::GetEditor() { return web_frame_impl_->frame()->editor(); } -void WebTextInputImpl::InsertText(const std::string& text) { - WebCore::String str(text.c_str()); +void WebTextInputImpl::InsertText(const string16& text) { + WebCore::String str = webkit_glue::String16ToString(text); GetEditor()->insertText(str, NULL); } -void WebTextInputImpl::DoCommand(const std::string& com) { +void WebTextInputImpl::DoCommand(const string16& com) { if (com.length() <= 2) return; // Since we don't have NSControl, we will convert the format of command // string and call the function on Editor directly. - std::string command = com; + string16 command = com; // Make sure the first letter is upper case. command.replace(0, 1, 1, toupper(command.at(0))); @@ -56,16 +58,16 @@ void WebTextInputImpl::DoCommand(const std::string& com) { // Specially handling commands that Editor::execCommand does not directly // support. - if (!command.compare("DeleteToEndOfParagraph")) { + if (EqualsASCII(command, "DeleteToEndOfParagraph")) { DeleteToEndOfParagraph(); - } else if(!command.compare("Indent")) { + } else if(EqualsASCII(command, "Indent")) { GetEditor()->indent(); - } else if(!command.compare("Outdent")) { + } else if(EqualsASCII(command, "Outdent")) { GetEditor()->outdent(); - } else if(!command.compare("DeleteBackward")) { + } else if(EqualsASCII(command, "DeleteBackward")) { WebCore::AtomicString editor_command("BackwardDelete"); GetEditor()->command(editor_command).execute(); - } else if(!command.compare("DeleteForward")) { + } else if(EqualsASCII(command, "DeleteForward")) { WebCore::AtomicString editor_command("ForwardDelete"); GetEditor()->command(editor_command).execute(); } else { @@ -76,11 +78,11 @@ void WebTextInputImpl::DoCommand(const std::string& com) { return; } -void WebTextInputImpl::SetMarkedText(const std::string& text, +void WebTextInputImpl::SetMarkedText(const string16& text, int32_t location, int32_t length) { WebCore::Editor* editor = GetEditor(); - WebCore::String str(text.c_str()); + WebCore::String str = webkit_glue::String16ToString(text); editor->confirmComposition(str); diff --git a/webkit/glue/webtextinput_impl.h b/webkit/glue/webtextinput_impl.h index c7a162b..8344f7e 100644 --- a/webkit/glue/webtextinput_impl.h +++ b/webkit/glue/webtextinput_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -6,8 +6,8 @@ // used by TextInputController in test_shell. It only facilitates layout tests // and should not be used by renderers. -#ifndef WEBKIT_GLUE_WEBTEXTINPUT_IMPL_H__ -#define WEBKIT_GLUE_WEBTEXTINPUT_IMPL_H__ +#ifndef WEBKIT_GLUE_WEBTEXTINPUT_IMPL_H_ +#define WEBKIT_GLUE_WEBTEXTINPUT_IMPL_H_ #include "webkit/glue/webtextinput.h" @@ -19,9 +19,9 @@ class WebTextInputImpl : public WebTextInput { virtual ~WebTextInputImpl(); // WebTextInput methods - virtual void InsertText(const std::string& text); - virtual void DoCommand(const std::string& command); - virtual void SetMarkedText(const std::string& text, + virtual void InsertText(const string16& text); + virtual void DoCommand(const string16& command); + virtual void SetMarkedText(const string16& text, int32_t location, int32_t length); virtual void UnMarkText(); virtual bool HasMarkedText(); @@ -49,7 +49,7 @@ class WebTextInputImpl : public WebTextInput { // Holding a non-owning pointer to the web frame we are associated with. WebFrameImpl* web_frame_impl_; - DISALLOW_EVIL_CONSTRUCTORS(WebTextInputImpl); + DISALLOW_COPY_AND_ASSIGN(WebTextInputImpl); }; -#endif // #ifndef WEBKIT_GLUE_WEBTEXTINPUT_IMPL_H__ +#endif // #ifndef WEBKIT_GLUE_WEBTEXTINPUT_IMPL_H_ diff --git a/webkit/tools/test_shell/text_input_controller.cc b/webkit/tools/test_shell/text_input_controller.cc index 121d9a9..a371881 100644 --- a/webkit/tools/test_shell/text_input_controller.cc +++ b/webkit/tools/test_shell/text_input_controller.cc @@ -4,6 +4,7 @@ #include "webkit/tools/test_shell/text_input_controller.h" +#include "base/string_util.h" #include "webkit/glue/webview.h" #include "webkit/glue/webframe.h" #include "webkit/glue/webtextinput.h" @@ -50,7 +51,7 @@ void TextInputController::insertText( return; if (args.size() >= 1 && args[0].isString()) { - text_input->InsertText(args[0].ToString()); + text_input->InsertText(UTF8ToUTF16(args[0].ToString())); } } @@ -63,7 +64,7 @@ void TextInputController::doCommand( return; if (args.size() >= 1 && args[0].isString()) { - text_input->DoCommand(args[0].ToString()); + text_input->DoCommand(UTF8ToUTF16(args[0].ToString())); } } @@ -77,7 +78,7 @@ void TextInputController::setMarkedText( if (args.size() >= 3 && args[0].isString() && args[1].isNumber() && args[2].isNumber()) { - text_input->SetMarkedText(args[0].ToString(), + text_input->SetMarkedText(UTF8ToUTF16(args[0].ToString()), args[1].ToInt32(), args[2].ToInt32()); } |