Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: content/renderer/render_widget.cc

Issue 2029423003: OOPIF IME: Renderer Side Changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implemented WebViewImpl::getCompositionCharacterBounds Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 FOR_EACH_OBSERVER(
1489 RenderFrameImpl, render_frames_,
1490 OnImeSetComposition(this, text, underlines, replacement_range,
EhsanK 2016/06/03 02:38:54 This and the one below for OnImeConfirmComposition
kenrb 2016/06/07 20:18:13 This is a bit tricky. The code is a bit tortured a
EhsanK 2016/06/09 03:24:26 Done.
1491 selection_start, selection_end));
1492 }
1493
1494 void RenderWidget::HandleImeSetComposition(
1495 const base::string16& text,
1496 const std::vector<WebCompositionUnderline>& underlines,
1497 const gfx::Range& replacement_range,
1498 int selection_start,
1499 int selection_end) {
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 FOR_EACH_OBSERVER(
1518 RenderFrameImpl, render_frames_,
1519 OnImeConfirmComposition(this, text, replacement_range, keep_selection));
1520 }
1521
1522 void RenderWidget::HandleImeConfirmComposition(
1523 const base::string16& text,
1524 const gfx::Range& replacement_range,
1525 bool keep_selection) {
1504 if (!ShouldHandleImeEvent()) 1526 if (!ShouldHandleImeEvent())
1505 return; 1527 return;
1506 ImeEventGuard guard(this); 1528 ImeEventGuard guard(this);
1507 input_handler_->set_handling_input_event(true); 1529 input_handler_->set_handling_input_event(true);
1508 if (text.length()) 1530 if (text.length())
1509 webwidget_->confirmComposition(text); 1531 webwidget_->confirmComposition(text);
1510 else if (keep_selection) 1532 else if (keep_selection)
1511 webwidget_->confirmComposition(WebWidget::KeepSelection); 1533 webwidget_->confirmComposition(WebWidget::KeepSelection);
1512 else 1534 else
1513 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); 1535 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) { 1603 void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1582 if (compositor_) 1604 if (compositor_)
1583 compositor_->OnHandleCompositorProto(proto); 1605 compositor_->OnHandleCompositorProto(proto);
1584 } 1606 }
1585 1607
1586 void RenderWidget::showImeIfNeeded() { 1608 void RenderWidget::showImeIfNeeded() {
1587 OnShowImeIfNeeded(); 1609 OnShowImeIfNeeded();
1588 } 1610 }
1589 1611
1590 ui::TextInputType RenderWidget::GetTextInputType() { 1612 ui::TextInputType RenderWidget::GetTextInputType() {
1613 #if defined(ENABLE_PLUGINS)
1614 if (focused_pepper_plugin_)
1615 return focused_pepper_plugin_->text_input_type();
1616 #endif
1591 if (webwidget_) 1617 if (webwidget_)
1592 return WebKitToUiTextInputType(webwidget_->textInputType()); 1618 return WebKitToUiTextInputType(webwidget_->textInputType());
1593 return ui::TEXT_INPUT_TYPE_NONE; 1619 return ui::TEXT_INPUT_TYPE_NONE;
1594 } 1620 }
1595 1621
1596 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { 1622 void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
1597 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); 1623 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1598 gfx::Range range = gfx::Range(); 1624 gfx::Range range = gfx::Range();
1599 if (should_update_range) { 1625 if (should_update_range) {
1600 GetCompositionRange(&range); 1626 GetCompositionRange(&range);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 // ime event. 1819 // ime event.
1794 UpdateSelectionBounds(); 1820 UpdateSelectionBounds();
1795 #if defined(OS_ANDROID) 1821 #if defined(OS_ANDROID)
1796 UpdateTextInputState( 1822 UpdateTextInputState(
1797 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, 1823 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1798 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); 1824 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
1799 #endif 1825 #endif
1800 } 1826 }
1801 1827
1802 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { 1828 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1829 #if defined(ENABLE_PLUGINS)
1830 if (focused_pepper_plugin_) {
1831 // TODO(kinaba) http://crbug.com/101101
1832 // Current Pepper IME API does not handle selection bounds. So we simply
1833 // use the caret position as an empty range for now. It will be updated
1834 // after Pepper API equips features related to surrounding text retrieval.
1835 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1836 convertViewportToWindow(&caret);
1837 *focus = caret;
1838 *anchor = caret;
1839 return;
1840 }
1841 #endif
1803 WebRect focus_webrect; 1842 WebRect focus_webrect;
1804 WebRect anchor_webrect; 1843 WebRect anchor_webrect;
1805 webwidget_->selectionBounds(focus_webrect, anchor_webrect); 1844 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1806 convertViewportToWindow(&focus_webrect); 1845 convertViewportToWindow(&focus_webrect);
1807 convertViewportToWindow(&anchor_webrect); 1846 convertViewportToWindow(&anchor_webrect);
1808 *focus = focus_webrect; 1847 *focus = focus_webrect;
1809 *anchor = anchor_webrect; 1848 *anchor = anchor_webrect;
1810 } 1849 }
1811 1850
1812 void RenderWidget::UpdateSelectionBounds() { 1851 void RenderWidget::UpdateSelectionBounds() {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 // Check the type is in the range representable by ui::TextInputType. 1926 // Check the type is in the range representable by ui::TextInputType.
1888 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) << 1927 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
1889 "blink::WebTextInputType and ui::TextInputType not synchronized"; 1928 "blink::WebTextInputType and ui::TextInputType not synchronized";
1890 return static_cast<ui::TextInputType>(type); 1929 return static_cast<ui::TextInputType>(type);
1891 } 1930 }
1892 1931
1893 void RenderWidget::GetCompositionCharacterBounds( 1932 void RenderWidget::GetCompositionCharacterBounds(
1894 std::vector<gfx::Rect>* bounds) { 1933 std::vector<gfx::Rect>* bounds) {
1895 DCHECK(bounds); 1934 DCHECK(bounds);
1896 bounds->clear(); 1935 bounds->clear();
1936
1937 #if defined(ENABLE_PLUGINS)
1938 if (focused_pepper_plugin_)
1939 return;
1940 #endif
1941
1942 if (!webwidget_)
1943 return;
1944 blink::WebVector<blink::WebRect> bounds_from_blink;
1945 if (!webwidget_->getCompositionCharacterBounds(bounds_from_blink))
1946 return;
1947
1948 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
1949 convertViewportToWindow(&bounds_from_blink[i]);
1950 bounds->push_back(bounds_from_blink[i]);
1951 }
1897 } 1952 }
1898 1953
1899 void RenderWidget::GetCompositionRange(gfx::Range* range) { 1954 void RenderWidget::GetCompositionRange(gfx::Range* range) {
1955 #if defined(ENABLE_PLUGINS)
1956 if (focused_pepper_plugin_)
1957 return;
1958 #endif
1900 size_t location, length; 1959 size_t location, length;
1901 if (webwidget_->compositionRange(&location, &length)) { 1960 if (webwidget_->compositionRange(&location, &length)) {
1902 range->set_start(location); 1961 range->set_start(location);
1903 range->set_end(location + length); 1962 range->set_end(location + length);
1904 } else if (webwidget_->caretOrSelectionRange(&location, &length)) { 1963 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1905 range->set_start(location); 1964 range->set_start(location);
1906 range->set_end(location + length); 1965 range->set_end(location + length);
1907 } else { 1966 } else {
1908 *range = gfx::Range::InvalidRange(); 1967 *range = gfx::Range::InvalidRange();
1909 } 1968 }
1910 } 1969 }
1911 1970
1912 bool RenderWidget::ShouldUpdateCompositionInfo( 1971 bool RenderWidget::ShouldUpdateCompositionInfo(
1913 const gfx::Range& range, 1972 const gfx::Range& range,
1914 const std::vector<gfx::Rect>& bounds) { 1973 const std::vector<gfx::Rect>& bounds) {
1915 if (composition_range_ != range) 1974 if (composition_range_ != range)
1916 return true; 1975 return true;
1917 if (bounds.size() != composition_character_bounds_.size()) 1976 if (bounds.size() != composition_character_bounds_.size())
1918 return true; 1977 return true;
1919 for (size_t i = 0; i < bounds.size(); ++i) { 1978 for (size_t i = 0; i < bounds.size(); ++i) {
1920 if (bounds[i] != composition_character_bounds_[i]) 1979 if (bounds[i] != composition_character_bounds_[i])
1921 return true; 1980 return true;
1922 } 1981 }
1923 return false; 1982 return false;
1924 } 1983 }
1925 1984
1926 bool RenderWidget::CanComposeInline() { 1985 bool RenderWidget::CanComposeInline() {
1986 #if defined(ENABLE_PLUGINS)
1987 if (focused_pepper_plugin_)
1988 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
1989 #endif
1927 return true; 1990 return true;
1928 } 1991 }
1929 1992
1930 WebScreenInfo RenderWidget::screenInfo() { 1993 WebScreenInfo RenderWidget::screenInfo() {
1931 return screen_info_; 1994 return screen_info_;
1932 } 1995 }
1933 1996
1934 void RenderWidget::resetInputMethod() { 1997 void RenderWidget::resetInputMethod() {
1935 ImeEventGuard guard(this); 1998 ImeEventGuard guard(this);
1936 // If the last text input type is not None, then we should finish any 1999 // 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
2090 } 2153 }
2091 2154
2092 float RenderWidget::GetOriginalDeviceScaleFactor() const { 2155 float RenderWidget::GetOriginalDeviceScaleFactor() const {
2093 return 2156 return
2094 screen_metrics_emulator_ ? 2157 screen_metrics_emulator_ ?
2095 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : 2158 screen_metrics_emulator_->original_screen_info().deviceScaleFactor :
2096 device_scale_factor_; 2159 device_scale_factor_;
2097 } 2160 }
2098 2161
2099 } // namespace content 2162 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698