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

📄 webhtmlview.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
    _private->enumeratingSubviews = NO;#endif}@end@implementation WebHTMLView (WebPrivate)+ (NSArray *)supportedMIMETypes{    return [WebHTMLRepresentation supportedMIMETypes];}+ (NSArray *)supportedImageMIMETypes{    return [WebHTMLRepresentation supportedImageMIMETypes];}+ (NSArray *)supportedNonImageMIMETypes{    return [WebHTMLRepresentation supportedNonImageMIMETypes];}+ (NSArray *)unsupportedTextMIMETypes{    return [NSArray arrayWithObjects:        @"text/calendar",       // iCal        @"text/x-calendar",        @"text/x-vcalendar",        @"text/vcalendar",        @"text/vcard",          // vCard        @"text/x-vcard",        @"text/directory",        @"text/ldif",           // Netscape Address Book        @"text/qif",            // Quicken        @"text/x-qif",        @"text/x-csv",          // CSV (for Address Book and Microsoft Outlook)        @"text/x-vcf",          // vCard type used in Sun affinity app        @"text/rtf",            // Rich Text Format        nil];}+ (void)_postFlagsChangedEvent:(NSEvent *)flagsChangedEvent{    // This is a workaround for: <rdar://problem/2981619> NSResponder_Private should include notification for FlagsChanged    NSEvent *fakeEvent = [NSEvent mouseEventWithType:NSMouseMoved        location:[[flagsChangedEvent window] convertScreenToBase:[NSEvent mouseLocation]]        modifierFlags:[flagsChangedEvent modifierFlags]        timestamp:[flagsChangedEvent timestamp]        windowNumber:[flagsChangedEvent windowNumber]        context:[flagsChangedEvent context]        eventNumber:0 clickCount:0 pressure:0];    // Pretend it's a mouse move.    [[NSNotificationCenter defaultCenter]        postNotificationName:WKMouseMovedNotification() object:self        userInfo:[NSDictionary dictionaryWithObject:fakeEvent forKey:@"NSEvent"]];}- (id)_bridge{    // This method exists to maintain compatibility with Leopard's Dictionary.app, since it    // calls _bridge to get access to convertNSRangeToDOMRange: and convertDOMRangeToNSRange:.    // Return the WebFrame, which implements the compatibility methods. <rdar://problem/6002160>    return [self _frame];}- (void)_updateMouseoverWithFakeEvent{    [self _cancelUpdateMouseoverTimer];        NSEvent *fakeEvent = [NSEvent mouseEventWithType:NSMouseMoved        location:[[self window] convertScreenToBase:[NSEvent mouseLocation]]        modifierFlags:[[NSApp currentEvent] modifierFlags]        timestamp:[NSDate timeIntervalSinceReferenceDate]        windowNumber:[[self window] windowNumber]        context:[[NSApp currentEvent] context]        eventNumber:0 clickCount:0 pressure:0];        [self _updateMouseoverWithEvent:fakeEvent];}static void _updateMouseoverTimerCallback(CFRunLoopTimerRef timer, void *info){    WebHTMLView *view = (WebHTMLView *)info;        [view _updateMouseoverWithFakeEvent];}- (void)_frameOrBoundsChanged{    if (!NSEqualSizes(_private->lastLayoutSize, [(NSClipView *)[self superview] documentVisibleRect].size)) {        [self setNeedsLayout:YES];        [self setNeedsDisplay:YES];        [_private->compController endRevertingChange:NO moveLeft:NO];    }    NSPoint origin = [[self superview] bounds].origin;    if (!NSEqualPoints(_private->lastScrollPosition, origin)) {        if (Frame* coreFrame = core([self _frame]))            coreFrame->eventHandler()->sendScrollEvent();        [_private->compController endRevertingChange:NO moveLeft:NO];                WebView *webView = [self _webView];        [[webView _UIDelegateForwarder] webView:webView didScrollDocumentInFrameView:[self _frameView]];    }    _private->lastScrollPosition = origin;    if ([self window] && !_private->closed && !_private->updateMouseoverTimer) {        CFRunLoopTimerContext context = { 0, self, NULL, NULL, NULL };                // Use a 100ms delay so that the synthetic mouse over update doesn't cause cursor thrashing when pages are loading        // and scrolling rapidly back to back.        _private->updateMouseoverTimer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + 0.1, 0, 0, 0,                                                              _updateMouseoverTimerCallback, &context);        CFRunLoopAddTimer(CFRunLoopGetCurrent(), _private->updateMouseoverTimer, kCFRunLoopDefaultMode);    }}- (void)_setAsideSubviews{    ASSERT(!_private->subviewsSetAside);    ASSERT(_private->savedSubviews == nil);    _private->savedSubviews = _subviews;#if USE(ACCELERATED_COMPOSITING)    // We need to keep the layer-hosting view in the subviews, otherwise the layers flash.    if (_private->layerHostingView) {        NSArray* newSubviews = [[NSArray alloc] initWithObjects:_private->layerHostingView, nil];        _subviews = newSubviews;    } else        _subviews = nil;#else    _subviews = nil;#endif        _private->subviewsSetAside = YES; }  - (void)_restoreSubviews {    ASSERT(_private->subviewsSetAside);#if USE(ACCELERATED_COMPOSITING)    if (_private->layerHostingView) {        [_subviews release];        _subviews = _private->savedSubviews;    } else {        ASSERT(_subviews == nil);        _subviews = _private->savedSubviews;    }#else    ASSERT(_subviews == nil);    _subviews = _private->savedSubviews;#endif        _private->savedSubviews = nil;    _private->subviewsSetAside = NO;}#ifndef NDEBUG- (void)didAddSubview:(NSView *)subview{    if (_private->enumeratingSubviews)        LOG(View, "A view of class %s was added during subview enumeration for layout or printing mode change. This view might paint without first receiving layout.", object_getClassName([subview class]));}- (void)willRemoveSubview:(NSView *)subview{    // Have to null-check _private, since this can be called via -dealloc when    // cleaning up the the layerHostingView.    if (_private && _private->enumeratingSubviews)        LOG(View, "A view of class %s was removed during subview enumeration for layout or printing mode change. We will still do layout or the printing mode change even though this view is no longer in the view hierarchy.", object_getClassName([subview class]));}#endif#ifdef BUILDING_ON_TIGER// This is called when we are about to draw, but before our dirty rect is propagated to our ancestors.// That's the perfect time to do a layout, except that ideally we'd want to be sure that we're dirty// before doing it. As a compromise, when we're opaque we do the layout only when actually asked to// draw, but when we're transparent we do the layout at this stage so views behind us know that they// need to be redrawn (in case the layout causes some things to get dirtied).- (void)_propagateDirtyRectsToOpaqueAncestors{    if (![[self _webView] drawsBackground])        [self _web_layoutIfNeededRecursive];    [super _propagateDirtyRectsToOpaqueAncestors];}#else- (void)viewWillDraw{    // On window close we will be called when the datasource is nil, then hit an assert in _topHTMLView    // So check if the dataSource is nil before calling [self _isTopHTMLView], this can be removed    // once the FIXME in _isTopHTMLView is fixed.    if (_private->dataSource && [self _isTopHTMLView])        [self _web_layoutIfNeededRecursive];    [super viewWillDraw];}#endif// Don't let AppKit even draw subviews. We take care of that.- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView{    // This helps when we print as part of a larger print process.    // If the WebHTMLView itself is what we're printing, then we will never have to do this.    BOOL wasInPrintingMode = _private->printing;    BOOL isPrinting = ![NSGraphicsContext currentContextDrawingToScreen];    if (isPrinting) {        if (!wasInPrintingMode)            [self _web_setPrintingModeRecursive];#ifndef BUILDING_ON_TIGER        else            [self _web_layoutIfNeededRecursive];#endif    } else if (wasInPrintingMode)        [self _web_clearPrintingModeRecursive];#ifdef BUILDING_ON_TIGER    // Because Tiger does not have viewWillDraw we need to do layout here.    [self _web_layoutIfNeededRecursive];    [_subviews makeObjectsPerformSelector:@selector(_propagateDirtyRectsToOpaqueAncestors)];#endif    [self _setAsideSubviews];    [super _recursiveDisplayRectIfNeededIgnoringOpacity:rect isVisibleRect:isVisibleRect rectIsVisibleRectForView:visibleView topView:topView];    [self _restoreSubviews];    if (wasInPrintingMode != isPrinting) {        if (wasInPrintingMode)            [self _web_setPrintingModeRecursive];        else            [self _web_clearPrintingModeRecursive];    }}// Don't let AppKit even draw subviews. We take care of that.- (void)_recursiveDisplayAllDirtyWithLockFocus:(BOOL)needsLockFocus visRect:(NSRect)visRect{    BOOL needToSetAsideSubviews = !_private->subviewsSetAside;    BOOL wasInPrintingMode = _private->printing;    BOOL isPrinting = ![NSGraphicsContext currentContextDrawingToScreen];    if (needToSetAsideSubviews) {        // This helps when we print as part of a larger print process.        // If the WebHTMLView itself is what we're printing, then we will never have to do this.        if (isPrinting) {            if (!wasInPrintingMode)                [self _web_setPrintingModeRecursive];#ifndef BUILDING_ON_TIGER            else                [self _web_layoutIfNeededRecursive];#endif        } else if (wasInPrintingMode)            [self _web_clearPrintingModeRecursive];#ifdef BUILDING_ON_TIGER        // Because Tiger does not have viewWillDraw we need to do layout here.        NSRect boundsBeforeLayout = [self bounds];        if (!NSIsEmptyRect(visRect))            [self _web_layoutIfNeededRecursive];        // If layout changes the view's bounds, then we need to recompute the visRect.        // That's because the visRect passed to us was based on the bounds at the time        // we were called. This method is only displayed to draw "all", so it's safe        // to just call visibleRect to compute the entire rectangle.        if (!NSEqualRects(boundsBeforeLayout, [self bounds]))            visRect = [self visibleRect];#endif        [self _setAsideSubviews];    }    [super _recursiveDisplayAllDirtyWithLockFocus:needsLockFocus visRect:visRect];    if (needToSetAsideSubviews) {        if (wasInPrintingMode != isPrinting) {            if (wasInPrintingMode)                [self _web_setPrintingModeRecursive];            else                [self _web_clearPrintingModeRecursive];        }        [self _restoreSubviews];    }}// Don't let AppKit even draw subviews. We take care of that.- (void)_recursive:(BOOL)recurse displayRectIgnoringOpacity:(NSRect)displayRect inContext:(NSGraphicsContext *)context topView:(BOOL)topView{#ifdef BUILDING_ON_TIGER     // Because Tiger does not have viewWillDraw we need to do layout here.    [self _web_layoutIfNeededRecursive];#endif    [self _setAsideSubviews];    [super _recursive:recurse displayRectIgnoringOpacity:displayRect inContext:context topView:topView];    [self _restoreSubviews];}- (BOOL)_insideAnotherHTMLView{    return self != [self _topHTMLView];}- (NSView *)hitTest:(NSPoint)point{    // WebHTMLView objects handle all events for objects inside them.    // To get those events, we prevent hit testing from AppKit.    // But there are three exceptions to this:    //   1) For right mouse clicks and control clicks we don't yet have an implementation    //      that works for nested views, so we let the hit testing go through the    //      standard NSView code path (needs to be fixed, see bug 4361618).    //   2) Java depends on doing a hit test inside it's mouse moved handling,    //      so we let the hit testing go through the standard NSView code path    //      when the current event is a mouse move (except when we are calling    //      from _updateMouseoverWithEvent, so we have to use a global,    //      forceWebHTMLViewHitTest, for that)    //   3) The acceptsFirstMouse: and shouldDelayWindowOrderingForEvent: methods    //      both need to figure out which view to check with inside the WebHTMLView.    //      They use a global to change the behavior of hitTest: so they can get the    //      right view. The global is forceNSViewHitTest and the method they use to    //      do the hit testing is _hitViewForEvent:. (But this does not work correctly    //      when there is HTML overlapping the view, see bug 4361626)    //   4) NSAccessibilityHitTest relies on this for checking the cursor position.    //      Our check for that is whether the event is NSFlagsChanged.  This works    //      for VoiceOver's cntl-opt-f5 command (move focus to item under cursor)    //      and Dictionary's cmd-cntl-D (open dictionary popup for item under cursor).    //      This is of course a hack.    BOOL captureHitsOnSubviews;    if (forceNSViewHitTest)        captureHitsOnSubviews = NO;    else if (forceWebHTMLViewHitTest)        captureHitsOnSubviews = YES;    else {        NSEvent *event = [[self window] currentEvent];        captureHitsOnSubviews = !([event type] == NSMouseMoved            || [event type] == NSRightMouseDown            || ([event type] == NSLeftMouseDown && ([event modifierFlags] & NSControlKeyMask) != 0)

⌨️ 快捷键说明

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