OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/renderer/render_widget.h" | 5 #include "chrome/renderer/render_widget.h" |
6 | 6 |
7 #include "app/surface/transport_dib.h" | 7 #include "app/surface/transport_dib.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
16 #include "chrome/common/render_messages_params.h" | 16 #include "chrome/common/render_messages_params.h" |
| 17 #include "chrome/common/text_input_client_messages.h" |
17 #include "chrome/renderer/render_process.h" | 18 #include "chrome/renderer/render_process.h" |
18 #include "chrome/renderer/render_thread.h" | 19 #include "chrome/renderer/render_thread.h" |
19 #include "chrome/renderer/renderer_webkitclient_impl.h" | 20 #include "chrome/renderer/renderer_webkitclient_impl.h" |
20 #include "ipc/ipc_sync_message.h" | 21 #include "ipc/ipc_sync_message.h" |
21 #include "skia/ext/platform_canvas.h" | 22 #include "skia/ext/platform_canvas.h" |
22 #include "third_party/skia/include/core/SkShader.h" | 23 #include "third_party/skia/include/core/SkShader.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
29 #include "ui/gfx/point.h" | 31 #include "ui/gfx/point.h" |
30 #include "ui/gfx/size.h" | 32 #include "ui/gfx/size.h" |
31 #include "webkit/glue/webkit_glue.h" | 33 #include "webkit/glue/webkit_glue.h" |
32 #include "webkit/plugins/npapi/webplugin.h" | 34 #include "webkit/plugins/npapi/webplugin.h" |
33 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 35 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
34 | 36 |
35 #if defined(OS_POSIX) | 37 #if defined(OS_POSIX) |
36 #include "ipc/ipc_channel_posix.h" | 38 #include "ipc/ipc_channel_posix.h" |
37 #include "third_party/skia/include/core/SkPixelRef.h" | 39 #include "third_party/skia/include/core/SkPixelRef.h" |
38 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 40 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
39 #endif // defined(OS_POSIX) | 41 #endif // defined(OS_POSIX) |
40 | 42 |
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" | 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" |
42 | 44 |
43 using WebKit::WebCompositionUnderline; | 45 using WebKit::WebCompositionUnderline; |
44 using WebKit::WebCursorInfo; | 46 using WebKit::WebCursorInfo; |
45 using WebKit::WebInputEvent; | 47 using WebKit::WebInputEvent; |
46 using WebKit::WebMouseEvent; | 48 using WebKit::WebMouseEvent; |
47 using WebKit::WebNavigationPolicy; | 49 using WebKit::WebNavigationPolicy; |
48 using WebKit::WebPopupMenu; | 50 using WebKit::WebPopupMenu; |
49 using WebKit::WebPopupMenuInfo; | 51 using WebKit::WebPopupMenuInfo; |
50 using WebKit::WebPopupType; | 52 using WebKit::WebPopupType; |
| 53 using WebKit::WebRange; |
51 using WebKit::WebRect; | 54 using WebKit::WebRect; |
52 using WebKit::WebScreenInfo; | 55 using WebKit::WebScreenInfo; |
53 using WebKit::WebSize; | 56 using WebKit::WebSize; |
54 using WebKit::WebTextDirection; | 57 using WebKit::WebTextDirection; |
55 using WebKit::WebTextInputType; | 58 using WebKit::WebTextInputType; |
56 using WebKit::WebVector; | 59 using WebKit::WebVector; |
57 using WebKit::WebWidget; | 60 using WebKit::WebWidget; |
58 | 61 |
59 RenderWidget::RenderWidget(RenderThreadBase* render_thread, | 62 RenderWidget::RenderWidget(RenderThreadBase* render_thread, |
60 WebKit::WebPopupType popup_type) | 63 WebKit::WebPopupType popup_type) |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 // only during the input method attached to the browser process is active. | 871 // only during the input method attached to the browser process is active. |
869 input_method_is_active_ = is_active; | 872 input_method_is_active_ = is_active; |
870 } | 873 } |
871 | 874 |
872 void RenderWidget::OnImeSetComposition( | 875 void RenderWidget::OnImeSetComposition( |
873 const string16& text, | 876 const string16& text, |
874 const std::vector<WebCompositionUnderline>& underlines, | 877 const std::vector<WebCompositionUnderline>& underlines, |
875 int selection_start, int selection_end) { | 878 int selection_start, int selection_end) { |
876 if (!webwidget_) | 879 if (!webwidget_) |
877 return; | 880 return; |
878 if (!webwidget_->setComposition( | 881 if (webwidget_->setComposition( |
879 text, WebVector<WebCompositionUnderline>(underlines), | 882 text, WebVector<WebCompositionUnderline>(underlines), |
880 selection_start, selection_end)) { | 883 selection_start, selection_end)) { |
| 884 // Setting the IME composition was successful. Send the new composition |
| 885 // range to the browser. |
| 886 WebRange range = webwidget_->compositionRange(); |
| 887 if (range.isNull()) { |
| 888 // The IME was cancelled via the Esc key, so just send back the caret. |
| 889 range = webwidget_->caretOrSelectionRange(); |
| 890 } |
| 891 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(), |
| 892 range.startOffset(), range.endOffset())); |
| 893 } else { |
881 // If we failed to set the composition text, then we need to let the browser | 894 // If we failed to set the composition text, then we need to let the browser |
882 // process to cancel the input method's ongoing composition session, to make | 895 // process to cancel the input method's ongoing composition session, to make |
883 // sure we are in a consistent state. | 896 // sure we are in a consistent state. |
884 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); | 897 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 898 // Send an updated IME range with just the caret range. |
| 899 WebRange range = webwidget_->caretOrSelectionRange(); |
| 900 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(), |
| 901 range.startOffset(), range.endOffset())); |
885 } | 902 } |
886 } | 903 } |
887 | 904 |
888 void RenderWidget::OnImeConfirmComposition(const string16& text) { | 905 void RenderWidget::OnImeConfirmComposition(const string16& text) { |
889 if (webwidget_) | 906 if (webwidget_) |
890 webwidget_->confirmComposition(text); | 907 webwidget_->confirmComposition(text); |
| 908 // Send an updated IME range with just the caret range. |
| 909 WebRange range = webwidget_->caretOrSelectionRange(); |
| 910 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(), |
| 911 range.startOffset(), range.endOffset())); |
891 } | 912 } |
892 | 913 |
893 // This message causes the renderer to render an image of the | 914 // This message causes the renderer to render an image of the |
894 // desired_size, regardless of whether the tab is hidden or not. | 915 // desired_size, regardless of whether the tab is hidden or not. |
895 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, | 916 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, |
896 int tag, | 917 int tag, |
897 const gfx::Size& page_size, | 918 const gfx::Size& page_size, |
898 const gfx::Size& desired_size) { | 919 const gfx::Size& desired_size) { |
899 if (!webwidget_ || !TransportDIB::is_valid(dib_handle)) { | 920 if (!webwidget_ || !TransportDIB::is_valid(dib_handle)) { |
900 if (TransportDIB::is_valid(dib_handle)) { | 921 if (TransportDIB::is_valid(dib_handle)) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 return; | 1093 return; |
1073 | 1094 |
1074 // If the last text input type is not None, then we should finish any | 1095 // If the last text input type is not None, then we should finish any |
1075 // ongoing composition regardless of the new text input type. | 1096 // ongoing composition regardless of the new text input type. |
1076 if (text_input_type_ != WebKit::WebTextInputTypeNone) { | 1097 if (text_input_type_ != WebKit::WebTextInputTypeNone) { |
1077 // If a composition text exists, then we need to let the browser process | 1098 // If a composition text exists, then we need to let the browser process |
1078 // to cancel the input method's ongoing composition session. | 1099 // to cancel the input method's ongoing composition session. |
1079 if (webwidget_->confirmComposition()) | 1100 if (webwidget_->confirmComposition()) |
1080 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); | 1101 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
1081 } | 1102 } |
| 1103 |
| 1104 // Send an updated IME range with the current caret rect. |
| 1105 WebRange range = webwidget_->caretOrSelectionRange(); |
| 1106 if (!range.isNull()) { |
| 1107 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(), |
| 1108 range.startOffset(), range.endOffset())); |
| 1109 } |
1082 } | 1110 } |
1083 | 1111 |
1084 void RenderWidget::SchedulePluginMove( | 1112 void RenderWidget::SchedulePluginMove( |
1085 const webkit::npapi::WebPluginGeometry& move) { | 1113 const webkit::npapi::WebPluginGeometry& move) { |
1086 size_t i = 0; | 1114 size_t i = 0; |
1087 for (; i < plugin_window_moves_.size(); ++i) { | 1115 for (; i < plugin_window_moves_.size(); ++i) { |
1088 if (plugin_window_moves_[i].window == move.window) { | 1116 if (plugin_window_moves_[i].window == move.window) { |
1089 if (move.rects_valid) { | 1117 if (move.rects_valid) { |
1090 plugin_window_moves_[i] = move; | 1118 plugin_window_moves_[i] = move; |
1091 } else { | 1119 } else { |
1092 plugin_window_moves_[i].visible = move.visible; | 1120 plugin_window_moves_[i].visible = move.visible; |
1093 } | 1121 } |
1094 break; | 1122 break; |
1095 } | 1123 } |
1096 } | 1124 } |
1097 | 1125 |
1098 if (i == plugin_window_moves_.size()) | 1126 if (i == plugin_window_moves_.size()) |
1099 plugin_window_moves_.push_back(move); | 1127 plugin_window_moves_.push_back(move); |
1100 } | 1128 } |
1101 | 1129 |
1102 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { | 1130 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
1103 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); | 1131 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
1104 i != plugin_window_moves_.end(); ++i) { | 1132 i != plugin_window_moves_.end(); ++i) { |
1105 if (i->window == window) { | 1133 if (i->window == window) { |
1106 plugin_window_moves_.erase(i); | 1134 plugin_window_moves_.erase(i); |
1107 break; | 1135 break; |
1108 } | 1136 } |
1109 } | 1137 } |
1110 } | 1138 } |
OLD | NEW |