@@ -190,7 +190,14 @@ private IntPtr SourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, re
190190 {
191191 handled = false ;
192192
193- if ( ! isActive || ! isSetup || owner == null || owner . IsDisposed || ! owner . IsBrowserInitialized || owner . GetBrowserHost ( ) == null )
193+ if ( ! isActive || ! isSetup || owner == null || owner . IsDisposed || ! owner . IsBrowserInitialized )
194+ {
195+ return IntPtr . Zero ;
196+ }
197+
198+ var browserHost = owner . GetBrowserHost ( ) ;
199+
200+ if ( browserHost == null )
194201 {
195202 return IntPtr . Zero ;
196203 }
@@ -212,13 +219,13 @@ private IntPtr SourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, re
212219 }
213220 case WM . IME_COMPOSITION :
214221 {
215- OnImeComposition ( hwnd , lParam . ToInt32 ( ) ) ;
222+ OnImeComposition ( browserHost , hwnd , lParam . ToInt32 ( ) ) ;
216223 handled = true ;
217224 break ;
218225 }
219226 case WM . IME_ENDCOMPOSITION :
220227 {
221- OnImeEndComposition ( hwnd ) ;
228+ OnImeEndComposition ( browserHost , hwnd ) ;
222229 hasImeComposition = false ;
223230 handled = true ;
224231 break ;
@@ -239,15 +246,15 @@ private void CloseImeComposition()
239246 }
240247 }
241248
242- private void OnImeComposition ( IntPtr hwnd , int lParam )
249+ private void OnImeComposition ( IBrowserHost browserHost , IntPtr hwnd , int lParam )
243250 {
244251 string text = string . Empty ;
245252
246253 if ( ImeHandler . GetResult ( hwnd , ( uint ) lParam , out text ) )
247254 {
248- owner . GetBrowserHost ( ) . ImeCommitText ( text , new Range ( int . MaxValue , int . MaxValue ) , 0 ) ;
249- owner . GetBrowserHost ( ) . ImeSetComposition ( text , new CompositionUnderline [ 0 ] , new Range ( int . MaxValue , int . MaxValue ) , new Range ( 0 , 0 ) ) ;
250- owner . GetBrowserHost ( ) . ImeFinishComposingText ( false ) ;
255+ browserHost . ImeCommitText ( text , new Range ( int . MaxValue , int . MaxValue ) , 0 ) ;
256+ browserHost . ImeSetComposition ( text , new CompositionUnderline [ 0 ] , new Range ( int . MaxValue , int . MaxValue ) , new Range ( 0 , 0 ) ) ;
257+ browserHost . ImeFinishComposingText ( false ) ;
251258 }
252259 else
253260 {
@@ -256,14 +263,14 @@ private void OnImeComposition(IntPtr hwnd, int lParam)
256263
257264 if ( ImeHandler . GetComposition ( hwnd , ( uint ) lParam , underlines , ref compositionStart , out text ) )
258265 {
259- owner . GetBrowserHost ( ) . ImeSetComposition ( text , underlines . ToArray ( ) ,
266+ browserHost . ImeSetComposition ( text , underlines . ToArray ( ) ,
260267 new Range ( int . MaxValue , int . MaxValue ) , new Range ( compositionStart , compositionStart ) ) ;
261268
262269 UpdateCaretPosition ( compositionStart - 1 ) ;
263270 }
264271 else
265272 {
266- CancelComposition ( hwnd ) ;
273+ CancelComposition ( browserHost , hwnd ) ;
267274 }
268275 }
269276 }
@@ -272,19 +279,19 @@ private void OnImeComposition(IntPtr hwnd, int lParam)
272279 /// Cancel composition.
273280 /// </summary>
274281 /// <param name="hwnd">The hwnd.</param>
275- public void CancelComposition ( IntPtr hwnd )
282+ private void CancelComposition ( IBrowserHost browserHost , IntPtr hwnd )
276283 {
277- owner . GetBrowserHost ( ) . ImeCancelComposition ( ) ;
284+ browserHost . ImeCancelComposition ( ) ;
278285 DestroyImeWindow ( hwnd ) ;
279286 }
280287
281- private void OnImeEndComposition ( IntPtr hwnd )
288+ private void OnImeEndComposition ( IBrowserHost browserHost , IntPtr hwnd )
282289 {
283290 // Korean IMEs somehow ignore function calls to ::ImeFinishComposingText()
284291 // The same letter is commited in ::OnImeComposition()
285292 if ( languageCodeId != ImeNative . LANG_KOREAN )
286293 {
287- owner . GetBrowserHost ( ) . ImeFinishComposingText ( false ) ;
294+ browserHost . ImeFinishComposingText ( false ) ;
288295 }
289296 DestroyImeWindow ( hwnd ) ;
290297 }
0 commit comments