void WebViewInputMethodFilter::cancelCurrentComposition() { Frame* frame = focusedOrMainFrame(); if (!frame || !frame->editor().canEdit()) return; frame->editor().cancelComposition(); }
bool FocusController::advanceFocusInDocumentOrder(FocusType type, bool initialFocus) { LocalFrame* frame = focusedOrMainFrame(); ASSERT(frame); Document* document = frame->document(); Node* currentNode = document->focusedElement(); document->updateLayout(); RefPtr<Node> node = findFocusableNodeAcrossFocusScope(type, FocusNavigationScope::focusNavigationScopeOf(currentNode ? currentNode : document), currentNode); if (!node) { // We didn't find a node to focus, so we should try to pass focus to Chrome. if (!initialFocus && m_page->canTakeFocus(type)) { document->setFocusedElement(nullptr); setFocusedFrame(nullptr); m_page->takeFocus(type); return true; } // Chrome doesn't want focus, so we should wrap focus. node = findFocusableNodeRecursively(type, FocusNavigationScope::focusNavigationScopeOf(m_page->mainFrame()->document()), 0); node = findFocusableNodeDecendingDownIntoFrameDocument(type, node.get()); if (!node) return false; } ASSERT(node); if (node == document->focusedElement()) // Focus wrapped around to the same node. return true; if (!node->isElementNode()) // FIXME: May need a way to focus a document here. return false; Element* element = toElement(node); // FIXME: It would be nice to just be able to call setFocusedElement(node) // here, but we can't do that because some elements (e.g. HTMLInputElement // and HTMLTextAreaElement) do extra work in their focus() methods. Document& newDocument = element->document(); if (&newDocument != document) { // Focus is going away from this document, so clear the focused node. document->setFocusedElement(nullptr); } setFocusedFrame(newDocument.frame()); element->focus(false, type); return true; }
void WebViewInputMethodFilter::setPreedit(String newPreedit, int cursorOffset) { Frame* frame = focusedOrMainFrame(); if (!frame || !frame->editor().canEdit()) return; // TODO: We should parse the PangoAttrList that we get from the IM context here. Vector<CompositionUnderline> underlines; underlines.append(CompositionUnderline(0, newPreedit.length(), Color(1, 1, 1), false)); frame->editor().setComposition(newPreedit, underlines, m_cursorOffset, m_cursorOffset); }
void WebViewInputMethodFilter::confirmCompositionText(String text) { Frame* frame = focusedOrMainFrame(); if (!frame || !frame->editor().canEdit()) return; if (text.isNull()) { confirmCurrentComposition(); return; } frame->editor().confirmComposition(m_confirmedComposition); }
bool WebViewInputMethodFilter::sendKeyEventWithCompositionResults(GdkEventKey* event, ResultsToSend resultsToSend, EventFakedForComposition) { PlatformKeyboardEvent platformEvent(event, CompositionResults(CompositionResults::WillSendCompositionResultsSoon)); if (!focusedOrMainFrame()->eventHandler().keyEvent(platformEvent)) return false; if (resultsToSend & Composition && !m_confirmedComposition.isNull()) confirmCompositionText(m_confirmedComposition); if (resultsToSend & Preedit && !m_preedit.isNull()) setPreedit(m_preedit, m_cursorOffset); return true; }
void FocusController::setActive(bool active) { if (m_isActive == active) return; m_isActive = active; if (FrameView* view = m_page->mainFrame()->view()) { if (!view->platformWidget()) { view->layoutIfNeededRecursive(); view->updateControlTints(); } } focusedOrMainFrame()->selection()->pageActivationChanged(); if (m_focusedFrame && isFocused()) dispatchEventsOnWindowAndFocusedNode(m_focusedFrame->document(), active); }
Node* FocusController::findNextFocusableNode(const FocusDirection direction, const IntRect* specificRect) { #if PLATFORM(WKC) CRASH_IF_STACK_OVERFLOW(WKC_STACK_MARGIN_DEFAULT); #endif Frame* frame = focusedOrMainFrame(); ASSERT(frame); Document* focusedDocument = frame->document(); if (!focusedDocument) return 0; focusedDocument->updateLayoutIgnorePendingStylesheets(); Node* focusedNode = focusedDocument->focusedNode(); if (!focusedNode) { if (direction == FocusDirectionUp) { return findLastFocusableNode(m_page->mainFrame(), specificRect); } else { return findFirstFocusableNode(m_page->mainFrame(), specificRect); } } frame = frame->tree()->top(); FocusCandidate focusCandidate; findFocusableNodeInDirection(frame->document()->firstChild(), focusedNode, direction, 0, focusCandidate, FocusCandidate(), specificRect); Node* node = focusCandidate.node; if (!node || !node->isElementNode()) { return 0; } if (hasOffscreenRect(node)) { return 0; } return node; }
bool WebViewInputMethodFilter::sendSimpleKeyEvent(GdkEventKey* event, WTF::String simpleString, EventFakedForComposition) { PlatformKeyboardEvent platformEvent(event, CompositionResults(simpleString)); return focusedOrMainFrame()->eventHandler().keyEvent(platformEvent); }
bool WebViewInputMethodFilter::canEdit() { Frame* frame = focusedOrMainFrame(); return frame && frame->editor().canEdit(); }