Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions src/Config/BrowserConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CefSharp;
using CefSharp.WinForms;
using System.Net;

namespace SharpBrowser.Config {
internal static class BrowserConfig {
Expand Down Expand Up @@ -101,19 +102,29 @@ internal static class BrowserConfig {
public static bool TextAreaResize = true;


//3way to set proxy, needs enum to reduce complication.
public static ProxyMode currentProxyMode = ProxyMode.AutoDetect;
//public static bool useSystemProxy = true;

/// <summary>
/// If true then the following proxy is used for all browsing and downloads.
/// </summary>
public static bool Proxy = false;
//public static bool customProxy = false;
public static string ProxyIP = "123.123.123.123";
public static int ProxyPort = 123;
public static string ProxyUsername = "username";
public static string ProxyPassword = "pass";
public static string ProxyBypassList = "";



public enum ProxyMode
{
/// <summary>
/// aka use system proxy
/// </summary>
AutoDetect,
CustomProxy,
NoProxy,
}

/// <summary>
/// Load the above config into the CEF `BrowserSettings` object.
Expand Down Expand Up @@ -157,13 +168,21 @@ public static void GetCefSettings(CefSettings settings) {
settings.CefCommandLineArgs.Add("enable-media-stream", "1");
}

// enable proxy if wanted
if (Proxy) {
CefSharpSettings.Proxy = new ProxyOptions(ProxyIP,
ProxyPort.ToString(), ProxyUsername,
ProxyPassword, ProxyBypassList);
if (currentProxyMode == ProxyMode.AutoDetect)
{
//settings.CefCommandLineArgs.Add("proxy-auto-detect"); // or maybe do nothing.
}
else if (currentProxyMode == ProxyMode.CustomProxy)
{
// enable proxy if wanted
CefSharpSettings.Proxy = new ProxyOptions(
ProxyIP,
ProxyPort.ToString(),
ProxyUsername,ProxyPassword,
ProxyBypassList);
}
else {
else if (currentProxyMode == ProxyMode.NoProxy)
{

// disable proxy if not wanted
settings.CefCommandLineArgs.Add("no-proxy-server");
Expand Down
12 changes: 8 additions & 4 deletions src/Controls/BorderedTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ public class BorderedTextBox : Panel
private TextBox textBox;
private bool focusedAlways = false;
private Color normalBorderColor = Color.LightGray;
//private Color focusedBorderColor = Color.FromArgb(86,156,214);
//private Color focusedBorderColor = Color.FromArgb(86, 156, 214);
//private Color focusedBorderColor = Color.FromArgb(0,00,225);
private Color focusedBorderColor = Color.FromArgb(11, 87, 208);
//private Color focusedBorderColor = Color.FromArgb(11, 87, 208);
private Color focusedBorderColor = Color.FromArgb(153, 187, 239); //edge light blue
public int borderThickness = 2;

int roundingRadius=19; //5 firefox, //19 full-round //15

public TextBox TextBox
{
get { return textBox; }
Expand Down Expand Up @@ -143,15 +146,16 @@ protected override void OnPaint(PaintEventArgs e)
new Rectangle(0 + borderThickness, 0 + borderThickness,
this.ClientSize.Width - borderThickness * 2,
this.ClientSize.Height - borderThickness * 2)
, 15);
, roundingRadius);

e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

//e.Graphics.DrawRectangle(borderPen,
e.Graphics.DrawRoundRectangle(borderPen,
new Rectangle(0+borderThickness, 0 + borderThickness,
this.ClientSize.Width - borderThickness*2,
this.ClientSize.Height - borderThickness*2)
,15);
, roundingRadius);
}
base.OnPaint(e);
}
Expand Down
12 changes: 7 additions & 5 deletions src/Controls/BrowserTabStrip/BrowserTabStrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class BrowserTabStrip : BaseStyledPanel, ISupportInitialize, IDisposabl
private BrowserTabPage selectedItem;
private ContextMenuStrip menu;
private TabCloseButton closeButton;
private TabNewButton newTabButton;
private NewTabButton newTabButton;
private BrowserTabStripItemCollection items;

private StringFormat DrawStringFormat;
Expand Down Expand Up @@ -121,7 +121,7 @@ public BrowserTabStrip() {
menu.ItemClicked += OnMenuItemClicked;
menu.VisibleChanged += OnMenuVisibleChanged;
closeButton = new TabCloseButton(base.ToolStripRenderer);
newTabButton = new TabNewButton(base.ToolStripRenderer);
newTabButton = new NewTabButton(base.ToolStripRenderer);
DrawStringFormat = new StringFormat();
EndInit();
UpdateLayout();
Expand Down Expand Up @@ -357,6 +357,7 @@ protected override void OnPaint(PaintEventArgs e) {
}

//--------------------------------------------------------
// DRAW BOTTOM LINE to tabButtons, Except Active Tab.

if (Items.DrawnCount == 0 || Items.VisibleCount == 0) {
e.Graphics.DrawLine(Pens.Red, new Point(0, BrowserTabStyle.TabHeight), new Point(base.ClientRectangle.Width, BrowserTabStyle.TabHeight));
Expand Down Expand Up @@ -491,11 +492,12 @@ private void OnDrawTabButton(Graphics g, BrowserTabPage tab) {
}

// draw tab text title
// FIX: fix janky text rendering and bad kerning by using TextRenderer instead of DrawString
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
if (tab == SelectedTab) {
if (tab == SelectedTab)
{
textRect.Width -= 25;
}
// FIX: fix janky text rendering and bad kerning by using TextRenderer instead of DrawString
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
TextRenderer.DrawText(g,tab.Title,font,Rectangle.Round(textRect),ForeColorSel,
TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Windows.Forms;

namespace SharpBrowser.Controls.BrowserTabStrip.Buttons {
internal class TabNewButton(ToolStripProfessionalRenderer renderer) : TabButtonBase(renderer) {
internal class NewTabButton(ToolStripProfessionalRenderer renderer) : TabButtonBase(renderer) {

public override void Draw(Graphics g) {
if (IsVisible) {
Expand Down
144 changes: 144 additions & 0 deletions src/Controls/CircularDownloadProgress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using SharpBrowser.Managers;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;

namespace SharpBrowser.Controls
{

/// <summary>
/// Draws Download Progress as Circle to Given Button..
/// </summary>
public class CircularDownloadProgress
{

public CircularDownloadProgress(Button btnDL)
{

init_downloads_indicator(btnDL);
}
//------ draw Circular downloading Progress

Button _btnDL;
public void init_downloads_indicator(Button btnDL)
{
_btnDL = btnDL;
btnDL.Paint += btnDL_Paint;
var tmr_downloader = new System.Windows.Forms.Timer();
tmr_downloader.Interval = 500;
tmr_downloader.Tick += Tmr_downloader_Tick;
tmr_downloader.Start();
}

int testdl_pct = 0;
private void Tmr_downloader_Tick(object sender, EventArgs e)
{

bool isDownloading=false;
bool needs_lastRefresh=false;
try
{
isDownloading = DownloadManager.DownloadsInProgress();
if (!isDownloading)
{
var curdlitemKV_val = DownloadManager.Downloads
.Where(x => DateTime.Now.Subtract( x.Value.EndTime ?? DateTime.MinValue).TotalSeconds <3 )
.Select(x=>x.Value)
.FirstOrDefault();
//var curdlitem = curdlitemKV.Value;
if(curdlitemKV_val != null)
needs_lastRefresh = true;
}
}
catch (Exception ex) { }

if (isDownloading || needs_lastRefresh)
_btnDL.Refresh();

//BtnDownloads.Invalidate();


//testdl_pct = testdl_pct + 10;
//if (testdl_pct > 100)
// testdl_pct = 0;
}

private void btnDL_Paint(object sender, PaintEventArgs e)
{
try
{
var isDownloading = DownloadManager.DownloadsInProgress();
float pct_ofRecentDownloadingItem = 0;
if (isDownloading)
{
var curdlitemKV = DownloadManager.Downloads.Where(x => x.Value.IsInProgress).FirstOrDefault();
var curdlitem = curdlitemKV.Value;
pct_ofRecentDownloadingItem = (int)(curdlitem.ReceivedBytes * 100.0f / curdlitem.TotalBytes);
}

//var isDownloading = true;
if (isDownloading)
{
//var pct1 = 100; // 100 %;
//var pct2 = 50; // 50 %;
//var pct3 =25; // 20 %;
var pct = testdl_pct; //test val; // <<<<---- input download percentage HERE;;
pct = (int)pct_ofRecentDownloadingItem;

var pctAs360val = pct / 100.0f * 360;
var arc_StartOffset = 90;

//Color activeColorORG = Color.FromArgb(11, 87, 208);
//Color activeLightColor = Color.FromArgb(76, 194, 255);
Color activeColor = Color.FromArgb(27, 117, 208);
int gray = 200;
var myGray = Color.FromArgb(gray, gray, gray);

//var loc = BtnDownloads.Location;
//var sz = BtnDownloads.Size;
var loc = new Point(0, 0);
var sz = _btnDL.ClientRectangle;
var pad = 0;
//var btng = BtnDownloads.CreateGraphics();

var thickness = 4;

var btng = e.Graphics;
//var btng = BtnDownloads.CreateGraphics();
btng.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;


var szHW_min = Math.Min(sz.Width, sz.Height);
var szHW_max_minus_min = Math.Abs(sz.Width - sz.Height) / 2; //aka center it. vertical.
Rectangle rect = new Rectangle(
loc.X + pad + thickness / 2,
loc.Y + pad + thickness / 2,
szHW_min - 1 * pad - thickness / 2 * 2 - 1,
szHW_min - 1 * pad - thickness / 2 * 2 - 1
);

rect.Offset(szHW_max_minus_min, 0);
//sz.Width - 1 * pad - thickness / 2 * 2 - 1,
//sz.Height - 1 * pad - thickness / 2 * 2 - 1
//);
//btng.FillRectangle(new Pen(new SolidBrush(Color.Black), 10).Brush, rect);
btng.DrawArc(new Pen(new SolidBrush(myGray), thickness), rect, 0 + arc_StartOffset, 360);
btng.DrawArc(new Pen(new SolidBrush(activeColor), thickness), rect, 0 + arc_StartOffset, pctAs360val);

}
}
catch (Exception ex)
{
Console.WriteLine(ex + "ERROR at btnDL_Paint:");
}
}



}
}
9 changes: 9 additions & 0 deletions src/Controls/DrawingExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ public static Color ChangeColorBrightness(this Color color, float correctionFact
return Color.FromArgb(color.A, (int)red, (int)green, (int)blue);
}

/// <summary>
/// Creates color with corrected brightness.
/// </summary>
/// <param name="color">Color to correct.</param>
/// <param name="correctionFactor">The brightness correction factor. Must be between -1 and 1.
/// Negative values produce darker colors.</param>
/// <returns>
/// Corrected <see cref="Color"/> structure.
/// </returns>
public static Color ChangeColorBrightness(this Color color, double correctionFactor)
=> ChangeColorBrightness(color, (float)correctionFactor);

Expand Down
34 changes: 33 additions & 1 deletion src/Handlers/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace SharpBrowser.Handlers {
internal class RequestHandler : IRequestHandler {
MainForm myForm;

public static bool settings__onCtrlClick_focusNewTab = true;

public RequestHandler(MainForm form) {
myForm = form;
}
Expand Down Expand Up @@ -107,6 +109,8 @@ public bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFr
public bool OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback) {
return true;
}


//
// Summary:
// Called on the UI thread before OnBeforeBrowse in certain limited cases where
Expand All @@ -132,8 +136,36 @@ public bool OnCertificateError(IWebBrowser browserControl, IBrowser browser, Cef
// Returns:
// Return true to cancel the navigation or false to allow the navigation to
// proceed in the source browser's top-level frame.
public bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture) {
public bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame,
string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture) {
//return false;

// check if the user intended to open the link in a new tab
// (Ctrl+Click often results in NewBackgroundTab or NewForegroundTab)
if (targetDisposition == WindowOpenDisposition.NewForegroundTab ||
targetDisposition == WindowOpenDisposition.NewBackgroundTab)
{
// Check if it was a user gesture (actual click)
if (userGesture)
{
myForm.Invoke((MethodInvoker)(() => {
myForm.AddNewBrowserTab(targetUrl,
//focusNewTab: (targetDisposition == WindowOpenDisposition.NewForegroundTab),
focusNewTab: settings__onCtrlClick_focusNewTab,
browser.MainFrame.Url
);
}));


//handled.. (dont load it in the current tab)
return true;
}
}

// For all other cases, return false to let the default navigation proceed.
return false;


}
//
// Summary:
Expand Down
2 changes: 1 addition & 1 deletion src/MainForm.Designer.cs

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

Loading