2 // System.Web.UI.HtmlControls.HtmlHead
\r
5 // Lluis Sanchez Gual (lluis@novell.com)
\r
7 // (C) 2004 Novell, Inc.
\r
10 // Permission is hereby granted, free of charge, to any person obtaining
\r
11 // a copy of this software and associated documentation files (the
\r
12 // "Software"), to deal in the Software without restriction, including
\r
13 // without limitation the rights to use, copy, modify, merge, publish,
\r
14 // distribute, sublicense, and/or sell copies of the Software, and to
\r
15 // permit persons to whom the Software is furnished to do so, subject to
\r
16 // the following conditions:
\r
18 // The above copyright notice and this permission notice shall be
\r
19 // included in all copies or substantial portions of the Software.
\r
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
33 using System.ComponentModel;
\r
35 using System.Web.UI;
\r
36 using System.Web.UI.WebControls;
\r
37 using System.Collections;
\r
39 namespace System.Web.UI.HtmlControls
\r
41 [ControlBuilder (typeof(HtmlHeadBuilder))]
\r
42 public class HtmlHead: HtmlContainerControl, IPageHeader
\r
46 ArrayList styleSheets;
\r
47 StyleSheetBag styleSheet;
\r
49 public HtmlHead(): base("head") {}
\r
51 protected override void OnInit (EventArgs e)
\r
53 Page.SetHeader (this);
\r
56 protected override void RenderChildren (HtmlTextWriter writer)
\r
58 base.RenderChildren (writer);
\r
59 if (metadata != null) {
\r
60 foreach (DictionaryEntry entry in metadata) {
\r
61 writer.AddAttribute ("name", entry.Key.ToString ());
\r
62 writer.AddAttribute ("content", entry.Value.ToString ());
\r
63 writer.RenderBeginTag (HtmlTextWriterTag.Meta);
\r
64 writer.RenderEndTag ();
\r
68 if (styleSheet != null)
\r
69 styleSheet.Render (writer);
\r
72 protected override void AddParsedSubObject (object ob)
\r
74 if (ob is HtmlTitle)
\r
75 title = (HtmlTitle) ob;
\r
77 base.AddParsedSubObject (ob);
\r
80 protected internal override void AddedControl (Control control, int index)
\r
82 base.AddedControl (control, index);
\r
85 IList IPageHeader.LinkedStyleSheets {
\r
87 if (styleSheets == null) styleSheets = new ArrayList ();
\r
92 IDictionary IPageHeader.Metadata {
\r
94 if (metadata == null) metadata = new Hashtable ();
\r
99 IStyleSheet IPageHeader.StyleSheet {
\r
101 if (styleSheet == null) styleSheet = new StyleSheetBag (Page);
\r
106 string IPageHeader.Title {
\r
107 get { return title.Text; }
\r
108 set { title.Text = value; }
\r
112 internal class StyleSheetBag: IStyleSheet
\r
114 ArrayList entries = new ArrayList ();
\r
117 internal class StyleEntry
\r
119 public Style Style;
\r
120 public string Selection;
\r
121 public IUrlResolutionService UrlResolver;
\r
124 public StyleSheetBag (Page page)
\r
129 public void CreateStyleRule (Style style, string selection, IUrlResolutionService urlResolver)
\r
131 StyleEntry entry = new StyleEntry ();
\r
132 entry.Style = style;
\r
133 entry.UrlResolver = urlResolver;
\r
134 entry.Selection = selection;
\r
135 entries.Add (entry);
\r
138 public void RegisterStyle (Style style, IUrlResolutionService urlResolver)
\r
140 for (int n=0; n<entries.Count; n++) {
\r
141 if (((StyleEntry)entries[n]).Style == style)
\r
145 string name = "aspnet_" + entries.Count;
\r
146 style.SetRegisteredCssClass (name);
\r
147 CreateStyleRule (style, "." + name, urlResolver);
\r
150 public void Render (HtmlTextWriter writer)
\r
152 writer.AddAttribute ("type", "text/css");
\r
153 writer.RenderBeginTag (HtmlTextWriterTag.Style);
\r
155 foreach (StyleEntry entry in entries) {
\r
156 CssStyleCollection sts = entry.Style.GetStyleAttributes (entry.UrlResolver);
\r
157 writer.Write ("\n" + entry.Selection + " {" + sts.BagToString () + "}");
\r
160 writer.RenderEndTag ();
\r