Example #1
0
File: HtmlDiv.cs Project: dfr0/moon
 public HtmlDiv(HtmlElement root) : base(root) 
 {
     if (root.TagName != HtmlTag.Div.ToString().ToLower(CultureInfo.InvariantCulture))
     {
         throw new ArgumentException("The HtmlElement must be a division (div) tag.", "root");
     }
 }
Example #2
0
        /// <summary>
        /// Retrieves the key, if any. Also attempts to be proactive in 
        /// clearing out no longer-alive weak references, though once the key 
        /// is found the remaining keys are not checked.
        /// </summary>
        /// <param name="element">The HtmlElement object.</param>
        /// <returns>Returns the WeakReference that corresponds to the element 
        /// key in the weak reference dictionary.</returns>
        private WeakReference GetKey(HtmlElement element)
        {
            List<WeakReference> deadReferences = new List<WeakReference>();
            WeakReference key = null;
            foreach (WeakReference reference in _managedControls.Keys)
            {
                if (!reference.IsAlive)
                {
                    deadReferences.Add(reference);
                    continue;
                }

                HtmlElement he = reference.Target as HtmlElement;
                if (he != null && he == element)
                {
                    key = reference;
                    break;
                }
            }

            if (deadReferences.Count > 0)
            {
                foreach (WeakReference wr in deadReferences)
                {
                    _managedControls.Remove(wr);
                }
            }

            return key;
        }
Example #3
0
 public HtmlElementWrapper(HtmlElement realElement, HtmlElementWrapperBag bag) : this(realElement)
 {
     if (bag == null)
     {
         throw new ArgumentNullException("bag");
     }
     MoveBagContents(bag);
 }
Example #4
0
 /// <summary>
 /// Used by an extension method on System.Windows.Browser.HtmlElement to
 /// hook a managed control up by creating a real underlying element.
 /// </summary>
 /// <param name="parent">The HtmlElement to append the managed 
 /// HtmlControl to.</param>
 /// <param name="control">The managed HtmlControlBase or HtmlControl to 
 /// append, Initialize, and create with a real element.</param>
 internal static void AppendAndInitialize(HtmlElement parent, HtmlControlBase control)
 {
     // If the control is already out there with live and active 
     // elements, the net effect of these calls is simply to initialize 
     // any children of the control.
     control.CreateAndAppend(parent);
     control.Initialize();
 }
Example #5
0
 /// <summary>
 /// Initializes a new element wrapper.
 /// </summary>
 /// <param name="realElement">The element whose properties to wrap.</param>
 public HtmlElementWrapper(HtmlElement realElement) : this()
 {
     if (realElement == null)
     {
         throw new ArgumentNullException("realElement");
     }
     _realElement = realElement;
 }
        public override void StartAd()
        {
            string url = AdSource.MediaSource;
            string click = AdSource.ClickUrl;
            string alt = AdSource.AltText;

            switch (AdSource.MediaSourceType)
            {
                case MediaSourceEnum.Static:
                    if (AdTarget.Target.TagName == "img")
                    {
                        element = AdTarget.Target;
                    }
                    else
                    {
                        element = HtmlPage.Document.CreateElement("img");
                        AdTarget.Target.AppendChild(element);
                    }

                    element.SetAttribute("src", url);
                    element.SetAttribute("alt", alt);
                    element.AttachEvent("onclick", new EventHandler(OnClick));
                    break;
                case MediaSourceEnum.HTML:
                    element = AdTarget.Target;
                    element.SetProperty("innerHTML", url);
                    element.AttachEvent("onclick", new EventHandler(OnClick));
                    break;
                case MediaSourceEnum.IFrame:
                    if (AdTarget.Target.TagName == "iframe")
                    {
                        element = AdTarget.Target;
                    }
                    else
                    {
                        element = HtmlPage.Document.CreateElement("iframe");
                        AdTarget.Target.AppendChild(element);
                    }

                    element.SetAttribute("src", url);
                    element.AttachEvent("onclick", new EventHandler(OnClick));
                    break;
            }

            if (!AdSource.Dimensions.IsEmpty)
            {
                element.SetStyleAttribute("width", AdSource.Dimensions.Width.ToString() + "px");
                element.SetStyleAttribute("height", AdSource.Dimensions.Height.ToString() + "px");
            }
            AdTarget.Target.SetStyleAttribute("visibility", "visible");

            base.StartAd();
            if (AdSource.Duration.HasValue)
            {
                StartVideo();
            }
        }
