Esempio n. 1
0
        /// <summary>Closes the document.</summary>
        public void close()
        {
            if (!IsOpen)
            {
                // Already closed.
                return;
            }

            // Mark as closed:
            IsOpen = false;

            if (!TryCompile())
            {
                // We're downloading code.
                // This flag lets the downloader know it needs to also attempt a TryCompile.
                FinishedParsing = true;
            }

            // Force a render request as required:
            RequestLayout();

            // Setup window:
            window.Ready();

            // Dispatch onload (doesn't bubble):

            if (body != null)
            {
                Dom.Event e = new Dom.Event("load");
                e.SetTrusted(false);
                body.dispatchEvent(e);
            }
        }
Esempio n. 2
0
    /// <summary>Called when an event is being dispatched here.</summary>
    public bool dispatchEvent(Dom.Event e)
    {
        Debug.Log("EVENT DISPATCHED!");

        // Ok!
        return(true);
    }
 /// <summary>
 /// IEventTarget requires the dispatchEvent method.
 /// It's the same as the standard W3C dispatchEvent.</summary>
 public bool dispatchEvent(Dom.Event e)
 {
     // We received some event!
     // This typically happens when the UI did not handle it,
     // or because an event was specifically dispatched to this gameObject (via gameObject.dispatchEvent).
     return(Target.dispatchEvent(e));
 }
Esempio n. 4
0
        public static void ResolveOptionFromClick(Dom.Event e)
        {
            // Get the src element:
            HtmlElement src = (e.srcElement as HtmlElement);

            // Get the optindex:
            int index;

            if (!int.TryParse(e.srcElement["optindex"], out index))
            {
                return;
            }

            // Resolve the option from just an index and a document ref:
            Option option = ResolveOption(index, src.widget);

            if (option != null)
            {
                // Set element which may be useful for submenu's:
                option.buttonElement = src;

                // Run it!
                option.run();
            }
        }
Esempio n. 5
0
        /// <summary>Looks out for paste events.</summary>
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            if (base.HandleLocalEvent(e, bubblePhase))
            {
                // It was blocked. Don't run the default.
                return(true);
            }

            if (e is ClipboardEvent && bubblePhase && e.type == "paste")
            {
                // Paste the data at the caret index (must be text only).
                string textToPaste = (e as ClipboardEvent).text;

                if (textToPaste != null)
                {
                    string value = this.value;

                    if (value == null)
                    {
                        value = "" + textToPaste;
                    }
                    else
                    {
                        value = value.Substring(0, CaretIndex) + textToPaste + value.Substring(CaretIndex, value.Length - CaretIndex);
                    }

                    SetValue(value);
                    MoveCaret(CaretIndex + textToPaste.Length, true);
                }
            }

            return(false);
        }
Esempio n. 6
0
        private void OnLoadEvent(Dom.Event e)
        {
            BackgroundImage bgImage = RenderData.BGImage;

            if (bgImage == null)
            {
                return;
            }

            Image = bgImage.Image;

            if (Image == null)
            {
                return;
            }

            float width  = (float)Image.Width;
            float height = (float)Image.Height;

            // Figure out the aspect ratios:
            AspectRatio        = width / height;
            InverseAspectRatio = height / width;

            // Cache w/h:
            RawWidth  = width;
            RawHeight = height;

            // Request layout:
            bgImage.RequestLayout();
        }
Esempio n. 7
0
        /// <summary>Sets the value of this textarea.</summary>
        /// <param name="value">The value to set.</param>
        private void SetValue(string newValue)
        {
            Dom.Event e = new Dom.Event("change");
            e.SetTrusted(false);
            if (!dispatchEvent(e))
            {
                return;
            }

            if (MaxLength != int.MaxValue)
            {
                // Do we need to clip it?
                if (newValue.Length > MaxLength)
                {
                    // Yep!
                    newValue = newValue.Substring(0, MaxLength);
                }
            }

            if (CaretIndex > newValue.Length)
            {
                MoveCaret(0);
            }

            if (newValue == "" && Placeholder_ != "")
            {
                newValue = Placeholder_;
            }

            // Write text content:
            textContent = newValue;

            // Redraw:
            RequestLayout();
        }
