void DropDown::Draw(const Point& screenPos) { if(!drawn) { if(optionIndex!=-1) TextPosition(options[optionIndex].first); drawn = true; } Graphics * g = ui::Engine::Ref().g; Point Position = screenPos; ui::Colour textColour = Appearance.TextInactive; ui::Colour borderColour = Appearance.BorderInactive; ui::Colour backgroundColour = Appearance.BackgroundInactive; if (isMouseInside) { textColour = Appearance.TextHover; borderColour = Appearance.BorderHover; backgroundColour = Appearance.BackgroundHover; } else { textColour = Appearance.TextInactive; borderColour = Appearance.BorderInactive; backgroundColour = Appearance.BackgroundInactive; } g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, backgroundColour.Red, backgroundColour.Green, backgroundColour.Blue, backgroundColour.Alpha); g->drawrect(Position.X, Position.Y, Size.X, Size.Y, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha); if(optionIndex!=-1) g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, textColour.Red, textColour.Green, textColour.Blue, textColour.Alpha); }
/** * Make sure disambiguating of Mappings works. */ void FMDIndexTests::testDisambiguate() { // Make some positions Mapping mapped(TextPosition(1, 1)); Mapping otherSide(TextPosition(0, 33)); Mapping unmapped(TextPosition(0, 0), false); Mapping elsewhere(TextPosition(2, 10)); // Make sure disambiguate does the right things CPPUNIT_ASSERT(index->disambiguate(mapped, otherSide) == mapped); CPPUNIT_ASSERT(index->disambiguate(otherSide, mapped) == otherSide); CPPUNIT_ASSERT(index->disambiguate(mapped, unmapped) == mapped); CPPUNIT_ASSERT(index->disambiguate(unmapped, mapped) == otherSide); CPPUNIT_ASSERT(index->disambiguate(unmapped, unmapped).is_mapped == false); CPPUNIT_ASSERT(index->disambiguate(elsewhere, mapped).is_mapped == false); }
TEST(CompactHTMLTokenTest, EmptyAttributeValueFromHTMLToken) { HTMLToken token; token.beginStartTag('a'); token.addNewAttribute(); token.beginAttributeName(3); token.appendToAttributeName('b'); token.endAttributeName(4); token.addNewAttribute(); token.beginAttributeName(5); token.appendToAttributeName('c'); token.endAttributeName(6); token.beginAttributeValue(8); token.endAttributeValue(8); CompactHTMLToken ctoken(&token, TextPosition()); const CompactHTMLToken::Attribute* attributeB = ctoken.getAttributeItem( QualifiedName(AtomicString(), "b", AtomicString())); ASSERT_TRUE(attributeB); EXPECT_FALSE(attributeB->value.isNull()); EXPECT_TRUE(attributeB->value.isEmpty()); const CompactHTMLToken::Attribute* attributeC = ctoken.getAttributeItem( QualifiedName(AtomicString(), "c", AtomicString())); ASSERT_TRUE(attributeC); EXPECT_FALSE(attributeC->value.isNull()); EXPECT_TRUE(attributeC->value.isEmpty()); const CompactHTMLToken::Attribute* attributeD = ctoken.getAttributeItem( QualifiedName(AtomicString(), "d", AtomicString())); EXPECT_FALSE(attributeD); }
void StyleSheetContents::parseAuthorStyleSheet(const CachedCSSStyleSheet* cachedStyleSheet) { bool hasValidMIMEType = true; String sheetText = cachedStyleSheet->sheetText(&hasValidMIMEType); if (!hasValidMIMEType) { ASSERT(sheetText.isNull()); if (auto* document = singleOwnerDocument()) { if (auto* page = document->page()) page->console().addMessage(MessageSource::Security, MessageLevel::Error, "Did not parse stylesheet at '" + cachedStyleSheet->url().stringCenterEllipsizedToLength() + "' because its MIME type was invalid."); } return; } CSSParser p(parserContext()); p.parseSheet(this, sheetText, TextPosition(), nullptr, true); if (m_parserContext.needsSiteSpecificQuirks && isStrictParserMode(m_parserContext.mode)) { // Work around <https://bugs.webkit.org/show_bug.cgi?id=28350>. DEPRECATED_DEFINE_STATIC_LOCAL(const String, mediaWikiKHTMLFixesStyleSheet, (ASCIILiteral("/* KHTML fix stylesheet */\n/* work around the horizontal scrollbars */\n#column-content { margin-left: 0; }\n\n"))); // There are two variants of KHTMLFixes.css. One is equal to mediaWikiKHTMLFixesStyleSheet, // while the other lacks the second trailing newline. if (baseURL().string().endsWith("/KHTMLFixes.css") && !sheetText.isNull() && mediaWikiKHTMLFixesStyleSheet.startsWith(sheetText) && sheetText.length() >= mediaWikiKHTMLFixesStyleSheet.length() - 1) clearRules(); }
TextPosition textPositionFromOffset(size_t offset, const Vector<size_t>& lineEndings) { const size_t* foundLineEnding = approximateBinarySearch<size_t, size_t>(lineEndings, lineEndings.size(), offset, sizetExtractor); size_t lineIndex = foundLineEnding - &lineEndings.at(0); if (offset > *foundLineEnding) ++lineIndex; size_t lineStartOffset = lineIndex > 0 ? lineEndings.at(lineIndex - 1) + 1 : 0; size_t column = offset - lineStartOffset; return TextPosition(OrdinalNumber::fromZeroBasedInt(lineIndex), OrdinalNumber::fromZeroBasedInt(column)); }
TextPosition TextPosition::fromOffsetAndLineEndings( unsigned offset, const Vector<unsigned>& lineEndings) { const unsigned* foundLineEnding = std::lower_bound(lineEndings.begin(), lineEndings.end(), offset); int lineIndex = foundLineEnding - &lineEndings.at(0); unsigned lineStartOffset = lineIndex > 0 ? lineEndings.at(lineIndex - 1) + 1 : 0; int column = offset - lineStartOffset; return TextPosition(OrdinalNumber::fromZeroBasedInt(lineIndex), OrdinalNumber::fromZeroBasedInt(column)); }
void DropDown::SetOption(int option) { for(int i = 0; i < options.size(); i++) { if(options[i].second == option) { optionIndex = i; TextPosition(options[optionIndex].first); return; } } }
void DropDown::SetOption(String option) { for (size_t i = 0; i < options.size(); i++) { if (options[i].first == option) { optionIndex = i; TextPosition(options[optionIndex].first); return; } } }
Button::Button(Point position, Point size, std::string buttonText, std::string toolTip): Component(position, size), ButtonText(buttonText), isMouseInside(false), isButtonDown(false), isTogglable(false), toggle(false), actionCallback(NULL), Enabled(true), toolTip(toolTip) { TextPosition(); }
void V8InjectedScriptHost::evaluateWithExceptionDetailsCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Isolate* isolate = info.GetIsolate(); if (info.Length() < 1) { isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(isolate, "One argument expected."))); return; } v8::Local<v8::String> expression = info[0]->ToString(isolate); if (expression.IsEmpty()) { isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(isolate, "The argument must be a string."))); return; } ASSERT(isolate->InContext()); v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate); if (wrappedResult.IsEmpty()) return; v8::TryCatch tryCatch(isolate); v8::Local<v8::Script> script; v8::Local<v8::Value> result; if (!v8Call(V8ScriptRunner::compileScript(expression, String(), String(), TextPosition(), isolate), script, tryCatch)) { setExceptionAsReturnValue(info, wrappedResult, tryCatch); return; } v8::Local<v8::Symbol> commandLineAPISymbolValue = commandLineAPISymbol(isolate); v8::Local<v8::Object> global = isolate->GetCurrentContext()->Global(); if (info.Length() >= 2 && info[1]->IsObject()) { v8::Local<v8::Object> commandLineAPI = info[1]->ToObject(isolate); global->Set(commandLineAPISymbolValue, commandLineAPI); } if (!v8Call(V8ScriptRunner::runCompiledScript(isolate, script, currentExecutionContext(isolate)), result, tryCatch)) { global->Delete(isolate->GetCurrentContext(), commandLineAPISymbolValue); setExceptionAsReturnValue(info, wrappedResult, tryCatch); return; } global->Delete(isolate->GetCurrentContext(), commandLineAPISymbolValue); wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result); wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8::Undefined(isolate)); v8SetReturnValue(info, wrappedResult); }
void CSSPreloadScanner::emitRule(const SegmentedString& source) { if (equalIgnoringCase("import", m_rule.characters(), m_rule.length())) { String url = parseCSSStringOrURL(m_ruleValue.characters(), m_ruleValue.length()); if (!url.isEmpty()) { KURL baseElementURL; // FIXME: This should be passed in from the HTMLPreloadScaner via scan()! TextPosition position = TextPosition(source.currentLine(), source.currentColumn()); OwnPtr<PreloadRequest> request = PreloadRequest::create("css", position, url, baseElementURL, CachedResource::CSSStyleSheet); // FIXME: Should this be including the charset in the preload request? m_requests->append(request.release()); } m_state = Initial; } else if (equalIgnoringCase("charset", m_rule.characters(), m_rule.length())) m_state = Initial; else m_state = DoneParsingImportRules; m_rule.clear(); m_ruleValue.clear(); }
void test(PreconnectTestCase testCase) { // TODO(yoav): Need a mock loader here to verify things are happenning beyond preconnect. PreloaderNetworkHintsMock networkHints; OwnPtr<PreloadRequest> preloadRequest = PreloadRequest::create(String(), TextPosition(), testCase.url, KURL(ParsedURLStringTag(), testCase.baseURL), Resource::Image, ReferrerPolicy(), FetchRequest::ResourceWidth(), ClientHintsPreferences(), PreloadRequest::RequestTypePreconnect); if (testCase.isCORS) preloadRequest->setCrossOriginEnabled(DoNotAllowStoredCredentials); OwnPtrWillBeRawPtr<HTMLResourcePreloader> preloader = HTMLResourcePreloader::create(m_dummyPageHolder->document()); preloader->preload(preloadRequest.release(), networkHints); ASSERT_TRUE(networkHints.didPreconnect()); ASSERT_EQ(testCase.isCORS, networkHints.isCrossOrigin()); ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); }
Ref<CSSStyleSheet> CSSStyleSheet::create(Ref<StyleSheetContents>&& sheet, Node& ownerNode, const std::optional<bool>& isCleanOrigin) { return adoptRef(*new CSSStyleSheet(WTFMove(sheet), ownerNode, TextPosition(), false, isCleanOrigin)); }
TextPosition XMLDocumentParser::textPosition() const { return TextPosition(lineNumber(), columnNumber()); }
// http://dev.w3.org/html5/spec/Overview.html#prepare-a-script bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, LegacyTypeSupport supportLegacyTypes) { if (m_alreadyStarted) return false; ScriptLoaderClient* client = this->client(); bool wasParserInserted; if (m_parserInserted) { wasParserInserted = true; m_parserInserted = false; } else { wasParserInserted = false; } if (wasParserInserted && !client->asyncAttributeValue()) m_forceAsync = true; // FIXME: HTML5 spec says we should check that all children are either comments or empty text nodes. if (!client->hasSourceAttribute() && !m_element->hasChildren()) return false; if (!m_element->inDocument()) return false; if (!isScriptTypeSupported(supportLegacyTypes)) return false; if (wasParserInserted) { m_parserInserted = true; m_forceAsync = false; } m_alreadyStarted = true; // FIXME: If script is parser inserted, verify it's still in the original document. Document& elementDocument = m_element->document(); Document* contextDocument = elementDocument.contextDocument().get(); if (!contextDocument || !contextDocument->allowExecutingScripts(m_element)) return false; if (!isScriptForEventSupported()) return false; if (!client->charsetAttributeValue().isEmpty()) m_characterEncoding = client->charsetAttributeValue(); else m_characterEncoding = elementDocument.characterSet(); if (client->hasSourceAttribute()) { FetchRequest::DeferOption defer = FetchRequest::NoDefer; if (!m_parserInserted || client->asyncAttributeValue() || client->deferAttributeValue()) defer = FetchRequest::LazyLoad; if (!fetchScript(client->sourceAttributeValue(), defer)) return false; } if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parserInserted && !client->asyncAttributeValue()) { m_willExecuteWhenDocumentFinishedParsing = true; m_willBeParserExecuted = true; } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyncAttributeValue()) { m_willBeParserExecuted = true; } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocument.isRenderingReady()) { m_willBeParserExecuted = true; m_readyToBeParserExecuted = true; } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && !m_forceAsync) { m_willExecuteInOrder = true; m_pendingScript = PendingScript(m_element, m_resource.get()); contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRunner::IN_ORDER_EXECUTION); // Note that watchForLoad can immediately call notifyFinished. m_pendingScript.watchForLoad(this); } else if (client->hasSourceAttribute()) { m_pendingScript = PendingScript(m_element, m_resource.get()); LocalFrame* frame = m_element->document().frame(); if (frame) { ScriptState* scriptState = ScriptState::forMainWorld(frame); if (scriptState->contextIsValid()) ScriptStreamer::startStreaming(m_pendingScript, PendingScript::Async, frame->settings(), scriptState, frame->frameScheduler()->loadingTaskRunner()); } contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRunner::ASYNC_EXECUTION); // Note that watchForLoad can immediately call notifyFinished. m_pendingScript.watchForLoad(this); } else { // Reset line numbering for nested writes. TextPosition position = elementDocument.isInDocumentWrite() ? TextPosition() : scriptStartPosition; KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInserted) ? elementDocument.url() : KURL(); if (!executeScript(ScriptSourceCode(scriptContent(), scriptURL, position))) { dispatchErrorEvent(); return false; } } return true; }
TextPosition DebuggerCallFrame::positionForCallFrame(CallFrame* callFrame) { LineAndColumnFunctor functor; callFrame->iterate(functor); return TextPosition(OrdinalNumber::fromOneBasedInt(functor.line()), OrdinalNumber::fromOneBasedInt(functor.column())); }
// http://dev.w3.org/html5/spec/Overview.html#prepare-a-script bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, LegacyTypeSupport supportLegacyTypes) { if (m_alreadyStarted) return false; ScriptLoaderClient* client = this->client(); bool wasParserInserted; if (m_parserInserted) { wasParserInserted = true; m_parserInserted = false; } else { wasParserInserted = false; } if (wasParserInserted && !client->asyncAttributeValue()) m_forceAsync = true; // FIXME: HTML5 spec says we should check that all children are either // comments or empty text nodes. if (!client->hasSourceAttribute() && !m_element->hasChildren()) return false; if (!m_element->isConnected()) return false; if (!isScriptTypeSupported(supportLegacyTypes)) return false; if (wasParserInserted) { m_parserInserted = true; m_forceAsync = false; } m_alreadyStarted = true; // FIXME: If script is parser inserted, verify it's still in the original // document. Document& elementDocument = m_element->document(); Document* contextDocument = elementDocument.contextDocument(); if (!contextDocument || !contextDocument->allowExecutingScripts(m_element)) return false; if (!isScriptForEventSupported()) return false; if (!client->charsetAttributeValue().isEmpty()) m_characterEncoding = client->charsetAttributeValue(); else m_characterEncoding = elementDocument.characterSet(); if (client->hasSourceAttribute()) { FetchRequest::DeferOption defer = FetchRequest::NoDefer; if (!m_parserInserted || client->asyncAttributeValue() || client->deferAttributeValue()) defer = FetchRequest::LazyLoad; if (m_documentWriteIntervention == DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) defer = FetchRequest::IdleLoad; if (!fetchScript(client->sourceAttributeValue(), defer)) return false; } // Since the asynchronous, low priority fetch for doc.written blocked // script is not for execution, return early from here. Watch for its // completion to be able to remove it from the memory cache. if (m_documentWriteIntervention == DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) { m_pendingScript = PendingScript::create(m_element, m_resource.get()); m_pendingScript->watchForLoad(this); return true; } if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parserInserted && !client->asyncAttributeValue()) { m_willExecuteWhenDocumentFinishedParsing = true; m_willBeParserExecuted = true; } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyncAttributeValue()) { m_willBeParserExecuted = true; } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocument.isScriptExecutionReady()) { m_willBeParserExecuted = true; m_readyToBeParserExecuted = true; } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && !m_forceAsync) { m_pendingScript = PendingScript::create(m_element, m_resource.get()); m_asyncExecType = ScriptRunner::InOrder; contextDocument->scriptRunner()->queueScriptForExecution(this, m_asyncExecType); // Note that watchForLoad can immediately call notifyFinished. m_pendingScript->watchForLoad(this); } else if (client->hasSourceAttribute()) { m_pendingScript = PendingScript::create(m_element, m_resource.get()); m_asyncExecType = ScriptRunner::Async; LocalFrame* frame = m_element->document().frame(); if (frame) { ScriptState* scriptState = ScriptState::forMainWorld(frame); if (scriptState) ScriptStreamer::startStreaming( m_pendingScript.get(), ScriptStreamer::Async, frame->settings(), scriptState, frame->frameScheduler()->loadingTaskRunner()); } contextDocument->scriptRunner()->queueScriptForExecution(this, m_asyncExecType); // Note that watchForLoad can immediately call notifyFinished. m_pendingScript->watchForLoad(this); } else { // Reset line numbering for nested writes. TextPosition position = elementDocument.isInDocumentWrite() ? TextPosition() : scriptStartPosition; KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInserted) ? elementDocument.url() : KURL(); if (!executeScript( ScriptSourceCode(scriptContent(), scriptURL, position))) { dispatchErrorEvent(); return false; } } return true; }
TextPosition ScriptController::eventHandlerPosition() const { notImplemented(); return TextPosition(); }
void Button::SetText(std::string buttonText) { ButtonText = buttonText; TextPosition(); }
void Button::Draw(const Point& screenPos) { if(!drawn) { TextPosition(); drawn = true; } Graphics * g = ui::Engine::Ref().g; Point Position = screenPos; ui::Colour bgColour(0, 0, 0); ui::Colour textColour = Appearance.TextInactive; ui::Colour borderColour = Appearance.BorderInactive; ui::Colour backgroundColour = Appearance.BackgroundInactive; if(Enabled) { if(isButtonDown || (isTogglable && toggle)) { textColour = Appearance.TextActive; borderColour = Appearance.BorderActive; backgroundColour = Appearance.BackgroundActive; } else if (isMouseInside) { textColour = Appearance.TextHover; borderColour = Appearance.BorderHover; backgroundColour = Appearance.BackgroundHover; } else { textColour = Appearance.TextInactive; borderColour = Appearance.BorderInactive; backgroundColour = Appearance.BackgroundInactive; } } else { textColour = Appearance.TextDisabled; borderColour = Appearance.BorderDisabled; backgroundColour = Appearance.BackgroundDisabled; } bgColour = Appearance.BackgroundInactive; g->fillrect(Position.X+1, Position.Y+1, Size.X-2, Size.Y-2, backgroundColour.Red, backgroundColour.Green, backgroundColour.Blue, backgroundColour.Alpha); if(Appearance.Border == 1) g->drawrect(Position.X, Position.Y, Size.X, Size.Y, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha); else { if(Appearance.Border.Top) g->draw_line(Position.X, Position.Y, Position.X+Size.X-1, Position.Y, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha); if(Appearance.Border.Bottom) g->draw_line(Position.X, Position.Y+Size.Y-1, Position.X+Size.X-1, Position.Y+Size.Y-1, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha); if(Appearance.Border.Left) g->draw_line(Position.X, Position.Y, Position.X, Position.Y+Size.Y-1, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha); if(Appearance.Border.Right) g->draw_line(Position.X+Size.X-1, Position.Y, Position.X+Size.X-1, Position.Y+Size.Y-1, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha); } g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, buttonDisplayText, textColour.Red, textColour.Green, textColour.Blue, textColour.Alpha); bool iconInvert = (backgroundColour.Blue + (3*backgroundColour.Green) + (2*backgroundColour.Red))>544?true:false; if(Appearance.icon) { if(Enabled) if(isButtonDown || (isTogglable && toggle)) { g->draw_icon(Position.X+iconPosition.X, Position.Y+iconPosition.Y, Appearance.icon, 255, iconInvert); } else { g->draw_icon(Position.X+iconPosition.X, Position.Y+iconPosition.Y, Appearance.icon, 255, iconInvert); } else g->draw_icon(Position.X+iconPosition.X, Position.Y+iconPosition.Y, Appearance.icon, 180, iconInvert); } }
void Button::SetIcon(Icon icon) { Appearance.icon = icon; TextPosition(); }
// http://dev.w3.org/html5/spec/Overview.html#prepare-a-script bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, LegacyTypeSupport supportLegacyTypes) { if (m_alreadyStarted) return false; ScriptLoaderClient* client = this->client(); bool wasParserInserted; if (m_parserInserted) { wasParserInserted = true; m_parserInserted = false; } else { wasParserInserted = false; } if (wasParserInserted && !client->asyncAttributeValue()) m_forceAsync = true; // FIXME: HTML5 spec says we should check that all children are either comments or empty text nodes. if (!client->hasSourceAttribute() && !m_element->firstChild()) return false; if (!m_element->inDocument()) return false; if (!isScriptTypeSupported(supportLegacyTypes)) return false; if (wasParserInserted) { m_parserInserted = true; m_forceAsync = false; } m_alreadyStarted = true; // FIXME: If script is parser inserted, verify it's still in the original document. Document& elementDocument = m_element->document(); Document* contextDocument = elementDocument.contextDocument().get(); if (!contextDocument || !contextDocument->allowExecutingScripts(m_element)) return false; if (!isScriptForEventSupported()) return false; if (!client->charsetAttributeValue().isEmpty()) m_characterEncoding = client->charsetAttributeValue(); else m_characterEncoding = elementDocument.charset(); if (client->hasSourceAttribute()) { if (!fetchScript(client->sourceAttributeValue())) return false; } if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parserInserted && !client->asyncAttributeValue()) { m_willExecuteWhenDocumentFinishedParsing = true; m_willBeParserExecuted = true; } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyncAttributeValue()) { m_willBeParserExecuted = true; } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocument.isRenderingReady()) { m_willBeParserExecuted = true; m_readyToBeParserExecuted = true; } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && !m_forceAsync) { m_willExecuteInOrder = true; contextDocument->scriptRunner()->queueScriptForExecution(this, m_resource, ScriptRunner::IN_ORDER_EXECUTION); m_resource->addClient(this); } else if (client->hasSourceAttribute()) { contextDocument->scriptRunner()->queueScriptForExecution(this, m_resource, ScriptRunner::ASYNC_EXECUTION); m_resource->addClient(this); } else { // Reset line numbering for nested writes. TextPosition position = elementDocument.isInDocumentWrite() ? TextPosition() : scriptStartPosition; KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInserted) ? elementDocument.url() : KURL(); executeScript(ScriptSourceCode(scriptContent(), scriptURL, position)); } return true; }
// ECMA 15.3.2 The Function Constructor JSObject* constructFunction(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, FunctionConstructionMode functionConstructionMode, JSValue newTarget) { return constructFunction(exec, globalObject, args, exec->propertyNames().anonymous, String(), TextPosition(), functionConstructionMode, newTarget); }
// http://dev.w3.org/html5/spec/Overview.html#prepare-a-script bool ScriptElement::prepareScript(const TextPosition& scriptStartPosition, LegacyTypeSupport supportLegacyTypes) { if (m_alreadyStarted) return false; bool wasParserInserted; if (m_parserInserted) { wasParserInserted = true; m_parserInserted = false; } else wasParserInserted = false; if (wasParserInserted && !asyncAttributeValue()) m_forceAsync = true; // FIXME: HTML5 spec says we should check that all children are either comments or empty text nodes. if (!hasSourceAttribute() && !m_element->firstChild()) return false; if (!m_element->inDocument()) return false; if (!isScriptTypeSupported(supportLegacyTypes)) return false; if (wasParserInserted) { m_parserInserted = true; m_forceAsync = false; } m_alreadyStarted = true; // FIXME: If script is parser inserted, verify it's still in the original document. Document* document = m_element->document(); // FIXME: Eventually we'd like to evaluate scripts which are inserted into a // viewless document but this'll do for now. // See http://bugs.webkit.org/show_bug.cgi?id=5727 if (!document->frame()) return false; if (!document->frame()->script()->canExecuteScripts(AboutToExecuteScript)) return false; if (!isScriptForEventSupported()) return false; if (!charsetAttributeValue().isEmpty()) m_characterEncoding = charsetAttributeValue(); else m_characterEncoding = document->charset(); if (hasSourceAttribute()) if (!requestScript(sourceAttributeValue())) return false; if (hasSourceAttribute() && deferAttributeValue() && m_parserInserted && !asyncAttributeValue()) { m_willExecuteWhenDocumentFinishedParsing = true; m_willBeParserExecuted = true; } else if (hasSourceAttribute() && m_parserInserted && !asyncAttributeValue()) m_willBeParserExecuted = true; else if (!hasSourceAttribute() && m_parserInserted && !document->haveStylesheetsLoaded()) { m_willBeParserExecuted = true; m_readyToBeParserExecuted = true; } else if (hasSourceAttribute() && !asyncAttributeValue() && !m_forceAsync) { m_willExecuteInOrder = true; document->scriptRunner()->queueScriptForExecution(this, m_cachedScript, ScriptRunner::IN_ORDER_EXECUTION); m_cachedScript->addClient(this); } else if (hasSourceAttribute()) { m_element->document()->scriptRunner()->queueScriptForExecution(this, m_cachedScript, ScriptRunner::ASYNC_EXECUTION); m_cachedScript->addClient(this); } else { // Reset line numbering for nested writes. TextPosition position = document->isInDocumentWrite() ? TextPosition() : scriptStartPosition; executeScript(ScriptSourceCode(scriptContent(), document->url(), position)); } return true; }
//------------------------------------------------------------------------------ void ofApp::update() { unsigned long long now = ofGetElapsedTimeMillis(); grabber.update(); if(grabber.isFrameNew()) { ofPixelsRef pixels = grabber.getPixelsRef(); sensorColorRaw = pixels.getColor(sensor.x,sensor.y); sensorColorBrightness = sensorColorRaw.getBrightness(); brightnessHistory.push_back(sensorColorBrightness); if(brightnessHistory.size() > 1) { float currentValue = brightnessHistory[brightnessHistory.size()-1]; float lastValue = brightnessHistory[brightnessHistory.size()-2]; if(currentValue < brightnessThreshold && lastValue >= brightnessThreshold) { unsigned long long highDuration = now - lastCrossing; // was it a dot or a dash? // because of the camera's after image, we reverse the search if(highDuration > dtDash) { letterBuffer += "-"; } else { letterBuffer += "."; } isHigh = false; lastCrossing = now; } else if(currentValue >= brightnessThreshold && lastValue < brightnessThreshold) { unsigned long long lowDuration = now - lastCrossing; if(lowDuration < dtPauseLetter) { // inside the word } else if(lowDuration < dtPauseWord) { std::string letter = morseDecode(letterBuffer); resolvedLetters.push_back(TextPosition(letter,0)); wordBuffer += letter; letterBuffer.clear(); } else { std::string letter = morseDecode(letterBuffer); resolvedLetters.push_back(TextPosition(letter,0)); wordBuffer += letter; letterBuffer.clear(); resolvedWords.push_back(TextPosition(wordBuffer,0)); wordBuffer.clear(); } isHigh = true; lastCrossing = now; } else { // not interested in this point. } } volume = isHigh ? 1 : 0; while(brightnessHistory.size() > historyBarWidth) { brightnessHistory.pop_front(); } std::vector<TextPosition>::iterator letterIter = resolvedLetters.begin(); while (letterIter != resolvedLetters.end()) { if ((*letterIter).x > ofGetWidth()) { cout << "Ersing resolved letter " << endl; letterIter = resolvedLetters.erase(letterIter); } else { (*letterIter).x++; ++letterIter; } } std::vector<TextPosition>::iterator wordIter = resolvedWords.begin(); while (wordIter != resolvedWords.end()) { if ((*wordIter).x > ofGetWidth()) { wordIter = resolvedWords.erase(wordIter); } else { (*wordIter).x++; ++wordIter; } } } }