Example #7
0
 /// <summary>
 /// Retrieves a managed control instance, if any, for the HTML element.
 /// </summary>
 /// <param name="element">The HTML element.</param>
 /// <returns>Returns the managed control for an HTML element.</returns>
 public HtmlControlBase GetControl(HtmlElement element)
 {
     WeakReference key = GetKey(element);
     HtmlControlBase value = null;
     if (key != null && _managedControls.ContainsKey(key))
     {
         value = _managedControls[key];
     }
     return value;
 }
Example #8
0
        /// <summary>
        /// Constructor to instantiate the surface with specifc book fragment.
        /// </summary>
        public HtmlSurface(HtmlElement container)
        {
            if (container == null)
            {
                // TODO: Specialized exception?
                throw new Exception("Yikes");
            }

            Container = container;
            _currentlyHighlightedElement = null;
            _currentElementClass = String.Empty;
        }
Example #9
0
        public MainPage(string nombreArchivo, string idElementoHtmlControl)
        {
            NombreArchivo = nombreArchivo;
            ElementoHtmlControl = HtmlPage.Document.GetElementById(idElementoHtmlControl);

            if (ElementoHtmlControl == null)
            {
                MessageBox.Show("Error: Elemento de control con id '" + idElementoHtmlControl + "' no encontrado.");
            }

            InitializeComponent();
            HtmlPage.RegisterScriptableObject("MainPage", this);
        }
Example #10
0
 public HtmlPageControl(HtmlElement existingElement)
     : base(existingElement) 
 {
     // Attempt to load these immediately 
     try
     {
         HtmlControlBase body = Body;
         HtmlControlBase head = Header;
     }
     catch (InvalidOperationException) 
     { 
     }
 }
Example #11
0
        /// <summary>
        /// Create a html button to display custom messages
        /// </summary>
        /// <param name="htmlElement"></param>
        /// <returns></returns>
        public static System.Windows.Browser.HtmlElement GetDisplayMessageButton(System.Windows.Browser.HtmlElement htmlElement)
        {
            htmlElement = System.Windows.Browser.HtmlPage.Document.CreateElement("input");
            htmlElement.SetProperty("id", "inputText");
            htmlElement.SetProperty("type", "button");
            htmlElement.SetStyleAttribute("border", "solid 1px black");
            htmlElement.SetStyleAttribute("position", "absolute");
            htmlElement.SetStyleAttribute("width", "900px");
            htmlElement.SetStyleAttribute("height", "20px");
            htmlElement.SetStyleAttribute("top", "520px");
            htmlElement.SetStyleAttribute("left", "0px");

            return(htmlElement);
        }
Example #12
0
        public void Page_Loaded(object o, EventArgs e)
        {
            // Required to initialize variables
            InitializeComponent();

            Canvas c = o as Canvas;
            _hidApi = HtmlPage.Document.GetElementByID("hidAPI");
            _hidSecret = HtmlPage.Document.GetElementByID("hidSecret");
            _hidSession = HtmlPage.Document.GetElementByID("hidSession");
            _hidUser = HtmlPage.Document.GetElementByID("hidUser");

            facebookProxy.UserJSON[] friends = CallWS(_hidApi.GetProperty<string>("Value"), _hidSecret.GetProperty<string>("Value"), _hidSession.GetProperty<string>("Value"), _hidUser.GetProperty<string>("Value"));

            tb.Text = "You have " + friends.Length + " friends.";//CallWS(_hidApi.GetProperty<string>("Value"), _hidSecret.GetProperty<string>("Value"), _hidSession.GetProperty<string>("Value"), _hidUser.GetProperty<string>("Value"));
        }
        private static void InsertMethods(HtmlElement parent, string name, IEnumerable<MethodInfo> methods)
        {
            // Setup initial conditions.
            if (methods.IsEmpty()) return;

            // Create the method container.
            var methodContainer = CreateElement(name);
            parent.AppendChild(methodContainer);

            // Insert each method.
            foreach (var methodInfo in methods)
            {
                var htmMethod = CreateElement("method");
                htmMethod.SetAttribute("name", methodInfo.Name);
                htmMethod.SetAttribute("class", methodInfo.DeclaringType.FullName);
                methodContainer.AppendChild(htmMethod);
            }
        }
Example #14
0
        private Window(HtmlElement windowLocationDiv, bool injectStyleAndScript)
        {
            if (_current == null) {
                _windowLocationDiv = windowLocationDiv;
                if (_windowLocationDiv == null) {
                    _windowLocationDiv = HtmlPage.Document.CreateElement("div");
                    _windowLocationDiv.Id = _windowContainerId;
                }
                if (HtmlPage.Document.GetElementById(_windowLocationDiv.Id) == null) {
                    HtmlPage.Document.Body.AppendChild(_windowLocationDiv);
                }
                _windowLocationDiv.SetProperty("innerHTML", WindowHtml());

                if (injectStyleAndScript) {
                    InjectScriptBlock();
                    InjectStyleBlock();
                    injectStyleAndScript = false;
                }
            }
        }
