📄 editorclientgtk.cpp
字号:
/* * Copyright (C) 2007 Alp Toker <alp@atoker.com> * Copyright (C) 2008 Nuanti Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */#include "config.h"#include "EditorClientGtk.h"#include "CString.h"#include "EditCommand.h"#include "Editor.h"#include "FocusController.h"#include "Frame.h"#include "KeyboardCodes.h"#include "KeyboardEvent.h"#include "NotImplemented.h"#include "Page.h"#include "PlatformKeyboardEvent.h"#include "markup.h"#include "webkitprivate.h"using namespace WebCore;namespace WebKit {static void imContextCommitted(GtkIMContext* context, const gchar* str, EditorClient* client){ Frame* targetFrame = core(client->m_webView)->focusController()->focusedOrMainFrame(); if (!targetFrame || !targetFrame->editor()->canEdit()) return; Editor* editor = targetFrame->editor(); String commitString = String::fromUTF8(str); editor->confirmComposition(commitString);}static void imContextPreeditChanged(GtkIMContext* context, EditorClient* client){ Frame* frame = core(client->m_webView)->focusController()->focusedOrMainFrame(); Editor* editor = frame->editor(); gchar* preedit = NULL; gint cursorPos = 0; // We ignore the provided PangoAttrList for now. gtk_im_context_get_preedit_string(context, &preedit, NULL, &cursorPos); String preeditString = String::fromUTF8(preedit); g_free(preedit); // setComposition() will replace the user selection if passed an empty // preedit. We don't want this to happen. if (preeditString.isEmpty() && !editor->hasComposition()) return; Vector<CompositionUnderline> underlines; underlines.append(CompositionUnderline(0, preeditString.length(), Color(0, 0, 0), false)); editor->setComposition(preeditString, underlines, cursorPos, 0);}void EditorClient::setInputMethodState(bool active){ WebKitWebViewPrivate* priv = m_webView->priv; if (active) gtk_im_context_focus_in(priv->imContext); else gtk_im_context_focus_out(priv->imContext);#ifdef MAEMO_CHANGES if (active) hildon_gtk_im_context_show(priv->imContext); else hildon_gtk_im_context_hide(priv->imContext);#endif}bool EditorClient::shouldDeleteRange(Range*){ notImplemented(); return true;}bool EditorClient::shouldShowDeleteInterface(HTMLElement*){ return false;}bool EditorClient::isContinuousSpellCheckingEnabled(){ notImplemented(); return false;}bool EditorClient::isGrammarCheckingEnabled(){ notImplemented(); return false;}int EditorClient::spellCheckerDocumentTag(){ notImplemented(); return 0;}bool EditorClient::shouldBeginEditing(WebCore::Range*){ notImplemented(); return true;}bool EditorClient::shouldEndEditing(WebCore::Range*){ notImplemented(); return true;}bool EditorClient::shouldInsertText(const String&, Range*, EditorInsertAction){ notImplemented(); return true;}bool EditorClient::shouldChangeSelectedRange(Range*, Range*, EAffinity, bool){ notImplemented(); return true;}bool EditorClient::shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*){ notImplemented(); return true;}bool EditorClient::shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*){ notImplemented(); return true;}void EditorClient::didBeginEditing(){ notImplemented();}void EditorClient::respondToChangedContents(){ notImplemented();}#if GTK_CHECK_VERSION(2,10,0)static void clipboard_get_contents_cb(GtkClipboard* clipboard, GtkSelectionData* selection_data, guint info, gpointer data){ WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data); Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); PassRefPtr<Range> selectedRange = frame->selection()->toNormalizedRange(); if (static_cast<gint>(info) == WEBKIT_WEB_VIEW_TARGET_INFO_HTML) { String markup = createMarkup(selectedRange.get(), 0, AnnotateForInterchange); gtk_selection_data_set(selection_data, selection_data->target, 8, reinterpret_cast<const guchar*>(markup.utf8().data()), markup.utf8().length()); } else { String text = selectedRange->text(); gtk_selection_data_set_text(selection_data, text.utf8().data(), text.utf8().length()); }}static void clipboard_clear_contents_cb(GtkClipboard* clipboard, gpointer data){ WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data); Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); // Collapse the selection without clearing it frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity());}#endifvoid EditorClient::respondToChangedSelection(){ WebKitWebViewPrivate* priv = m_webView->priv; Frame* targetFrame = core(m_webView)->focusController()->focusedOrMainFrame(); if (!targetFrame) return; if (targetFrame->editor()->ignoreCompositionSelectionChange()) return;#if GTK_CHECK_VERSION(2,10,0) GtkClipboard* clipboard = gtk_widget_get_clipboard(GTK_WIDGET(m_webView), GDK_SELECTION_PRIMARY); if (targetFrame->selection()->isRange()) { GtkTargetList* targetList = webkit_web_view_get_copy_target_list(m_webView); gint targetCount; GtkTargetEntry* targets = gtk_target_table_new_from_list(targetList, &targetCount); gtk_clipboard_set_with_owner(clipboard, targets, targetCount, clipboard_get_contents_cb, clipboard_clear_contents_cb, G_OBJECT(m_webView)); gtk_target_table_free(targets, targetCount); } else if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(m_webView)) gtk_clipboard_clear(clipboard);#endif if (!targetFrame->editor()->hasComposition()) return; unsigned start; unsigned end; if (!targetFrame->editor()->getCompositionSelection(start, end)) { // gtk_im_context_reset() clears the composition for us. gtk_im_context_reset(priv->imContext); targetFrame->editor()->confirmCompositionWithoutDisturbingSelection(); }}void EditorClient::didEndEditing(){ notImplemented();}void EditorClient::didWriteSelectionToPasteboard(){ notImplemented();}void EditorClient::didSetSelectionTypesForPasteboard(){ notImplemented();}bool EditorClient::isEditable(){ return webkit_web_view_get_editable(m_webView);}void EditorClient::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand>){ notImplemented();}void EditorClient::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>){ notImplemented();}void EditorClient::clearUndoRedoOperations(){ notImplemented();}bool EditorClient::canUndo() const{ notImplemented(); return false;}bool EditorClient::canRedo() const{ notImplemented(); return false;}void EditorClient::undo(){ notImplemented();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -