| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1525 } | 1525 } |
| 1526 #endif | 1526 #endif |
| 1527 if (replacement_range.IsValid()) { | 1527 if (replacement_range.IsValid()) { |
| 1528 GetWebWidget()->applyReplacementRange( | 1528 GetWebWidget()->applyReplacementRange( |
| 1529 WebRange(replacement_range.start(), replacement_range.length())); | 1529 WebRange(replacement_range.start(), replacement_range.length())); |
| 1530 } | 1530 } |
| 1531 | 1531 |
| 1532 if (!ShouldHandleImeEvent()) | 1532 if (!ShouldHandleImeEvent()) |
| 1533 return; | 1533 return; |
| 1534 ImeEventGuard guard(this); | 1534 ImeEventGuard guard(this); |
| 1535 blink::WebInputMethodController* controller = GetInputMethodController(); | 1535 blink::WebInputMethodController* controller = |
| 1536 GetWebWidget()->getActiveInputMethodController(); |
| 1536 DCHECK(controller); | 1537 DCHECK(controller); |
| 1537 if (!controller || | 1538 if (!controller || |
| 1538 !controller->setComposition( | 1539 !controller->setComposition( |
| 1539 text, WebVector<WebCompositionUnderline>(underlines), selection_start, | 1540 text, WebVector<WebCompositionUnderline>(underlines), selection_start, |
| 1540 selection_end)) { | 1541 selection_end)) { |
| 1541 // If we failed to set the composition text, then we need to let the browser | 1542 // If we failed to set the composition text, then we need to let the browser |
| 1542 // process to cancel the input method's ongoing composition session, to make | 1543 // process to cancel the input method's ongoing composition session, to make |
| 1543 // sure we are in a consistent state. | 1544 // sure we are in a consistent state. |
| 1544 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1545 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1545 } | 1546 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1558 #endif | 1559 #endif |
| 1559 if (replacement_range.IsValid()) { | 1560 if (replacement_range.IsValid()) { |
| 1560 GetWebWidget()->applyReplacementRange( | 1561 GetWebWidget()->applyReplacementRange( |
| 1561 WebRange(replacement_range.start(), replacement_range.length())); | 1562 WebRange(replacement_range.start(), replacement_range.length())); |
| 1562 } | 1563 } |
| 1563 | 1564 |
| 1564 if (!ShouldHandleImeEvent()) | 1565 if (!ShouldHandleImeEvent()) |
| 1565 return; | 1566 return; |
| 1566 ImeEventGuard guard(this); | 1567 ImeEventGuard guard(this); |
| 1567 input_handler_->set_handling_input_event(true); | 1568 input_handler_->set_handling_input_event(true); |
| 1568 if (auto* controller = GetInputMethodController()) | 1569 if (auto* controller = GetWebWidget()->getActiveInputMethodController()) |
| 1569 controller->commitText(text, relative_cursor_pos); | 1570 controller->commitText(text, relative_cursor_pos); |
| 1570 input_handler_->set_handling_input_event(false); | 1571 input_handler_->set_handling_input_event(false); |
| 1571 UpdateCompositionInfo(false /* not an immediate request */); | 1572 UpdateCompositionInfo(false /* not an immediate request */); |
| 1572 } | 1573 } |
| 1573 | 1574 |
| 1574 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { | 1575 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
| 1575 #if BUILDFLAG(ENABLE_PLUGINS) | 1576 #if BUILDFLAG(ENABLE_PLUGINS) |
| 1576 if (focused_pepper_plugin_) { | 1577 if (focused_pepper_plugin_) { |
| 1577 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( | 1578 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( |
| 1578 keep_selection); | 1579 keep_selection); |
| 1579 return; | 1580 return; |
| 1580 } | 1581 } |
| 1581 #endif | 1582 #endif |
| 1582 | 1583 |
| 1583 if (!ShouldHandleImeEvent()) | 1584 if (!ShouldHandleImeEvent()) |
| 1584 return; | 1585 return; |
| 1585 ImeEventGuard guard(this); | 1586 ImeEventGuard guard(this); |
| 1586 input_handler_->set_handling_input_event(true); | 1587 input_handler_->set_handling_input_event(true); |
| 1587 if (auto* controller = GetInputMethodController()) { | 1588 if (auto* controller = GetWebWidget()->getActiveInputMethodController()) { |
| 1588 controller->finishComposingText( | 1589 controller->finishComposingText( |
| 1589 keep_selection ? WebInputMethodController::KeepSelection | 1590 keep_selection ? WebInputMethodController::KeepSelection |
| 1590 : WebInputMethodController::DoNotKeepSelection); | 1591 : WebInputMethodController::DoNotKeepSelection); |
| 1591 } | 1592 } |
| 1592 input_handler_->set_handling_input_event(false); | 1593 input_handler_->set_handling_input_event(false); |
| 1593 UpdateCompositionInfo(false /* not an immediate request */); | 1594 UpdateCompositionInfo(false /* not an immediate request */); |
| 1594 } | 1595 } |
| 1595 | 1596 |
| 1596 void RenderWidget::OnDeviceScaleFactorChanged() { | 1597 void RenderWidget::OnDeviceScaleFactorChanged() { |
| 1597 if (!compositor_) | 1598 if (!compositor_) |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 return web_screen_info; | 2131 return web_screen_info; |
| 2131 } | 2132 } |
| 2132 | 2133 |
| 2133 void RenderWidget::resetInputMethod() { | 2134 void RenderWidget::resetInputMethod() { |
| 2134 ImeEventGuard guard(this); | 2135 ImeEventGuard guard(this); |
| 2135 // If the last text input type is not None, then we should finish any | 2136 // If the last text input type is not None, then we should finish any |
| 2136 // ongoing composition regardless of the new text input type. | 2137 // ongoing composition regardless of the new text input type. |
| 2137 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { | 2138 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
| 2138 // If a composition text exists, then we need to let the browser process | 2139 // If a composition text exists, then we need to let the browser process |
| 2139 // to cancel the input method's ongoing composition session. | 2140 // to cancel the input method's ongoing composition session. |
| 2140 blink::WebInputMethodController* controller = GetInputMethodController(); | 2141 blink::WebInputMethodController* controller = |
| 2142 GetWebWidget()->getActiveInputMethodController(); |
| 2141 if (controller && | 2143 if (controller && |
| 2142 controller->finishComposingText( | 2144 controller->finishComposingText( |
| 2143 WebInputMethodController::DoNotKeepSelection)) | 2145 WebInputMethodController::DoNotKeepSelection)) |
| 2144 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 2146 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 2145 } | 2147 } |
| 2146 | 2148 |
| 2147 UpdateCompositionInfo(false /* not an immediate request */); | 2149 UpdateCompositionInfo(false /* not an immediate request */); |
| 2148 } | 2150 } |
| 2149 | 2151 |
| 2150 #if defined(OS_ANDROID) | 2152 #if defined(OS_ANDROID) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2296 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y); | 2298 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y); |
| 2297 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask, | 2299 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask, |
| 2298 image.getSkBitmap(), imageOffset, | 2300 image.getSkBitmap(), imageOffset, |
| 2299 possible_drag_event_info_)); | 2301 possible_drag_event_info_)); |
| 2300 } | 2302 } |
| 2301 | 2303 |
| 2302 blink::WebWidget* RenderWidget::GetWebWidget() const { | 2304 blink::WebWidget* RenderWidget::GetWebWidget() const { |
| 2303 return webwidget_internal_; | 2305 return webwidget_internal_; |
| 2304 } | 2306 } |
| 2305 | 2307 |
| 2306 blink::WebInputMethodController* RenderWidget::GetInputMethodController() | |
| 2307 const { | |
| 2308 // TODO(ekaramad): Remove this CHECK when GetWebWidget() is | |
| 2309 // always a WebFrameWidget. | |
| 2310 CHECK(GetWebWidget()->isWebFrameWidget()); | |
| 2311 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | |
| 2312 ->getActiveWebInputMethodController(); | |
| 2313 } | |
| 2314 | |
| 2315 } // namespace content | 2308 } // namespace content |
| OLD | NEW |