Example #15
0
        public MainPage(string Nombre, string Apellido, string NroTarjeta, string Track1, string Track2, string TipoTarjeta, string Corporacion, string FechaVencimiento, string idElementoHtmlControl)
        {
            nombre = Nombre;
            apellido = Apellido;
            nroTarjeta = NroTarjeta;
            track1 = Track1;
            track2 = Track2;
            tipoTarjeta = TipoTarjeta;
            corporacion = Corporacion;
            fechaVencimiento = FechaVencimiento;

            ElementoHtmlControl = HtmlPage.Document.GetElementById(idElementoHtmlControl);

            if (ElementoHtmlControl == null)
            {
                MessageBox.Show("Error: Elemento de control con id '" + idElementoHtmlControl + "' no encontrado.");
            }

            InitializeComponent();
            HtmlPage.RegisterScriptableObject("MainPage", this);
        }
Example #16
0
		public ScriptableTest ()
		{
			plugin = HtmlPage.Plugin;
			window = HtmlPage.Window;
			content = plugin.GetProperty ("Content") as ScriptObject;

			//bool ispopupon = HtmlPage.IsPopupWindowAllowed;
			//HtmlWindow popup = HtmlPage.PopupWindow (new Uri ("about:blank"), "_blank", new HtmlPopupWindowOptions ());
			calc = new Calculator ();
			scriptable = new Scriptable ();
			scriptabletype = new ScriptableType ();

			HtmlPage.RegisterScriptableObject ("calc", calc);
			HtmlPage.RegisterScriptableObject ("scriptable", scriptable);
			HtmlPage.RegisterScriptableObject ("scriptabletype", scriptabletype);
			HtmlPage.RegisterCreateableType ("createable", typeof (CreateableType));

			if (Environment.OSVersion.Platform == PlatformID.Unix)
				strplugin = "document.getElementById('silverlight')";
			else
				strplugin = "document.getElementById('silverlightControlHost').getElementsByTagName('object')[0]";
		}
Example #17
0
 public void AddPanel(string title, HtmlElement panel) {
     var origClass = panel.CssClass;
     panel.CssClass += " silverlightDlrPanel";
     _current.Contents.AppendChild(panel);
     AddMenuItem(title, panel.Id, origClass);
 }
Example #18
0
 public static void Show(HtmlElement windowLocationDiv, bool inject) {
     if (_current == null) {
         _current = new Window(windowLocationDiv, inject);
     }
 }
Example #19
0
 void initGL(HtmlElement canvas)
 {
     try {
         gl = new WebGLRenderingContext(canvas);
         viewportWidth = (float)canvas.Width();
         viewportHeight = (float)canvas.Height();
     } catch (Exception e) {
     }
     if (gl == null) {
         alert("Could not initialise WebGL, sorry :-(");
     }
 }
Example #20
0
        /// <summary>
        /// Highlights a specific element within the book fragment. Highlighting can be
        /// achieved by adding a class the the corresponding HTML element called, say,
        /// highligh. This can be picked up by the buttercup.css stylesheet to set the
        /// background of the element.
        /// </summary>
        /// <param name="id">The id as specified in the HTML element.</param>
        public override void Highlight(string id)
        {
            //Unhighlight the currently-highlighted item - restore the original style.
            if (_currentlyHighlightedElement != null)
            {
                _currentlyHighlightedElement.CssClass = _currentElementClass;
            }

            if (String.IsNullOrEmpty(id))
            {
                //No element is highlighted
                _currentlyHighlightedElement = null;
                return;
            }

            HtmlElement targetElement = HtmlPage.Document.GetElementById(id);

            if (targetElement != null)
            {
                //Cache existing CSS class(es)
                _currentElementClass = targetElement.CssClass;

                if (!String.IsNullOrEmpty(_currentElementClass))
                    targetElement.CssClass = _currentElementClass + " " + _HIGHLIGHT_STYLE_CLASS;
                else
                    targetElement.CssClass = _HIGHLIGHT_STYLE_CLASS;

                _currentlyHighlightedElement = targetElement;
            }
            else
            {
                // What if we can't?
            }
        }
