⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webeditorclient.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved. * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1.  Redistributions of source code must retain the above copyright *     notice, this list of conditions and the following disclaimer.  * 2.  Redistributions in binary form must reproduce the above copyright *     notice, this list of conditions and the following disclaimer in the *     documentation and/or other materials provided with the distribution.  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of *     its contributors may be used to endorse or promote products derived *     from this software without specific prior written permission.  * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#import "WebEditorClient.h"#import "DOMHTMLInputElementInternal.h"#import "DOMHTMLTextAreaElementInternal.h"#import "DOMRangeInternal.h"#import "WebArchive.h"#import "WebDataSourceInternal.h"#import "WebDocument.h"#import "WebEditingDelegatePrivate.h"#import "WebFormDelegate.h"#import "WebFrameInternal.h"#import "WebHTMLView.h"#import "WebHTMLViewInternal.h"#import "WebKitLogging.h"#import "WebKitVersionChecks.h"#import "WebLocalizableStrings.h"#import "WebNSURLExtras.h"#import "WebViewInternal.h"#import <WebCore/Document.h>#import <WebCore/EditAction.h>#import <WebCore/EditCommand.h>#import <WebCore/KeyboardEvent.h>#import <WebCore/LegacyWebArchive.h>#import <WebCore/PlatformKeyboardEvent.h>#import <WebCore/PlatformString.h>#import <WebCore/WebCoreObjCExtras.h>#import <runtime/InitializeThreading.h>#import <wtf/PassRefPtr.h>using namespace WebCore;using namespace WTF;EditorInsertAction core(WebViewInsertAction);WebViewInsertAction kit(EditorInsertAction);EditorInsertAction core(WebViewInsertAction kitAction){    return static_cast<EditorInsertAction>(kitAction);}WebViewInsertAction kit(EditorInsertAction coreAction){    return static_cast<WebViewInsertAction>(coreAction);}#ifdef BUILDING_ON_TIGER@interface NSSpellChecker (NotYetPublicMethods)- (void)learnWord:(NSString *)word;@end#endif@interface WebEditCommand : NSObject{    RefPtr<EditCommand> m_command;   }+ (WebEditCommand *)commandWithEditCommand:(PassRefPtr<EditCommand>)command;- (EditCommand *)command;@end@implementation WebEditCommand+ (void)initialize{    JSC::initializeThreading();#ifndef BUILDING_ON_TIGER    WebCoreObjCFinalizeOnMainThread(self);#endif}- (id)initWithEditCommand:(PassRefPtr<EditCommand>)command{    ASSERT(command);    [super init];    m_command = command;    return self;}- (void)dealloc{    if (WebCoreObjCScheduleDeallocateOnMainThread([WebEditCommand class], self))        return;    [super dealloc];}- (void)finalize{    ASSERT_MAIN_THREAD();    [super finalize];}+ (WebEditCommand *)commandWithEditCommand:(PassRefPtr<EditCommand>)command{    return [[[WebEditCommand alloc] initWithEditCommand:command] autorelease];}- (EditCommand *)command{    return m_command.get();}@end@interface WebEditorUndoTarget : NSObject{}- (void)undoEditing:(id)arg;- (void)redoEditing:(id)arg;@end@implementation WebEditorUndoTarget- (void)undoEditing:(id)arg{    ASSERT([arg isKindOfClass:[WebEditCommand class]]);    [arg command]->unapply();}- (void)redoEditing:(id)arg{    ASSERT([arg isKindOfClass:[WebEditCommand class]]);    [arg command]->reapply();}@endvoid WebEditorClient::pageDestroyed(){    delete this;}WebEditorClient::WebEditorClient(WebView *webView)    : m_webView(webView)    , m_undoTarget([[[WebEditorUndoTarget alloc] init] autorelease])    , m_haveUndoRedoOperations(false){}bool WebEditorClient::isContinuousSpellCheckingEnabled(){    return [m_webView isContinuousSpellCheckingEnabled];}void WebEditorClient::toggleContinuousSpellChecking(){    [m_webView toggleContinuousSpellChecking:nil];}bool WebEditorClient::isGrammarCheckingEnabled(){#ifdef BUILDING_ON_TIGER    return false;#else    return [m_webView isGrammarCheckingEnabled];#endif}void WebEditorClient::toggleGrammarChecking(){#ifndef BUILDING_ON_TIGER    [m_webView toggleGrammarChecking:nil];#endif}int WebEditorClient::spellCheckerDocumentTag(){    return [m_webView spellCheckerDocumentTag];}bool WebEditorClient::isEditable(){    return [m_webView isEditable];}bool WebEditorClient::shouldDeleteRange(Range* range){    return [[m_webView _editingDelegateForwarder] webView:m_webView        shouldDeleteDOMRange:kit(range)];}bool WebEditorClient::shouldShowDeleteInterface(HTMLElement* element){    return [[m_webView _editingDelegateForwarder] webView:m_webView        shouldShowDeleteInterfaceForElement:kit(element)];}bool WebEditorClient::smartInsertDeleteEnabled(){    return [m_webView smartInsertDeleteEnabled];}bool WebEditorClient::isSelectTrailingWhitespaceEnabled(){    return [m_webView isSelectTrailingWhitespaceEnabled];}bool WebEditorClient::shouldApplyStyle(CSSStyleDeclaration* style, Range* range){    return [[m_webView _editingDelegateForwarder] webView:m_webView        shouldApplyStyle:kit(style) toElementsInDOMRange:kit(range)];}bool WebEditorClient::shouldMoveRangeAfterDelete(Range* range, Range* rangeToBeReplaced){    return [[m_webView _editingDelegateForwarder] webView:m_webView        shouldMoveRangeAfterDelete:kit(range) replacingRange:kit(rangeToBeReplaced)];}bool WebEditorClient::shouldBeginEditing(Range* range){    return [[m_webView _editingDelegateForwarder] webView:m_webView        shouldBeginEditingInDOMRange:kit(range)];    return false;}bool WebEditorClient::shouldEndEditing(Range* range){    return [[m_webView _editingDelegateForwarder] webView:m_webView                             shouldEndEditingInDOMRange:kit(range)];}bool WebEditorClient::shouldInsertText(const String& text, Range* range, EditorInsertAction action){    WebView* webView = m_webView;    return [[webView _editingDelegateForwarder] webView:webView shouldInsertText:text replacingDOMRange:kit(range) givenAction:kit(action)];}bool WebEditorClient::shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity selectionAffinity, bool stillSelecting){    return [m_webView _shouldChangeSelectedDOMRange:kit(fromRange) toDOMRange:kit(toRange) affinity:kit(selectionAffinity) stillSelecting:stillSelecting];}void WebEditorClient::didBeginEditing(){    [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidBeginEditingNotification object:m_webView];}void WebEditorClient::respondToChangedContents(){    NSView <WebDocumentView> *view = [[[m_webView selectedFrame] frameView] documentView];    if ([view isKindOfClass:[WebHTMLView class]])        [(WebHTMLView *)view _updateFontPanel];    [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidChangeNotification object:m_webView];    }void WebEditorClient::respondToChangedSelection(){    NSView <WebDocumentView> *view = [[[m_webView selectedFrame] frameView] documentView];    if ([view isKindOfClass:[WebHTMLView class]])        [(WebHTMLView *)view _selectionChanged];    // FIXME: This quirk is needed due to <rdar://problem/5009625> - We can phase it out once Aperture can adopt the new behavior on their end    if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITHOUT_APERTURE_QUIRK) && [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.Aperture"])        return;    [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidChangeSelectionNotification object:m_webView];}void WebEditorClient::didEndEditing(){    [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidEndEditingNotification object:m_webView];}void WebEditorClient::didWriteSelectionToPasteboard(){    [[m_webView _editingDelegateForwarder] webView:m_webView didWriteSelectionToPasteboard:[NSPasteboard generalPasteboard]];}void WebEditorClient::didSetSelectionTypesForPasteboard(){    [[m_webView _editingDelegateForwarder] webView:m_webView didSetSelectionTypesForPasteboard:[NSPasteboard generalPasteboard]];}NSString* WebEditorClient::userVisibleString(NSURL *URL){    return [URL _web_userVisibleString];}#ifdef BUILDING_ON_TIGERNSArray* WebEditorClient::pasteboardTypesForSelection(Frame* selectedFrame){    WebFrame* frame = kit(selectedFrame);    return [[[frame frameView] documentView] pasteboardTypesForSelection];}#endifbool WebEditorClient::shouldInsertNode(Node *node, Range* replacingRange, EditorInsertAction givenAction){     return [[m_webView _editingDelegateForwarder] webView:m_webView shouldInsertNode:kit(node) replacingDOMRange:kit(replacingRange) givenAction:(WebViewInsertAction)givenAction];}static NSString* undoNameForEditAction(EditAction editAction){    switch (editAction) {        case EditActionUnspecified: return nil;        case EditActionSetColor: return UI_STRING_KEY("Set Color", "Set Color (Undo action name)", "Undo action name");        case EditActionSetBackgroundColor: return UI_STRING_KEY("Set Background Color", "Set Background Color (Undo action name)", "Undo action name");        case EditActionTurnOffKerning: return UI_STRING_KEY("Turn Off Kerning", "Turn Off Kerning (Undo action name)", "Undo action name");        case EditActionTightenKerning: return UI_STRING_KEY("Tighten Kerning", "Tighten Kerning (Undo action name)", "Undo action name");        case EditActionLoosenKerning: return UI_STRING_KEY("Loosen Kerning", "Loosen Kerning (Undo action name)", "Undo action name");        case EditActionUseStandardKerning: return UI_STRING_KEY("Use Standard Kerning", "Use Standard Kerning (Undo action name)", "Undo action name");        case EditActionTurnOffLigatures: return UI_STRING_KEY("Turn Off Ligatures", "Turn Off Ligatures (Undo action name)", "Undo action name");        case EditActionUseStandardLigatures: return UI_STRING_KEY("Use Standard Ligatures", "Use Standard Ligatures (Undo action name)", "Undo action name");        case EditActionUseAllLigatures: return UI_STRING_KEY("Use All Ligatures", "Use All Ligatures (Undo action name)", "Undo action name");        case EditActionRaiseBaseline: return UI_STRING_KEY("Raise Baseline", "Raise Baseline (Undo action name)", "Undo action name");        case EditActionLowerBaseline: return UI_STRING_KEY("Lower Baseline", "Lower Baseline (Undo action name)", "Undo action name");        case EditActionSetTraditionalCharacterShape: return UI_STRING_KEY("Set Traditional Character Shape", "Set Traditional Character Shape (Undo action name)", "Undo action name");        case EditActionSetFont: return UI_STRING_KEY("Set Font", "Set Font (Undo action name)", "Undo action name");        case EditActionChangeAttributes: return UI_STRING_KEY("Change Attributes", "Change Attributes (Undo action name)", "Undo action name");        case EditActionAlignLeft: return UI_STRING_KEY("Align Left", "Align Left (Undo action name)", "Undo action name");        case EditActionAlignRight: return UI_STRING_KEY("Align Right", "Align Right (Undo action name)", "Undo action name");        case EditActionCenter: return UI_STRING_KEY("Center", "Center (Undo action name)", "Undo action name");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -