diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 35e304e0..0075e835 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,10 @@ if(APPLE) add_subdirectory(cocoa) endif() +# TODO: Remove this and integrate these files' functionality into unit tests +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/TEST") +add_subdirectory(TEST) + add_subdirectory(prototype) if(AXR_BUILD_EXAMPLES) diff --git a/src/core/debug/AXRTestProducer.cpp b/src/TEST/AXRTestProducer.cpp similarity index 88% rename from src/core/debug/AXRTestProducer.cpp rename to src/TEST/AXRTestProducer.cpp index 2aa642ef..5838141d 100644 --- a/src/core/debug/AXRTestProducer.cpp +++ b/src/TEST/AXRTestProducer.cpp @@ -44,11 +44,12 @@ #include "AXRDebugging.h" #include "AXRInitializer.h" #include "AXRTestProducer.h" +#include "AXRTestRunner.h" using namespace AXR; // Constructor with name and the queue to use -AXRTestProducer::AXRTestProducer(AXRWrapper * wrapper, std::vector test, unsigned * totalTests, unsigned * totalPassed, HSSContainer::p status) +AXRTestProducer::AXRTestProducer(AXRTestRunner * wrapper, std::vector test, unsigned * totalTests, unsigned * totalPassed, HSSContainer::p status) { this->wrapper = wrapper; this->test = test; @@ -75,15 +76,12 @@ void AXRTestProducer::operator () () AXRString expectedRep; //load the XML - AXRCore core = *AXRCore::getInstance(); - AXRWrapper * wrapper = this->wrapper; - core = *AXRCore::getInstance(); + AXRCore *core = AXRCore::getInstance(); - testLoaded = wrapper->loadXMLFile(this->test[0]); + testLoaded = core->loadXMLFile(this->test[0]); if (testLoaded) { - AXRCore* core = AXRCore::getInstance(); AXRController::p controller = core->getController(); HSSContainer::p root = controller->getRoot(); core->getRender()->windowWidth = 400.; @@ -101,7 +99,7 @@ void AXRTestProducer::operator () () //load the "expected" file if (testLoaded) { - AXRBuffer::p expectedFile = this->wrapper->getFile(test[1]); + AXRBuffer::p expectedFile = core->getFile(test[1]); if (!expectedFile->isValid()) { std_log("could not load file with expected results"); @@ -127,7 +125,7 @@ void AXRTestProducer::operator () () this->statusMutex.lock(); this->status->setContentText(AXRString("Passed %1 out of %2").arg(*this->totalPassed).arg(*this->totalTests)); this->statusMutex.unlock(); - this->wrapper->setNeedsDisplay(true); + core->setNeedsDisplay(true); } else { diff --git a/src/core/debug/AXRTestProducer.h b/src/TEST/AXRTestProducer.h similarity index 91% rename from src/core/debug/AXRTestProducer.h rename to src/TEST/AXRTestProducer.h index 7e1c3195..f82f891e 100644 --- a/src/core/debug/AXRTestProducer.h +++ b/src/TEST/AXRTestProducer.h @@ -51,12 +51,12 @@ namespace AXR { - class AXRWrapper; + class AXRTestRunner; class AXR_API AXRTestProducer : public QRunnable { private: - AXRWrapper * wrapper; + AXRTestRunner * wrapper; std::vector test; // the filename of the test unsigned * totalTests; unsigned * totalPassed; @@ -66,7 +66,7 @@ namespace AXR static QMutex statusMutex; public: - AXRTestProducer(AXRWrapper * wrapper, std::vector test, unsigned * totalTests, unsigned * totalPassed, HSSContainer::p status); + AXRTestProducer(AXRTestRunner *testRunner, std::vector test, unsigned * totalTests, unsigned * totalPassed, HSSContainer::p status); void operator () (); void run(); }; diff --git a/src/TEST/AXRTestRunner.cpp b/src/TEST/AXRTestRunner.cpp new file mode 100644 index 00000000..d212a125 --- /dev/null +++ b/src/TEST/AXRTestRunner.cpp @@ -0,0 +1,102 @@ +/******************************************************************** + * a A + * AM\/MA + * (MA:MMD + * :: VD + * :: º + * :: + * :: ** .A$MMMMND AMMMD AMMM6 MMMM MMMM6 + + 6::Z. TMMM MMMMMMMMMDA VMMMD AMMM6 MMMMMMMMM6 + * 6M:AMMJMMOD V MMMA VMMMD AMMM6 MMMMMMM6 + * :: TMMTMC ___MMMM VMMMMMMM6 MMMM + * MMM TMMMTTM, AMMMMMMMM VMMMMM6 MMMM + * :: MM TMMTMMMD MMMMMMMMMM MMMMMM MMMM + * :: MMMTTMMM6 MMMMMMMMMMM AMMMMMMD MMMM + * :. MMMMMM6 MMMM MMMM AMMMMMMMMD MMMM + * TTMMT MMMM MMMM AMMM6 MMMMD MMMM + * TMMMM8 MMMMMMMMMMM AMMM6 MMMMD MMMM + * TMMMMMM$ MMMM6 MMMM AMMM6 MMMMD MMMM + * TMMM MMMM + * TMMM .MMM + * TMM .MMD ARBITRARY·······XML········RENDERING + * TMM MMA ==================================== + * TMN MM + * MN ZM + * MM, + * + * + * AUTHORS: see AUTHORS file + * + * COPYRIGHT: ©2012 - All Rights Reserved + * + * LICENSE: see LICENSE file + * + * WEB: http://axr.vg + * + * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR + * FITNESS FOR A PARTICULAR PURPOSE. + * + ********************************************************************/ + +#include +#include +#include +#include +#include "AXRDebugging.h" +#include "AXRInitializer.h" +#include "AXRTestThread.h" +#include "AXRTestRunner.h" +#include "AXRWarning.h" +#include "HSSFunction.h" +#include "HSSSelFunction.h" + +using namespace AXR; + +AXRTestRunner::AXRTestRunner() +{ +} + +AXRTestRunner::~AXRTestRunner() +{ +} + +AXRString AXRTestRunner::getPathToTestsFile() +{ + QDir dir = QDir(QCoreApplication::applicationDirPath()); +#ifdef Q_WS_MACX + dir.cdUp(); +#endif + dir.cd("Resources"); + dir.cd("views"); + return dir.filePath("layoutTests.hss"); +} + +void AXRTestRunner::executeLayoutTests(HSSObservableProperty passnull, void*data) +{ + HSSContainer::p status; + AXRCore* core = AXRCore::getInstance(); + HSSContainer::p root = core->getController()->getRoot(); + std::deque arguments = *(std::deque*)data; + + for (std::deque::iterator it = arguments.begin(); it != arguments.end(); ++it) + { + HSSParserNode::p argument = *it; + if (argument->isA(HSSFunctionTypeSel)) + { + HSSSelFunction::p selFunction = qSharedPointerCast(argument); + QVariant remoteValue = selFunction->evaluate(); + if (remoteValue.canConvert > >()) + { + std::vector< std::vector > selection = remoteValue.value > >(); + std::vector innerSelection = selection[0]; + status = HSSContainer::asContainer(innerSelection[0]); + } + } + } + + AXRTestThread thrd(this, QUrl::fromLocalFile(this->getPathToTestsFile()), status); + thrd.start(); +} diff --git a/src/TEST/AXRTestRunner.h b/src/TEST/AXRTestRunner.h new file mode 100644 index 00000000..ca14c9b4 --- /dev/null +++ b/src/TEST/AXRTestRunner.h @@ -0,0 +1,85 @@ +/******************************************************************** + * a A + * AM\/MA + * (MA:MMD + * :: VD + * :: º + * :: + * :: ** .A$MMMMND AMMMD AMMM6 MMMM MMMM6 + + 6::Z. TMMM MMMMMMMMMDA VMMMD AMMM6 MMMMMMMMM6 + * 6M:AMMJMMOD V MMMA VMMMD AMMM6 MMMMMMM6 + * :: TMMTMC ___MMMM VMMMMMMM6 MMMM + * MMM TMMMTTM, AMMMMMMMM VMMMMM6 MMMM + * :: MM TMMTMMMD MMMMMMMMMM MMMMMM MMMM + * :: MMMTTMMM6 MMMMMMMMMMM AMMMMMMD MMMM + * :. MMMMMM6 MMMM MMMM AMMMMMMMMD MMMM + * TTMMT MMMM MMMM AMMM6 MMMMD MMMM + * TMMMM8 MMMMMMMMMMM AMMM6 MMMMD MMMM + * TMMMMMM$ MMMM6 MMMM AMMM6 MMMMD MMMM + * TMMM MMMM + * TMMM .MMM + * TMM .MMD ARBITRARY·······XML········RENDERING + * TMM MMA ==================================== + * TMN MM + * MN ZM + * MM, + * + * + * AUTHORS: see AUTHORS file + * + * COPYRIGHT: ©2012 - All Rights Reserved + * + * LICENSE: see LICENSE file + * + * WEB: http://axr.vg + * + * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR + * FITNESS FOR A PARTICULAR PURPOSE. + * + ********************************************************************/ + +#ifndef AXRWRAPPER_H +#define AXRWRAPPER_H + +#include +#include +#include +#include +#include +#include "AXRError.h" +#include "AXRBuffer.h" +#include "HSSContainer.h" +#include "HSSObservableProperties.h" + +namespace AXR +{ + /** + * @brief This is the abstract superclass from with all OS-specific wrappers + * should inherit from. + */ + class AXR_API AXRTestRunner + { + public: + /** + * Creates a new instance of the wrapper. It will obtain the singleton instance of + * the AXRCore and initialize it. + */ + AXRTestRunner(); + + /** + * Destructs the wrapper + */ + virtual ~AXRTestRunner(); + + virtual AXRString getPathToTestsFile(); + + void executeLayoutTests(HSSObservableProperty passnull, void*data); + + QMap files; + }; +} + +#endif diff --git a/src/core/debug/AXRTestThread.cpp b/src/TEST/AXRTestThread.cpp similarity index 95% rename from src/core/debug/AXRTestThread.cpp rename to src/TEST/AXRTestThread.cpp index b869ab93..d38e2d8b 100644 --- a/src/core/debug/AXRTestThread.cpp +++ b/src/TEST/AXRTestThread.cpp @@ -44,11 +44,13 @@ #include "AXRDebugging.h" #include "AXRInitializer.h" #include "AXRTestProducer.h" +#include "AXRTestRunner.h" #include "AXRTestThread.h" +#include "HSSContainer.h" using namespace AXR; -AXRTestThread::AXRTestThread(AXRWrapper * wrapper, QUrl url, HSSContainer::p status) +AXRTestThread::AXRTestThread(AXRTestRunner * wrapper, QUrl url, HSSContainer::p status) { this->wrapper = wrapper; this->url = url; @@ -67,11 +69,10 @@ void AXRTestThread::operator () () try { //load the XML file - AXRWrapper * wrapper = this->wrapper; AXRCore* core = AXRCore::getInstance(); XMLParser::p parser = core->getParserXML(); HSSContainer::p status = this->status; - AXRBuffer::p testsFile = wrapper->getFile(this->url); + AXRBuffer::p testsFile = core->getFile(this->url); bool loadingSuccess = parser->loadFile(testsFile); if (loadingSuccess) { diff --git a/src/core/debug/AXRTestThread.h b/src/TEST/AXRTestThread.h similarity index 93% rename from src/core/debug/AXRTestThread.h rename to src/TEST/AXRTestThread.h index c8b1c9da..81813883 100644 --- a/src/core/debug/AXRTestThread.h +++ b/src/TEST/AXRTestThread.h @@ -50,19 +50,19 @@ namespace AXR { - class AXRWrapper; + class AXRTestRunner; class AXR_API AXRTestThread : public QThread { private: - AXRWrapper * wrapper; + AXRTestRunner *wrapper; QUrl url; unsigned totalTests; unsigned totalPassed; HSSContainer::p status; public: - AXRTestThread(AXRWrapper * wrapper, QUrl url, HSSContainer::p status); + AXRTestThread(AXRTestRunner *testRunner, QUrl url, HSSContainer::p status); void operator () (); void run(); }; diff --git a/src/TEST/CMakeLists.txt b/src/TEST/CMakeLists.txt new file mode 100644 index 00000000..b140a6b4 --- /dev/null +++ b/src/TEST/CMakeLists.txt @@ -0,0 +1,25 @@ +if(BUILD_SHARED_LIBS) + add_definitions(-DAXR_EXPORTS) +endif() + +# Find all sources +file(GLOB_RECURSE test_SOURCES *.c *.cpp *.h) +list(SORT test_SOURCES) + +group_by_folder(${CMAKE_CURRENT_SOURCE_DIR} "${test_SOURCES}") + +add_library(TEST ${test_SOURCES}) +target_link_libraries(TEST ${TARGET_NAME_LIB_CORE}) +set_target_properties(TEST PROPERTIES FOLDER Libraries) + +if(APPLE AND BUILD_SHARED_LIBS AND AXR_BUILD_FRAMEWORKS) + set_target_properties(TEST PROPERTIES FRAMEWORK TRUE) +endif() + +if(IS_RELEASE_BUILD) + install(TARGETS TEST + LIBRARY DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_REL} COMPONENT libraries + ARCHIVE DESTINATION ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_REL} COMPONENT libraries + FRAMEWORK DESTINATION Frameworks COMPONENT frameworks + ) +endif() diff --git a/src/core/axr/AXRInitializer.cpp b/src/core/axr/AXRInitializer.cpp index 16d6efce..18c2b0be 100644 --- a/src/core/axr/AXRInitializer.cpp +++ b/src/core/axr/AXRInitializer.cpp @@ -41,9 +41,11 @@ * ********************************************************************/ +#include #include #include "AXRDebugging.h" #include "AXRInitializer.h" +#include "AXRWarning.h" using namespace AXR; @@ -60,20 +62,22 @@ AXRCore* AXRCore::getInstance() AXRCore::AXRCore() { + this->_isHSSOnly = false; + this->_hasLoadedFile = false; + this->_showLayoutSteps = false; + this->_currentLayoutStep = 0; + this->_currentLayoutTick = 0; + this->_currentLayoutChild = 0; + this->_needsDisplay = true; -} - -void AXRCore::initialize(AXRWrapper * wrpr) -{ axr_log(AXR_DEBUG_CH_GENERAL | AXR_DEBUG_CH_GENERAL_SPECIFIC, "AXRCore: initializing core for thread"); AXRController::p ctrlr = AXRController::p(new AXRController()); AXRRender::p rndr = AXRRender::p(new AXRRender(ctrlr.data())); - this->setWrapper(wrpr); this->setController(ctrlr); this->setRender(rndr); this->setParserXML(XMLParser::p(new XMLParser(ctrlr.data()))); - this->setParserHSS(HSSParser::p(new HSSParser(ctrlr.data(), wrpr))); + this->setParserHSS(HSSParser::p(new HSSParser(ctrlr.data()))); this->_hasLoadedFile = false; } @@ -90,15 +94,27 @@ void AXRCore::drawInRectWithBounds(HSSRect rect, HSSRect bounds) } } +AXRString AXRCore::getPathToResources() const +{ + // TODO: it's best to do this in a different way entirely... the library + // shouldn't be using the client process's directory to determine where + // to load resources from. For example, two different browsers will be + // at different file paths, while the resources path will be independent + // of either of them. Perhaps an AXR configuration file at a standard + // location? /etc/axr.conf on Unix and %WINDIR%/axr.ini on Windows? + QDir dir(QCoreApplication::applicationDirPath()); +#ifdef Q_WS_MACX + dir.cdUp(); + dir.cd("Resources"); +#endif + dir.cd("resources"); + return dir.canonicalPath(); +} + void AXRCore::run() { axr_log(AXR_DEBUG_CH_OVERVIEW, "AXRCore: running"); - //check for wrapper - if (!this->getWrapper()) - { - AXRError("AXRCore", "The wrapper was not defined").raise(); - return; - } + bool loadingSuccess = this->parserXML->loadFile(this->file); axr_log(AXR_DEBUG_CH_OVERVIEW, "AXRCore: finished parsing " + this->file->sourceUrl().toString()); @@ -121,7 +137,7 @@ void AXRCore::run() AXRBuffer::p hssfile; try { - hssfile = this->wrapper->getFile(loadSheets[i]); + hssfile = this->getFile(loadSheets[i]); } catch (const AXRError &e) { @@ -168,16 +184,6 @@ bool AXRCore::hasLoadedFile() return _hasLoadedFile; } -AXRWrapper * AXRCore::getWrapper() -{ - return this->wrapper; -} - -void AXRCore::setWrapper(AXRWrapper * wrapper) -{ - this->wrapper = wrapper; -} - AXRController::p AXRCore::getController() { return this->controller; @@ -246,3 +252,289 @@ void AXRCore::evaluateCustomFunction(AXRString name, void* data) this->_customFunctions[name]->call(HSSObservablePropertyValue, data); } } + +AXRBuffer::p AXRCore::getFile(QUrl u) +{ + if (u.isValid()) + { + if (u.scheme() == "file") + { + QFileInfo fi(u.toLocalFile()); + AXRBuffer::p ret = AXRBuffer::p(new AXRBuffer(fi)); + if (!fi.exists()) + { + throw AXRError("AXRWrapper", "the file " + u.toLocalFile() + " doesn't exist"); + } + else if (!ret->isValid()) + { + throw AXRError("AXRWrapper", "the file " + u.toLocalFile() + " couldn't be read"); + } + + return ret; + } + else if (u.scheme() == "http" || u.scheme() == "https") + { + std_log("http is not implemented yet"); + } + } + + return AXRBuffer::p(new AXRBuffer()); +} + +bool AXRCore::needsDisplay() const +{ + return this->_needsDisplay; +} + +void AXRCore::setNeedsDisplay(bool newValue) +{ + this->_needsDisplay = newValue; +} + +AXRBuffer::p AXRCore::createDummyXML(QUrl hssUrl) +{ + axr_log(AXR_DEBUG_CH_OVERVIEW, "AXRWrapper: creating dummy XML file for HSS file " + hssUrl.toString()); + + if (hssUrl.isValid()) + { + AXRString dummyXML = ""; + return AXRBuffer::p(new AXRBuffer(dummyXML.toUtf8())); + } + else + { + AXRError("AXRWrapper", "Could not create dummy XML for invalid HSS file URL").raise(); + return AXRBuffer::p(new AXRBuffer()); + } +} + +bool AXRCore::loadFileByPath(QUrl url) +{ + if (url.isRelative()) + { + if (url.isLocalFile()) + { + url = QUrl::fromLocalFile(QFileInfo(url.path()).canonicalFilePath()); + } + else + { + AXRError("AXRWrapper", "Could not load relative URL as main file", url).raise(); + return false; + } + } + + axr_log(AXR_DEBUG_CH_OVERVIEW, "AXRWrapper: loading file " + url.toString()); + axr_log(AXR_DEBUG_CH_FULL_FILENAMES, url.toString()); + + QFileInfo pathInfo(url.path()); + if (pathInfo.suffix() == "xml") + { + this->_isHSSOnly = false; + return this->loadXMLFile(url); + } + else if (pathInfo.suffix() == "hss") + { + return this->loadHSSFile(url); + } + else + { + AXRError("AXRController", "Unknown file extension").raise(); + return false; + } +} + +bool AXRCore::loadXMLFile(QUrl url) +{ + axr_log(AXR_DEBUG_CH_OVERVIEW, AXRString("AXRWrapper: opening XML document: %1").arg(url.toString())); + + this->_isHSSOnly = false; + this->_showLayoutSteps = false; + this->_currentLayoutStep = 0; + this->_currentLayoutTick = 0; + this->_currentLayoutChild = 0; + + AXRCore* core = AXRCore::getInstance(); + if (core->getFile()) + { + core->reset(); + } + + try + { + AXRBuffer::p theFile = this->getFile(url); + core->setFile(theFile); + } + catch (const AXRError &e) + { + e.raise(); + return false; + } + + try + { + core->run(); + } + catch (const AXRError &e) + { + e.raise(); + } + + this->setNeedsDisplay(true); + + return true; +} + +bool AXRCore::loadXMLFile(AXRBuffer::p buffer) +{ + axr_log(AXR_DEBUG_CH_OVERVIEW, AXRString("AXRWrapper: opening XML document from buffer")); + + this->_isHSSOnly = false; + this->_showLayoutSteps = false; + this->_currentLayoutStep = 0; + this->_currentLayoutTick = 0; + this->_currentLayoutChild = 0; + + AXRCore* core = AXRCore::getInstance(); + if (core->getFile()) + { + core->reset(); + } + + try + { + core->setFile(buffer); + } + catch (const AXRError &e) + { + e.raise(); + return false; + } + + try + { + core->run(); + } + catch (const AXRError &e) + { + e.raise(); + } + + this->setNeedsDisplay(true); + + return true; +} + +bool AXRCore::reload() +{ + this->_showLayoutSteps = false; + this->_currentLayoutStep = 0; + this->_currentLayoutTick = 0; + this->_currentLayoutChild = 0; + + AXRCore* core = AXRCore::getInstance(); + if (!this->_isHSSOnly) + { + if (core->getFile()) + { + return this->loadXMLFile(core->getFile()->sourceUrl()); + } + else + { + AXRWarning("AXRWrapper", "no file loaded").raise(); + return false; + } + } + else + { + return this->loadHSSFile(core->getController()->loadSheetsGet(0)); + } +} + +bool AXRCore::loadHSSFile(QUrl url) +{ + axr_log(AXR_DEBUG_CH_OVERVIEW, AXRString("AXRWrapper: opening HSS document: %1").arg(url.toString())); + + this->_isHSSOnly = true; + this->_showLayoutSteps = false; + this->_currentLayoutStep = 0; + this->_currentLayoutTick = 0; + this->_currentLayoutChild = 0; + + AXRCore* core = AXRCore::getInstance(); + if (core->getFile()) + { + core->reset(); + } + + core->setFile(this->createDummyXML(url)); + core->run(); + this->setNeedsDisplay(true); + + return true; +} + +void AXRCore::setShowLayoutSteps(bool value) +{ + this->_showLayoutSteps = value; +} + +bool AXRCore::showLayoutSteps() +{ + return this->_showLayoutSteps; +} + +void AXRCore::previousLayoutStep() +{ + if (this->_currentLayoutStep > 0) + { + this->_currentLayoutStep -= 1; + } + + this->_currentLayoutTick = 0; + this->_currentLayoutChild = 0; + this->setNeedsDisplay(true); +} + +void AXRCore::nextLayoutStep() +{ + this->_currentLayoutStep += 1; + this->_currentLayoutTick = 0; + this->_currentLayoutChild = 0; + this->setNeedsDisplay(true); +} + +void AXRCore::nextLayoutTick() +{ + this->_currentLayoutTick += 1; +} + +void AXRCore::resetLayoutTicks() +{ + this->_currentLayoutTick = 0; +} + +bool AXRCore::layoutStepDone() +{ + return this->_currentLayoutTick >= this->_currentLayoutStep; +} + +void AXRCore::breakIfNeeded() +{ + bool breakvar = _currentLayoutTick >= (_currentLayoutStep - 1); + + axr_log(AXR_DEBUG_CH_GENERAL_SPECIFIC, AXRString("currentLayoutTick = %1, currentLayoutStep = %2, %3").arg(_currentLayoutTick).arg(_currentLayoutStep).arg(breakvar)); +} + +void AXRCore::nextLayoutChild() +{ + this->_currentLayoutChild += 1; +} + +void AXRCore::resetLayoutChild() +{ + this->_currentLayoutChild = 0; +} + +bool AXRCore::layoutChildDone() +{ + return this->_currentLayoutTick >= this->_currentLayoutChild + 1; +} diff --git a/src/core/axr/AXRInitializer.h b/src/core/axr/AXRInitializer.h index a1276fef..847a2a3c 100644 --- a/src/core/axr/AXRInitializer.h +++ b/src/core/axr/AXRInitializer.h @@ -157,7 +157,6 @@ #include #include "AXRController.h" #include "AXRRender.h" -#include "AXRWrapper.h" #include "HSSCallback.h" #include "HSSUnits.h" #include "XMLParser.h" @@ -180,15 +179,6 @@ namespace AXR */ static AXRCore* getInstance(); - /** - * Initializes all default values. - * @param wrpr The platform-specific wrapper that is embedding the core library. - * This is a c++ pointer, not a shared one. Since the embedder owns the core, - * no memory management is done whatsoever. - * @warning Needs to be called before the first time the core is used. - * @see AXRWrapper - */ - void initialize(AXRWrapper * wrpr); /** * Destroys the object */ @@ -202,6 +192,12 @@ namespace AXR * the rect parameter is actually ignored. This will be fixed in the near future. */ virtual void drawInRectWithBounds(HSSRect rect, HSSRect bounds); + + /** + * Gets the path to where the HSS framework resource files are stored. + */ + virtual AXRString getPathToResources() const; + /** * After everything is set up, this puts everything in motion: * loads xml, loads hss, applies rules, etc @@ -227,17 +223,6 @@ namespace AXR * @param file The AXRBuffer to store for later use. */ void setFile(AXRBuffer::p file); - /** - * @return a c++ pointer to the AXRWrapper - */ - AXRWrapper * getWrapper(); - /** - * Sets the AXRWrapper that is embedding the core library. - * @param wrapper A c++ pointer to the AXRWrapper subclass instance. Since - * the embedder owns the core, no memory management is done whatsoever. - - */ - void setWrapper(AXRWrapper * wrapper); /** * Getter for shared pointer to the AXRController that is managing the * object tree. @@ -299,8 +284,79 @@ namespace AXR void registerCustomFunction(AXRString name, HSSCallback* fn); void evaluateCustomFunction(AXRString name, void* data); + // From AXRWrapper + public: + /** + * Creates a AXRBuffer representation from the url you provide. + * Subclasses should override this method with the OS specific implementation. + * @param url A string containing the url to the file + */ + virtual AXRBuffer::p getFile(QUrl url); + virtual bool needsDisplay() const; + /** + * This is to be called when something happens that needs to trigger a redraw. + * Subclasses should override this method with the OS specific implementation. + * @param newValue A boolean containing the new state. + */ + virtual void setNeedsDisplay(bool newValue); + + /** + * This creates a string containing a basic XML document with 1 element called "root". + * It is used when a HSS file is loaded directly. + * @return A shared pointer to the AXRBuffer representation of the basic XML document. + */ + AXRBuffer::p createDummyXML(QUrl hssUrl); + /** + * Loads the XML file at the path you provide. + * @param xmlfilepath A string containing the path to the file on the local system. + * @return Wether it has been loaded successfully or not. + */ + bool loadXMLFile(QUrl url); + bool loadXMLFile(AXRBuffer::p buffer); + /** + * Loads the file you provide, and then handles it according to its file extension. + * @param filepath A string containing the path to the file on the local system, can be + * either an XML or an HSS file. + * + * @return Wether it has been loaded successfully or not. + */ + bool loadFileByPath(QUrl url); + /** + * Loads the HSS file at the path you provide. + * @param hssfilepath A string containing the path to the file on the local system. + * @return Wether it has been loaded successfully or not. + */ + bool loadHSSFile(QUrl url); + /** + * Reloads the file that is currently loaded. + * @return Wether it has been reloaded successfully or not. + */ + bool reload(); + + // Layout stuff from AXRWrapper + public: + bool showLayoutSteps(); + void setShowLayoutSteps(bool value); + void previousLayoutStep(); + void nextLayoutStep(); + void nextLayoutTick(); + void resetLayoutTicks(); + bool layoutStepDone(); + void nextLayoutChild(); + void resetLayoutChild(); + bool layoutChildDone(); + void breakIfNeeded(); + + private: + bool _isHSSOnly; + bool _hasLoadedFile; + bool _showLayoutSteps; + unsigned int _currentLayoutStep; + unsigned int _currentLayoutTick; + unsigned int _currentLayoutChild; + bool _needsDisplay; + protected: - AXRWrapper * wrapper; AXRRender::p render; AXRController::p controller; AXRBuffer::p file; @@ -308,7 +364,6 @@ namespace AXR XMLParser::p parserXML; HSSParser::p parserHSS; - bool _hasLoadedFile; QMap _customFunctions; private: diff --git a/src/core/axr/AXRWrapper.cpp b/src/core/axr/AXRWrapper.cpp deleted file mode 100644 index 60c49578..00000000 --- a/src/core/axr/AXRWrapper.cpp +++ /dev/null @@ -1,415 +0,0 @@ -/******************************************************************** - * a A - * AM\/MA - * (MA:MMD - * :: VD - * :: º - * :: - * :: ** .A$MMMMND AMMMD AMMM6 MMMM MMMM6 - + 6::Z. TMMM MMMMMMMMMDA VMMMD AMMM6 MMMMMMMMM6 - * 6M:AMMJMMOD V MMMA VMMMD AMMM6 MMMMMMM6 - * :: TMMTMC ___MMMM VMMMMMMM6 MMMM - * MMM TMMMTTM, AMMMMMMMM VMMMMM6 MMMM - * :: MM TMMTMMMD MMMMMMMMMM MMMMMM MMMM - * :: MMMTTMMM6 MMMMMMMMMMM AMMMMMMD MMMM - * :. MMMMMM6 MMMM MMMM AMMMMMMMMD MMMM - * TTMMT MMMM MMMM AMMM6 MMMMD MMMM - * TMMMM8 MMMMMMMMMMM AMMM6 MMMMD MMMM - * TMMMMMM$ MMMM6 MMMM AMMM6 MMMMD MMMM - * TMMM MMMM - * TMMM .MMM - * TMM .MMD ARBITRARY·······XML········RENDERING - * TMM MMA ==================================== - * TMN MM - * MN ZM - * MM, - * - * - * AUTHORS: see AUTHORS file - * - * COPYRIGHT: ©2012 - All Rights Reserved - * - * LICENSE: see LICENSE file - * - * WEB: http://axr.vg - * - * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR - * FITNESS FOR A PARTICULAR PURPOSE. - * - ********************************************************************/ - -#include -#include -#include -#include -#include "AXRDebugging.h" -#include "AXRInitializer.h" -#include "AXRTestThread.h" -#include "AXRWarning.h" -#include "AXRWrapper.h" -#include "HSSFunction.h" -#include "HSSSelFunction.h" - -using namespace AXR; - -AXRWrapper::AXRWrapper() -{ - axr_log(AXR_DEBUG_CH_GENERAL | AXR_DEBUG_CH_GENERAL_SPECIFIC, "AXRWrapper: creating AXRWrapper"); - this->_isHSSOnly = false; - this->_hasLoadedFile = false; - this->_showLayoutSteps = false; - this->_currentLayoutStep = 0; - this->_currentLayoutTick = 0; - this->_currentLayoutChild = 0; - this->_needsDisplay = true; - AXRCore* axr = AXRCore::getInstance(); - axr->initialize(this); -} - -AXRWrapper::~AXRWrapper() -{ -} - -AXRBuffer::p AXRWrapper::getFile(QUrl u) -{ - if (u.isValid()) - { - if (u.scheme() == "file") - { - QFileInfo fi(u.toLocalFile()); - AXRBuffer::p ret = AXRBuffer::p(new AXRBuffer(fi)); - if (!fi.exists()) - { - throw AXRError("AXRWrapper", "the file " + u.toLocalFile() + " doesn't exist"); - } - else if (!ret->isValid()) - { - throw AXRError("AXRWrapper", "the file " + u.toLocalFile() + " couldn't be read"); - } - - return ret; - } - else if (u.scheme() == "http" || u.scheme() == "https") - { - std_log("http is not implemented yet"); - } - } - - return AXRBuffer::p(new AXRBuffer()); -} - -bool AXRWrapper::needsDisplay() const -{ - return this->_needsDisplay; -} - -void AXRWrapper::setNeedsDisplay(bool newValue) -{ - this->_needsDisplay = newValue; -} - -AXRBuffer::p AXRWrapper::createDummyXML(QUrl hssUrl) -{ - axr_log(AXR_DEBUG_CH_OVERVIEW, "AXRWrapper: creating dummy XML file for HSS file " + hssUrl.toString()); - - if (hssUrl.isValid()) - { - AXRString dummyXML = ""; - return AXRBuffer::p(new AXRBuffer(dummyXML.toUtf8())); - } - else - { - AXRError("AXRWrapper", "Could not create dummy XML for invalid HSS file URL").raise(); - return AXRBuffer::p(new AXRBuffer()); - } -} - -bool AXRWrapper::loadFileByPath(QUrl url) -{ - if (url.isRelative()) - { - if (url.isLocalFile()) - { - url = QUrl::fromLocalFile(QFileInfo(url.path()).canonicalFilePath()); - } - else - { - AXRError("AXRWrapper", "Could not load relative URL as main file", url).raise(); - return false; - } - } - - axr_log(AXR_DEBUG_CH_OVERVIEW, "AXRWrapper: loading file " + url.toString()); - axr_log(AXR_DEBUG_CH_FULL_FILENAMES, url.toString()); - - QFileInfo pathInfo(url.path()); - if (pathInfo.suffix() == "xml") - { - this->_isHSSOnly = false; - return this->loadXMLFile(url); - } - else if (pathInfo.suffix() == "hss") - { - return this->loadHSSFile(url); - } - else - { - AXRError("AXRController", "Unknown file extension").raise(); - return false; - } -} - -bool AXRWrapper::loadXMLFile(QUrl url) -{ - axr_log(AXR_DEBUG_CH_OVERVIEW, AXRString("AXRWrapper: opening XML document: %1").arg(url.toString())); - - this->_isHSSOnly = false; - this->_showLayoutSteps = false; - this->_currentLayoutStep = 0; - this->_currentLayoutTick = 0; - this->_currentLayoutChild = 0; - - AXRCore* core = AXRCore::getInstance(); - if (core->getFile()) - { - core->reset(); - } - - try - { - AXRBuffer::p theFile = this->getFile(url); - core->setFile(theFile); - } - catch (const AXRError &e) - { - e.raise(); - return false; - } - - try - { - core->run(); - } - catch (const AXRError &e) - { - e.raise(); - } - - this->setNeedsDisplay(true); - - return true; -} - -bool AXRWrapper::loadXMLFile(AXRBuffer::p buffer) -{ - axr_log(AXR_DEBUG_CH_OVERVIEW, AXRString("AXRWrapper: opening XML document from buffer")); - - this->_isHSSOnly = false; - this->_showLayoutSteps = false; - this->_currentLayoutStep = 0; - this->_currentLayoutTick = 0; - this->_currentLayoutChild = 0; - - AXRCore* core = AXRCore::getInstance(); - if (core->getFile()) - { - core->reset(); - } - - try - { - core->setFile(buffer); - } - catch (const AXRError &e) - { - e.raise(); - return false; - } - - try - { - core->run(); - } - catch (const AXRError &e) - { - e.raise(); - } - - this->setNeedsDisplay(true); - - return true; -} - -bool AXRWrapper::reload() -{ - this->_showLayoutSteps = false; - this->_currentLayoutStep = 0; - this->_currentLayoutTick = 0; - this->_currentLayoutChild = 0; - - AXRCore* core = AXRCore::getInstance(); - if (!this->_isHSSOnly) - { - if (core->getFile()) - { - return this->loadXMLFile(core->getFile()->sourceUrl()); - } - else - { - AXRWarning("AXRWrapper", "no file loaded").raise(); - return false; - } - } - else - { - return this->loadHSSFile(core->getController()->loadSheetsGet(0)); - } -} - -bool AXRWrapper::loadHSSFile(QUrl url) -{ - axr_log(AXR_DEBUG_CH_OVERVIEW, AXRString("AXRWrapper: opening HSS document: %1").arg(url.toString())); - - this->_isHSSOnly = true; - this->_showLayoutSteps = false; - this->_currentLayoutStep = 0; - this->_currentLayoutTick = 0; - this->_currentLayoutChild = 0; - - AXRCore* core = AXRCore::getInstance(); - if (core->getFile()) - { - core->reset(); - } - - core->setFile(this->createDummyXML(url)); - core->run(); - this->setNeedsDisplay(true); - - return true; -} - -bool AXRWrapper::hasLoadedFile() -{ - AXRCore* core = AXRCore::getInstance(); - return core->hasLoadedFile(); -} - -void AXRWrapper::setShowLayoutSteps(bool value) -{ - this->_showLayoutSteps = value; -} - -bool AXRWrapper::showLayoutSteps() -{ - return this->_showLayoutSteps; -} - -void AXRWrapper::previousLayoutStep() -{ - if (this->_currentLayoutStep > 0) - { - this->_currentLayoutStep -= 1; - } - - this->_currentLayoutTick = 0; - this->_currentLayoutChild = 0; - this->setNeedsDisplay(true); -} - -void AXRWrapper::nextLayoutStep() -{ - this->_currentLayoutStep += 1; - this->_currentLayoutTick = 0; - this->_currentLayoutChild = 0; - this->setNeedsDisplay(true); -} - -void AXRWrapper::nextLayoutTick() -{ - this->_currentLayoutTick += 1; -} - -void AXRWrapper::resetLayoutTicks() -{ - this->_currentLayoutTick = 0; -} - -bool AXRWrapper::layoutStepDone() -{ - return this->_currentLayoutTick >= this->_currentLayoutStep; -} - -void AXRWrapper::breakIfNeeded() -{ - bool breakvar = _currentLayoutTick >= (_currentLayoutStep - 1); - - axr_log(AXR_DEBUG_CH_GENERAL_SPECIFIC, AXRString("currentLayoutTick = %1, currentLayoutStep = %2, %3").arg(_currentLayoutTick).arg(_currentLayoutStep).arg(breakvar)); -} - -void AXRWrapper::nextLayoutChild() -{ - this->_currentLayoutChild += 1; -} - -void AXRWrapper::resetLayoutChild() -{ - this->_currentLayoutChild = 0; -} - -bool AXRWrapper::layoutChildDone() -{ - return this->_currentLayoutTick >= this->_currentLayoutChild + 1; -} - -AXRString AXRWrapper::getPathToResources() -{ - // TODO: it's best to do this in a different way entirely... the library - // shouldn't be using the client process's directory to determine where - // to load resources from. For example, two different browsers will be - // at different file paths, while the resources path will be independent - // of either of them. Perhaps an AXR configuration file at a standard - // location? /etc/axr.conf on Unix and %WINDIR%/axr.ini on Windows? - QDir dir(QCoreApplication::applicationDirPath()); -#ifdef Q_WS_MACX - dir.cdUp(); - dir.cd("Resources"); -#endif - dir.cd("resources"); - return dir.canonicalPath(); -} - -AXRString AXRWrapper::getPathToTestsFile() -{ - return _layoutTestsFilePath; -} - -void AXRWrapper::executeLayoutTests(HSSObservableProperty passnull, void*data) -{ - HSSContainer::p status; - AXRCore* core = AXRCore::getInstance(); - HSSContainer::p root = core->getController()->getRoot(); - std::deque arguments = *(std::deque*)data; - - for (std::deque::iterator it = arguments.begin(); it != arguments.end(); ++it) - { - HSSParserNode::p argument = *it; - if (argument->isA(HSSFunctionTypeSel)) - { - HSSSelFunction::p selFunction = qSharedPointerCast(argument); - QVariant remoteValue = selFunction->evaluate(); - if (remoteValue.canConvert > >()) - { - std::vector< std::vector > selection = remoteValue.value > >(); - std::vector innerSelection = selection[0]; - status = HSSContainer::asContainer(innerSelection[0]); - } - } - } - - AXRTestThread thrd(this, QUrl::fromLocalFile(this->getPathToTestsFile()), status); - thrd.start(); -} diff --git a/src/core/axr/AXRWrapper.h b/src/core/axr/AXRWrapper.h deleted file mode 100644 index a209923c..00000000 --- a/src/core/axr/AXRWrapper.h +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************** - * a A - * AM\/MA - * (MA:MMD - * :: VD - * :: º - * :: - * :: ** .A$MMMMND AMMMD AMMM6 MMMM MMMM6 - + 6::Z. TMMM MMMMMMMMMDA VMMMD AMMM6 MMMMMMMMM6 - * 6M:AMMJMMOD V MMMA VMMMD AMMM6 MMMMMMM6 - * :: TMMTMC ___MMMM VMMMMMMM6 MMMM - * MMM TMMMTTM, AMMMMMMMM VMMMMM6 MMMM - * :: MM TMMTMMMD MMMMMMMMMM MMMMMM MMMM - * :: MMMTTMMM6 MMMMMMMMMMM AMMMMMMD MMMM - * :. MMMMMM6 MMMM MMMM AMMMMMMMMD MMMM - * TTMMT MMMM MMMM AMMM6 MMMMD MMMM - * TMMMM8 MMMMMMMMMMM AMMM6 MMMMD MMMM - * TMMMMMM$ MMMM6 MMMM AMMM6 MMMMD MMMM - * TMMM MMMM - * TMMM .MMM - * TMM .MMD ARBITRARY·······XML········RENDERING - * TMM MMA ==================================== - * TMN MM - * MN ZM - * MM, - * - * - * AUTHORS: see AUTHORS file - * - * COPYRIGHT: ©2012 - All Rights Reserved - * - * LICENSE: see LICENSE file - * - * WEB: http://axr.vg - * - * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR - * FITNESS FOR A PARTICULAR PURPOSE. - * - ********************************************************************/ - -#ifndef AXRWRAPPER_H -#define AXRWRAPPER_H - -#include -#include -#include -#include -#include -#include "AXRError.h" -#include "AXRBuffer.h" -#include "HSSContainer.h" -#include "HSSObservableProperties.h" - -namespace AXR -{ - class AXRCore; - - /** - * @brief This is the abstract superclass from with all OS-specific wrappers - * should inherit from. - */ - class AXR_API AXRWrapper - { - public: - /** - * The shared pointer to the wrapper. - */ - typedef QSharedPointer p; - - /** - * Creates a new instance of the wrapper. It will obtain the singleton instance of - * the AXRCore and initialize it. - */ - AXRWrapper(); - - /** - * Destructs the wrapper - */ - virtual ~AXRWrapper(); - /** - * Creates a AXRBuffer representation from the url you provide. - * Subclasses should override this method with the OS specific implementation. - * @param url A string containing the url to the file - */ - virtual AXRBuffer::p getFile(QUrl url); - virtual bool needsDisplay() const; - /** - * This is to be called when something happens that needs to trigger a redraw. - * Subclasses should override this method with the OS specific implementation. - * @param newValue A boolean containing the new state. - */ - virtual void setNeedsDisplay(bool newValue); - /** - * Getter for the core. - * @return A shared pointer to the core object. - */ - QSharedPointer getCore(); - /** - * Setter for the core. - * param xcr A shared pointer to the core object. - */ - void setCore(QSharedPointer xcr); - /** - * This creates a string containing a basic XML document with 1 element called "root". - * It is used when a HSS file is loaded directly. - * @return A shared pointer to the AXRBuffer representation of the basic XML document. - */ - AXRBuffer::p createDummyXML(QUrl hssUrl); - /** - * Loads the XML file at the path you provide. - * @param xmlfilepath A string containing the path to the file on the local system. - * @return Wether it has been loaded successfully or not. - */ - bool loadXMLFile(QUrl url); - bool loadXMLFile(AXRBuffer::p buffer); - /** - * Loads the file you provide, and then handles it according to its file extension. - * @param filepath A string containing the path to the file on the local system, can be - * either an XML or an HSS file. - * - * @return Wether it has been loaded successfully or not. - */ - bool loadFileByPath(QUrl url); - /** - * Loads the HSS file at the path you provide. - * @param hssfilepath A string containing the path to the file on the local system. - * @return Wether it has been loaded successfully or not. - */ - bool loadHSSFile(QUrl url); - /** - * Reloads the file that is currently loaded. - * @return Wether it has been reloaded successfully or not. - */ - bool reload(); - /** - * Tells if there is a file already loaded. - * @return Wether a file has already been loaded or not. - */ - bool hasLoadedFile(); - /** - * Each platform specific wrapper defines how it gets the path to the resources folder. - * @return A string containing the path to where the HSS resources files are - * stored. - */ - virtual AXRString getPathToResources(); - - /** - */ - virtual AXRString getPathToTestsFile(); - - bool showLayoutSteps(); - void setShowLayoutSteps(bool value); - void previousLayoutStep(); - void nextLayoutStep(); - void nextLayoutTick(); - void resetLayoutTicks(); - bool layoutStepDone(); - void nextLayoutChild(); - void resetLayoutChild(); - bool layoutChildDone(); - void breakIfNeeded(); - - void executeLayoutTests(HSSObservableProperty passnull, void*data); - - QMap files; - - private: - bool _isHSSOnly; - bool _hasLoadedFile; - bool _showLayoutSteps; - unsigned int _currentLayoutStep; - unsigned int _currentLayoutTick; - unsigned int _currentLayoutChild; - bool _needsDisplay; - - public: - AXRString _layoutTestsFilePath; - }; -} - -#endif diff --git a/src/core/hss/objects/HSSContainer.cpp b/src/core/hss/objects/HSSContainer.cpp index 1303b135..5066d483 100644 --- a/src/core/hss/objects/HSSContainer.cpp +++ b/src/core/hss/objects/HSSContainer.cpp @@ -506,7 +506,7 @@ void HSSContainer::layout() unsigned i, size, j, k; //HSSUnit acc2 = 0; security_brake_init(); - AXRWrapper * wrapper = AXRCore::getInstance()->getWrapper(); + AXRCore * wrapper = AXRCore::getInstance(); //bool secondaryIsHorizontal = (this->directionSecondary == HSSDirectionLeftToRight || this->directionSecondary == HSSDirectionRightToLeft); @@ -1609,7 +1609,7 @@ bool HSSContainer::_arrangeLines(displayGroup::p &group, HSSDirectionValue direc return true; } - AXRWrapper * wrapper = AXRCore::getInstance()->getWrapper(); + AXRCore * wrapper = AXRCore::getInstance(); switch (direction) { diff --git a/src/core/hss/objects/HSSDisplayObject.cpp b/src/core/hss/objects/HSSDisplayObject.cpp index a126c4dd..a035ea6e 100644 --- a/src/core/hss/objects/HSSDisplayObject.cpp +++ b/src/core/hss/objects/HSSDisplayObject.cpp @@ -548,7 +548,7 @@ void HSSDisplayObject::setRuleStatus(HSSRule::p rule, HSSRuleState newValue) if (changed) { this->setNeedsRereadRules(true); - AXRCore::getInstance()->getWrapper()->setNeedsDisplay(true); + AXRCore::getInstance()->setNeedsDisplay(true); } } @@ -772,7 +772,7 @@ bool HSSDisplayObject::isDirty() void HSSDisplayObject::draw(QPainter &painter) { - AXRWrapper * wrapper = AXRCore::getInstance()->getWrapper(); + AXRCore * wrapper = AXRCore::getInstance(); if (wrapper->showLayoutSteps()) { wrapper->nextLayoutTick(); @@ -3897,7 +3897,7 @@ void HSSDisplayObject::ruleChanged(HSSObservableProperty source, void*data) { //HSSRule * theRule = (HSSRule*)data; this->setNeedsRereadRules(true); - AXRCore::getInstance()->getWrapper()->setNeedsDisplay(true); + AXRCore::getInstance()->setNeedsDisplay(true); } void HSSDisplayObject::createFlag(HSSFlag::p flag, HSSRuleState defaultValue) diff --git a/src/core/hss/objects/actions/HSSRequest.cpp b/src/core/hss/objects/actions/HSSRequest.cpp index 5ba74bad..068bbd01 100644 --- a/src/core/hss/objects/actions/HSSRequest.cpp +++ b/src/core/hss/objects/actions/HSSRequest.cpp @@ -135,8 +135,7 @@ void HSSRequest::fire() if (this->target.empty()) { AXRCore* core = AXRCore::getInstance(); - AXRWrapper * wrapper = core->getWrapper(); - wrapper->loadXMLFile(this->src); + core->loadXMLFile(this->src); } else { @@ -145,15 +144,14 @@ void HSSRequest::fire() default: { AXRCore* core = AXRCore::getInstance(); - AXRWrapper * wrapper = core->getWrapper(); AXRController::p controller = AXRController::p(new AXRController()); XMLParser::p xmlParser(new XMLParser(controller.data())); - HSSParser::p hssParser(new HSSParser(controller.data(), wrapper)); + HSSParser::p hssParser(new HSSParser(controller.data())); AXRBuffer::p baseFile = core->getFile(); AXRBuffer::p newFile; try { - newFile = wrapper->getFile(this->src); + newFile = core->getFile(this->src); } catch (const AXRError &e) { @@ -179,7 +177,7 @@ void HSSRequest::fire() AXRBuffer::p hssfile; try { - hssfile = wrapper->getFile(*sheetsIt); + hssfile = core->getFile(*sheetsIt); } catch (const AXRError &e) { @@ -214,7 +212,7 @@ void HSSRequest::fire() root->setNeedsRereadRules(true); root->recursiveReadDefinitionObjects(); root->handleEvent(HSSEventTypeLoad, NULL); - wrapper->setNeedsDisplay(true); + core->setNeedsDisplay(true); } } } diff --git a/src/core/hss/parsing/HSSParser.cpp b/src/core/hss/parsing/HSSParser.cpp index e8807c73..d147ffbd 100644 --- a/src/core/hss/parsing/HSSParser.cpp +++ b/src/core/hss/parsing/HSSParser.cpp @@ -48,7 +48,6 @@ #include "AXRDebugging.h" #include "AXRInitializer.h" #include "AXRWarning.h" -#include "AXRWrapper.h" #include "HSSAttrFunction.h" #include "HSSComment.h" #include "HSSDivision.h" @@ -73,12 +72,11 @@ using namespace AXR; -HSSParser::HSSParser(AXRController * theController, AXRWrapper * wrapper) +HSSParser::HSSParser(AXRController * theController) { axr_log(AXR_DEBUG_CH_GENERAL | AXR_DEBUG_CH_GENERAL_SPECIFIC, "HSSParser: creating HSS parser"); this->controller = theController; - this->wrapper = wrapper; this->tokenizer = HSSTokenizer::p(new HSSTokenizer()); this->currentContext.push_back(HSSParserContextRoot); @@ -280,14 +278,14 @@ bool HSSParser::readNextStatement() QUrl url(theInstr->getValue()); if (url.scheme() == HSSFRAMEWORK_PROTOCOL) { - theFile = this->wrapper->getFile(QUrl::fromLocalFile(this->wrapper->getPathToResources()).resolved(url)); + theFile = AXRCore::getInstance()->getFile(QUrl::fromLocalFile(AXRCore::getInstance()->getPathToResources()).resolved(url)); } else { if (url.isRelative()) - theFile = this->wrapper->getFile(currentFile->sourceUrl().resolved(url)); + theFile = AXRCore::getInstance()->getFile(currentFile->sourceUrl().resolved(url)); else - theFile = this->wrapper->getFile(url); + theFile = AXRCore::getInstance()->getFile(url); } if (theFile) diff --git a/src/core/hss/parsing/HSSParser.h b/src/core/hss/parsing/HSSParser.h index 239983ff..769f3ed7 100644 --- a/src/core/hss/parsing/HSSParser.h +++ b/src/core/hss/parsing/HSSParser.h @@ -105,9 +105,8 @@ namespace AXR * It will create a new instance of a HSSTokenizer automatically, and set the current context to root. * * @param theController A regular pointer to the controller associated to this parser. - * @param wrapper A regular pointer to the wrapper associated to this parser. */ - HSSParser(AXRController * theController, AXRWrapper * wrapper); + HSSParser(AXRController * theController); /** * Destructor for this class. Clears the currentObjectContext stack and the loaded files. @@ -442,7 +441,6 @@ namespace AXR HSSTokenizer::p tokenizer; //weak pointer AXRController * controller; - AXRWrapper * wrapper; HSSToken::p currentToken; std::vector currentContext; diff --git a/src/core/rendering/AXRRender.cpp b/src/core/rendering/AXRRender.cpp index 98837e53..0f3a5de0 100644 --- a/src/core/rendering/AXRRender.cpp +++ b/src/core/rendering/AXRRender.cpp @@ -44,6 +44,7 @@ #include #include "AXRController.h" #include "AXRDebugging.h" +#include "AXRError.h" #include "AXRInitializer.h" #include "AXRRender.h" #include "AXRString.h" @@ -64,7 +65,7 @@ void AXRRender::drawInRectWithBounds(HSSRect rect, HSSRect bounds) { //prepare values HSSContainer::p root = this->controller->getRoot(); - AXRWrapper * wrapper = AXRCore::getInstance()->getWrapper(); + AXRCore * wrapper = AXRCore::getInstance(); if (root) { diff --git a/src/core/xml/XMLParser.cpp b/src/core/xml/XMLParser.cpp index 00e6947b..23f57c57 100644 --- a/src/core/xml/XMLParser.cpp +++ b/src/core/xml/XMLParser.cpp @@ -45,6 +45,7 @@ #include #include "AXRController.h" #include "AXRDebugging.h" +#include "AXRError.h" #include "AXRInitializer.h" #include "XMLParser.h" diff --git a/src/examples/rendering/cocoa/CocoaAppDelegate.h b/src/examples/rendering/cocoa/CocoaAppDelegate.h index 3b99adfd..3207352d 100644 --- a/src/examples/rendering/cocoa/CocoaAppDelegate.h +++ b/src/examples/rendering/cocoa/CocoaAppDelegate.h @@ -44,7 +44,6 @@ #import #import "AXRInitializer.h" #import "AXRView.h" -#import "AXRWrapper.h" #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 #define Superclass @@ -55,7 +54,7 @@ NSWindow *window; NSWindow *axrWindow; AXRView *axrView; - AXR::AXRWrapper *wrapper; + AXR::AXRCore *wrapper; BOOL needsFile; } diff --git a/src/examples/rendering/cocoa/CocoaAppDelegate.mm b/src/examples/rendering/cocoa/CocoaAppDelegate.mm index 3507de68..4493ae6e 100644 --- a/src/examples/rendering/cocoa/CocoaAppDelegate.mm +++ b/src/examples/rendering/cocoa/CocoaAppDelegate.mm @@ -42,6 +42,7 @@ ********************************************************************/ #import "AXRDebugging.h" +#import "AXRInitializer.h" #import "HSSDisplayObject.h" #import "CocoaAppDelegate.h" @@ -53,8 +54,7 @@ @implementation CocoaAppDelegate -(id) init { - wrapper = new AXR::AXRWrapper(); - + wrapper = AXR::AXRCore::getInstance(); [self setNeedsFile : YES]; // axr_debug_activate_channel(AXR_DEBUG_CH_ON); // axr_debug_activate_channel(AXR_DEBUG_CH_OVERVIEW); @@ -72,7 +72,8 @@ -(id) init -(void) dealloc { - delete wrapper; + // TODO: don't delete until thread pointer is eliminated + //delete wrapper; [super dealloc]; } diff --git a/src/examples/rendering/sdl/main.cpp b/src/examples/rendering/sdl/main.cpp index 7c41b404..006fe7d0 100644 --- a/src/examples/rendering/sdl/main.cpp +++ b/src/examples/rendering/sdl/main.cpp @@ -47,7 +47,6 @@ #include #include "AXRDebugging.h" #include "AXRInitializer.h" -#include "AXRWrapper.h" #if defined(_WIN32) #include @@ -60,7 +59,7 @@ const int WINDOW_WIDTH = 640; const int WINDOW_HEIGHT = 480; const char* WINDOW_TITLE = "AXR SDL Demo"; -AXRWrapper *wrapper; +AXRCore *core; SDL_Surface* screen = NULL; #ifdef _WIN32 @@ -98,9 +97,8 @@ SDL_Surface* QImage_toSDLSurface(const QImage &sourceImage) void render() { - if (wrapper->needsDisplay()) + if (core->needsDisplay()) { - AXRCore*core = AXRCore::getInstance(); HSSRect bounds(0, 0, screen->w, screen->h); core->drawInRectWithBounds(bounds, bounds); @@ -110,14 +108,14 @@ void render() SDL_FreeSurface(surf); SDL_Flip(screen); - wrapper->setNeedsDisplay(false); + core->setNeedsDisplay(false); } } -void loadFile(AXRWrapper *wrapper) +void loadFile() { QString filepath = QFileDialog::getOpenFileName(NULL, QObject::tr("Open File"), QString(), QObject::tr("AXR Files (*.xml *.hss)")); - wrapper->loadFileByPath(QUrl::fromLocalFile(filepath)); + core->loadFileByPath(QUrl::fromLocalFile(filepath)); } int main(int argc, char **argv) @@ -145,39 +143,23 @@ int main(int argc, char **argv) SDL_EnableKeyRepeat(300, 50); SDL_EnableUNICODE(1); - wrapper = new AXRWrapper(); - AXRCore*core = AXRCore::getInstance(); + core = AXRCore::getInstance(); if (!args.empty()) { - if (args.contains("--layout-tests")) + QFileInfo fi(args.last()); + if (fi.exists()) { - QDir dir(wrapper->getPathToResources()); - dir.cd("views"); - - wrapper->_layoutTestsFilePath = dir.absolutePath(); - - core->registerCustomFunction("AXRLayoutTestsExecute", - new AXR::HSSValueChangedCallback(wrapper, &AXRWrapper::executeLayoutTests)); - - wrapper->loadFileByPath(QUrl::fromLocalFile(dir.absoluteFilePath("layoutTests.hss"))); + core->loadFileByPath(QUrl::fromLocalFile(AXR::fromQString(args.first()))); } else { - QFileInfo fi(args.last()); - if (fi.exists()) - { - wrapper->loadFileByPath(QUrl::fromLocalFile(AXR::fromQString(args.first()))); - } - else - { - loadFile(wrapper); - } + loadFile(); } } else { - loadFile(wrapper); + loadFile(); } int done = 0; @@ -240,17 +222,17 @@ int main(int argc, char **argv) if (event.key.keysym.sym == SDLK_F5) { std_log("Reloading file"); - wrapper->reload(); + core->reload(); } else if (event.key.keysym.sym == SDLK_o && (event.key.keysym.mod & KMOD_CTRL)) { - loadFile(wrapper); + loadFile(); } } else if (event.type == SDL_VIDEORESIZE) { screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE); - wrapper->setNeedsDisplay(true); + core->setNeedsDisplay(true); } else if (event.active.state & SDL_APPMOUSEFOCUS && event.active.gain == 0) { @@ -275,7 +257,8 @@ int main(int argc, char **argv) ::DestroyIcon(mainicon); #endif - delete wrapper; + // TODO: don't delete until thread pointer is eliminated + //delete core; return 0; } diff --git a/src/plugin/AXRPlugin.cpp b/src/plugin/AXRPlugin.cpp index a1df832d..e19a1af2 100644 --- a/src/plugin/AXRPlugin.cpp +++ b/src/plugin/AXRPlugin.cpp @@ -48,19 +48,13 @@ #include "AXRInitializer.h" #include "AXRRender.h" -#include "AXRWrapper.h" #include "DOM/Window.h" -#ifdef FB_WIN +#if FB_WIN #include -#include "PluginWindowWin.h" -#include "PluginWindowlessWin.h" -#endif - -#ifdef FB_MACOSX +#elif FB_MACOSX #include -#include "PluginWindowMacCG.h" #endif using namespace AXR; @@ -99,8 +93,8 @@ void AXRPlugin::StaticDeinitialize() * the JSAPI object until the onPluginReady method is called */ AXRPlugin::AXRPlugin() -: wrapper(new AXRWrapper()) { + wrapper = AXRCore::getInstance(); } /*! @@ -114,7 +108,9 @@ AXRPlugin::~AXRPlugin() // they will be released here. releaseRootJSAPI(); m_host->freeRetainedObjects(); - delete wrapper; + + // TODO: don't delete until thread pointer is eliminated + //delete wrapper; } void AXRPlugin::onPluginReady() diff --git a/src/plugin/AXRPlugin.h b/src/plugin/AXRPlugin.h index 95ee1022..f759cde1 100644 --- a/src/plugin/AXRPlugin.h +++ b/src/plugin/AXRPlugin.h @@ -65,7 +65,7 @@ namespace AXR { - class AXRWrapper; + class AXRCore; } FB_FORWARD_PTR(AXRPlugin) @@ -126,7 +126,7 @@ class AXRPlugin : public FB::PluginCore #endif private: - AXR::AXRWrapper *wrapper; + AXR::AXRCore *wrapper; }; #endif diff --git a/src/prototype/AXRWidget.cpp b/src/prototype/AXRWidget.cpp index 22b670f1..190e2ba9 100644 --- a/src/prototype/AXRWidget.cpp +++ b/src/prototype/AXRWidget.cpp @@ -106,10 +106,10 @@ void AXRWidget::mouseMoveEvent(QMouseEvent *e) { HSSPoint thePoint(e->pos()); root->handleEvent(AXR::HSSEventTypeMouseMove, (void*)&thePoint); - AXRWrapper * wrapper = core->getWrapper(); - if(wrapper->needsDisplay()){ + if (core->needsDisplay()) + { this->update(); - wrapper->setNeedsDisplay(false); + core->setNeedsDisplay(false); } } } @@ -122,10 +122,10 @@ void AXRWidget::mousePressEvent(QMouseEvent *e) { HSSPoint thePoint(e->pos()); root->handleEvent(AXR::HSSEventTypeMouseDown, (void*)&thePoint); - AXRWrapper * wrapper = core->getWrapper(); - if(wrapper->needsDisplay()){ + if (core->needsDisplay()) + { this->update(); - wrapper->setNeedsDisplay(false); + core->setNeedsDisplay(false); } } } @@ -139,10 +139,10 @@ void AXRWidget::mouseReleaseEvent(QMouseEvent *e) HSSPoint thePoint(e->pos()); root->handleEvent(AXR::HSSEventTypeMouseUp, (void*)&thePoint); root->handleEvent(AXR::HSSEventTypeClick, (void*)&thePoint); - AXRWrapper * wrapper = core->getWrapper(); - if(wrapper->needsDisplay()){ + if (core->needsDisplay()) + { this->update(); - wrapper->setNeedsDisplay(false); + core->setNeedsDisplay(false); } } } diff --git a/src/prototype/CMakeLists.txt b/src/prototype/CMakeLists.txt index 251db1aa..eb808127 100644 --- a/src/prototype/CMakeLists.txt +++ b/src/prototype/CMakeLists.txt @@ -37,6 +37,9 @@ qt_transform_sources(prototype_SOURCES "${prototype_SOURCES}") add_executable(${TARGET_NAME_APP_PROTOTYPE} WIN32 MACOSX_BUNDLE ${prototype_SOURCES}) target_link_libraries(${TARGET_NAME_APP_PROTOTYPE} ${TARGET_NAME_LIB_CORE} ${QT_QTMAIN_LIBRARY}) +# TODO: Temporary until TEST target is removed +target_link_libraries(${TARGET_NAME_APP_PROTOTYPE} TEST) + set(MACOSX_BUNDLE_ICON_FILE prototype.icns) set_source_files_properties(${axr_icon_SOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) diff --git a/src/prototype/PrototypeWindow.cpp b/src/prototype/PrototypeWindow.cpp index 48ea984b..fbebda05 100644 --- a/src/prototype/PrototypeWindow.cpp +++ b/src/prototype/PrototypeWindow.cpp @@ -50,7 +50,7 @@ #include "AXRController.h" #include "AXRDebugging.h" #include "AXRInitializer.h" -#include "AXRWrapper.h" +#include "AXRTestRunner.h" #include "XMLParser.h" #include "LogWindow.h" @@ -66,8 +66,10 @@ using namespace AXR; class PrototypeWindow::Private { public: - Private() : wrapper(new AXRWrapper()) + Private() { + wrapper = AXRCore::getInstance(); + testRunner = new AXRTestRunner(); axr_debug_device = qApp->loggingDevice(); } @@ -75,10 +77,13 @@ class PrototypeWindow::Private { axr_debug_device = NULL; - delete wrapper; + // TODO: don't delete until thread pointer is eliminated + //delete wrapper; + delete testRunner; } - AXRWrapper *wrapper; + AXRCore *wrapper; + AXRTestRunner *testRunner; }; PrototypeWindow::PrototypeWindow(QWidget *parent) @@ -86,8 +91,7 @@ PrototypeWindow::PrototypeWindow(QWidget *parent) { ui->setupUi(this); - AXRCore*core = AXRCore::getInstance(); - ui->enableAntialiasingAction->setChecked(core->getRender()->globalAntialiasingEnabled()); + ui->enableAntialiasingAction->setChecked(d->wrapper->getRender()->globalAntialiasingEnabled()); // The subview needs to accept drops as well even though the main window handles it ui->renderingView->setAcceptDrops(true); @@ -257,7 +261,7 @@ void PrototypeWindow::listHssStatements() AXRBuffer::p f(new AXRBuffer(fi)); AXRController controller; - HSSParser hssparser(&controller, d->wrapper); + HSSParser hssparser(&controller); if (hssparser.loadFile(f)) { @@ -313,16 +317,9 @@ void PrototypeWindow::listHssTokens() void PrototypeWindow::runLayoutTests() { - QDir dir = QDir(QCoreApplication::applicationDirPath()); -#ifdef Q_WS_MACX - dir.cdUp(); -#endif - dir.cd("Resources"); - dir.cd("views"); - - AXRCore*core = AXRCore::getInstance(); - core->registerCustomFunction("AXRLayoutTestsExecute", new HSSValueChangedCallback(d->wrapper, &AXRWrapper::executeLayoutTests)); - this->openFile(dir.filePath("layoutTests.hss")); + AXRCore *core = AXRCore::getInstance(); + core->registerCustomFunction("AXRLayoutTestsExecute", new HSSValueChangedCallback(d->testRunner, &AXRTestRunner::executeLayoutTests)); + this->openFile(d->testRunner->getPathToTestsFile()); } void PrototypeWindow::showErrorLog()