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

📄 pluginviewmac.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void PluginView::setNPWindowRect(const IntRect&){    setNPWindowIfNeeded();}void PluginView::setNPWindowIfNeeded(){    if (!m_isStarted || !parent() || !m_plugin->pluginFuncs()->setwindow)        return;    CGContextRef newContextRef = cgHandleFor(platformPluginWidget());    if (!newContextRef)        return;    WindowRef newWindowRef = nativeWindowFor(platformPluginWidget());    if (!newWindowRef)        return;    m_npWindow.window = (void*)&m_npCgContext;    m_npCgContext.window = newWindowRef;    m_npCgContext.context = newContextRef;    m_npWindow.x = m_windowRect.x();    m_npWindow.y = m_windowRect.y();    m_npWindow.width = m_windowRect.width();    m_npWindow.height = m_windowRect.height();    // TODO: (also clip against scrollbars, etc.)    m_npWindow.clipRect.left = 0;    m_npWindow.clipRect.top = 0;    m_npWindow.clipRect.right = m_windowRect.width();    m_npWindow.clipRect.bottom = m_windowRect.height();    PluginView::setCurrentPluginView(this);    JSC::JSLock::DropAllLocks dropAllLocks(false);    setCallingPlugin(true);    m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow);    setCallingPlugin(false);    PluginView::setCurrentPluginView(0);}void PluginView::updatePluginWidget(){    if (!parent())       return;    ASSERT(parent()->isFrameView());    FrameView* frameView = static_cast<FrameView*>(parent());    IntRect oldWindowRect = m_windowRect;    IntRect oldClipRect = m_clipRect;    m_windowRect = IntRect(frameView->contentsToWindow(frameRect().location()), frameRect().size());    m_clipRect = windowClipRect();    m_clipRect.move(-m_windowRect.x(), -m_windowRect.y());    if (platformPluginWidget() && (m_windowRect != oldWindowRect || m_clipRect != oldClipRect))        setNPWindowIfNeeded();}void PluginView::paint(GraphicsContext* context, const IntRect& rect){    if (!m_isStarted) {        paintMissingPluginIcon(context, rect);        return;    }    if (context->paintingDisabled())        return;    setNPWindowIfNeeded();    EventRecord event;    event.what = updateEvt;    event.message = (long unsigned int)m_npCgContext.window;    event.when = TickCount();    event.where.h = 0;    event.where.v = 0;    event.modifiers = GetCurrentKeyModifiers();    CGContextRef cg = m_npCgContext.context;    CGContextSaveGState(cg);    IntPoint offset = frameRect().location();    CGContextTranslateCTM(cg, offset.x(), offset.y());    if (!dispatchNPEvent(event))        LOG(Events, "PluginView::paint(): Paint event not accepted");    CGContextRestoreGState(cg);}void PluginView::invalidateRect(const IntRect& rect){    if (platformPluginWidget())        platformPluginWidget()->update(convertToContainingWindow(rect));}void PluginView::invalidateRect(NPRect* rect){    // TODO: optimize    invalidate();}void PluginView::invalidateRegion(NPRegion region){    // TODO: optimize    invalidate();}void PluginView::forceRedraw(){    notImplemented();}// ----------------- Event handling --------------------void PluginView::handleMouseEvent(MouseEvent* event){    EventRecord record;    if (event->type() == eventNames().mousemoveEvent) {        // Mouse movement is handled by null timer events        return;    } else if (event->type() == eventNames().mouseoverEvent) {        record.what = adjustCursorEvent;    } else if (event->type() == eventNames().mouseoutEvent) {        record.what = adjustCursorEvent;    } else if (event->type() == eventNames().mousedownEvent) {        record.what = mouseDown;        // The plugin needs focus to receive keyboard events        if (Page* page = m_parentFrame->page())            page->focusController()->setFocusedFrame(m_parentFrame);        m_parentFrame->document()->setFocusedNode(m_element);    } else if (event->type() == eventNames().mouseupEvent) {        record.what = mouseUp;    } else {        return;    }    record.where = globalMousePosForPlugin();    record.modifiers = modifiersForEvent(event);    if (!event->buttonDown())        record.modifiers |= btnState;    if (event->button() == 2)        record.modifiers |= controlKey;    if (!dispatchNPEvent(record)) {        if (record.what == adjustCursorEvent)            return; // Signals that the plugin wants a normal cursor        LOG(Events, "PluginView::handleMouseEvent(): Mouse event type %d at %d,%d not accepted",                record.what, record.where.h, record.where.v);    } else {        event->setDefaultHandled();    }}void PluginView::handleKeyboardEvent(KeyboardEvent* event){    LOG(Plugin, "PluginView::handleKeyboardEvent() ----------------- ");    LOG(Plugin, "PV::hKE(): KE.keyCode: 0x%02X, KE.charCode: %d",            event->keyCode(), event->charCode());    EventRecord record;    if (event->type() == eventNames().keydownEvent) {        // This event is the result of a PlatformKeyboardEvent::KeyDown which        // was disambiguated into a PlatformKeyboardEvent::RawKeyDown. Since        // we don't have access to the text here, we return, and wait for the        // corresponding event based on PlatformKeyboardEvent::Char.        return;    } else if (event->type() == eventNames().keypressEvent) {        // Which would be this one. This event was disambiguated from the same        // PlatformKeyboardEvent::KeyDown, but to a PlatformKeyboardEvent::Char,        // which retains the text from the original event. So, we can safely pass        // on the event as a key-down event to the plugin.        record.what = keyDown;    } else if (event->type() == eventNames().keyupEvent) {        // PlatformKeyboardEvent::KeyUp events always have the text, so nothing        // fancy here.        record.what = keyUp;    } else {        return;    }    const PlatformKeyboardEvent* platformEvent = event->keyEvent();    int keyCode = platformEvent->nativeVirtualKeyCode();    const String text = platformEvent->text();    if (text.length() < 1) {        event->setDefaultHandled();        return;    }    WTF::RetainPtr<CFStringRef> cfText(WTF::AdoptCF, text.createCFString());    LOG(Plugin, "PV::hKE(): PKE.text: %s, PKE.unmodifiedText: %s, PKE.keyIdentifier: %s",            text.ascii().data(), platformEvent->unmodifiedText().ascii().data(),            platformEvent->keyIdentifier().ascii().data());    char charCodes[2] = { 0, 0 };    if (!CFStringGetCString(cfText.get(), charCodes, 2, CFStringGetSystemEncoding())) {        LOG_ERROR("Could not resolve character code using system encoding.");        event->setDefaultHandled();        return;    }    record.where = globalMousePosForPlugin();    record.modifiers = modifiersForEvent(event);    record.message = ((keyCode & 0xFF) << 8) | (charCodes[0] & 0xFF);    record.when = TickCount();    LOG(Plugin, "PV::hKE(): record.modifiers: %d", record.modifiers);    LOG(Plugin, "PV::hKE(): PKE.qtEvent()->nativeVirtualKey: 0x%02X, charCode: %d",               keyCode, int(uchar(charCodes[0])));    if (!dispatchNPEvent(record))        LOG(Events, "PluginView::handleKeyboardEvent(): Keyboard event type %d not accepted", record.what);    else        event->setDefaultHandled();}void PluginView::nullEventTimerFired(Timer<PluginView>*){    EventRecord record;    record.what = nullEvent;    record.message = 0;    record.when = TickCount();    record.where = globalMousePosForPlugin();    record.modifiers = GetCurrentKeyModifiers();    if (!Button())        record.modifiers |= btnState;    if (!dispatchNPEvent(record))        LOG(Events, "PluginView::nullEventTimerFired(): Null event not accepted");}static int modifiersForEvent(UIEventWithKeyState* event){    int modifiers = 0;    if (event->ctrlKey())        modifiers |= controlKey;    if (event->altKey())        modifiers |= optionKey;    if (event->metaKey())        modifiers |= cmdKey;    if (event->shiftKey())        modifiers |= shiftKey;     return modifiers;}static bool tigerOrBetter(){    static SInt32 systemVersion = 0;    if (!systemVersion) {        if (Gestalt(gestaltSystemVersion, &systemVersion) != noErr)            return false;    }    return systemVersion >= 0x1040;}Point PluginView::globalMousePosForPlugin() const{    Point pos;    GetGlobalMouse(&pos);    IntPoint offset = topLevelOffsetFor(platformPluginWidget());    pos.h -= offset.x();    pos.v -= offset.y();    float scaleFactor = tigerOrBetter() ? HIGetScaleFactor() : 1;    pos.h = short(pos.h * scaleFactor);    pos.v = short(pos.v * scaleFactor);    return pos;}bool PluginView::dispatchNPEvent(NPEvent& event){    PluginView::setCurrentPluginView(this);    JSC::JSLock::DropAllLocks dropAllLocks(false);    setCallingPlugin(true);    bool accepted = m_plugin->pluginFuncs()->event(m_instance, &event);    setCallingPlugin(false);    PluginView::setCurrentPluginView(0);    return accepted;}// ------------------- Miscellaneous  ------------------static const char* MozillaUserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0";const char* PluginView::userAgent(){    if (m_plugin->quirks().contains(PluginQuirkWantsMozillaUserAgent))        return MozillaUserAgent;    if (m_userAgent.isNull())        m_userAgent = m_parentFrame->loader()->userAgent(m_url).utf8();    return m_userAgent.data();}const char* PluginView::userAgentStatic(){    return MozillaUserAgent;}NPError PluginView::handlePostReadFile(Vector<char>& buffer, uint32 len, const char* buf){    String filename(buf, len);    if (filename.startsWith("file:///"))        filename = filename.substring(8);    if (!fileExists(filename))        return NPERR_FILE_NOT_FOUND;    FILE* fileHandle = fopen((filename.utf8()).data(), "r");    if (fileHandle == 0)        return NPERR_FILE_NOT_FOUND;    int bytesRead = fread(buffer.data(), 1, 0, fileHandle);    fclose(fileHandle);    if (bytesRead <= 0)        return NPERR_FILE_NOT_FOUND;    return NPERR_NO_ERROR;}} // namespace WebCore#endif // !__LP64__

⌨️ 快捷键说明

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