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

📄 webnetscapepluginview.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
    if (!_isStarted)        return;    _eventHandler->mouseEntered(theEvent);}- (void)mouseExited:(NSEvent *)theEvent{    if (!_isStarted)        return;    _eventHandler->mouseExited(theEvent);        // Set cursor back to arrow cursor.  Because NSCursor doesn't know about changes that the plugin made, we could get confused about what we think the    // current cursor is otherwise.  Therefore we have no choice but to unconditionally reset the cursor when the mouse exits the plugin.    [[NSCursor arrowCursor] set];}// We can't name this method mouseMoved because we don't want to override // the NSView mouseMoved implementation.- (void)handleMouseMoved:(NSEvent *)theEvent{    if (!_isStarted)        return;    _eventHandler->mouseMoved(theEvent);}    - (void)mouseDragged:(NSEvent *)theEvent{    if (!_isStarted)        return;    _eventHandler->mouseDragged(theEvent);}- (void)scrollWheel:(NSEvent *)theEvent{    if (!_isStarted) {        [super scrollWheel:theEvent];        return;    }    if (!_eventHandler->scrollWheel(theEvent))        [super scrollWheel:theEvent];}- (void)keyUp:(NSEvent *)theEvent{    if (!_isStarted)        return;    _eventHandler->keyUp(theEvent);}- (void)keyDown:(NSEvent *)theEvent{    if (!_isStarted)        return;    _eventHandler->keyDown(theEvent);}- (void)flagsChanged:(NSEvent *)theEvent{    if (!_isStarted)        return;    _eventHandler->flagsChanged(theEvent);}#pragma mark WEB_NETSCAPE_PLUGIN- (BOOL)isNewWindowEqualToOldWindow{    if (window.x != lastSetWindow.x)        return NO;    if (window.y != lastSetWindow.y)        return NO;    if (window.width != lastSetWindow.width)        return NO;    if (window.height != lastSetWindow.height)        return NO;    if (window.clipRect.top != lastSetWindow.clipRect.top)        return NO;    if (window.clipRect.left != lastSetWindow.clipRect.left)        return NO;    if (window.clipRect.bottom  != lastSetWindow.clipRect.bottom)        return NO;    if (window.clipRect.right != lastSetWindow.clipRect.right)        return NO;    if (window.type != lastSetWindow.type)        return NO;        switch (drawingModel) {#ifndef NP_NO_QUICKDRAW        case NPDrawingModelQuickDraw:            if (nPort.qdPort.portx != lastSetPort.qdPort.portx)                return NO;            if (nPort.qdPort.porty != lastSetPort.qdPort.porty)                return NO;            if (nPort.qdPort.port != lastSetPort.qdPort.port)                return NO;        break;#endif /* NP_NO_QUICKDRAW */                    case NPDrawingModelCoreGraphics:            if (nPort.cgPort.window != lastSetPort.cgPort.window)                return NO;            if (nPort.cgPort.context != lastSetPort.cgPort.context)                return NO;        break;                            case NPDrawingModelCoreAnimation:          if (window.window != lastSetWindow.window)              return NO;          break;        default:            ASSERT_NOT_REACHED();        break;    }        return YES;}-(void)tellQuickTimeToChill{#ifndef NP_NO_QUICKDRAW    ASSERT(isDrawingModelQuickDraw(drawingModel));        // Make a call to the secret QuickDraw API that makes QuickTime calm down.    WindowRef windowRef = (WindowRef)[[self window] windowRef];    if (!windowRef) {        return;    }    CGrafPtr port = GetWindowPort(windowRef);    ::Rect bounds;    GetPortBounds(port, &bounds);    WKCallDrawingNotification(port, &bounds);#endif /* NP_NO_QUICKDRAW */}- (void)updateAndSetWindow{    // A plug-in can only update if it's (1) already been started (2) isn't stopped    // and (3) is able to draw on-screen. To meet condition (3) the plug-in must not    // be hidden and be attached to a window. QuickDraw plug-ins are an important    // excpetion to rule (3) because they manually must be told when to stop writing    // bits to the window backing store, thus to do so requires a new call to    // NPP_SetWindow() with an empty NPWindow struct.    if (!_isStarted)        return;    #ifdef NP_NO_QUICKDRAW    if (![self canDraw])        return;#else    if (drawingModel == NPDrawingModelQuickDraw)        [self tellQuickTimeToChill];    else if (drawingModel == NPDrawingModelCoreGraphics && ![self canDraw])        return;    #endif // NP_NO_QUICKDRAW        BOOL didLockFocus = [NSView focusView] != self && [self lockFocusIfCanDraw];    PortState portState = [self saveAndSetNewPortState];    if (portState) {        [self setWindowIfNecessary];        [self restorePortState:portState];        if (portState != (PortState)1)            free(portState);    }       if (didLockFocus)        [self unlockFocus];}- (void)setWindowIfNecessary{    if (!_isStarted)         return;        if (![self isNewWindowEqualToOldWindow]) {                // Make sure we don't call NPP_HandleEvent while we're inside NPP_SetWindow.        // We probably don't want more general reentrancy protection; we are really        // protecting only against this one case, which actually comes up when        // you first install the SVG viewer plug-in.        NPError npErr;        ASSERT(!inSetWindow);                inSetWindow = YES;                // A CoreGraphics plugin's window may only be set while the plugin is being updated        ASSERT((drawingModel != NPDrawingModelCoreGraphics) || [NSView focusView] == self);                [self willCallPlugInFunction];        {            JSC::JSLock::DropAllLocks dropAllLocks(false);            npErr = [_pluginPackage.get() pluginFuncs]->setwindow(plugin, &window);        }        [self didCallPlugInFunction];        inSetWindow = NO;#ifndef NDEBUG        switch (drawingModel) {#ifndef NP_NO_QUICKDRAW            case NPDrawingModelQuickDraw:                LOG(Plugins, "NPP_SetWindow (QuickDraw): %d, port=0x%08x, window.x:%d window.y:%d window.width:%d window.height:%d",                npErr, (int)nPort.qdPort.port, (int)window.x, (int)window.y, (int)window.width, (int)window.height);            break;#endif /* NP_NO_QUICKDRAW */                        case NPDrawingModelCoreGraphics:                LOG(Plugins, "NPP_SetWindow (CoreGraphics): %d, window=%p, context=%p, window.x:%d window.y:%d window.width:%d window.height:%d",                npErr, nPort.cgPort.window, nPort.cgPort.context, (int)window.x, (int)window.y, (int)window.width, (int)window.height);            break;            case NPDrawingModelCoreAnimation:                LOG(Plugins, "NPP_SetWindow (CoreAnimation): %d, window=%p window.x:%d window.y:%d window.width:%d window.height:%d",                npErr, window.window, nPort.cgPort.context, (int)window.x, (int)window.y, (int)window.width, (int)window.height);            break;            default:                ASSERT_NOT_REACHED();            break;        }#endif /* !defined(NDEBUG) */                lastSetWindow = window;        lastSetPort = nPort;    }}+ (void)setCurrentPluginView:(WebNetscapePluginView *)view{    currentPluginView = view;}+ (WebNetscapePluginView *)currentPluginView{    return currentPluginView;}- (BOOL)createPlugin{    // Open the plug-in package so it remains loaded while our plugin uses it    [_pluginPackage.get() open];        // Initialize drawingModel to an invalid value so that we can detect when the plugin does not specify a drawingModel    drawingModel = (NPDrawingModel)-1;        // Initialize eventModel to an invalid value so that we can detect when the plugin does not specify an event model.    eventModel = (NPEventModel)-1;        NPError npErr = [self _createPlugin];    if (npErr != NPERR_NO_ERROR) {        LOG_ERROR("NPP_New failed with error: %d", npErr);        [self _destroyPlugin];        [_pluginPackage.get() close];        return NO;    }        if (drawingModel == (NPDrawingModel)-1) {#ifndef NP_NO_QUICKDRAW        // Default to QuickDraw if the plugin did not specify a drawing model.        drawingModel = NPDrawingModelQuickDraw;#else        // QuickDraw is not available, so we can't default to it. Instead, default to CoreGraphics.        drawingModel = NPDrawingModelCoreGraphics;#endif    }    if (eventModel == (NPEventModel)-1) {        // If the plug-in did not specify a drawing model we default to Carbon when it is available.#ifndef NP_NO_CARBON        eventModel = NPEventModelCarbon;#else        eventModel = NPEventModelCocoa;#endif // NP_NO_CARBON    }#ifndef NP_NO_CARBON    if (eventModel == NPEventModelCocoa && isDrawingModelQuickDraw(drawingModel)) {        LOG(Plugins, "Plugin can't use use Cocoa event model with QuickDraw drawing model: %@", _pluginPackage.get());        [self _destroyPlugin];        [_pluginPackage.get() close];                return NO;    }        #endif // NP_NO_CARBON    #ifndef BUILDING_ON_TIGER    if (drawingModel == NPDrawingModelCoreAnimation) {        void *value = 0;        if ([_pluginPackage.get() pluginFuncs]->getvalue(plugin, NPPVpluginCoreAnimationLayer, &value) == NPERR_NO_ERROR && value) {                        // The plug-in gives us a retained layer.            _pluginLayer.adoptNS((CALayer *)value);            [self setWantsLayer:YES];            LOG(Plugins, "%@ is using Core Animation drawing model with layer %@", _pluginPackage.get(), _pluginLayer.get());        }        ASSERT(_pluginLayer);    }#endif        // Create the event handler    _eventHandler.set(WebNetscapePluginEventHandler::create(self));        // Get the text input vtable    if (eventModel == NPEventModelCocoa) {        [self willCallPlugInFunction];        {            JSC::JSLock::DropAllLocks dropAllLocks(false);            NPPluginTextInputFuncs *value = 0;            if (![_pluginPackage.get() pluginFuncs]->getvalue(plugin, NPPVpluginTextInputFuncs, &value) == NPERR_NO_ERROR && value)                textInputFuncs = value;        }        [self didCallPlugInFunction];    }        return YES;}#ifndef BUILDING_ON_TIGER- (void)setLayer:(CALayer *)newLayer{    [super setLayer:newLayer];    if (_pluginLayer) {        _pluginLayer.get().autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;        [newLayer addSublayer:_pluginLayer.get()];    }}#endif- (void)loadStream{    if ([self _shouldCancelSrcStream])        return;        if (_loadManually) {        [self _redeliverStream];        return;    }        // If the OBJECT/EMBED tag has no SRC, the URL is passed to us as "".    // Check for this and don't start a load in this case.    if (_sourceURL && ![_sourceURL.get() _web_isEmpty]) {        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:_sourceURL.get()];        [request _web_setHTTPReferrer:core([self webFrame])->loader()->outgoingReferrer()];        [self loadRequest:request inTarget:nil withNotifyData:nil sendNotification:NO];    } }- (BOOL)shouldStop{    // If we're already calling a plug-in function, do not call NPP_Destroy().  The plug-in function we are calling    // may assume that its instance->pdata, or other memory freed by NPP_Destroy(), is valid and unchanged until said    // plugin-function returns.    // See <rdar://problem/4480737>.    if (pluginFunctionCallDepth > 0) {        shouldStopSoon = YES;        return NO;    }    return YES;}- (void)destroyPlugin{    // To stop active streams it's necessary to invoke stop() on a copy     // of streams. This is because calling WebNetscapePluginStream::stop() also has the side effect    // of removing a stream from this hash set.

⌨️ 快捷键说明

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