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

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

Issue 6289009: [Mac] Implement the system dictionary popup by implementing NSTextInput methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Create AttributedStringCoder Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.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 "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/render_messages.h" 14 #include "chrome/common/render_messages.h"
15 #include "chrome/common/text_input_client_messages.h"
15 #include "chrome/renderer/render_process.h" 16 #include "chrome/renderer/render_process.h"
16 #include "chrome/renderer/render_thread.h" 17 #include "chrome/renderer/render_thread.h"
17 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
18 #include "content/renderer/renderer_webkitclient_impl.h" 19 #include "content/renderer/renderer_webkitclient_impl.h"
19 #include "gpu/common/gpu_trace_event.h" 20 #include "gpu/common/gpu_trace_event.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 "ui/gfx/surface/transport_dib.h" 33 #include "ui/gfx/surface/transport_dib.h"
32 #include "webkit/glue/webkit_glue.h" 34 #include "webkit/glue/webkit_glue.h"
33 #include "webkit/plugins/npapi/webplugin.h" 35 #include "webkit/plugins/npapi/webplugin.h"
34 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 36 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
35 37
36 #if defined(OS_POSIX) 38 #if defined(OS_POSIX)
37 #include "ipc/ipc_channel_posix.h" 39 #include "ipc/ipc_channel_posix.h"
38 #include "third_party/skia/include/core/SkPixelRef.h" 40 #include "third_party/skia/include/core/SkPixelRef.h"
39 #include "third_party/skia/include/core/SkMallocPixelRef.h" 41 #include "third_party/skia/include/core/SkMallocPixelRef.h"
40 #endif // defined(OS_POSIX) 42 #endif // defined(OS_POSIX)
41 43
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
43 45
44 using WebKit::WebCompositionUnderline; 46 using WebKit::WebCompositionUnderline;
45 using WebKit::WebCursorInfo; 47 using WebKit::WebCursorInfo;
46 using WebKit::WebInputEvent; 48 using WebKit::WebInputEvent;
47 using WebKit::WebMouseEvent; 49 using WebKit::WebMouseEvent;
48 using WebKit::WebNavigationPolicy; 50 using WebKit::WebNavigationPolicy;
49 using WebKit::WebPopupMenu; 51 using WebKit::WebPopupMenu;
50 using WebKit::WebPopupMenuInfo; 52 using WebKit::WebPopupMenuInfo;
51 using WebKit::WebPopupType; 53 using WebKit::WebPopupType;
54 using WebKit::WebRange;
52 using WebKit::WebRect; 55 using WebKit::WebRect;
53 using WebKit::WebScreenInfo; 56 using WebKit::WebScreenInfo;
54 using WebKit::WebSize; 57 using WebKit::WebSize;
55 using WebKit::WebTextDirection; 58 using WebKit::WebTextDirection;
56 using WebKit::WebTextInputType; 59 using WebKit::WebTextInputType;
57 using WebKit::WebVector; 60 using WebKit::WebVector;
58 using WebKit::WebWidget; 61 using WebKit::WebWidget;
59 62
60 RenderWidget::RenderWidget(RenderThreadBase* render_thread, 63 RenderWidget::RenderWidget(RenderThreadBase* render_thread,
61 WebKit::WebPopupType popup_type) 64 WebKit::WebPopupType popup_type)
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 // only during the input method attached to the browser process is active. 879 // only during the input method attached to the browser process is active.
877 input_method_is_active_ = is_active; 880 input_method_is_active_ = is_active;
878 } 881 }
879 882
880 void RenderWidget::OnImeSetComposition( 883 void RenderWidget::OnImeSetComposition(
881 const string16& text, 884 const string16& text,
882 const std::vector<WebCompositionUnderline>& underlines, 885 const std::vector<WebCompositionUnderline>& underlines,
883 int selection_start, int selection_end) { 886 int selection_start, int selection_end) {
884 if (!webwidget_) 887 if (!webwidget_)
885 return; 888 return;
886 if (!webwidget_->setComposition( 889 if (webwidget_->setComposition(
887 text, WebVector<WebCompositionUnderline>(underlines), 890 text, WebVector<WebCompositionUnderline>(underlines),
888 selection_start, selection_end)) { 891 selection_start, selection_end)) {
892 // Setting the IME composition was successful. Send the new composition
893 // range to the browser.
894 ui::Range range(ui::Range::InvalidRange());
895 size_t location, length;
896 if (webwidget_->compositionRange(&location, &length)) {
897 range.set_start(location);
898 range.set_end(location + length);
899 }
900 // The IME was cancelled via the Esc key, so just send back the caret.
901 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
902 range.set_start(location);
903 range.set_end(location + length);
904 }
905 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(),
906 range));
907 } else {
889 // If we failed to set the composition text, then we need to let the browser 908 // If we failed to set the composition text, then we need to let the browser
890 // process to cancel the input method's ongoing composition session, to make 909 // process to cancel the input method's ongoing composition session, to make
891 // sure we are in a consistent state. 910 // sure we are in a consistent state.
892 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); 911 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
912
913 // Send an updated IME range with just the caret range.
914 ui::Range range(ui::Range::InvalidRange());
915 size_t location, length;
916 if (webwidget_->caretOrSelectionRange(&location, &length)) {
917 range.set_start(location);
918 range.set_end(location + length);
919 }
920 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(),
921 range));
893 } 922 }
894 } 923 }
895 924
896 void RenderWidget::OnImeConfirmComposition(const string16& text) { 925 void RenderWidget::OnImeConfirmComposition(const string16& text) {
897 if (webwidget_) 926 if (webwidget_)
898 webwidget_->confirmComposition(text); 927 webwidget_->confirmComposition(text);
928 // Send an updated IME range with just the caret range.
929 ui::Range range(ui::Range::InvalidRange());
930 size_t location, length;
931 if (webwidget_->caretOrSelectionRange(&location, &length)) {
932 range.set_start(location);
933 range.set_end(location + length);
934 }
935 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(),
936 range));
899 } 937 }
900 938
901 // This message causes the renderer to render an image of the 939 // This message causes the renderer to render an image of the
902 // desired_size, regardless of whether the tab is hidden or not. 940 // desired_size, regardless of whether the tab is hidden or not.
903 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, 941 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
904 int tag, 942 int tag,
905 const gfx::Size& page_size, 943 const gfx::Size& page_size,
906 const gfx::Size& desired_size) { 944 const gfx::Size& desired_size) {
907 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) { 945 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
908 if (TransportDIB::is_valid_handle(dib_handle)) { 946 if (TransportDIB::is_valid_handle(dib_handle)) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 return; 1118 return;
1081 1119
1082 // If the last text input type is not None, then we should finish any 1120 // If the last text input type is not None, then we should finish any
1083 // ongoing composition regardless of the new text input type. 1121 // ongoing composition regardless of the new text input type.
1084 if (text_input_type_ != WebKit::WebTextInputTypeNone) { 1122 if (text_input_type_ != WebKit::WebTextInputTypeNone) {
1085 // If a composition text exists, then we need to let the browser process 1123 // If a composition text exists, then we need to let the browser process
1086 // to cancel the input method's ongoing composition session. 1124 // to cancel the input method's ongoing composition session.
1087 if (webwidget_->confirmComposition()) 1125 if (webwidget_->confirmComposition())
1088 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); 1126 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1089 } 1127 }
1128
1129 // Send an updated IME range with the current caret rect.
1130 ui::Range range(ui::Range::InvalidRange());
1131 size_t location, length;
1132 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1133 range.set_start(location);
1134 range.set_end(location + length);
1135 }
1136 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(),
1137 range));
1090 } 1138 }
1091 1139
1092 void RenderWidget::SchedulePluginMove( 1140 void RenderWidget::SchedulePluginMove(
1093 const webkit::npapi::WebPluginGeometry& move) { 1141 const webkit::npapi::WebPluginGeometry& move) {
1094 size_t i = 0; 1142 size_t i = 0;
1095 for (; i < plugin_window_moves_.size(); ++i) { 1143 for (; i < plugin_window_moves_.size(); ++i) {
1096 if (plugin_window_moves_[i].window == move.window) { 1144 if (plugin_window_moves_[i].window == move.window) {
1097 if (move.rects_valid) { 1145 if (move.rects_valid) {
1098 plugin_window_moves_[i] = move; 1146 plugin_window_moves_[i] = move;
1099 } else { 1147 } else {
1100 plugin_window_moves_[i].visible = move.visible; 1148 plugin_window_moves_[i].visible = move.visible;
1101 } 1149 }
1102 break; 1150 break;
1103 } 1151 }
1104 } 1152 }
1105 1153
1106 if (i == plugin_window_moves_.size()) 1154 if (i == plugin_window_moves_.size())
1107 plugin_window_moves_.push_back(move); 1155 plugin_window_moves_.push_back(move);
1108 } 1156 }
1109 1157
1110 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { 1158 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1111 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); 1159 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1112 i != plugin_window_moves_.end(); ++i) { 1160 i != plugin_window_moves_.end(); ++i) {
1113 if (i->window == window) { 1161 if (i->window == window) {
1114 plugin_window_moves_.erase(i); 1162 plugin_window_moves_.erase(i);
1115 break; 1163 break;
1116 } 1164 }
1117 } 1165 }
1118 } 1166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698