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

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_mac.h

Issue 1908006: [Mac]Refactor input method related code. (Closed)
Patch Set: Update CL according to review feedback. Created 10 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/renderer_host/render_widget_host_view_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_ 5 #ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_
6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_ 6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #import <QuartzCore/CALayer.h> 9 #import <QuartzCore/CALayer.h>
10 10
(...skipping 27 matching lines...) Expand all
38 BOOL canBeKeyView_; 38 BOOL canBeKeyView_;
39 BOOL closeOnDeactivate_; 39 BOOL closeOnDeactivate_;
40 scoped_ptr<RWHVMEditCommandHelper> editCommand_helper_; 40 scoped_ptr<RWHVMEditCommandHelper> editCommand_helper_;
41 41
42 // These are part of the magic tooltip code from WebKit's WebHTMLView: 42 // These are part of the magic tooltip code from WebKit's WebHTMLView:
43 id trackingRectOwner_; // (not retained) 43 id trackingRectOwner_; // (not retained)
44 void *trackingRectUserData_; 44 void *trackingRectUserData_;
45 NSTrackingRectTag lastToolTipTag_; 45 NSTrackingRectTag lastToolTipTag_;
46 scoped_nsobject<NSString> toolTip_; 46 scoped_nsobject<NSString> toolTip_;
47 47
48 // Set to YES if insertText: or insertNewline: get called.
49 BOOL textInserted_;
50
51 // Is YES if there was a mouse-down as yet unbalanced with a mouse-up. 48 // Is YES if there was a mouse-down as yet unbalanced with a mouse-up.
52 BOOL hasOpenMouseDown_; 49 BOOL hasOpenMouseDown_;
53 50
54 // Keep current key event when keyEvent: gets called. It's used in
55 // insertText: and insertNewline: to synthesize the corresponding Char event.
56 scoped_nsobject<NSEvent> currentKeyEvent_;
57 NSWindow* lastWindow_; // weak 51 NSWindow* lastWindow_; // weak
58 52
59 // The Core Animation layer, if any, hosting the accelerated plugins' output. 53 // The Core Animation layer, if any, hosting the accelerated plugins' output.
60 scoped_nsobject<CALayer> acceleratedPluginLayer_; 54 scoped_nsobject<CALayer> acceleratedPluginLayer_;
55
56 // Variables used by our implementaion of the NSTextInput protocol.
57 // An input method of Mac calls the methods of this protocol not only to
58 // notify an application of its status, but also to retrieve the status of
59 // the application. That is, an application cannot control an input method
60 // directly.
61 // This object keeps the status of a composition of the renderer and returns
62 // it when an input method asks for it.
63 // We need to implement Objective-C methods for the NSTextInput protocol. On
64 // the other hand, we need to implement a C++ method for an IPC-message
65 // handler which receives input-method events from the renderer.
66
67 // Represents the input-method attributes supported by this object.
68 scoped_nsobject<NSArray> validAttributesForMarkedText_;
69
70 // Represents the cursor position in this view coordinate.
71 // The renderer sends the cursor position through an IPC message.
72 // We save the latest cursor position here and return it when an input
73 // methods needs it.
74 NSRect caretRect_;
75
76 // Indicates if we are currently handling a key down event.
77 BOOL handlingKeyDown_;
78
79 // Indicates if there is any marked text.
80 BOOL hasMarkedText_;
81
82 // The range of current marked text inside the whole content of the DOM node
83 // being edited.
84 // TODO(suzhe): This is currently a fake value, as we do not support accessing
85 // the whole content yet.
86 NSRange markedRange_;
87
88 // The selected range inside current marked text.
89 // TODO(suzhe): Currently it's only valid when there is any marked text.
90 // In the future, we may need to support accessing the whole content of the
91 // DOM node being edited, then this should be the selected range inside the
92 // DOM node.
93 NSRange selectedRange_;
94
95 // Text to be inserted which was generated by handling a key down event.
96 string16 textToBeInserted_;
97
98 // New marked text which was generated by handling a key down event.
99 string16 newMarkedText_;
61 } 100 }
62 101
102 @property(assign, nonatomic) NSRect caretRect;
103
63 - (void)setCanBeKeyView:(BOOL)can; 104 - (void)setCanBeKeyView:(BOOL)can;
64 - (void)setCloseOnDeactivate:(BOOL)b; 105 - (void)setCloseOnDeactivate:(BOOL)b;
65 - (void)setToolTipAtMousePoint:(NSString *)string; 106 - (void)setToolTipAtMousePoint:(NSString *)string;
66 // Makes sure that the initial layer setup for accelerated plugin drawing has 107 // Makes sure that the initial layer setup for accelerated plugin drawing has
67 // been done. Can be called multiple times. 108 // been done. Can be called multiple times.
68 - (void)ensureAcceleratedPluginLayer; 109 - (void)ensureAcceleratedPluginLayer;
69 // Triggers a refresh of the accelerated plugin layer; should be called whenever 110 // Triggers a refresh of the accelerated plugin layer; should be called whenever
70 // the shared surface for one of the plugins is updated. 111 // the shared surface for one of the plugins is updated.
71 - (void)drawAcceleratedPluginLayer; 112 - (void)drawAcceleratedPluginLayer;
72 // Set frame, then notify the RenderWidgetHost that the frame has been changed, 113 // Set frame, then notify the RenderWidgetHost that the frame has been changed,
73 // but do it in a separate task, using |performSelector:withObject:afterDelay:|. 114 // but do it in a separate task, using |performSelector:withObject:afterDelay:|.
74 // This stops the flickering issue in http://crbug.com/31970 115 // This stops the flickering issue in http://crbug.com/31970
75 - (void)setFrameWithDeferredUpdate:(NSRect)frame; 116 - (void)setFrameWithDeferredUpdate:(NSRect)frame;
76 // Notify the RenderWidgetHost that the frame was updated so it can resize 117 // Notify the RenderWidgetHost that the frame was updated so it can resize
77 // its contents. 118 // its contents.
78 - (void)renderWidgetHostWasResized; 119 - (void)renderWidgetHostWasResized;
120 // Cancel ongoing composition (abandon the marked text).
121 - (void)cancelComposition;
79 122
80 @end 123 @end
81 124
82 /////////////////////////////////////////////////////////////////////////////// 125 ///////////////////////////////////////////////////////////////////////////////
83 // RenderWidgetHostViewMac 126 // RenderWidgetHostViewMac
84 // 127 //
85 // An object representing the "View" of a rendered web page. This object is 128 // An object representing the "View" of a rendered web page. This object is
86 // responsible for displaying the content of the web page, and integrating with 129 // responsible for displaying the content of the web page, and integrating with
87 // the Cocoa view system. It is the implementation of the RenderWidgetHostView 130 // the Cocoa view system. It is the implementation of the RenderWidgetHostView
88 // that the cross-platform RenderWidgetHost object uses 131 // that the cross-platform RenderWidgetHost object uses
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 virtual void DrawAcceleratedSurfaceInstances(CGLContextObj context); 205 virtual void DrawAcceleratedSurfaceInstances(CGLContextObj context);
163 // Informs the plug-in instances that their drawing context has changed. 206 // Informs the plug-in instances that their drawing context has changed.
164 virtual void AcceleratedSurfaceContextChanged(); 207 virtual void AcceleratedSurfaceContextChanged();
165 208
166 virtual void SetVisuallyDeemphasized(bool deemphasized); 209 virtual void SetVisuallyDeemphasized(bool deemphasized);
167 210
168 void KillSelf(); 211 void KillSelf();
169 212
170 void set_parent_view(BaseView* parent_view) { parent_view_ = parent_view; } 213 void set_parent_view(BaseView* parent_view) { parent_view_ = parent_view; }
171 214
172 // Cancels the ongoing composition and cleans up all input-method resources.
173 // This function dispatches a cancelation request from a renderer to
174 // NSInputManager to synchronize the input-method status with it.
175 void IMECleanupComposition();
176
177 // These member variables should be private, but the associated ObjC class 215 // These member variables should be private, but the associated ObjC class
178 // needs access to them and can't be made a friend. 216 // needs access to them and can't be made a friend.
179 217
180 // The associated Model. Can be NULL if Destroy() is called when 218 // The associated Model. Can be NULL if Destroy() is called when
181 // someone (other than superview) has retained |cocoa_view_|. 219 // someone (other than superview) has retained |cocoa_view_|.
182 RenderWidgetHost* render_widget_host_; 220 RenderWidgetHost* render_widget_host_;
183 221
184 // This is true when we are currently painting and thus should handle extra 222 // This is true when we are currently painting and thus should handle extra
185 // paint requests by expanding the invalid rect rather than actually painting. 223 // paint requests by expanding the invalid rect rather than actually painting.
186 bool about_to_validate_and_paint_; 224 bool about_to_validate_and_paint_;
187 225
188 // This is true when we have already scheduled a call to 226 // This is true when we have already scheduled a call to
189 // |-callSetNeedsDisplayInRect:| but it has not been fulfilled yet. Used to 227 // |-callSetNeedsDisplayInRect:| but it has not been fulfilled yet. Used to
190 // prevent us from scheduling multiple calls. 228 // prevent us from scheduling multiple calls.
191 bool call_set_needs_display_in_rect_pending_; 229 bool call_set_needs_display_in_rect_pending_;
192 230
193 // The invalid rect that needs to be painted by callSetNeedsDisplayInRect. 231 // The invalid rect that needs to be painted by callSetNeedsDisplayInRect.
194 // This value is only meaningful when 232 // This value is only meaningful when
195 // |call_set_needs_display_in_rect_pending_| is true. 233 // |call_set_needs_display_in_rect_pending_| is true.
196 NSRect invalid_rect_; 234 NSRect invalid_rect_;
197 235
198 // The time at which this view started displaying white pixels as a result of 236 // The time at which this view started displaying white pixels as a result of
199 // not having anything to paint (empty backing store from renderer). This 237 // not having anything to paint (empty backing store from renderer). This
200 // value returns true for is_null() if we are not recording whiteout times. 238 // value returns true for is_null() if we are not recording whiteout times.
201 base::TimeTicks whiteout_start_time_; 239 base::TimeTicks whiteout_start_time_;
202 240
203 // The time it took after this view was selected for it to be fully painted. 241 // The time it took after this view was selected for it to be fully painted.
204 base::TimeTicks tab_switch_paint_time_; 242 base::TimeTicks tab_switch_paint_time_;
205 243
206 // Variables used by our implementaion of the NSTextInput protocol.
207 // An input method of Mac calls the methods of this protocol not only to
208 // notify an application of its status, but also to retrieve the status of
209 // the application. That is, an application cannot control an input method
210 // directly.
211 // This object keeps the status of a composition of the renderer and returns
212 // it when an input method asks for it.
213 // We need to implement Objective-C methods for the NSTextInput protocol. On
214 // the other hand, we need to implement a C++ method for an IPC-message
215 // handler which receives input-method events from the renderer.
216 // To avoid fragmentation of variables used by our input-method
217 // implementation, we define all variables as public member variables of
218 // this C++ class so both the C++ methods and the Objective-C methods can
219 // access them.
220
221 // Represents the input-method attributes supported by this object.
222 NSArray* im_attributes_;
223
224 // Represents whether or not an input method is composing a text.
225 bool im_composing_;
226
227 // Represents the composition string (i.e. a text being composed by an input
228 // method), its range, and the range of the selected text in the composition
229 // string.
230 string16 im_text_;
231 NSRange im_marked_range_;
232 NSRange im_selected_range_;
233
234 // Represents the state of modifier keys.
235 // An input method doesn't notify the state of modifier keys. On the other
236 // hand, the state of modifier keys are required by Char events because they
237 // are dispatched to onkeypress() event handlers of JavaScript.
238 // To create a Char event in NSTextInput methods, we save the latest state
239 // of modifier keys when we receive it.
240 int im_modifiers_;
241
242 // Represents the cursor position in this view coordinate.
243 // The renderer sends the cursor position through an IPC message.
244 // We save the latest cursor position here and return it when an input
245 // methods needs it.
246 NSRect im_caret_rect_;
247
248 private: 244 private:
249 // Updates the display cursor to the current cursor if the cursor is over this 245 // Updates the display cursor to the current cursor if the cursor is over this
250 // render view. 246 // render view.
251 void UpdateCursorIfOverSelf(); 247 void UpdateCursorIfOverSelf();
252 248
253 // Shuts down the render_widget_host_. This is a separate function so we can 249 // Shuts down the render_widget_host_. This is a separate function so we can
254 // invoke it from the message loop. 250 // invoke it from the message loop.
255 void ShutdownHost(); 251 void ShutdownHost();
256 252
257 // The associated view. This is weak and is inserted into the view hierarchy 253 // The associated view. This is weak and is inserted into the view hierarchy
(...skipping 26 matching lines...) Expand all
284 // Used for positioning a popup menu. 280 // Used for positioning a popup menu.
285 BaseView* parent_view_; 281 BaseView* parent_view_;
286 282
287 // Helper class for managing instances of accelerated plug-ins. 283 // Helper class for managing instances of accelerated plug-ins.
288 AcceleratedSurfaceContainerManagerMac plugin_container_manager_; 284 AcceleratedSurfaceContainerManagerMac plugin_container_manager_;
289 285
290 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewMac); 286 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewMac);
291 }; 287 };
292 288
293 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_ 289 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/render_widget_host_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698