예제 #1
0
 public override void RunCommand(ICommand command, ExecutedRoutedEventArgs args)
 {
     if (command == ViewCommands.ToggleVisibility)
     {
         ToggleVisibility();
     }
     else if (command == ViewCommands.GetWebViewBounds)
     {
         ShowWebViewBounds();
     }
     else if (command == ViewCommands.ZoomHalf)
     {
         SetZoomFactor(.5f);
     }
     else if (command == ViewCommands.ZoomWhole)
     {
         SetZoomFactor(1f);
     }
     else if (command == ViewCommands.ZoomTwice)
     {
         SetZoomFactor(2f);
     }
     else if (command == ViewCommands.Area25Percent)
     {
     }
     else if (command == ViewCommands.Area50Percent)
     {
     }
     else if (command == ViewCommands.Area75Percent)
     {
     }
     else if (command == ViewCommands.Area100Percent)
     {
     }
     else if (command == ViewCommands.SetFocus)
     {
         _webView2.Focus();
     }
     else if (command == ViewCommands.TabIn)
     {
         _webView2.MoveFocus(WEBVIEW2_MOVE_FOCUS_REASON.WEBVIEW2_MOVE_FOCUS_REASON_NEXT);
     }
     else if (command == ViewCommands.ReverseTabIn)
     {
         _webView2.MoveFocus(WEBVIEW2_MOVE_FOCUS_REASON.WEBVIEW2_MOVE_FOCUS_REASON_PREVIOUS);
     }
     else if (command == ViewCommands.ToggleTabHandling)
     {
         _parent.AutoTabHandle = !_parent.AutoTabHandle;
     }
 }
예제 #2
0
 private void setFocusToolStripMenuItem_Click(object sender, EventArgs e)
 {
     _webView2Control.Focus();
 }
예제 #3
0
        public void OnWebMessageRecieved(WebMessageReceivedEventArgs args)
        {
            string source = args.Source;
            string json   = args.WebMessageAsJson;
            string str    = args.WebMessageAsString;

            JObject jsonObj = JObject.Parse(json);

            if (!jsonObj.ContainsKey("message"))
            {
                return;
            }

            if (!jsonObj.ContainsKey("args"))
            {
                return;
            }


            Messages m;

            if (!Enum.TryParse <Messages>(jsonObj["message"].Value <string>(), out m))
            {
                return;
            }
            JToken msgArgs = jsonObj["args"];

            switch (m)
            {
            case Messages.MG_CREATE_TAB:
            {
                int  tabId          = msgArgs["tabId"].Value <int>();
                bool shouldBeActive = msgArgs["active"].Value <bool>();

                Tab newTab = Tab.CreateNewTab(this, _contentEnvironment, tabId, shouldBeActive);

                if (!_tabDictionary.ContainsKey(tabId))
                {
                    newTab.Dock = DockStyle.Fill;
                    tableLayoutPanel1.Controls.Add(newTab, 0, 1);

                    _tabDictionary.Add(tabId, newTab);
                }
            }
            break;

            case Messages.MG_NAVIGATE:
            {
                string uri           = msgArgs["uri"].Value <string>();
                string browserScheme = "browser://";

                if (uri.Contains(browserScheme))
                {
                    string path = uri.Substring(browserScheme.Length);
                    if (path == "favorites" ||
                        path == "settings" ||
                        path == "history")
                    {
                        string filePath = "Content\\content_ui\\";
                        filePath  = Path.Combine(filePath, path);
                        filePath += ".html";
                        string fullPath = GetFullPathFor(filePath);
                        _tabDictionary[_activeTabId].Navigate(fullPath);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Requested unknown browser page");
                    }
                }
                else
                {
                    _tabDictionary[_activeTabId].Navigate(uri);
                }
            }
            break;

            case Messages.MG_GO_FORWARD:
            {
                _tabDictionary[_activeTabId].GoForward();
            }
            break;

            case Messages.MG_GO_BACK:
            {
                _tabDictionary[_activeTabId].GoBack();
            }
            break;

            case Messages.MG_RELOAD:
            {
                _tabDictionary[_activeTabId].Reload();
            }
            break;

            case Messages.MG_CANCEL:
            {
                _tabDictionary[_activeTabId].CallDevToolsProtocolMethod("Page.stopLoading", "{}", null);
            }
            break;

            case Messages.MG_SWITCH_TAB:
            {
                int tabId = msgArgs["tabId"].Value <int>();

                SwitchToTab(tabId);
            }
            break;

            case Messages.MG_CLOSE_TAB:
            {
                int tabId = msgArgs["tabId"].Value <int>();
                tableLayoutPanel1.Controls.Remove(_tabDictionary[tabId]);
                _tabDictionary.Remove(tabId);
            }
            break;

            case Messages.MG_CLOSE_WINDOW:
            {
                Close();
            }
            break;

            case Messages.MG_SHOW_OPTIONS:
            {
                _optionsWebView.Visible = true;
                ResizeUIWebViews();
                _optionsWebView.BringToFront();
                _optionsWebView.Focus();
            }
            break;

            case Messages.MG_HIDE_OPTIONS:
            {
                _optionsWebView.Visible = false;
            }
            break;

            case Messages.MG_OPTION_SELECTED:
            {
                _tabDictionary[_activeTabId].Focus();
            }
            break;

            case Messages.MG_GET_FAVORITES:
            case Messages.MG_GET_SETTINGS:
            case Messages.MG_GET_HISTORY:
            {
                // Forward back to requesting tab
                JToken tabIdToken = msgArgs["tabId"];
                int    tabId      = tabIdToken.Value <int>();

                RemoveFields(msgArgs, new string[] { "tabId" });

                PostJsonToWebView(jsonObj, _tabDictionary[tabId]);
            }
            break;
            }
        }