// Keep this in sync with the other platform event constructors
// TODO: m_balEventKey should be refcounted
PlatformKeyboardEvent::PlatformKeyboardEvent(BalEventKey* event)
    : m_type((event->state == SDL_RELEASED) ? KeyUp : KeyDown)
    , m_autoRepeat(false)
    , m_windowsVirtualKeyCode(ConvertSDLKeyToVirtualKey(event->keysym.sym, event->keysym.mod))
    , m_isKeypad(event->keysym.sym >= SDLK_KP0 && event->keysym.sym <= SDLK_KP_EQUALS)
    , m_shiftKey(event->keysym.mod & KMOD_SHIFT)
    , m_ctrlKey(event->keysym.mod & KMOD_CTRL)
    , m_altKey(event->keysym.mod & KMOD_ALT)
    , m_metaKey(event->keysym.mod & KMOD_META)
    , m_balEventKey(event)
{
    UChar aSrc[2];
    aSrc[0] = event->keysym.unicode;
    aSrc[1] = 0;

    WebCore::String aText(aSrc);
    WebCore::String aUnmodifiedText(aSrc);
    WebCore::String aKeyIdentifier = keyIdentifierForSDLKeyCode(event->keysym.sym);

    m_text = aText;
    m_unmodifiedText = aUnmodifiedText;
    m_keyIdentifier = aKeyIdentifier;

#if ENABLE(CEHTML)
    bool isVKKey = event->keysym.scancode == 0xFF && event->keysym.sym == event->keysym.unicode;
    if (UNLIKELY(isVKKey)) {
        WebCore::String vkKey = convertVKKeyToString(event->keysym.sym);
        ASSERT(!vkKey.isNull());
        m_keyIdentifier = vkKey;
        m_unmodifiedText = vkKey;
        m_windowsVirtualKeyCode = event->keysym.sym;
    }
#endif
}
示例#2
0
文件: WebSocket.cpp 项目: dzip/webkit
static bool isValidProtocolString(const WebCore::String& protocol)
{
    if (protocol.isNull())
        return true;
    if (protocol.isEmpty())
        return false;
    const UChar* characters = protocol.characters();
    for (size_t i = 0; i < protocol.length(); i++) {
        if (characters[i] < 0x21 || characters[i] > 0x7E)
            return false;
    }
    return true;
}
void WebDebugListenerImpl::sourceParsed(ExecState* execState, const SourceCode& source, int errorLine, const UString& errorMsg)
{
    if (m_listener && !m_inDebug) {
        m_inDebug = true;

        WebCore::String coreSourceURL = WebCore::ustringToString(source.provider()->url());
        WebCore::Frame *frame = static_cast<WebCore::JSDOMWindow*>(execState->lexicalGlobalObject())->impl()->frame();
        if (!(coreSourceURL.isNull() || coreSourceURL.isEmpty())) {
            WebCore::KURL sourceURL(WebCore::ParsedURLString, coreSourceURL);
            WebCore::KURL mappedURL;
            if(WebCore::FrameLoaderClientApollo::mapFrameUrl(frame, sourceURL, &mappedURL)) {
                coreSourceURL = mappedURL.string();
            }
        }

        WebCore::String coreErrorMsg = WebCore::ustringToString(errorMsg);

        WebCore::String coreSource(source.data(), source.length());

        m_listener->m_pVTable->sourceParsed(m_listener, source.provider()->asID(), coreSourceURL.webString(), coreSource.webString(), source.firstLine(), errorLine, coreErrorMsg.webString());

        m_inDebug = false;
    }
}
示例#4
0
void XMLTokenizer::parseStartElement()
{
    if (!m_sawFirstElement && m_parsingFragment) {  // If we are parsing a document fragment and this is the first element of it...
        // skip dummy element for fragments         // Ignore it, because we wrap document fragments in a bogus element in order to simply make it work like a well-formed XML file.
        m_sawFirstElement = true;
        return;
    }

    m_sawFirstElement = true;

    exitText();

    // To do: use EA::XML::Strlcpy instead of this .decode stuff, as it would be more friendly to the heap.
    WebCore::String localName;
    const char* pName = mpXmlReader->GetName();
    if(pName)  // This should always be valid.
        localName = UTF8Encoding().decode(pName, strlen(pName));

    WebCore::String uri;
    const char* pNamespaceURI = mpXmlReader->GetNamespaceURI();
    if(pNamespaceURI) // This may be NULL.
        uri = UTF8Encoding().decode(pNamespaceURI, strlen(pNamespaceURI));

    // Usually prefixLength is zero, as there won't usually be a namespace prefix.
    const size_t prefixLength = mpXmlReader->GetNamePrefixLength();
    WebCore::String prefix = UTF8Encoding().decode(pName, prefixLength);

    if (m_parsingFragment && uri.isNull()) {
        // ASSERT(prefix.isNull());
        uri = m_defaultNamespaceURI;
    }

    #if EA_XMLTOKENIZER_TRACE
        WTFLogEvent("XMLTokenizer start element: %s\n", pName);
    #endif

    WebCore::ExceptionCode ec = 0;
    WebCore::QualifiedName qName(prefix, localName, uri);
    RefPtr<Element> newElement = m_doc->createElement(qName, true, ec);
    if (!newElement) {
        stopParsing();
        return;
    }

    // WebCore expects that we copy all attributes to the dom element, including 
    // namespace attributes. All elements are expected to have namespaces. But 
    // UTFXml stores namespace attributes and regular attributes for a node 
    // separately, so we get them with the handleElementNamespaces and handleElementAttributes
    // functions.
    handleElementNamespaces(newElement.get(), mpXmlReader, ec);
    if (ec) {
        stopParsing();
        return;
    }

    handleElementAttributes(newElement.get(), mpXmlReader, ec);
    if (ec) {
        stopParsing();
        return;
    }

    if (newElement->hasTagName(HTMLNames::scriptTag))
        static_cast<HTMLScriptElement*>(newElement.get())->setCreatedByParser(true);
    else if (newElement->hasTagName(HTMLNames::styleTag))
        static_cast<HTMLStyleElement*>(newElement.get())->setCreatedByParser(true);
#if ENABLE(SVG)
    else if (newElement->hasTagName(SVGNames::styleTag))
        static_cast<SVGStyleElement*>(newElement.get())->setCreatedByParser(true);
#endif

    if (newElement->hasTagName(HTMLNames::scriptTag)
#if ENABLE(SVG)
     || newElement->hasTagName(SVGNames::scriptTag)
#endif
        )
        m_scriptStartLine = lineNumber();

    if (!m_currentNode->addChild(newElement.get())) {
        stopParsing();
        return;
    }

    setCurrentNode(newElement.get());
    if (m_view && !newElement->attached())
        newElement->attach();
}