Esempio n. 8
0
        /// <summary>Looks out for paste events.</summary>
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            // Handle locally:
            if (base.HandleLocalEvent(e, bubblePhase))
            {
                if (e is ClipboardEvent && IsTextInput() && e.type == "paste")
                {
                    // Paste the data at the caret index (must be text only).
                    string textToPaste = (e as ClipboardEvent).text;

                    if (textToPaste != null)
                    {
                        string value = Value;

                        if (value == null)
                        {
                            value = "" + textToPaste;
                        }
                        else
                        {
                            value = value.Substring(0, CaretIndex) + textToPaste + value.Substring(CaretIndex, value.Length - CaretIndex);
                        }

                        SetValue(value);
                        MoveCaret(CaretIndex + textToPaste.Length);
                    }
                }

                return(true);
            }

            return(false);
        }
Esempio n. 9
0
        internal void ApplyNewRenderTexture(int w, int h)
        {
            if (w <= 0 || h <= 0)
            {
                return;
            }

            CreatedTexture = true;

            RenderTexture rt = new RenderTexture(w, h, 24);

            // Create it now:
            Camera.targetTexture = rt;

            // Element.image API:
            image = rt;

            // Dispatch an event to signal the RT changed:
            Dom.Event e = new Dom.Event("cameraresize");
            e.SetTrusted(false);
            dispatchEvent(e);

            // Setup the clear flags:
            // Camera.clearFlags=CameraClearFlags.Depth;
        }
Esempio n. 10
0
        /// <summary>Runs the given function held in the named attribute (e.g. onkeydown) and checks if that function blocked
        /// the event. In the case of a blocked event, no default action should occur. Note that this is called by dispatchEvent
        /// and the attribute functions run before handlers do (same as Firefox).</summary>
        /// <param name="e">A standard DOM Event containing e.g. key/mouse information.</param>
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            if (bubblePhase)
            {
                // Run the function:
                object result = Run("on" + e.type, e);

                if (result != null && result is bool)
                {
                    // It returned true/false - was it false?

                    if (!(bool)result)
                    {
                        // Explicitly returned false - Blocked it.
                        return(true);
                    }
                }
            }

            if (base.HandleLocalEvent(e, bubblePhase))
            {
                // Blocked it - stop there.
                return(true);
            }

            // Main defaults occur in here:
            if (bubblePhase && e is MouseEvent && e.type == "click")
            {
                OnClickEvent((MouseEvent)e);
            }

            return(false);
        }
Esempio n. 11
0
        /// <summary>Called when the marquee bounces the content.</summary>
        private void Bounced()
        {
            // Trigger:
            Dom.Event e = new Dom.Event("bounce");
            e.SetTrusted(false);
            dispatchEvent(e);

            // Consider looping too:
            Wrapped();
        }
Esempio n. 12
0
        /// <summary>Sets how many pixels of space this renderer has. The actual world space size is dictated by this and
        /// <see cref="PowerUI.WorldUI.SetResolution"/>. The amount of pixels and pixels per world unit (resolution).</summary>
        /// <param name="widthPX">The width in pixels.</param>
        /// <param name="heightPX">The height in pixels.</param>
        public virtual bool SetDimensions(int widthPX, int heightPX)
        {
            if (widthPX == pixelWidth && heightPX == pixelHeight)
            {
                return(false);
            }

            // Inform media rules if we have any too:
            var media = document.MediaIfExists;

            // Resize:
            if (widthPX != pixelWidth)
            {
                pixelWidth = widthPX;
                document.Viewport.Width = widthPX;

                if (media != null)
                {
                    // Nudge it!
                    media.Width = widthPX;
                }
            }

            if (heightPX != pixelHeight)
            {
                pixelHeight              = heightPX;
                PixelHeightF             = (float)pixelHeight;
                document.Viewport.Height = heightPX;

                if (media != null)
                {
                    // Nudge it!
                    media.Height = heightPX;
                }
            }

            // Update ratio:
            Ratio = (float)pixelWidth / PixelHeightF;

            // Reset the origin position:
            SetOrigin(OriginLocation.x, OriginLocation.y);

            // Fire the resize event:
            if (document.body != null)
            {
                Dom.Event e = new Dom.Event("resize");
                e.SetTrusted();
                document.dispatchEvent(e);
            }

            // Request a layout too:
            document.RequestLayout();

            return(true);
        }
