瀏覽代碼

[asp.net] Fix for bug #646984. Theme stylesheets must be output in correct order.

This patch changes the way we output theme stylesheets to match .NET behavior. Theme
.css files are sorted using an ordinal and case-insensitive comparer and are output
to the page at the top of the <head> element's contents instead of at the end.
Marek Habersack 15 年之前
父節點
當前提交
30bbf985d2

+ 2 - 1
mcs/class/System.Web/System.Web.Compilation/ThemeDirectoryBuildProvider.cs

@@ -5,7 +5,7 @@
 //   Chris Toshok ([email protected])
 //   Marek Habersack ([email protected])
 //
-// (C) 2008 Novell, Inc
+// (C) 2008-2010 Novell, Inc (http://novell.com)
 //
 
 //
@@ -80,6 +80,7 @@ namespace System.Web.Compilation
 				css_urls [i] = VirtualPathUtility.Combine (vp, Path.GetFileName (css_files [i]));
 				ptp.AddDependency (css_urls [i]);
 			}
+			Array.Sort (css_urls, StringComparer.OrdinalIgnoreCase);
 			ptp.LinkedStyleSheets = css_urls;
 			
 			AspComponentFoundry shared_foundry = new AspComponentFoundry ();

+ 2 - 0
mcs/class/System.Web/System.Web.Compilation/ThemeDirectoryCompiler.cs

@@ -55,6 +55,8 @@ namespace System.Web.UI
 				ptp.AddDependency (css_files [i]);
 				css_urls [i] = virtualPath + Path.GetFileName (css_files [i]);
 			}
+
+			Array.Sort (css_urls, StringComparer.OrdinalIgnoreCase);
 			ptp.LinkedStyleSheets = css_urls;
 			
 			AspComponentFoundry shared_foundry = new AspComponentFoundry ();

+ 28 - 10
mcs/class/System.Web/System.Web.UI/Page.cs

@@ -2637,27 +2637,45 @@ public partial class Page : TemplateControl, IHttpHandler
 		return dataItemCtx.Peek ();
 	}
 
+	void AddStyleSheets (PageTheme theme, ref List <string> links)
+	{
+		if (theme == null)
+			return;
+
+		string[] tmpThemes = theme != null ? theme.GetStyleSheets () : null;
+		if (tmpThemes == null || tmpThemes.Length == 0)
+			return;
+
+		if (links == null)
+			links = new List <string> ();
+
+		links.AddRange (tmpThemes);
+	}
+	
 	protected internal override void OnInit (EventArgs e)
 	{
 		base.OnInit (e);
 
-		var themes = new List <string> ();
+		List <string> themes = null;
+		AddStyleSheets (StyleSheetPageTheme, ref themes);
+		AddStyleSheets (PageTheme, ref themes);
 
-		if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
-			themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
+		if (themes == null)
+			return;
 		
-		if (PageTheme != null && PageTheme.GetStyleSheets () != null)
-			themes.AddRange (PageTheme.GetStyleSheets ());
-
-		if (themes.Count > 0 && Header == null)
+		HtmlHead header = Header;
+		if (themes != null && header == null)
 			throw new InvalidOperationException ("Using themed css files requires a header control on the page.");
-
-		foreach (string lss in themes) {
+		
+		ControlCollection headerControls = header.Controls;
+		string lss;
+		for (int i = themes.Count - 1; i >= 0; i--) {
+			lss = themes [i];
 			HtmlLink hl = new HtmlLink ();
 			hl.Href = lss;
 			hl.Attributes["type"] = "text/css";
 			hl.Attributes["rel"] = "stylesheet";
-			Header.Controls.Add (hl);
+			headerControls.AddAt (0, hl);
 		}
 	}