示例#1
0
        private void OnIMEComposition(IntPtr hwnd, int lParam)
        {
            string text = string.Empty;

            using (var handler = IMEHandler.Create(hwnd))
            {
                if (handler.GetResult((uint)lParam, out text))
                {
                    _owner.GetBrowserHost().ImeCommitText(text, new Range(Int32.MaxValue, Int32.MaxValue), 0);
                    return;
                }
            }

            using (var handler = IMEHandler.Create(hwnd))
            {
                var underlines       = new List <CompositionUnderline>();
                int compositionStart = 0;

                if (handler.GetComposition((uint)lParam, underlines, ref compositionStart, out text))
                {
                    _owner.GetBrowserHost().ImeSetComposition(text, underlines.ToArray(), new Range(Int32.MaxValue, Int32.MaxValue), new Range(compositionStart, compositionStart));

                    UpdateCaretPosition(compositionStart - 1);
                }
            }
        }
示例#2
0
        private void MoveImeWindow(IntPtr hwnd)
        {
            if (!_owner.IsFocused)
            {
                return;
            }

            CefSharp.Structs.Rect rc = _imeRect;
            int location             = _cursorIndex;

            // If location is not specified fall back to the composition range start.
            if (location == -1)
            {
                location = _compositionRange.From;
            }

            // Offset location by the composition range start if required.
            if (location >= _compositionRange.From)
            {
                location -= _compositionRange.From;
            }

            if (location < _compositionBounds.Count)
            {
                rc = _compositionBounds[location];
            }
            else
            {
                return;
            }

            int caretMargin = 1;

            if (_languageCodeId == NativeIME.LANG_CHINESE)
            {
                var formPoint = new NativeIME.TagCompositionForm
                {
                    DwStyle      = NativeIME.CFS_POINT,
                    PtCurrentPos = new NativeIME.TagPoint
                    {
                        X = rc.X,
                        Y = rc.Y
                    },
                    RcArea = new NativeIME.TagRect
                    {
                        Left   = rc.X,
                        Top    = rc.Y,
                        Right  = rc.X + rc.Width,
                        Bottom = rc.Y + rc.Height
                    }
                };

                // TODO :: candidate window for Chinese
                using (var handler = IMEHandler.Create(hwnd))
                {
                    //NativeIME.ImmSetCompositionWindow(handler._hIMC, ref formPoint);
                }
            }

            if (_systemCaret)
            {
                if (_languageCodeId == NativeIME.LANG_JAPANESE)
                {
                    var firstRc = _compositionBounds[0];
                    NativeIME.SetCaretPos(firstRc.X, firstRc.Y + firstRc.Height);
                }
                else
                {
                    NativeIME.SetCaretPos(rc.X, rc.Y);
                }
            }

            if (_languageCodeId == NativeIME.LANG_KOREAN)
            {
                rc = new CefSharp.Structs.Rect(rc.X, rc.Y + caretMargin, rc.Width, rc.Height);
            }

            // Japanese IMEs and Korean IMEs also use the rectangle given to
            // ::ImmSetCandidateWindow() with its 'dwStyle' parameter CFS_EXCLUDE
            // Therefore, we also set this parameter here.

            //Referred from : https://bitbucket.org/chromiumembedded/cef/src/af349ade330c33b669c9ad61cd5000c140968fd7/tests/cefclient/browser/osr_ime_handler_win.cc?at=master&fileviewer=file-view-default#osr_ime_handler_win.cc-206

            /*
             *  CANDIDATEFORM exclude_rectangle = {
             *  0,
             *  CFS_EXCLUDE,
             *  {rc.x, rc.y},
             *  {rc.x, rc.y, rc.x + rc.width, rc.y + rc.height}};
             *  ::ImmSetCandidateWindow(imc, &exclude_rectangle);
             *
             *  ::ImmReleaseContext(hwnd_, imc);
             */

            var candidateForm = new NativeIME.TagCandidateForm
            {
                DwStyle      = NativeIME.CFS_EXCLUDE,
                PtCurrentPos = new NativeIME.TagPoint
                {
                    X = rc.X,
                    Y = rc.Y
                },
                RcArea = new NativeIME.TagRect
                {
                    Left   = rc.X,
                    Top    = rc.Y,
                    Right  = rc.X + rc.Width,
                    Bottom = rc.Y + rc.Height
                }
            };

            using (var handler = IMEHandler.Create(hwnd))
            {
                NativeIME.ImmSetCandidateWindow(handler._hIMC, ref candidateForm);
            }
        }