Skip to content

Commit

Permalink
Squashed commits from uglyPatches
Browse files Browse the repository at this point in the history
  • Loading branch information
hrj committed Jan 7, 2015
1 parent b3c48cb commit c641c42
Show file tree
Hide file tree
Showing 81 changed files with 3,091 additions and 573 deletions.
4 changes: 2 additions & 2 deletions src/Common/org/lobobrowser/util/WeakValueHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public Collection<V> values() {
checkQueue();
final Stream<V> m =
this.map.values().stream()
.map(t -> t == null ? null : t.get())
.filter(t -> t != null);
.map(t -> t == null ? null : t.get())
.filter(t -> t != null);
return m.collect(Collectors.toList());
}

Expand Down
16 changes: 8 additions & 8 deletions src/Common/org/lobobrowser/util/io/IORoutines.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static byte[] load(final File file) throws IOException {
throw new IOException("File '" + file.getName() + "' too big");
}
try (
final InputStream in = new FileInputStream(file)) {
final InputStream in = new FileInputStream(file)) {
return loadExact(in, (int) fileLength);
}
}
Expand Down Expand Up @@ -137,15 +137,15 @@ public static boolean equalContent(final File file, final byte[] content) throws
}

try (
final InputStream in = new FileInputStream(file);) {
final InputStream in = new FileInputStream(file);) {
final byte[] fileContent = loadExact(in, (int) length);
return java.util.Arrays.equals(content, fileContent);
}
}

public static void save(final File file, final byte[] content) throws IOException {
try (
final FileOutputStream out = new FileOutputStream(file);) {
final FileOutputStream out = new FileOutputStream(file);) {
out.write(content);
}
}
Expand Down Expand Up @@ -179,18 +179,18 @@ public static void touch(final File file) {

public static void saveStrings(final File file, final Collection<String> list) throws IOException {
try (
final FileOutputStream fout = new FileOutputStream(file);
final BufferedOutputStream bout = new BufferedOutputStream(fout);
final PrintWriter writer = new PrintWriter(bout)) {
final FileOutputStream fout = new FileOutputStream(file);
final BufferedOutputStream bout = new BufferedOutputStream(fout);
final PrintWriter writer = new PrintWriter(bout)) {
list.forEach(text -> writer.println(text));
writer.flush();
}
}

public static java.util.List<String> loadStrings(final File file) throws IOException {
try (
final InputStream in = new FileInputStream(file);
final BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
final InputStream in = new FileInputStream(file);
final BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
return reader.lines().collect(Collectors.toList());
}
}
Expand Down
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 @@ -78,4 +81,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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import java.util.Map;

import org.lobobrowser.js.AbstractScriptableDelegate;
import org.lobobrowser.js.JavaScript;
import org.lobobrowser.util.Nodes;
import org.lobobrowser.util.Objects;
import org.w3c.dom.Node;
import org.w3c.dom.html.HTMLCollection;

Expand Down Expand Up @@ -116,6 +118,31 @@ public Node item(final int index) {
}
}

public Node item(final Object obj) {
// Assuming that non integer calls are supposed to be treated as zero, as per this test:
// https://github.com/w3c/web-platform-tests/blob/master/dom/nodes/Element-children.html#L10
// Reported bug https://github.com/w3c/web-platform-tests/issues/1264
if (obj instanceof Integer) {
final Integer index = (Integer) obj;
return item((int) index);
}
return item(0);
}

/* Quick hack to get w3c tests working. This function very likely needs to
* be included for every JS object. */
public boolean hasOwnProperty(final Object obj) {
System.out.println("Checking " + obj);
if (Objects.isAssignableOrBox(obj, Integer.TYPE)) {
// if (obj instanceof Integer) {
final Integer i = (Integer) JavaScript.getInstance().getJavaObject(obj, Integer.TYPE);
// final Integer i = (Integer) obj;
return i < getLength();
} else {
return false;
}
}

