diff options
author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-02-01 20:50:41 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-02-01 20:58:12 +0100 |
commit | b5d7ec9226eee41d9c3516bf51dc48c283e8b13e (patch) | |
tree | 994d2f09fd2106efed07e007becffed6e56a584c /src/core/render_widget_host_view_qt.cpp | |
parent | 3c4c080e46a8fa229d7e1fdaee82f750b3558aa0 (diff) | |
parent | 2313a580c0e3f0636a12697ba4b872bfdccbcf7f (diff) |
Merge dev into 5.9
Change-Id: Id919bfd67d9d435fd5a05a892151a12ae5bcd3c0
Diffstat (limited to 'src/core/render_widget_host_view_qt.cpp')
-rw-r--r-- | src/core/render_widget_host_view_qt.cpp | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index fef3831e3..280a0475d 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -116,7 +116,7 @@ static inline Qt::InputMethodHints toQtInputMethodHints(ui::TextInputType inputT case ui::TEXT_INPUT_TYPE_SEARCH: return Qt::ImhPreferLowercase | Qt::ImhNoAutoUppercase; case ui::TEXT_INPUT_TYPE_PASSWORD: - return Qt::ImhSensitiveData | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase; + return Qt::ImhSensitiveData | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase | Qt::ImhHiddenText; case ui::TEXT_INPUT_TYPE_EMAIL: return Qt::ImhEmailCharactersOnly; case ui::TEXT_INPUT_TYPE_NUMBER: @@ -575,6 +575,9 @@ void RenderWidgetHostViewQt::TextInputStateChanged(const content::TextInputState { m_currentInputType = params.type; m_delegate->inputMethodStateChanged(params.type != ui::TEXT_INPUT_TYPE_NONE); + m_delegate->setInputMethodHints(toQtInputMethodHints(params.type)); + + m_surroundingText = QString::fromStdString(params.value); } void RenderWidgetHostViewQt::ImeCancelComposition() @@ -838,7 +841,7 @@ QVariant RenderWidgetHostViewQt::inputMethodQuery(Qt::InputMethodQuery query) co case Qt::ImAnchorPosition: return static_cast<uint>(m_anchorPositionWithinSelection); case Qt::ImSurroundingText: - return toQt(selection_text_); + return m_surroundingText; case Qt::ImCurrentSelection: return toQt(GetSelectedText()); case Qt::ImMaximumTextLength: @@ -971,7 +974,13 @@ void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev) } else { if (ev->type() == QEvent::KeyRelease) { m_receivedEmptyImeText = false; - m_host->ImeConfirmComposition(toString16(ev->text()), gfx::Range::InvalidRange(), + m_host->ImeSetComposition(toString16(ev->text()), + std::vector<blink::WebCompositionUnderline>(), + gfx::Range::InvalidRange(), + gfx::Range::InvalidRange().start(), + gfx::Range::InvalidRange().end()); + m_host->ImeConfirmComposition(base::string16(), + gfx::Range::InvalidRange(), false); m_imeInProgress = false; } @@ -980,17 +989,16 @@ void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev) } content::NativeWebKeyboardEvent webEvent = WebEventFactory::toWebKeyboardEvent(ev); - if (webEvent.type == blink::WebInputEvent::RawKeyDown && !ev->text().isEmpty()) { + bool keyDownTextInsertion = webEvent.type == blink::WebInputEvent::RawKeyDown && webEvent.text[0]; + webEvent.skip_in_browser = keyDownTextInsertion; + m_host->ForwardKeyboardEvent(webEvent); + + if (keyDownTextInsertion) { // Blink won't consume the RawKeyDown, but rather the Char event in this case. // Make sure to skip the former on the way back. The same os_event will be set on both of them. webEvent.skip_in_browser = true; - m_host->ForwardKeyboardEvent(webEvent); - - webEvent.skip_in_browser = false; webEvent.type = blink::WebInputEvent::Char; m_host->ForwardKeyboardEvent(webEvent); - } else { - m_host->ForwardKeyboardEvent(webEvent); } } @@ -1002,9 +1010,6 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev) QString commitString = ev->commitString(); QString preeditString = ev->preeditString(); - int replacementStart = ev->replacementStart(); - int replacementLength = ev->replacementLength(); - int cursorPositionInPreeditString = -1; gfx::Range selectionRange = gfx::Range::InvalidRange(); @@ -1067,33 +1072,45 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev) } } - gfx::Range replacementRange = (replacementLength > 0) ? gfx::Range(replacementStart, replacementStart + replacementLength) - : gfx::Range::InvalidRange(); + int replacementLength = ev->replacementLength(); + gfx::Range replacementRange = gfx::Range::InvalidRange(); - auto setCompositionForPreEditString = [&](){ + if (replacementLength > 0) + { + int start = ev->replacementStart(); + + if (start >= 0) + replacementRange = gfx::Range(start, start + replacementLength); + else if (m_surroundingText.length() + start >= 0) { + start = m_surroundingText.length() + start; + replacementRange = gfx::Range(start, start + replacementLength); + } + } + + auto setCompositionString = [&](const QString &compositionString){ ensureValidSelectionRange(); - m_host->ImeSetComposition(toString16(preeditString), + m_host->ImeSetComposition(toString16(compositionString), underlines, replacementRange, selectionRange.start(), selectionRange.end()); }; - if (!commitString.isEmpty()) { - m_host->ImeConfirmComposition(toString16(commitString), replacementRange, false); + if (!commitString.isEmpty() || replacementLength > 0) { + setCompositionString(commitString); + m_host->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(), false); // We might get a commit string and a pre-edit string in a single event, which means // we need to confirm thećlast composition, and start a new composition. if (!preeditString.isEmpty()) { - setCompositionForPreEditString(); + setCompositionString(preeditString); m_imeInProgress = true; } else { m_imeInProgress = false; } - m_receivedEmptyImeText = false; - + m_receivedEmptyImeText = commitString.isEmpty(); } else if (!preeditString.isEmpty()) { - setCompositionForPreEditString(); + setCompositionString(preeditString); m_imeInProgress = true; m_receivedEmptyImeText = false; } else { @@ -1115,7 +1132,10 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev) QGuiApplication::postEvent(qApp->focusObject(), eventCopy); } else { m_receivedEmptyImeText = false; - m_host->ImeCancelComposition(); + if (m_imeInProgress) { + m_imeInProgress = false; + m_host->ImeCancelComposition(); + } } } } |