com.gargoylesoftware.htmlunit.javascript.host.Window类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 JavaScript  
字(11.3k)|赞(0)|评价(0)|浏览(210)

本文整理了Java中com.gargoylesoftware.htmlunit.javascript.host.Window类的一些代码示例,展示了Window类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window类的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.javascript.host.Window
类名称:Window

Window介绍

[英]A JavaScript object for Window.
[中]窗口的JavaScript对象。

代码示例

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Executes the event on this object only (needed for instance for onload on (i)frame tags).
 * @param event the event
 * @see #fireEvent(Event)
 */
public void executeEventLocally(final Event event) {
  final EventListenersContainer eventListenersContainer = getEventListenersContainer();
  final Window window = getWindow();
  final Object[] args = new Object[] {event};
  final Event previousEvent = window.getCurrentEvent();
  window.setCurrentEvent(event);
  try {
    event.setEventPhase(Event.AT_TARGET);
    eventListenersContainer.executeAtTargetListeners(event, args);
  }
  finally {
    window.setCurrentEvent(previousEvent); // reset event
  }
}

代码示例来源:origin: org.jvnet.hudson/htmlunit

/**
 * Allows the registration of event listeners on the event target.
 * @param type the event type to listen for (like "onload")
 * @param listener the event listener
 * @param useCapture If <code>true</code>, indicates that the user wishes to initiate capture (not yet implemented)
 * @see <a href="http://developer.mozilla.org/en/docs/DOM:element.addEventListener">Mozilla documentation</a>
 */