public Node namedItem(final String name) {
synchronized (this.treeLock) {
this.ensurePopulatedImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;

public class DocumentFragmentImpl extends NodeImpl implements DocumentFragment {
public class DocumentFragmentImpl extends ElementImpl implements DocumentFragment {
public DocumentFragmentImpl() {
super();
super("#document-fragment");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public final HTMLElement createElement(final HTMLDocumentImpl document, final St
final HTMLElementBuilder builder = this.builders.get(normalName);
if (builder == null) {
// TODO: IE would assume name is html text here?
// TODO: ^^ Other browsers throw an exception if there are illegal characters in the name.
// But am not sure what the legal character set is. Characters like angle-brackets
// do throw an exception in Chromium and Firefox. - hrj
final HTMLElementImpl element = new HTMLElementImpl(name);
element.setOwnerDocument(document);
return element;
Expand Down
61 changes: 52 additions & 9 deletions src/HTML_Renderer/org/lobobrowser/html/domimpl/ElementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,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 @@ -171,6 +171,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 @@ -206,15 +207,18 @@ public TypeInfo getSchemaTypeInfo() {
}

public String getTagName() {
return this.getNodeName();
// In HTML, tag names are supposed to be returned in upper-case, but in XHTML they are returned in original case
// as per https://developer.mozilla.org/en-US/docs/Web/API/Element.tagName
return this.getNodeName().toUpperCase();
}

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 All @@ -238,6 +242,8 @@ public void removeAttributeNS(final String namespaceURI, final String localName)
}

protected void assignAttributeField(final String normalName, final String value) {
// Not sure why id and name were conflated in this code: they are orthogonal.

// Note: overriders assume that processing here is only done after
// checking attribute names, i.e. they may not call the super
// implementation if an attribute is already taken care of.
Expand Down Expand Up @@ -531,4 +537,41 @@ private void updateIdMap(final String oldIdValue, final String newIdValue) {
}
}
}

// TODO: Need to implement these for Document and DocumentFragment as well as per https://developer.mozilla.org/en-US/docs/Web/API/ParentNode
public Element getFirstElementChild() {
final ArrayList<Node> nl = this.nodeList;
for (final Node n : nl) {
if (n instanceof Element) {
return (Element) n;
}
}

return null;
}

public Element getLastElementChild() {
final ArrayList<Node> nl = this.nodeList;
final int N = nl.size();
for (int i = N - 1; i >= 0; i--) {
final Node n = nl.get(i);
if (n instanceof Element) {
return (Element) n;
}
}

return null;
}

public int getChildElementCount() {
final ArrayList<Node> nl = this.nodeList;
int count = 0;
for (final Node n : nl) {
if (n instanceof Element) {
count++;
}
}

return count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.logging.Level;

import org.lobobrowser.html.js.Executor;
import org.lobobrowser.html.js.Window;
import org.lobobrowser.js.JavaScript;
import org.lobobrowser.ua.UserAgentContext;
import org.mozilla.javascript.Context;
Expand Down Expand Up @@ -170,12 +171,12 @@ protected Function getEventFunction(final Function varValue, final String attrib
if (doc == null) {
throw new IllegalStateException("Element does not belong to a document.");
}
final Context ctx = Executor.createContext(this.getDocumentURL(), uac);
final Window window = ((HTMLDocumentImpl) doc).getWindow();
final Context ctx = Executor.createContext(this.getDocumentURL(), uac, window.windowFactory);
try {
final Scriptable scope = (Scriptable) doc.getUserData(Executor.SCOPE_KEY);
final Scriptable scope = window.getWindowScope();
if (scope == null) {
throw new IllegalStateException("Scriptable (scope) instance was expected to be keyed as UserData to document using "
+ Executor.SCOPE_KEY);
throw new IllegalStateException("Scriptable (scope) instance was null");
}
final Scriptable thisScope = (Scriptable) JavaScript.getInstance().getJavascriptObject(this, scope);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import java.util.ArrayList;

import org.lobobrowser.html.FormInput;
import org.lobobrowser.html.js.Executor;
import org.lobobrowser.html.js.Event;
import org.lobobrowser.html.js.NotGetterSetter;
import org.mozilla.javascript.Function;
import org.w3c.dom.Node;
import org.w3c.dom.html.HTMLFormElement;
Expand Down Expand Up @@ -381,11 +382,16 @@ private void dispatchEvent(final String expectedImgSrc, final ImageEvent event)
// Inform listener, holding no lock.
listenerArray[i].imageLoaded(event);
}

// TODO: With this change, setOnLoad method should add a listener with dispatch mechanism. Best implemented in a parent class.
dispatchEvent(new Event("load", this));

/*
final Function onload = this.getOnload();
if (onload != null) {
// TODO: onload event object?
Executor.executeFunction(HTMLBaseInputElement.this, onload, null);
}
}*/
}

private class LocalImageListener implements ImageListener {
Expand All @@ -398,6 +404,14 @@ public LocalImageListener(final String imgSrc) {
public void imageLoaded(final ImageEvent event) {
dispatchEvent(this.expectedImgSrc, event);
}

public void imageAborted() {
// Do nothing
}
}

@NotGetterSetter
public void setCustomValidity(final String message) {
System.out.println("HTMLBaseInputElement.setCustomValidity() " + message);
}
}
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();
}
}
Loading

0 comments on commit c641c42

Please sign in to comment.