Changeset 887
- Timestamp:
- 02/13/14 22:59:29 (10 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/JfxBrowserActions.java
r876 r887 153 153 * @throws Exception 154 154 */ 155 public static void createFrameWithBrowser( Textlink, String url) throws Exception {155 public static void createFrameWithBrowser(Item link, String url) throws Exception { 156 156 Frame frame = FrameIO.CreateNewFrame(link); 157 157 frame.removeAllItems(frame.getItems()); 158 158 159 link.setLink("" + frame.getNumber()); 159 160 link.setAction(null); 160 161 161 162 // Create widget via text annotation 162 Text wt =frame.addText(10, 10, "@iw: org.expeditee.items.widgets.JfxBrowser " + (int) (FrameGraphics.getMaxFrameSize().getWidth() * 0.9) + " "163 frame.addText(10, 10, "@iw: org.expeditee.items.widgets.JfxBrowser " + (int) (FrameGraphics.getMaxFrameSize().getWidth() * 0.9) + " " 163 164 + (int) (FrameGraphics.getMaxFrameSize().getHeight() * 0.9) + " : " + url, null); 164 165 -
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r886 r887 543 543 JSObject window = (JSObject) JfxBrowser.this._webEngine.executeScript("window"); 544 544 Object o = JfxBrowser.this._webEngine.executeScript("document.elementFromPoint(" + e.getX() + "," + e.getY() + ");"); 545 545 546 if(o instanceof org.w3c.dom.Node) { 546 547 org.w3c.dom.Node node = (org.w3c.dom.Node) o; 547 548 JSObject style = (JSObject) window.call("getComputedStyle", node); 549 548 550 if(node.getNodeName().toLowerCase().equals("img") || 549 551 ((String) style.call("getPropertyValue", "background-image")).startsWith("url")) { 550 try {551 552 553 try { 552 554 JSObject bounds = (JSObject) ((JSObject) node).call("getBoundingClientRect", new Object[] {}); 553 555 float width = Float.valueOf(bounds.getMember("width").toString()); … … 559 561 pic = WebParser.getBackgroundImageFromNode(node, style, DisplayIO.getCurrentFrame(), null, 560 562 (float) FrameMouseActions.getX(), (float) FrameMouseActions.getY(), width, height); 563 561 564 } else { 562 565 String imgSrc; … … 569 572 } 570 573 } 574 575 String linkUrl; 576 577 // Check the image and its immediate parent for links 578 if ((node.getNodeName().toLowerCase().equals("a") && (linkUrl = (String) ((JSObject)node).getMember("href")) != null) 579 || (node.getParentNode().getNodeName().toLowerCase().equals("a") && (linkUrl = (String)((JSObject)node.getParentNode()).getMember("href")) != null)) { 580 581 if(hasValidProtocol(linkUrl)) { 582 pic.getSource().setAction("createFrameWithBrowser " + linkUrl); 583 } 584 } 585 571 586 pic.setXY(FrameMouseActions.getX(), FrameMouseActions.getY()); 572 587 FrameMouseActions.pickup(pic); … … 575 590 e1.printStackTrace(); 576 591 } 592 577 593 } else if(node.getNodeName().toLowerCase().equals("video")) { 578 594 String src = ((JSObject)node).getMember("src").toString(); … … 601 617 JfxMedia media = new JfxMedia(t, new String[] { src }); 602 618 FrameMouseActions.pickup(media.getItems()); 619 620 } else if(node.getNodeName().toLowerCase().equals("a") && ((JSObject)node).getMember("href") != null) { 621 // If a link is right clicked, copy the text content and give it an action to create 622 // a new frame containing a browser pointing to the linked page 623 Text t = DisplayIO.getCurrentFrame().createNewText(((String) ((JSObject)node).getMember("textContent")).trim()); 624 t.addAction("createFrameWithBrowser " + (String) ((JSObject)node).getMember("href")); 625 t.setXY(FrameMouseActions.getX(), FrameMouseActions.getY()); 626 FrameMouseActions.pickup(t); 603 627 } 604 628 } 605 629 } else { 606 630 // Copy text and attach to cursor 607 Text t = new Text(selection); 608 t.setParent(DisplayIO.getCurrentFrame()); 631 Text t = DisplayIO.getCurrentFrame().createNewText(); 609 632 t.setXY(FrameMouseActions.getX(), FrameMouseActions.getY()); 610 633 FrameMouseActions.pickup(t); … … 622 645 public void navigate(String url) { 623 646 final String actualURL; 624 String urlLower = url.toLowerCase(); 647 625 648 // check if protocol is missing 626 if (! (urlLower.startsWith("http://") || url.startsWith("https://") || urlLower.startsWith("ftp://") || urlLower.startsWith("file://"))) {649 if (!hasValidProtocol(url)) { 627 650 // check if it's a search 628 651 int firstSpace = url.indexOf(" "); … … 973 996 return stringBuilder.toString(); 974 997 } 998 999 /** 1000 * Checks if a URL string starts with a protocol that can be loaded by the webview 1001 * @param url URL string to check 1002 * @return 1003 */ 1004 private static boolean hasValidProtocol(String url) { 1005 String urlLower = url.toLowerCase(); 1006 1007 // check if protocol is present 1008 return (urlLower.startsWith("http://") || url.startsWith("https://") || urlLower.startsWith("ftp://") || urlLower.startsWith("file://")); 1009 } 975 1010 }
Note:
See TracChangeset
for help on using the changeset viewer.