Skip to content

Commit c206151

Browse files
committed
squashed commit of curr/jsUgly2 and curr/misc3 branches
1 parent 8bae532 commit c206151

26 files changed

+253
-51
lines changed

src/HTML_Renderer/org/lobobrowser/html/BrowserFrame.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import java.awt.Component;
2727
import java.net.URL;
2828

29+
import org.lobobrowser.ua.ParameterInfo;
30+
import org.lobobrowser.ua.RequestType;
31+
import org.lobobrowser.ua.TargetType;
2932
import org.w3c.dom.Document;
3033

3134
/**
@@ -83,4 +86,7 @@ public interface BrowserFrame {
8386
* See constants in {@link org.lobobrowser.html.style.RenderState}.
8487
*/
8588
public void setDefaultOverflowY(int overflowY);
89+
90+
// Trying out a way for a frame's target to be set to an iframe. for issue #96
91+
public void navigate(URL url, String method, ParameterInfo pinfo, TargetType targetType, RequestType form);
8692
}

src/HTML_Renderer/org/lobobrowser/html/domimpl/ElementImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ public void setDir(final String dir) {
143143

144144
public final String getAttribute(final String name) {
145145
final String normalName = normalizeAttributeName(name);
146-
synchronized (this) {
147-
final Map<String, String> attributes = this.attributes;
148-
return attributes == null ? null : attributes.get(normalName);
149-
}
146+
// synchronized (this) {
147+
final Map<String, String> attributes = this.attributes;
148+
return attributes == null ? null : attributes.get(normalName);
149+
// }
150150
}
151151

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

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

218219
public boolean hasAttribute(final String name) {
219220
final String normalName = normalizeAttributeName(name);
220-
synchronized (this) {
221-
final Map<String, String> attributes = this.attributes;
222-
return attributes == null ? false : attributes.containsKey(normalName);
223-
}
221+
// This was causing deadlocks, hence removed the sync
222+
// synchronized (this) {
223+
final Map<String, String> attributes = this.attributes;
224+
return attributes == null ? false : attributes.containsKey(normalName);
225+
// }
224226
}
225227

226228
public boolean hasAttributeNS(final String namespaceURI, final String localName) throws DOMException {

src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLButtonElementImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ public class HTMLButtonElementImpl extends HTMLBaseInputElement {
2424
public HTMLButtonElementImpl(final String name) {
2525
super(name);
2626
}
27+
28+
public void click() {
29+
// TODO: see issue #95
30+
System.out.println("Button clicked. TODO");
31+
// inputContext.click();
32+
}
2733
}

src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLDocumentImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public HTMLDocumentImpl(final UserAgentContext ucontext, final HtmlRendererConte
159159
// with setCookie() method.
160160
final String protocol = docURL.getProtocol();
161161
if ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) {
162-
sm.checkPermission(new java.net.SocketPermission(docURL.getHost(), "connect"));
162+
sm.checkPermission(new java.net.SocketPermission(docURL.getHost(), "connect"));
163163
}
164164
}
165165
this.documentURL = docURL;
@@ -264,6 +264,7 @@ public void setDefaultTarget(final String value) {
264264
this.defaultTarget = value;
265265
}
266266

267+
// TODO: Is this required? Check JS DOM specs.
267268
public AbstractView getDefaultView() {
268269
return this.window;
269270
}
@@ -399,16 +400,19 @@ public String getCookie() {
399400
}
400401

401402
public void setCookie(final String cookie) throws DOMException {
403+
// Update in gngr: Whoa! No, we won't allow the privilege escalation below until better justification is presented ;)
404+
// Chagned for Issue #78
405+
402406
// Justification: A caller (e.g. Google Analytics script)
403407
// might want to set cookies on the parent document.
404408
// If the caller has access to the document, it appears
405409
// they should be able to set cookies on that document.
406410
// Note that this Document instance cannot be created
407411
// with an arbitrary URL.
408-
SecurityUtil.doPrivileged(() -> {
409-
ucontext.setCookie(documentURL, cookie);
410-
return null;
411-
});
412+
// SecurityUtil.doPrivileged(() -> {
413+
ucontext.setCookie(documentURL, cookie);
414+
// return null;
415+
// });
412416
}
413417

414418
public void open() {
@@ -630,6 +634,7 @@ public EntityReference createEntityReference(final String name) throws DOMExcept
630634
* The element tag name or an asterisk character (*) to match all
631635
* elements.
632636
*/
637+
@Override
633638
public NodeList getElementsByTagName(final String tagname) {
634639
if ("*".equals(tagname)) {
635640
return this.getNodeList(new ElementFilter());

src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLElementImpl.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
import org.w3c.dom.DOMException;
5454
import org.w3c.dom.Node;
5555
import org.w3c.dom.NodeList;
56+
import org.w3c.dom.events.Event;
57+
import org.w3c.dom.events.EventException;
58+
import org.w3c.dom.events.EventListener;
59+
import org.w3c.dom.events.EventTarget;
5660
import org.w3c.dom.html.HTMLElement;
5761
import org.w3c.dom.html.HTMLFormElement;
5862

@@ -73,7 +77,7 @@
7377
import cz.vutbr.web.domassign.Analyzer.OrderedRule;
7478
import cz.vutbr.web.domassign.AnalyzerUtil;
7579

76-
public class HTMLElementImpl extends ElementImpl implements HTMLElement, CSS2PropertiesContext {
80+
public class HTMLElementImpl extends ElementImpl implements HTMLElement, CSS2PropertiesContext, EventTarget {
7781
private final boolean noStyleSheet;
7882
private static final MatchConditionOnElements elementMatchCondition = new MatchConditionOnElements();
7983

@@ -315,6 +319,9 @@ protected void assignAttributeField(final String normalName, final String value)
315319
} else {
316320
if ("style".equals(normalName)) {
317321
this.forgetLocalStyle();
322+
// informDocumentInvalid();
323+
// informLayoutInvalid();
324+
// invalidateDescendentsForHover();
318325
}
319326
}
320327
super.assignAttributeField(normalName, value);
@@ -923,4 +930,22 @@ public boolean toggle(final String token, final boolean force) {
923930
/* TODO: stringifier; */
924931
}
925932

933+
@Override
934+
public void addEventListener(final String type, final EventListener listener, final boolean useCapture) {
935+
// TODO Auto-generated method stub
936+
throw new UnsupportedOperationException();
937+
}
938+
939+
@Override
940+
public void removeEventListener(final String type, final EventListener listener, final boolean useCapture) {
941+
// TODO Auto-generated method stub
942+
throw new UnsupportedOperationException();
943+
}
944+
945+
@Override
946+
public boolean dispatchEvent(final Event evt) throws EventException {
947+
// TODO Auto-generated method stub
948+
throw new UnsupportedOperationException();
949+
// return false;
950+
}
926951
}

src/HTML_Renderer/org/lobobrowser/html/domimpl/HTMLIFrameElementImpl.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import org.lobobrowser.html.style.IFrameRenderState;
1111
import org.lobobrowser.html.style.RenderState;
1212
import org.lobobrowser.js.HideFromJS;
13+
import org.lobobrowser.ua.ParameterInfo;
14+
import org.lobobrowser.ua.RequestType;
15+
import org.lobobrowser.ua.TargetType;
1316
import org.lobobrowser.ua.UserAgentContext.Request;
1417
import org.lobobrowser.ua.UserAgentContext.RequestKind;
1518
import org.mozilla.javascript.Function;
@@ -269,4 +272,34 @@ public void run() {
269272
protected RenderState createRenderState(final RenderState prevRenderState) {
270273
return new IFrameRenderState(prevRenderState, this);
271274
}
275+
276+
// Trying out a way for a frame's target to be set to an iframe. for issue #96
277+
278+
public void navigate(final URL url, final String method, final ParameterInfo pinfo, final TargetType targetType, final RequestType form) {
279+
final Window window = ((HTMLDocumentImpl) document).getWindow();
280+
window.addJSTask(new JSRunnableTask(0, "Frame navigation to " + url, () -> {
281+
final BrowserFrame frame = this.browserFrame;
282+
if (frame != null) {
283+
if (getUserAgentContext().isRequestPermitted(new Request(url, RequestKind.Frame))) {
284+
frame.getHtmlRendererContext().setJobFinishedHandler(new Runnable() {
285+
public void run() {
286+
System.out.println("Iframes window's job over!");
287+
if (onload != null) {
288+
// TODO: onload event object?
289+
final Window window = ((HTMLDocumentImpl) document).getWindow();
290+
window.addJSTask(new JSRunnableTask(0, "IFrame onload handler", () -> {
291+
Executor.executeFunction(HTMLIFrameElementImpl.this, onload, null, window.getContextFactory());
292+
}));
293+
}
294+
// markJobDone();
295+
}
296+
});
297+
// frame.loadURL(fullURL);
298+
browserFrame.navigate(url, method, pinfo, targetType, form);
299+
}
300+
// browserFrame.navigate(url, method, pinfo, targetType, form);
301+
}
302+
}
303+
));
304+
}
272305
}

src/HTML_Renderer/org/lobobrowser/html/gui/HtmlBlockPanel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,10 @@ private void onMouseMoved(final MouseEvent event) {
646646
*
647647
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
648648
*/
649-
// protected void paintComponent(Graphics g) {
650649
@Override
651-
public void paint(final Graphics g) {
650+
protected void paintComponent(final Graphics g) {
651+
// public void paint(final Graphics g) {
652+
// Update to below: paintComponent seems to work fine too
652653
// We go against Sun's advice and override
653654
// paint() instead of paintComponent(). Scrollbars
654655
// do not repaint correctly if we use

src/HTML_Renderer/org/lobobrowser/html/js/Window.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,9 +1452,24 @@ public void run() {
14521452
// jobsOver.set(true);
14531453
}
14541454

1455+
/*
14551456
@PropertyName("Element")
14561457
public Class<Element> getElement() {
14571458
return Element.class;
1459+
}*/
1460+
1461+
/* changed from above For prototype.js */
1462+
private Object element = Element.class;
1463+
1464+
@PropertyName("Element")
1465+
public Object getElement() {
1466+
return element;
1467+
}
1468+
1469+
@PropertyName("Element")
1470+
public void setElement(final Object o) {
1471+
System.out.println("Setting element to: " + o);
1472+
element = o;
14581473
}
14591474

14601475
@PropertyName("Node")

src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextAreaControl.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
import java.awt.Font;
2727
import java.awt.FontMetrics;
2828
import java.awt.Insets;
29+
import java.awt.event.KeyEvent;
30+
import java.awt.event.KeyListener;
31+
import java.security.AccessController;
32+
import java.security.PrivilegedAction;
2933

3034
import javax.swing.JScrollPane;
3135
import javax.swing.JTextArea;
@@ -42,6 +46,23 @@ public InputTextAreaControl(final HTMLBaseInputElement modelNode) {
4246
super(modelNode);
4347
this.setLayout(WrapperLayout.getInstance());
4448
final JTextComponent widget = this.createTextField();
49+
widget.addKeyListener(new KeyListener() {
50+
51+
@Override
52+
public void keyTyped(final KeyEvent e) {
53+
System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyTyped()" + e);
54+
}
55+
56+
@Override
57+
public void keyReleased(final KeyEvent e) {
58+
System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyReleased()" + e);
59+
}
60+
61+
@Override
62+
public void keyPressed(final KeyEvent e) {
63+
System.out.println("InputTextAreaControl.InputTextAreaControl(...).new KeyListener() {...}.keyPressed(): " + e);
64+
}
65+
});
4566
this.widget = widget;
4667
this.add(new JScrollPane(widget));
4768

@@ -78,7 +99,16 @@ public void reset(final int availWidth, final int availHeight) {
7899
}
79100

80101
protected JTextComponent createTextField() {
81-
return new JTextArea();
102+
// Creating with privileges; otherwise the AWT events generated for this component
103+
// capture the current stack of priviliges. If the component is created from javascript
104+
// it fails for AccessController.checkPermission('accessClipboard')
105+
return AccessController.doPrivileged(new PrivilegedAction<JTextComponent>() {
106+
107+
@Override
108+
public JTextComponent run() {
109+
return new JTextArea();
110+
}
111+
});
82112
}
83113

84114
/*

src/HTML_Renderer/org/lobobrowser/html/renderer/InputTextControl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import java.awt.event.ActionEvent;
2727
import java.awt.event.ActionListener;
28+
import java.awt.event.KeyEvent;
29+
import java.awt.event.KeyListener;
2830

2931
import javax.swing.JTextField;
3032
import javax.swing.text.JTextComponent;
@@ -35,6 +37,22 @@ class InputTextControl extends BaseInputTextControl {
3537
public InputTextControl(final HTMLBaseInputElement modelNode) {
3638
super(modelNode);
3739
final JTextField w = (JTextField) this.widget;
40+
w.addKeyListener(new KeyListener() {
41+
@Override
42+
public void keyTyped(final KeyEvent e) {
43+
// System.out.println("typed: " + e);
44+
}
45+
46+
@Override
47+
public void keyReleased(final KeyEvent e) {
48+
HtmlController.getInstance().onKeyUp(modelNode, e);
49+
}
50+
51+
@Override
52+
public void keyPressed(final KeyEvent e) {
53+
// System.out.println("pressed: " + e);
54+
}
55+
});
3856
w.addActionListener(new ActionListener() {
3957
public void actionPerformed(final ActionEvent event) {
4058
HtmlController.getInstance().onEnterPressed(modelNode, null);

src/HTML_Renderer/org/lobobrowser/html/renderer/RBlock.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,11 @@ private final LayoutValue forceLayout(final RenderState renderState, final int a
490490
// Expected to be invoked in the GUI thread.
491491
// TODO: Not necessary to do full layout if only expandWidth or
492492
// expandHeight change (specifically in tables).
493-
RenderState rs = renderState;
493+
final RenderState rs = renderState;
494494
if (rs == null) {
495-
rs = new BlockRenderState(null);
495+
// Doesn't seem to be null ever
496+
throw new IllegalStateException("rs was null");
497+
// rs = new BlockRenderState(null);
496498
}
497499

498500
// // Clear adjust() cache.

src/HTML_Renderer/org/lobobrowser/html/renderer/RBlockViewport.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,10 +2362,10 @@ public void layoutMarkup(final RBlockViewport bodyLayout, final HTMLElementImpl
23622362
}
23632363
}
23642364
}
2365+
final UINode node = markupElement.getUINode();
23652366
switch (display) {
23662367
case DISPLAY_NONE:
23672368
// skip it completely.
2368-
final UINode node = markupElement.getUINode();
23692369
if (node instanceof BaseBoundableRenderable) {
23702370
// This is necessary so that if the element is made
23712371
// visible again, it can be invalidated.
@@ -2374,16 +2374,24 @@ public void layoutMarkup(final RBlockViewport bodyLayout, final HTMLElementImpl
23742374
break;
23752375
case DISPLAY_BLOCK:
23762376
//TODO refer issue #87
2377+
if (node instanceof RTable) {
2378+
bodyLayout.layoutRTable(markupElement);
2379+
} else {
2380+
bodyLayout.layoutRBlock(markupElement);
2381+
}
2382+
break;
2383+
case DISPLAY_LIST_ITEM:
23772384
final String tagName = markupElement.getTagName();
23782385
if ("UL".equalsIgnoreCase(tagName) || "OL".equalsIgnoreCase(tagName)) {
23792386
bodyLayout.layoutList(markupElement);
23802387
} else {
2381-
bodyLayout.layoutRBlock(markupElement);
2388+
// bodyLayout.layoutRBlock(markupElement);
2389+
bodyLayout.layoutListItem(markupElement);
23822390
}
23832391
break;
2384-
case DISPLAY_LIST_ITEM:
2392+
/*case DISPLAY_LIST_ITEM:
23852393
bodyLayout.layoutListItem(markupElement);
2386-
break;
2394+
break;*/
23872395
case DISPLAY_TABLE:
23882396
bodyLayout.layoutRTable(markupElement);
23892397
break;

0 commit comments

Comments
 (0)