Skip to content

Commit

Permalink
WebBrowser Overhaul
Browse files Browse the repository at this point in the history
Added some awesome CSS buttons. Totally worth it!
  • Loading branch information
PythEch committed May 4, 2014
1 parent dd45931 commit 83bf2b7
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 199 deletions.
5 changes: 4 additions & 1 deletion Cygnus/Cygnus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
<EmbeddedResource Include="AlertView.resx">
<DependentUpon>AlertView.cs</DependentUpon>
</EmbeddedResource>
<None Include="WebBrowserStyles.html">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down Expand Up @@ -171,4 +174,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
252 changes: 111 additions & 141 deletions Cygnus/MainForm.Designer.cs

Large diffs are not rendered by default.

91 changes: 48 additions & 43 deletions Cygnus/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ public partial class MainForm : Form
/// </summary>
private static Queue selectedQueue;

/// <summary>
/// Used to zoom once after the first website is loaded to load user preferences.
/// </summary>
private static bool zoomedBefore = false;
private static HtmlElement cssBtnDownload, cssBtnDownloadFully, cssBtnBack, cssFrameDepiction;

#endregion Fields

Expand Down Expand Up @@ -324,7 +321,27 @@ private void MainForm_Load(object sender, EventArgs e)
this.statusStrip.Items.Add(new ToolStripControlHost(this.trackBarZoom));
//Adds zoom trackbar which isn't possible to do with the Designer

this.tabMain_SelectedIndexChanged(null, null);
this.webBrowser1.Navigate("about:blank");
this.webBrowser1.Document.Write(String.Empty); // Stupid workaround, thanks: http://stackoverflow.com/a/21608474
this.webBrowser1.DocumentText = Properties.Resources.WebBrowserStyles;

while (this.webBrowser1.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();

cssBtnDownload = this.webBrowser1.Document.GetElementById("download");
cssBtnDownloadFully = this.webBrowser1.Document.GetElementById("downloadfully");
cssBtnBack = this.webBrowser1.Document.GetElementById("back");
cssFrameDepiction = this.webBrowser1.Document.GetElementById("depiction");

cssBtnDownload.Enabled = cssBtnDownloadFully.Enabled = false;

cssBtnDownload.Click += delegate { DownloadPackage(false); };
cssBtnDownloadFully.Click += delegate { DownloadPackage(true); };
cssBtnBack.Click += delegate { NavigateWebBrowser(selectedPack.Depiction); };

ZoomWebBrowser();

tabMain_SelectedIndexChanged(null, null);
}

/// <summary>
Expand Down Expand Up @@ -477,7 +494,7 @@ private void btnReload_Click(object sender, EventArgs e)
/// </summary>
private void btnSearch_Click(object sender, EventArgs e)
{
this.btnDownload.Enabled = this.btnDownloadFully.Enabled = true;
cssBtnDownload.Enabled = cssBtnDownloadFully.Enabled = true;
this.tablePackages.BeginUpdate();
this.tablePackages.ClearAllData();

Expand All @@ -487,7 +504,7 @@ private void btnSearch_Click(object sender, EventArgs e)
{
this.tablePackages.NoItemsText = "No packages found...";
this.tablePackages.EndUpdate();
this.btnDownload.Enabled = this.btnDownloadFully.Enabled = false;
cssBtnDownload.Enabled = cssBtnDownloadFully.Enabled = false;
return;
}

Expand Down Expand Up @@ -567,25 +584,9 @@ private void btnDownloadFully_Click(object sender, EventArgs e)
/// <param name="url">The URL to navigate.</param>
private void NavigateWebBrowser(string url)
{
// SUPER HACKY WORKAROUND TO SOLVE STUPID WebBrowser PROBLEM
webBrowser1.DocumentText = @"<html>
<head><meta http-equiv='X-UA-Compatible' content='IE=edge'></head>
<body>
<iframe src='" + url.toValidURL() + @"' style='border:0; position:absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%' />
</body>
</html>";
// Problem:
// ieframe.dll based WebBrowser control loads webpages using IE7 compatibility mode by default
//
// I've found this workaround by myself. This solves three problems:
// • We won't need to have Administrator privileges and do a stupid registry trick:
// http://msdn.microsoft.com/en-us/library/ie/ee330730%28v=vs.85%29.aspx
//
// • And other than that, for some reason, this WebBrowser control doesn't render
// Modmyi properly even after that trick.
//
// • And finally, we won't need to detect IE Version to set registry value correctly.
// It'll use the latest Version avaiable on the computer automatically
cssFrameDepiction.SetAttribute("src", url.toValidURL());

ShowDownloadButtons();
}

/// <summary>
Expand All @@ -594,7 +595,7 @@ private void NavigateWebBrowser(string url)
/// </para><para>
/// Basically, first this function navigates to the depiction of
/// selected package. Then it changes selectedPack variable to make
/// btnDownload can determine which package was selected.
/// cssBtnDownload can determine which package was selected.
/// </para>
/// </summary>
private void listPackages_SelectionChanged(object sender, XPTable.Events.SelectionEventArgs e)
Expand Down Expand Up @@ -648,22 +649,6 @@ private void ZoomWebBrowser()

}

