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

📄 webhtmlview.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. *           (C) 2006, 2007 Graham Dennis (graham.dennis@gmail.com) * * 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 "WebHTMLView.h"#import "DOMNodeInternal.h"#import "DOMRangeInternal.h"#import "WebArchive.h"#import "WebNetscapePluginView.h"#import "WebClipView.h"#import "WebDOMOperationsPrivate.h"#import "WebDataSourceInternal.h"#import "WebDefaultUIDelegate.h"#import "WebDocumentInternal.h"#import "WebDynamicScrollBarsView.h"#import "WebEditingDelegate.h"#import "WebElementDictionary.h"#import "WebFrameInternal.h"#import "WebFramePrivate.h"#import "WebFrameViewInternal.h"#import "WebHTMLRepresentationPrivate.h"#import "WebHTMLViewInternal.h"#import "WebKitLogging.h"#import "WebKitNSStringExtras.h"#import "WebKitVersionChecks.h"#import "WebLocalizableStrings.h"#import "WebNodeHighlight.h"#import "WebNSAttributedStringExtras.h"#import "WebNSEventExtras.h"#import "WebNSFileManagerExtras.h"#import "WebNSImageExtras.h"#import "WebNSObjectExtras.h"#import "WebNSPasteboardExtras.h"#import "WebNSPrintOperationExtras.h"#import "WebNSURLExtras.h"#import "WebNSViewExtras.h"#import "WebPluginController.h"#import "WebPreferences.h"#import "WebPreferencesPrivate.h"#import "WebResourcePrivate.h"#import "WebStringTruncator.h"#import "WebTypesInternal.h"#import "WebUIDelegatePrivate.h"#import "WebViewInternal.h"#import <AppKit/NSAccessibility.h>#import <ApplicationServices/ApplicationServices.h>#import <dlfcn.h>#import <WebCore/CachedImage.h>#import <WebCore/CachedResourceClient.h>#import <WebCore/ColorMac.h>#import <WebCore/ContextMenu.h>#import <WebCore/ContextMenuController.h>#import <WebCore/Document.h>#import <WebCore/DocumentFragment.h>#import <WebCore/Editor.h>#import <WebCore/EditorDeleteAction.h>#import <WebCore/Element.h>#import <WebCore/EventHandler.h>#import <WebCore/ExceptionHandlers.h>#import <WebCore/DragController.h>#import <WebCore/FloatRect.h>#import <WebCore/FocusController.h>#import <WebCore/Frame.h>#import <WebCore/FrameLoader.h>#import <WebCore/FrameView.h>#import <WebCore/HitTestResult.h>#import <WebCore/HTMLNames.h>#import <WebCore/Image.h>#import <WebCore/KeyboardEvent.h>#import <WebCore/LegacyWebArchive.h>#import <WebCore/MIMETypeRegistry.h>#import <WebCore/Page.h>#import <WebCore/PlatformKeyboardEvent.h>#import <WebCore/PlatformMouseEvent.h>#import <WebCore/Range.h>#import <WebCore/SelectionController.h>#import <WebCore/SharedBuffer.h>#import <WebCore/SimpleFontData.h>#import <WebCore/Text.h>#import <WebCore/WebCoreObjCExtras.h>#import <WebCore/WebCoreTextRenderer.h>#import <WebCore/markup.h>#import <WebKit/DOM.h>#import <WebKit/DOMExtensions.h>#import <WebKit/DOMPrivate.h>#import <WebKitSystemInterface.h>#import <limits>#import <runtime/InitializeThreading.h>#if USE(ACCELERATED_COMPOSITING)#import <QuartzCore/QuartzCore.h>#endifusing namespace WebCore;using namespace HTMLNames;using namespace WTF;@interface NSWindow (BorderViewAccess)- (NSView*)_web_borderView;@end@implementation NSWindow (BorderViewAccess)- (NSView*)_web_borderView{    return _borderView;}@endstatic IMP oldSetCursorIMP = NULL;#ifdef BUILDING_ON_TIGERstatic IMP oldResetCursorRectsIMP = NULL;static BOOL canSetCursor = YES;static void resetCursorRects(NSWindow* self, SEL cmd){    NSPoint point = [self mouseLocationOutsideOfEventStream];    NSView* view = [[self _web_borderView] hitTest:point];    if ([view isKindOfClass:[WebHTMLView class]]) {        WebHTMLView *htmlView = (WebHTMLView*)view;        NSPoint localPoint = [htmlView convertPoint:point fromView:nil];        NSDictionary *dict = [htmlView elementAtPoint:localPoint allowShadowContent:NO];        DOMElement *element = [dict objectForKey:WebElementDOMNodeKey];        if (![element isKindOfClass:[DOMHTMLAppletElement class]] && ![element isKindOfClass:[DOMHTMLObjectElement class]] &&            ![element isKindOfClass:[DOMHTMLEmbedElement class]])            canSetCursor = NO;    }    oldResetCursorRectsIMP(self, cmd);    canSetCursor = YES;}static void setCursor(NSCursor* self, SEL cmd){    if (canSetCursor)        oldSetCursorIMP(self, cmd);}#elsestatic void setCursor(NSWindow* self, SEL cmd, NSPoint point){    NSView* view = [[self _web_borderView] hitTest:point];    if ([view isKindOfClass:[WebHTMLView class]]) {        WebHTMLView *htmlView = (WebHTMLView*)view;        NSPoint localPoint = [htmlView convertPoint:point fromView:nil];        NSDictionary *dict = [htmlView elementAtPoint:localPoint allowShadowContent:NO];        DOMElement *element = [dict objectForKey:WebElementDOMNodeKey];        if (![element isKindOfClass:[DOMHTMLAppletElement class]] && ![element isKindOfClass:[DOMHTMLObjectElement class]] &&            ![element isKindOfClass:[DOMHTMLEmbedElement class]])            return;    }    oldSetCursorIMP(self, cmd, point);}#endif#if USE(ACCELERATED_COMPOSITING)@interface WebLayerHostingView : NSView@end@implementation WebLayerHostingView// Empty NSViews intercept rightMouseDown: to do context menu handling, but we need the WebLayerHostingView to// let right mouse clicks through.- (void)rightMouseDown:(NSEvent *)theEvent{    [[self nextResponder] performSelector:_cmd withObject:theEvent];}@end#endif // USE(ACCELERATED_COMPOSITING)extern "C" {// Need to declare these attribute names because AppKit exports them but does not make them available in API or SPI headers.extern NSString *NSMarkedClauseSegmentAttributeName;extern NSString *NSTextInputReplacementRangeAttributeName;}@interface NSView (WebNSViewDetails)- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView;- (void)_recursiveDisplayAllDirtyWithLockFocus:(BOOL)needsLockFocus visRect:(NSRect)visRect;- (void)_recursive:(BOOL)recurse displayRectIgnoringOpacity:(NSRect)displayRect inContext:(NSGraphicsContext *)context topView:(BOOL)topView;- (NSRect)_dirtyRect;- (void)_setDrawsOwnDescendants:(BOOL)drawsOwnDescendants;- (void)_propagateDirtyRectsToOpaqueAncestors;- (void)_windowChangedKeyState;@end@interface NSApplication (WebNSApplicationDetails)- (void)speakString:(NSString *)string;@end@interface NSWindow (WebNSWindowDetails)- (id)_newFirstResponderAfterResigning;- (void)_setForceActiveControls:(BOOL)flag;@end@interface NSAttributedString (WebNSAttributedStringDetails)- (id)_initWithDOMRange:(DOMRange *)range;- (DOMDocumentFragment *)_documentFromRange:(NSRange)range document:(DOMDocument *)document documentAttributes:(NSDictionary *)dict subresources:(NSArray **)subresources;@end@interface NSSpellChecker (WebNSSpellCheckerDetails)- (void)learnWord:(NSString *)word;@end// By imaging to a width a little wider than the available pixels,// thin pages will be scaled down a little, matching the way they// print in IE and Camino. This lets them use fewer sheets than they// would otherwise, which is presumably why other browsers do this.// Wide pages will be scaled down more than this.#define PrintingMinimumShrinkFactor     1.25f// This number determines how small we are willing to reduce the page content// in order to accommodate the widest line. If the page would have to be// reduced smaller to make the widest line fit, we just clip instead (this// behavior matches MacIE and Mozilla, at least)#define PrintingMaximumShrinkFactor     2.0f// This number determines how short the last printed page of a multi-page print session// can be before we try to shrink the scale in order to reduce the number of pages, and// thus eliminate the orphan.#define LastPrintedPageOrphanRatio      0.1f// This number determines the amount the scale factor is adjusted to try to eliminate orphans.// It has no direct mathematical relationship to LastPrintedPageOrphanRatio, due to variable// numbers of pages, logic to avoid breaking elements, and CSS-supplied hard page breaks.#define PrintingOrphanShrinkAdjustment  1.1f#define AUTOSCROLL_INTERVAL             0.1f#define DRAG_LABEL_BORDER_X             4.0f//Keep border_y in synch with DragController::LinkDragBorderInset#define DRAG_LABEL_BORDER_Y             2.0f#define DRAG_LABEL_RADIUS               5.0f#define DRAG_LABEL_BORDER_Y_OFFSET              2.0f#define MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP        120.0f#define MAX_DRAG_LABEL_WIDTH                    320.0f#define DRAG_LINK_LABEL_FONT_SIZE   11.0f#define DRAG_LINK_URL_FONT_SIZE   10.0f// Any non-zero value will do, but using something recognizable might help us debug some day.#define TRACKING_RECT_TAG 0xBADFACE// FIXME: This constant is copied from AppKit's _NXSmartPaste constant.#define WebSmartPastePboardType @"NeXT smart paste pasteboard type"#define STANDARD_WEIGHT 5#define MIN_BOLD_WEIGHT 7#define STANDARD_BOLD_WEIGHT 9// Fake URL scheme.#define WebDataProtocolScheme @"webkit-fake-url"// <rdar://problem/4985524> References to WebCoreScrollView as a subview of a WebHTMLView may be present// in some NIB files, so NSUnarchiver must be still able to look up this now-unused class.@interface WebCoreScrollView : NSScrollView@end@implementation WebCoreScrollView@end// if YES, do the standard NSView hit test (which can't give the right result when HTML overlaps a view)static BOOL forceNSViewHitTest;// if YES, do the "top WebHTMLView" hit test (which we'd like to do all the time but can't because of Java requirements [see bug 4349721])static BOOL forceWebHTMLViewHitTest;static WebHTMLView *lastHitView;// We need this to be able to safely reference the CachedImage for the promised drag datastatic CachedResourceClient* promisedDataClient(){    static CachedResourceClient* staticCachedResourceClient = new CachedResourceClient;    return staticCachedResourceClient;}@interface WebHTMLView (WebHTMLViewFileInternal)- (BOOL)_imageExistsAtPaths:(NSArray *)paths;- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard inContext:(DOMRange *)context allowPlainText:(BOOL)allowPlainText;- (NSString *)_plainTextFromPasteboard:(NSPasteboard *)pasteboard;- (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;- (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard;- (void)_removeMouseMovedObserverUnconditionally;- (void)_removeSuperviewObservers;- (void)_removeWindowObservers;- (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;- (BOOL)_shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;- (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action;- (float)_calculatePrintHeight;- (DOMRange *)_selectedRange;- (BOOL)_shouldDeleteRange:(DOMRange *)range;- (NSView *)_hitViewForEvent:(NSEvent *)event;- (void)_writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard cachedAttributedString:(NSAttributedString *)attributedString;- (DOMRange *)_documentRange;- (void)_setMouseDownEvent:(NSEvent *)event;- (WebHTMLView *)_topHTMLView;- (BOOL)_isTopHTMLView;- (void)_web_setPrintingModeRecursive;- (void)_web_setPrintingModeRecursiveAndAdjustViewSize;- (void)_web_clearPrintingModeRecursive;@end@interface WebHTMLView (WebForwardDeclaration) // FIXME: Put this in a normal category and stop doing the forward declaration trick.- (void)_setPrinting:(BOOL)printing minimumPageWidth:(float)minPageWidth maximumPageWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize;@end@class NSTextInputContext;@interface NSResponder (AppKitDetails)- (NSTextInputContext *)inputContext;@end@interface NSObject (NSTextInputContextDetails)- (BOOL)wantsToHandleMouseEvents;- (BOOL)handleMouseEvent:(NSEvent *)event;@end@interface WebHTMLView (WebNSTextInputSupport) <NSTextInput>- (void)_updateSelectionForInputManager;@end@interface WebHTMLView (WebEditingStyleSupport)

⌨️ 快捷键说明

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