| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 screen_info_(screen_info), | 239 screen_info_(screen_info), |
| 240 device_scale_factor_(screen_info_.deviceScaleFactor), | 240 device_scale_factor_(screen_info_.deviceScaleFactor), |
| 241 next_output_surface_id_(0), | 241 next_output_surface_id_(0), |
| 242 #if defined(OS_ANDROID) | 242 #if defined(OS_ANDROID) |
| 243 text_field_is_dirty_(false), | 243 text_field_is_dirty_(false), |
| 244 #endif | 244 #endif |
| 245 popup_origin_scale_for_emulation_(0.f), | 245 popup_origin_scale_for_emulation_(0.f), |
| 246 frame_swap_message_queue_(new FrameSwapMessageQueue()), | 246 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
| 247 resizing_mode_selector_(new ResizingModeSelector()), | 247 resizing_mode_selector_(new ResizingModeSelector()), |
| 248 has_host_context_menu_location_(false), | 248 has_host_context_menu_location_(false), |
| 249 has_focus_(false) { | 249 has_focus_(false), |
| 250 focused_pepper_plugin_(nullptr) { |
| 250 if (!swapped_out) | 251 if (!swapped_out) |
| 251 RenderProcess::current()->AddRefProcess(); | 252 RenderProcess::current()->AddRefProcess(); |
| 252 DCHECK(RenderThread::Get()); | 253 DCHECK(RenderThread::Get()); |
| 253 device_color_profile_.push_back('0'); | 254 device_color_profile_.push_back('0'); |
| 254 #if defined(OS_ANDROID) | 255 #if defined(OS_ANDROID) |
| 255 text_input_info_history_.push_back(blink::WebTextInputInfo()); | 256 text_input_info_history_.push_back(blink::WebTextInputInfo()); |
| 256 #endif | 257 #endif |
| 257 | 258 |
| 258 // In tests there may not be a RenderThreadImpl. | 259 // In tests there may not be a RenderThreadImpl. |
| 259 if (RenderThreadImpl::current()) { | 260 if (RenderThreadImpl::current()) { |
| (...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 | 1478 |
| 1478 WebRect RenderWidget::windowResizerRect() { | 1479 WebRect RenderWidget::windowResizerRect() { |
| 1479 return resizer_rect_; | 1480 return resizer_rect_; |
| 1480 } | 1481 } |
| 1481 | 1482 |
| 1482 void RenderWidget::OnImeSetComposition( | 1483 void RenderWidget::OnImeSetComposition( |
| 1483 const base::string16& text, | 1484 const base::string16& text, |
| 1484 const std::vector<WebCompositionUnderline>& underlines, | 1485 const std::vector<WebCompositionUnderline>& underlines, |
| 1485 const gfx::Range& replacement_range, | 1486 const gfx::Range& replacement_range, |
| 1486 int selection_start, int selection_end) { | 1487 int selection_start, int selection_end) { |
| 1488 #if defined(ENABLE_PLUGINS) |
| 1489 if (focused_pepper_plugin_) { |
| 1490 focused_pepper_plugin_->render_frame()->OnImeSetComposition( |
| 1491 text, underlines, selection_start, selection_end); |
| 1492 return; |
| 1493 } |
| 1494 #endif |
| 1495 if (replacement_range.IsValid()) { |
| 1496 webwidget_->adjustReplacementRangeForAccentedCharacters( |
| 1497 replacement_range.start(), replacement_range.length()); |
| 1498 } |
| 1499 |
| 1487 if (!ShouldHandleImeEvent()) | 1500 if (!ShouldHandleImeEvent()) |
| 1488 return; | 1501 return; |
| 1489 ImeEventGuard guard(this); | 1502 ImeEventGuard guard(this); |
| 1490 if (!webwidget_->setComposition( | 1503 if (!webwidget_->setComposition( |
| 1491 text, WebVector<WebCompositionUnderline>(underlines), | 1504 text, WebVector<WebCompositionUnderline>(underlines), |
| 1492 selection_start, selection_end)) { | 1505 selection_start, selection_end)) { |
| 1493 // If we failed to set the composition text, then we need to let the browser | 1506 // If we failed to set the composition text, then we need to let the browser |
| 1494 // process to cancel the input method's ongoing composition session, to make | 1507 // process to cancel the input method's ongoing composition session, to make |
| 1495 // sure we are in a consistent state. | 1508 // sure we are in a consistent state. |
| 1496 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1509 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1497 } | 1510 } |
| 1498 UpdateCompositionInfo(true); | 1511 UpdateCompositionInfo(true); |
| 1499 } | 1512 } |
| 1500 | 1513 |
| 1501 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1514 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
| 1502 const gfx::Range& replacement_range, | 1515 const gfx::Range& replacement_range, |
| 1503 bool keep_selection) { | 1516 bool keep_selection) { |
| 1517 #if defined(ENABLE_PLUGINS) |
| 1518 if (focused_pepper_plugin_) { |
| 1519 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( |
| 1520 text, replacement_range, keep_selection); |
| 1521 return; |
| 1522 } |
| 1523 #endif |
| 1524 if (replacement_range.IsValid()) { |
| 1525 webwidget_->adjustReplacementRangeForAccentedCharacters( |
| 1526 replacement_range.start(), replacement_range.length()); |
| 1527 } |
| 1528 |
| 1504 if (!ShouldHandleImeEvent()) | 1529 if (!ShouldHandleImeEvent()) |
| 1505 return; | 1530 return; |
| 1506 ImeEventGuard guard(this); | 1531 ImeEventGuard guard(this); |
| 1507 input_handler_->set_handling_input_event(true); | 1532 input_handler_->set_handling_input_event(true); |
| 1508 if (text.length()) | 1533 if (text.length()) |
| 1509 webwidget_->confirmComposition(text); | 1534 webwidget_->confirmComposition(text); |
| 1510 else if (keep_selection) | 1535 else if (keep_selection) |
| 1511 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1536 webwidget_->confirmComposition(WebWidget::KeepSelection); |
| 1512 else | 1537 else |
| 1513 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1538 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) { | 1606 void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) { |
| 1582 if (compositor_) | 1607 if (compositor_) |
| 1583 compositor_->OnHandleCompositorProto(proto); | 1608 compositor_->OnHandleCompositorProto(proto); |
| 1584 } | 1609 } |
| 1585 | 1610 |
| 1586 void RenderWidget::showImeIfNeeded() { | 1611 void RenderWidget::showImeIfNeeded() { |
| 1587 OnShowImeIfNeeded(); | 1612 OnShowImeIfNeeded(); |
| 1588 } | 1613 } |
| 1589 | 1614 |
| 1590 ui::TextInputType RenderWidget::GetTextInputType() { | 1615 ui::TextInputType RenderWidget::GetTextInputType() { |
| 1616 #if defined(ENABLE_PLUGINS) |
| 1617 if (focused_pepper_plugin_) |
| 1618 return focused_pepper_plugin_->text_input_type(); |
| 1619 #endif |
| 1591 if (webwidget_) | 1620 if (webwidget_) |
| 1592 return WebKitToUiTextInputType(webwidget_->textInputType()); | 1621 return WebKitToUiTextInputType(webwidget_->textInputType()); |
| 1593 return ui::TEXT_INPUT_TYPE_NONE; | 1622 return ui::TEXT_INPUT_TYPE_NONE; |
| 1594 } | 1623 } |
| 1595 | 1624 |
| 1596 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { | 1625 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { |
| 1597 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); | 1626 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
| 1598 gfx::Range range = gfx::Range(); | 1627 gfx::Range range = gfx::Range(); |
| 1599 if (should_update_range) { | 1628 if (should_update_range) { |
| 1600 GetCompositionRange(&range); | 1629 GetCompositionRange(&range); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1793 // ime event. | 1822 // ime event. |
| 1794 UpdateSelectionBounds(); | 1823 UpdateSelectionBounds(); |
| 1795 #if defined(OS_ANDROID) | 1824 #if defined(OS_ANDROID) |
| 1796 UpdateTextInputState( | 1825 UpdateTextInputState( |
| 1797 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, | 1826 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, |
| 1798 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); | 1827 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); |
| 1799 #endif | 1828 #endif |
| 1800 } | 1829 } |
| 1801 | 1830 |
| 1802 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { | 1831 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
| 1832 #if defined(ENABLE_PLUGINS) |
| 1833 if (focused_pepper_plugin_) { |
| 1834 // TODO(kinaba) http://crbug.com/101101 |
| 1835 // Current Pepper IME API does not handle selection bounds. So we simply |
| 1836 // use the caret position as an empty range for now. It will be updated |
| 1837 // after Pepper API equips features related to surrounding text retrieval. |
| 1838 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds()); |
| 1839 convertViewportToWindow(&caret); |
| 1840 *focus = caret; |
| 1841 *anchor = caret; |
| 1842 return; |
| 1843 } |
| 1844 #endif |
| 1803 WebRect focus_webrect; | 1845 WebRect focus_webrect; |
| 1804 WebRect anchor_webrect; | 1846 WebRect anchor_webrect; |
| 1805 webwidget_->selectionBounds(focus_webrect, anchor_webrect); | 1847 webwidget_->selectionBounds(focus_webrect, anchor_webrect); |
| 1806 convertViewportToWindow(&focus_webrect); | 1848 convertViewportToWindow(&focus_webrect); |
| 1807 convertViewportToWindow(&anchor_webrect); | 1849 convertViewportToWindow(&anchor_webrect); |
| 1808 *focus = focus_webrect; | 1850 *focus = focus_webrect; |
| 1809 *anchor = anchor_webrect; | 1851 *anchor = anchor_webrect; |
| 1810 } | 1852 } |
| 1811 | 1853 |
| 1812 void RenderWidget::UpdateSelectionBounds() { | 1854 void RenderWidget::UpdateSelectionBounds() { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 // Check the type is in the range representable by ui::TextInputType. | 1929 // Check the type is in the range representable by ui::TextInputType. |
| 1888 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) << | 1930 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) << |
| 1889 "blink::WebTextInputType and ui::TextInputType not synchronized"; | 1931 "blink::WebTextInputType and ui::TextInputType not synchronized"; |
| 1890 return static_cast<ui::TextInputType>(type); | 1932 return static_cast<ui::TextInputType>(type); |
| 1891 } | 1933 } |
| 1892 | 1934 |
| 1893 void RenderWidget::GetCompositionCharacterBounds( | 1935 void RenderWidget::GetCompositionCharacterBounds( |
| 1894 std::vector<gfx::Rect>* bounds) { | 1936 std::vector<gfx::Rect>* bounds) { |
| 1895 DCHECK(bounds); | 1937 DCHECK(bounds); |
| 1896 bounds->clear(); | 1938 bounds->clear(); |
| 1939 |
| 1940 #if defined(ENABLE_PLUGINS) |
| 1941 if (focused_pepper_plugin_) |
| 1942 return; |
| 1943 #endif |
| 1944 |
| 1945 if (!webwidget_) |
| 1946 return; |
| 1947 blink::WebVector<blink::WebRect> bounds_from_blink; |
| 1948 if (!webwidget_->getCompositionCharacterBounds(bounds_from_blink)) |
| 1949 return; |
| 1950 |
| 1951 for (size_t i = 0; i < bounds_from_blink.size(); ++i) { |
| 1952 convertViewportToWindow(&bounds_from_blink[i]); |
| 1953 bounds->push_back(bounds_from_blink[i]); |
| 1954 } |
| 1897 } | 1955 } |
| 1898 | 1956 |
| 1899 void RenderWidget::GetCompositionRange(gfx::Range* range) { | 1957 void RenderWidget::GetCompositionRange(gfx::Range* range) { |
| 1958 #if defined(ENABLE_PLUGINS) |
| 1959 if (focused_pepper_plugin_) |
| 1960 return; |
| 1961 #endif |
| 1900 size_t location, length; | 1962 size_t location, length; |
| 1901 if (webwidget_->compositionRange(&location, &length)) { | 1963 if (webwidget_->compositionRange(&location, &length)) { |
| 1902 range->set_start(location); | 1964 range->set_start(location); |
| 1903 range->set_end(location + length); | 1965 range->set_end(location + length); |
| 1904 } else if (webwidget_->caretOrSelectionRange(&location, &length)) { | 1966 } else if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1905 range->set_start(location); | 1967 range->set_start(location); |
| 1906 range->set_end(location + length); | 1968 range->set_end(location + length); |
| 1907 } else { | 1969 } else { |
| 1908 *range = gfx::Range::InvalidRange(); | 1970 *range = gfx::Range::InvalidRange(); |
| 1909 } | 1971 } |
| 1910 } | 1972 } |
| 1911 | 1973 |
| 1912 bool RenderWidget::ShouldUpdateCompositionInfo( | 1974 bool RenderWidget::ShouldUpdateCompositionInfo( |
| 1913 const gfx::Range& range, | 1975 const gfx::Range& range, |
| 1914 const std::vector<gfx::Rect>& bounds) { | 1976 const std::vector<gfx::Rect>& bounds) { |
| 1915 if (composition_range_ != range) | 1977 if (composition_range_ != range) |
| 1916 return true; | 1978 return true; |
| 1917 if (bounds.size() != composition_character_bounds_.size()) | 1979 if (bounds.size() != composition_character_bounds_.size()) |
| 1918 return true; | 1980 return true; |
| 1919 for (size_t i = 0; i < bounds.size(); ++i) { | 1981 for (size_t i = 0; i < bounds.size(); ++i) { |
| 1920 if (bounds[i] != composition_character_bounds_[i]) | 1982 if (bounds[i] != composition_character_bounds_[i]) |
| 1921 return true; | 1983 return true; |
| 1922 } | 1984 } |
| 1923 return false; | 1985 return false; |
| 1924 } | 1986 } |
| 1925 | 1987 |
| 1926 bool RenderWidget::CanComposeInline() { | 1988 bool RenderWidget::CanComposeInline() { |
| 1989 #if defined(ENABLE_PLUGINS) |
| 1990 if (focused_pepper_plugin_) |
| 1991 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents(); |
| 1992 #endif |
| 1927 return true; | 1993 return true; |
| 1928 } | 1994 } |
| 1929 | 1995 |
| 1930 WebScreenInfo RenderWidget::screenInfo() { | 1996 WebScreenInfo RenderWidget::screenInfo() { |
| 1931 return screen_info_; | 1997 return screen_info_; |
| 1932 } | 1998 } |
| 1933 | 1999 |
| 1934 void RenderWidget::resetInputMethod() { | 2000 void RenderWidget::resetInputMethod() { |
| 1935 ImeEventGuard guard(this); | 2001 ImeEventGuard guard(this); |
| 1936 // If the last text input type is not None, then we should finish any | 2002 // If the last text input type is not None, then we should finish any |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2090 } | 2156 } |
| 2091 | 2157 |
| 2092 float RenderWidget::GetOriginalDeviceScaleFactor() const { | 2158 float RenderWidget::GetOriginalDeviceScaleFactor() const { |
| 2093 return | 2159 return |
| 2094 screen_metrics_emulator_ ? | 2160 screen_metrics_emulator_ ? |
| 2095 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : | 2161 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : |
| 2096 device_scale_factor_; | 2162 device_scale_factor_; |
| 2097 } | 2163 } |
| 2098 | 2164 |
| 2099 } // namespace content | 2165 } // namespace content |
| OLD | NEW |