public void jsxFunction_addEventListener(final String type, final Function listener, final boolean useCapture) {
  getEventListenersContainer().addEventListener(type, listener, useCapture);
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@SuppressWarnings("unchecked")
private static Scriptable staticGetPrototype(final Window window,
    final Class<? extends SimpleScriptable> javaScriptClass) {
  final Scriptable prototype = window.getPrototype(javaScriptClass);
  if (prototype == null && javaScriptClass != SimpleScriptable.class) {
    return staticGetPrototype(window, (Class<? extends SimpleScriptable>) javaScriptClass.getSuperclass());
  }
  return prototype;
}

代码示例来源:origin: org.jenkins-ci/htmlunit

private Object getHandlerForJavaScript(final String eventName) {
  Object handler = getEventListenersContainer().getEventHandlerProp(eventName);
  if (handler == null && !getBrowserVersion().isIE()) {
    handler = Scriptable.NOT_FOUND;
  }
  return handler;
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Initialize the object.
 * @param enclosedPage the page containing the JavaScript
 */
public void initialize(final Page enclosedPage) {
  if (enclosedPage != null && enclosedPage.isHtmlPage()) {
    final HtmlPage htmlPage = (HtmlPage) enclosedPage;
    // Windows don't have corresponding DomNodes so set the domNode
    // variable to be the page. If this isn't set then SimpleScriptable.get()
    // won't work properly
    setDomNode(htmlPage);
    clearEventListenersContainer();
    WebAssert.notNull("document_", document_);
    document_.setDomNode(htmlPage);
  }
}

代码示例来源:origin: net.disy.htmlunit/htmlunit

new HashMap<Class< ? extends SimpleScriptable>, Scriptable>();
final Map<String, Scriptable> prototypesPerJSName = new HashMap<String, Scriptable>();
final Window window = new Window(this);
final JavaScriptConfiguration jsConfig = JavaScriptConfiguration.getInstance(webClient.getBrowserVersion());
context.initStandardObjects(window);
  "JavaImporter", "Continuation"};
for (final String property : undesirableWindowProps) {
  window.delete(property);
    "Namespace", "QName"};
  for (final String property : undesirableWindowPropsIE) {
    window.delete(property);
final Member evalFn = Window.class.getMethod("custom_eval", evalFnTypes);
final FunctionObject jsCustomEval = new FunctionObject("eval", evalFn, window);
window.associateValue("custom_eval", jsCustomEval);
window.setPrototypes(prototypes);
window.initialize(webWindow);

代码示例来源:origin: net.disy.htmlunit/htmlunit

final Event previousEvent = window.getCurrentEvent();
window.setCurrentEvent(event);
  final EventListenersContainer windowsListeners = getWindow().getEventListenersContainer();
  window.setCurrentEvent(previousEvent); // reset event

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

final Map<String, Scriptable> prototypesPerJSName = new HashMap<>();
final Window window = new Window();
((SimpleScriptable) window).setClassName("Window");
context.initStandardObjects(window);
  defineConstructor(window, window, new Window());
window.defineProperty(intl.getClassName(), intl, ScriptableObject.DONTENUM);
intl.defineProperties(browserVersion);
  final Reflect reflect = new Reflect();
  reflect.setParentScope(window);
  window.defineProperty(reflect.getClassName(), reflect, ScriptableObject.DONTENUM);
  reflect.defineProperties();
window.setPrototype(prototypesPerJSName.get(Window.class.getSimpleName()));
    NumberCustom.class, ScriptableObject.DONTENUM);
window.setPrototypes(prototypes, prototypesPerJSName);
window.initialize(webWindow);

代码示例来源:origin: org.jvnet.hudson/htmlunit

/**
 * Creates a modeless dialog box that displays the specified HTML document.
 * @param url the URL of the document to load and display
 * @param arguments object to be made available via <tt>window.dialogArguments</tt> in the dialog window
 * @param features string that specifies the window ornaments for the dialog window
 * @return a reference to the new window object created for the modeless dialog
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536761.aspx">MSDN Documentation</a>
 */
public Object jsxFunction_showModelessDialog(final String url, final Object arguments, final String features) {
  final WebWindow ww = getWebWindow();
  final WebClient client = ww.getWebClient();
  try {
    final URL completeUrl = ((HtmlPage) getDomNodeOrDie()).getFullyQualifiedUrl(url);
    final DialogWindow dialog = client.openDialogWindow(completeUrl, ww, arguments);
    final Window jsDialog = (Window) dialog.getScriptObject();
    return jsDialog;
  }
  catch (final IOException e) {
    throw Context.throwAsScriptRuntimeEx(e);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Sets this location's URL, triggering a server hit and loading the resultant document
 * into this location's window.
 * @param url This location's new URL
 * @throws IOException if there is a problem loading the new location
 */
private void setUrl(final URL url) throws IOException {
  window_.getWebWindow().getWebClient().getPage(window_.getWebWindow(), new WebRequest(url));
}

代码示例来源:origin: org.jvnet.hudson/htmlunit

if (openerPage != null) {
  final Window jsWindow = (Window) window.getScriptObject();
  jsWindow.setDomNode(openerPage);
  jsWindow.jsxGet_document().setDomNode(openerPage);

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Returns the {@code offscreenBuffering} property.
 * @return the {@code offscreenBuffering} property
 */
@JsxGetter({CHROME, IE})
public Object getOffscreenBuffering() {
  if (getBrowserVersion().hasFeature(JS_WINDOW_FRAMES_ACCESSIBLE_BY_ID)) {
    return "auto";
  }
  return true;
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Returns the current HtmlUnit DOM selection ranges.
 * @return the current HtmlUnit DOM selection ranges
 */
private List<Range> getRanges() {
  final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie();
  return page.getSelectionRanges();
}

代码示例来源:origin: net.disy.htmlunit/htmlunit

/**
 * Initialize the object.
 * @param enclosedPage the page containing the JavaScript
 */
public void initialize(final Page enclosedPage) {
  if (enclosedPage instanceof HtmlPage) {
    final HtmlPage htmlPage = (HtmlPage) enclosedPage;
    // Windows don't have corresponding DomNodes so set the domNode
    // variable to be the page. If this isn't set then SimpleScriptable.get()
    // won't work properly
    setDomNode(htmlPage);
    eventListenersContainer_ = null;
    WebAssert.notNull("document_", document_);
    document_.setDomNode(htmlPage);
  }
}

代码示例来源:origin: com.github.seykron/htmlunit-maven-plugin

/** Publishes runner configuration properties to JavaScript's global scope.
  *
  * @param window Window to expose configuration. Cannot be null.
  */
 private void publishConfiguration(
   final com.gargoylesoftware.htmlunit.javascript.host.Window window) {
  Properties config = getContext().getRunnerConfiguration();
  for (Object key : config.keySet()) {
   window.defineProperty((String) key, config.get(key),
     ScriptableObject.READONLY);
  }
 }
}

代码示例来源:origin: org.jvnet.hudson/htmlunit

/**
 * Executes the event on this object only (needed for instance for onload on (i)frame tags).
 * @param event the event
 * @return the result
 */
public ScriptResult executeEvent(final Event event) {
  if (eventListenersContainer_ != null) {
    final HtmlPage page = (HtmlPage) getDomNodeOrDie().getPage();
    final boolean isIE = getBrowserVersion().isIE();
    final Window window = (Window) page.getEnclosingWindow().getScriptObject();
    final Object[] args = new Object[] {event};
    // handlers declared as property on a node don't receive the event as argument for IE
    final Object[] propHandlerArgs;
    if (isIE) {
      propHandlerArgs = ArrayUtils.EMPTY_OBJECT_ARRAY;
    }
    else {
      propHandlerArgs = args;
    }
    window.setCurrentEvent(event);
    try {
      return eventListenersContainer_.executeListeners(event, args, propHandlerArgs);
    }
    finally {
      window.setCurrentEvent(null); // reset event
    }
  }
  return null;
}

代码示例来源:origin: org.jvnet.hudson/htmlunit

/**
 * Submits the form (at the end of the current script execution).
 *
 * @throws IOException if an IO error occurs
 */
public void jsxFunction_submit()
  throws IOException {
  boolean postpone = false;
  final Event currentEvent = getWindow().getCurrentEvent();
  if (currentEvent != null) {
    // Use target instead of srcElement because target is read-only,
    // but srcElement is writable from JavaScript.
    final SimpleScriptable src = (SimpleScriptable) currentEvent.jsxGet_target();
    postpone = src.getDomNodeOrNull() instanceof HtmlSubmitInput;
  }
  if (postpone) {
    final SgmlPage page = getDomNodeOrDie().getPage();
    final JavaScriptEngine jsEngine = page.getWebClient().getJavaScriptEngine();
    final PostponedAction action = new PostponedAction() {
      public void execute() throws IOException {
        getHtmlForm().submit((SubmittableElement) null);
      }
    };
    jsEngine.addPostponedAction(action);
  }
  else {
    getHtmlForm().submit((SubmittableElement) null);
  }
}

代码示例来源:origin: org.jenkins-ci/htmlunit

new HashMap<Class< ? extends SimpleScriptable>, Scriptable>();
final Map<String, Scriptable> prototypesPerJSName = new HashMap<String, Scriptable>();
final Window window = new Window(this);
final JavaScriptConfiguration jsConfig = JavaScriptConfiguration.getInstance(webClient.getBrowserVersion());
context.initStandardObjects(window);
  "JavaImporter", "Continuation"};
for (final String property : undesirableWindowProps) {
  window.delete(property);
    "Namespace", "QName"};
  for (final String property : undesirableWindowPropsIE) {
    window.delete(property);
final Member evalFn = Window.class.getMethod("custom_eval", evalFnTypes);
final FunctionObject jsCustomEval = new FunctionObject("eval", evalFn, window);
window.associateValue("custom_eval", jsCustomEval);
window.setPrototypes(prototypes);
window.initialize(webWindow);

代码示例来源:origin: org.jvnet.hudson/htmlunit

final Event previousEvent = window.getCurrentEvent();
window.setCurrentEvent(event);
  final EventListenersContainer windowsListeners = getWindow().getEventListenersContainer();
  window.setCurrentEvent(previousEvent); // reset event

代码示例来源:origin: HtmlUnit/htmlunit

final Map<String, Scriptable> prototypesPerJSName = new HashMap<>();
final Window window = new Window();
((SimpleScriptable) window).setClassName("Window");
context.initStandardObjects(window);
  defineConstructor(window, window, new Window());
window.defineProperty(intl.getClassName(), intl, ScriptableObject.DONTENUM);
intl.defineProperties(browserVersion);
  final Reflect reflect = new Reflect();
  reflect.setParentScope(window);
  window.defineProperty(reflect.getClassName(), reflect, ScriptableObject.DONTENUM);
  reflect.defineProperties();
window.setPrototype(prototypesPerJSName.get(Window.class.getSimpleName()));
    NumberCustom.class, ScriptableObject.DONTENUM);
window.setPrototypes(prototypes, prototypesPerJSName);
window.initialize(webWindow);

相关文章

微信公众号