csscollection.cs
来自「浏览器端看到树型目录结构,用户可以完整地看到像windows资源管理器一样的效果」· CS 代码 · 共 757 行 · 第 1/2 页
CS
757 行
/// <summary>
/// Gets the font size.
/// </summary>
/// <returns>The font size.</returns>
public string GetFontSize()
{
string szSize = this["font-size"];
if (szSize != null)
{
FontUnit fu = new FontUnit(szSize);
if (fu.Type == FontSize.NotSet)
{
return szSize;
}
else
{
return Util.ConvertToHtmlFontSize(fu);
}
}
return null;
}
/// <summary>
/// Gets background color.
/// </summary>
/// <returns>The background color.</returns>
public string GetBackColor()
{
string szBackColor = this["background-color"];
if (szBackColor == null)
szBackColor = this["background"];
if (szBackColor == null)
return null;
return Util.ColorToHexString(szBackColor);
}
/// <summary>
/// Detects if the border has been set.
/// </summary>
/// <returns>true if the border has been set.</returns>
public bool IsBorderSet()
{
foreach (string key in Keys)
{
// Check for border*
if ((key.IndexOf("border") == 0) && (key != String.Empty))
return true;
}
return false;
}
/// <summary>
/// Renders a font tag.
/// </summary>
/// <param name="writer">The HtmlTextWriter to receive the HTML.</param>
public void RenderBeginFontTag(HtmlTextWriter writer)
{
bool bAttribAdded = false;
string color = GetColor();
string fontFace = GetFontFace();
string fontSize = GetFontSize();
if (color != null)
{
writer.AddAttribute("COLOR", color);
bAttribAdded = true;
}
if (fontFace != null)
{
writer.AddAttribute("FACE", fontFace);
bAttribAdded = true;
}
if (fontSize != null)
{
writer.AddAttribute("SIZE", fontSize);
bAttribAdded = true;
}
if (bAttribAdded)
{
writer.RenderBeginTag(HtmlTextWriterTag.Font);
_bRenderFontTag = true;
}
}
/// <summary>
/// Renders the close tag.
/// </summary>
/// <param name="writer">The HtmlTextWriter to receive the HTML.</param>
public void RenderEndFontTag(HtmlTextWriter writer)
{
if (_bRenderFontTag)
writer.RenderEndTag();
}
/// <summary>
/// Renders bold and italic tags.
/// </summary>
/// <param name="writer">The HtmlTextWriter to receive the HTML.</param>
public void RenderBeginModalTags(HtmlTextWriter writer)
{
string fontWeight = GetFontWeight();
string fontStyle = GetFontStyle();
if (fontWeight == "bold" || fontWeight == "bolder" || fontWeight == "700" || fontWeight == "800" || fontWeight == "900")
{
writer.RenderBeginTag(HtmlTextWriterTag.B);
_bRenderBoldTag = true;
}
if (fontStyle == "italic" || fontStyle == "oblique")
{
writer.RenderBeginTag(HtmlTextWriterTag.I);
_bRenderItalicTag = true;
}
}
/// <summary>
/// Closes tags.
/// </summary>
/// <param name="writer">The HtmlTextWriter to receive the HTML.</param>
public void RenderEndModalTags(HtmlTextWriter writer)
{
if (_bRenderItalicTag)
writer.RenderEndTag();
if (_bRenderBoldTag)
writer.RenderEndTag();
}
/// <summary>
/// Adds the style attributes to the HtmlTextWriter.
/// </summary>
/// <param name="writer">The HtmlTextWriter that will receive the style attributes.</param>
public void AddAttributesToRender(HtmlTextWriter writer)
{
foreach (string name in this)
{
writer.AddStyleAttribute(name, this[name]);
}
if (writer is Html32TextWriter)
{
string cssText = CssText;
if (cssText != String.Empty)
{
writer.AddAttribute(HtmlTextWriterAttribute.Style, cssText);
}
}
}
/// <summary>
/// Loads the collection's previously saved view state.
/// </summary>
/// <param name="state">An Object that contains the saved view state values for the collection.</param>
void IStateManager.LoadViewState(object state)
{
if (state != null)
{
CssText = (string)state;
}
}
/// <summary>
/// Saves the changes to the collection's view state to an Object.
/// </summary>
/// <returns>The Object that contains the view state changes.</returns>
object IStateManager.SaveViewState()
{
if (_Dirty)
{
return CssText;
}
return null;
}
/// <summary>
/// Instructs the collection to track changes to its view state.
/// </summary>
void IStateManager.TrackViewState()
{
_IsTrackingViewState = true;
}
/// <summary>
/// Gets a value indicating whether the collection is tracking its view state changes.
/// </summary>
bool IStateManager.IsTrackingViewState
{
get { return _IsTrackingViewState; }
}
/// <summary>
/// Gets a value indicating whether the collection is dirty. The collection needs
/// to be tracking view state changes in order for this value to be anything other
/// than false.
/// </summary>
protected internal virtual bool Dirty
{
get { return _Dirty; }
set
{
if (((IStateManager)this).IsTrackingViewState)
{
_Dirty = value;
}
}
}
/// <summary>
/// Determines whether the specified Object is the same instance as the current Object.
/// </summary>
/// <param name="obj">The Object to compare with the current Object.</param>
/// <returns>true if the values are equal, false otherwise.</returns>
public override bool Equals(Object obj)
{
if (obj is CssCollection)
{
return CssText == ((CssCollection)obj).CssText;
}
return false;
}
/// <summary>
/// Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return CssText.GetHashCode();
}
/// <summary>
/// Whether the collection can be expanded.
/// </summary>
bool IList.IsFixedSize
{
get { return false; }
}
/// <summary>
/// Whether items in the collection can be changed.
/// </summary>
bool IList.IsReadOnly
{
get { return ((CssCollection)this).IsReadOnly; }
}
/// <summary>
/// Index into the array of keys.
/// </summary>
object IList.this[int index]
{
get { return ((CssCollection)this)[index]; }
set { ((CssCollection)this)[index] = (string)value; }
}
/// <summary>
/// Adds a key with an empty value.
/// </summary>
/// <param name="value">The name of the key.</param>
/// <returns>Index of the key in the key collection.</returns>
int IList.Add(object value)
{
((CssCollection)this).Add((string)value, String.Empty);
return ((IList)this).IndexOf(value);
}
/// <summary>
/// Clears the collection.
/// </summary>
void IList.Clear()
{
((CssCollection)this).Clear();
}
/// <summary>
/// Whether the value is in the collection.
/// </summary>
/// <param name="value">The key name to test for.</param>
/// <returns>True if the key was found.</returns>
bool IList.Contains(object value)
{
return ((CssCollection)this)[(string)value] != null;
}
/// <summary>
/// The index of the key.
/// </summary>
/// <param name="value">The key to look for.</param>
/// <returns>The index of the key or -1 if not found.</returns>
int IList.IndexOf(object value)
{
int index = 0;
foreach (string s in Keys)
{
if (s == (string)value)
{
return index;
}
index++;
}
return -1;
}
/// <summary>
/// Inserts the key. The index is ignored.
/// </summary>
/// <param name="index">The index is ignored.</param>
/// <param name="value">The key to add.</param>
void IList.Insert(int index, object value)
{
((IList)this).Add(value);
}
/// <summary>
/// Removes the key from the collection.
/// </summary>
/// <param name="value">The key to remove.</param>
void IList.Remove(object value)
{
((CssCollection)this).Remove((string)value);
}
/// <summary>
/// Removes the key at the specified index.
/// </summary>
/// <param name="index">The index of the key to remove.</param>
void IList.RemoveAt(int index)
{
((IList)this).Remove(((IList)this)[index]);
}
}
/// <summary>
/// Event arguments for CssCollection events.
/// </summary>
public class CssEventArgs : EventArgs
{
/// <summary>
/// The name of the CSS pair
/// </summary>
public readonly string Name;
/// <summary>
/// The CSS value
/// </summary>
public readonly string Value;
/// <summary>
/// Initializes a new instance of CssEventArgs
/// </summary>
/// <param name="name">The name of the attribute</param>
/// <param name="value">The value</param>
public CssEventArgs(string name, string value)
{
Name = name;
Value = value;
}
}
/// <summary>
/// Event handler delegate for CssCollection events.
/// </summary>
public delegate void CssEventHandler(CssCollection c, CssEventArgs e);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?