| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 pending_window_rect_count_(0), | 250 pending_window_rect_count_(0), |
| 251 screen_info_(screen_info), | 251 screen_info_(screen_info), |
| 252 device_scale_factor_(screen_info_.deviceScaleFactor), | 252 device_scale_factor_(screen_info_.deviceScaleFactor), |
| 253 #if defined(OS_ANDROID) | 253 #if defined(OS_ANDROID) |
| 254 text_field_is_dirty_(false), | 254 text_field_is_dirty_(false), |
| 255 #endif | 255 #endif |
| 256 popup_origin_scale_for_emulation_(0.f), | 256 popup_origin_scale_for_emulation_(0.f), |
| 257 frame_swap_message_queue_(new FrameSwapMessageQueue()), | 257 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
| 258 resizing_mode_selector_(new ResizingModeSelector()), | 258 resizing_mode_selector_(new ResizingModeSelector()), |
| 259 has_host_context_menu_location_(false), | 259 has_host_context_menu_location_(false), |
| 260 has_focus_(false) { | 260 has_focus_(false), |
| 261 focused_pepper_plugin_(nullptr) { |
| 261 if (!swapped_out) | 262 if (!swapped_out) |
| 262 RenderProcess::current()->AddRefProcess(); | 263 RenderProcess::current()->AddRefProcess(); |
| 263 DCHECK(RenderThread::Get()); | 264 DCHECK(RenderThread::Get()); |
| 264 device_color_profile_.push_back('0'); | 265 device_color_profile_.push_back('0'); |
| 265 #if defined(OS_ANDROID) | 266 #if defined(OS_ANDROID) |
| 266 text_input_info_history_.push_back(blink::WebTextInputInfo()); | 267 text_input_info_history_.push_back(blink::WebTextInputInfo()); |
| 267 #endif | 268 #endif |
| 268 | 269 |
| 269 // In tests there may not be a RenderThreadImpl. | 270 // In tests there may not be a RenderThreadImpl. |
| 270 if (RenderThreadImpl::current()) { | 271 if (RenderThreadImpl::current()) { |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 | 1354 |
| 1354 WebRect RenderWidget::windowResizerRect() { | 1355 WebRect RenderWidget::windowResizerRect() { |
| 1355 return resizer_rect_; | 1356 return resizer_rect_; |
| 1356 } | 1357 } |
| 1357 | 1358 |
| 1358 void RenderWidget::OnImeSetComposition( | 1359 void RenderWidget::OnImeSetComposition( |
| 1359 const base::string16& text, | 1360 const base::string16& text, |
| 1360 const std::vector<WebCompositionUnderline>& underlines, | 1361 const std::vector<WebCompositionUnderline>& underlines, |
| 1361 const gfx::Range& replacement_range, | 1362 const gfx::Range& replacement_range, |
| 1362 int selection_start, int selection_end) { | 1363 int selection_start, int selection_end) { |
| 1364 #if defined(ENABLE_PLUGINS) |
| 1365 if (focused_pepper_plugin_) { |
| 1366 focused_pepper_plugin_->render_frame()->OnImeSetComposition( |
| 1367 text, underlines, selection_start, selection_end); |
| 1368 return; |
| 1369 } |
| 1370 #endif |
| 1371 if (replacement_range.IsValid()) { |
| 1372 webwidget_->applyReplacementRange(replacement_range.start(), |
| 1373 replacement_range.length()); |
| 1374 } |
| 1375 |
| 1363 if (!ShouldHandleImeEvent()) | 1376 if (!ShouldHandleImeEvent()) |
| 1364 return; | 1377 return; |
| 1365 ImeEventGuard guard(this); | 1378 ImeEventGuard guard(this); |
| 1366 if (!webwidget_->setComposition( | 1379 if (!webwidget_->setComposition( |
| 1367 text, WebVector<WebCompositionUnderline>(underlines), | 1380 text, WebVector<WebCompositionUnderline>(underlines), |
| 1368 selection_start, selection_end)) { | 1381 selection_start, selection_end)) { |
| 1369 // If we failed to set the composition text, then we need to let the browser | 1382 // If we failed to set the composition text, then we need to let the browser |
| 1370 // process to cancel the input method's ongoing composition session, to make | 1383 // process to cancel the input method's ongoing composition session, to make |
| 1371 // sure we are in a consistent state. | 1384 // sure we are in a consistent state. |
| 1372 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1385 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1373 } | 1386 } |
| 1374 UpdateCompositionInfo(true); | 1387 UpdateCompositionInfo(true); |
| 1375 } | 1388 } |
| 1376 | 1389 |
| 1377 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1390 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
| 1378 const gfx::Range& replacement_range, | 1391 const gfx::Range& replacement_range, |
| 1379 bool keep_selection) { | 1392 bool keep_selection) { |
| 1393 #if defined(ENABLE_PLUGINS) |
| 1394 if (focused_pepper_plugin_) { |
| 1395 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( |
| 1396 text, replacement_range, keep_selection); |
| 1397 return; |
| 1398 } |
| 1399 #endif |
| 1400 if (replacement_range.IsValid()) { |
| 1401 webwidget_->applyReplacementRange(replacement_range.start(), |
| 1402 replacement_range.length()); |
| 1403 } |
| 1404 |
| 1380 if (!ShouldHandleImeEvent()) | 1405 if (!ShouldHandleImeEvent()) |
| 1381 return; | 1406 return; |
| 1382 ImeEventGuard guard(this); | 1407 ImeEventGuard guard(this); |
| 1383 input_handler_->set_handling_input_event(true); | 1408 input_handler_->set_handling_input_event(true); |
| 1384 if (text.length()) | 1409 if (text.length()) |
| 1385 webwidget_->confirmComposition(text); | 1410 webwidget_->confirmComposition(text); |
| 1386 else if (keep_selection) | 1411 else if (keep_selection) |
| 1387 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1412 webwidget_->confirmComposition(WebWidget::KeepSelection); |
| 1388 else | 1413 else |
| 1389 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1414 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) { | 1482 void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) { |
| 1458 if (compositor_) | 1483 if (compositor_) |
| 1459 compositor_->OnHandleCompositorProto(proto); | 1484 compositor_->OnHandleCompositorProto(proto); |
| 1460 } | 1485 } |
| 1461 | 1486 |
| 1462 void RenderWidget::showImeIfNeeded() { | 1487 void RenderWidget::showImeIfNeeded() { |
| 1463 OnShowImeIfNeeded(); | 1488 OnShowImeIfNeeded(); |
| 1464 } | 1489 } |
| 1465 | 1490 |
| 1466 ui::TextInputType RenderWidget::GetTextInputType() { | 1491 ui::TextInputType RenderWidget::GetTextInputType() { |
| 1492 #if defined(ENABLE_PLUGINS) |
| 1493 if (focused_pepper_plugin_) |
| 1494 return focused_pepper_plugin_->text_input_type(); |
| 1495 #endif |
| 1467 if (webwidget_) | 1496 if (webwidget_) |
| 1468 return WebKitToUiTextInputType(webwidget_->textInputType()); | 1497 return WebKitToUiTextInputType(webwidget_->textInputType()); |
| 1469 return ui::TEXT_INPUT_TYPE_NONE; | 1498 return ui::TEXT_INPUT_TYPE_NONE; |
| 1470 } | 1499 } |
| 1471 | 1500 |
| 1472 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { | 1501 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { |
| 1473 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); | 1502 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
| 1474 gfx::Range range = gfx::Range(); | 1503 gfx::Range range = gfx::Range(); |
| 1475 if (should_update_range) { | 1504 if (should_update_range) { |
| 1476 GetCompositionRange(&range); | 1505 GetCompositionRange(&range); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1669 // ime event. | 1698 // ime event. |
| 1670 UpdateSelectionBounds(); | 1699 UpdateSelectionBounds(); |
| 1671 #if defined(OS_ANDROID) | 1700 #if defined(OS_ANDROID) |
| 1672 UpdateTextInputState( | 1701 UpdateTextInputState( |
| 1673 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, | 1702 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, |
| 1674 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); | 1703 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); |
| 1675 #endif | 1704 #endif |
| 1676 } | 1705 } |
| 1677 | 1706 |
| 1678 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { | 1707 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
| 1708 #if defined(ENABLE_PLUGINS) |
| 1709 if (focused_pepper_plugin_) { |
| 1710 // TODO(kinaba) http://crbug.com/101101 |
| 1711 // Current Pepper IME API does not handle selection bounds. So we simply |
| 1712 // use the caret position as an empty range for now. It will be updated |
| 1713 // after Pepper API equips features related to surrounding text retrieval. |
| 1714 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds()); |
| 1715 convertViewportToWindow(&caret); |
| 1716 *focus = caret; |
| 1717 *anchor = caret; |
| 1718 return; |
| 1719 } |
| 1720 #endif |
| 1679 WebRect focus_webrect; | 1721 WebRect focus_webrect; |
| 1680 WebRect anchor_webrect; | 1722 WebRect anchor_webrect; |
| 1681 webwidget_->selectionBounds(focus_webrect, anchor_webrect); | 1723 webwidget_->selectionBounds(focus_webrect, anchor_webrect); |
| 1682 convertViewportToWindow(&focus_webrect); | 1724 convertViewportToWindow(&focus_webrect); |
| 1683 convertViewportToWindow(&anchor_webrect); | 1725 convertViewportToWindow(&anchor_webrect); |
| 1684 *focus = focus_webrect; | 1726 *focus = focus_webrect; |
| 1685 *anchor = anchor_webrect; | 1727 *anchor = anchor_webrect; |
| 1686 } | 1728 } |
| 1687 | 1729 |
| 1688 void RenderWidget::UpdateSelectionBounds() { | 1730 void RenderWidget::UpdateSelectionBounds() { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1763 // Check the type is in the range representable by ui::TextInputType. | 1805 // Check the type is in the range representable by ui::TextInputType. |
| 1764 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) << | 1806 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) << |
| 1765 "blink::WebTextInputType and ui::TextInputType not synchronized"; | 1807 "blink::WebTextInputType and ui::TextInputType not synchronized"; |
| 1766 return static_cast<ui::TextInputType>(type); | 1808 return static_cast<ui::TextInputType>(type); |
| 1767 } | 1809 } |
| 1768 | 1810 |
| 1769 void RenderWidget::GetCompositionCharacterBounds( | 1811 void RenderWidget::GetCompositionCharacterBounds( |
| 1770 std::vector<gfx::Rect>* bounds) { | 1812 std::vector<gfx::Rect>* bounds) { |
| 1771 DCHECK(bounds); | 1813 DCHECK(bounds); |
| 1772 bounds->clear(); | 1814 bounds->clear(); |
| 1815 |
| 1816 #if defined(ENABLE_PLUGINS) |
| 1817 if (focused_pepper_plugin_) |
| 1818 return; |
| 1819 #endif |
| 1820 |
| 1821 if (!webwidget_) |
| 1822 return; |
| 1823 blink::WebVector<blink::WebRect> bounds_from_blink; |
| 1824 if (!webwidget_->getCompositionCharacterBounds(bounds_from_blink)) |
| 1825 return; |
| 1826 |
| 1827 for (size_t i = 0; i < bounds_from_blink.size(); ++i) { |
| 1828 convertViewportToWindow(&bounds_from_blink[i]); |
| 1829 bounds->push_back(bounds_from_blink[i]); |
| 1830 } |
| 1773 } | 1831 } |
| 1774 | 1832 |
| 1775 void RenderWidget::GetCompositionRange(gfx::Range* range) { | 1833 void RenderWidget::GetCompositionRange(gfx::Range* range) { |
| 1834 #if defined(ENABLE_PLUGINS) |
| 1835 if (focused_pepper_plugin_) |
| 1836 return; |
| 1837 #endif |
| 1776 size_t location, length; | 1838 size_t location, length; |
| 1777 if (webwidget_->compositionRange(&location, &length)) { | 1839 if (webwidget_->compositionRange(&location, &length)) { |
| 1778 range->set_start(location); | 1840 range->set_start(location); |
| 1779 range->set_end(location + length); | 1841 range->set_end(location + length); |
| 1780 } else if (webwidget_->caretOrSelectionRange(&location, &length)) { | 1842 } else if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1781 range->set_start(location); | 1843 range->set_start(location); |
| 1782 range->set_end(location + length); | 1844 range->set_end(location + length); |
| 1783 } else { | 1845 } else { |
| 1784 *range = gfx::Range::InvalidRange(); | 1846 *range = gfx::Range::InvalidRange(); |
| 1785 } | 1847 } |
| 1786 } | 1848 } |
| 1787 | 1849 |
| 1788 bool RenderWidget::ShouldUpdateCompositionInfo( | 1850 bool RenderWidget::ShouldUpdateCompositionInfo( |
| 1789 const gfx::Range& range, | 1851 const gfx::Range& range, |
| 1790 const std::vector<gfx::Rect>& bounds) { | 1852 const std::vector<gfx::Rect>& bounds) { |
| 1791 if (composition_range_ != range) | 1853 if (composition_range_ != range) |
| 1792 return true; | 1854 return true; |
| 1793 if (bounds.size() != composition_character_bounds_.size()) | 1855 if (bounds.size() != composition_character_bounds_.size()) |
| 1794 return true; | 1856 return true; |
| 1795 for (size_t i = 0; i < bounds.size(); ++i) { | 1857 for (size_t i = 0; i < bounds.size(); ++i) { |
| 1796 if (bounds[i] != composition_character_bounds_[i]) | 1858 if (bounds[i] != composition_character_bounds_[i]) |
| 1797 return true; | 1859 return true; |
| 1798 } | 1860 } |
| 1799 return false; | 1861 return false; |
| 1800 } | 1862 } |
| 1801 | 1863 |
| 1802 bool RenderWidget::CanComposeInline() { | 1864 bool RenderWidget::CanComposeInline() { |
| 1865 #if defined(ENABLE_PLUGINS) |
| 1866 if (focused_pepper_plugin_) |
| 1867 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents(); |
| 1868 #endif |
| 1803 return true; | 1869 return true; |
| 1804 } | 1870 } |
| 1805 | 1871 |
| 1806 WebScreenInfo RenderWidget::screenInfo() { | 1872 WebScreenInfo RenderWidget::screenInfo() { |
| 1807 return screen_info_; | 1873 return screen_info_; |
| 1808 } | 1874 } |
| 1809 | 1875 |
| 1810 void RenderWidget::resetInputMethod() { | 1876 void RenderWidget::resetInputMethod() { |
| 1811 ImeEventGuard guard(this); | 1877 ImeEventGuard guard(this); |
| 1812 // If the last text input type is not None, then we should finish any | 1878 // If the last text input type is not None, then we should finish any |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 void RenderWidget::requestPointerUnlock() { | 2045 void RenderWidget::requestPointerUnlock() { |
| 1980 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); | 2046 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 1981 } | 2047 } |
| 1982 | 2048 |
| 1983 bool RenderWidget::isPointerLocked() { | 2049 bool RenderWidget::isPointerLocked() { |
| 1984 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2050 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 1985 webwidget_mouse_lock_target_.get()); | 2051 webwidget_mouse_lock_target_.get()); |
| 1986 } | 2052 } |
| 1987 | 2053 |
| 1988 } // namespace content | 2054 } // namespace content |
| OLD | NEW |