/// <summary>
/// The default zoom factor is 100% hence we need to zoom
/// once if the user preference is different than 100%.
/// I tried some other ways to do the exact same thing but
/// this was the most reliable way. This event gets called
/// after every website is fully loaded.
/// </summary>
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!zoomedBefore)
{
ZoomWebBrowser();
zoomedBefore = true;
}
}

/// <summary>
/// This prevents WebBrowser from opening (real) Internet Explorer and then
/// navigates to the clicked link.
Expand All @@ -672,6 +657,19 @@ private void webBrowser1_NewWindow(object sender, System.ComponentModel.CancelEv
{
e.Cancel = true;
NavigateWebBrowser(this.webBrowser1.StatusText);
HideDownloadButtons();
}

private void ShowDownloadButtons()
{
cssBtnDownload.Style = cssBtnDownloadFully.Style = String.Empty;
cssBtnBack.Style = "display: none;";
}

private void HideDownloadButtons()
{
cssBtnDownload.Style = cssBtnDownloadFully.Style = "display: none;";
cssBtnBack.Style = String.Empty;
}

/// <summary>
Expand Down Expand Up @@ -735,6 +733,13 @@ private void txtSearch_KeyDown(object sender, KeyEventArgs e)
}
}

private void label5_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/PythEch/Cygnus");
}

#endregion Methods


}
}
4 changes: 2 additions & 2 deletions Cygnus/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.1.0")]
[assembly: AssemblyFileVersion("0.5.1.0")]
[assembly: AssemblyVersion("0.5.2.0")]
[assembly: AssemblyFileVersion("0.5.2.0")]
53 changes: 41 additions & 12 deletions Cygnus/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cygnus/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,7 @@
<data name="spinner" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\spinner.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="WebBrowserStyles" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\WebBrowserStyles.html;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
67 changes: 67 additions & 0 deletions Cygnus/WebBrowserStyles.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<html>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=edge' />
<style type='text/css'>
html,
body,
#depiction {
height: 100%;
}
body {
overflow: hidden;
margin: 0;
padding: 0;
}
.btn {
position: relative;
top: 0;
width: 45%;
padding: 3% 0;
margin: 5px;
border: 0;
border-radius: 6px;
box-shadow: #007269 0 5px 0;
background-color: #00a683;
font-size: 1.2rem;
font-weight: 450;
color: white;
cursor: pointer;
transition-property: background-color, box-shadow, top;
transition-duration: 300ms, 150ms, 150ms;
}
.btn:hover {
background-color: #007e6a;
box-shadow: #004047 0 5px 0;
}
.btn:active {
top: 2px;
box-shadow: #004047 0 3px 0;
}
#header {
top: 0;
left: 0;
width: 100%;
padding: 0 0 5px;
margin: 0;
background-color: #08C29A;
}
#depiction {
padding-bottom: 70px;
width: 100%;
border: none;
box-sizing: border-box;
}
#downloadfully {
float: right;
}
</style>
</head>
<body>
<div id='header'>
<input type='button' class='btn' value='&lt; Back' id='back' style='display: none;' />
<input type='button' class='btn' value='Download' id='download' />
<input type='button' class='btn' value='Download Fully' id='downloadfully' />
</div>
<iframe id='depiction'>Your browser is too damn old...</iframe>
</body>
</html>

1 comment on commit 83bf2b7

@PythEch
Copy link
Owner Author

@PythEch PythEch commented on 83bf2b7 May 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This html needs a beta test though, I tried that only with IE11.

Please sign in to comment.