Beispiel #1
0
 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");
     }
 }
Beispiel #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;
        }
Beispiel #3
0
 public HtmlElementWrapper(HtmlElement realElement, HtmlElementWrapperBag bag) : this(realElement)
 {
     if (bag == null)
     {
         throw new ArgumentNullException("bag");
     }
     MoveBagContents(bag);
 }
Beispiel #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();
 }
Beispiel #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();
            }
        }
Beispiel #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;
 }
        /// <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;
        }
Beispiel #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);
        }
Beispiel #10
0
 public HtmlPageControl(HtmlElement existingElement)
     : base(existingElement) 
 {
     // Attempt to load these immediately 
     try
     {
         HtmlControlBase body = Body;
         HtmlControlBase head = Header;
     }
     catch (InvalidOperationException) 
     { 
     }
 }
Beispiel #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);
        }
        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);
            }
        }
Beispiel #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;
                }
            }
        }
Beispiel #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);
        }
Beispiel #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]";
		}
Beispiel #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);
 }
Beispiel #18
0
 public static void Show(HtmlElement windowLocationDiv, bool inject) {
     if (_current == null) {
         _current = new Window(windowLocationDiv, inject);
     }
 }
Beispiel #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 :-(");
     }
 }
        /// <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?
            }
        }
Beispiel #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;
		}
Beispiel #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);
 }
Beispiel #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);
     }
 }
Beispiel #24
0
 internal void AppendTextInElement(string str, HtmlElement e) {
     var toPrepend = e.GetProperty("innerHTML").ToString();
     e.SetProperty("innerHTML", toPrepend + EscapeHtml(str));
 }
Beispiel #25
0
 public void AppendChild(HtmlElement element, HtmlElement referenceElement)
 {
     Invoke("insertBefore", element, referenceElement);
 }
Beispiel #26
0
 public static object GetBoundMember(HtmlElement element, string name) {
     return element.GetProperty(name);
 }
Beispiel #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));
 }
Beispiel #28
0
 public static void Show(HtmlElement windowLocationDiv) {
     Show(windowLocationDiv, true);
 }
Beispiel #29
0
 private void findIFrame()
 {
     _iFrame = HtmlPage.Document.GetElementById("pdfFrame");
 }
Beispiel #30
0
 public void AppendChild(HtmlElement element)
 {
     Invoke("appendChild", element);
 }
Beispiel #31
0
 public ReplOutputBuffer(HtmlElement results, string outputClass) {
     _results = results;
     _outputClass = outputClass;
     _queue = "";
     Reset();
 }
Beispiel #32
0
 public void RemoveChild(HtmlElement element)
 {
     Invoke("removeChild", element);
 }
Beispiel #33
0
 public static void SetMember(HtmlElement element, string name, string value) {
     element.SetProperty(name, value);
 }
Beispiel #34
0
 internal void PutTextInElement(string str, HtmlElement e) {
     e.SetProperty("innerHTML", EscapeHtml(str));
 }