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

Side by Side Diff: chrome/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: Address comments Created 9 years, 10 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) 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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 // only during the input method attached to the browser process is active. 858 // only during the input method attached to the browser process is active.
856 input_method_is_active_ = is_active; 859 input_method_is_active_ = is_active;
857 } 860 }
858 861
859 void RenderWidget::OnImeSetComposition( 862 void RenderWidget::OnImeSetComposition(
860 const string16& text, 863 const string16& text,
861 const std::vector<WebCompositionUnderline>& underlines, 864 const std::vector<WebCompositionUnderline>& underlines,
862 int selection_start, int selection_end) { 865 int selection_start, int selection_end) {
863 if (!webwidget_) 866 if (!webwidget_)
864 return; 867 return;
865 if (!webwidget_->setComposition( 868 if (webwidget_->setComposition(
866 text, WebVector<WebCompositionUnderline>(underlines), 869 text, WebVector<WebCompositionUnderline>(underlines),
867 selection_start, selection_end)) { 870 selection_start, selection_end)) {
871 // Setting the IME composition was successful. Send the new composition
872 // range to the browser.
873 WebRange range = webwidget_->compositionRange();
874 if (range.isNull()) {
875 // The IME was cancelled via the Esc key, so just send back the caret.
876 range = webwidget_->caretOrSelectionRange();
877 }
878 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(),
879 range.startOffset(), range.endOffset()));
880 } else {
868 // If we failed to set the composition text, then we need to let the browser 881 // If we failed to set the composition text, then we need to let the browser
869 // process to cancel the input method's ongoing composition session, to make 882 // process to cancel the input method's ongoing composition session, to make
870 // sure we are in a consistent state. 883 // sure we are in a consistent state.
871 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); 884 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
885 // Send an updated IME range with just the caret range.
886 WebRange range = webwidget_->caretOrSelectionRange();
887 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(),
888 range.startOffset(), range.endOffset()));
872 } 889 }
873 } 890 }
874 891
875 void RenderWidget::OnImeConfirmComposition(const string16& text) { 892 void RenderWidget::OnImeConfirmComposition(const string16& text) {
876 if (webwidget_) 893 if (webwidget_)
877 webwidget_->confirmComposition(text); 894 webwidget_->confirmComposition(text);
895 // Send an updated IME range with just the caret range.
896 WebRange range = webwidget_->caretOrSelectionRange();
897 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(),
898 range.startOffset(), range.endOffset()));
878 } 899 }
879 900
880 // This message causes the renderer to render an image of the 901 // This message causes the renderer to render an image of the
881 // desired_size, regardless of whether the tab is hidden or not. 902 // desired_size, regardless of whether the tab is hidden or not.
882 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, 903 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
883 int tag, 904 int tag,
884 const gfx::Size& page_size, 905 const gfx::Size& page_size,
885 const gfx::Size& desired_size) { 906 const gfx::Size& desired_size) {
886 if (!webwidget_ || !TransportDIB::is_valid(dib_handle)) { 907 if (!webwidget_ || !TransportDIB::is_valid(dib_handle)) {
887 if (TransportDIB::is_valid(dib_handle)) { 908 if (TransportDIB::is_valid(dib_handle)) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 return; 1080 return;
1060 1081
1061 // If the last text input type is not None, then we should finish any 1082 // If the last text input type is not None, then we should finish any
1062 // ongoing composition regardless of the new text input type. 1083 // ongoing composition regardless of the new text input type.
1063 if (text_input_type_ != WebKit::WebTextInputTypeNone) { 1084 if (text_input_type_ != WebKit::WebTextInputTypeNone) {
1064 // If a composition text exists, then we need to let the browser process 1085 // If a composition text exists, then we need to let the browser process
1065 // to cancel the input method's ongoing composition session. 1086 // to cancel the input method's ongoing composition session.
1066 if (webwidget_->confirmComposition()) 1087 if (webwidget_->confirmComposition())
1067 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); 1088 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1068 } 1089 }
1090
1091 // Send an updated IME range with the current caret rect.
1092 WebRange range = webwidget_->caretOrSelectionRange();
1093 if (!range.isNull()) {
1094 Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(),
1095 range.startOffset(), range.endOffset()));
1096 }
1069 } 1097 }
1070 1098
1071 void RenderWidget::SchedulePluginMove( 1099 void RenderWidget::SchedulePluginMove(
1072 const webkit::npapi::WebPluginGeometry& move) { 1100 const webkit::npapi::WebPluginGeometry& move) {
1073 size_t i = 0; 1101 size_t i = 0;
1074 for (; i < plugin_window_moves_.size(); ++i) { 1102 for (; i < plugin_window_moves_.size(); ++i) {
1075 if (plugin_window_moves_[i].window == move.window) { 1103 if (plugin_window_moves_[i].window == move.window) {
1076 if (move.rects_valid) { 1104 if (move.rects_valid) {
1077 plugin_window_moves_[i] = move; 1105 plugin_window_moves_[i] = move;
1078 } else { 1106 } else {
1079 plugin_window_moves_[i].visible = move.visible; 1107 plugin_window_moves_[i].visible = move.visible;
1080 } 1108 }
1081 break; 1109 break;
1082 } 1110 }
1083 } 1111 }
1084 1112
1085 if (i == plugin_window_moves_.size()) 1113 if (i == plugin_window_moves_.size())
1086 plugin_window_moves_.push_back(move); 1114 plugin_window_moves_.push_back(move);
1087 } 1115 }
1088 1116
1089 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { 1117 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1090 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); 1118 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1091 i != plugin_window_moves_.end(); ++i) { 1119 i != plugin_window_moves_.end(); ++i) {
1092 if (i->window == window) { 1120 if (i->window == window) {
1093 plugin_window_moves_.erase(i); 1121 plugin_window_moves_.erase(i);
1094 break; 1122 break;
1095 } 1123 }
1096 } 1124 }
1097 } 1125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698