/// <summary> /// Creates and returns a composite {@link ScriptResult} based on the two input {@link ScriptResult}s. This /// method defines how the return values for multiple event handlers are combined during event capturing and /// bubbling. The behavior of this method varies based on whether or not we are emulating IE. /// </summary> /// <param name="newResult">the new {@link ScriptResult} (may be <tt>null</tt>)</param> /// <param name="originalResult">the original {@link ScriptResult} (may be <tt>null</tt>)</param> /// <param name="ie">whether or not we are emulating IE</param> /// <returns>a composite {@link ScriptResult}, based on the two input {@link ScriptResult}s</returns> public static ScriptResult Combine(ScriptResult newResult, ScriptResult originalResult, bool ie) { Object jsResult; IPage page; // If we're emulating IE, the overall JavaScript return value is the last return value. // If we're emulating FF, the overall JavaScript return value is false if the return value // was false at any level. if (ie) { if (newResult != null && !ScriptResult.IsUndefined(newResult)) { jsResult = newResult.JavaScriptResult; } else if (originalResult != null) { jsResult = originalResult.JavaScriptResult; } else { jsResult = null; } } else { if (ScriptResult.IsFalse(newResult)) { jsResult = newResult.JavaScriptResult; } else if (originalResult != null) { jsResult = originalResult.JavaScriptResult; } else { jsResult = null; } } // The new page is always the newest page. if (newResult != null) { page = newResult.NewPage; } else if (originalResult != null) { page = originalResult.NewPage; } else { page = null; } // Build and return the composite script result. if (jsResult == null && page == null) { return(null); } return(new ScriptResult(jsResult, page)); }
/// <summary> /// Utility method testing if a script result is undefined (there was no return value). /// </summary> /// <param name="scriptResult">a script result (may be <tt>null</tt>)</param> /// <returns><tt>true</tt> if <tt>scriptResult</tt> is undefined (there was no return value)</returns> public static bool IsUndefined(ScriptResult scriptResult) { return(scriptResult != null && scriptResult.JavaScriptResult is Undefined); }
/// <summary> /// Utility method testing if a script result is <tt>false</tt>. /// </summary> /// <param name="scriptResult">a script result (may be <tt>null</tt>)</param> /// <returns><tt>true</tt> if <tt>scriptResult</tt> is <tt>false</tt></returns> public static bool IsFalse(ScriptResult scriptResult) { return(scriptResult != null && String.Equals(Boolean.FalseString, scriptResult.JavaScriptResult)); }
/// <summary> /// Utility method testing if a script result is <tt>false</tt>. /// </summary> /// <param name="scriptResult">a script result (may be <tt>null</tt>)</param> /// <returns><tt>true</tt> if <tt>scriptResult</tt> is <tt>false</tt></returns> public static bool IsFalse(ScriptResult scriptResult) { return scriptResult != null && String.Equals(Boolean.FalseString, scriptResult.JavaScriptResult); }
/// <summary> /// Creates and returns a composite {@link ScriptResult} based on the two input {@link ScriptResult}s. This /// method defines how the return values for multiple event handlers are combined during event capturing and /// bubbling. The behavior of this method varies based on whether or not we are emulating IE. /// </summary> /// <param name="newResult">the new {@link ScriptResult} (may be <tt>null</tt>)</param> /// <param name="originalResult">the original {@link ScriptResult} (may be <tt>null</tt>)</param> /// <param name="ie">whether or not we are emulating IE</param> /// <returns>a composite {@link ScriptResult}, based on the two input {@link ScriptResult}s</returns> public static ScriptResult Combine(ScriptResult newResult, ScriptResult originalResult, bool ie) { Object jsResult; IPage page; // If we're emulating IE, the overall JavaScript return value is the last return value. // If we're emulating FF, the overall JavaScript return value is false if the return value // was false at any level. if (ie) { if (newResult != null && !ScriptResult.IsUndefined(newResult)) { jsResult = newResult.JavaScriptResult; } else if (originalResult != null) { jsResult = originalResult.JavaScriptResult; } else { jsResult = null; } } else { if (ScriptResult.IsFalse(newResult)) { jsResult = newResult.JavaScriptResult; } else if (originalResult != null) { jsResult = originalResult.JavaScriptResult; } else { jsResult = null; } } // The new page is always the newest page. if (newResult != null) { page = newResult.NewPage; } else if (originalResult != null) { page = originalResult.NewPage; } else { page = null; } // Build and return the composite script result. if (jsResult == null && page == null) { return null; } return new ScriptResult(jsResult, page); }
/// <summary> /// Utility method testing if a script result is undefined (there was no return value). /// </summary> /// <param name="scriptResult">a script result (may be <tt>null</tt>)</param> /// <returns><tt>true</tt> if <tt>scriptResult</tt> is undefined (there was no return value)</returns> public static bool IsUndefined(ScriptResult scriptResult) { return scriptResult != null && scriptResult.JavaScriptResult is Undefined; }