diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 07:40:53 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 07:40:53 +0000 |
commit | 34f6bc1937fe617875e8f5e95485904569cca582 (patch) | |
tree | 94f201b6bb78ff601a8a97783f4ac0134423af48 /webkit | |
parent | 576d8bff4e6778c6de60b8a7269a78c5e8bf602a (diff) | |
download | chromium_src-34f6bc1937fe617875e8f5e95485904569cca582.zip chromium_src-34f6bc1937fe617875e8f5e95485904569cca582.tar.gz chromium_src-34f6bc1937fe617875e8f5e95485904569cca582.tar.bz2 |
Changes parameters used by IME code to fix several issues caused by Japanese IMEs.
Recent Japanese IMEs (ATOK2008 and MSIME 2007) display a suggestion window (a window which contains suggestions) above a composition string. To fix this issue, we do not only send the lower-left corner of a composition string but also send its upper-left corner and its upper-right corner. So, this change changes IPC parameters used by IME from a tuple of integers to gfx::Rect.
Also, this change fixes cursor positions for Japanese IMEs.
BUG=2770 "IME: Candidate window of Japanese IME follows the end of composition"
BUG=2771 "ATOK 2008 IME pop-ups are displayed below the main Chrome window."
BUG=2775 "IME: Caret is always displayed at the last of IME composition."
Review URL: http://codereview.chromium.org/7385
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webview_impl.cc | 50 | ||||
-rw-r--r-- | webkit/glue/webview_impl.h | 14 | ||||
-rw-r--r-- | webkit/glue/webwidget.h | 7 | ||||
-rw-r--r-- | webkit/glue/webwidget_impl.cc | 15 | ||||
-rw-r--r-- | webkit/glue/webwidget_impl.h | 14 |
5 files changed, 52 insertions, 48 deletions
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index f795b0f..77a099c 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -1013,23 +1013,24 @@ void WebViewImpl::StoreFocusForFrame(WebFrame* frame) { } } -void WebViewImpl::ImeSetComposition(int string_type, int cursor_position, - int target_start, int target_end, - int string_length, - const wchar_t *string_data) { +bool WebViewImpl::ImeSetComposition(int string_type, + int cursor_position, + int target_start, + int target_end, + const std::wstring& ime_string) { Frame* focused = GetFocusedWebCoreFrame(); if (!focused || !ime_accept_events_) { - return; + return false; } Editor* editor = focused->editor(); if (!editor) - return; + return false; if (!editor->canEdit()) { // The input focus has been moved to another WebWidget object. // We should use this |editor| object only to complete the ongoing // composition. if (!editor->hasComposition()) - return; + return false; } if (string_type == 0) { @@ -1053,11 +1054,11 @@ void WebViewImpl::ImeSetComposition(int string_type, int cursor_position, // (I have not been able to find good methods for re-activating it.) // Therefore, I have to prevent from calling Editor::setComposition() // with its first argument an empty string. - if (string_length > 0) { + if (ime_string.length() > 0) { if (target_start < 0) target_start = 0; - if (target_end < 0) target_end = string_length; - std::wstring temp(string_data, string_length); - WebCore::String composition_string(webkit_glue::StdWStringToString(temp)); + if (target_end < 0) target_end = static_cast<int>(ime_string.length()); + WebCore::String composition_string( + webkit_glue::StdWStringToString(ime_string)); // Create custom underlines. // To emphasize the selection, the selected region uses a solid black // for its underline while other regions uses a pale gray for theirs. @@ -1071,7 +1072,7 @@ void WebViewImpl::ImeSetComposition(int string_type, int cursor_position, underlines[1].thick = true; underlines[1].color.setRGB(0x00, 0x00, 0x00); underlines[2].startOffset = target_end; - underlines[2].endOffset = string_length; + underlines[2].endOffset = static_cast<int>(ime_string.length()); underlines[2].thick = true; underlines[2].color.setRGB(0xd3, 0xd3, 0xd3); // When we use custom underlines, WebKit ("InlineTextBox.cpp" Line 282) @@ -1091,24 +1092,20 @@ void WebViewImpl::ImeSetComposition(int string_type, int cursor_position, } #endif } + + return editor->hasComposition(); } -bool WebViewImpl::ImeUpdateStatus(bool* enable_ime, const void **id, - int* x, int* y) { - // Initialize the return values so that we can disable the IME attached - // to a browser process when an error occurs while retrieving information - // of the focused edit control. - *enable_ime = false; - *id = NULL; - *x = -1; - *y = -1; - // Store the position of the bottom-left corner of the caret. +bool WebViewImpl::ImeUpdateStatus(bool* enable_ime, + const void** new_node, + gfx::Rect* caret_rect) { + // Store whether the selected node needs IME and the caret rectangle. // This process consists of the following four steps: // 1. Retrieve the selection controller of the focused frame; // 2. Retrieve the caret rectangle from the controller; // 3. Convert the rectangle, which is relative to the parent view, to the // one relative to the client window, and; - // 4. Store the position of its bottom-left corner. + // 4. Store the converted rectangle. const Frame* focused = GetFocusedWebCoreFrame(); if (!focused) return false; @@ -1121,12 +1118,13 @@ bool WebViewImpl::ImeUpdateStatus(bool* enable_ime, const void **id, const Node* node = controller->start().node(); if (!node) return false; + *enable_ime = node->shouldUseInputMethod() && + !controller->isInPasswordField(); const FrameView* view = node->document()->view(); if (!view) return false; - IntRect rect = view->contentsToWindow(controller->caretRect()); - *x = rect.x(); - *y = rect.bottom(); + const IntRect rect(view->contentsToWindow(controller->caretRect())); + caret_rect->SetRect(rect.x(), rect.y(), rect.width(), rect.height()); return true; } diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 5d66def..83cddebd 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -64,12 +64,14 @@ class WebViewImpl : public WebView, public WebCore::BackForwardListClient { virtual void MouseCaptureLost(); virtual void SetFocus(bool enable); virtual void StoreFocusForFrame(WebFrame* frame); - virtual void ImeSetComposition(int string_type, int cursor_position, - int target_start, int target_end, - int string_length, - const wchar_t *string_data); - virtual bool ImeUpdateStatus(bool* enable_ime, const void** id, - int* x, int* y); + virtual bool ImeSetComposition(int string_type, + int cursor_position, + int target_start, + int target_end, + const std::wstring& ime_string); + virtual bool ImeUpdateStatus(bool* enable_ime, + const void** node, + gfx::Rect* caret_rect); virtual void StopLoading(); virtual void SetBackForwardListSize(int size); virtual void RestoreFocus(); diff --git a/webkit/glue/webwidget.h b/webkit/glue/webwidget.h index 8ee0b47..d3c28f4 100644 --- a/webkit/glue/webwidget.h +++ b/webkit/glue/webwidget.h @@ -59,14 +59,13 @@ class WebWidget : public base::RefCounted<WebWidget> { // Called to inform the webwidget of a composition event from IMM // (Input Method Manager). - virtual void ImeSetComposition(int string_type, int cursor_position, + virtual bool ImeSetComposition(int string_type, int cursor_position, int target_start, int target_end, - int string_length, - const wchar_t *string_data) = 0; + const std::wstring& ime_string) = 0; // Retrieve the status of this widget required by IME APIs. virtual bool ImeUpdateStatus(bool* enable_ime, const void** node, - int* x, int* y) = 0; + gfx::Rect* caret_rect) = 0; private: DISALLOW_EVIL_CONSTRUCTORS(WebWidget); diff --git a/webkit/glue/webwidget_impl.cc b/webkit/glue/webwidget_impl.cc index 1ff4269..7e7a218 100644 --- a/webkit/glue/webwidget_impl.cc +++ b/webkit/glue/webwidget_impl.cc @@ -185,14 +185,17 @@ void WebWidgetImpl::MouseCaptureLost() { void WebWidgetImpl::SetFocus(bool enable) { } -void WebWidgetImpl::ImeSetComposition(int string_type, int cursor_position, - int target_start, int target_end, - int string_length, - const wchar_t *string_data) { +bool WebWidgetImpl::ImeSetComposition(int string_type, + int cursor_position, + int target_start, + int target_end, + const std::wstring& ime_string) { + return false; } -bool WebWidgetImpl::ImeUpdateStatus(bool* enable_ime, const void** id, - int* x, int* y) { +bool WebWidgetImpl::ImeUpdateStatus(bool* enable_ime, + const void** node, + gfx::Rect* caret_rect) { return false; } diff --git a/webkit/glue/webwidget_impl.h b/webkit/glue/webwidget_impl.h index 1c8a9a2..c19e6a2e 100644 --- a/webkit/glue/webwidget_impl.h +++ b/webkit/glue/webwidget_impl.h @@ -41,12 +41,14 @@ class WebWidgetImpl : public WebWidget, virtual bool HandleInputEvent(const WebInputEvent* input_event); virtual void MouseCaptureLost(); virtual void SetFocus(bool enable); - virtual void ImeSetComposition(int string_type, int cursor_position, - int target_start, int target_end, - int string_length, - const wchar_t *string_data); - virtual bool ImeUpdateStatus(bool* enable_ime, const void** id, - int* x, int* y); + virtual bool ImeSetComposition(int string_type, + int cursor_position, + int target_start, + int target_end, + const std::wstring& ime_string); + virtual bool ImeUpdateStatus(bool* enable_ime, + const void** node, + gfx::Rect* caret_rect); // WebWidgetImpl void Init(WebCore::FramelessScrollView* widget, const gfx::Rect& bounds); |