Skip to content

Commit

Permalink
squashed commit of curr/jsUgly2 and curr/misc3 branches
Browse files Browse the repository at this point in the history
  • Loading branch information
hrj committed Sep 13, 2015
1 parent 8bae532 commit c206151
Show file tree
Hide file tree
Showing 26 changed files with 253 additions and 51 deletions.
6 changes: 6 additions & 0 deletions src/HTML_Renderer/org/lobobrowser/html/BrowserFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import java.awt.Component;
import java.net.URL;

import org.lobobrowser.ua.ParameterInfo;
import org.lobobrowser.ua.RequestType;
import org.lobobrowser.ua.TargetType;
import org.w3c.dom.Document;

/**
Expand Down Expand Up @@ -83,4 +86,7 @@ public interface BrowserFrame {
* See constants in {@link org.lobobrowser.html.style.RenderState}.
*/
public void setDefaultOverflowY(int overflowY);

// Trying out a way for a frame's target to be set to an iframe. for issue #96
public void navigate(URL url, String method, ParameterInfo pinfo, TargetType targetType, RequestType form);
}
18 changes: 10 additions & 8 deletions src/HTML_Renderer/org/lobobrowser/html/domimpl/ElementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public void setDir(final String dir) {

public final String getAttribute(final String name) {
final String normalName = normalizeAttributeName(name);
synchronized (this) {
final Map<String, String> attributes = this.attributes;
return attributes == null ? null : attributes.get(normalName);
}
// synchronized (this) {
final Map<String, String> attributes = this.attributes;
return attributes == null ? null : attributes.get(normalName);
// }
}

private Attr getAttr(final String normalName, final String value) {
Expand Down Expand Up @@ -175,6 +175,7 @@ protected static boolean isTagName(final Node node, final String name) {
return node.getNodeName().equalsIgnoreCase(name);
}

@Override
public NodeList getElementsByTagName(final String name) {
final boolean matchesAll = "*".equals(name);
final List<Node> descendents = new LinkedList<>();
Expand Down Expand Up @@ -217,10 +218,11 @@ public String getTagName() {

public boolean hasAttribute(final String name) {
final String normalName = normalizeAttributeName(name);
synchronized (this) {
final Map<String, String> attributes = this.attributes;
return attributes == null ? false : attributes.containsKey(normalName);
}
// This was causing deadlocks, hence removed the sync
// synchronized (this) {
final Map<String, String> attributes = this.attributes;
return attributes == null ? false : attributes.containsKey(normalName);
// }
}

public boolean hasAttributeNS(final String namespaceURI, final String localName) throws DOMException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ public class HTMLButtonElementImpl extends HTMLBaseInputElement {
public HTMLButtonElementImpl(final String name) {
super(name);
}

public void click() {
// TODO: see issue #95
System.out.println("Button clicked. TODO");
// inputContext.click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public HTMLDocumentImpl(final UserAgentContext ucontext, final HtmlRendererConte
// with setCookie() method.
final String protocol = docURL.getProtocol();
if ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) {
sm.checkPermission(new java.net.SocketPermission(docURL.getHost(), "connect"));
sm.checkPermission(new java.net.SocketPermission(docURL.getHost(), "connect"));
}
}
this.documentURL = docURL;
Expand Down Expand Up @@ -264,6 +264,7 @@ public void setDefaultTarget(final String value) {
this.defaultTarget = value;
}

// TODO: Is this required? Check JS DOM specs.
public AbstractView getDefaultView() {
return this.window;
}
Expand Down Expand Up @@ -399,16 +400,19 @@ public String getCookie() {
}

public void setCookie(final String cookie) throws DOMException {
// Update in gngr: Whoa! No, we won't allow the privilege escalation below until better justification is presented ;)
// Chagned for Issue #78

// Justification: A caller (e.g. Google Analytics script)
// might want to set cookies on the parent document.
// If the caller has access to the document, it appears
// they should be able to set cookies on that document.
// Note that this Document instance cannot be created
// with an arbitrary URL.
SecurityUtil.doPrivileged(() -> {
ucontext.setCookie(documentURL, cookie);
return null;
});
// SecurityUtil.doPrivileged(() -> {
ucontext.setCookie(documentURL, cookie);
// return null;
// });
}

public void open() {
Expand Down Expand Up @@ -630,6 +634,7 @@ public EntityReference createEntityReference(final String name) throws DOMExcept
* The element tag name or an asterisk character (*) to match all
* elements.
*/
@Override
public NodeList getElementsByTagName(final String tagname) {
if ("*".equals(tagname)) {
return this.getNodeList(new ElementFilter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventException;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;
import org.w3c.dom.html.HTMLElement;
import org.w3c.dom.html.HTMLFormElement;

Expand All @@ -73,7 +77,7 @@
import cz.vutbr.web.domassign.Analyzer.OrderedRule;
import cz.vutbr.web.domassign.AnalyzerUtil;

public class HTMLElementImpl extends ElementImpl implements HTMLElement, CSS2PropertiesContext {
public class HTMLElementImpl extends ElementImpl implements HTMLElement, CSS2PropertiesContext, EventTarget {
private final boolean noStyleSheet;
private static final MatchConditionOnElements elementMatchCondition = new MatchConditionOnElements();

Expand Down Expand Up @@ -315,6 +319,9 @@ protected void assignAttributeField(final String normalName, final String value)
} else {
if ("style".equals(normalName)) {
this.forgetLocalStyle();
// informDocumentInvalid();
// informLayoutInvalid();
// invalidateDescendentsForHover();
}
}
super.assignAttributeField(normalName, value);
Expand Down Expand Up @@ -923,4 +930,22 @@ public boolean toggle(final String token, final boolean force) {
/* TODO: stringifier; */
}

@Override
public void addEventListener(final String type, final EventListener listener, final boolean useCapture) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}

@Override
public void removeEventListener(final String type, final EventListener listener, final boolean useCapture) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}

@Override
public boolean dispatchEvent(final Event evt) throws EventException {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
// return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.lobobrowser.html.style.IFrameRenderState;
import org.lobobrowser.html.style.RenderState;
import org.lobobrowser.js.HideFromJS;
import org.lobobrowser.ua.ParameterInfo;
import org.lobobrowser.ua.RequestType;
import org.lobobrowser.ua.TargetType;
import org.lobobrowser.ua.UserAgentContext.Request;
import org.lobobrowser.ua.UserAgentContext.RequestKind;
import org.mozilla.javascript.Function;
Expand Down Expand Up @@ -269,4 +272,34 @@ public void run() {
protected RenderState createRenderState(final RenderState prevRenderState) {
return new IFrameRenderState(prevRenderState, this);
}

// Trying out a way for a frame's target to be set to an iframe. for issue #96

public void navigate(final URL url, final String method, final ParameterInfo pinfo, final TargetType targetType, final RequestType form) {
final Window window = ((HTMLDocumentImpl) document).getWindow();
window.addJSTask(new JSRunnableTask(0, "Frame navigation to " + url, () -> {
final BrowserFrame frame = this.browserFrame;
if (frame != null) {
if (getUserAgentContext().isRequestPermitted(new Request(url, RequestKind.Frame))) {
frame.getHtmlRendererContext().setJobFinishedHandler(new Runnable() {
public void run() {
System.out.println("Iframes window's job over!");
if (onload != null) {
// TODO: onload event object?
final Window window = ((HTMLDocumentImpl) document).getWindow();
window.addJSTask(new JSRunnableTask(0, "IFrame onload handler", () -> {
Executor.executeFunction(HTMLIFrameElementImpl.this, onload, null, window.getContextFactory());
}));
}
// markJobDone();
}
});
// frame.loadURL(fullURL);
browserFrame.navigate(url, method, pinfo, targetType, form);
}
// browserFrame.navigate(url, method, pinfo, targetType, form);
}
}
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,10 @@ private void onMouseMoved(final MouseEvent event) {
*
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
*/
// protected void paintComponent(Graphics g) {
@Override
public void paint(final Graphics g) {
protected void paintComponent(final Graphics g) {
// public void paint(final Graphics g) {
// Update to below: paintComponent seems to work fine too
// We go against Sun's advice and override
// paint() instead of paintComponent(). Scrollbars
// do not repaint correctly if we use
Expand Down
15 changes: 15 additions & 0 deletions src/HTML_Renderer/org/lobobrowser/html/js/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -1452,9 +1452,24 @@ public void run() {
// jobsOver.set(true);
}

/*
@PropertyName("Element")
public Class<Element> getElement() {
return Element.class;
}*/

/* changed from above For prototype.js */
private Object element = Element.class;

@PropertyName("Element")
public Object getElement() {
return element;
}

@PropertyName("Element")
public void setElement(final Object o) {
System.out.println("Setting element to: " + o);
element = o;
}

@PropertyName("Node")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Insets;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.security.AccessController;
import java.security.PrivilegedAction;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;
Expand All @@ -42,6 +46,23 @@ public InputTextAreaControl(final HTMLBaseInputElement modelNode) {
super(modelNode);
this.setLayout(WrapperLayout.getInstance());
final JTextComponent widget = this.createTextField();
widget.addKeyListener(new KeyListener() {

@Override
public void keyTyped(final KeyEvent e) {
System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyTyped()" + e);
}

@Override
public void keyReleased(final KeyEvent e) {
System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyReleased()" + e);
}

@Override
public void keyPressed(final KeyEvent e) {
System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyPressed(): " + e);
}
});
this.widget = widget;
this.add(new JScrollPane(widget));

Expand Down Expand Up @@ -78,7 +99,16 @@ public void reset(final int availWidth, final int availHeight) {
}

protected JTextComponent createTextField() {
return new JTextArea();
// Creating with privileges; otherwise the AWT events generated for this component
// capture the current stack of priviliges. If the component is created from javascript
// it fails for AccessController.checkPermission('accessClipboard')
return AccessController.doPrivileged(new PrivilegedAction<JTextComponent>() {

@Override
public JTextComponent run() {
return new JTextArea();
}
});
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JTextField;
import javax.swing.text.JTextComponent;
Expand All @@ -35,6 +37,22 @@ class InputTextControl extends BaseInputTextControl {
public InputTextControl(final HTMLBaseInputElement modelNode) {
super(modelNode);
final JTextField w = (JTextField) this.widget;
w.addKeyListener(new KeyListener() {
@Override
public void keyTyped(final KeyEvent e) {
// System.out.println("typed: " + e);
}

@Override
public void keyReleased(final KeyEvent e) {
HtmlController.getInstance().onKeyUp(modelNode, e);
}

@Override
public void keyPressed(final KeyEvent e) {
// System.out.println("pressed: " + e);
}
});
w.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
HtmlController.getInstance().onEnterPressed(modelNode, null);
Expand Down
6 changes: 4 additions & 2 deletions src/HTML_Renderer/org/lobobrowser/html/renderer/RBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,11 @@ private final LayoutValue forceLayout(final RenderState renderState, final int a
// Expected to be invoked in the GUI thread.
// TODO: Not necessary to do full layout if only expandWidth or
// expandHeight change (specifically in tables).
RenderState rs = renderState;
final RenderState rs = renderState;
if (rs == null) {
rs = new BlockRenderState(null);
// Doesn't seem to be null ever
throw new IllegalStateException("rs was null");
// rs = new BlockRenderState(null);
}

// // Clear adjust() cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2362,10 +2362,10 @@ public void layoutMarkup(final RBlockViewport bodyLayout, final HTMLElementImpl
}
}
}
final UINode node = markupElement.getUINode();
switch (display) {
case DISPLAY_NONE:
// skip it completely.
final UINode node = markupElement.getUINode();
if (node instanceof BaseBoundableRenderable) {
// This is necessary so that if the element is made
// visible again, it can be invalidated.
Expand All @@ -2374,16 +2374,24 @@ public void layoutMarkup(final RBlockViewport bodyLayout, final HTMLElementImpl
break;
case DISPLAY_BLOCK:
//TODO refer issue #87
if (node instanceof RTable) {
bodyLayout.layoutRTable(markupElement);
} else {
bodyLayout.layoutRBlock(markupElement);
}
break;
case DISPLAY_LIST_ITEM:
final String tagName = markupElement.getTagName();
if ("UL".equalsIgnoreCase(tagName) || "OL".equalsIgnoreCase(tagName)) {
bodyLayout.layoutList(markupElement);
} else {
bodyLayout.layoutRBlock(markupElement);
// bodyLayout.layoutRBlock(markupElement);
bodyLayout.layoutListItem(markupElement);
}
break;
case DISPLAY_LIST_ITEM:
/*case DISPLAY_LIST_ITEM:
bodyLayout.layoutListItem(markupElement);
break;
break;*/
case DISPLAY_TABLE:
bodyLayout.layoutRTable(markupElement);
break;
Expand Down
Loading

0 comments on commit c206151

Please sign in to comment.