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::OnMouseEvents(wxMouseEvent& event) { event.Skip(); if (!m_impl->page) 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) { if (m_mouseWheelZooms && event.ControlDown() && !event.AltDown() && !event.ShiftDown()) { if (event.GetWheelRotation() < 0) DecreaseTextSize(); else if (event.GetWheelRotation() > 0) IncreaseTextSize(); } else { WebCore::PlatformWheelEvent wkEvent(event, globalPoint); frame->eventHandler()->handleWheelEvent(wkEvent); } return; } int clickCount = event.ButtonDClick() ? 2 : 1; if (clickCount == 1 && m_impl->tripleClickTimer.IsRunning()) { wxPoint diff(event.GetPosition() - m_impl->tripleClickPos); if (abs(diff.x) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_X) && abs(diff.y) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_Y)) { clickCount = 3; } } else if (clickCount == 2) { m_impl->tripleClickTimer.Start(getDoubleClickTime(), false); m_impl->tripleClickPos = event.GetPosition(); } WebCore::PlatformMouseEvent wkEvent(event, globalPoint, clickCount); 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); if (!HasCapture()) CaptureMouse(); } else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP) { frame->eventHandler()->handleMouseReleaseEvent(wkEvent); while (HasCapture()) ReleaseMouse(); } else if (type == wxEVT_MOTION || type == wxEVT_ENTER_WINDOW || type == wxEVT_LEAVE_WINDOW) frame->eventHandler()->mouseMoved(wkEvent); }
void BWebPage::handleKeyEvent(BMessage* message) { WebCore::Frame* frame = fPage->focusController()->focusedOrMainFrame(); if (!frame->view() || !frame->document()) return; PlatformKeyboardEvent event(message); // Try to let WebCore handle this event if (!frame->eventHandler()->keyEvent(event) && message->what == B_KEY_DOWN) { // Handle keyboard scrolling (probably should be extracted to a method.) ScrollDirection direction; ScrollGranularity granularity; BString bytes = message->FindString("bytes"); switch (bytes.ByteAt(0)) { case B_UP_ARROW: granularity = ScrollByLine; direction = ScrollUp; break; case B_DOWN_ARROW: granularity = ScrollByLine; direction = ScrollDown; break; case B_LEFT_ARROW: granularity = ScrollByLine; direction = ScrollLeft; break; case B_RIGHT_ARROW: granularity = ScrollByLine; direction = ScrollRight; break; case B_HOME: granularity = ScrollByDocument; direction = ScrollUp; break; case B_END: granularity = ScrollByDocument; direction = ScrollDown; break; case B_PAGE_UP: granularity = ScrollByPage; direction = ScrollUp; break; case B_PAGE_DOWN: granularity = ScrollByPage; direction = ScrollDown; break; default: return; } frame->eventHandler()->scrollRecursively(direction, granularity); } }
void BWebPage::handleMouseEvent(const BMessage* message) { WebCore::Frame* frame = fMainFrame->Frame(); if (!frame->view() || !frame->document()) return; PlatformMouseEvent event(message); switch (message->what) { case B_MOUSE_DOWN: // Handle context menus, if necessary. if (event.button() == RightButton) { fPage->contextMenuController()->clearContextMenu(); WebCore::Frame* focusedFrame = fPage->focusController()->focusedOrMainFrame(); focusedFrame->eventHandler()->sendContextMenuEvent(event); // If the web page implements it's own context menu handling, then // the contextMenu() pointer will be zero. In this case, we should // also swallow the event. ContextMenu* contextMenu = fPage->contextMenuController()->contextMenu(); if (contextMenu) { BMenu* platformMenu = contextMenu->releasePlatformDescription(); if (platformMenu) { // Need to convert the BMenu into BPopUpMenu. BPopUpMenu* popupMenu = new BPopUpMenu("context menu"); for (int32 i = platformMenu->CountItems() - 1; i >= 0; i--) { BMenuItem* item = platformMenu->RemoveItem(i); popupMenu->AddItem(item, 0); } BPoint screenLocation(event.globalPosition().x() + 2, event.globalPosition().y() + 2); popupMenu->Go(screenLocation, true, true, true); delete platformMenu; } } break; } // Handle regular mouse events. frame->eventHandler()->handleMousePressEvent(event); break; case B_MOUSE_UP: frame->eventHandler()->handleMouseReleaseEvent(event); break; case B_MOUSE_MOVED: default: frame->eventHandler()->mouseMoved(event); break; } }
static gboolean webkit_web_view_motion_event(GtkWidget* widget, GdkEventMotion* event) { //WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); WebCore::Frame* frame = core(webView_s->mainFrame()); return frame->eventHandler()->mouseMoved(PlatformMouseEvent(event)); }
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::OnContextMenuEvents(wxContextMenuEvent& event) { Connect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(wxWebView::OnMenuSelectEvents), NULL, this); m_impl->page->contextMenuController()->clearContextMenu(); wxPoint localEventPoint = ScreenToClient(event.GetPosition()); if (!m_impl->page) return; WebCore::Frame* focusedFrame = m_impl->page->focusController()->focusedOrMainFrame(); 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(), 1); 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); Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(wxWebView::OnMenuSelectEvents), NULL, this); }
static gboolean webkit_web_view_scroll_event(GtkWidget* widget, GdkEventScroll* event) { //WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); WebCore::Frame* frame = core(webView_s->mainFrame()); PlatformWheelEvent wheelEvent(event); return frame->eventHandler()->handleWheelEvent(wheelEvent); }
void BWebPage::handleMouseWheelChanged(BMessage* message) { WebCore::Frame* frame = fMainFrame->Frame(); if (!frame->view() || !frame->document()) return; PlatformWheelEvent event(message); frame->eventHandler()->handleWheelEvent(event); }
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::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(); }
static gboolean webkit_web_view_key_release_event(GtkWidget* widget, GdkEventKey* event) { //WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); WebCore::Frame* frame = core(webView_s)->focusController()->focusedOrMainFrame(); PlatformKeyboardEvent keyboardEvent(event); if (frame->eventHandler()->keyEvent(keyboardEvent)) return TRUE; /* Chain up to our parent class for binding activation */ return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_release_event(widget, event); }
static gboolean webkit_web_view_button_press_event(GtkWidget* widget, GdkEventButton* event) { //WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); WebCore::Frame* frame = core(webView_s->mainFrame()); // FIXME: need to keep track of subframe focus for key events gtk_widget_grab_focus(widget); if (event->button == 3) return false;//webkit_web_view_forward_context_menu_event(webView, PlatformMouseEvent(event)); return frame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(event)); }
static gboolean webkit_web_view_button_release_event(GtkWidget* widget, GdkEventButton* event) { //WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); ////WebKitWebViewPrivate* priv = webView->priv; WebCore::Frame* focusedFrame = core(webView_s)->focusController()->focusedFrame(); if (focusedFrame && focusedFrame->editor()->canEdit()) { GdkWindow* window = gtk_widget_get_parent_window(widget); gtk_im_context_set_client_window(imContext, window); #ifdef MAEMO_CHANGES hildon_gtk_im_context_filter_event(imContext, (GdkEvent*)event); hildon_gtk_im_context_show(imContext); #endif } return focusedFrame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event)); }
void wxWebView::OnMouseEvents(wxMouseEvent& event) { event.Skip(); if (!m_impl->page) 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) { if (m_mouseWheelZooms && event.ControlDown() && !event.AltDown() && !event.ShiftDown()) { if (event.GetWheelRotation() < 0) DecreaseTextSize(); else if (event.GetWheelRotation() > 0) IncreaseTextSize(); } else { WebCore::PlatformWheelEvent wkEvent(event, globalPoint); frame->eventHandler()->handleWheelEvent(wkEvent); } return; } // If an event, such as a right-click event, leads to a focus change (e.g. it // raises a dialog), WebKit never gets the mouse up event and never relinquishes // mouse capture. This leads to WebKit handling mouse events, such as modifying // the selection, while other controls or top level windows have the focus. // I'm not sure if this is the right place to handle this, but I can't seem to // find a precedent on how to handle this in other ports. if (wxWindow::FindFocus() != this) { while (HasCapture()) ReleaseMouse(); frame->eventHandler()->setMousePressed(false); return; } int clickCount = event.ButtonDClick() ? 2 : 1; if (clickCount == 1 && m_impl->tripleClickTimer.IsRunning()) { wxPoint diff(event.GetPosition() - m_impl->tripleClickPos); if (abs(diff.x) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_X) && abs(diff.y) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_Y)) { clickCount = 3; } } else if (clickCount == 2) { m_impl->tripleClickTimer.Start(getDoubleClickTime(), false); m_impl->tripleClickPos = event.GetPosition(); } WebCore::PlatformMouseEvent wkEvent(event, globalPoint, clickCount); 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); if (!HasCapture()) CaptureMouse(); } else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP) { frame->eventHandler()->handleMouseReleaseEvent(wkEvent); while (HasCapture()) ReleaseMouse(); } else if (type == wxEVT_MOTION || type == wxEVT_ENTER_WINDOW || type == wxEVT_LEAVE_WINDOW) frame->eventHandler()->mouseMoved(wkEvent); }
void wxWebView::OnKeyEvents(wxKeyEvent& event) { WebCore::Frame* frame = 0; if (m_impl->page) frame = m_impl->page->focusController()->focusedOrMainFrame(); if (!(frame && frame->view())) return; if (event.GetKeyCode() == WXK_CAPITAL) frame->eventHandler()->capsLockStateMayHaveChanged(); WebCore::PlatformKeyboardEvent wkEvent(event); if (frame->eventHandler()->keyEvent(wkEvent)) return; //Some things WebKit won't do for us... Copy/Cut/Paste and KB scrolling if (event.GetEventType() == wxEVT_KEY_DOWN) { switch (event.GetKeyCode()) { case 67: //"C" if (CanCopy() && event.GetModifiers() == wxMOD_CMD) { Copy(); return; } break; case 86: //"V" if (CanPaste() && event.GetModifiers() == wxMOD_CMD) { Paste(); return; } break; case 88: //"X" if (CanCut() && event.GetModifiers() == wxMOD_CMD) { Cut(); return; } break; case WXK_INSERT: if (CanCopy() && event.GetModifiers() == wxMOD_CMD) { Copy(); return; } if (CanPaste() && event.GetModifiers() == wxMOD_SHIFT) { Paste(); return; } return; //Insert shall not become a char case WXK_DELETE: if (CanCut() && event.GetModifiers() == wxMOD_SHIFT) { Cut(); return; } break; case WXK_LEFT: case WXK_NUMPAD_LEFT: frame->view()->scrollBy(WebCore::IntSize(-WebCore::Scrollbar::pixelsPerLineStep(), 0)); return; case WXK_UP: case WXK_NUMPAD_UP: frame->view()->scrollBy(WebCore::IntSize(0, -WebCore::Scrollbar::pixelsPerLineStep())); return; case WXK_RIGHT: case WXK_NUMPAD_RIGHT: frame->view()->scrollBy(WebCore::IntSize(WebCore::Scrollbar::pixelsPerLineStep(), 0)); return; case WXK_DOWN: case WXK_NUMPAD_DOWN: frame->view()->scrollBy(WebCore::IntSize(0, WebCore::Scrollbar::pixelsPerLineStep())); return; case WXK_END: case WXK_NUMPAD_END: frame->view()->setScrollPosition(WebCore::IntPoint(frame->view()->scrollX(), frame->view()->maximumScrollPosition().y())); return; case WXK_HOME: case WXK_NUMPAD_HOME: frame->view()->setScrollPosition(WebCore::IntPoint(frame->view()->scrollX(), 0)); return; case WXK_PAGEUP: case WXK_NUMPAD_PAGEUP: frame->view()->scrollBy(WebCore::IntSize(0, -frame->view()->visibleHeight() * WebCore::Scrollbar::minFractionToStepWhenPaging())); return; case WXK_PAGEDOWN: case WXK_NUMPAD_PAGEDOWN: frame->view()->scrollBy(WebCore::IntSize(0, frame->view()->visibleHeight() * WebCore::Scrollbar::minFractionToStepWhenPaging())); return; //These we don't want turning into char events, stuff 'em case WXK_ESCAPE: case WXK_LBUTTON: case WXK_RBUTTON: case WXK_CANCEL: case WXK_MENU: case WXK_MBUTTON: case WXK_CLEAR: case WXK_PAUSE: case WXK_SELECT: case WXK_PRINT: case WXK_EXECUTE: case WXK_SNAPSHOT: case WXK_HELP: case WXK_F1: case WXK_F2: case WXK_F3: case WXK_F4: case WXK_F5: case WXK_F6: case WXK_F7: case WXK_F8: case WXK_F9: case WXK_F10: case WXK_F11: case WXK_F12: case WXK_F13: case WXK_F14: case WXK_F15: case WXK_F16: case WXK_F17: case WXK_F18: case WXK_F19: case WXK_F20: case WXK_F21: case WXK_F22: case WXK_F23: case WXK_F24: case WXK_NUMPAD_F1: case WXK_NUMPAD_F2: case WXK_NUMPAD_F3: case WXK_NUMPAD_F4: //When numlock is off Numpad 5 becomes BEGIN, or HOME on Char case WXK_NUMPAD_BEGIN: case WXK_NUMPAD_INSERT: return; } } event.Skip(); }
static gboolean webkit_web_view_key_press_event(GtkWidget* widget, GdkEventKey* event) { // WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); WebCore::Frame* frame = core(webView_s)->focusController()->focusedOrMainFrame(); PlatformKeyboardEvent keyboardEvent(event); if (frame->eventHandler()->keyEvent(keyboardEvent)) return TRUE; FrameView* view = frame->view(); SelectionController::EAlteration alteration; if (event->state & GDK_SHIFT_MASK) alteration = SelectionController::EXTEND; else alteration = SelectionController::MOVE; // TODO: We probably want to use GTK+ key bindings here and perhaps take an // approach more like the Win and Mac ports for key handling. switch (event->keyval) { case GDK_Down: view->scrollBy(IntSize(0, (int)Scrollbar::pixelsPerLineStep())); return TRUE; case GDK_Up: view->scrollBy(IntSize(0, (int)-Scrollbar::pixelsPerLineStep())); return TRUE; case GDK_Right: view->scrollBy(IntSize((int)Scrollbar::pixelsPerLineStep(), 0)); return TRUE; case GDK_Left: view->scrollBy(IntSize((int)-Scrollbar::pixelsPerLineStep(), 0)); return TRUE; case GDK_Home: frame->selection()->modify(alteration, SelectionController::BACKWARD, DocumentBoundary, true); return TRUE; case GDK_End: frame->selection()->modify(alteration, SelectionController::FORWARD, DocumentBoundary, true); return TRUE; case GDK_Escape: gtk_main_quit(); return true; case GDK_F1: webView_s->goBack(); return true; case GDK_F2: webView_s->goForward(); return true; case GDK_F3: // We ignore the return value as we are not interested // in whether the zoom occurred. webView_s->zoomPageIn(); return true; case GDK_F4: // Same comment as above. webView_s->zoomPageOut(); return true; } /* Chain up to our parent class for binding activation */ return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_press_event(widget, event); }