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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 message->set_routing_id(routing_id_); | 654 message->set_routing_id(routing_id_); |
655 | 655 |
656 return RenderThread::Get()->Send(message); | 656 return RenderThread::Get()->Send(message); |
657 } | 657 } |
658 | 658 |
659 void RenderWidget::SendOrCrash(IPC::Message* message) { | 659 void RenderWidget::SendOrCrash(IPC::Message* message) { |
660 bool result = Send(message); | 660 bool result = Send(message); |
661 CHECK(closing_ || result) << "Failed to send message"; | 661 CHECK(closing_ || result) << "Failed to send message"; |
662 } | 662 } |
663 | 663 |
664 bool RenderWidget::ShouldHandleImeEvents() const { | |
665 return GetWebWidget()->isWebFrameWidget() && has_focus_; | |
666 } | |
667 | |
664 void RenderWidget::SetWindowRectSynchronously( | 668 void RenderWidget::SetWindowRectSynchronously( |
665 const gfx::Rect& new_window_rect) { | 669 const gfx::Rect& new_window_rect) { |
666 ResizeParams params; | 670 ResizeParams params; |
667 params.screen_info = screen_info_; | 671 params.screen_info = screen_info_; |
668 params.new_size = new_window_rect.size(); | 672 params.new_size = new_window_rect.size(); |
669 params.physical_backing_size = | 673 params.physical_backing_size = |
670 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_); | 674 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_); |
671 params.visible_viewport_size = new_window_rect.size(); | 675 params.visible_viewport_size = new_window_rect.size(); |
672 params.is_fullscreen_granted = is_fullscreen_granted_; | 676 params.is_fullscreen_granted = is_fullscreen_granted_; |
673 params.display_mode = display_mode_; | 677 params.display_mode = display_mode_; |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1027 ime_event_guard_->set_show_ime(true); | 1031 ime_event_guard_->set_show_ime(true); |
1028 } | 1032 } |
1029 return; | 1033 return; |
1030 } | 1034 } |
1031 | 1035 |
1032 ui::TextInputType new_type = GetTextInputType(); | 1036 ui::TextInputType new_type = GetTextInputType(); |
1033 if (IsDateTimeInput(new_type)) | 1037 if (IsDateTimeInput(new_type)) |
1034 return; // Not considered as a text input field in WebKit/Chromium. | 1038 return; // Not considered as a text input field in WebKit/Chromium. |
1035 | 1039 |
1036 blink::WebTextInputInfo new_info; | 1040 blink::WebTextInputInfo new_info; |
1037 if (GetWebWidget()) | 1041 if (auto* controller = GetInputMethodController()) |
1038 new_info = GetWebWidget()->textInputInfo(); | 1042 new_info = controller->textInputInfo(); |
1039 const ui::TextInputMode new_mode = | 1043 const ui::TextInputMode new_mode = |
1040 ConvertWebTextInputMode(new_info.inputMode); | 1044 ConvertWebTextInputMode(new_info.inputMode); |
1041 | 1045 |
1042 bool new_can_compose_inline = CanComposeInline(); | 1046 bool new_can_compose_inline = CanComposeInline(); |
1043 | 1047 |
1044 // Only sends text input params if they are changed or if the ime should be | 1048 // Only sends text input params if they are changed or if the ime should be |
1045 // shown. | 1049 // shown. |
1046 if (show_ime == ShowIme::IF_NEEDED || | 1050 if (show_ime == ShowIme::IF_NEEDED || |
1047 change_source == ChangeSource::FROM_IME || | 1051 change_source == ChangeSource::FROM_IME || |
1048 text_input_type_ != new_type || text_input_mode_ != new_mode || | 1052 text_input_type_ != new_type || text_input_mode_ != new_mode || |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1497 window_screen_rect_ = rect; | 1501 window_screen_rect_ = rect; |
1498 view_screen_rect_ = rect; | 1502 view_screen_rect_ = rect; |
1499 } | 1503 } |
1500 } | 1504 } |
1501 | 1505 |
1502 void RenderWidget::OnImeSetComposition( | 1506 void RenderWidget::OnImeSetComposition( |
1503 const base::string16& text, | 1507 const base::string16& text, |
1504 const std::vector<WebCompositionUnderline>& underlines, | 1508 const std::vector<WebCompositionUnderline>& underlines, |
1505 const gfx::Range& replacement_range, | 1509 const gfx::Range& replacement_range, |
1506 int selection_start, int selection_end) { | 1510 int selection_start, int selection_end) { |
1511 if (!ShouldHandleImeEvents()) | |
1512 return; | |
1513 | |
1507 #if BUILDFLAG(ENABLE_PLUGINS) | 1514 #if BUILDFLAG(ENABLE_PLUGINS) |
1508 if (focused_pepper_plugin_) { | 1515 if (focused_pepper_plugin_) { |
1509 focused_pepper_plugin_->render_frame()->OnImeSetComposition( | 1516 focused_pepper_plugin_->render_frame()->OnImeSetComposition( |
1510 text, underlines, selection_start, selection_end); | 1517 text, underlines, selection_start, selection_end); |
1511 return; | 1518 return; |
1512 } | 1519 } |
1513 #endif | 1520 #endif |
1514 if (replacement_range.IsValid()) { | 1521 if (replacement_range.IsValid()) { |
1515 GetWebWidget()->applyReplacementRange( | 1522 GetWebWidget()->applyReplacementRange( |
1516 WebRange(replacement_range.start(), replacement_range.length())); | 1523 WebRange(replacement_range.start(), replacement_range.length())); |
(...skipping 11 matching lines...) Expand all Loading... | |
1528 // process to cancel the input method's ongoing composition session, to make | 1535 // process to cancel the input method's ongoing composition session, to make |
1529 // sure we are in a consistent state. | 1536 // sure we are in a consistent state. |
1530 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1537 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1531 } | 1538 } |
1532 UpdateCompositionInfo(false /* not an immediate request */); | 1539 UpdateCompositionInfo(false /* not an immediate request */); |
1533 } | 1540 } |
1534 | 1541 |
1535 void RenderWidget::OnImeCommitText(const base::string16& text, | 1542 void RenderWidget::OnImeCommitText(const base::string16& text, |
1536 const gfx::Range& replacement_range, | 1543 const gfx::Range& replacement_range, |
1537 int relative_cursor_pos) { | 1544 int relative_cursor_pos) { |
1545 if (!ShouldHandleImeEvents()) | |
1546 return; | |
1547 | |
1538 #if BUILDFLAG(ENABLE_PLUGINS) | 1548 #if BUILDFLAG(ENABLE_PLUGINS) |
1539 if (focused_pepper_plugin_) { | 1549 if (focused_pepper_plugin_) { |
1540 focused_pepper_plugin_->render_frame()->OnImeCommitText( | 1550 focused_pepper_plugin_->render_frame()->OnImeCommitText( |
1541 text, replacement_range, relative_cursor_pos); | 1551 text, replacement_range, relative_cursor_pos); |
1542 return; | 1552 return; |
1543 } | 1553 } |
1544 #endif | 1554 #endif |
1545 if (replacement_range.IsValid()) { | 1555 if (replacement_range.IsValid()) { |
1546 GetWebWidget()->applyReplacementRange( | 1556 GetWebWidget()->applyReplacementRange( |
1547 WebRange(replacement_range.start(), replacement_range.length())); | 1557 WebRange(replacement_range.start(), replacement_range.length())); |
1548 } | 1558 } |
1549 | 1559 |
1550 if (!GetWebWidget()) | 1560 if (!GetWebWidget()) |
1551 return; | 1561 return; |
1552 ImeEventGuard guard(this); | 1562 ImeEventGuard guard(this); |
1553 input_handler_->set_handling_input_event(true); | 1563 input_handler_->set_handling_input_event(true); |
1554 if (auto* controller = GetInputMethodController()) | 1564 if (auto* controller = GetInputMethodController()) |
1555 controller->commitText(text, relative_cursor_pos); | 1565 controller->commitText(text, relative_cursor_pos); |
1556 input_handler_->set_handling_input_event(false); | 1566 input_handler_->set_handling_input_event(false); |
1557 UpdateCompositionInfo(false /* not an immediate request */); | 1567 UpdateCompositionInfo(false /* not an immediate request */); |
1558 } | 1568 } |
1559 | 1569 |
1560 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { | 1570 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
1571 if (!ShouldHandleImeEvents()) | |
1572 return; | |
1573 | |
1561 #if BUILDFLAG(ENABLE_PLUGINS) | 1574 #if BUILDFLAG(ENABLE_PLUGINS) |
1562 if (focused_pepper_plugin_) { | 1575 if (focused_pepper_plugin_) { |
1563 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( | 1576 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( |
1564 keep_selection); | 1577 keep_selection); |
1565 return; | 1578 return; |
1566 } | 1579 } |
1567 #endif | 1580 #endif |
1568 | 1581 |
1569 if (!GetWebWidget()) | 1582 if (!GetWebWidget()) |
1570 return; | 1583 return; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1722 #if !defined(OS_ANDROID) | 1735 #if !defined(OS_ANDROID) |
1723 FocusChangeComplete(); | 1736 FocusChangeComplete(); |
1724 #endif | 1737 #endif |
1725 } | 1738 } |
1726 | 1739 |
1727 ui::TextInputType RenderWidget::GetTextInputType() { | 1740 ui::TextInputType RenderWidget::GetTextInputType() { |
1728 #if BUILDFLAG(ENABLE_PLUGINS) | 1741 #if BUILDFLAG(ENABLE_PLUGINS) |
1729 if (focused_pepper_plugin_) | 1742 if (focused_pepper_plugin_) |
1730 return focused_pepper_plugin_->text_input_type(); | 1743 return focused_pepper_plugin_->text_input_type(); |
1731 #endif | 1744 #endif |
1732 if (GetWebWidget()) | 1745 if (auto* controller = GetInputMethodController()) |
1733 return ConvertWebTextInputType(GetWebWidget()->textInputType()); | 1746 return ConvertWebTextInputType(controller->textInputType()); |
1734 return ui::TEXT_INPUT_TYPE_NONE; | 1747 return ui::TEXT_INPUT_TYPE_NONE; |
1735 } | 1748 } |
1736 | 1749 |
1737 void RenderWidget::UpdateCompositionInfo(bool immediate_request) { | 1750 void RenderWidget::UpdateCompositionInfo(bool immediate_request) { |
1738 if (!monitor_composition_info_ && !immediate_request) | 1751 if (!monitor_composition_info_ && !immediate_request) |
1739 return; // Do not calculate composition info if not requested. | 1752 return; // Do not calculate composition info if not requested. |
1740 | 1753 |
1741 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); | 1754 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
1742 gfx::Range range; | 1755 gfx::Range range; |
1743 std::vector<gfx::Rect> character_bounds; | 1756 std::vector<gfx::Rect> character_bounds; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2104 void RenderWidget::didHandleGestureEvent( | 2117 void RenderWidget::didHandleGestureEvent( |
2105 const WebGestureEvent& event, | 2118 const WebGestureEvent& event, |
2106 bool event_cancelled) { | 2119 bool event_cancelled) { |
2107 #if defined(OS_ANDROID) || defined(USE_AURA) | 2120 #if defined(OS_ANDROID) || defined(USE_AURA) |
2108 if (event_cancelled) | 2121 if (event_cancelled) |
2109 return; | 2122 return; |
2110 if (event.type == WebInputEvent::GestureTap) { | 2123 if (event.type == WebInputEvent::GestureTap) { |
2111 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); | 2124 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); |
2112 } else if (event.type == WebInputEvent::GestureLongPress) { | 2125 } else if (event.type == WebInputEvent::GestureLongPress) { |
2113 DCHECK(GetWebWidget()); | 2126 DCHECK(GetWebWidget()); |
2114 if (GetWebWidget()->textInputInfo().value.isEmpty()) | 2127 blink::WebInputMethodController* controller = GetInputMethodController(); |
wjmaclean
2017/01/05 21:24:57
Why do you explicitly declare the type here, but u
EhsanK
2017/01/05 21:46:43
This format goes back to this CL:
https://coderevi
Charlie Reis
2017/01/05 22:25:03
Yeah, auto wasn't buying much here in terms of spa
| |
2128 if (!controller || controller->textInputInfo().value.isEmpty()) | |
2115 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); | 2129 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); |
2116 else | 2130 else |
2117 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); | 2131 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); |
2118 } | 2132 } |
2119 // TODO(ananta): Piggyback off existing IPCs to communicate this information, | 2133 // TODO(ananta): Piggyback off existing IPCs to communicate this information, |
2120 // crbug/420130. | 2134 // crbug/420130. |
2121 #if defined(OS_WIN) | 2135 #if defined(OS_WIN) |
2122 if (event.type != blink::WebGestureEvent::GestureTap) | 2136 if (event.type != blink::WebGestureEvent::GestureTap) |
2123 return; | 2137 return; |
2124 | 2138 |
2125 // TODO(estade): hit test the event against focused node to make sure | 2139 // TODO(estade): hit test the event against focused node to make sure |
2126 // the tap actually hit the focused node. | 2140 // the tap actually hit the focused node. |
2127 blink::WebTextInputType text_input_type = GetWebWidget()->textInputType(); | 2141 blink::WebInputMethodController* controller = GetInputMethodController(); |
2142 blink::WebTextInputType text_input_type = | |
2143 controller ? controller->textInputType() : blink::WebTextInputTypeNone; | |
2128 | 2144 |
2129 Send(new ViewHostMsg_FocusedNodeTouched( | 2145 Send(new ViewHostMsg_FocusedNodeTouched( |
2130 routing_id_, text_input_type != blink::WebTextInputTypeNone)); | 2146 routing_id_, text_input_type != blink::WebTextInputTypeNone)); |
2131 #endif | 2147 #endif |
2132 #endif | 2148 #endif |
2133 } | 2149 } |
2134 | 2150 |
2135 void RenderWidget::didOverscroll( | 2151 void RenderWidget::didOverscroll( |
2136 const blink::WebFloatSize& overscrollDelta, | 2152 const blink::WebFloatSize& overscrollDelta, |
2137 const blink::WebFloatSize& accumulatedOverscroll, | 2153 const blink::WebFloatSize& accumulatedOverscroll, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2255 // browser side (https://crbug.com/669219). | 2271 // browser side (https://crbug.com/669219). |
2256 // If there is no WebFrameWidget, then there will be no | 2272 // If there is no WebFrameWidget, then there will be no |
2257 // InputMethodControllers for a WebLocalFrame. | 2273 // InputMethodControllers for a WebLocalFrame. |
2258 return nullptr; | 2274 return nullptr; |
2259 } | 2275 } |
2260 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | 2276 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
2261 ->getActiveWebInputMethodController(); | 2277 ->getActiveWebInputMethodController(); |
2262 } | 2278 } |
2263 | 2279 |
2264 } // namespace content | 2280 } // namespace content |
OLD | NEW |