1 /* 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.javafx.webkit; 27 28 import java.lang.ref.WeakReference; 29 import java.util.ArrayList; 30 import java.util.List; 31 32 import com.sun.javafx.scene.input.ExtendedInputMethodRequests; 33 import javafx.geometry.Point2D; 34 import javafx.scene.input.InputMethodEvent; 35 import javafx.scene.input.InputMethodHighlight; 36 import javafx.scene.input.InputMethodRequests; 37 import javafx.scene.input.InputMethodTextRun; 38 import javafx.scene.web.WebView; 39 40 import com.sun.webkit.InputMethodClient; 41 import com.sun.webkit.WebPage; 42 import com.sun.webkit.event.WCInputMethodEvent; 43 import com.sun.webkit.graphics.WCPoint; 44 45 public final class InputMethodClientImpl 46 implements InputMethodClient, ExtendedInputMethodRequests 47 { 48 private final WeakReference<WebView> wvRef; 49 private final WebPage webPage; 50 51 // the state of the last setInputMethodState() call. 52 private boolean state; 53 54 public InputMethodClientImpl(WebView wv, WebPage webPage) { 55 this.wvRef = new WeakReference<WebView>(wv); 56 this.webPage = webPage; 57 if (webPage != null) { 58 webPage.setInputMethodClient(this); 59 } 60 } 61 62 public void activateInputMethods(final boolean doActivate) { 63 WebView wv = wvRef.get(); 64 if (wv != null && wv.getScene() != null) { 65 wv.getScene().impl_enableInputMethodEvents(doActivate); 66 } 67 state = doActivate; 68 } 69 70 public boolean getInputMethodState() { 71 return state; 72 } 73 74 /** 75 * Converts the given InputMethodEvent to a WCInputMethodEvent. 76 */ 77 public static WCInputMethodEvent convertToWCInputMethodEvent(InputMethodEvent ie) { 78 List<Integer> underlines = new ArrayList<Integer>(); 79 StringBuilder composed = new StringBuilder(); 80 int pos = 0; 81 82 // Scan the given composedText to find input method highlight attribute runs. 83 for (InputMethodTextRun run : ie.getComposed()) { 84 String rawText = run.getText(); 85 | 1 /* 2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.javafx.webkit; 27 28 import com.sun.javafx.scene.SceneHelper; 29 import java.lang.ref.WeakReference; 30 import java.util.ArrayList; 31 import java.util.List; 32 33 import com.sun.javafx.scene.input.ExtendedInputMethodRequests; 34 import javafx.geometry.Point2D; 35 import javafx.scene.input.InputMethodEvent; 36 import javafx.scene.input.InputMethodHighlight; 37 import javafx.scene.input.InputMethodRequests; 38 import javafx.scene.input.InputMethodTextRun; 39 import javafx.scene.web.WebView; 40 41 import com.sun.webkit.InputMethodClient; 42 import com.sun.webkit.WebPage; 43 import com.sun.webkit.event.WCInputMethodEvent; 44 import com.sun.webkit.graphics.WCPoint; 45 46 public final class InputMethodClientImpl 47 implements InputMethodClient, ExtendedInputMethodRequests 48 { 49 private final WeakReference<WebView> wvRef; 50 private final WebPage webPage; 51 52 // the state of the last setInputMethodState() call. 53 private boolean state; 54 55 public InputMethodClientImpl(WebView wv, WebPage webPage) { 56 this.wvRef = new WeakReference<WebView>(wv); 57 this.webPage = webPage; 58 if (webPage != null) { 59 webPage.setInputMethodClient(this); 60 } 61 } 62 63 public void activateInputMethods(final boolean doActivate) { 64 WebView wv = wvRef.get(); 65 if (wv != null && wv.getScene() != null) { 66 SceneHelper.enableInputMethodEvents(wv.getScene(), doActivate); 67 } 68 state = doActivate; 69 } 70 71 public boolean getInputMethodState() { 72 return state; 73 } 74 75 /** 76 * Converts the given InputMethodEvent to a WCInputMethodEvent. 77 */ 78 public static WCInputMethodEvent convertToWCInputMethodEvent(InputMethodEvent ie) { 79 List<Integer> underlines = new ArrayList<Integer>(); 80 StringBuilder composed = new StringBuilder(); 81 int pos = 0; 82 83 // Scan the given composedText to find input method highlight attribute runs. 84 for (InputMethodTextRun run : ie.getComposed()) { 85 String rawText = run.getText(); 86 |