/// <inheritdoc/>> public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { bool result = false; Debug.WriteLine(String.Format("OnKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers)); // TODO: Handle MessageNeeded cases here somehow. return result; }
public bool OnPreKeyEvent(IWebBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, bool isKeyboardShortcut) { bool block = false; if (KeyCommand != null) block = KeyCommand(this, windowsKeyCode); return block; }
internal CefMouseEvent(cef_mouse_event_t* ptr) { Debug.Assert(ptr != null); _x = ptr->x; _y = ptr->y; _modifiers = ptr->modifiers; }
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, int commandId, CefEventFlags eventFlags) { if (commandId == (int)CefMenuCommand.Reload) { browser.Reload(); } return false; }
public bool OnPreKeyEvent(IWebBrowser browserControl, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { if (windowsKeyCode == (int)Keys.F12) { Program.Form.ChromiumBrowser.ShowDevTools(); } return false; }
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { if ((int)commandId == ShowDevTools) { browser.ShowDevTools(); } if ((int)commandId == CloseDevTools) { browser.CloseDevTools(); } return false; }
protected override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags) { foreach (CommandItem commItem in commandItems) { if (commItem.id == commandId) { commItem.item.PerformClick(); break; } } return base.OnContextMenuCommand(browser, frame, state, commandId, eventFlags); }
private int on_context_menu_command(cef_context_menu_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, cef_context_menu_params_t* @params, int command_id, CefEventFlags event_flags) { CheckSelf(self); var mBrowser = CefBrowser.FromNative(browser); var mFrame = CefFrame.FromNative(frame); var mState = CefContextMenuParams.FromNative(@params); var result = OnContextMenuCommand(mBrowser, mFrame, mState, command_id, event_flags); mState.Dispose(); return result ? 1 : 0; }
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { if (commandId == (CefMenuCommand)26501) { browser.GetHost().ShowDevTools(); return true; } if (commandId == (CefMenuCommand)26502) { browser.GetHost().CloseDevTools(); return true; } return false; }
private int OnContextMenuCommand(IntPtr self, IntPtr browser, IntPtr frame, IntPtr @params, int commandid, CefEventFlags eventflags) { var e = new ContextMenuCommandEventArgs { Browser = Browser.FromHandle(browser), Frame = Frame.FromHandle(frame), Arguments = ContextMenuArgs.FromHandle(@params), Command = commandid, Modifiers = (KeyModifiers) eventflags }; _browserDelegate.OnContextMenuCommand(e); e.Arguments.Dispose(); return Convert.ToInt32(false); }
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { if ((int)commandId == OpenLinkInNewTab) { //browser.ShowDevTools(); OpenInNewTabContextMenu?.Invoke(this, new NewTabEventArgs(parameters.UnfilteredLinkUrl)); } if ((int)commandId == CloseDevTools) { browser.CloseDevTools(); } if ((int)commandId == MenuSaveImage) { DownloadImage?.Invoke(this, new DownloadImageViaContextMenuEventArgs(parameters.SourceUrl)); } if ((int)commandId == ViewSource) { ViewPageSource?.Invoke(this, null); } if ((int)commandId == SaveYouTubeVideo) { DownloadYouTubeVideo?.Invoke(this, null); //we have the address, anyway, so don't need to pass it via event args. } if ((int)commandId == ViewImageExifData) { ViewImageExif?.Invoke(this, new ExifViewerEventArgs(parameters.SourceUrl)); } if ((int)commandId == ViewFacebookId) { ViewFacebookIdNum?.Invoke(this, EventArgs.Empty); } if ((int)commandId == CopyImgLocation) { CopyImageLocation?.Invoke(this, new ExifViewerEventArgs(parameters.SourceUrl)); } if ((int)commandId == ReverseImageSearch) { ReverseImgSearch?.Invoke(this, new ExifViewerEventArgs(parameters.SourceUrl)); } return false; }
public static int ToNativeKeyCode(this Key key, CefKeyEventType eventType, bool isRepeat, CefEventFlags modifiers, bool isExtended) { return(CefNetApi.GetNativeKeyCode(eventType, isRepeat ? 1 : 0, ToVirtualKey(key), modifiers, isExtended)); }
public bool OnPreKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { //throw new NotImplementedException(); return(false); }
public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { return(false); }
/// <summary> /// Perform the action associated with the specified |command_id| and optional /// |event_flags|. /// </summary> public unsafe virtual void ExecuteCommand(CefMenuModel menuModel, int commandId, CefEventFlags eventFlags) { }
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { return(false); }
/// <inheritdoc/>> public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { const int WM_SYSKEYDOWN = 0x104; const int WM_KEYDOWN = 0x100; const int WM_KEYUP = 0x101; const int WM_SYSKEYUP = 0x105; const int WM_CHAR = 0x102; const int WM_SYSCHAR = 0x106; const int VK_TAB = 0x9; const int VK_LEFT = 0x25; const int VK_UP = 0x26; const int VK_RIGHT = 0x27; const int VK_DOWN = 0x28; isKeyboardShortcut = false; // Don't deal with TABs by default: // TODO: Are there any additional ones we need to be careful of? // i.e. Escape, Return, etc...? if (windowsKeyCode == VK_TAB || windowsKeyCode == VK_LEFT || windowsKeyCode == VK_UP || windowsKeyCode == VK_DOWN || windowsKeyCode == VK_RIGHT) { return(false); } var result = false; var control = browserControl as Control; var msgType = 0; switch (type) { case KeyType.RawKeyDown: if (isSystemKey) { msgType = WM_SYSKEYDOWN; } else { msgType = WM_KEYDOWN; } break; case KeyType.KeyUp: if (isSystemKey) { msgType = WM_SYSKEYUP; } else { msgType = WM_KEYUP; } break; case KeyType.Char: if (isSystemKey) { msgType = WM_SYSCHAR; } else { msgType = WM_CHAR; } break; default: Trace.Assert(false); break; } // We have to adapt from CEF's UI thread message loop to our fronting WinForm control here. // So, we have to make some calls that Application.Run usually ends up handling for us: var state = PreProcessControlState.MessageNotNeeded; // We can't use BeginInvoke here, because we need the results for the return value // and isKeyboardShortcut. In theory this shouldn't deadlock, because // atm this is the only synchronous operation between the two threads. control.Invoke(new Action(() => { var msg = new Message { HWnd = control.Handle, Msg = msgType, WParam = new IntPtr(windowsKeyCode), LParam = new IntPtr(nativeKeyCode) }; // First comes Application.AddMessageFilter related processing: // 99.9% of the time in WinForms this doesn't do anything interesting. var processed = Application.FilterMessage(ref msg); if (processed) { state = PreProcessControlState.MessageProcessed; } else { // Next we see if our control (or one of its parents) // wants first crack at the message via several possible Control methods. // This includes things like Mnemonics/Accelerators/Menu Shortcuts/etc... state = control.PreProcessControlMessage(ref msg); } })); if (state == PreProcessControlState.MessageNeeded) { // TODO: Determine how to track MessageNeeded for OnKeyEvent. isKeyboardShortcut = true; } else if (state == PreProcessControlState.MessageProcessed) { // Most of the interesting cases get processed by PreProcessControlMessage. result = true; } Debug.WriteLine("OnPreKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers); Debug.WriteLine("OnPreKeyEvent PreProcessControlState: {0}", state); return(result); }
public bool OnKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int keyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { var handled = false; if (IsReloadShortcut(type, keyCode, modifiers)) { webBrowser.Reload(); handled = true; } return(handled); }
bool IKeyboardHandler.OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { return(false); }
public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { var isHandled = false; switch (type) { case KeyType.RawKeyDown: if (windowsKeyCode == F12Code && Settings.RemoteDebuggingPort != default(int)) { _logger.LogInformation(LoggerEventIds.OpenDebugTools, "F12: Opening debug tools"); Process.Start("chrome.exe", "http://localhost:" + Settings.RemoteDebuggingPort); isHandled = true; } break; case KeyType.KeyUp: break; case KeyType.Char: if (windowsKeyCode == ControlRCode) { _logger.LogInformation(LoggerEventIds.Refresh, "Ctrl-R: Triggering reload of '{0}'", browserControl.Address); browserControl.Reload(); isHandled = true; } break; } return(isHandled); }
public override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams @params, int commandId, CefEventFlags eventFlags) { return(_implementation.OnContextMenuCommand(browser, frame, @params, commandId, eventFlags)); }
public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { switch (commandId) { case (CefMenuCommand)26501: browser.GetHost().ShowDevTools(); return(true); case (CefMenuCommand)26502: browser.GetHost().CloseDevTools(); return(true); case CefMenuCommand.Back: browser.GoBack(); return(true); case CefMenuCommand.Forward: browser.GoForward(); return(true); case CefMenuCommand.Print: browser.GetHost().Print(); return(true); case CefMenuCommand.ViewSource: browser.FocusedFrame.ViewSource(); return(true); } return(false); }
/// <summary> /// The on context menu command. /// </summary> /// <param name="browserControl"> /// The browser control. /// </param> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="commandId"> /// The command id. /// </param> /// <param name="eventFlags"> /// The event flags. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { if (debugging) { if ((int)commandId == ShowDevTools) { browser.ShowDevTools(); } if ((int)commandId == CloseDevTools) { browser.CloseDevTools(); } } return(false); }
/// <summary> /// Called before a context menu is displayed. |params| provides information /// about the context menu state. |model| initially contains the default /// context menu. The |model| can be cleared to show no context menu or /// modified to show a custom menu. Do not keep references to |params| or /// |model| outside of this callback. /// </summary> // protected abstract void OnBeforeContextMenu(cef_browser_t* browser, cef_frame_t* frame, cef_context_menu_params_t* @params, cef_menu_model_t* model); private int on_context_menu_command(cef_context_menu_handler_t *self, cef_browser_t *browser, cef_frame_t *frame, cef_context_menu_params_t * @params, int command_id, CefEventFlags event_flags) { CheckSelf(self); throw new NotImplementedException(); // TODO: CefContextMenuHandler.OnContextMenuCommand }
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { if ((int)commandId == OpenLinkInNewTab) { //browser.ShowDevTools(); OpenInNewTabContextMenu?.Invoke(this, new NewTabEventArgs(parameters.UnfilteredLinkUrl)); } if ((int)commandId == CloseDevTools) { browser.CloseDevTools(); } if ((int)commandId == MenuSaveImage) { DownloadImage?.Invoke(this, new DownloadImageViaContextMenuEventArgs(parameters.SourceUrl)); } if ((int)commandId == ViewSource) { ViewPageSource?.Invoke(this, null); } if ((int)commandId == SaveYouTubeVideo) { DownloadYouTubeVideo?.Invoke(this, null); //we have the address, anyway, so don't need to pass it via event args. } if ((int)commandId == ViewImageExifData) { ViewImageExif?.Invoke(this, new ExifViewerEventArgs(parameters.SourceUrl)); } if ((int)commandId == ViewFacebookId) { ViewFacebookIdNum?.Invoke(this, EventArgs.Empty); } if ((int)commandId == ViewTwitterId) { ViewTwitterIdNum?.Invoke(this, EventArgs.Empty); } if ((int)commandId == CopyImgLocation) { CopyImageLocation?.Invoke(this, new ExifViewerEventArgs(parameters.SourceUrl)); } if ((int)commandId == ReverseImageSearch) { ReverseImgSearch?.Invoke(this, new ExifViewerEventArgs(parameters.SourceUrl)); } if ((int)commandId == ExtractAllLinks) { ExtractLinks?.Invoke(this, EventArgs.Empty); } if ((int)commandId == Bookmark) { AddPageToBookmarks?.Invoke(this, EventArgs.Empty); } return(false); }
public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { int id = (int)commandId; if (id == ShowDevTools) { browser.ShowDevTools(); } if (id == CloseDevTools) { browser.CloseDevTools(); } if (id == SaveImageAs) { browser.GetHost().StartDownload(parameters.SourceUrl); } if (id == SaveLinkAs) { browser.GetHost().StartDownload(parameters.LinkUrl); } if (id == OpenLinkInNewTab) { ChromiumWebBrowser newBrowser = myForm.AddNewBrowserTab(parameters.LinkUrl, false); } if (id == CopyLinkAddress) { Clipboard.SetText(parameters.LinkUrl); } if (id == CloseTab) { myForm.InvokeOnParent(delegate() { myForm.CloseActiveTab(); }); } if (id == RefreshTab) { myForm.InvokeOnParent(delegate() { myForm.RefreshActiveTab(); }); } return(false); }
public override bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { if (base.OnContextMenuCommand(browserControl, browser, frame, parameters, commandId, eventFlags)) { return(true); } switch ((int)commandId) { case MenuSkipTweet: form.InvokeAsyncSafe(form.FinishCurrentNotification); return(true); case MenuFreeze: form.InvokeAsyncSafe(() => form.FreezeTimer = !form.FreezeTimer); return(true); case MenuCopyTweetUrl: SetClipboardText(form.CurrentTweetUrl); return(true); case MenuCopyQuotedTweetUrl: SetClipboardText(form.CurrentQuoteUrl); return(true); } return(false); }
protected virtual bool HandleRawKey(IWebBrowser browserControl, IBrowser browser, Keys key, CefEventFlags modifiers) { if (modifiers == (CefEventFlags.ControlDown | CefEventFlags.ShiftDown) && key == Keys.I) { if (BrowserUtils.HasDevTools) { browserControl.OpenDevToolsCustom(); } else { browserControl.AsControl().InvokeSafe(() => { string extraMessage; if (Program.IsPortable) { extraMessage = "Please download the portable installer, select the folder with your current installation of TweetDuck Portable, and tick 'Install dev tools' during the installation process."; } else { extraMessage = "Please download the installer, and tick 'Install dev tools' during the installation process. The installer will automatically find and update your current installation of TweetDuck."; } FormMessage.Information("Dev Tools", "You do not have dev tools installed. " + extraMessage, FormMessage.OK); }); } return(true); } return(false); }
public static void SendMouseWheelEvent(this IWebBrowser browser, int x, int y, int deltaX, int deltaY, CefEventFlags modifiers) { var cefBrowser = browser.GetBrowser(); ThrowExceptionIfBrowserNull(cefBrowser); cefBrowser.SendMouseWheelEvent(x, y, deltaX, deltaY, modifiers); }
public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { var isHandled = false; switch (type) { case KeyType.RawKeyDown: if (windowsKeyCode == F12Code) { isKeyboardShortcut = true; } break; case KeyType.KeyUp: break; case KeyType.Char: if (windowsKeyCode == ControlRCode) { isKeyboardShortcut = true; } break; } return(isHandled); }
public cef_mouse_event_t(int x, int y, CefEventFlags modifiers) { this.x = x; this.y = y; this.modifiers = modifiers; }
/// <inheritdoc/>> public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { var result = false; Debug.WriteLine("OnKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers); // TODO: Handle MessageNeeded cases here somehow. return(result); }
public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { return true; }
public bool OnPreKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int keyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { if (IsReloadShortcut(type, keyCode, modifiers)) { isKeyboardShortcut = true; } return(false); }
public static void SendMouseWheelEvent(this IBrowser browser, int x, int y, int deltaX, int deltaY, CefEventFlags modifiers) { var host = browser.GetHost(); ThrowExceptionIfBrowserHostNull(host); host.SendMouseWheelEvent(x, y, deltaX, deltaY, modifiers); }
// void (*)(_cef_menu_model_delegate_t* self, _cef_menu_model_t* menu_model, int command_id, cef_event_flags_t event_flags)* private static unsafe void ExecuteCommandImpl(cef_menu_model_delegate_t *self, cef_menu_model_t *menu_model, int command_id, CefEventFlags event_flags) { var instance = GetInstance((IntPtr)self) as CefMenuModelDelegate; if (instance == null || ((ICefMenuModelDelegatePrivate)instance).AvoidExecuteCommand()) { ReleaseIfNonNull((cef_base_ref_counted_t *)menu_model); return; } instance.ExecuteCommand(CefMenuModel.Wrap(CefMenuModel.Create, menu_model), command_id, event_flags); }
public bool OnKeyEvent(IWebBrowser browser, KeyType type, int code, CefEventFlags modifiers, bool isSystemKey) { return false; }
public bool OnKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { //throw new NotImplementedException(); if (type == KeyType.KeyUp && Enum.IsDefined(typeof(Keys), windowsKeyCode)) { var key = (Keys)windowsKeyCode; switch (key) { case Keys.F12: browser.ShowDevTools(); break; case Keys.F5: if (modifiers == CefEventFlags.ControlDown) { //MessageBox.Show("ctrl+f5"); browser.Reload(true); //强制忽略缓存 } else { //MessageBox.Show("f5"); browser.Reload(); } break; } } return(false); }
static CefEventFlags GetCurrentKeyboardModifiers() { CefEventFlags result = new CefEventFlags(); if( EngineApp.Instance.IsKeyPressed( EKeys.Alt ) ) result |= CefEventFlags.AltDown; if( EngineApp.Instance.IsKeyPressed( EKeys.Shift ) ) result |= CefEventFlags.ShiftDown; if( EngineApp.Instance.IsKeyPressed( EKeys.Control ) ) result |= CefEventFlags.ControlDown; if( EngineApp.Instance.IsKeyPressed( EKeys.LWin ) || EngineApp.Instance.IsKeyPressed( EKeys.RWin ) || EngineApp.Instance.IsKeyPressed( EKeys.Command ) ) { result |= CefEventFlags.CommandDown; } return result; }
public static void SendMouseWheelEvent(this IBrowserHost host, int x, int y, int deltaX, int deltaY, CefEventFlags modifiers) { ThrowExceptionIfBrowserHostNull(host); host.SendMouseWheelEvent(new MouseEvent(x, y, modifiers), deltaX, deltaY); }
/// <summary> /// Called to execute a command selected from the context menu. Return true if /// the command was handled or false for the default implementation. See /// cef_menu_id_t for the command ids that have default implementations. All /// user-defined command ids should be between MENU_ID_USER_FIRST and /// MENU_ID_USER_LAST. |params| will have the same values as what was passed to /// OnBeforeContextMenu(). Do not keep a reference to |params| outside of this /// callback. /// </summary> protected virtual bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags) { return false; }
public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { return false; }
public static void SendMouseClickEvent(this IBrowserHost host, int x, int y, MouseButtonType mouseButtonType, bool mouseUp, int clickCount, CefEventFlags modifiers) { ThrowExceptionIfBrowserHostNull(host); host.SendMouseClickEvent(new MouseEvent(x, y, modifiers), mouseButtonType, mouseUp, clickCount); }
public static void SendMouseMoveEvent(this IBrowserHost host, int x, int y, bool mouseLeave, CefEventFlags modifiers) { ThrowExceptionIfBrowserHostNull(host); host.SendMouseMoveEvent(new MouseEvent(x, y, modifiers), mouseLeave); }
public CefMouseEvent(int x, int y, CefEventFlags modifiers) { _x = x; _y = y; _modifiers = modifiers; }
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { if ((int)commandId == ShowDevTools) { browser.GetHost().ShowDevTools(); return(true); } if ((int)commandId == CloseDevTools) { browser.GetHost().CloseDevTools(); return(true); } return(false); }
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { return false; }
public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { switch ((int)commandId) { case MenuOpenLinkUrl: BrowserUtils.OpenExternalBrowser(parameters.LinkUrl); break; case MenuCopyLinkUrl: SetClipboardText(string.IsNullOrEmpty(TweetDeckBridge.LastRightClickedLink) ? parameters.UnfilteredLinkUrl : TweetDeckBridge.LastRightClickedLink); break; case MenuOpenImage: BrowserUtils.OpenExternalBrowser(parameters.SourceUrl); break; case MenuSaveImage: string fileName = GetImageFileName(parameters.SourceUrl); string extension = Path.GetExtension(fileName); string saveTarget; using (SaveFileDialog dialog = new SaveFileDialog { AutoUpgradeEnabled = true, OverwritePrompt = true, Title = "Save image", FileName = fileName, Filter = "Image (" + (string.IsNullOrEmpty(extension) ? "unknown" : extension) + ")|*.*" }){ saveTarget = dialog.ShowDialog() == DialogResult.OK ? dialog.FileName : null; } if (saveTarget != null) { BrowserUtils.DownloadFileAsync(parameters.SourceUrl, saveTarget, ex => { MessageBox.Show("An error occurred while downloading the image: " + ex.Message, Program.BrandName + " Has Failed :(", MessageBoxButtons.OK, MessageBoxIcon.Error); }); } break; case MenuCopyImageUrl: SetClipboardText(parameters.SourceUrl); break; #if DEBUG case MenuOpenDevTools: browserControl.ShowDevTools(); break; #endif } return(false); }
/// <inheritdoc/>> public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { const int WM_SYSKEYDOWN = 0x104; const int WM_KEYDOWN = 0x100; const int WM_KEYUP = 0x101; const int WM_SYSKEYUP = 0x105; const int WM_CHAR = 0x102; const int WM_SYSCHAR = 0x106; const int VK_TAB = 0x9; bool result = false; isKeyboardShortcut = false; // Don't deal with TABs by default: // TODO: Are there any additional ones we need to be careful of? // i.e. Escape, Return, etc...? if (windowsKeyCode == VK_TAB) { return result; } Control control = browserControl as Control; int msgType = 0; switch (type) { case KeyType.RawKeyDown: if (isSystemKey) { msgType = WM_SYSKEYDOWN; } else { msgType = WM_KEYDOWN; } break; case KeyType.KeyUp: if (isSystemKey) { msgType = WM_SYSKEYUP; } else { msgType = WM_KEYUP; } break; case KeyType.Char: if (isSystemKey) { msgType = WM_SYSCHAR; } else { msgType = WM_CHAR; } break; default: Trace.Assert(false); break; } // We have to adapt from CEF's UI thread message loop to our fronting WinForm control here. // So, we have to make some calls that Application.Run usually ends up handling for us: PreProcessControlState state = PreProcessControlState.MessageNotNeeded; // We can't use BeginInvoke here, because we need the results for the return value // and isKeyboardShortcut. In theory this shouldn't deadlock, because // atm this is the only synchronous operation between the two threads. control.Invoke(new Action(() => { Message msg = new Message() { HWnd = control.Handle, Msg = msgType, WParam = new IntPtr(windowsKeyCode), LParam = new IntPtr(nativeKeyCode) }; // First comes Application.AddMessageFilter related processing: // 99.9% of the time in WinForms this doesn't do anything interesting. bool processed = Application.FilterMessage(ref msg); if (processed) { state = PreProcessControlState.MessageProcessed; } else { // Next we see if our control (or one of its parents) // wants first crack at the message via several possible Control methods. // This includes things like Mnemonics/Accelerators/Menu Shortcuts/etc... state = control.PreProcessControlMessage(ref msg); } })); if (state == PreProcessControlState.MessageNeeded) { // TODO: Determine how to track MessageNeeded for OnKeyEvent. isKeyboardShortcut = true; } else if (state == PreProcessControlState.MessageProcessed) { // Most of the interesting cases get processed by PreProcessControlMessage. result = true; } Debug.WriteLine(String.Format("OnPreKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers)); Debug.WriteLine(String.Format("OnPreKeyEvent PreProcessControlState: {0}", state)); return result; }
public bool OnContextMenuCommand(IWebBrowser browserControl, CefSharp.IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { return(false); }
bool IKeyboardHandler.OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { if (type == KeyType.RawKeyDown && !browser.FocusedFrame.Url.StartsWith("devtools://")) { return(HandleRawKey(browserControl, browser, (Keys)windowsKeyCode, modifiers)); } return(false); }
bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { if (commandId == (CefMenuCommand)26501) { if (!url.Equals("")) { Dispatcher.Invoke(() => { Console.WriteLine(parameters.SelectionText); ApplicationCommands.New.Execute( new OpenTabCommandParameters(url, "New tab", "#FFF9F9F9"), this); }); return true; } } if (commandId == (CefMenuCommand) 26502) { SaveFileDialog dialog = new SaveFileDialog(); dialog.FileName = "image.png"; dialog.Filter = "Png image (*.png)|*.png|Gif Image (*.gif)|*.gif|JPEG image (*.jpg)|*.jpg"; var result = dialog.ShowDialog(); if (result == DialogResult.OK) { Console.WriteLine("writing to: " + dialog.FileName); var wClient = new WebClient(); wClient.DownloadFile(img, dialog.FileName); } } return false; }