Example #21
0
		public bool TryChangeType (object value, Type type, CultureInfo culture, out object ret)
		{
			ScriptObject script_object;
			
			ret = value;

			if (value == null)
				return true;

			if (value.GetType() == type)
				return true;

			// we need to do this before the ScriptObject
			// block because we might be passing
			// ManagedObject arguments to a method that
			// takes ScriptObjects, and therefore we
			// shouldn't "unwrap" the ScriptObject's
			// ManagedObject field.
			if (type.IsAssignableFrom (value.GetType ()))
				return true;

			script_object = value as ScriptObject;
			if (script_object != null) {
				value = script_object.ManagedObject;
				if (value == null && type == typeof(HtmlElement))
					value = new HtmlElement (script_object.Handle);
				ret = value;
				if (value.GetType () == type)
					return true;
			}

			if (type.IsAssignableFrom (value.GetType ()))
				return true;

			if (type == typeof (ScriptObject)) {
				ret = new ManagedObject (value);
				return true;
			}

			if (type.IsEnum) {
				try {
					ret = Enum.Parse (type, value.ToString(), true);
					return true;
				} catch {
					return false;
				}
			}

			/* the set of source types for JS functions is
			 * very, very small, so we switch over the
			 * parameter type first */
			try {
				ret = Convert.ChangeType (value, type, culture);
				return true;
			}
			catch {
				// no clue if this is right.. if we
				// fail to convert, what do we return?

				switch (Type.GetTypeCode (type))
				{
				case TypeCode.Char:
				case TypeCode.Byte:
				case TypeCode.SByte:
				case TypeCode.Int16:
				case TypeCode.Int32:
				case TypeCode.Int64:
				case TypeCode.UInt16:
				case TypeCode.UInt32:
				case TypeCode.UInt64:
				case TypeCode.Single:
				case TypeCode.Double:
					ret = Convert.ChangeType (0, type, culture);
					return true;
				case TypeCode.String:
					ret = "";
					return true;

				case TypeCode.Boolean:
					ret = false;
					return true;
				}
			}

			return false;
		}
Example #22
0
 /// <summary>
 /// Check if the HtmlElement has a known managed control.
 /// </summary>
 /// <param name="element">The element object.</param>
 /// <returns>Returns whether the element has an attached control.</returns>
 public bool HasControl(HtmlElement element)
 {
     HtmlControlBase hcb = GetControl(element);
     return (hcb != null);
 }
Example #23
0
 /// <summary>
 /// Removes an HTML element from the set of known control.
 /// </summary>
 /// <param name="element">The HTML element object.</param>
 public void UnregisterElement(HtmlElement element)
 {
     WeakReference key = GetKey(element);
     if (key != null)
     {
         _managedControls.Remove(key);
     }
 }
Example #24
0
 internal void AppendTextInElement(string str, HtmlElement e) {
     var toPrepend = e.GetProperty("innerHTML").ToString();
     e.SetProperty("innerHTML", toPrepend + EscapeHtml(str));
 }
Example #25
0
 public void AppendChild(HtmlElement element, HtmlElement referenceElement)
 {
     Invoke("insertBefore", element, referenceElement);
 }
Example #26
0
 public static object GetBoundMember(HtmlElement element, string name) {
     return element.GetProperty(name);
 }
Example #27
0
 public void Start() {
     _silverlightDlrReplCode = HtmlPage.Document.GetElementById(_sdlrCode);
     _silverlightDlrReplResult = HtmlPage.Document.GetElementById(_sdlrResult);
     _silverlightDlrReplPrompt = HtmlPage.Document.GetElementById(_sdlrPrompt);
     _inputBuffer = new ReplInputBuffer(_current);
     _outputBuffer = new ReplOutputBuffer(_silverlightDlrReplResult, _sdlrOutput);
     ShowDefaults();
     ShowPrompt();
     _silverlightDlrReplCode.AttachEvent("onkeypress", new EventHandler<HtmlEventArgs>(OnKeyPress));
 }
Example #28
0
 public static void Show(HtmlElement windowLocationDiv) {
     Show(windowLocationDiv, true);
 }
Example #29
0
 private void findIFrame()
 {
     _iFrame = HtmlPage.Document.GetElementById("pdfFrame");
 }
Example #30
0
 public void AppendChild(HtmlElement element)
 {
     Invoke("appendChild", element);
 }
Example #31
0
 public ReplOutputBuffer(HtmlElement results, string outputClass) {
     _results = results;
     _outputClass = outputClass;
     _queue = "";
     Reset();
 }
Example #32
0
 public void RemoveChild(HtmlElement element)
 {
     Invoke("removeChild", element);
 }
Example #33
0
 public static void SetMember(HtmlElement element, string name, string value) {
     element.SetProperty(name, value);
 }
Example #34
0
 internal void PutTextInElement(string str, HtmlElement e) {
     e.SetProperty("innerHTML", EscapeHtml(str));
 }