📄 webview.cpp
字号:
return wxEmptyString;}void wxWebView::LoadURL(const wxString& url){ if (m_mainFrame) m_mainFrame->LoadURL(url);}bool wxWebView::GoBack(){ if (m_mainFrame) return m_mainFrame->GoBack(); return false;}bool wxWebView::GoForward(){ if (m_mainFrame) return m_mainFrame->GoForward(); return false;}bool wxWebView::CanGoBack(){ if (m_mainFrame) return m_mainFrame->CanGoBack(); return false;}bool wxWebView::CanGoForward(){ if (m_mainFrame) return m_mainFrame->CanGoForward(); return false;}bool wxWebView::CanIncreaseTextSize() const{ if (m_mainFrame) return m_mainFrame->CanIncreaseTextSize(); return false;}void wxWebView::IncreaseTextSize(){ if (m_mainFrame) m_mainFrame->IncreaseTextSize();}bool wxWebView::CanDecreaseTextSize() const{ if (m_mainFrame) m_mainFrame->CanDecreaseTextSize(); return false;}void wxWebView::DecreaseTextSize(){ if (m_mainFrame) m_mainFrame->DecreaseTextSize();}void wxWebView::MakeEditable(bool enable){ m_isEditable = enable;}/* * Event forwarding functions to send events down to WebCore. */void wxWebView::OnPaint(wxPaintEvent& event){ if (m_beingDestroyed || !m_mainFrame) return; WebCore::Frame* frame = m_mainFrame->GetFrame(); if (!frame || !frame->view()) return; wxAutoBufferedPaintDC dc(this); if (IsShown() && frame->document()) {#if USE(WXGC) wxGCDC gcdc(dc);#endif if (dc.IsOk()) { wxRect paintRect = GetUpdateRegion().GetBox(); WebCore::IntSize offset = frame->view()->scrollOffset();#if USE(WXGC) gcdc.SetDeviceOrigin(-offset.width(), -offset.height());#endif dc.SetDeviceOrigin(-offset.width(), -offset.height()); paintRect.Offset(offset.width(), offset.height());#if USE(WXGC) WebCore::GraphicsContext* gc = new WebCore::GraphicsContext(&gcdc);#else WebCore::GraphicsContext* gc = new WebCore::GraphicsContext((wxWindowDC*)&dc);#endif if (gc && frame->contentRenderer()) { if (frame->view()->needsLayout()) frame->view()->layout(); frame->view()->paintContents(gc, paintRect); } delete gc; } }}bool wxWebView::FindString(const wxString& string, bool forward, bool caseSensitive, bool wrapSelection, bool startInSelection){ if (m_mainFrame) return m_mainFrame->FindString(string, forward, caseSensitive, wrapSelection, startInSelection); return false;}void wxWebView::OnSize(wxSizeEvent& event){ if (m_isInitialized && m_mainFrame) { WebCore::Frame* frame = m_mainFrame->GetFrame(); frame->eventHandler()->sendResizeEvent(); frame->view()->layout(); frame->view()->adjustScrollbars(); } event.Skip();}void wxWebView::OnMouseEvents(wxMouseEvent& event){ event.Skip(); if (!m_mainFrame) return; WebCore::Frame* frame = m_mainFrame->GetFrame(); if (!frame || !frame->view()) return; wxPoint globalPoint = ClientToScreen(event.GetPosition()); wxEventType type = event.GetEventType(); if (type == wxEVT_MOUSEWHEEL) { WebCore::PlatformWheelEvent wkEvent(event, globalPoint); frame->eventHandler()->handleWheelEvent(wkEvent); return; } WebCore::PlatformMouseEvent wkEvent(event, globalPoint); if (type == wxEVT_LEFT_DOWN || type == wxEVT_MIDDLE_DOWN || type == wxEVT_RIGHT_DOWN || type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK) frame->eventHandler()->handleMousePressEvent(wkEvent); else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP) frame->eventHandler()->handleMouseReleaseEvent(wkEvent); else if (type == wxEVT_MOTION) frame->eventHandler()->mouseMoved(wkEvent);}void wxWebView::OnContextMenuEvents(wxContextMenuEvent& event){ m_impl->page->contextMenuController()->clearContextMenu(); wxPoint localEventPoint = ScreenToClient(event.GetPosition()); if (!m_mainFrame) return; WebCore::Frame* focusedFrame = m_mainFrame->GetFrame(); if (!focusedFrame->view()) return; //Create WebCore mouse event from the wxContextMenuEvent wxMouseEvent mouseEvent(wxEVT_RIGHT_DOWN); mouseEvent.m_x = localEventPoint.x; mouseEvent.m_y = localEventPoint.y; WebCore::PlatformMouseEvent wkEvent(mouseEvent, event.GetPosition()); bool handledEvent = focusedFrame->eventHandler()->sendContextMenuEvent(wkEvent); if (!handledEvent) return; WebCore::ContextMenu* coreMenu = m_impl->page->contextMenuController()->contextMenu(); if (!coreMenu) return; WebCore::PlatformMenuDescription menuWx = coreMenu->platformDescription(); if (!menuWx) return; PopupMenu(menuWx, localEventPoint);}void wxWebView::OnMenuSelectEvents(wxCommandEvent& event){ WebCore::ContextMenuItem* item = WebCore::ContextMenu::itemWithId (event.GetId()); if (!item) return; m_impl->page->contextMenuController()->contextMenuItemSelected(item); delete item;}bool wxWebView::CanCopy(){ if (m_mainFrame) return m_mainFrame->CanCopy(); return false;}void wxWebView::Copy(){ if (m_mainFrame) m_mainFrame->Copy();}bool wxWebView::CanCut(){ if (m_mainFrame) m_mainFrame->CanCut(); return false;}void wxWebView::Cut(){ if (m_mainFrame) m_mainFrame->Cut();}bool wxWebView::CanPaste(){ if (m_mainFrame) m_mainFrame->CanPaste(); return false;}void wxWebView::Paste(){ if (m_mainFrame) m_mainFrame->Paste();}void wxWebView::OnKeyEvents(wxKeyEvent& event){ WebCore::Frame* frame = 0; if (m_mainFrame) frame = m_mainFrame->GetFrame(); if (frame && frame->view()) { // WebCore doesn't handle these events itself, so we need to do // it and not send the event down or else CTRL+C will erase the text // and replace it with c. if (event.CmdDown() && event.GetEventType() == wxEVT_KEY_UP) { if (event.GetKeyCode() == static_cast<int>('C')) Copy(); else if (event.GetKeyCode() == static_cast<int>('X')) Cut(); else if (event.GetKeyCode() == static_cast<int>('V')) Paste(); else if (event.GetKeyCode() == static_cast<int>('Z')) { if (event.ShiftDown()) { if (m_mainFrame->CanRedo()) m_mainFrame->Redo(); } else { if (m_mainFrame->CanUndo()) m_mainFrame->Undo(); } } } else { WebCore::PlatformKeyboardEvent wkEvent(event); if (wkEvent.type() == WebCore::PlatformKeyboardEvent::Char && wkEvent.altKey()) frame->eventHandler()->handleAccessKey(wkEvent); else frame->eventHandler()->keyEvent(wkEvent); } } // make sure we get the character event. if (event.GetEventType() != wxEVT_CHAR) event.Skip();}void wxWebView::OnSetFocus(wxFocusEvent& event){ WebCore::Frame* frame = 0; if (m_mainFrame) frame = m_mainFrame->GetFrame(); if (frame) { m_impl->page->focusController()->setActive(true); frame->selection()->setFocused(true); } event.Skip();}void wxWebView::OnKillFocus(wxFocusEvent& event){ WebCore::Frame* frame = 0; if (m_mainFrame) frame = m_mainFrame->GetFrame(); if (frame) { m_impl->page->focusController()->setActive(false); frame->selection()->setFocused(false); } event.Skip();}void wxWebView::OnActivate(wxActivateEvent& event){ if (m_impl->page) m_impl->page->focusController()->setActive(event.GetActive()); event.Skip();}wxWebViewDOMElementInfo wxWebView::HitTest(const wxPoint& pos) const{ if (m_mainFrame) return m_mainFrame->HitTest(pos); return wxWebViewDOMElementInfo();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -