OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 void RenderFrameImpl::SimulateImeSetComposition( | 1313 void RenderFrameImpl::SimulateImeSetComposition( |
1314 const base::string16& text, | 1314 const base::string16& text, |
1315 const std::vector<blink::WebCompositionUnderline>& underlines, | 1315 const std::vector<blink::WebCompositionUnderline>& underlines, |
1316 int selection_start, | 1316 int selection_start, |
1317 int selection_end) { | 1317 int selection_end) { |
1318 render_view_->OnImeSetComposition( | 1318 render_view_->OnImeSetComposition( |
1319 text, underlines, gfx::Range::InvalidRange(), | 1319 text, underlines, gfx::Range::InvalidRange(), |
1320 selection_start, selection_end); | 1320 selection_start, selection_end); |
1321 } | 1321 } |
1322 | 1322 |
1323 void RenderFrameImpl::SimulateImeConfirmComposition( | 1323 void RenderFrameImpl::SimulateImeCommitText( |
1324 const base::string16& text, | 1324 const base::string16& text, |
1325 const gfx::Range& replacement_range) { | 1325 const gfx::Range& replacement_range) { |
1326 render_view_->OnImeConfirmComposition(text, replacement_range, false); | 1326 render_view_->OnImeCommitText(text, replacement_range, 0); |
| 1327 } |
| 1328 |
| 1329 void RenderFrameImpl::SimulateImeFinishComposingText(bool keep_selection) { |
| 1330 render_view_->OnImeFinishComposingText(keep_selection); |
1327 } | 1331 } |
1328 | 1332 |
1329 void RenderFrameImpl::OnImeSetComposition( | 1333 void RenderFrameImpl::OnImeSetComposition( |
1330 const base::string16& text, | 1334 const base::string16& text, |
1331 const std::vector<blink::WebCompositionUnderline>& underlines, | 1335 const std::vector<blink::WebCompositionUnderline>& underlines, |
1332 int selection_start, | 1336 int selection_start, |
1333 int selection_end) { | 1337 int selection_end) { |
1334 // When a PPAPI plugin has focus, we bypass WebKit. | 1338 // When a PPAPI plugin has focus, we bypass WebKit. |
1335 if (!IsPepperAcceptingCompositionEvents()) { | 1339 if (!IsPepperAcceptingCompositionEvents()) { |
1336 pepper_composition_text_ = text; | 1340 pepper_composition_text_ = text; |
(...skipping 13 matching lines...) Expand all Loading... |
1350 } | 1354 } |
1351 pepper_composition_text_ = text; | 1355 pepper_composition_text_ = text; |
1352 // Nonempty: composition is ongoing. | 1356 // Nonempty: composition is ongoing. |
1353 if (!pepper_composition_text_.empty()) { | 1357 if (!pepper_composition_text_.empty()) { |
1354 focused_pepper_plugin_->HandleCompositionUpdate( | 1358 focused_pepper_plugin_->HandleCompositionUpdate( |
1355 pepper_composition_text_, underlines, selection_start, selection_end); | 1359 pepper_composition_text_, underlines, selection_start, selection_end); |
1356 } | 1360 } |
1357 } | 1361 } |
1358 } | 1362 } |
1359 | 1363 |
1360 void RenderFrameImpl::OnImeConfirmComposition( | 1364 void RenderFrameImpl::OnImeCommitText(const base::string16& text, |
1361 const base::string16& text, | 1365 const gfx::Range& replacement_range, |
1362 const gfx::Range& replacement_range, | 1366 int relative_cursor_pos) { |
1363 bool keep_selection) { | 1367 if (text.empty()) |
1364 // When a PPAPI plugin has focus, we bypass WebKit. | |
1365 // Here, text.empty() has a special meaning. It means to commit the last | |
1366 // update of composition text (see | |
1367 // RenderWidgetHost::ImeConfirmComposition()). | |
1368 const base::string16& last_text = text.empty() ? pepper_composition_text_ | |
1369 : text; | |
1370 | |
1371 // last_text is empty only when both text and pepper_composition_text_ is. | |
1372 // Ignore it. | |
1373 if (last_text.empty()) | |
1374 return; | 1368 return; |
1375 | 1369 |
1376 if (!IsPepperAcceptingCompositionEvents()) { | 1370 if (!IsPepperAcceptingCompositionEvents()) { |
1377 base::i18n::UTF16CharIterator iterator(&last_text); | 1371 base::i18n::UTF16CharIterator iterator(&text); |
1378 int32_t i = 0; | 1372 int32_t i = 0; |
1379 while (iterator.Advance()) { | 1373 while (iterator.Advance()) { |
1380 blink::WebKeyboardEvent char_event; | 1374 blink::WebKeyboardEvent char_event; |
1381 char_event.type = blink::WebInputEvent::Char; | 1375 char_event.type = blink::WebInputEvent::Char; |
1382 char_event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 1376 char_event.timeStampSeconds = base::Time::Now().ToDoubleT(); |
1383 char_event.modifiers = 0; | 1377 char_event.modifiers = 0; |
1384 char_event.windowsKeyCode = last_text[i]; | 1378 char_event.windowsKeyCode = text[i]; |
1385 char_event.nativeKeyCode = last_text[i]; | 1379 char_event.nativeKeyCode = text[i]; |
1386 | 1380 |
1387 const int32_t char_start = i; | 1381 const int32_t char_start = i; |
1388 for (; i < iterator.array_pos(); ++i) { | 1382 for (; i < iterator.array_pos(); ++i) { |
1389 char_event.text[i - char_start] = last_text[i]; | 1383 char_event.text[i - char_start] = text[i]; |
1390 char_event.unmodifiedText[i - char_start] = last_text[i]; | 1384 char_event.unmodifiedText[i - char_start] = text[i]; |
1391 } | 1385 } |
1392 | 1386 |
1393 if (GetRenderWidget()->GetWebWidget()) | 1387 if (GetRenderWidget()->GetWebWidget()) |
| 1388 GetRenderWidget()->GetWebWidget()->handleInputEvent(char_event); |
| 1389 } |
| 1390 } else { |
| 1391 // Mimics the order of events sent by WebKit. |
| 1392 // See WebCore::Editor::setComposition() for the corresponding code. |
| 1393 focused_pepper_plugin_->HandleCompositionEnd(text); |
| 1394 focused_pepper_plugin_->HandleTextInput(text); |
| 1395 } |
| 1396 pepper_composition_text_.clear(); |
| 1397 } |
| 1398 |
| 1399 void RenderFrameImpl::OnImeFinishComposingText(bool keep_selection) { |
| 1400 const base::string16& text = pepper_composition_text_; |
| 1401 |
| 1402 if (text.empty()) |
| 1403 return; |
| 1404 |
| 1405 if (!IsPepperAcceptingCompositionEvents()) { |
| 1406 base::i18n::UTF16CharIterator iterator(&text); |
| 1407 int32_t i = 0; |
| 1408 while (iterator.Advance()) { |
| 1409 blink::WebKeyboardEvent char_event; |
| 1410 char_event.type = blink::WebInputEvent::Char; |
| 1411 char_event.timeStampSeconds = base::Time::Now().ToDoubleT(); |
| 1412 char_event.modifiers = 0; |
| 1413 char_event.windowsKeyCode = text[i]; |
| 1414 char_event.nativeKeyCode = text[i]; |
| 1415 |
| 1416 const int32_t char_start = i; |
| 1417 for (; i < iterator.array_pos(); ++i) { |
| 1418 char_event.text[i - char_start] = text[i]; |
| 1419 char_event.unmodifiedText[i - char_start] = text[i]; |
| 1420 } |
| 1421 |
| 1422 if (GetRenderWidget()->GetWebWidget()) |
1394 GetRenderWidget()->GetWebWidget()->handleInputEvent(char_event); | 1423 GetRenderWidget()->GetWebWidget()->handleInputEvent(char_event); |
1395 } | 1424 } |
1396 } else { | 1425 } else { |
1397 // Mimics the order of events sent by WebKit. | 1426 // Mimics the order of events sent by WebKit. |
1398 // See WebCore::Editor::setComposition() for the corresponding code. | 1427 // See WebCore::Editor::setComposition() for the corresponding code. |
1399 focused_pepper_plugin_->HandleCompositionEnd(last_text); | 1428 focused_pepper_plugin_->HandleCompositionEnd(text); |
1400 focused_pepper_plugin_->HandleTextInput(last_text); | 1429 focused_pepper_plugin_->HandleTextInput(text); |
1401 } | 1430 } |
1402 pepper_composition_text_.clear(); | 1431 pepper_composition_text_.clear(); |
1403 } | 1432 } |
1404 #endif // defined(ENABLE_PLUGINS) | 1433 #endif // defined(ENABLE_PLUGINS) |
1405 | 1434 |
1406 MediaStreamDispatcher* RenderFrameImpl::GetMediaStreamDispatcher() { | 1435 MediaStreamDispatcher* RenderFrameImpl::GetMediaStreamDispatcher() { |
1407 if (!web_user_media_client_) | 1436 if (!web_user_media_client_) |
1408 InitializeUserMediaClient(); | 1437 InitializeUserMediaClient(); |
1409 return web_user_media_client_ ? | 1438 return web_user_media_client_ ? |
1410 web_user_media_client_->media_stream_dispatcher() : NULL; | 1439 web_user_media_client_->media_stream_dispatcher() : NULL; |
(...skipping 4955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6366 // event target. Potentially a Pepper plugin will receive the event. | 6395 // event target. Potentially a Pepper plugin will receive the event. |
6367 // In order to tell whether a plugin gets the last mouse event and which it | 6396 // In order to tell whether a plugin gets the last mouse event and which it |
6368 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets | 6397 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets |
6369 // the event, it will notify us via DidReceiveMouseEvent() and set itself as | 6398 // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
6370 // |pepper_last_mouse_event_target_|. | 6399 // |pepper_last_mouse_event_target_|. |
6371 pepper_last_mouse_event_target_ = nullptr; | 6400 pepper_last_mouse_event_target_ = nullptr; |
6372 #endif | 6401 #endif |
6373 } | 6402 } |
6374 | 6403 |
6375 } // namespace content | 6404 } // namespace content |
OLD | NEW |