|
From: <dos...@us...> - 2013-04-07 19:47:32
|
Revision: 4559
http://sourceforge.net/p/mp-plugins/code/4559
Author: doskabouter
Date: 2013-04-07 19:47:28 +0000 (Sun, 07 Apr 2013)
Log Message:
-----------
- version increased to 1.1
- Major rework of DOM-interaction. Increases the number of items to click on, better handling of textboxes (value prefilled on clicking)
- Explicit loading of preferences
Modified Paths:
--------------
trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/BrowseTheWeb.csproj
trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/GUIPlugin.cs
trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/Properties/AssemblyInfo.cs
Added Paths:
-----------
trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/DomHelper.cs
Removed Paths:
-------------
trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/HtmlInputType.cs
trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/HtmlLinkNumber.cs
Modified: trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/BrowseTheWeb.csproj
===================================================================
--- trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/BrowseTheWeb.csproj 2013-04-06 19:42:56 UTC (rev 4558)
+++ trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/BrowseTheWeb.csproj 2013-04-07 19:47:28 UTC (rev 4559)
@@ -83,6 +83,7 @@
<Compile Include="Bookmark.cs" />
<Compile Include="BookmarkElement.cs" />
<Compile Include="BookmarkXml.cs" />
+ <Compile Include="DomHelper.cs" />
<Compile Include="GetFolder.cs">
<SubType>Form</SubType>
</Compile>
@@ -103,8 +104,6 @@
</Compile>
<Compile Include="GUIBookmark.cs" />
<Compile Include="GUIPlugin.cs" />
- <Compile Include="HtmlInputType.cs" />
- <Compile Include="HtmlLinkNumber.cs" />
<Compile Include="ImportIE.cs">
<SubType>Form</SubType>
</Compile>
Added: trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/DomHelper.cs
===================================================================
--- trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/DomHelper.cs (rev 0)
+++ trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/DomHelper.cs 2013-04-07 19:47:28 UTC (rev 4559)
@@ -0,0 +1,285 @@
+using System;
+using System.Drawing;
+using System.Linq;
+using Gecko;
+using Gecko.DOM;
+
+namespace BrowseTheWeb
+{
+ public class DomHelper
+ {
+ private const string _spanstyle = "font-family: arial,sans-serif; font-size: 12px ! important; line-height: 130% ! important; border-width: 1px ! important; border-style: solid ! important; -moz-border-radius: 2px 2px 2px 2px ! important; padding: 0px 2px ! important; margin-right: 2px; max-width: 20px; max-height: 10px ! important; overflow: visible ! important; float: none ! important; display: inline;";
+ private const string btwebId = "btweb_id";
+
+ public static void AddLinksToPage(GeckoDocument document)
+ {
+ int maxId = GetMaxId(document);
+ AddLinksToPage(document, maxId + 1);
+ }
+
+ public static GeckoHtmlElement GetElement(string linkId, GeckoDocument document)
+ {
+ GeckoHtmlElement ge = document.GetElements(String.Format("//*[@{0}='{1}']", btwebId, linkId)).FirstOrDefault();
+ if (ge != null)
+ return ge;
+
+ GeckoElementCollection iframes = document.GetElementsByTagName("iframe");
+ foreach (GeckoIFrameElement element in iframes)
+ {
+ ge = GetElement(linkId, element.ContentDocument);
+ if (ge != null)
+ return ge;
+ }
+ return null;
+ }
+
+ public static Point GetCenterCoordinate(GeckoDocument root, GeckoHtmlElement element)
+ {
+ Point documentOffset = DocumentOffset(root, element.OwnerDocument);
+ RectangleF rect = element.BoundingClientRect;
+ Point p = new Point(Convert.ToInt32(rect.Left + rect.Width / 2), Convert.ToInt32(rect.Top + rect.Height / 2));
+ p.X += documentOffset.X;
+ p.Y += documentOffset.Y;
+ return p;
+ }
+
+ public static int NrOfChildElementsDone(GeckoHtmlElement element)
+ {
+ return element.GetElements(".//*[@" + btwebId + "]").Count();
+ }
+
+ private static Point DocumentOffset(GeckoDocument root, GeckoDocument current)
+ {
+ Point result = new Point(0, 0);
+ if (root.Equals(current))
+ return result;
+
+ GeckoElementCollection iframes = root.GetElementsByTagName("iframe");
+ foreach (GeckoIFrameElement element in iframes)
+ {
+ if (element.ContentDocument.Equals(current))
+ {
+ Point tmp = DocumentOffset(root, element.OwnerDocument);
+ result.X += element.BoundingClientRect.Left + tmp.X;
+ result.Y += element.BoundingClientRect.Top + tmp.Y;
+ return result;
+ }
+ }
+ return new Point(0, 0);
+ }
+
+ private static void AddLinksToPage(GeckoDocument document, int id)
+ {
+ GeckoElementCollection links = document.Links;
+ MyLog.debug("page links cnt : " + links.Count);
+ foreach (GeckoHtmlElement element in links) // no casting to GeckoAnchorElement, because document.links also returns GeckoAreaElemenets
+ if (!element.GetAttribute("href").StartsWith("javascript:"))
+ {
+ GeckoHtmlElement lastSpan = element;
+ bool ready = false;
+ while (!ready)
+ {
+ GeckoHtmlElement ls = lastSpan.LastChild as GeckoHtmlElement;
+ if (ls == null || ls.TagName != "SPAN")
+ ready = true;
+ else
+ lastSpan = ls;
+ };
+ if (!elementDone(element))
+ {
+ GeckoElement ls = element;
+ while (ls.LastChild != null && ls.LastChild is GeckoElement && !String.IsNullOrEmpty(ls.LastChild.TextContent))
+ ls = (GeckoElement)ls.LastChild;
+ insertSpanAfter(id, lastSpan.ClassName, ls);
+ SetLinkAttributes(element, id);
+ id++;
+ }
+ }
+
+ foreach (GeckoHtmlElement element in links) // no casting to GeckoAnchorElement, because document.links also returns GeckoAreaElemenets
+ if (!element.GetAttribute("href").StartsWith("javascript:") && element.ClientRects.Length == 0)
+ //invisible, so find visible previousSibling/parent and put a number on that
+ {
+ GeckoNode el = element;
+ while (el != null && !ElementVisible(el))
+ {
+ GeckoNode ps = el.PreviousSibling;
+ if (ps != null)
+ el = ps;
+ else
+ el = el.ParentNode;
+ }
+
+ if (el != null)// -> ElementVisible(el)=true, and thus el is a GeckoHtmlElement
+ {
+ GeckoHtmlElement geckoEl = (GeckoHtmlElement)el;
+
+ GeckoHtmlElement lastSpan = geckoEl;
+ bool ready = false;
+ while (!ready)
+ {
+ GeckoHtmlElement ls = lastSpan.LastChild as GeckoHtmlElement;
+ if (ls == null || ls.TagName != "SPAN")
+ ready = true;
+ else
+ lastSpan = ls;
+ };
+
+ if (!elementDone(geckoEl))
+ {
+
+ GeckoElement ls = geckoEl;
+ while (ls.LastChild != null && ls.LastChild is GeckoElement && !String.IsNullOrEmpty(ls.LastChild.TextContent))
+ ls = (GeckoElement)ls.LastChild;
+ insertSpanAfter(id, lastSpan.ClassName, ls);
+ SetLinkAttributes(geckoEl, id);
+ id++;
+ }
+ }
+ }
+
+ GeckoElementCollection objects = document.GetElementsByTagName("object");
+ MyLog.debug("page objects cnt : " + objects.Count);
+ foreach (GeckoObjectElement element in objects)
+ if (element.Type == "application/x-shockwave-flash")
+ {
+ if (!elementDone(element))
+ {
+ insertSpanAfter(id, null, element.Parent, "color:black;background-color:white");
+ SetLinkAttributes(element, id);
+ id++;
+ }
+ }
+
+ GeckoElementCollection forms = document.GetElementsByTagName("form");
+ MyLog.debug("page forms cnt : " + forms.Count);
+ foreach (GeckoHtmlElement element in forms)
+ {
+ GeckoElementCollection inps = element.GetElementsByTagName("input");
+ foreach (GeckoInputElement inp in inps)
+ if (!elementDone(inp))
+ {
+ string linkType = inp.Type;
+ if (!String.IsNullOrEmpty(linkType))
+ {
+ if (linkType != "hidden")
+ {
+ SetLinkAttributes(inp, id);
+
+ GeckoNode ps = inp.PreviousSibling;
+ while (ps != null && !(ps is GeckoHtmlElement))
+ ps = ps.PreviousSibling;
+
+ if (inp.PreviousSibling != null)
+ insertSpanBefore(id, null, inp);
+ else
+ insertSpanAfter(id, null, inp.Parent);
+ id++;
+ }
+ }
+ else
+ {
+ SetLinkAttributes(inp, id);
+ insertSpanAfter(id, null, inp.Parent);
+ id++;
+ }
+ }
+
+ GeckoElementCollection buttons = element.GetElementsByTagName("button");
+ foreach (GeckoHtmlElement button in buttons)
+ if (!elementDone(button) && button.ClientRects.Length != 0)
+ {
+ SetLinkAttributes(button, id);
+ insertSpanBefore(id, null, button);
+ id++;
+ }
+
+ GeckoElementCollection selects = element.GetElementsByTagName("select");
+ foreach (GeckoHtmlElement select in selects)
+ if (!elementDone(select) && select.ClientRects.Length != 0)
+ {
+ SetLinkAttributes(select, id);
+ insertSpanBefore(id, null, select);
+ id++;
+ }
+ }
+
+ GeckoElementCollection iframes = document.GetElementsByTagName("iframe");
+ MyLog.debug("page iframes cnt : " + iframes.Count);
+ foreach (GeckoIFrameElement element in iframes)
+ AddLinksToPage(element.ContentDocument, id);
+ }
+
+ private static int GetMaxId(GeckoDocument document)
+ {
+ int maxId = 0;
+ try
+ {
+ foreach (GeckoHtmlElement ge in document.GetElements("//*[@" + btwebId + "]"))
+ {
+ int j;
+ if (Int32.TryParse(ge.Attributes[btwebId].NodeValue, out j))
+ maxId = Math.Max(maxId, j);
+ }
+ }
+ catch
+ {
+ // sometimes this causes an exception...
+ };
+
+ GeckoElementCollection iframes = document.GetElementsByTagName("iframe");
+ foreach (GeckoIFrameElement element in iframes)
+ maxId = Math.Max(maxId, GetMaxId(element.ContentDocument));
+ return maxId;
+ }
+
+ private static GeckoHtmlElement CreateSpan(GeckoDocument owner, int geckoId, string className, string extra)
+ {
+ GeckoHtmlElement result = owner.CreateHtmlElement("span");
+ result.SetAttribute("style", _spanstyle + extra);
+ result.InnerHtml = geckoId.ToString();
+ if (!String.IsNullOrEmpty(className))
+ result.SetAttribute("class", className);
+ return result;
+ }
+
+ private static GeckoElement insertSpanAfter(int geckoId, string className, GeckoNode after, string extra = "")
+ {
+ if (after == null)
+ throw new ArgumentNullException("after");
+ GeckoHtmlElement newChild = CreateSpan(after.OwnerDocument, geckoId, className, extra);
+ if (after.FirstChild == null)
+ after.AppendChild(newChild);
+ else
+ after.InsertBefore(newChild, after.FirstChild);
+ return newChild;
+ }
+
+ private static GeckoElement insertSpanBefore(int geckoId, string className, GeckoNode before, string extra = "")
+ {
+ if (before == null)
+ throw new ArgumentNullException("after");
+ GeckoHtmlElement newElement = CreateSpan(before.OwnerDocument, geckoId, className, extra);
+ before.ParentNode.InsertBefore(newElement, before);
+ return newElement;
+ }
+
+ private static void SetLinkAttributes(GeckoElement link, int linkNumber)
+ {
+ link.SetAttribute(btwebId, linkNumber.ToString());
+ }
+
+ private static bool elementDone(GeckoElement element)
+ {
+ return !String.IsNullOrEmpty(element.GetAttribute(btwebId));
+ }
+
+ private static bool ElementVisible(GeckoNode el)
+ {
+ GeckoHtmlElement ge = el as GeckoHtmlElement;
+ return ge != null && ge.OffsetHeight > 0;
+ }
+
+
+ }
+}
Modified: trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/GUIPlugin.cs
===================================================================
--- trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/GUIPlugin.cs 2013-04-06 19:42:56 UTC (rev 4558)
+++ trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/GUIPlugin.cs 2013-04-07 19:47:28 UTC (rev 4559)
@@ -23,9 +23,9 @@
#endregion
using System;
-using System.Collections.Generic;
using System.Drawing;
using System.IO;
+using System.Text;
using MediaPortal.GUI.Library;
using MediaPortal.Dialogs;
@@ -35,6 +35,7 @@
using System.Runtime.InteropServices;
using Gecko;
+using Gecko.DOM;
namespace BrowseTheWeb
{
@@ -57,12 +58,8 @@
private bool mouseVisible = false;
private bool clickFromPlugin = false;
private bool aeroDisabled = false;
- #region Links
- private Dictionary<int, HtmlLinkNumber> _htmlLinkNumbers = new Dictionary<int, HtmlLinkNumber>();
- #endregion
#region Constants
- private const string _spanstyle = "font-family: arial,sans-serif; font-size: 12px ! important; line-height: 130% ! important; border-width: 1px ! important; border-style: solid ! important; -moz-border-radius: 2px 2px 2px 2px ! important; padding: 0px 2px ! important; margin-right: 2px; max-width: 20px; max-height: 10px ! important; overflow: visible ! important; float: none ! important; display: inline;";
public const int PluginWindowId = 54537689;
#endregion
@@ -217,6 +214,9 @@
osd_linkID = new OSD_LinkId();
GUIGraphicsContext.form.Controls.Add(osd_linkID);
osd_linkID.Visible = false;
+ string preferenceFile = Path.Combine(Config.GetFolder(Config.Dir.Config), "btwebprefs.js");
+ if (File.Exists(preferenceFile))
+ GeckoPreferences.Load(preferenceFile);
#endregion
}
@@ -291,7 +291,7 @@
webBrowser.Visible = true;
webBrowser.Enabled = settings.UseMouse;
- //webBrowser.ClearCachedCOMPtrs();possibly not needed anymore
+ webBrowser.ClearCachedCOMPtrs();
webBrowser.Dock = DockStyle.None;
SetBrowserWindow();
@@ -410,8 +410,7 @@
// http://geckofx.org/viewtopic.php?id=832
GeckoPreferences.User["network.proxy.http"] = Server;
GeckoPreferences.User["network.proxy.http_port"] = Port;
- int ena = 0; if (useProxy) ena = 1;
- GeckoPreferences.User["network.proxy.type"] = ena;
+ GeckoPreferences.User["network.proxy.type"] = useProxy ? 1 : 0;
// maybe possible... not sure...
// network.proxy.login
@@ -903,56 +902,6 @@
}
}
- private void AddElements(List<GeckoHtmlElement> list, GeckoNode parent, string elName)
- {
- if (parent is GeckoHtmlElement && ((GeckoHtmlElement)parent).TagName.ToLowerInvariant() == elName)
- list.Add((GeckoHtmlElement)parent);
- foreach (GeckoNode child in parent.ChildNodes)
- AddElements(list, child, elName);
- }
-
- private List<GeckoHtmlElement> getElements(GeckoNode parent, string elName)
- {
- List<GeckoHtmlElement> res = new List<GeckoHtmlElement>();
- AddElements(res, parent, elName);
- return res;
- }
-
- private GeckoElement insertSpan(int geckoId, string geckoAction, string geckoType, string className, GeckoNode after)
- {
- if (after == null)
- throw new ArgumentNullException("after");
- GeckoHtmlElement newChild = after.OwnerDocument.CreateHtmlElement("span");
- newChild.SetAttribute("style", _spanstyle);
- newChild.SetAttribute("gecko_id", geckoId.ToString());
- newChild.SetAttribute("gecko_action", geckoAction);
- newChild.SetAttribute("gecko_type", geckoType);
- newChild.InnerHtml = geckoId.ToString();
- if (!String.IsNullOrEmpty(className))
- newChild.SetAttribute("class", className);
- if (after.FirstChild == null)
- after.AppendChild(newChild);
- else
- after.InsertBefore(newChild, after.FirstChild);
- return newChild;
- }
-
- private void SetLinkAttributes(GeckoElement link, int linkNumber, out string id, out string name)
- {
- string gb = link.GetAttribute("gb");
- id = link.GetAttribute("id");
- name = link.GetAttribute("name");
- if (string.IsNullOrEmpty(gb))
- {
- link.SetAttribute("gb", "gecko_link" + linkNumber);
- }
- if (string.IsNullOrEmpty(id))
- {
- link.SetAttribute("id", "gb" + linkNumber);
- id = "gb" + linkNumber;
- }
- }
-
private void webBrowser_DocumentCompleted(object sender, EventArgs e)
{
MyLog.debug("page completed : " + webBrowser.Url.ToString());
@@ -968,123 +917,8 @@
#endregion
if (!settings.UseMouse)
- {
- #region add links to page
- _htmlLinkNumbers.Clear();
+ DomHelper.AddLinksToPage(webBrowser.Document);
- GeckoElementCollection links = webBrowser.Document.Links;
- int i = 1;
-
- MyLog.debug("page links cnt : " + links.Count);
-
- foreach (GeckoHtmlElement element in links)
- {
- string link = element.GetAttribute("href");
-
- if (!link.StartsWith("javascript:"))
- {
- GeckoHtmlElement lastSpan = element;
- bool ready = false;
- while (!ready)
- {
- GeckoHtmlElement ls = lastSpan.LastChild as GeckoHtmlElement;
- if (ls == null || ls.TagName != "SPAN")
- ready = true;
- else
- lastSpan = ls;
- };
- if (!element.InnerHtml.Contains("gecko_id"))
- {
- GeckoElement ls = element;
- while (ls.LastChild != null && ls.LastChild is GeckoElement && !String.IsNullOrEmpty(ls.LastChild.TextContent))
- ls = (GeckoElement)ls.LastChild;
- insertSpan(i, String.Empty, "LINK", lastSpan.ClassName, ls);
- }
-
- string id, name;
- SetLinkAttributes(element, i, out id, out name);
- _htmlLinkNumbers.Add(i, new HtmlLinkNumber(i, id, name, link, HtmlInputType.Link));
- i++;
- }
- }
-
- GeckoElementCollection objects = webBrowser.Document.GetElementsByTagName("object");
- MyLog.debug("page objects cnt : " + objects.Count);
- foreach (GeckoHtmlElement element in objects)
- if (element.GetAttribute("type") == "application/x-shockwave-flash")
- {
- string id, name;
- GeckoHtmlElement element2 = element.Parent;
- SetLinkAttributes(element2, i, out id, out name);
-
- if (!element2.InnerHtml.Contains("gecko_id=\"" + i + "\""))
- {
- insertSpan(i, String.Empty, "LINK", null, element2);
- }
- RectangleF rect = element2.BoundingClientRect;
- Point p = new Point(Convert.ToInt32(rect.Left + rect.Width / 2), Convert.ToInt32(rect.Top + rect.Height / 2));
- _htmlLinkNumbers.Add(i, new HtmlLinkNumber(i, id, name, p, HtmlInputType.FlashObject));
- i++;
- }
-
- GeckoElementCollection forms = webBrowser.Document.GetElementsByTagName("form");
-
- MyLog.debug("page forms cnt : " + forms.Count);
-
- foreach (GeckoHtmlElement element in forms)
- {
- List<GeckoHtmlElement> inps = getElements(element, "input");
- string action = element.GetAttribute("action");
- foreach (GeckoHtmlElement link in inps)
- {
- string linkType = link.GetAttribute("type");
- if (!String.IsNullOrEmpty(linkType))
- {
- if (linkType != "hidden")
- {
- string id, name;
- SetLinkAttributes(link, i, out id, out name);
-
- if (!element.InnerHtml.Contains("gecko_id=\"" + i + "\""))
- {
- insertSpan(i, action, "INPUT", null, link.Parent);
- }
- if (linkType == "submit" ||
- linkType == "reset" ||
- linkType == "radio" ||
- linkType == "image" ||
- linkType == "checkbox")
- {
- _htmlLinkNumbers.Add(i, new HtmlLinkNumber(i, id, name, action, HtmlInputType.Action));
- }
- else
- {
- if (linkType == "password")
- _htmlLinkNumbers.Add(i, new HtmlLinkNumber(i, id, name, action, HtmlInputType.InputPassword));
- else
- _htmlLinkNumbers.Add(i, new HtmlLinkNumber(i, id, name, action, HtmlInputType.Input));
- }
- i++;
- }
- }
- else
- {
- string id, name;
- SetLinkAttributes(link, i, out id, out name);
-
- if (!element.InnerHtml.Contains("gecko_id=\"" + i + "\""))
- {
- insertSpan(i, action, "INPUT", null, link.Parent);
- }
-
- _htmlLinkNumbers.Add(i, new HtmlLinkNumber(i, id, name, action, HtmlInputType.Input));
- i++;
- }
- }
- }
- #endregion
- }
-
#region reset zoom
if (settings.ZoomPage)
{
@@ -1125,118 +959,120 @@
osd_linkID.Visible = false;
Application.DoEvents();
- HtmlLinkNumber hln = null;
- if (GetLinkById(Convert.ToInt32(LinkId), out hln))
+ GeckoHtmlElement ge = DomHelper.GetElement(LinkId, webBrowser.Document);
+
+ if (ge == null)
{
- switch (hln.Type)
- {
- case HtmlInputType.Link:
- string link = (string)hln.Obj;
- webBrowser.Navigate(link);
- MyLog.debug("navigate to linkid=" + LinkId + " URL=" + link);
- break;
- case HtmlInputType.Input:
- case HtmlInputType.InputPassword:
- ShowInputDialog(hln);
- break;
- case HtmlInputType.Action:
- webBrowser.Navigate("javascript:document.getElementById(\"" + hln.Id + "\").click()");
- MyLog.debug("action linkid=" + LinkId);
- break;
- case HtmlInputType.FlashObject:
- MyLog.debug("flash click on " + Cursor.Position.ToString());
- Point p = (Point)hln.Obj;
- webBrowser.Enabled = true;
+ MyLog.debug(String.Format("LinkId {0} not found in _htmlLinkNumbers", LinkId));
+ return;
+ }
- System.Threading.Thread.Sleep(200);
- Cursor.Position = webBrowser.PointToScreen(p);
- int X = Cursor.Position.X;
- int Y = Cursor.Position.Y;
- clickFromPlugin = true;
- mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
- break;
- }
+ if (ge is GeckoAnchorElement)
+ {
+ string link = ((GeckoAnchorElement)ge).Href;
+ webBrowser.Navigate(link);
+ MyLog.debug("navigate to linkid=" + LinkId + " URL=" + link);
}
- }
- private bool GetLinkById(int value, out HtmlLinkNumber hln)
- {
- if (_htmlLinkNumbers.ContainsKey(value))
- {
- HtmlLinkNumber id = _htmlLinkNumbers[value];
- switch (id.Type)
+ else
+ if (ge is GeckoButtonElement)
{
- case HtmlInputType.Link:
+ ge.Click();
+ }
+ else
+ if (ge is GeckoSelectElement)
+ {
+ ShowSelect(ge as GeckoSelectElement);
+ }
+ else
+ if (ge is GeckoInputElement)
{
- string link = (string)id.Obj;
- if (!Uri.IsWellFormedUriString(link, UriKind.Absolute))
+ string linkType = ((GeckoInputElement)ge).Type;
+ if (!String.IsNullOrEmpty(linkType))
{
- Uri baseUri = webBrowser.Url;
-
- GeckoElementCollection baseElements = webBrowser.Document.GetElementsByTagName("base");
- if (baseElements != null && baseElements.Count > 0)
+ switch (linkType)
{
- GeckoNode gn = baseElements[0].Attributes["href"];
- if (gn != null && !String.IsNullOrEmpty(gn.NodeValue))
- baseUri = new Uri(gn.NodeValue);
+ case "password": ShowInputDialog(true, ge as GeckoInputElement); break;
+ case "submit":
+ case "reset":
+ case "radio":
+ case "image":
+ case "checkbox":
+ ge.Click();
+ MyLog.debug("action linkid=" + LinkId);
+ break;
+ case "hidden": break;
+ default: ShowInputDialog(false, ge as GeckoInputElement); break;
}
- id.Obj = new Uri(baseUri, link).AbsoluteUri;
}
- hln = id;
- return true;
}
- case HtmlInputType.FlashObject:
- case HtmlInputType.Input:
- case HtmlInputType.InputPassword:
- case HtmlInputType.Action:
- hln = id;
- return true;
- //return "javascript:document.getElementById(\"" + id.Name + "\").click()";
- }
- }
- else
- MyLog.debug(String.Format("LinkId {0} not found in _htmlLinkNumbers", value));
- hln = null;
- return false;
+ else
+ //if (ge is GeckoObjectElement)
+ // some items just need a mousehover, and a ge.Click won't do that
+ {
+ Point p = DomHelper.GetCenterCoordinate(webBrowser.Document, ge);
+ MyLog.debug("perform click on " + p.ToString());
+
+ webBrowser.Enabled = true;
+ System.Threading.Thread.Sleep(200);
+ Cursor.Position = webBrowser.PointToScreen(p);
+ clickFromPlugin = true;
+ mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
+ }
+ //else
+ // ge.Click();
}
- public void ShowInputDialog(HtmlLinkNumber id)
+ public void ShowInputDialog(bool isPassword, GeckoInputElement element)
{
webBrowser.Visible = false;
- string result = string.Empty;
- if (ShowKeyboard(ref result, id.Type == HtmlInputType.InputPassword) == DialogResult.OK)
+ string result = element.Value;
+ if (ShowKeyboard(ref result, isPassword) == DialogResult.OK)
{
- SetInputElementValue(webBrowser.Document, id.Number, result);
- }
- webBrowser.Visible = true;
- }
+ if (element != null)
+ element.SetAttribute("value", result);
+ GeckoFormElement form = element.Form;
+ if (form != null)
+ {
+ //List<GeckoHtmlElement> inps = DomHelper.GetElements(form, "input");
+ GeckoElementCollection inps = form.GetElementsByTagName("input");
+ if (DomHelper.NrOfChildElementsDone(form) == 1)
+ {
+ StringBuilder sb = new StringBuilder();
+ foreach (GeckoInputElement inp in inps)
+ {
+ if (sb.Length != 0)
+ sb.Append('&');
+ sb.Append(inp.Name);
+ sb.Append('=');
+ sb.Append(inp.Value);
+ }
- private bool SetInputElementValue(GeckoNode parent, int geckoId, string text)
- {
- GeckoElement el = parent as GeckoElement;
- if (el != null && el.TagName.ToLowerInvariant() == "input" && el.GetAttribute("gb") == "gecko_link" + geckoId)
- {
- el.SetAttribute("value", text);
- return true;
- }
- else
- {
- foreach (GeckoNode child in parent.ChildNodes)
- {
- if (SetInputElementValue(child, geckoId, text))
- return true;
+ if (form.Method == "get")
+ webBrowser.Navigate(form.Action + '?' + sb.ToString());
+ else
+ {
+ using (GeckoMIMEInputStream stream = new GeckoMIMEInputStream())
+ {
+ stream.AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ stream.AddContentLength = true;
+ stream.SetData(sb.ToString());
+ webBrowser.Navigate(form.Action, 0, null, stream);
+ }
+ }
+ }
}
- return false;
}
+ webBrowser.Visible = true;
}
public static DialogResult ShowKeyboard(ref string DefaultText, bool PasswordInput)
{
VirtualKeyboard vk = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD);
-
vk.Reset();
vk.Password = PasswordInput;
vk.Text = DefaultText;
+ vk.SetLabelAsInitialText(false); // set to false, otherwise our intial text is cleared
vk.DoModal(GUIWindowManager.ActiveWindow);
if (vk.IsConfirmed)
@@ -1256,7 +1092,30 @@
dlg.SetLine(3, line3);
dlg.DoModal(GUIWindowManager.ActiveWindow);
}
+ public void ShowSelect(GeckoSelectElement select)
+ {
+ webBrowser.Visible = false;
+ GUIDialogSelect2 dlgMenu = (GUIDialogSelect2)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_SELECT2);
+ dlgMenu.Reset();
+ dlgMenu.SetHeading(select.Name);
+ dlgMenu.SelectedLabel = select.SelectedIndex;
+ GeckoOptionsCollection options = select.Options;
+ for (uint i = 0; i < options.Length; i++)
+ {
+ GeckoOptionElement option = options.item(i);
+ dlgMenu.Add(option.Label);
+ }
+ dlgMenu.DoModal(GUIWindowManager.ActiveWindow);
+ webBrowser.Visible = true;
+
+ if (dlgMenu.SelectedLabel == -1)
+ return;
+ select.SelectedIndex = dlgMenu.SelectedLabel;
+ return;
+
+ }
+
private void OnRenderSound(string strFilePath)
{
MediaPortal.Util.Utils.PlaySound(strFilePath, false, true);
Deleted: trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/HtmlInputType.cs
===================================================================
--- trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/HtmlInputType.cs 2013-04-06 19:42:56 UTC (rev 4558)
+++ trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/HtmlInputType.cs 2013-04-07 19:47:28 UTC (rev 4559)
@@ -1,36 +0,0 @@
-#region Copyright (C) 2005-2010 Team MediaPortal
-
-/*
- * Copyright (C) 2005-2010 Team MediaPortal
- * http://www.team-mediaportal.com
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-#endregion
-
-
-namespace BrowseTheWeb
-{
- public enum HtmlInputType
- {
- Input,
- InputPassword,
- Link,
- Action,
- FlashObject
- }
-}
Deleted: trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/HtmlLinkNumber.cs
===================================================================
--- trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/HtmlLinkNumber.cs 2013-04-06 19:42:56 UTC (rev 4558)
+++ trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/HtmlLinkNumber.cs 2013-04-07 19:47:28 UTC (rev 4559)
@@ -1,46 +0,0 @@
-#region Copyright (C) 2005-2010 Team MediaPortal
-
-/*
- * Copyright (C) 2005-2010 Team MediaPortal
- * http://www.team-mediaportal.com
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-#endregion
-
-
-namespace BrowseTheWeb
-{
- public class HtmlLinkNumber
- {
- public HtmlLinkNumber(int number, string id, string name, object obj, HtmlInputType type)
- {
- Type = type;
- Number = number;
- Name = name;
- Id = id;
- Obj =obj;
-
- }
-
- public int Number { get; set; }
- public string Id { get; set; }
- public string Name { get; set; }
- public HtmlInputType Type { get; set; }
- public object Obj { get; set; }
- }
-}
Modified: trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/Properties/AssemblyInfo.cs
===================================================================
--- trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/Properties/AssemblyInfo.cs 2013-04-06 19:42:56 UTC (rev 4558)
+++ trunk/plugins/BrowseTheWeb/Source/BrowseTheWeb/Properties/AssemblyInfo.cs 2013-04-07 19:47:28 UTC (rev 4559)
@@ -16,7 +16,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MP")]
[assembly: AssemblyProduct("BrowseTheWeb")]
-[assembly: AssemblyCopyright("Copyright © 2010")]
+[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -38,5 +38,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|