Esempio n. 13
0
        /// <summary>Used by boolean inputs (checkbox/radio). Selects this as the active one.</summary>
        public void Select()
        {
            if (Checked_)
            {
                return;
            }
            Checked_ = true;

            // Set checked:
            this["checked"] = "1";

            if (Type == InputType.Radio)
            {
                // Firstly, unselect all other radio elements with this same name:
                string name = this["name"];

                HTMLCollection allInputs;

                if (form == null)
                {
                    // Find all inputs with the same name:
                    allInputs = document.getElementsByTagName("input");
                }
                else
                {
                    allInputs = form.elements;
                }

                if (allInputs != null)
                {
                    foreach (Element element in allInputs)
                    {
                        if (element == this)
                        {
                            // Skip this element
                            continue;
                        }

                        if (element["type"] == "radio" && element["name"] == name)
                        {
                            // Yep; unselect it.
                            ((HtmlInputElement)element).Unselect();
                        }
                    }
                }

                Dom.Event e = new Dom.Event("change");
                e.SetTrusted(true);
                dispatchEvent(e);
            }
            else if (Type == InputType.Checkbox)
            {
                SetValue("1");
            }
        }
Esempio n. 14
0
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            if (bubblePhase && Dropdown != null && e.type == "mouseup")
            {
                Dropdown.SetSelected(this);
                Dropdown.Hide();
            }

            // Handle locally:
            return(base.HandleLocalEvent(e, bubblePhase));
        }
Esempio n. 15
0
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            if (e.type == "dragstart")
            {
                // Track where the bar started off:
                Start = Position;
            }

            // Handle locally:
            return(base.HandleLocalEvent(e, bubblePhase));
        }
Esempio n. 16
0
        /// <summary>The request has timed out.</summary>
        public void TimedOut()
        {
            statusCode = 408;
            Dom.Event e = new Dom.Event();
            e.SetTrusted();
            e.EventType = "timeout";
            dispatchEvent(e);

            // RS4:
            readyState = 4;
        }
        /// <summary>Requests this element (e.g. a video) to go fullscreen.</summary>
        public void requestFullscreen()
        {
            if (htmlDocument.fullscreenElement == this)
            {
                // Already fullscreen:
                return;
            }

            // Trigger fullscreen event:
            Dom.Event e = new Dom.Event("fullscreenchange");
            e.SetTrusted(false);

            if (!dispatchEvent(e))
            {
                // Cancelled it.
                return;
            }

            if (htmlDocument.fullscreenElement != null)
            {
                // Cancel it:
                htmlDocument.exitFullscreen();
            }

            // Apply element:
            htmlDocument.fullscreenElement = this;

            // Cache the current parent:
            CachedFullscreenParent = parentNode;

            if (parentNode != null)
            {
                // Can't actually do anything with it anyway otherwise - it's already filling the screen!

                // Remove it from the DOM:
                parentNode.removeChild(this);

                // Add it elsewhere:
                htmlDocument.html.appendChild(this);

                // Cache ele style:
                CachedFullscreenStyle = style.cssText;

                // Set basic style:
                style.cssText = "width:100%;height:100%;left:0px;top:0px;right:0px;bottom:0px;position:fixed;";
            }

            // Set (note that this triggers a CSS event):
            setAttribute("fullscreen", "1");

            // Update local style:
            Style.Computed.RefreshLocal();
        }
Esempio n. 18
0
        /// <summary>Fires all events into the scene.</summary>
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            // Handle locally:
            if (base.HandleLocalEvent(e, bubblePhase))
            {
                // Fire it in if it's got coords:
                FireIntoScene(e as UIEvent);

                return(true);
            }

            return(false);
        }
