diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 01:05:27 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 01:05:27 +0000 |
commit | 7be0e1710c92420e5b15b3d0d1850a09848cf217 (patch) | |
tree | 2e78a8d47b62abcf752b502aeefe3ca01cade638 | |
parent | 7912282690d4ec3a0a408af669febb4db0930119 (diff) | |
download | chromium_src-7be0e1710c92420e5b15b3d0d1850a09848cf217.zip chromium_src-7be0e1710c92420e5b15b3d0d1850a09848cf217.tar.gz chromium_src-7be0e1710c92420e5b15b3d0d1850a09848cf217.tar.bz2 |
Retry r16006.
Review URL: http://codereview.chromium.org/113369
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16025 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/string_util.cc | 6 | ||||
-rw-r--r-- | base/string_util.h | 4 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 2 | ||||
-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 |
7 files changed, 40 insertions, 26 deletions
diff --git a/base/string_util.cc b/base/string_util.cc index 2e6f7b3..3a71ba4 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -734,6 +734,12 @@ bool LowerCaseEqualsASCII(const wchar_t* a_begin, return DoLowerCaseEqualsASCII(a_begin, a_end, b); } +bool EqualsASCII(const string16& a, const StringPiece& b) { + if (a.length() != b.length()) + return false; + return std::equal(b.begin(), b.end(), a.begin()); +} + bool StartsWithASCII(const std::string& str, const std::string& search, bool case_sensitive) { diff --git a/base/string_util.h b/base/string_util.h index c32bef3..84cb6e5 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -316,6 +316,10 @@ bool LowerCaseEqualsASCII(const wchar_t* a_begin, const wchar_t* a_end, const char* b); +// Performs a case-sensitive string compare. The behavior is undefined if both +// strings are not ASCII. +bool EqualsASCII(const string16& a, const StringPiece& b); + // Returns true if str starts with search, or false otherwise. bool StartsWithASCII(const std::string& str, const std::string& search, diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 1907c80..210fd7f 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -2434,7 +2434,7 @@ void RenderView::OnInsertText(const string16& text) { return; WebTextInput* text_input = frame->GetTextInput(); if (text_input) - text_input->InsertText(UTF16ToUTF8(text)); + text_input->InsertText(text); } void RenderView::OnSetPageEncoding(const std::wstring& encoding_name) { 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()); } |