Changeset 854
- Timestamp:
- 02/07/14 12:26:51 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r840 r854 54 54 import org.expeditee.items.Text; 55 55 import org.expeditee.settings.network.NetworkSettings; 56 import org.w3c.dom.NodeList; 56 57 57 58 import com.sun.javafx.scene.control.skin.TextFieldSkin; … … 74 75 private static final String REFRESH = "refresh"; 75 76 private static final String CONVERT = "convert"; 77 private static final String VIDEO = "video"; 76 78 77 79 private JFXPanel _panel; … … 497 499 if (selection.length() == 0) { 498 500 JSObject window = (JSObject) JfxBrowser.this._webEngine.executeScript("window"); 499 Object image = JfxBrowser.this._webEngine.executeScript("" 500 + "function isImage(o) {" 501 + " if(o.tagName == \"IMG\" && o.src != null) {" 502 + " return true;" 503 + " }" 504 + " if(window.getComputedStyle(o).getPropertyValue(\"background-image\").indexOf(\"url\") == 0) {" 505 + " return true;" 506 + " }" 507 + " return false;" 508 + "};" 509 + "var clicked = document.elementFromPoint(" + e.getX() + "," + e.getY() + ");" 510 + "if(isImage(clicked)) {" 511 + " clicked;" 512 + "} else {" 513 // TODO: look in child elements and other elements behind the current one 514 // For now just return nothing 515 + " null;" 516 + "}" 517 + ""); 518 if(image instanceof org.w3c.dom.Node) { 519 System.out.println(image); 520 try { 521 JSObject style = (JSObject) window.call("getComputedStyle", image); 522 523 JSObject bounds = (JSObject) ((JSObject) image).call("getBoundingClientRect", new Object[] {}); 524 float width = Float.valueOf(bounds.getMember("width").toString()); 525 float height = Float.valueOf(bounds.getMember("height").toString()); 526 527 Picture pic; 528 529 org.w3c.dom.Node node = ((org.w3c.dom.Node) image); 530 531 if (((String) style.call("getPropertyValue", new Object[] { "background-image" })).startsWith("url(")) { 532 pic = WebParser.getBackgroundImageFromNode(node, style, DisplayIO.getCurrentFrame(), null, 533 (float) FrameMouseActions.getX(), (float) FrameMouseActions.getY(), width, height); 534 } else { 535 String imgSrc; 536 if(node.getNodeName().toLowerCase().equals("img") && 537 (imgSrc = ((JSObject) node).getMember("src").toString()) != null) { 538 pic = WebParser.getImageFromUrl(imgSrc, null, DisplayIO.getCurrentFrame(), 539 (float) FrameMouseActions.getX(), (float) FrameMouseActions.getY(), (int) width, null, null, null, null, null, 0, 0); 540 } else { 501 Object o = JfxBrowser.this._webEngine.executeScript("document.elementFromPoint(" + e.getX() + "," + e.getY() + ");"); 502 if(o instanceof org.w3c.dom.Node) { 503 org.w3c.dom.Node node = (org.w3c.dom.Node) o; 504 JSObject style = (JSObject) window.call("getComputedStyle", node); 505 if(node.getNodeName().toLowerCase().equals("img") || 506 ((String) style.call("getPropertyValue", "background-image")).startsWith("url")) { 507 try { 508 509 JSObject bounds = (JSObject) ((JSObject) node).call("getBoundingClientRect", new Object[] {}); 510 float width = Float.valueOf(bounds.getMember("width").toString()); 511 float height = Float.valueOf(bounds.getMember("height").toString()); 512 513 Picture pic; 514 515 if (((String) style.call("getPropertyValue", new Object[] { "background-image" })).startsWith("url(")) { 516 pic = WebParser.getBackgroundImageFromNode(node, style, DisplayIO.getCurrentFrame(), null, 517 (float) FrameMouseActions.getX(), (float) FrameMouseActions.getY(), width, height); 518 } else { 519 String imgSrc; 520 if(node.getNodeName().toLowerCase().equals("img") && 521 (imgSrc = ((JSObject) node).getMember("src").toString()) != null) { 522 pic = WebParser.getImageFromUrl(imgSrc, null, DisplayIO.getCurrentFrame(), 523 (float) FrameMouseActions.getX(), (float) FrameMouseActions.getY(), (int) width, null, null, null, null, null, 0, 0); 524 } else { 525 return; 526 } 527 } 528 pic.setXY(FrameMouseActions.getX(), FrameMouseActions.getY()); 529 FrameMouseActions.pickup(pic); 530 } catch (Exception e1) { 531 // TODO Auto-generated catch block 532 e1.printStackTrace(); 533 } 534 } else if(node.getNodeName().toLowerCase().equals("video")) { 535 String src = ((JSObject)node).getMember("src").toString(); 536 if(src == null || src.trim().length() == 0) { 537 NodeList children = node.getChildNodes(); 538 for(int i = 0; i < children.getLength(); i++) { 539 org.w3c.dom.Node child = children.item(i); 540 if(child.getNodeName().toLowerCase().equals("source")) { 541 src = ((JSObject)child).getMember("src").toString(); 542 if(src != null && src.trim().length() > 0) { 543 break; 544 } 545 } 546 547 } 548 if(src == null || src.trim().length() == 0) { 541 549 return; 542 550 } 543 551 } 544 pic.setXY(FrameMouseActions.getX(), FrameMouseActions.getY()); 545 FrameMouseActions.pickup(pic); 546 } catch (Exception e1) { 547 // TODO Auto-generated catch block 548 e1.printStackTrace(); 549 } 552 Text t = new Text("@iw: org.expeditee.items.widgets.jfxmedia " 553 + ((JSObject)node).getMember("width") 554 + ((JSObject)node).getMember("height") 555 + ":" + src); 556 t.setParent(DisplayIO.getCurrentFrame()); 557 t.setXY(FrameMouseActions.getX(), FrameMouseActions.getY()); 558 JfxMedia media = new JfxMedia(t, new String[] { src }); 559 FrameMouseActions.pickup(media.getItems()); 560 } 550 561 } 551 562 } else {
Note:
See TracChangeset
for help on using the changeset viewer.