1 /* 2 * Copyright (c) 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.java.scene.web; 27 28 import com.sun.javafx.geom.BaseBounds; 29 import com.sun.javafx.geom.PickRay; 30 import com.sun.javafx.geom.transform.BaseTransform; 31 import com.sun.javafx.scene.ParentHelper; 32 import com.sun.javafx.scene.input.PickResultChooser; 33 import com.sun.javafx.sg.prism.NGNode; 34 import com.sun.javafx.util.Utils; 35 import javafx.scene.web.WebView; 36 import javafx.scene.Node; 37 38 /** 39 * Used to access internal methods of WebView. 40 */ 41 public class WebViewHelper extends ParentHelper { 42 43 private static final WebViewHelper theInstance; 44 private static WebViewAccessor webViewAccessor; 45 46 static { 47 theInstance = new WebViewHelper(); 48 Utils.forceInit(WebView.class); 49 } 50 51 private static WebViewHelper getInstance() { 52 return theInstance; 53 } 54 55 public static void initHelper(WebView webView) { 56 setHelper(webView, getInstance()); 57 } 58 59 @Override 60 protected NGNode createPeerImpl(Node node) { 61 return webViewAccessor.doCreatePeer(node); 62 } 63 64 @Override 65 protected void updatePeerImpl(Node node) { 66 super.updatePeerImpl(node); 67 webViewAccessor.doUpdatePeer(node); 68 } 69 70 protected void transformsChangedImpl(Node node) { 71 super.transformsChangedImpl(node); 72 webViewAccessor.doTransformsChanged(node); 73 } 74 75 @Override 76 protected BaseBounds computeGeomBoundsImpl(Node node, BaseBounds bounds, 77 BaseTransform tx) { 78 return webViewAccessor.doComputeGeomBounds(node, bounds, tx); 79 } 80 81 @Override 82 protected boolean computeContainsImpl(Node node, double localX, double localY) { 83 return webViewAccessor.doComputeContains(node, localX, localY); 84 } 85 86 @Override 87 protected void pickNodeLocalImpl(Node node, PickRay localPickRay, 88 PickResultChooser result) { 89 webViewAccessor.doPickNodeLocal(node, localPickRay, result); 90 } 91 92 public static void setWebViewAccessor(final WebViewAccessor newAccessor) { 93 if (webViewAccessor != null) { 94 throw new IllegalStateException(); 95 } 96 97 webViewAccessor = newAccessor; 98 } 99 100 public interface WebViewAccessor { 101 NGNode doCreatePeer(Node node); 102 void doUpdatePeer(Node node); 103 void doTransformsChanged(Node node); 104 BaseBounds doComputeGeomBounds(Node node, BaseBounds bounds, BaseTransform tx); 105 boolean doComputeContains(Node node, double localX, double localY); 106 void doPickNodeLocal(Node node, PickRay localPickRay, PickResultChooser result); 107 } 108 109 }