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

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

Issue 671503005: Plumb composition character bounds for Android 5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 1 month 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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #include "ui/gfx/frame_time.h" 70 #include "ui/gfx/frame_time.h"
71 #include "ui/gfx/point_conversions.h" 71 #include "ui/gfx/point_conversions.h"
72 #include "ui/gfx/rect_conversions.h" 72 #include "ui/gfx/rect_conversions.h"
73 #include "ui/gfx/size_conversions.h" 73 #include "ui/gfx/size_conversions.h"
74 #include "ui/gfx/skia_util.h" 74 #include "ui/gfx/skia_util.h"
75 #include "ui/gl/gl_switches.h" 75 #include "ui/gl/gl_switches.h"
76 #include "ui/surface/transport_dib.h" 76 #include "ui/surface/transport_dib.h"
77 77
78 #if defined(OS_ANDROID) 78 #if defined(OS_ANDROID)
79 #include <android/keycodes.h> 79 #include <android/keycodes.h>
80 #include "base/android/build_info.h"
80 #include "content/renderer/android/synchronous_compositor_factory.h" 81 #include "content/renderer/android/synchronous_compositor_factory.h"
81 #endif 82 #endif
82 83
83 #if defined(OS_POSIX) 84 #if defined(OS_POSIX)
84 #include "ipc/ipc_channel_posix.h" 85 #include "ipc/ipc_channel_posix.h"
85 #include "third_party/skia/include/core/SkMallocPixelRef.h" 86 #include "third_party/skia/include/core/SkMallocPixelRef.h"
86 #include "third_party/skia/include/core/SkPixelRef.h" 87 #include "third_party/skia/include/core/SkPixelRef.h"
87 #endif // defined(OS_POSIX) 88 #endif // defined(OS_POSIX)
88 89
89 #include "third_party/WebKit/public/web/WebWidget.h" 90 #include "third_party/WebKit/public/web/WebWidget.h"
(...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 return; 1536 return;
1536 ImeEventGuard guard(this); 1537 ImeEventGuard guard(this);
1537 if (!webwidget_->setComposition( 1538 if (!webwidget_->setComposition(
1538 text, WebVector<WebCompositionUnderline>(underlines), 1539 text, WebVector<WebCompositionUnderline>(underlines),
1539 selection_start, selection_end)) { 1540 selection_start, selection_end)) {
1540 // If we failed to set the composition text, then we need to let the browser 1541 // If we failed to set the composition text, then we need to let the browser
1541 // process to cancel the input method's ongoing composition session, to make 1542 // process to cancel the input method's ongoing composition session, to make
1542 // sure we are in a consistent state. 1543 // sure we are in a consistent state.
1543 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1544 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1544 } 1545 }
1545 #if defined(OS_MACOSX) || defined(USE_AURA) 1546 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID)
1546 UpdateCompositionInfo(true); 1547 UpdateCompositionInfo(true);
1547 #endif 1548 #endif
1548 } 1549 }
1549 1550
1550 void RenderWidget::OnImeConfirmComposition(const base::string16& text, 1551 void RenderWidget::OnImeConfirmComposition(const base::string16& text,
1551 const gfx::Range& replacement_range, 1552 const gfx::Range& replacement_range,
1552 bool keep_selection) { 1553 bool keep_selection) {
1553 if (!ShouldHandleImeEvent()) 1554 if (!ShouldHandleImeEvent())
1554 return; 1555 return;
1555 ImeEventGuard guard(this); 1556 ImeEventGuard guard(this);
1556 handling_input_event_ = true; 1557 handling_input_event_ = true;
1557 if (text.length()) 1558 if (text.length())
1558 webwidget_->confirmComposition(text); 1559 webwidget_->confirmComposition(text);
1559 else if (keep_selection) 1560 else if (keep_selection)
1560 webwidget_->confirmComposition(WebWidget::KeepSelection); 1561 webwidget_->confirmComposition(WebWidget::KeepSelection);
1561 else 1562 else
1562 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); 1563 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
1563 handling_input_event_ = false; 1564 handling_input_event_ = false;
1564 #if defined(OS_MACOSX) || defined(USE_AURA) 1565 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID)
1565 UpdateCompositionInfo(true); 1566 UpdateCompositionInfo(true);
1566 #endif 1567 #endif
1567 } 1568 }
1568 1569
1569 void RenderWidget::OnRepaint(gfx::Size size_to_paint) { 1570 void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
1570 // During shutdown we can just ignore this message. 1571 // During shutdown we can just ignore this message.
1571 if (!webwidget_) 1572 if (!webwidget_)
1572 return; 1573 return;
1573 1574
1574 // Even if the browser provides an empty damage rect, it's still expecting to 1575 // Even if the browser provides an empty damage rect, it's still expecting to
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 if (selection_anchor_rect_ != params.anchor_rect || 1887 if (selection_anchor_rect_ != params.anchor_rect ||
1887 selection_focus_rect_ != params.focus_rect) { 1888 selection_focus_rect_ != params.focus_rect) {
1888 selection_anchor_rect_ = params.anchor_rect; 1889 selection_anchor_rect_ = params.anchor_rect;
1889 selection_focus_rect_ = params.focus_rect; 1890 selection_focus_rect_ = params.focus_rect;
1890 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); 1891 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1891 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); 1892 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1892 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); 1893 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1893 } 1894 }
1894 } 1895 }
1895 1896
1896 #if defined(OS_MACOSX) || defined(USE_AURA) 1897 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID)
1897 UpdateCompositionInfo(false); 1898 UpdateCompositionInfo(false);
1898 #endif 1899 #endif
1899 } 1900 }
1900 1901
1901 // Check blink::WebTextInputType and ui::TextInputType is kept in sync. 1902 // Check blink::WebTextInputType and ui::TextInputType is kept in sync.
1902 COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \ 1903 COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \
1903 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums); 1904 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1904 COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \ 1905 COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \
1905 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums); 1906 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1906 COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \ 1907 COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 "blink::WebTextInputType and ui::TextInputType not synchronized"; 1942 "blink::WebTextInputType and ui::TextInputType not synchronized";
1942 return static_cast<ui::TextInputType>(type); 1943 return static_cast<ui::TextInputType>(type);
1943 } 1944 }
1944 1945
1945 ui::TextInputType RenderWidget::GetTextInputType() { 1946 ui::TextInputType RenderWidget::GetTextInputType() {
1946 if (webwidget_) 1947 if (webwidget_)
1947 return WebKitToUiTextInputType(webwidget_->textInputInfo().type); 1948 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
1948 return ui::TEXT_INPUT_TYPE_NONE; 1949 return ui::TEXT_INPUT_TYPE_NONE;
1949 } 1950 }
1950 1951
1951 #if defined(OS_MACOSX) || defined(USE_AURA) 1952 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID)
1952 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { 1953 void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
1954 #if defined(OS_ANDROID)
1955 // Sending composition info makes sense only in Lollipop (API level 21)
1956 // and above due to the API availability.
1957 if (base::android::BuildInfo::GetInstance()->sdk_int() < 21)
1958 return;
1959 #endif
1960
1953 gfx::Range range = gfx::Range(); 1961 gfx::Range range = gfx::Range();
1954 if (should_update_range) { 1962 if (should_update_range) {
1955 GetCompositionRange(&range); 1963 GetCompositionRange(&range);
1956 } else { 1964 } else {
1957 range = composition_range_; 1965 range = composition_range_;
1958 } 1966 }
1959 std::vector<gfx::Rect> character_bounds; 1967 std::vector<gfx::Rect> character_bounds;
1960 GetCompositionCharacterBounds(&character_bounds); 1968 GetCompositionCharacterBounds(&character_bounds);
1961 1969
1962 if (!ShouldUpdateCompositionInfo(range, character_bounds)) 1970 if (!ShouldUpdateCompositionInfo(range, character_bounds))
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 ImeEventGuard guard(this); 2042 ImeEventGuard guard(this);
2035 // If the last text input type is not None, then we should finish any 2043 // If the last text input type is not None, then we should finish any
2036 // ongoing composition regardless of the new text input type. 2044 // ongoing composition regardless of the new text input type.
2037 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 2045 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
2038 // If a composition text exists, then we need to let the browser process 2046 // If a composition text exists, then we need to let the browser process
2039 // to cancel the input method's ongoing composition session. 2047 // to cancel the input method's ongoing composition session.
2040 if (webwidget_->confirmComposition()) 2048 if (webwidget_->confirmComposition())
2041 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 2049 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
2042 } 2050 }
2043 2051
2044 #if defined(OS_MACOSX) || defined(USE_AURA) 2052 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID)
2045 UpdateCompositionInfo(true); 2053 UpdateCompositionInfo(true);
2046 #endif 2054 #endif
2047 } 2055 }
2048 2056
2049 void RenderWidget::didHandleGestureEvent( 2057 void RenderWidget::didHandleGestureEvent(
2050 const WebGestureEvent& event, 2058 const WebGestureEvent& event,
2051 bool event_cancelled) { 2059 bool event_cancelled) {
2052 #if defined(OS_ANDROID) || defined(USE_AURA) 2060 #if defined(OS_ANDROID) || defined(USE_AURA)
2053 if (event_cancelled) 2061 if (event_cancelled)
2054 return; 2062 return;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { 2254 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2247 video_hole_frames_.AddObserver(frame); 2255 video_hole_frames_.AddObserver(frame);
2248 } 2256 }
2249 2257
2250 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { 2258 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2251 video_hole_frames_.RemoveObserver(frame); 2259 video_hole_frames_.RemoveObserver(frame);
2252 } 2260 }
2253 #endif // defined(VIDEO_HOLE) 2261 #endif // defined(VIDEO_HOLE)
2254 2262
2255 } // namespace content 2263 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698