Esempio n. 19
0
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            // Handle locally:
            bool result = base.HandleLocalEvent(e, bubblePhase);

            // Always run this:
            if (e.type == "load" && bubblePhase)
            {
                // Run the load event handle:
                OnLoadEvent(e);
            }

            return(result);
        }
Esempio n. 20
0
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            if (base.HandleLocalEvent(e, bubblePhase))
            {
                // It was blocked. Don't run the default.
                return(true);
            }

            if (e.type == "dragstart")
            {
                if (ToResize == null)
                {
                    ToResize_ = parentElement as HtmlElement;
                }
                else
                {
                    ToResize_ = ToResize;
                }

                // Get the CSS resize property:
                if (ToResize_ != null)
                {
                    // Obtain its values:
                    Css.Properties.Resize.Compute(ToResize_.ComputedStyle, out AllowX, out AllowY);

                    // Does it explicitly change the resize target?
                    while (ToResize_ != null)
                    {
                        // Get the target attrib:
                        string attr = ToResize_.getAttribute("resize-target");

                        if (attr != null)
                        {
                            if (attr == "parent")
                            {
                                // Update to resize:
                                ToResize_ = ToResize_.parentElement as HtmlElement;

                                // Loop again; that might also specify a target.
                                continue;
                            }
                        }

                        break;
                    }
                }
            }

            return(false);
        }
        /// <summary>Dispatches an event to a gameObject.
        /// Depending on the events settings, it may bubble up the scene hierarchy.</summary>
        public static bool dispatchEvent(this GameObject go, Dom.Event e)
        {
            // Get the monobehaviour:
            GameObjectEventTarget monoBehaviour = go.GetComponent <GameObjectEventTarget>();

            if (monoBehaviour == null)
            {
                // Build it now:
                monoBehaviour = go.AddComponent <GameObjectEventTarget>();
                monoBehaviour.Setup();
            }

            // Dispatch:
            return(monoBehaviour.Target.dispatchEvent(e));
        }
Esempio n. 22
0
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            if (e.type == "mousedown" && bubblePhase)
            {
                if (Dropped)
                {
                    Hide();
                }
                else
                {
                    Drop();
                }
            }

            // Handle locally:
            return(base.HandleLocalEvent(e, bubblePhase));
        }
