/// <summary>Attempts to apply any added css. It's only successful if there are no nulls in the style buffer.</summary>
        /// <returns>Returns false if we're still waiting on css to download.</returns>
        public bool TryStyle()
        {
            if (StyleBuffer == null || AotDocument)
            {
                return(true);
            }
            if (StyleBuffer.Length == 0)
            {
                StyleBuffer = null;
                return(true);
            }
            for (int i = 0; i < StyleBuffer.Length; i++)
            {
                if (StyleBuffer[i] == null)
                {
                    return(false);
                }
            }
            // Good to go!
            string styleToCompile = "";

            for (int i = 0; i < StyleBuffer.Length; i++)
            {
                styleToCompile += StyleBuffer[i] + "\n";
            }
            StyleBuffer = null;
            // Parse it in now:
            Style.ParseCss(styleToCompile);
            return(true);
        }
Beispiel #2
0
        /// <summary>Loads external CSS if a href is available and it's known to be css.</summary>
        public void LoadContent()
        {
            if (!IsCSS || string.IsNullOrEmpty(Href) || styleSheet != null)
            {
                return;
            }

            // Let's go get it!
            styleSheet = htmlDocument.AddStyle(this, null);

            DataPackage package = new DataPackage(Href, document.basepath);

            styleSheet.Location = package.location;

            package.onload = delegate(UIEvent e){
                if (document == null || styleSheet == null)
                {
                    return;
                }

                // The element is still somewhere on the UI.

                // Load it now:
                styleSheet.ParseCss(package.responseText);

                // Redraw:
                htmlDocument.RequestLayout();
            };

            package.send();
        }
        /// <summary>Creates a new document which will be rendered with the given renderer.</summary>
        /// <param name="renderer">The renderer to use when rendering this document.</param>
        /// <param name="parentWindow">The window that will become the parent window. Used in e.g. iframes.</param>
        /// <param name="aot">True if this is a Nitro AOT document (used in the Editor only).</param>
        public Document(Renderman renderer, Window parentWindow, bool aot) : base()
        {
            AotDocument = aot;

            if (!aot && DefaultStyleSheet == null)
            {
                // No default styles loaded yet. Load them now.
                string styleText = ((TextAsset)Resources.Load("style")).text;
                // Have they applied any overrides?
                TextAsset extraStyle = Resources.Load("customStyle") as TextAsset;
                if (extraStyle != null && extraStyle.text != null)
                {
                    styleText += "\n\n" + extraStyle.text;
                }
                DefaultStyleSheet = new Css.StyleSheet(this);
                DefaultStyleSheet.ParseCss(styleText);
            }

                        #if !NoNitroRuntime
            // Get the default security domain:
            SecurityDomain = UI.DefaultSecurityDomain;
                        #endif

            Renderer = renderer;

            window          = new Window();
            window.document = this;
            window.parent   = parentWindow;
            if (parentWindow != null)
            {
                window.top = parentWindow.top;
            }
            else
            {
                window.top = window;
            }

            ActiveFonts = new Dictionary <string, DynamicFont>();
            Style       = new Css.StyleSheet(this);
            html        = new Element(this, null);
            html.SetTag("html");
            string ddbox = "";

            if (parentWindow == null)
            {
                // Dropdown box belongs to the top window only:
                ddbox = "<ddbox></ddbox>";
            }

            html.innerHTML = "<body></body>" + ddbox;
        }
		/// <summary>Creates a new document which will be rendered with the given renderer.</summary>
		/// <param name="renderer">The renderer to use when rendering this document.</param>
		/// <param name="parentWindow">The window that will become the parent window. Used in e.g. iframes.</param>
		/// <param name="aot">True if this is a Nitro AOT document (used in the Editor only).</param>
		public Document(Renderman renderer,Window parentWindow,bool aot):base(){
			AotDocument=aot;
			
			if(!aot && DefaultStyleSheet==null){
				// No default styles loaded yet. Load them now.
				string styleText=((TextAsset)Resources.Load("style")).text;
				// Have they applied any overrides?
				TextAsset extraStyle=Resources.Load("customStyle") as TextAsset;
				if(extraStyle!=null && extraStyle.text!=null){
					styleText+="\n\n"+extraStyle.text;
				}
				DefaultStyleSheet=new Css.StyleSheet(this);
				DefaultStyleSheet.ParseCss(styleText);
			}
			
			#if !NoNitroRuntime
			// Get the default security domain:
			SecurityDomain=UI.DefaultSecurityDomain;
			#endif
			
			Renderer=renderer;
			
			window=new Window();
			window.document=this;
			window.parent=parentWindow;
			if(parentWindow!=null){
				window.top=parentWindow.top;
			}else{
				window.top=window;
			}
			
			ActiveFonts=new Dictionary<string,DynamicFont>();
			Style=new Css.StyleSheet(this);
			html=new Element(this,null);
			html.SetTag("html");
			string ddbox="";
			
			if(parentWindow==null){
				// Dropdown box belongs to the top window only:
				ddbox="<ddbox></ddbox>";
			}
			
			html.innerHTML="<body></body>"+ddbox;
		}