|
From: CVS C. to T. <the...@li...> - 2011-04-14 19:08:01
|
Revision: 646
http://themis.svn.sourceforge.net/themis/?rev=646&view=rev
Author: mark_hellegers
Date: 2011-04-14 19:07:55 +0000 (Thu, 14 Apr 2011)
Log Message:
-----------
- Added separate class for the stylesheets. This should make future improvements easier. Especially multiple stylesheets.
- Added basic style for the TBODY element.
Modified Paths:
--------------
trunk/themis/makefile
trunk/themis/modules/CSSParser/html4.css
trunk/themis/modules/CSSRenderer/CSSRendererView.cpp
trunk/themis/modules/CSSRenderer/CSSRendererView.hpp
trunk/themis/modules/CSSRenderer/CSSView.cpp
trunk/themis/modules/CSSRenderer/CSSView.hpp
Added Paths:
-----------
trunk/themis/modules/CSSRenderer/CSSStyleContainer.cpp
trunk/themis/modules/CSSRenderer/CSSStyleContainer.hpp
Modified: trunk/themis/makefile
===================================================================
--- trunk/themis/makefile 2011-04-11 20:42:39 UTC (rev 645)
+++ trunk/themis/makefile 2011-04-14 19:07:55 UTC (rev 646)
@@ -231,7 +231,8 @@
CSSRenderer/CSSRendererView.cpp \
CSSRenderer/CSSScrolledRendererView.cpp \
CSSRenderer/CSSView.cpp \
- CSSRenderer/TextBox.cpp
+ CSSRenderer/TextBox.cpp \
+ CSSRenderer/CSSStyleContainer.cpp
#make install directories as necessary
ifeq "$(shell if [ -d $(BASE_ADDON_INSTALL_DIR) ] ; then echo 1 ; else mkdir -p $(BASE_ADDON_INSTALL_DIR) ; echo 0 ; fi)" "0"
Modified: trunk/themis/modules/CSSParser/html4.css
===================================================================
--- trunk/themis/modules/CSSParser/html4.css 2011-04-11 20:42:39 UTC (rev 645)
+++ trunk/themis/modules/CSSParser/html4.css 2011-04-14 19:07:55 UTC (rev 646)
@@ -30,6 +30,9 @@
TABLE { display: table;
border-style: solid;
border-width: 1px; }
+TBODY { display: table-row-group;
+ border-style: solid;
+ border-width: 1px; }
TR { display: table-row;
border-style: solid;
border-width: 1px }
Modified: trunk/themis/modules/CSSRenderer/CSSRendererView.cpp
===================================================================
--- trunk/themis/modules/CSSRenderer/CSSRendererView.cpp 2011-04-11 20:42:39 UTC (rev 645)
+++ trunk/themis/modules/CSSRenderer/CSSRendererView.cpp 2011-04-14 19:07:55 UTC (rev 646)
@@ -46,6 +46,7 @@
// CSS Renderer headers
#include "CSSRendererView.hpp"
#include "CSSView.hpp"
+#include "CSSStyleContainer.hpp"
CSSRendererView :: CSSRendererView(BRect aFrame,
TDocumentPtr aDocument,
@@ -56,7 +57,8 @@
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) {
printf("Creating CSSRendererView\n");
- mStyleSheet = aStyleSheet;
+ mStyleSheets = new CSSStyleContainer();
+ mStyleSheets->addStyleSheet(aStyleSheet);
mDocument = aDocument;
BRect rect = Bounds();
if (mDocument->hasChildNodes()) {
@@ -65,9 +67,12 @@
defaultColor.green = 0;
defaultColor.blue = 0;
+
+ TNodePtr root = mDocument->getFirstChild();
+
mView = new CSSView(this,
- mDocument->getFirstChild(),
- mStyleSheet,
+ root,
+ mStyleSheets,
rect,
defaultColor);
printf("Doing layout\n");
@@ -85,6 +90,7 @@
printf("Destroying CSSRendererView\n");
delete mView;
+ delete mStyleSheets;
printf("Destroyed CSSRendererView\n");
}
Modified: trunk/themis/modules/CSSRenderer/CSSRendererView.hpp
===================================================================
--- trunk/themis/modules/CSSRenderer/CSSRendererView.hpp 2011-04-11 20:42:39 UTC (rev 645)
+++ trunk/themis/modules/CSSRenderer/CSSRendererView.hpp 2011-04-14 19:07:55 UTC (rev 646)
@@ -51,6 +51,7 @@
// Declarations used
class CSSView;
+class CSSStyleContainer;
class CSSRendererView : public BView {
@@ -59,7 +60,7 @@
TDOMString mTitle;
TDocumentPtr mDocument;
BRect mCSSViewSize;
- CSSStyleSheetPtr mStyleSheet;
+ CSSStyleContainer * mStyleSheets;
public:
CSSRendererView(BRect aFrame,
Added: trunk/themis/modules/CSSRenderer/CSSStyleContainer.cpp
===================================================================
--- trunk/themis/modules/CSSRenderer/CSSStyleContainer.cpp (rev 0)
+++ trunk/themis/modules/CSSRenderer/CSSStyleContainer.cpp 2011-04-14 19:07:55 UTC (rev 646)
@@ -0,0 +1,103 @@
+/*
+ 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: April 10, 2011
+*/
+
+/* CSSStyleContainer implementation
+ See CSSStyleContainer.hpp for more information
+
+*/
+
+// Standard C headers
+#include <stdio.h>
+
+// DOM Style headers
+#include "CSSRuleList.hpp"
+#include "CSSStyleRule.hpp"
+
+// CSS Renderer headers
+#include "CSSStyleContainer.hpp"
+
+CSSStyleContainer :: CSSStyleContainer() {
+}
+
+CSSStyleContainer :: ~CSSStyleContainer() {
+}
+
+void CSSStyleContainer :: addStyleSheet(const CSSStyleSheetPtr aStyleSheet) {
+
+ mStyleSheetList.push_back(aStyleSheet);
+
+}
+
+CSSStyleDeclarationPtr CSSStyleContainer :: getComputedStyle(const TElementPtr aElement) {
+
+ CSSStyleDeclarationPtr result;
+ unsigned int styleSheetLength = mStyleSheetList.size();
+
+ for (unsigned int j = 0; j < styleSheetLength; j++) {
+ CSSStyleSheetPtr styleSheet = mStyleSheetList[j];
+ CSSRuleListPtr rules = styleSheet->getCSSRules();
+ unsigned long length = rules->getLength();
+ bool found = false;
+ unsigned long i = 0;
+ while (i < length && !found) {
+ CSSRulePtr rule = rules->item(i);
+ switch (rule->getType()) {
+ case CSSRule::STYLE_RULE: {
+ CSSStyleRulePtr styleRule = shared_static_cast<CSSStyleRule>(rule);
+ // Trim trailing spaces before comparing.
+ string styleText = styleRule->getSelectorText();
+ size_t endPos = styleText.find_last_not_of(" ");
+ if (string::npos != endPos) {
+ styleText = styleText.substr(0, endPos + 1);
+ }
+ if (styleText == aElement->getTagName()) {
+ result = styleRule->getStyle();
+ found = true;
+ }
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ i++;
+ }
+ }
+
+/*
+ if (found) {
+ printf("Found a match for %s\n", aElement->getTagName().c_str());
+ }
+ else {
+ printf("Didn't find a match for %s\n", aElement->getTagName().c_str());
+ }
+*/
+ return result;
+}
Added: trunk/themis/modules/CSSRenderer/CSSStyleContainer.hpp
===================================================================
--- trunk/themis/modules/CSSRenderer/CSSStyleContainer.hpp (rev 0)
+++ trunk/themis/modules/CSSRenderer/CSSStyleContainer.hpp 2011-04-14 19:07:55 UTC (rev 646)
@@ -0,0 +1,74 @@
+/*
+ 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: April 10, 2011
+*/
+
+/* CSSStyleContainer
+ Contains the CSS Stylesheets for a document
+ and provides a function to compute the style for an element of the document
+
+ Mark Hellegers (ma...@fi...)
+ 10-04-2011
+
+*/
+
+#ifndef CSSSTYLECONTAINER_HPP
+#define CSSSTYLECONTAINER_HPP
+
+// Standard C++ headers
+#include <vector>
+
+// DOM headers
+#include "TElement.h"
+
+// DOM Style headers
+#include "CSSStyleSheet.hpp"
+#include "CSSStyleDeclaration.hpp"
+
+// Namespaces used
+using std::vector;
+
+class CSSStyleContainer {
+
+ private:
+ vector<CSSStyleSheetPtr> mStyleSheetList;
+
+ public:
+ CSSStyleContainer();
+ ~CSSStyleContainer();
+ void addStyleSheet(const CSSStyleSheetPtr aStyleSheet);
+
+ /// A function to compute the style based on the stylesheets in the list.
+ /**
+ This functions computes the style for a given element by looking in the list
+ of stylesheets to see what applies to the element.
+ */
+ CSSStyleDeclarationPtr getComputedStyle(const TElementPtr aElement);
+};
+
+#endif
Modified: trunk/themis/modules/CSSRenderer/CSSView.cpp
===================================================================
--- trunk/themis/modules/CSSRenderer/CSSView.cpp 2011-04-11 20:42:39 UTC (rev 645)
+++ trunk/themis/modules/CSSRenderer/CSSView.cpp 2011-04-14 19:07:55 UTC (rev 646)
@@ -61,13 +61,14 @@
// CSS Renderer headers
#include "CSSView.hpp"
#include "CSSRendererView.hpp"
+#include "CSSStyleContainer.hpp"
// Constants used
const char cSpace = ' ';
CSSView :: CSSView(CSSRendererView * aBaseView,
TNodePtr aNode,
- CSSStyleSheetPtr aStyleSheet,
+ CSSStyleContainer * aStyleSheets,
BRect aRect,
rgb_color aColor,
BFont * aFont)
@@ -75,7 +76,7 @@
mBaseView = aBaseView;
mNode = aNode;
- mStyleSheet = aStyleSheet;
+ mStyleSheets = aStyleSheets;
mRect = aRect;
mDisplay = true;
mBlock = true;
@@ -123,7 +124,7 @@
mClickable = true;
}
}
- CSSStyleDeclarationPtr style = GetComputedStyle(element);
+ CSSStyleDeclarationPtr style = mStyleSheets->getComputedStyle(element);
if (style.get()) {
CSSValuePtr value = style->getPropertyCSSValue("display");
if (value.get()) {
@@ -137,7 +138,7 @@
else if (valueString == "inline") {
mBlock = false;
}
- else if (valueString == "table") {
+ else if ((valueString == "table") || (valueString == "table-row-group")) {
mTable = true;
}
else if (valueString == "table-row") {
@@ -259,7 +260,7 @@
TNodePtr child = children->item(i);
CSSView * childView = new CSSView(aBaseView,
child,
- mStyleSheet,
+ mStyleSheets,
mRect,
mColor,
mFont);
@@ -730,46 +731,3 @@
}
}
-
-CSSStyleDeclarationPtr CSSView :: GetComputedStyle(TElementPtr aElement) {
-
- CSSStyleDeclarationPtr result;
- CSSRuleListPtr rules = mStyleSheet->getCSSRules();
- unsigned long length = rules->getLength();
- bool found = false;
- unsigned long i = 0;
- while (i < length && !found) {
- CSSRulePtr rule = rules->item(i);
- switch (rule->getType()) {
- case CSSRule::STYLE_RULE: {
- CSSStyleRulePtr styleRule = shared_static_cast<CSSStyleRule>(rule);
- // Trim trailing spaces before comparing.
- string styleText = styleRule->getSelectorText();
- size_t endPos = styleText.find_last_not_of(" ");
- if (string::npos != endPos) {
- styleText = styleText.substr(0, endPos + 1);
- }
- if (styleText == aElement->getTagName()) {
- result = styleRule->getStyle();
- found = true;
- }
- break;
- }
- default: {
- break;
- }
- }
- i++;
- }
-
-/*
- if (found) {
- printf("Found a match for %s\n", aElement->getTagName().c_str());
- }
- else {
- printf("Didn't find a match for %s\n", aElement->getTagName().c_str());
- }
-*/
- return result;
-
-}
Modified: trunk/themis/modules/CSSRenderer/CSSView.hpp
===================================================================
--- trunk/themis/modules/CSSRenderer/CSSView.hpp 2011-04-11 20:42:39 UTC (rev 645)
+++ trunk/themis/modules/CSSRenderer/CSSView.hpp 2011-04-14 19:07:55 UTC (rev 646)
@@ -59,8 +59,9 @@
#include "TextBox.hpp"
// Declarations used
+class BFont;
class CSSRendererView;
-class BFont;
+class CSSStyleContainer;
// Namespaces used
using std::vector;
@@ -71,7 +72,7 @@
private:
vector<CSSView *> mChildren;
TNodePtr mNode;
- CSSStyleSheetPtr mStyleSheet;
+ CSSStyleContainer * mStyleSheets;
CSSRendererView * mBaseView;
vector<BRect> mRects;
BRect mRect;
@@ -103,7 +104,7 @@
public:
CSSView(CSSRendererView * aBaseView,
TNodePtr aNode,
- CSSStyleSheetPtr aStyleSheet,
+ CSSStyleContainer * aStyleSheets,
BRect aRect,
rgb_color aColor,
BFont * aFont = NULL);
@@ -119,7 +120,7 @@
void Layout(BRect aRect,
BPoint aStartingPoint);
void SplitText();
- CSSStyleDeclarationPtr GetComputedStyle(TElementPtr aElement);
+ CSSStyleDeclarationPtr GetComputedStyle(const TElementPtr aElement);
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|