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

📄 pluginviewmac.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved. * Copyright (C) 2008 Collabora Ltd. 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. * * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 COMPUTER, INC. OR * 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. */#ifndef __LP64__#include "config.h"#include "PluginView.h"#include <runtime/JSLock.h>#include <runtime/JSValue.h>#include "wtf/RetainPtr.h"#include "Document.h"#include "DocumentLoader.h"#include "Element.h"#include "EventNames.h"#include "FocusController.h"#include "FrameLoader.h"#include "FrameLoadRequest.h"#include "FrameTree.h"#include "Frame.h"#include "FrameView.h"#include "GraphicsContext.h"#include "HTMLNames.h"#include "HTMLPlugInElement.h"#include "Image.h"#include "JSDOMBinding.h"#include "KeyboardEvent.h"#include "MouseEvent.h"#include "NotImplemented.h"#include "npruntime_impl.h"#include "Page.h"#include "PlatformMouseEvent.h"#include "PlatformKeyboardEvent.h"#include "PluginDebug.h"#include "PluginPackage.h"#include "PluginMainThreadScheduler.h"#include "RenderLayer.h"#include "runtime.h"#include "runtime_root.h"#include "ScriptController.h"#include "Settings.h"using JSC::ExecState;using JSC::Interpreter;using JSC::JSLock;using JSC::JSObject;using JSC::JSValue;using JSC::UString;#if PLATFORM(QT)#include <QWidget>#include <QKeyEvent>QT_BEGIN_NAMESPACEextern Q_GUI_EXPORT OSWindowRef qt_mac_window_for(const QWidget *w);QT_END_NAMESPACE#endifusing std::min;using namespace WTF;namespace WebCore {using namespace HTMLNames;static int modifiersForEvent(UIEventWithKeyState *event);static inline WindowRef nativeWindowFor(PlatformWidget widget){#if PLATFORM(QT)    if (widget)        return static_cast<WindowRef>(qt_mac_window_for(widget));#endif    return 0;}static inline CGContextRef cgHandleFor(PlatformWidget widget){#if PLATFORM(QT)    if (widget)        return (CGContextRef)widget->macCGHandle();#endif    return 0;}static inline IntPoint topLevelOffsetFor(PlatformWidget widget){#if PLATFORM(QT)    if (widget) {        PlatformWidget topLevel = widget->window();        return widget->mapTo(topLevel, QPoint(0, 0)) + topLevel->geometry().topLeft() - topLevel->pos();    }#endif    return IntPoint();}// --------------- Lifetime management -----------------void PluginView::init(){    if (m_haveInitialized)        return;    m_haveInitialized = true;    if (!m_plugin) {        ASSERT(m_status == PluginStatusCanNotFindPlugin);        return;    }    if (!m_plugin->load()) {        m_plugin = 0;        m_status = PluginStatusCanNotLoadPlugin;        return;    }    if (!start()) {        m_status = PluginStatusCanNotLoadPlugin;        return;    }    setPlatformPluginWidget(m_parentFrame->view()->hostWindow()->platformWindow());    m_npCgContext.window = 0;    m_npCgContext.context = 0;    m_npWindow.window = (void*)&m_npCgContext;    m_npWindow.type = NPWindowTypeWindow;    m_npWindow.x = 0;    m_npWindow.y = 0;    m_npWindow.width = 0;    m_npWindow.height = 0;    m_npWindow.clipRect.left = 0;    m_npWindow.clipRect.top = 0;    m_npWindow.clipRect.right = 0;    m_npWindow.clipRect.bottom = 0;    setIsNPAPIPlugin(true);    show();    m_status = PluginStatusLoadedSuccessfully;    // TODO: Implement null timer throttling depending on plugin activation    m_nullEventTimer.set(new Timer<PluginView>(this, &PluginView::nullEventTimerFired));    m_nullEventTimer->startRepeating(0.02);}PluginView::~PluginView(){    stop();    deleteAllValues(m_requests);    freeStringArray(m_paramNames, m_paramCount);    freeStringArray(m_paramValues, m_paramCount);    m_parentFrame->script()->cleanupScriptObjectsForPlugin(this);    if (m_plugin && !(m_plugin->quirks().contains(PluginQuirkDontUnloadPlugin)))        m_plugin->unload();    m_window = 0;}void PluginView::stop(){    if (!m_isStarted)        return;    HashSet<RefPtr<PluginStream> > streams = m_streams;    HashSet<RefPtr<PluginStream> >::iterator end = streams.end();    for (HashSet<RefPtr<PluginStream> >::iterator it = streams.begin(); it != end; ++it) {        (*it)->stop();        disconnectStream((*it).get());    }    ASSERT(m_streams.isEmpty());    m_isStarted = false;    JSC::JSLock::DropAllLocks dropAllLocks(false);    PluginMainThreadScheduler::scheduler().unregisterPlugin(m_instance);    // Destroy the plugin    PluginView::setCurrentPluginView(this);    setCallingPlugin(true);    m_plugin->pluginFuncs()->destroy(m_instance, 0);    setCallingPlugin(false);    PluginView::setCurrentPluginView(0);    m_instance->pdata = 0;}NPError PluginView::getValueStatic(NPNVariable variable, void* value){    LOG(Plugin, "PluginView::getValueStatic(%d)", variable);    switch (variable) {    case NPNVToolkit:        *static_cast<uint32*>(value) = 0;        return NPERR_NO_ERROR;    case NPNVjavascriptEnabledBool:        *static_cast<NPBool*>(value) = true;        return NPERR_NO_ERROR;    default:        return NPERR_GENERIC_ERROR;    }}NPError PluginView::getValue(NPNVariable variable, void* value){    LOG(Plugin, "PluginView::getValue(%d)", variable);    switch (variable) {    case NPNVWindowNPObject: {        if (m_isJavaScriptPaused)            return NPERR_GENERIC_ERROR;        NPObject* windowScriptObject = m_parentFrame->script()->windowScriptNPObject();        // Return value is expected to be retained, as described in        // <http://www.mozilla.org/projects/plugin/npruntime.html>        if (windowScriptObject)            _NPN_RetainObject(windowScriptObject);        void** v = (void**)value;        *v = windowScriptObject;        return NPERR_NO_ERROR;    }    case NPNVPluginElementNPObject: {        if (m_isJavaScriptPaused)            return NPERR_GENERIC_ERROR;        NPObject* pluginScriptObject = 0;        if (m_element->hasTagName(appletTag) || m_element->hasTagName(embedTag) || m_element->hasTagName(objectTag))            pluginScriptObject = static_cast<HTMLPlugInElement*>(m_element)->getNPObject();        // Return value is expected to be retained, as described in        // <http://www.mozilla.org/projects/plugin/npruntime.html>        if (pluginScriptObject)            _NPN_RetainObject(pluginScriptObject);        void** v = (void**)value;        *v = pluginScriptObject;        return NPERR_NO_ERROR;    }    case NPNVsupportsCoreGraphicsBool:        *static_cast<NPBool*>(value) = true;        return NPERR_NO_ERROR;    default:        return getValueStatic(variable, value);    }}void PluginView::setParent(ScrollView* parent){    Widget::setParent(parent);    if (parent)        init();}// -------------- Geometry and painting ----------------void PluginView::show(){    LOG(Plugin, "PluginView::show()");    setSelfVisible(true);    if (isParentVisible() && platformPluginWidget())        platformPluginWidget()->setVisible(true);    Widget::show();}void PluginView::hide(){    LOG(Plugin, "PluginView::hide()");    setSelfVisible(false);    if (isParentVisible() && platformPluginWidget())        platformPluginWidget()->setVisible(false);    Widget::hide();}void PluginView::setFocus(){    LOG(Plugin, "PluginView::setFocus()");    if (platformPluginWidget())       platformPluginWidget()->setFocus(Qt::OtherFocusReason);   else       Widget::setFocus();    // TODO: Also handle and pass on blur events (focus lost)    EventRecord record;    record.what = getFocusEvent;    record.message = 0;    record.when = TickCount();    record.where = globalMousePosForPlugin();    record.modifiers = GetCurrentKeyModifiers();    if (!dispatchNPEvent(record))        LOG(Events, "PluginView::setFocus(): Get-focus event not accepted");}void PluginView::setParentVisible(bool visible){    if (isParentVisible() == visible)        return;    Widget::setParentVisible(visible);    if (isSelfVisible() && platformPluginWidget())        platformPluginWidget()->setVisible(visible);}

⌨️ 快捷键说明

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