Changeset 815 for trunk/src/org/expeditee/items/widgets
- Timestamp:
- 02/03/14 16:03:18 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r813 r815 36 36 import javafx.scene.web.WebEngine; 37 37 import javafx.scene.web.WebView; 38 import netscape.javascript.JSObject; 38 39 39 40 import org.expeditee.gui.DisplayIO; … … 43 44 import org.expeditee.io.WebParser; 44 45 import org.expeditee.items.Item; 46 import org.expeditee.items.Picture; 45 47 import org.expeditee.items.Text; 46 48 import org.expeditee.settings.network.NetworkSettings; … … 382 384 String selection = (String) JfxBrowser.this._webEngine.executeScript("window.getSelection().toString()"); 383 385 384 // Do nothing if no text is selected 385 if (!selection.equals("")) { 386 // If no text is selected, see if an image is under the cursor 387 if (selection.length() == 0) { 388 JSObject window = (JSObject) JfxBrowser.this._webEngine.executeScript("window"); 389 Object image = JfxBrowser.this._webEngine.executeScript("" 390 + "function isImage(o) {" 391 + " if(o.tagName == \"IMG\" && o.src != null) {" 392 + " return true;" 393 + " }" 394 + " if(window.getComputedStyle(o).getPropertyValue(\"background-image\").indexOf(\"url\") == 0) {" 395 + " return true;" 396 + " }" 397 + " return false;" 398 + "};" 399 + "var clicked = document.elementFromPoint(" + e.getX() + "," + e.getY() + ");" 400 + "if(isImage(clicked)) {" 401 + " clicked;" 402 + "} else {" 403 // TODO: look in child elements and other elements behind the current one 404 // For now just return nothing 405 + " null;" 406 + "}" 407 + ""); 408 if(image instanceof org.w3c.dom.Node) { 409 System.out.println(image); 410 try { 411 JSObject style = (JSObject) window.call("getComputedStyle", image); 412 413 JSObject bounds = (JSObject) ((JSObject) image).call("getBoundingClientRect", new Object[] {}); 414 float width = Float.valueOf(bounds.getMember("width").toString()); 415 float height = Float.valueOf(bounds.getMember("height").toString()); 416 417 Picture pic; 418 419 org.w3c.dom.Node node = ((org.w3c.dom.Node) image); 420 421 if (((String) style.call("getPropertyValue", new Object[] { "background-image" })).startsWith("url(")) { 422 pic = WebParser.getBackgroundImageFromNode(node, style, DisplayIO.getCurrentFrame(), null, 423 (float) FrameMouseActions.getX(), (float) FrameMouseActions.getY(), width, height); 424 } else { 425 String imgSrc; 426 if(node.getNodeName().toLowerCase().equals("img") && 427 (imgSrc = ((JSObject) node).getMember("src").toString()) != null) { 428 pic = WebParser.getImageFromUrl(imgSrc, null, DisplayIO.getCurrentFrame(), 429 (float) FrameMouseActions.getX(), (float) FrameMouseActions.getY(), (int) width, null, null, null, null, null, 0, 0); 430 } else { 431 return; 432 } 433 } 434 pic.setXY(FrameMouseActions.getX(), FrameMouseActions.getY()); 435 FrameMouseActions.pickup(pic); 436 } catch (Exception e1) { 437 // TODO Auto-generated catch block 438 e1.printStackTrace(); 439 } 440 } 441 } else { 386 442 // Copy text and attach to cursor 387 443 Text t = new Text(selection);
Note:
See TracChangeset
for help on using the changeset viewer.