Esempio n. 23
0
        internal override bool ResourceStatus(EventTarget package, int status)
        {
            if (base.ResourceStatus(package, status))
            {
                // Run the onload event if we're in an iframe:
                if (window.iframe != null)
                {
                    // Dispatch to the element too (don't bubble):
                    Dom.Event e = new Dom.Event("load");
                    e.SetTrusted(false);
                    window.iframe.dispatchEvent(e);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 24
0
        /// <summary>A callback used when the graphic has been loaded and is ready for display.</summary>
        public void ImageReady(ImagePackage package)
        {
            if (Image == null || !Image.Loaded)
            {
                return;
            }

            // Dispatch load (don't bubble, default):
            Dom.Event e = new Dom.Event("load");
            e.SetTrusted(false);
            RenderData.Node.dispatchEvent(e);

            RequestLayout();

            if (Image != null && Filtering != FilterMode.Point)
            {
                Image.Contents.FilterMode = Filtering;
            }
        }
Esempio n. 25
0
        /// <summary>Sets the option at the given index as the selected one.</summary>
        /// <param name="index">The index of the option to select.</param>
        /// <param name="element">The element at the given index.</param>
        /// <param name="runOnChange">True if the onchange event should run.</param>
        private void SetSelected(int index, HtmlOptionElement element, bool runOnChange)
        {
            if (element == SelectedNode_)
            {
                return;
            }

            Dom.Event e = new Dom.Event("change");
            e.SetTrusted(false);

            // Cache previous:
            int prevIndex = SelectedIndex_;
            HtmlOptionElement prevNode = SelectedNode_;

            // Update current (so onchange gets the correct value):
            SelectedNode_  = element;
            SelectedIndex_ = index;

            if (runOnChange)
            {
                if (!dispatchEvent(e))
                {
                    // Restore to previous:
                    SelectedIndex_ = prevIndex;
                    SelectedNode_  = prevNode;

                    return;
                }
            }

            // Update placeholder:
            if (SelectedNode_ == null)
            {
                // Clear the option text:
                Placeholder.innerHTML = "";
                index = -1;
            }
            else
            {
                Placeholder.innerHTML = SelectedNode_.innerHTML;
            }
        }
Esempio n. 26
0
        /// <summary>Call this to begin a marquee.</summary>
        public void Start()
        {
            if (Active)
            {
                return;
            }

            Active = true;

            // Doesn't bubble:
            Dom.Event e = new Dom.Event("start");
            e.SetTrusted(false);

            if (dispatchEvent(e))
            {
                // Start our timer:
                Timer          = new UITimer(false, ScrollDelay, OnTick);
                Timer.Document = document_;
            }
        }
Esempio n. 27
0
        /// <summary>Call this to stop a scrolling marquee.</summary>
        public void Stop()
        {
            if (!Active)
            {
                return;
            }

            // Doesn't bubble:
            Dom.Event e = new Dom.Event("stop");
            e.SetTrusted(false);

            if (dispatchEvent(e))
            {
                Active = false;

                // Stop and clear the timer:
                Timer.Stop();

                Timer = null;
            }
        }
Esempio n. 28
0
        /// <summary>Runs the given function held in the named attribute (e.g. onkeydown) and checks if that function blocked
        /// the event. In the case of a blocked event, no default action should occur. Note that this is called by dispatchEvent
        /// and the attribute functions run before handlers do (same as Firefox).</summary>
        /// <param name="e">A standard DOM Event containing e.g. key/mouse information.</param>
        protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase)
        {
            if (bubblePhase)
            {
                // Run the function:
                object result = Run("on" + e.type, e);

                if (result != null && result is bool)
                {
                    // It returned true/false - was it false?

                    if (!(bool)result)
                    {
                        // Explicitly returned false - Blocked it.
                        return(true);
                    }
                }
            }

            return(base.HandleLocalEvent(e, bubblePhase));
        }
Esempio n. 29
0
        /// <summary>Handles events on the widget itself.</summary>
        protected override void OnEvent(Dom.Event e)
        {
            // Catch PowerSlide dialogue events and convert them to our virtual methods:
            PowerSlide.SlideEvent se;

            if (e.type == "dialoguestart")
            {
                // It's a slide event:
                se = e as PowerSlide.SlideEvent;

                // Get the slide:
                Show(se.slide as PowerSlide.DialogueSlide);
            }
            else if (e.type == "dialogueend")
            {
                // It's a slide event:
                se = e as PowerSlide.SlideEvent;

                // Hide:
                Hide(se.slide as PowerSlide.DialogueSlide);
            }
            else if (e.type == "timelinepause")
            {
                // The slides just paused (and are now waiting for a cue)
                se = e as PowerSlide.SlideEvent;

                // Waiting for a cue:
                WaitForCue(se);
            }
            else if (e.type == "timelineplay")
            {
                // The slides just cued (and are now continuing).
                se = e as PowerSlide.SlideEvent;

                // Cue received:
                Cued(se);
            }

            base.OnEvent(e);
        }
Esempio n. 30
0
        /// <summary>Called when the game screen changes size. Used by pixel perfect WorldUI's.</summary>
        private void MainScreenSizeChanged(Dom.Event e)
        {
            Camera camera = CameraToFace;

            if (camera == null)
            {
                camera = Input.CameraFor3DInput;

                if (camera == null)
                {
                    camera = Camera.main;
                }
            }

            // Update the screen space proportion.

            // First get the 'growth' rate of the screen height.
            ScreenSpaceProportion = Mathf.Tan(Mathf.Deg2Rad * camera.fieldOfView / 2f) * 2f;

            // Divide it by the screen height in pixels for it in world units:
            ScreenSpaceProportion /= (float)UnityEngine.Screen.height;
        }