| 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 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 | 1331 |
| 1331 WebRect RenderWidget::windowResizerRect() { | 1332 WebRect RenderWidget::windowResizerRect() { |
| 1332 return resizer_rect_; | 1333 return resizer_rect_; |
| 1333 } | 1334 } |
| 1334 | 1335 |
| 1335 void RenderWidget::OnImeSetComposition( | 1336 void RenderWidget::OnImeSetComposition( |
| 1336 const base::string16& text, | 1337 const base::string16& text, |
| 1337 const std::vector<WebCompositionUnderline>& underlines, | 1338 const std::vector<WebCompositionUnderline>& underlines, |
| 1338 const gfx::Range& replacement_range, | 1339 const gfx::Range& replacement_range, |
| 1339 int selection_start, int selection_end) { | 1340 int selection_start, int selection_end) { |
| 1341 #if defined(ENABLE_PLUGINS) |
| 1342 if (focused_pepper_plugin_) { |
| 1343 focused_pepper_plugin_->render_frame()->OnImeSetComposition( |
| 1344 text, underlines, selection_start, selection_end); |
| 1345 return; |
| 1346 } |
| 1347 #endif |
| 1348 if (replacement_range.IsValid()) { |
| 1349 webwidget_->applyReplacementRange(replacement_range.start(), |
| 1350 replacement_range.length()); |
| 1351 } |
| 1352 |
| 1340 if (!ShouldHandleImeEvent()) | 1353 if (!ShouldHandleImeEvent()) |
| 1341 return; | 1354 return; |
| 1342 ImeEventGuard guard(this); | 1355 ImeEventGuard guard(this); |
| 1343 if (!webwidget_->setComposition( | 1356 if (!webwidget_->setComposition( |
| 1344 text, WebVector<WebCompositionUnderline>(underlines), | 1357 text, WebVector<WebCompositionUnderline>(underlines), |
| 1345 selection_start, selection_end)) { | 1358 selection_start, selection_end)) { |
| 1346 // If we failed to set the composition text, then we need to let the browser | 1359 // If we failed to set the composition text, then we need to let the browser |
| 1347 // process to cancel the input method's ongoing composition session, to make | 1360 // process to cancel the input method's ongoing composition session, to make |
| 1348 // sure we are in a consistent state. | 1361 // sure we are in a consistent state. |
| 1349 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1362 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1350 } | 1363 } |
| 1351 UpdateCompositionInfo(true); | 1364 UpdateCompositionInfo(true); |
| 1352 } | 1365 } |
| 1353 | 1366 |
| 1354 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1367 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
| 1355 const gfx::Range& replacement_range, | 1368 const gfx::Range& replacement_range, |
| 1356 bool keep_selection) { | 1369 bool keep_selection) { |
| 1370 #if defined(ENABLE_PLUGINS) |
| 1371 if (focused_pepper_plugin_) { |
| 1372 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( |
| 1373 text, replacement_range, keep_selection); |
| 1374 return; |
| 1375 } |
| 1376 #endif |
| 1377 if (replacement_range.IsValid()) { |
| 1378 webwidget_->applyReplacementRange(replacement_range.start(), |
| 1379 replacement_range.length()); |
| 1380 } |
| 1381 |
| 1357 if (!ShouldHandleImeEvent()) | 1382 if (!ShouldHandleImeEvent()) |
| 1358 return; | 1383 return; |
| 1359 ImeEventGuard guard(this); | 1384 ImeEventGuard guard(this); |
| 1360 input_handler_->set_handling_input_event(true); | 1385 input_handler_->set_handling_input_event(true); |
| 1361 if (text.length()) | 1386 if (text.length()) |
| 1362 webwidget_->confirmComposition(text); | 1387 webwidget_->confirmComposition(text); |
| 1363 else if (keep_selection) | 1388 else if (keep_selection) |
| 1364 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1389 webwidget_->confirmComposition(WebWidget::KeepSelection); |
| 1365 else | 1390 else |
| 1366 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1391 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) { | 1459 void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) { |
| 1435 if (compositor_) | 1460 if (compositor_) |
| 1436 compositor_->OnHandleCompositorProto(proto); | 1461 compositor_->OnHandleCompositorProto(proto); |
| 1437 } | 1462 } |
| 1438 | 1463 |
| 1439 void RenderWidget::showImeIfNeeded() { | 1464 void RenderWidget::showImeIfNeeded() { |
| 1440 OnShowImeIfNeeded(); | 1465 OnShowImeIfNeeded(); |
| 1441 } | 1466 } |
| 1442 | 1467 |
| 1443 ui::TextInputType RenderWidget::GetTextInputType() { | 1468 ui::TextInputType RenderWidget::GetTextInputType() { |
| 1469 #if defined(ENABLE_PLUGINS) |
| 1470 if (focused_pepper_plugin_) |
| 1471 return focused_pepper_plugin_->text_input_type(); |
| 1472 #endif |
| 1444 if (webwidget_) | 1473 if (webwidget_) |
| 1445 return WebKitToUiTextInputType(webwidget_->textInputType()); | 1474 return WebKitToUiTextInputType(webwidget_->textInputType()); |
| 1446 return ui::TEXT_INPUT_TYPE_NONE; | 1475 return ui::TEXT_INPUT_TYPE_NONE; |
| 1447 } | 1476 } |
| 1448 | 1477 |
| 1449 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { | 1478 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { |
| 1450 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); | 1479 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
| 1451 gfx::Range range = gfx::Range(); | 1480 gfx::Range range = gfx::Range(); |
| 1452 if (should_update_range) { | 1481 if (should_update_range) { |
| 1453 GetCompositionRange(&range); | 1482 GetCompositionRange(&range); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 // ime event. | 1675 // ime event. |
| 1647 UpdateSelectionBounds(); | 1676 UpdateSelectionBounds(); |
| 1648 #if defined(OS_ANDROID) | 1677 #if defined(OS_ANDROID) |
| 1649 UpdateTextInputState( | 1678 UpdateTextInputState( |
| 1650 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, | 1679 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, |
| 1651 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); | 1680 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); |
| 1652 #endif | 1681 #endif |
| 1653 } | 1682 } |
| 1654 | 1683 |
| 1655 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { | 1684 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
| 1685 #if defined(ENABLE_PLUGINS) |
| 1686 if (focused_pepper_plugin_) { |
| 1687 // TODO(kinaba) http://crbug.com/101101 |
| 1688 // Current Pepper IME API does not handle selection bounds. So we simply |
| 1689 // use the caret position as an empty range for now. It will be updated |
| 1690 // after Pepper API equips features related to surrounding text retrieval. |
| 1691 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds()); |
| 1692 convertViewportToWindow(&caret); |
| 1693 *focus = caret; |
| 1694 *anchor = caret; |
| 1695 return; |
| 1696 } |
| 1697 #endif |
| 1656 WebRect focus_webrect; | 1698 WebRect focus_webrect; |
| 1657 WebRect anchor_webrect; | 1699 WebRect anchor_webrect; |
| 1658 webwidget_->selectionBounds(focus_webrect, anchor_webrect); | 1700 webwidget_->selectionBounds(focus_webrect, anchor_webrect); |
| 1659 convertViewportToWindow(&focus_webrect); | 1701 convertViewportToWindow(&focus_webrect); |
| 1660 convertViewportToWindow(&anchor_webrect); | 1702 convertViewportToWindow(&anchor_webrect); |
| 1661 *focus = focus_webrect; | 1703 *focus = focus_webrect; |
| 1662 *anchor = anchor_webrect; | 1704 *anchor = anchor_webrect; |
| 1663 } | 1705 } |
| 1664 | 1706 |
| 1665 void RenderWidget::UpdateSelectionBounds() { | 1707 void RenderWidget::UpdateSelectionBounds() { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 // Check the type is in the range representable by ui::TextInputType. | 1803 // Check the type is in the range representable by ui::TextInputType. |
| 1762 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) << | 1804 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) << |
| 1763 "blink::WebTextInputType and ui::TextInputType not synchronized"; | 1805 "blink::WebTextInputType and ui::TextInputType not synchronized"; |
| 1764 return static_cast<ui::TextInputType>(type); | 1806 return static_cast<ui::TextInputType>(type); |
| 1765 } | 1807 } |
| 1766 | 1808 |
| 1767 void RenderWidget::GetCompositionCharacterBounds( | 1809 void RenderWidget::GetCompositionCharacterBounds( |
| 1768 std::vector<gfx::Rect>* bounds) { | 1810 std::vector<gfx::Rect>* bounds) { |
| 1769 DCHECK(bounds); | 1811 DCHECK(bounds); |
| 1770 bounds->clear(); | 1812 bounds->clear(); |
| 1813 |
| 1814 #if defined(ENABLE_PLUGINS) |
| 1815 if (focused_pepper_plugin_) |
| 1816 return; |
| 1817 #endif |
| 1818 |
| 1819 if (!webwidget_) |
| 1820 return; |
| 1821 blink::WebVector<blink::WebRect> bounds_from_blink; |
| 1822 if (!webwidget_->getCompositionCharacterBounds(bounds_from_blink)) |
| 1823 return; |
| 1824 |
| 1825 for (size_t i = 0; i < bounds_from_blink.size(); ++i) { |
| 1826 convertViewportToWindow(&bounds_from_blink[i]); |
| 1827 bounds->push_back(bounds_from_blink[i]); |
| 1828 } |
| 1771 } | 1829 } |
| 1772 | 1830 |
| 1773 void RenderWidget::GetCompositionRange(gfx::Range* range) { | 1831 void RenderWidget::GetCompositionRange(gfx::Range* range) { |
| 1832 #if defined(ENABLE_PLUGINS) |
| 1833 if (focused_pepper_plugin_) |
| 1834 return; |
| 1835 #endif |
| 1774 size_t location, length; | 1836 size_t location, length; |
| 1775 if (webwidget_->compositionRange(&location, &length)) { | 1837 if (webwidget_->compositionRange(&location, &length)) { |
| 1776 range->set_start(location); | 1838 range->set_start(location); |
| 1777 range->set_end(location + length); | 1839 range->set_end(location + length); |
| 1778 } else if (webwidget_->caretOrSelectionRange(&location, &length)) { | 1840 } else if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1779 range->set_start(location); | 1841 range->set_start(location); |
| 1780 range->set_end(location + length); | 1842 range->set_end(location + length); |
| 1781 } else { | 1843 } else { |
| 1782 *range = gfx::Range::InvalidRange(); | 1844 *range = gfx::Range::InvalidRange(); |
| 1783 } | 1845 } |
| 1784 } | 1846 } |
| 1785 | 1847 |
| 1786 bool RenderWidget::ShouldUpdateCompositionInfo( | 1848 bool RenderWidget::ShouldUpdateCompositionInfo( |
| 1787 const gfx::Range& range, | 1849 const gfx::Range& range, |
| 1788 const std::vector<gfx::Rect>& bounds) { | 1850 const std::vector<gfx::Rect>& bounds) { |
| 1789 if (composition_range_ != range) | 1851 if (composition_range_ != range) |
| 1790 return true; | 1852 return true; |
| 1791 if (bounds.size() != composition_character_bounds_.size()) | 1853 if (bounds.size() != composition_character_bounds_.size()) |
| 1792 return true; | 1854 return true; |
| 1793 for (size_t i = 0; i < bounds.size(); ++i) { | 1855 for (size_t i = 0; i < bounds.size(); ++i) { |
| 1794 if (bounds[i] != composition_character_bounds_[i]) | 1856 if (bounds[i] != composition_character_bounds_[i]) |
| 1795 return true; | 1857 return true; |
| 1796 } | 1858 } |
| 1797 return false; | 1859 return false; |
| 1798 } | 1860 } |
| 1799 | 1861 |
| 1800 bool RenderWidget::CanComposeInline() { | 1862 bool RenderWidget::CanComposeInline() { |
| 1863 #if defined(ENABLE_PLUGINS) |
| 1864 if (focused_pepper_plugin_) |
| 1865 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents(); |
| 1866 #endif |
| 1801 return true; | 1867 return true; |
| 1802 } | 1868 } |
| 1803 | 1869 |
| 1804 WebScreenInfo RenderWidget::screenInfo() { | 1870 WebScreenInfo RenderWidget::screenInfo() { |
| 1805 return screen_info_; | 1871 return screen_info_; |
| 1806 } | 1872 } |
| 1807 | 1873 |
| 1808 void RenderWidget::resetInputMethod() { | 1874 void RenderWidget::resetInputMethod() { |
| 1809 ImeEventGuard guard(this); | 1875 ImeEventGuard guard(this); |
| 1810 // If the last text input type is not None, then we should finish any | 1876 // 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... |
| 1977 void RenderWidget::requestPointerUnlock() { | 2043 void RenderWidget::requestPointerUnlock() { |
| 1978 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); | 2044 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 1979 } | 2045 } |
| 1980 | 2046 |
| 1981 bool RenderWidget::isPointerLocked() { | 2047 bool RenderWidget::isPointerLocked() { |
| 1982 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2048 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 1983 webwidget_mouse_lock_target_.get()); | 2049 webwidget_mouse_lock_target_.get()); |
| 1984 } | 2050 } |
| 1985 | 2051 |
| 1986 } // namespace content | 2052 } // namespace content |
| OLD | NEW |