|
From: CVS C. to T. <the...@li...> - 2011-01-16 14:47:11
|
Revision: 612
http://themis.svn.sourceforge.net/themis/?rev=612&view=rev
Author: mark_hellegers
Date: 2011-01-16 14:47:04 +0000 (Sun, 16 Jan 2011)
Log Message:
-----------
- Added CSSDOMEntry class and converted the CSSParser and CSSViewer to use it.
- Cleaned up the code a bit.
Modified Paths:
--------------
trunk/themis/makefile
trunk/themis/modules/CSSParser/CSSParserPlugin.cpp
trunk/themis/modules/CSSParser/CSSParserPlugin.hpp
trunk/themis/modules/CSSViewer/CSSViewer.cpp
Added Paths:
-----------
trunk/themis/common/CSSDOMEntry.cpp
trunk/themis/common/CSSDOMEntry.hpp
Added: trunk/themis/common/CSSDOMEntry.cpp
===================================================================
--- trunk/themis/common/CSSDOMEntry.cpp (rev 0)
+++ trunk/themis/common/CSSDOMEntry.cpp 2011-01-16 14:47:04 UTC (rev 612)
@@ -0,0 +1,54 @@
+/*
+ Copyright (c) 2011 Mark Hellegers. All Rights Reserved.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or
+ sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice
+ shall be included in all copies or substantial portions
+ of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ Original Author: Mark Hellegers (ma...@fi...)
+ Project Start Date: October 18, 2000
+ Class Start Date: January 16, 2011
+*/
+
+/* CSSDOMEntry implementation
+ See CSSDOMEntry.hpp for more information
+*/
+
+// Standard C headers
+#include <stdio.h>
+
+// SGMLParser headers
+#include "CSSDOMEntry.hpp"
+
+// Constants declared
+const string kCSSStyleSheet = "CSS Stylesheet";
+
+CSSDOMEntry :: CSSDOMEntry(int32 aId, CSSStyleSheetPtr aStyleSheet)
+ : BaseEntry(aId) {
+
+ set(kCSSStyleSheet, shared_static_cast<void>(aStyleSheet));
+
+}
+
+CSSStyleSheetPtr CSSDOMEntry :: getStyleSheet() {
+
+ return shared_static_cast<CSSStyleSheet>(getSharedPtr(kCSSStyleSheet));
+}
Added: trunk/themis/common/CSSDOMEntry.hpp
===================================================================
--- trunk/themis/common/CSSDOMEntry.hpp (rev 0)
+++ trunk/themis/common/CSSDOMEntry.hpp 2011-01-16 14:47:04 UTC (rev 612)
@@ -0,0 +1,49 @@
+/*
+ Copyright (c) 2011 Mark Hellegers. All Rights Reserved.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or
+ sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice
+ shall be included in all copies or substantial portions
+ of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ Original Author: Mark Hellegers (ma...@fi...)
+ Project Start Date: October 18, 2000
+ Class Start Date: January 16, 2011
+*/
+
+#ifndef CSSDOMENTRY_HPP
+#define CSSDOMENTRY_HPP
+
+// DOM Style headers
+#include "CSSStyleSheet.hpp"
+
+// Themis headers
+#include "BaseEntry.hpp"
+
+class CSSDOMEntry : public BaseEntry {
+
+ public:
+ CSSDOMEntry(int32 aId, CSSStyleSheetPtr aStyleSheet);
+
+ CSSStyleSheetPtr getStyleSheet();
+
+};
+
+#endif
Modified: trunk/themis/makefile
===================================================================
--- trunk/themis/makefile 2011-01-16 14:35:13 UTC (rev 611)
+++ trunk/themis/makefile 2011-01-16 14:47:04 UTC (rev 612)
@@ -120,7 +120,8 @@
common/prefsman.cpp \
common/BasePrefsView.cpp \
common/BaseEntry.cpp \
- common/DOMEntry.cpp
+ common/DOMEntry.cpp \
+ common/CSSDOMEntry.cpp
#add similar lines for new plugins, libraries, etc.
HTTPADDONSOURCES= \
http/optionshandler.cpp \
@@ -541,11 +542,11 @@
$(COMMON_DEPENDS_DIR)%.d: common/%.cpp
@echo "Common: Updating dependency file $(notdir $@)"
- @set -e;VAR1=$(shell echo "$(COMMON_DEPENDS_DIR)$(notdir $@)"|sed 's/\//\\\//g');VAR2=$(shell echo "$(COMMON_OBJECT_DIR)"|sed 's/\//\\\//g'); $(CC) -Icommon -I./ -Iframework/DOM -M $(CPPFLAGS) $< | sed 's/\($*\)\.o[ :]*/objects\/common\/\1.o depends\/common\/\1.d : /g' > $@;[ -s $@ ] || rm -f $@
+ @set -e;VAR1=$(shell echo "$(COMMON_DEPENDS_DIR)$(notdir $@)"|sed 's/\//\\\//g');VAR2=$(shell echo "$(COMMON_OBJECT_DIR)"|sed 's/\//\\\//g'); $(CC) -Icommon -I./ -Iframework/DOM -Iframework/DOMStyle -M $(CPPFLAGS) $< | sed 's/\($*\)\.o[ :]*/objects\/common\/\1.o depends\/common\/\1.d : /g' > $@;[ -s $@ ] || rm -f $@
$(COMMON_OBJECT_DIR)%.o: common/%.cpp $(COMMON_DEPENDS_DIR)%.d
@echo "Common: Updating object file $(notdir $@)"
- @$(CC) $(CFLAGS) $(COMPILE_FLAGS) -Icommon -I./ -Iframework/DOM -c $< -o $@
+ @$(CC) $(CFLAGS) $(COMPILE_FLAGS) -Icommon -I./ -Iframework/DOM -Iframework/DOMStyle -c $< -o $@
#renderer
Modified: trunk/themis/modules/CSSParser/CSSParserPlugin.cpp
===================================================================
--- trunk/themis/modules/CSSParser/CSSParserPlugin.cpp 2011-01-16 14:35:13 UTC (rev 611)
+++ trunk/themis/modules/CSSParser/CSSParserPlugin.cpp 2011-01-16 14:47:04 UTC (rev 612)
@@ -48,9 +48,12 @@
#include <storage/Directory.h>
// Themis headers
+#include "framework/app.h"
+#include "framework/SiteHandler.h"
#include "commondefs.h"
#include "plugman.h"
#include "PrefsDefs.h"
+#include "CSSDOMEntry.hpp"
// CSSParser headers
#include "CSSParserPlugin.hpp"
@@ -208,21 +211,28 @@
}
-void CSSParserPlugin :: NotifyParseFinished(void * aDocument,
+void CSSParserPlugin :: NotifyParseFinished(CSSStyleSheetPtr aStyleSheet,
string aType,
BMessage * aOriginalMessage) {
- int32 siteID = 0;
- int32 urlID = 0;
- aOriginalMessage->FindInt32("site_id", &siteID);
- aOriginalMessage->FindInt32("url_id", &urlID);
+ int32 siteId = 0;
+ int32 urlId = 0;
+ int32 domId = 0;
+ aOriginalMessage->FindInt32("site_id", &siteId);
+ aOriginalMessage->FindInt32("url_id", &urlId);
+ aOriginalMessage->FindInt32("dom_id", &domId);
+ /* Get an unique ID from the app for the DOM entry */
+ int32 cssId = ((App *)be_app)->GetNewID();
+ CSSDOMEntry * entry = new CSSDOMEntry(cssId, aStyleSheet);
+ ((App *)be_app)->GetSiteHandler()->AddEntry(entry, siteId, domId);
+
BMessage * done = new BMessage(SH_PARSE_DOC_FINISHED);
done->AddInt32("command", COMMAND_INFO);
done->AddString("type", aType.c_str());
- done->AddPointer("pointer", aDocument);
- done->AddInt32("site_id", siteID);
- done->AddInt32("url_id", urlID);
+ done->AddInt32("site_id", siteId);
+ done->AddInt32("url_id", urlId);
+ done->AddInt32("cssdom_id", cssId);
// Message created. Broadcast it.
Broadcast(MS_TARGET_ALL, done);
@@ -232,57 +242,6 @@
}
-void CSSParserPlugin :: ParseDocument(string aURL,
- BMessage * aOriginalMessage) {
-
- if (CacheRegistered()) {
- int32 fileToken = mCache->FindObject(mUserToken, aURL.c_str());
- ssize_t fileSize = mCache->GetObjectSize(mUserToken, fileToken);
-
- if (fileSize == 0) {
- Debug("Requested file is 0 bytes long. Aborting parse", PlugID());
- }
- else {
- // Read the file and parse it.
- const unsigned int BUFFER_SIZE = 2000;
- string content = "";
- char * buffer = new char[BUFFER_SIZE];
- ssize_t bytesRead = 0;
- int totalBytes = 0;
- bool foundData = true;
- while (foundData) {
- if (totalBytes > fileSize) {
- foundData = false;
- printf("Reading more bytes than possible. Skipping last buffer\n");
- }
- else {
- bytesRead = mCache->Read(mUserToken, fileToken, buffer, BUFFER_SIZE);
- if (bytesRead > 0) {
- content += buffer;
- memset(buffer, 0, BUFFER_SIZE);
- totalBytes += bytesRead;
- }
- else {
- foundData = false;
- }
- }
- }
- delete[] buffer;
-
- // Parse it
- if (content.size() != 0) {
- mParser->parse(content);
-
- NotifyParseFinished(mDocuments.end() - 1, "cssdom", aOriginalMessage);
- }
- }
- }
- else {
- printf("Not registered with the cache. Nothing to do\n");
- }
-
-}
-
void CSSParserPlugin :: MessageReceived(BMessage * aMessage) {
switch (aMessage->what) {
@@ -297,7 +256,7 @@
Debug(cssLoad.c_str(), PlugID());
CSSStyleSheetPtr document = mParser->parse(path);
mDocuments.push_back(document);
- NotifyParseFinished(mDocuments.end() - 1, "cssdom", aMessage);
+ NotifyParseFinished(document, "cssdom", aMessage);
}
break;
}
@@ -394,9 +353,14 @@
Debug(cssLoad.c_str(), PlugID());
CSSStyleSheetPtr document = mParser->parse(path);
mDocuments.push_back(document);
- NotifyParseFinished(mDocuments.end() - 1, "cssdom", aMessage);
+ NotifyParseFinished(document, "cssdom", aMessage);
}
}
+ else {
+ // Assuming the default stylesheet is parsed first!!!
+ CSSStyleSheetPtr document = mDocuments[0];
+ NotifyParseFinished(document, "cssdom", aMessage);
+ }
}
}
}
Modified: trunk/themis/modules/CSSParser/CSSParserPlugin.hpp
===================================================================
--- trunk/themis/modules/CSSParser/CSSParserPlugin.hpp 2011-01-16 14:35:13 UTC (rev 611)
+++ trunk/themis/modules/CSSParser/CSSParserPlugin.hpp 2011-01-16 14:47:04 UTC (rev 612)
@@ -90,12 +90,9 @@
// Function to check if the document is a supported one.
bool IsDocumentSupported(BMessage * aMessage);
// Function to notify plugins that parsing is finished.
- void NotifyParseFinished(void * aDocument,
+ void NotifyParseFinished(CSSStyleSheetPtr aStyleSheet,
string aType,
BMessage * aOriginalMessage);
- // Function to parse a document.
- void ParseDocument(string aURL,
- BMessage * aOriginalMessage);
public:
CSSParserPlugin(BMessage * aInfo = NULL);
Modified: trunk/themis/modules/CSSViewer/CSSViewer.cpp
===================================================================
--- trunk/themis/modules/CSSViewer/CSSViewer.cpp 2011-01-16 14:35:13 UTC (rev 611)
+++ trunk/themis/modules/CSSViewer/CSSViewer.cpp 2011-01-16 14:47:04 UTC (rev 612)
@@ -47,6 +47,10 @@
#include <Autolock.h>
// Themis headers
+#include "framework/app.h"
+#include "framework/SiteHandler.h"
+#include "framework/SiteEntry.h"
+#include "CSSDOMEntry.hpp"
#include "commondefs.h"
CSSViewer * viewer;
@@ -137,7 +141,7 @@
float CSSViewer :: PlugVersion() {
- return 0.1;
+ return 0.2;
}
@@ -150,25 +154,28 @@
int32 command = 0;
aMessage->FindInt32("command", &command);
- switch ( command ) {
- case COMMAND_INFO: {
+ switch (command) {
+ case COMMAND_INFO: {
// Check if it is css dom data
- BString type;
- aMessage->FindString("type", &type);
- if ( type == "cssdom" ) {
- // Get the pointer out
- void * document = NULL;
- aMessage->FindPointer("pointer", &document);
- if (document) {
- CSSStyleSheetPtr * temp = (CSSStyleSheetPtr *) document;
- if (!mView) {
- mView = new CSSView(*temp);
- }
- else {
- BAutolock viewLock(mView);
- if (viewLock.IsLocked()) {
- mView->SetStyleSheet(*temp);
+ BString typeOfDocument;
+ aMessage->FindString("type", &typeOfDocument);
+ if (typeOfDocument == "cssdom") {
+ int32 siteId = aMessage->FindInt32("site_id");
+ SiteEntry * site = ((App *)be_app)->GetSiteHandler()->GetEntry(siteId);
+ if (site != NULL) {
+ int32 cssId = aMessage->FindInt32("cssdom_id");
+ CSSDOMEntry * entry = (CSSDOMEntry *) site->getEntry(cssId);
+ if (entry != NULL) {
+ CSSStyleSheetPtr document = entry->getStyleSheet();
+ if (!mView) {
+ mView = new CSSView(document);
}
+ else {
+ BAutolock viewLock(mView);
+ if (viewLock.IsLocked()) {
+ mView->SetStyleSheet(document);
+ }
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|