//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.RelyingParty {
using System;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Drawing.Design;
using System.Web.UI;
using DotNetOpenAuth.Messaging;
///
/// A button that appears in the control that
/// allows the user to type in a user-supplied identifier.
///
public class SelectorOpenIdButton : SelectorButton {
///
/// Initializes a new instance of the class.
///
public SelectorOpenIdButton() {
Reporting.RecordFeatureUse(this);
}
///
/// Initializes a new instance of the class.
///
/// The image to display on the button.
public SelectorOpenIdButton(string imageUrl)
: this() {
Requires.NotNullOrEmpty(imageUrl, "imageUrl");
this.Image = imageUrl;
}
///
/// Gets or sets the path to the image to display on the button's surface.
///
/// The virtual path to the image.
[Editor("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[UrlProperty]
public string Image { get; set; }
///
/// Ensures that this button has been initialized to a valid state.
///
internal override void EnsureValid() {
Contract.Ensures(!string.IsNullOrEmpty(this.Image));
// Every button must have an image.
ErrorUtilities.VerifyOperation(!string.IsNullOrEmpty(this.Image), OpenIdStrings.PropertyNotSet, "SelectorButton.Image");
}
///
/// Renders the leading attributes for the LI tag.
///
/// The writer.
protected internal override void RenderLeadingAttributes(HtmlTextWriter writer) {
writer.AddAttribute(HtmlTextWriterAttribute.Id, "OpenIDButton");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "OpenIDButton");
}
///
/// Renders the content of the button.
///
/// The writer.
/// The containing selector control.
protected internal override void RenderButtonContent(HtmlTextWriter writer, OpenIdSelector selector) {
writer.AddAttribute(HtmlTextWriterAttribute.Src, selector.Page.ResolveUrl(this.Image));
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
writer.AddAttribute(HtmlTextWriterAttribute.Src, selector.Page.ClientScript.GetWebResourceUrl(typeof(OpenIdAjaxTextBox), OpenIdAjaxTextBox.EmbeddedLoginSuccessResourceName));
writer.AddAttribute(HtmlTextWriterAttribute.Class, "loginSuccess");
writer.AddAttribute(HtmlTextWriterAttribute.Title, selector.AuthenticatedAsToolTip);
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
}
}