1 package org.lobobrowser.html.renderer; 2 3 import org.lobobrowser.html.*; 4 import org.lobobrowser.html.domimpl.*; 5 import org.lobobrowser.html.js.*; 6 import org.mozilla.javascript.*; 7 import java.util.logging.*; 8 import java.awt.event.*; 9 10 class HtmlController implements Controller { 11 private static final Logger logger = Logger.getLogger(HtmlController.class.getName()); 12 private static final HtmlController instance = new HtmlController(); 13 14 public static HtmlController getInstance() { 15 return instance; 16 } 17 18 21 public boolean onEnterPressed(ModelNode node, InputEvent event) { 22 if(node instanceof HTMLInputElementImpl) { 23 HTMLInputElementImpl hie = (HTMLInputElementImpl) node; 24 if(hie.isSubmittableWithEnterKey()) { 25 hie.submitForm(null); 26 return false; 27 } 28 } 29 return false; 31 } 32 33 36 public boolean onMouseClick(ModelNode node, MouseEvent event, int x, int y) { 37 if(logger.isLoggable(Level.INFO)) { 38 logger.info("onMouseClick(): node=" + node + ",class=" + node.getClass().getName()); 39 } 40 if(node instanceof HTMLAbstractUIElement) { 41 HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node; 42 Function f = uiElement.getOnclick(); 43 if(f != null) { 44 Event jsEvent = new Event("click", uiElement, event, x, y); 45 if(!Executor.executeFunction(uiElement, f, jsEvent)) { 46 return false; 47 } 48 } 49 } 50 if(node instanceof HTMLLinkElementImpl) { 51 ((HTMLLinkElementImpl) node).navigate(); 52 return false; 53 } 54 else if(node instanceof HTMLButtonElementImpl) { 55 HTMLButtonElementImpl button = (HTMLButtonElementImpl) node; 56 String rawType = button.getAttribute("type"); 57 String type; 58 if(rawType == null) { 59 type = "submit"; 60 } 61 else { 62 type = rawType.trim().toLowerCase(); 63 } 64 if("submit".equals(type)) { 65 FormInput[] formInputs; 66 String name = button.getName(); 67 if(name == null) { 68 formInputs = null; 69 } 70 else { 71 formInputs = new FormInput[] { new FormInput(name, button.getValue()) }; 72 } 73 button.submitForm(formInputs); 74 } 75 else if("reset".equals(type)) { 76 button.resetForm(); 77 } 78 else { 79 } 81 return false; 82 } 83 ModelNode parent = node.getParentModelNode(); 84 if(parent == null) { 85 return true; 86 } 87 return this.onMouseClick(parent, event, x, y); 88 } 89 90 93 public boolean onDoubleClick(ModelNode node, MouseEvent event, int x, int y) { 94 if(logger.isLoggable(Level.INFO)) { 95 logger.info("onDoubleClick(): node=" + node + ",class=" + node.getClass().getName()); 96 } 97 if(node instanceof HTMLAbstractUIElement) { 98 HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node; 99 Function f = uiElement.getOndblclick(); 100 if(f != null) { 101 Event jsEvent = new Event("dblclick", uiElement, event, x, y); 102 if(!Executor.executeFunction(uiElement, f, jsEvent)) { 103 return false; 104 } 105 } 106 } 107 ModelNode parent = node.getParentModelNode(); 108 if(parent == null) { 109 return true; 110 } 111 return this.onDoubleClick(parent, event, x, y); 112 } 113 114 117 public boolean onMouseDisarmed(ModelNode node, MouseEvent event) { 118 if(node instanceof HTMLLinkElementImpl) { 119 ((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor(null); 120 return false; 121 } 122 ModelNode parent = node.getParentModelNode(); 123 if(parent == null) { 124 return true; 125 } 126 return this.onMouseDisarmed(parent, event); 127 } 128 129 132 public boolean onMouseDown(ModelNode node, MouseEvent event, int x, int y) { 133 boolean pass = true; 134 if(node instanceof HTMLAbstractUIElement) { 135 HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node; 136 Function f = uiElement.getOnmousedown(); 137 if(f != null) { 138 Event jsEvent = new Event("mousedown", uiElement, event, x, y); 139 pass = Executor.executeFunction(uiElement, f, jsEvent); 140 } 141 } 142 if(node instanceof HTMLLinkElementImpl) { 143 ((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor("#9090FF80"); 144 return false; 145 } 146 if(!pass) { 147 return false; 148 } 149 ModelNode parent = node.getParentModelNode(); 150 if(parent == null) { 151 return true; 152 } 153 return this.onMouseDown(parent, event, x, y); 154 } 155 156 159 public boolean onMouseUp(ModelNode node, MouseEvent event, int x, int y) { 160 boolean pass = true; 161 if(node instanceof HTMLAbstractUIElement) { 162 HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node; 163 Function f = uiElement.getOnmouseup(); 164 if(f != null) { 165 Event jsEvent = new Event("mouseup", uiElement, event, x, y); 166 pass = Executor.executeFunction(uiElement, f, jsEvent); 167 } 168 } 169 if(node instanceof HTMLLinkElementImpl) { 170 ((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor(null); 171 return false; 172 } 173 if(!pass) { 174 return false; 175 } 176 ModelNode parent = node.getParentModelNode(); 177 if(parent == null) { 178 return true; 179 } 180 return this.onMouseUp(parent, event, x, y); 181 } 182 183 189 public boolean onPressed(ModelNode node, InputEvent event, int x, int y) { 190 if(node instanceof HTMLAbstractUIElement) { 191 HTMLAbstractUIElement uiElement = (HTMLAbstractUIElement) node; 192 Function f = uiElement.getOnclick(); 193 if(f != null) { 194 Event jsEvent = new Event("click", uiElement, event, x, y); 195 if(!Executor.executeFunction(uiElement, f, jsEvent)) { 196 return false; 197 } 198 } 199 } 200 if(node instanceof HTMLInputElementImpl) { 201 HTMLInputElementImpl hie = (HTMLInputElementImpl) node; 202 if(hie.isSubmitInput()) { 203 FormInput[] formInputs; 204 String name = hie.getName(); 205 if(name == null) { 206 formInputs = null; 207 } 208 else { 209 formInputs = new FormInput[] { new FormInput(name, hie.getValue()) }; 210 } 211 hie.submitForm(formInputs); 212 } 213 else if(hie.isImageInput()) { 214 String name = hie.getName(); 215 String prefix = name == null ? "" : name + "."; 216 FormInput[] extraFormInputs = new FormInput[] { 217 new FormInput(prefix + "x", String.valueOf(x)), 218 new FormInput(prefix + "y", String.valueOf(y)) 219 }; 220 hie.submitForm(extraFormInputs); 221 } 222 else if(hie.isResetInput()) { 223 hie.resetForm(); 224 } 225 } 226 return false; 228 } 229 } 230 | Popular Tags |