/// /// Copyright © 2003-2008 JetBrains s.r.o. /// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder). /// using System; using System.Collections; using System.Reflection; using System.Windows.Forms; namespace JetBrains.Omea.OpenAPI { #region Abstract Web Browser Pseudo-Interface /// /// The base interface for a Web browser embedded in Omea. /// public abstract class AbstractWebBrowser : UserControl, ICommandProcessor { /// /// Navigates a web browser to show a page identified by the URI specified. /// /// URI of the resource to display. That may be a web page, a file, a MSDN collection topic, or some custom protocol scheme resource. public abstract void Navigate( string url ); /// /// Navigates a web browser to show a page identified by the URI specified, within the same browser window. /// /// URI of the resource to display. That may be a web page, a file, a MSDN collection topic, or some custom protocol scheme resource. public abstract void NavigateInPlace( string url ); /// /// Renders the specified HTML text in the browser window as if it were downloaded from a web site or a file. /// /// HTML text. This must be a complete and well-formed web page, better XHTML. /// /// This function provides for displaying your page in the embedded web browser by directly uploading its contents into the browser. /// The browser maintains its history which allows to go Back and Forward within the browser using the Omea Back and Forward actions. The history typically consists of two stacks: pages visited in this session before the current page — Back stack, and pages visited "after" it (this means the pages we've visited but then undone using the "back" action) — Forward stack. If we navigate to a new page, the current one is pushed to the Back stack and the Forward stack is emptied. If we invoke the "back" action, the current page gets pushed into the Forward stack and a page popped from the Back stack gets into the browser. If we invoke the "forward" action, the current page goes into the "Back" stack and a page popped out of the Forward stack gets into the browser. /// Each time you inovke the ShowHtml action, the history is reset, which means that both Back and Forward stacks get empty and a new History session starts. If you press either Back or Forward button in this state, the action would not be processed by the browser and will be delegated to the Omea framework. /// Do not call this function before the control window is created. Use property instead. /// [Obsolete( "Use another overload of the ShowHtml method that allows to supply the WebSecurityContext.", false )] public abstract void ShowHtml( string html ); /// /// Renders the specified HTML text in the browser window as if it were downloaded from a web site or a file. /// /// HTML text. This must be a complete and well-formed web page, better XHTML. /// Security context to display the content in. Defines whether the images are displayed, scripts executed, java enabled, and so on, also allows to speicfy one of the standard Internet Security Zones. /// /// This function provides for displaying your page in the embedded web browser by directly uploading its contents into the browser. /// The browser maintains its history which allows to go Back and Forward within the browser using the Omea Back and Forward actions. The history typically consists of two stacks: pages visited in this session before the current page — Back stack, and pages visited "after" it (this means the pages we've visited but then undone using the "back" action) — Forward stack. If we navigate to a new page, the current one is pushed to the Back stack and the Forward stack is emptied. If we invoke the "back" action, the current page gets pushed into the Forward stack and a page popped from the Back stack gets into the browser. If we invoke the "forward" action, the current page goes into the "Back" stack and a page popped out of the Forward stack gets into the browser. /// Each time you inovke the ShowHtml action, the history is reset, which means that both Back and Forward stacks get empty and a new History session starts. If you press either Back or Forward button in this state, the action would not be processed by the browser and will be delegated to the Omea framework. /// Do not call this function before the control window is created. Use property instead. /// /// 2.0 public abstract void ShowHtml( string html, WebSecurityContext ctx ); /// /// Renders the specified HTML text in the browser window as if it were downloaded from a web site or a file. /// /// HTML text. This must be a complete and well-formed web page, better XHTML. /// Security context to display the content in. Defines whether the images are displayed, scripts executed, java enabled, and so on, also allows to speicfy one of the standard Internet Security Zones. May be null, in this case the browser defaults to some unspecified set of permissions. /// The words to be highlighted in the loaded content. May be null, which means no highlighting should be applied. /// /// This function provides for displaying your page in the embedded web browser by directly uploading its contents into the browser. /// The browser maintains its history which allows to go Back and Forward within the browser using the Omea Back and Forward actions. The history typically consists of two stacks: pages visited in this session before the current page — Back stack, and pages visited "after" it (this means the pages we've visited but then undone using the "back" action) — Forward stack. If we navigate to a new page, the current one is pushed to the Back stack and the Forward stack is emptied. If we invoke the "back" action, the current page gets pushed into the Forward stack and a page popped from the Back stack gets into the browser. If we invoke the "forward" action, the current page goes into the "Back" stack and a page popped out of the Forward stack gets into the browser. /// Each time you inovke the ShowHtml action, the history is reset, which means that both Back and Forward stacks get empty and a new History session starts. If you press either Back or Forward button in this state, the action would not be processed by the browser and will be delegated to the Omea framework. /// You should use this method to apply highlighting, rather then , because it provides better performance and is capable of highlighting exactly those words that were found by the search, and not all the similar words in the document. /// Do not call this function before the control window is created. Use property instead. /// /// 2.0 public abstract void ShowHtml( string html, WebSecurityContext ctx, WordPtr[] wordsToHighlight ); /// /// Highlights the specified words in the page text when download is complete. /// Can be used, for example, for highlighting search results. /// /// A set of words to highlight. May be null if no highlighting is actually required. /// The offset to subtract from the offsets passed in WordPtr structures. /// Words with offsets less than should be ignored. [Obsolete( "Use ShowHtml overload with the wordsToHighlight parameter to apply word highlighting on the content-feeding stage in order to improve highlighting performance and quality.", false )] public abstract void HighlightWords( WordPtr[] words, int startOffset ); /// /// Checks if the command with the specified ID can be executed in the current state /// of the control. /// /// The ID of the command. /// true if the ID of the command is known to the control and can be /// executed; false otherwise. public abstract bool CanExecuteCommand( string command ); /// /// Executes the command with the specified ID. /// /// ID of the command to execute. public abstract void ExecuteCommand( string command ); /// /// Controls whether the browser displays images in the HTML page or not. /// [Obsolete( "Set WebSecurityContext.ShowPictures instead, and pass that secutity context to the ShowHtml( string, WebSecurityContext ) method.", false )] public abstract bool ShowImages { get; set; } /// /// The display name of the current Web page URL. /// /// /// Note that the property setter should not invoke navigation to the new URL. /// Instead, it should save the supplied value and use it for display whenever applicable /// instead of the original URL of the page currently displayed in the browser. /// The property getter should return the display name obtained from property setter, or, /// if it was not called, the location URL of the current Web page. Each navigation or /// content feeding action should reset the override established with the property setter. /// If the current URL is undefined (ie the browser has not been given the content or navigated yet), the property getter should return either a null value or an empty string. If the current URL is not applicable (ie the browser has been populated with content directly), the getter should return an empty string. /// public abstract string CurrentUrl { get; set; } /// /// Retrieves the text currently selected in the page, in an HTML-formatted representation. /// /// /// Remember that it is a costly operation. Take care when using it on a regular basis, and try to reduce the calls frequency. /// public abstract string SelectedHtml { get; } /// /// Retrieves the text currently selected in the page, in a plain-text, unformatted representation. /// /// /// Remember that it is a costly operation. Take care when using it on a regular basis, and try to reduce the calls frequency. /// public abstract string SelectedText { get; } /// /// Gets the title of the document or Web page currently viewed in the browser. /// /// /// The event fires when the value of this property changes. /// If the title is not available (for example, the Web browser has not been created yet), returns an empty string. /// /// 2.0 public abstract string Title { get; } /// /// Fires when the title of the document or Web page currently viewed in the browser (see property) changes. /// /// 2.0 public abstract event EventHandler TitleChanged; /// /// Represents the security context in which the content is being displayed by the Web browser. /// /// /// Note that in order to reuse the browser object it is shared between multiple plugins, so you have to re-apply the security context each time you want to show new content, to ensure that the security is not violated. Use the overload which allows to specify the context explicitly whenever possible. /// /// 2.0 public abstract WebSecurityContext SecurityContext { get; set; } /// /// The context provider that supplies the action context, which the browser should use /// for showing context menus and doing other UI actions. /// /// /// This is an input property rather than an output one, which means that /// the context provider is supplied into the Web browser by its consumer. /// It should be stored by the Web browser internally and used to retrieve /// the action context through its method. /// The property getter should simply return the value supplied to the Web browser before. /// /// 2.0 public abstract IContextProvider ContextProvider { get; set; } /// /// Provides access to the HTML content currently being displayed in the Web browser. Also, by assigning this property to a new value, allows to upload HTML content into the browser. /// /// HTML content being displayed in the browser. /// /// This property can be set up at design-time or at any moment, even before the control window is created. /// A null value or empty string means that no content will be loaded into the control when it's created. Passing a null value when control has already been created is illegal. The default value that should be returned before the control is created and if no special content has been assigned to the control is an empty string. /// /// 2.0 public abstract string Html { get; set; } /// /// Creates a new instance of the Web browser control that can be placed on a Windows form. /// /// A browser control instance. /// /// For display panes, consider using the default instance of the abstract web browser. /// /// 2.0 public abstract AbstractWebBrowser NewInstance(); /// /// Border style for the Web Browser control. Note that not all the possible enumeration values are necessarily supported. /// /// 2.0 public abstract BorderStyle BorderStyle { get; set; } /// /// Provides programmatical access to the document element of the HTML document loaded in the control. /// /// 2.0 public abstract IHtmlDomDocument HtmlDocument { get; } /// /// Fired by Web browser when page title changes so that the Resource Manager could update the title in UI if appropriate. /// /// 2.0 new public abstract event KeyEventHandler KeyDown; /// /// Fired by the Web browser when a context menu is about to be displayed. /// /// /// Having sinked this event, you may show your own context menu or cancel the default context menu displayed by the Web browser, which is the menu by default. /// Also you may enable display of the underlying browser's native context menu in particular cases. /// The corresponding event argument properties, and , are filled in by the Web browser before raising the event so that they would indicate the browser-preferred behavior which would have taken place in absence of custom processing in response to this event. For example, Omea menu is suppressed for anchors and images. You may use this information as well as the hit target to decide for showing the menu or not. /// /// 2.0 new public abstract event ContextMenuEventHandler ContextMenu; /// /// Retrieves the ready state of the Web browser. /// /// 2.0 public abstract BrowserReadyState ReadyState { get; } /// /// Fires when a document finishes loading into the Web browser and is completely ready for interaction, including the full DOM. /// /// 2.0 public abstract event DocumentCompleteEventHandler DocumentComplete; /// /// Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations. /// /// 2.0 public abstract void Stop(); /// /// Fires before navigation occurs in the given object on either a window or frameset element. /// /// Allows to cancel the navigation or control whether it occurs in-place, in external window, etc. /// 2.0 public abstract event BeforeNavigateEventHandler BeforeNavigate; /// /// Fires before the HTML content gets actually uploaded into the Web browser. /// /// /// Provides access to the original HTML, the formatted HTML that contains highlighting data, and allows to cancel feeding the data. /// /// 2.0 public abstract event BeforeShowHtmlEventHandler BeforeShowHtml; } #region AbstractWebBrowser Events Data Types #region AbstractWebBrowser.ContextMenu Event Supplementary Data /// /// Arguments for the event. /// /// 2.0 public class ContextMenuEventArgs : EventArgs { /// /// Specifies whether the default Omea context menu should be cancelled. /// /// /// If not cancelled, the default Omea menu will be displayed after returning from this handler. /// The actions present in this context menu are picked according to the context provided by the Web browser. If a context provider is specified for the Web browser, it is queried for the context as well. /// The default value for this parameter is False, which means that Omea context menu is the one and only context menu displayed in case the event handler does nothing. /// private bool _isOmeaMenuCancelled = false; /// /// Specifies whether the native Web browser's context menu should be cancelled. /// /// If not cancelled, the native Web browser menu will be displayed after returning from this handler (after Omea menu displayes, if not cancelled). /// Context menu items for this menu are determined by the Web browser itself and do not correspond to Omea selected resource and so on. /// The default value for this parameter is True, which means that Omea context menu is the one and only context menu displayed in case the event handler does nothing. private bool _isNativeMenuCancelled = true; /// /// X-coordinate for the context menu, in pixels. This value is given in screen coordinates. /// private int _x; /// /// Y-coordinate for the context menu, in pixels. This value is given in screen coordinates. /// private int _y; /// /// Type of the HTML element right-clicking on which has caused the context menu to appear, or the active element if the context menu was requested by keyboard. /// private ContextMenuTargetType _targetType; /// /// The HTML element right-clicking on which has caused the context menu to appear, or the active element if the context menu was requested by keyboard. /// private IHtmlDomElement _target; /// /// Action context for the context menu actions provided by the Web browser. /// private IActionContext _actionContext; /// /// Initializes the event arguments object. /// /// X-coordinate for the context menu, in pixels. This value is given in screen coordinates. /// Y-coordinate for the context menu, in pixels. This value is given in screen coordinates. /// Type of the HTML element right-clicking on which has caused the context menu to appear, or the active element if the context menu was requested by keyboard. /// The HTML element right-clicking on which has caused the context menu to appear, or the active element if the context menu was requested by keyboard. /// Action context for the context menu actions provided by the Web browser. public ContextMenuEventArgs( int x, int y, ContextMenuTargetType targetType, IHtmlDomElement target, IActionContext actionContext ) { // Store the arguments _x = x; _y = y; _targetType = targetType; _target = target; _actionContext = actionContext; } /// /// Specifies whether the default Omea context menu should be cancelled. /// /// /// If not cancelled, the default Omea menu will be displayed after returning from this handler. /// The actions present in this context menu are picked according to the context provided by the Web browser. If a context provider is specified for the Web browser, it is queried for the context as well. /// The default value for this parameter is False, which means that Omea context menu is the one and only context menu displayed in case the event handler does nothing. /// public bool CancelOmeaMenu { get { return _isOmeaMenuCancelled; } set { _isOmeaMenuCancelled = value; } } /// /// Specifies whether the native Web browser's context menu should be cancelled. /// /// If not cancelled, the native Web browser menu will be displayed after returning from this handler (after Omea menu displayes, if not cancelled). /// Context menu items for this menu are determined by the Web browser itself and do not correspond to Omea selected resource and so on. /// The default value for this parameter is True, which means that Omea context menu is the one and only context menu displayed in case the event handler does nothing. public bool CancelNativeMenu { get { return _isNativeMenuCancelled; } set { _isNativeMenuCancelled = value; } } /// /// X-coordinate for the context menu, in pixels. This value is given in screen coordinates. /// public int X { get { return _x; } } /// /// Y-coordinate for the context menu, in pixels. This value is given in screen coordinates. /// public int Y { get { return _y; } } /// /// Type of the HTML element right-clicking on which has caused the context menu to appear, or the active element if the context menu was requested by keyboard. /// public ContextMenuTargetType TargetType { get { return _targetType; } } /// /// The HTML element right-clicking on which has caused the context menu to appear, or the active element if the context menu was requested by keyboard. /// public IHtmlDomElement Target { get { return _target; } } /// /// Action context for the context menu actions provided by the Web browser. /// public IActionContext ActionContext { get { return _actionContext; } } } /// /// Delegate type for the event. /// /// 2.0 public delegate void ContextMenuEventHandler( object sender, ContextMenuEventArgs args ); #endregion #region AbstractWebBrowser.DocumentComplete Event Supplimentary Data /// /// An event handler delegate type for the event. /// /// 2.0 public delegate void DocumentCompleteEventHandler( object sender, DocumentCompleteEventArgs args ); /// /// Event arguments class for the event. /// /// 2.0 public class DocumentCompleteEventArgs { /// /// URI of the document that has finished loading. /// private string _uri; /// /// Initializes the object. /// /// URI of the document that has finished loading. public DocumentCompleteEventArgs( string uri ) { _uri = uri; } /// /// URI of the document that has finished loading. /// public string Uri { get { return _uri; } } } #endregion #region AbstractWebBrowser.BeforeNavigate Event Supplimentary Types /// /// An event handler delegate type for the event. /// /// 2.0 public delegate void BeforeNavigateEventHandler( object sender, BeforeNavigateEventArgs args ); /// /// Event arguments class for the event. /// /// 2.0 public class BeforeNavigateEventArgs { #region Data private readonly string _uri; private readonly string _frame; private readonly object _postData; private readonly string _headers; private readonly BrowserNavigationCause _cause; private bool _cancel = false; private bool _inplace = false; #endregion #region Ctor public BeforeNavigateEventArgs( string uri, string frame, object postData, string headers, BrowserNavigationCause cause ) { _uri = uri; _frame = frame; _postData = postData; _headers = headers; _cause = cause; } #endregion #region Gettersetters /// /// The URI to be navigated to. /// public string Uri { get { return _uri; } } /// /// The name of the frame in which the resource should be displayed, or NULL if no named frame is targeted for the resource. /// public string Frame { get { return _frame; } } /// /// HTTP POST data. /// public object PostData { get { return _postData; } } /// /// HTTP headers to be sent to server. /// public string Headers { get { return _headers; } } /// /// Gets or sets whether navigation should be cancelled. /// public bool Cancel { get { return _cancel; } set { _cancel = value; } } /// /// Gets or sets whether the navigation should happen in-place. /// public bool Inplace { get { return _inplace; } set { _inplace = value; } } /// /// The cause due to which the navigation is about to occur. /// public BrowserNavigationCause Cause { get { return _cause; } } #endregion } #endregion #region AbstractWebBrowser.BeforeShowHtml Event Supplimentary Data /// /// An event handler delegate type for the event. /// /// 2.0 public delegate void BeforeShowHtmlEventHandler( object sender, BeforeShowHtmlEventArgs args ); /// /// Event arguments class for the event. /// /// 2.0 public class BeforeShowHtmlEventArgs { #region Data private string _sourceHtml; private string _formattedHtml; private WebSecurityContext _ctx; private string _uriDisplayName; #endregion #region Ctor public BeforeShowHtmlEventArgs( string sourceHtml, string formattedHtml, WebSecurityContext ctx, string uriDisplayName ) { _sourceHtml = sourceHtml; _formattedHtml = formattedHtml; _ctx = ctx; _uriDisplayName = uriDisplayName; } #endregion #region Gettersetters /// /// Gets the original HTML text that was submitted for upload to the method or property. /// /// If you would like to alter the display text, put it into the property. public string SourceHtml { get { return _sourceHtml; } } /// /// Gets or sets the HTML text that will be uploaded into the browser, with all the appropriate formatting applied, /// for example, search terms highlighting tags. It is non-Null even if no formatting was applied, /// use string comparison with if you need to check whether it was formatted or not. /// /// You may apply additional formatting and submit the new HTML content into this property. public string FormattedHtml { get { return _formattedHtml; } set { _formattedHtml = value; } } /// /// Gets or sets the security context that will be used for displaying the provided content. /// public WebSecurityContext SecurityContext { get { return _ctx; } set { _ctx = value; } } /// /// Gets or sets the URI's display name, the same that can be furtherly accessed thru the property. /// /// /// As the manually-uploaded content has no native URI, it can be assigned manually to be then queried thru the /// property just as an ordinary Web page URI that can be displayed in the title, /// header, etc. /// Initially, this property will provide an empty string ("") as there's no predefined URI to be assigned /// to the manually-uploaded content. /// public string UriDisplayName { get { return _uriDisplayName; } set { _uriDisplayName = value; } } #endregion } #endregion #endregion #region Web Browser's Security Context et cetera /// /// Defines a security context in which the Web browser should display its content. Use , , or to obtain a default security context. /// /// /// There is a set of predefined templates for the standard security contexts, which can be obtained from , , or . You can freely modify the returned objects to derive a security context from a standard one, and those changes would not affect other instances, both existing and future, obtained from the same property. /// The typical use consists of obtaining a default security context, setting up its parameters, and storing the object in your plugin, supplying it to the Web browser each time you wish to display some content. /// Note that in order to reuse the browser object it is shared between multiple plugins, so you have to re-apply the security context each time you want to show new content, to ensure that the security is not violated. /// /// 2.0 public class WebSecurityContext { /// /// You should not create instances of this class directly. Instead, consider using one of the default contexts , , or , and altering their individual parameters, if needed. /// private WebSecurityContext() { } /// /// Specifies whether graphical images should be included when pages are displayed. /// /// /// If is set to False, you can still display an individual picture on a Web page by right-clicking its icon, and then clicking Show Picture. /// If the pictures on the current page are still visible after you set to False, you can hide them by forcing Refresh. /// public bool ShowPictures { get { return _bShowPictures; } set { _bShowPictures = value; } } private bool _bShowPictures = true; /// /// Specifies whether video clips can play when pages are displayed. /// /// /// If is set to False, you can still display an individual animation on a Web page by right-clicking its icon, and then clicking Show Picture. /// public bool PlayVideos { get { return _bPlayVideos; } set { _bPlayVideos = value; } } private bool _bPlayVideos = true; /// /// Specifies whether music and other sounds can play when pages are displayed. /// /// /// If RealNetworks RealAudio is installed, or if a video clip is playing, some sounds might play even if you set to False. /// public bool PlaySounds { get { return _bPlaySounds; } set { _bPlaySounds = value; } } private bool _bPlaySounds = true; /// /// Specifies whether the Web browser is working in silent mode. In silent mode, no UI prompts are shown to the user. /// public bool SilentMode { get { return _bSilentMode; } set { _bSilentMode = value; } } private bool _bSilentMode = false; /// /// Specifies whether the Web browser is prevented form accessing the Internet while displaying the content. /// public bool WorkOffline { get { return _bWorkOffline; } set { _bWorkOffline = value; } } private bool _bWorkOffline = false; /// /// Defines the Internet Security Zone to display the Web page in. /// /// /// The Security Zones are defined in the Internet Options applet in the Control Panel. /// This property has no effect unless the property is set to . /// You might use one of the enumeration constants to specify the Internet Security Zone (casted to ), as well as any of user-defined security zone numbers which typically reside in the 1000 … 10000 range, while the predefined security zones occupy the 0 … 999 space. /// public int SecurityZone { get { return _nSecurityZone; } set { _nSecurityZone = value; } } private int _nSecurityZone = (int) System.Security.SecurityZone.Untrusted; /// /// Defines a permission set that is granted to the content being viewed in the web browser. /// /// If set to , the property takes effect. public WebPermissionSet PermissionSet { get { return _permissions; } set { _permissions = value; } } private WebPermissionSet _permissions = WebPermissionSet.Auto; /// /// Specifies whether the user is allowed to navigate out of the Web page by clicking its links or invoking the navigation actions from client script. /// public bool AllowNavigation { get { return _bAllowNavigation; } set { _bAllowNavigation = value; } } private bool _bAllowNavigation = true; /// /// Specifies whether in-place navigation is allowed. If yes, the links are opened depending on the Omea settings, either inplace or in a new browser. If not, all the links are forced to be opened in another browser instance. /// public bool AllowInPlaceNavigation { get { return _bAllowInPlaceNavigation; } set { _bAllowInPlaceNavigation = value; } } private bool _bAllowInPlaceNavigation = true; /// /// Specifies whether user can select text in the browser with the mouse and carry out operations on the selection. /// public bool AllowSelect { get { return _bAllowSelect; } set { _bAllowSelect = value; } } private bool _bAllowSelect = true; /// /// The security context set up for default Internet browsing. /// public static WebSecurityContext Internet { get { WebSecurityContext ctx = new WebSecurityContext(); ctx.PermissionSet = WebPermissionSet.Auto; ctx.PlaySounds = true; ctx.PlayVideos = true; ctx.ShowPictures = true; ctx.SilentMode = false; ctx.WorkOffline = false; ctx.AllowNavigation = true; ctx.AllowInPlaceNavigation = true; ctx.AllowSelect = true; return ctx; } } /// /// The security context set up for viewing the untrasted content. /// public static WebSecurityContext Restricted { get { WebSecurityContext ctx = new WebSecurityContext(); ctx.PermissionSet = WebPermissionSet.Nothing; ctx.PlaySounds = true; ctx.PlayVideos = true; ctx.ShowPictures = true; ctx.SilentMode = true; ctx.WorkOffline = true; ctx.AllowNavigation = true; ctx.AllowInPlaceNavigation = true; ctx.AllowSelect = true; return ctx; } } /// /// The security context set up for viewing the trusted content. /// public static WebSecurityContext Trusted { get { WebSecurityContext ctx = new WebSecurityContext(); ctx.PermissionSet = WebPermissionSet.Everything; ctx.PlaySounds = true; ctx.PlayVideos = true; ctx.ShowPictures = true; ctx.SilentMode = false; ctx.WorkOffline = false; ctx.AllowNavigation = true; ctx.AllowInPlaceNavigation = true; ctx.AllowSelect = true; return ctx; } } } /// /// Defines a permission set which applies to a page being viewed in the Web browser window through the security context object. /// /// 2.0 public enum WebPermissionSet { /// /// No permissions granted. The Web page is being viewed in the restricted environment. Use for content obtained from an untrysty source or one which display the user cannot control (e. g. mail messages). /// Nothing, /// /// All permissions granted. The Web page is being viewed in the trusted environment. Use for content obtained from a trustworthy source, for example, the pages generated by Omea which need to interact with the application. /// Everything, /// /// The security zone is determined automatically, using the Internet Security Zones set up on this computer (see Control Panel, Internet Options). This option needs the content URI to function and is not effective if the content is being directly fed into the Web browser and has no URI. In the latter case, the Nothing permission set is assumed by default. /// Auto, /// /// An Internet Security Zone is explicitly defined by the property. The Zones are defined by the Internet Options applet form the Control Panel. /// Zone } #endregion #endregion #region HtmlDom /// /// A base wrapper for the generic object in the W3C HTML Document Object Model. /// /// 2.0 public interface IHtmlDomObject { /// /// Provides immediate access to an object that represents the document object. This object can be called via the late binding mechanism from the languages capable of making such calls. /// object Instance { get; } /// /// Invokes a generic method on the object. /// /// Name of the method. /// Arguments for the invocation. /// Return value of the method. object InvokeMethod( string name, params object[] args ); /// /// Retrieves a value of the generic property of the object. /// /// Name of the property. /// Property value. object GetProperty( string name ); /// /// Assigns a value to a generic property of the object. /// /// Name of the property. /// Proposed property value. void SetProperty( string name, object value ); } /// /// A wrapper for the Document object in the W3C HTML Document Object Model. /// /// 2.0 public interface IHtmlDomDocument : IHtmlDomObject { /// /// Looks up an HTML element with a specific ID. /// /// ID of the element. /// The desired HTML element, or Null, if it cannot be found. IHtmlDomElement GetElementById( string id ); /// /// The body element of the document. /// IHtmlDomElement Body { get; } /// /// Creates an instance of the HTML element for the specified tag. /// /// Tag name for the element. /// The newly-created element. IHtmlDomElement CreateElement( string tagName ); } /// /// A wrapper for an element object in the W3C HTML Document Object Model. /// /// 2.0 public interface IHtmlDomElement : IHtmlDomObject { #region General /// /// Gets or sets the ID of an HTML element. /// string Id { get; set; } /// /// Gets or sets the name of an HTML element. /// /// The name is represented by the name HTML attribute. string Name { get; set; } #endregion #region Contents /// /// Gets or sets the HTML representation of element contents, not including the own element's tags. /// string InnerHtml { get; set; } /// /// Gets the HTML representation of element contents, including the own element's tags. /// string OuterHtml { get; } /// /// Gets or sets the text representation of element's contents. /// string InnerText { get; set; } #endregion #region Positioning /// /// Causes the object to scroll into view, aligning it either at the top or bottom of the window. /// /// /// If True, scrolls the object so that top of the object is visible at the top of the window. /// If False, scrolls the object so that the bottom of the object is visible at the bottom of the window. /// void ScrollIntoView( bool bAlignToTop ); /// /// Gets the calculated top position of the object relative to the layout or coordinate parent, as specified by the offsetParent property. /// The dimensions are measured in pixels. /// int OffsetTop { get; } /// /// Gets the calculated left position of the object relative to the layout or coordinate parent, as specified by the offsetParent property. /// The dimensions are measured in pixels. /// int OffsetLeft { get; } /// /// Gets the height of the object relative to the layout or coordinate parent, as specified by the offsetParent property. /// The dimensions are measured in pixels. /// int OffsetHeight { get; } /// /// Gets the width of the object relative to the layout or coordinate parent, as specified by the offsetParent property. /// The dimensions are measured in pixels. /// int OffsetWidth { get; } /// /// Gets or sets the distance between the left edge of the object and the leftmost portion of the content currently visible in the window. /// The dimensions are measured in pixels. /// int ScrollLeft { get; set; } /// /// Gets or sets the distance between the top of the object and the topmost portion of the content currently visible in the window. /// The dimensions are measured in pixels. /// int ScrollTop { get; set; } /// /// Gets the scrolling width of the object. /// The dimensions are measured in pixels. /// int ScrollWidth { get; } /// /// Gets the scrolling height of the object. /// The dimensions are measured in pixels. /// int ScrollHeight { get; } /// /// Gets the distance between the property and the true left side of the client area. /// /// /// The difference between the and properties is the border of the object. /// int ClientLeft { get; } /// /// Gets the distance between the property and the true top of the client area. /// /// /// The difference between the and properties is the border area of the object. /// int ClientTop { get; } /// /// Gets the width of the object including padding, but not including margin, border, or scroll bar. /// int ClientWidth { get; } /// /// Gets the height of the object including padding, but not including margin, border, or scroll bar. /// int ClientHeight { get; } /// /// Simulates a click on a scroll-bar component. /// /// Specifies how the object scrolls. /// /// Cascading Style Sheets (CSS) allow you to scroll on all objects through the Overflow property. /// When the content of an element changes and causes scroll bars to display, the method might not work correctly immediately following the content update. When this happens, you can use the SetTimeout method to enable the browser to recognize the dynamic changes that affect scrolling. /// void DoScroll( ScrollAction action ); /// /// Gets a reference to the container object that defines the and properties of the object. /// IHtmlDomElement OffsetParent { get; } #endregion #region Hierarchy /// /// Gets the parent object in the object hierarchy. /// /// The topmost object returns null as its parent. IHtmlDomElement ParentElement { get; } /// /// Removes the object from the document hierarchy. /// /// Specifies whether the child nodes of the object are removed. void RemoveNode( bool deep ); /// /// Gets a collection of child nodes (HTML elements and text nodes) of this element. /// /// Note that a text node object lacks support for some of the properties or methods. IEnumerable /**/ ChildNodes { get; } /// /// Inserts an element into the document hierarchy as a child node of a parent object. /// /// Element to be inserted. Elements can be created with . /// Element before which a new one should be inserted, or Null to insert at the end. /// The newly-inserted element. IHtmlDomElement InsertBefore( IHtmlDomElement newChild, IHtmlDomElement refChild ); /// /// Appends an element as a child to the object. /// /// Element to be inserted. Elements can be created with . /// The newly-inserted element. IHtmlDomElement AppendChild( IHtmlDomElement newChild ); /// /// Returns a collection of the child elements (direct and indirect) with the tag name specified. /// /// Tag name of the child elements, case-insensitive by default. /// An enumerator for the collection. IEnumerable /**/ GetElementsByTagName( string tagname ); #endregion #region Attributes /// /// Gets the name of the CSS class assigned to this element. /// /// The class name is represented by the class attribute of an HTML element, like "selected" in "<div class="selected">text</div>". string ClassName { get; set; } /// /// Gets the tag name of the object. /// /// A tag name is the name of the tag which represents this element in HTML text, for example, "DIV" for a "<div>some content</div>". string TagName { get; } /// /// Retrieves an attribute of the HTML element by its name. /// /// Name of the attribuite, either case-sensitive or not. /// Flags that affect the retrieval. /// Attribute value. /// In the case-insensitive case, if more than one attribute fits the name, only one is returned. object GetAttribute( string name, GetAttributeFlags flags ); /// /// Retrieves an attribute of the HTML element by its name. /// /// Name of the attribuite, case-insensitive. /// Attribute value. /// In the case-insensitive case, if more than one attribute fits the name, only one is returned. object GetAttribute( string name ); /// /// Assigns a value to an attribute of the HTML element. /// /// Name of the attribute. /// Proposed value for the attribute. /// Specifies whether the attribute search is case-sensitive or not. /// Case-insensitive search picks the first suitable attribute. void SetAttribute( string name, object value, bool caseSensitive ); #endregion #region Events #region Mouse Events Family /// /// Fires when the user clicks the left mouse button on the object. /// event HtmlEventHandler Click; /// /// Fires when the user double-clicks the left mouse button on the object. /// event HtmlEventHandler DoubleClick; /// /// Fires when the user moves the mouse pointer into the object. /// event HtmlEventHandler MouseEnter; /// /// Fires when the user moves the mouse pointer outside the boundaries of the object. /// event HtmlEventHandler MouseLeave; /// /// Fires when the user clicks the object with either mouse button. /// event HtmlEventHandler MouseDown; /// /// Fires when the wheel button is rotated. /// event HtmlEventHandler MouseWheel; /// /// Fires when the user moves the mouse over the object. /// event HtmlEventHandler MouseMove; /// /// Fires when the user moves the mouse pointer outside the boundaries of the object. /// event HtmlEventHandler MouseOut; /// /// Fires when the user moves the mouse pointer into the object. /// event HtmlEventHandler MouseOver; /// /// Fires when the user releases a mouse button while the mouse is over the object. /// event HtmlEventHandler MouseUp; #endregion /// /// Fires when the user clicks the right mouse button in the client area, opening the context menu. /// event HtmlEventHandler ContextMenu; #region Drag'n'Drop Events Family /// /// Fires on the source object continuously during a drag operation. /// /// This event fires on the source object after the event. The event fires throughout the drag operation, whether the selection being dragged is over the drag source, a valid target, or an invalid target. event HtmlEventHandler Drag; /// /// Fires on the target object when the mouse button is released during a drag-and-drop operation. /// /// /// The event fires before the and events. Use the property to disable the default action. /// You must cancel the default action for and in order for to fire. /// event HtmlEventHandler Drop; /// /// Fires on the target element when the user drags the object to a valid drop target. /// /// /// You can handle the event on the source or on the target object. Of the target events, it is the first to fire during a drag operation. Target events use the getData method to stipulate which data and data formats to retrieve. The list of drag-and-drop target events includes: /// /// /// /// /// /// /// /// /// When scripting custom functionality, use the property to disable the default action. /// event HtmlEventHandler DragEnter; /// /// Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation. /// /// The event does not support the object's and properties. event HtmlEventHandler DragLeave; /// /// Fires on the target element continuously while the user drags the object over a valid drop target. /// /// /// The event fires on the target object after the event has fired. /// When scripting custom functionality, use the property to disable the default action. /// event HtmlEventHandler DragOver; /// /// Fires on the source object when the user starts to drag a text selection or selected object. /// /// /// The event is the first to fire when the user starts to drag the mouse. It is essential to every drag operation, yet is just one of several source events in the data transfer object model. Source events use the setData method of the dataTransfer object to provide information about data being transferred. Source events include , , and . /// When dragging anything other than an img object, some text to be dragged must be selected. /// event HtmlEventHandler DragStart; /// /// Fires on the source object when the user releases the mouse at the close of a drag operation. /// /// The event is the final drag event to fire, following the event, which fires on the target object. event HtmlEventHandler DragEnd; #endregion #region CopyPaste Events Family /// /// Fires on the target object when the user pastes data, transferring the data from the system clipboard to the document. /// event HtmlEventHandler Paste; /// /// Fires on the target object before the selection is pasted from the system clipboard to the document. /// event HtmlEventHandler BeforePaste; /// /// Fires on the source object before the selection is copied to the system clipboard. /// event HtmlEventHandler BeforeCopy; /// /// Fires on the source element when the user copies the object or selection, adding it to the system clipboard. /// event HtmlEventHandler Copy; /// /// Fires on the source object before the selection is deleted from the document. /// event HtmlEventHandler BeforeCut; /// /// Fires on the source element when the object or selection is removed from the document and added to the system clipboard. /// event HtmlEventHandler Cut; #endregion /// /// Fires when a property changes on the object. /// event HtmlEventHandler PropertyChange; /// /// Fires when the size of the object is about to change. /// event HtmlEventHandler Resize; #endregion } #region HtmlDom Events Supplimentary Data Types /// /// Handler for the HTML events. /// /// 2.0 public delegate void HtmlEventHandler( object sender, HtmlEventArgs args ); /// /// The event arguments object for the HTML events. /// /// 2.0 public abstract class HtmlEventArgs : HtmlDomObject { /// /// Initializes the instance by passing in the native event args object. /// /// public HtmlEventArgs( object eventArgsObject ) : base( eventArgsObject ) { } /// Retrieves a value that indicates the state of the ALT key. public bool AltKey { get { return (bool) GetProperty( "altKey" ); } } /// Retrieves the mouse button pressed by the user. /// This property is used with the onmousedown, onmouseup, and onmousemove events. For other events, it defaults to 0 regardless of the state of the mouse buttons. public MouseButtons Button { get { MouseButtons ret = 0; int nButtons = (int) GetProperty( "button" ); if( (nButtons & 1) != 0 ) ret |= MouseButtons.Left; if( (nButtons & 2) != 0 ) ret |= MouseButtons.Right; if( (nButtons & 4) != 0 ) ret |= MouseButtons.Middle; return ret; } } /// Sets or retrieves whether the current event should bubble up the hierarchy of event handlers. /// Using this property to cancel bubbling for an event does not affect subsequent events. public bool CancelBubble { get { return (bool) GetProperty( "cancelBubble" ); } set { SetProperty( "cancelBubble", value ); } } /// Retrieves the x-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars. /// Within a viewlink, the client area begins at the edge of the master element. public int ClientX { get { return (int) GetProperty( "clientX" ); } } /// Retrieves the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars. /// Within a viewlink, the client area begins at the edge of the master element. public int ClientY { get { return (int) GetProperty( "clientY" ); } } /// Retrieves the state of the CTRL key. public bool CtrlKey { get { return (bool) GetProperty( "ctrlKey" ); } } /// Retrieves the object from which activation or the mouse pointer is exiting during the event. public abstract IHtmlDomElement FromElement { get; } /// Sets or retrieves the Unicode key code associated with the key that caused the event. /// The property is used with the onkeydown, onkeyup, and onkeypress events. The property's value is 0 if no key caused the event. public char KeyCode { get { return (char) (int) GetProperty( "keyCode" ); } set { SetProperty( "keyCode", value ); } } /// Retrieves the x-coordinate of the mouse pointer's position relative to the object firing the event. /// The coordinates match the and properties of the object. Use to find the container object that defines this coordinate system. public int OffsetX { get { return (int) GetProperty( "offsetX" ); } } /// Retrieves the y-coordinate of the mouse pointer's position relative to the object firing the event. /// The coordinates match the and properties of the object. Use to find the container object that defines this coordinate system. public int OffsetY { get { return (int) GetProperty( "offsetY" ); } } /// Retrieves the name of the data member provided by a data source object. public string Qualifier { get { return (string) GetProperty( "qualifier" ); } } /// Retrieves the result of the data transfer for a data source object. public DataTransferReason Reason { get { return (DataTransferReason) GetProperty( "reason" ); } } /// Sets or retrieves the return value from the event. /// /// True is the default. Value from the event is returned. /// False. Default action of the event on the source object is canceled. /// public bool ReturnValue { get { return (bool) GetProperty( "returnValue" ); } set { SetProperty( "returnValue", value ); } } /// Retrieves the x-coordinate of the mouse pointer's position relative to the user's screen. public int ScreenX { get { return (int) GetProperty( "screenX" ); } } /// Retrieves the y-coordinate of the mouse pointer's position relative to the user's screen. public int ScreenY { get { return (int) GetProperty( "screenY" ); } } /// Retrieves the state of the SHIFT key. public bool ShiftKey { get { return (bool) GetProperty( "shiftKey" ); } } /// Retrieves the object that fired the event. public abstract IHtmlDomElement SrcElement { get; } /// Retrieves the filter object that caused the onfilterchange event to fire. public IHtmlDomObject SrcFilter { get { object o = GetProperty( "srcFilter" ); return o != null ? new HtmlDomObject( o ) : null; } } /// Retrieves a reference to the object toward which the user is moving the mouse pointer. public abstract IHtmlDomElement ToElement { get; } /// Sets or retrieves the event name from the event object. /// Events are returned without the "on" prefix. For example, the onclick event is returned as "click". public string Type { get { return (string) GetProperty( "type" ); } set { SetProperty( "type", value ); } } /// Retrieves the x-coordinate, in pixels, of the mouse pointer's position relative to a relatively positioned parent element. public int X { get { return (int) GetProperty( "x" ); } } /// Retrieves the y-coordinate, in pixels, of the mouse pointer's position relative to a relatively positioned parent element. public int Y { get { return (int) GetProperty( "y" ); } } /// /// Sets or retrieves the name of the property that changes on the object. /// public string PropertyName { get { return (string) GetProperty( "propertyName" ); } } } #endregion /// /// A default implementation for the HTML DOM object. /// /// 2.0 public class HtmlDomObject : IHtmlDomObject { private object _instanceBase; public HtmlDomObject( object instance ) { _instanceBase = instance; } /// /// Wraps the given value into a new instance of . /// Returns a pure Null if the is Null, /// instead of a non-null instance wrapping a new value. /// /// Value to be wrapped. /// The wrapped value, or Null. public static HtmlDomObject AttachBase(object value) { return value != null ? new HtmlDomObject(value) : null; } #region IHtmlDomObject Members public object Instance { get { return _instanceBase; } } public object InvokeMethod( string name, params object[] args ) { if( _instanceBase == null ) throw new NullReferenceException(); return _instanceBase.GetType().InvokeMember( name, BindingFlags.InvokeMethod, null, _instanceBase, args ); } public object GetProperty( string name ) { if( _instanceBase == null ) throw new NullReferenceException(); return _instanceBase.GetType().InvokeMember( name, BindingFlags.GetProperty, null, _instanceBase, new object[] {} ); } public void SetProperty( string name, object value ) { if( _instanceBase == null ) throw new NullReferenceException(); _instanceBase.GetType().InvokeMember( name, BindingFlags.SetProperty, null, _instanceBase, new object[] {value} ); } #endregion } #endregion #region HtmlDom and WebBrowser Constants & Enumerations /// /// Lists possible values for the property, which represents the result of the data transfer for a data source object. /// /// 2.0 public enum DataTransferReason { /// /// Data transmitted successfully. /// Success, /// /// Data transfer aborted. /// Aborted, /// /// Data transferred in error. /// Error } /// /// Specifies how the HTML object scrolls. /// /// 2.0 public enum ScrollAction { /// /// Scrolls the object in the specified direction. /// Left, /// /// Scrolls the object in the specified direction. /// Up, /// /// Scrolls the object in the specified direction. /// Right, /// /// Scrolls the object in the specified direction. /// Down, /// /// Scrolls the object in the specified direction. /// PageLeft, /// /// Scrolls the object in the specified direction. /// PageUp, /// /// Scrolls the object in the specified direction. /// PageRight, /// /// Scrolls the object in the specified direction. /// PageDown } /// /// Available types of the content menu targets in the Web browser. /// Note that some of them are for internal use only. /// /// /// Numeric values of the basic constants correspond to the MSHTML's context menu constants and thus must be immutable. /// Origin: mshtmhst.h /// /// 2.0 public enum ContextMenuTargetType : int { Default = 0, Image = 1, Control = 2, Table = 3, TextSelect = 4, Anchor = 5, Unknown = 6, Imgdynsrc = 7, Imgart = 8, Debug = 9, Vscroll = 10, Hscroll = 11 } /// /// Flags for the method. /// /// 2.0 [Flags] public enum GetAttributeFlags { /// /// No flags. /// None = 0, /// /// Performs a case-sensitive search for the attribute by its name. /// CaseSensitive = 1, /// /// Returns the attribute value exactly as it was set. /// ExactValue = 2 } /// /// Represents the ready state of the browser that tells whether the browser is currently loading the page, parsing its content, or finished and ready for work. /// /// Particular Web browsers may implement only a subset of these states. However, the state must be supported by any browser and it must be achieved only after the page is completely loaded and ready for full-scale DOM interaction. /// 2.0 public enum BrowserReadyState { ///Default initialization state. Uninitialized = 0, ///Object is currently loading its properties. Loading = 1, ///Object has been initialized. Loaded = 2, ///Object is interactive, but not all of its data is available. Interactive = 3, ///Object has received all of its data. Complete = 4 } /// /// Reveals the cause due to which the Web browser performed a navigation. /// /// 2.0 public enum BrowserNavigationCause { /// /// The HTML content was directly uploaded into the Web browser by Omea. /// This means that the function was called, /// or property was set. /// ShowHtml, /// /// The browser is performing a navigation initiated by Omea. /// This means that the or function was called. /// Navigate, /// /// Navigation was initiated by user or a script within the page, however, was not explicitly caused by Omea. /// FollowLink, /// /// Navigation has occured because the browser is going back. /// GoBack, /// /// Navigation has occured because the browser is going forward. /// GoForward, /// /// Navigation has occured because the browser is returning to the original page displayed by the or function. /// ReturnToOriginal } #endregion }