1 /* 2 * Copyright (c) 2013, 2018, 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.sg.prism; 27 28 import com.sun.javafx.geom.BaseBounds; 29 import com.sun.javafx.geom.RectBounds; 30 import com.sun.javafx.logging.PlatformLogger; 31 import com.sun.prism.Graphics; 32 import com.sun.prism.paint.Color; 33 import com.sun.webkit.WebPage; 34 35 public final class NGWebView extends NGGroup { 36 37 private final static PlatformLogger log = 38 PlatformLogger.getLogger(NGWebView.class.getName()); 39 private volatile WebPage page; 40 private volatile float width, height; 41 private static final Color VERY_LIGHT_RED = new Color(1, 0, 0, .3f); 42 43 public void setPage(WebPage page) { 44 this.page = page; 45 } 46 47 public void resize(float w, float h) { 48 if (width != w || height != h) { 49 width = w; 50 height = h; 51 geometryChanged(); 52 } 53 } 54 55 // Invoked on JavaFX User Thread. 56 public void update() { 57 } 58 59 public void requestRender() { 60 visualsChanged(); 61 } 62 private final float[] src = new float[]{0.0f, 0.0f}; 63 private final float[] dest = new float[]{0.0f, 0.0f}; 64 private final RectBounds destBounds = new RectBounds(); 65 66 @Override 67 protected void doRender(Graphics g) { 68 renderContent(g); 69 } 70 71 @Override 72 public void setTransformedBounds(BaseBounds bounds, boolean byTransformChangeOnly) { 73 super.setTransformedBounds(bounds, byTransformChangeOnly); 74 } 75 76 // Invoked on Render Thread. 77 @Override 78 protected void renderContent(Graphics g) { 79 // g.setPaint(VERY_LIGHT_RED); 80 // g.fillRect(transformedBounds.getMinX(), 81 // transformedBounds.getMinY(), 82 // transformedBounds.getWidth(), 83 // transformedBounds.getHeight()); 84 85 g.getTransformNoClone(). 86 transform(transformedBounds, destBounds); 87 page.moveAndResize( 88 destBounds.getMinX(), 89 destBounds.getMinY(), 90 destBounds.getWidth(), 91 destBounds.getHeight()); 92 } 93 94 @Override public boolean hasOverlappingContents() { 95 return false; 96 } 97 98 @Override protected boolean hasVisuals() { 99 return true; 100 } 101 }