diff options
Diffstat (limited to 'chromium/ui/base/ime/input_method_chromeos.cc')
-rw-r--r-- | chromium/ui/base/ime/input_method_chromeos.cc | 120 |
1 files changed, 55 insertions, 65 deletions
diff --git a/chromium/ui/base/ime/input_method_chromeos.cc b/chromium/ui/base/ime/input_method_chromeos.cc index 1665269b1b9..8062a3c6d8c 100644 --- a/chromium/ui/base/ime/input_method_chromeos.cc +++ b/chromium/ui/base/ime/input_method_chromeos.cc @@ -4,12 +4,13 @@ #include "ui/base/ime/input_method_chromeos.h" +#include <stddef.h> + #include <algorithm> #include <cstring> #include <set> #include <vector> -#include "base/basictypes.h" #include "base/bind.h" #include "base/i18n/char_iterator.h" #include "base/logging.h" @@ -17,16 +18,18 @@ #include "base/strings/utf_string_conversions.h" #include "base/sys_info.h" #include "base/third_party/icu/icu_utf.h" -#include "ui/base/ime/chromeos/composition_text_chromeos.h" #include "ui/base/ime/chromeos/ime_keyboard.h" #include "ui/base/ime/chromeos/input_method_manager.h" +#include "ui/base/ime/composition_text.h" +#include "ui/base/ime/ime_bridge.h" +#include "ui/base/ime/ime_engine_handler_interface.h" #include "ui/base/ime/text_input_client.h" #include "ui/events/event.h" #include "ui/gfx/geometry/rect.h" namespace { -chromeos::IMEEngineHandlerInterface* GetEngine() { - return chromeos::IMEBridge::Get()->GetCurrentEngineHandler(); +ui::IMEEngineHandlerInterface* GetEngine() { + return ui::IMEBridge::Get()->GetCurrentEngineHandler(); } } // namespace @@ -40,7 +43,7 @@ InputMethodChromeOS::InputMethodChromeOS( handling_key_event_(false), weak_ptr_factory_(this) { SetDelegate(delegate); - chromeos::IMEBridge::Get()->SetInputContextHandler(this); + ui::IMEBridge::Get()->SetInputContextHandler(this); UpdateContextFocusState(); } @@ -50,8 +53,8 @@ InputMethodChromeOS::~InputMethodChromeOS() { // We are dead, so we need to ask the client to stop relying on us. OnInputMethodChanged(); - if (chromeos::IMEBridge::Get()) - chromeos::IMEBridge::Get()->SetInputContextHandler(NULL); + if (ui::IMEBridge::Get()) + ui::IMEBridge::Get()->SetInputContextHandler(NULL); } void InputMethodChromeOS::OnFocus() { @@ -106,10 +109,8 @@ void InputMethodChromeOS::DispatchKeyEvent(ui::KeyEvent* event) { if (manager) { chromeos::input_method::ImeKeyboard* keyboard = manager->GetImeKeyboard(); if (keyboard && event->type() == ui::ET_KEY_PRESSED) { - bool caps = (event->key_code() == ui::VKEY_CAPITAL) - ? !keyboard->CapsLockIsEnabled() - : (event->flags() & EF_CAPS_LOCK_DOWN); - keyboard->SetCapsLockEnabled(caps); + keyboard->SetCapsLockEnabled((event->key_code() == ui::VKEY_CAPITAL) ? + !keyboard->CapsLockIsEnabled() : event->IsCapsLockOn()); } } } @@ -136,12 +137,12 @@ void InputMethodChromeOS::DispatchKeyEvent(ui::KeyEvent* event) { handling_key_event_ = true; if (GetEngine()->IsInterestedInKeyEvent()) { - GetEngine()->ProcessKeyEvent( - *event, + ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback = base::Bind(&InputMethodChromeOS::ProcessKeyEventDone, weak_ptr_factory_.GetWeakPtr(), // Pass the ownership of the new copied event. - base::Owned(new ui::KeyEvent(*event)))); + base::Owned(new ui::KeyEvent(*event))); + GetEngine()->ProcessKeyEvent(*event, callback); } else { ProcessKeyEventDone(event, false); } @@ -154,13 +155,13 @@ void InputMethodChromeOS::OnTextInputTypeChanged( UpdateContextFocusState(); - chromeos::IMEEngineHandlerInterface* engine = GetEngine(); + ui::IMEEngineHandlerInterface* engine = GetEngine(); if (engine) { // When focused input client is not changed, a text input type change should // cause blur/focus events to engine. // The focus in to or out from password field should also notify engine. engine->FocusOut(); - chromeos::IMEEngineHandlerInterface::InputContext context( + ui::IMEEngineHandlerInterface::InputContext context( GetTextInputType(), GetTextInputMode(), GetTextInputFlags()); engine->FocusIn(context); } @@ -185,7 +186,7 @@ void InputMethodChromeOS::OnCaretBoundsChanged(const TextInputClient* client) { gfx::Rect composition_head; std::vector<gfx::Rect> rects; if (client->HasCompositionText()) { - uint32 i = 0; + uint32_t i = 0; gfx::Rect rect; while (client->GetCompositionCharacterBounds(i++, &rect)) rects.push_back(rect); @@ -204,7 +205,7 @@ void InputMethodChromeOS::OnCaretBoundsChanged(const TextInputClient* client) { GetEngine()->SetCompositionBounds(rects); chromeos::IMECandidateWindowHandlerInterface* candidate_window = - chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); + ui::IMEBridge::Get()->GetCandidateWindowHandler(); if (!candidate_window) return; candidate_window->SetCursorBounds(caret_rect, composition_head); @@ -282,7 +283,7 @@ void InputMethodChromeOS::OnDidChangeFocusedClient( UpdateContextFocusState(); if (GetEngine()) { - chromeos::IMEEngineHandlerInterface::InputContext context( + ui::IMEEngineHandlerInterface::InputContext context( GetTextInputType(), GetTextInputMode(), GetTextInputFlags()); GetEngine()->FocusIn(context); } @@ -324,13 +325,13 @@ void InputMethodChromeOS::UpdateContextFocusState() { // Propagate the focus event to the candidate window handler which also // manages the input method mode indicator. chromeos::IMECandidateWindowHandlerInterface* candidate_window = - chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); + ui::IMEBridge::Get()->GetCandidateWindowHandler(); if (candidate_window) candidate_window->FocusStateChanged(IsNonPasswordInputFieldFocused()); - chromeos::IMEEngineHandlerInterface::InputContext context( + ui::IMEEngineHandlerInterface::InputContext context( GetTextInputType(), GetTextInputMode(), GetTextInputFlags()); - chromeos::IMEBridge::Get()->SetCurrentInputContext(context); + ui::IMEBridge::Get()->SetCurrentInputContext(context); if (!IsTextInputTypeNone()) OnCaretBoundsChanged(GetTextInputClient()); @@ -412,9 +413,9 @@ void InputMethodChromeOS::ProcessUnfilteredKeyPressEvent( // If a key event was not filtered by |context_| and |character_composer_|, // then it means the key event didn't generate any result text. So we need // to send corresponding character to the focused text input client. - uint16 ch = event->GetCharacter(); + uint16_t ch = event->GetCharacter(); if (ch) - client->InsertChar(ch, event->flags()); + client->InsertChar(*event); } void InputMethodChromeOS::ProcessInputMethodResult(ui::KeyEvent* event, @@ -426,7 +427,9 @@ void InputMethodChromeOS::ProcessInputMethodResult(ui::KeyEvent* event, if (handled && NeedInsertChar()) { for (base::string16::const_iterator i = result_text_.begin(); i != result_text_.end(); ++i) { - client->InsertChar(*i, event->flags()); + ui::KeyEvent ch_event(*event); + ch_event.set_character(*i); + client->InsertChar(ch_event); } } else { client->InsertText(result_text_); @@ -495,18 +498,17 @@ void InputMethodChromeOS::CommitText(const std::string& text) { } } -void InputMethodChromeOS::UpdateCompositionText( - const chromeos::CompositionText& text, - uint32 cursor_pos, - bool visible) { +void InputMethodChromeOS::UpdateCompositionText(const CompositionText& text, + uint32_t cursor_pos, + bool visible) { if (IsTextInputTypeNone()) return; if (!CanComposeInline()) { chromeos::IMECandidateWindowHandlerInterface* candidate_window = - chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); + ui::IMEBridge::Get()->GetCandidateWindowHandler(); if (candidate_window) - candidate_window->UpdatePreeditText(text.text(), cursor_pos, visible); + candidate_window->UpdatePreeditText(text.text, cursor_pos, visible); } // |visible| argument is very confusing. For example, what's the correct @@ -559,12 +561,13 @@ void InputMethodChromeOS::HidePreeditText() { } } -void InputMethodChromeOS::DeleteSurroundingText(int32 offset, uint32 length) { +void InputMethodChromeOS::DeleteSurroundingText(int32_t offset, + uint32_t length) { if (!composition_.text.empty()) return; // do nothing if there is ongoing composition. if (GetTextInputClient()) { - uint32 before = offset >= 0 ? 0U : static_cast<uint32>(-1 * offset); + uint32_t before = offset >= 0 ? 0U : static_cast<uint32_t>(-1 * offset); GetTextInputClient()->ExtendSelectionAndDelete(before, length - before); } } @@ -574,10 +577,9 @@ bool InputMethodChromeOS::ExecuteCharacterComposer(const ui::KeyEvent& event) { return false; // CharacterComposer consumed the key event. Update the composition text. - chromeos::CompositionText preedit; - preedit.set_text(character_composer_.preedit_string()); - UpdateCompositionText(preedit, preedit.text().size(), - !preedit.text().empty()); + CompositionText preedit; + preedit.text = character_composer_.preedit_string(); + UpdateCompositionText(preedit, preedit.text.size(), !preedit.text.empty()); std::string commit_text = base::UTF16ToUTF8(character_composer_.composed_character()); if (!commit_text.empty()) { @@ -587,11 +589,11 @@ bool InputMethodChromeOS::ExecuteCharacterComposer(const ui::KeyEvent& event) { } void InputMethodChromeOS::ExtractCompositionText( - const chromeos::CompositionText& text, - uint32 cursor_position, + const CompositionText& text, + uint32_t cursor_position, CompositionText* out_composition) const { out_composition->Clear(); - out_composition->text = text.text(); + out_composition->text = text.text; if (out_composition->text.empty()) return; @@ -606,7 +608,7 @@ void InputMethodChromeOS::ExtractCompositionText( } while (char_iterator.Advance()); // The text length in Unicode characters. - uint32 char_length = static_cast<uint32>(char16_offsets.size()); + uint32_t char_length = static_cast<uint32_t>(char16_offsets.size()); // Make sure we can convert the value of |char_length| as well. char16_offsets.push_back(length); @@ -615,36 +617,24 @@ void InputMethodChromeOS::ExtractCompositionText( out_composition->selection = gfx::Range(cursor_offset); - const std::vector<chromeos::CompositionText::UnderlineAttribute>& - underline_attributes = text.underline_attributes(); - if (!underline_attributes.empty()) { - for (size_t i = 0; i < underline_attributes.size(); ++i) { - const uint32 start = underline_attributes[i].start_index; - const uint32 end = underline_attributes[i].end_index; + const CompositionUnderlines text_underlines = text.underlines; + if (!text_underlines.empty()) { + for (size_t i = 0; i < text_underlines.size(); ++i) { + const uint32_t start = text_underlines[i].start_offset; + const uint32_t end = text_underlines[i].end_offset; if (start >= end) continue; - CompositionUnderline underline(char16_offsets[start], - char16_offsets[end], - SK_ColorBLACK, - false /* thick */, - SK_ColorTRANSPARENT); - if (underline_attributes[i].type == - chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_DOUBLE) - underline.thick = true; - else if (underline_attributes[i].type == - chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_ERROR) - underline.color = SK_ColorRED; - else if (underline_attributes[i].type == - chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_NONE) - underline.color = SK_ColorTRANSPARENT; + CompositionUnderline underline( + char16_offsets[start], char16_offsets[end], text_underlines[i].color, + text_underlines[i].thick, text_underlines[i].background_color); out_composition->underlines.push_back(underline); } } - DCHECK(text.selection_start() <= text.selection_end()); - if (text.selection_start() < text.selection_end()) { - const uint32 start = text.selection_start(); - const uint32 end = text.selection_end(); + DCHECK(text.selection.start() <= text.selection.end()); + if (text.selection.start() < text.selection.end()) { + const uint32_t start = text.selection.start(); + const uint32_t end = text.selection.end(); CompositionUnderline underline(char16_offsets[start], char16_offsets[end], SK_ColorBLACK, |