|
From: CVS C. to T. <the...@li...> - 2011-04-14 20:22:29
|
Revision: 647
http://themis.svn.sourceforge.net/themis/?rev=647&view=rev
Author: mark_hellegers
Date: 2011-04-14 20:22:22 +0000 (Thu, 14 Apr 2011)
Log Message:
-----------
Moved the applying of the styles to a separate function and changed the code so it loops through the values instead of trying everything it knows about.
Modified Paths:
--------------
trunk/themis/modules/CSSRenderer/CSSView.cpp
trunk/themis/modules/CSSRenderer/CSSView.hpp
Modified: trunk/themis/modules/CSSRenderer/CSSView.cpp
===================================================================
--- trunk/themis/modules/CSSRenderer/CSSView.cpp 2011-04-14 19:07:55 UTC (rev 646)
+++ trunk/themis/modules/CSSRenderer/CSSView.cpp 2011-04-14 20:22:22 UTC (rev 647)
@@ -124,10 +124,100 @@
mClickable = true;
}
}
- CSSStyleDeclarationPtr style = mStyleSheets->getComputedStyle(element);
- if (style.get()) {
- CSSValuePtr value = style->getPropertyCSSValue("display");
- if (value.get()) {
+ ApplyStyle(element);
+ }
+
+ for (unsigned int i = 0; i < length; i++) {
+ TNodePtr child = children->item(i);
+ CSSView * childView = new CSSView(aBaseView,
+ child,
+ mStyleSheets,
+ mRect,
+ mColor,
+ mFont);
+ mChildren.push_back(childView);
+ }
+ }
+ else if (mNode->getNodeType() == TEXT_NODE) {
+ if (mFont == NULL) {
+ mFont = new BFont(be_plain_font);
+ mInheritedFont = false;
+ }
+ font_height height;
+ mFont->GetHeight(&height);
+ mLineHeight = height.ascent + height.descent + height.leading;
+ mBottomMargin = height.descent;
+ mSpaceWidth = mFont->StringWidth(&cSpace, 1);
+ mBlock = false;
+
+ SplitText();
+ }
+
+}
+
+CSSView :: ~CSSView() {
+
+ unsigned int length = mChildren.size();
+ for (unsigned int i = 0; i < length; i++) {
+ delete mChildren[i];
+ }
+
+/*
+ if (!mInheritedFont) {
+ delete mFont;
+ }
+*/
+
+}
+
+void CSSView :: RetrieveLink() {
+
+ if (mHref.size() > 0) {
+ // Send a message to the window.
+ // The window will do all the actual work of requesting a new page.
+ string urlString = "";
+ unsigned int position = mHref.find("://");
+ if (position == string::npos) {
+ urlString = mBaseView->GetDocumentURI();
+ if (mHref[0] == '/') {
+ // Get past the :// in the base uri, so we can find the right /
+ position = urlString.find("://");
+ if (position != string::npos) {
+ position += 3;
+ }
+ else {
+ position = 0;
+ }
+ // Find domain and use that as the base of the url.
+ position = urlString.find_first_of("/", position);
+ urlString = urlString.substr(0, position);
+
+ }
+ else {
+ // Find last subdirectory and use that as the base of the url.
+ position = urlString.find_last_of("/");
+ urlString = urlString.substr(0, position + 1);
+ }
+ }
+ urlString += mHref;
+ BMessage message(URL_OPEN);
+ message.AddString("url_to_open", urlString.c_str());
+ BMessenger messenger(NULL, mBaseView->Window());
+ messenger.SendMessage(&message);
+ }
+
+}
+
+void CSSView :: ApplyStyle(const TElementPtr aElement) {
+
+ CSSStyleDeclarationPtr style = mStyleSheets->getComputedStyle(aElement);
+ if (style.get()) {
+ unsigned long length = style->getLength();
+ for (unsigned long i = 0; i < length; i++) {
+ TDOMString propertyName = style->item(i);
+ CSSValuePtr value = style->getPropertyCSSValue(propertyName);
+ if (value.get()) {
+ if (propertyName == "display") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
TDOMString valueString = primitiveValue->getStringValue();
// printf("Display property value: %s\n", valueString.c_str());
@@ -148,8 +238,7 @@
mTableCell = true;
}
}
- value = style->getPropertyCSSValue("font-size");
- if (value.get()) {
+ else if (propertyName == "font-size") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
if (primitiveValue.get()) {
if (primitiveValue->getPrimitiveType() == CSSPrimitiveValue::CSS_EMS) {
@@ -162,8 +251,7 @@
}
}
}
- value = style->getPropertyCSSValue("font-style");
- if (value.get()) {
+ else if (propertyName == "font-style") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
if (primitiveValue.get()) {
TDOMString valueString = primitiveValue->getStringValue();
@@ -176,8 +264,7 @@
}
}
}
- value = style->getPropertyCSSValue("font-weight");
- if (value.get()) {
+ else if (propertyName == "font-weight") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
if (primitiveValue.get()) {
TDOMString valueString = primitiveValue->getStringValue();
@@ -190,8 +277,7 @@
}
}
}
- value = style->getPropertyCSSValue("margin-bottom");
- if (value.get()) {
+ else if (propertyName == "margin-bottom") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
if (primitiveValue.get()) {
if (primitiveValue->getPrimitiveType() == CSSPrimitiveValue::CSS_PX) {
@@ -200,8 +286,7 @@
}
}
}
- value = style->getPropertyCSSValue("margin-right");
- if (value.get()) {
+ else if (propertyName == "margin-right") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
if (primitiveValue.get()) {
if (primitiveValue->getPrimitiveType() == CSSPrimitiveValue::CSS_PX) {
@@ -210,8 +295,7 @@
}
}
}
- value = style->getPropertyCSSValue("color");
- if (value.get()) {
+ else if (propertyName == "color") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
if (primitiveValue.get()) {
if (primitiveValue->getPrimitiveType() == CSSPrimitiveValue::CSS_RGBCOLOR) {
@@ -229,22 +313,19 @@
}
}
}
- value = style->getPropertyCSSValue("list-style-type");
- if (value.get()) {
+ else if (propertyName == "list-style-type") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
if (primitiveValue.get()) {
mListStyleType = primitiveValue->getStringValue();
}
}
- value = style->getPropertyCSSValue("border-style");
- if (value.get()) {
+ else if (propertyName == "border-style") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
if (primitiveValue.get()) {
mBorderStyle = primitiveValue->getStringValue();
}
}
- value = style->getPropertyCSSValue("border-width");
- if (value.get()) {
+ else if (propertyName == "border-width") {
CSSPrimitiveValuePtr primitiveValue = shared_static_cast<CSSPrimitiveValue>(value);
if (primitiveValue.get()) {
if (primitiveValue->getPrimitiveType() == CSSPrimitiveValue::CSS_PX) {
@@ -255,88 +336,9 @@
}
}
}
-
- for (unsigned int i = 0; i < length; i++) {
- TNodePtr child = children->item(i);
- CSSView * childView = new CSSView(aBaseView,
- child,
- mStyleSheets,
- mRect,
- mColor,
- mFont);
- mChildren.push_back(childView);
- }
}
- else if (mNode->getNodeType() == TEXT_NODE) {
- if (mFont == NULL) {
- mFont = new BFont(be_plain_font);
- mInheritedFont = false;
- }
- font_height height;
- mFont->GetHeight(&height);
- mLineHeight = height.ascent + height.descent + height.leading;
- mBottomMargin = height.descent;
- mSpaceWidth = mFont->StringWidth(&cSpace, 1);
- mBlock = false;
-
- SplitText();
- }
-
}
-CSSView :: ~CSSView() {
-
- unsigned int length = mChildren.size();
- for (unsigned int i = 0; i < length; i++) {
- delete mChildren[i];
- }
-
-/*
- if (!mInheritedFont) {
- delete mFont;
- }
-*/
-
-}
-
-void CSSView :: RetrieveLink() {
-
- if (mHref.size() > 0) {
- // Send a message to the window.
- // The window will do all the actual work of requesting a new page.
- string urlString = "";
- unsigned int position = mHref.find("://");
- if (position == string::npos) {
- urlString = mBaseView->GetDocumentURI();
- if (mHref[0] == '/') {
- // Get past the :// in the base uri, so we can find the right /
- position = urlString.find("://");
- if (position != string::npos) {
- position += 3;
- }
- else {
- position = 0;
- }
- // Find domain and use that as the base of the url.
- position = urlString.find_first_of("/", position);
- urlString = urlString.substr(0, position);
-
- }
- else {
- // Find last subdirectory and use that as the base of the url.
- position = urlString.find_last_of("/");
- urlString = urlString.substr(0, position + 1);
- }
- }
- urlString += mHref;
- BMessage message(URL_OPEN);
- message.AddString("url_to_open", urlString.c_str());
- BMessenger messenger(NULL, mBaseView->Window());
- messenger.SendMessage(&message);
- }
-
-}
-
void CSSView :: MouseDown(BPoint aPoint) {
if (mClickable) {
Modified: trunk/themis/modules/CSSRenderer/CSSView.hpp
===================================================================
--- trunk/themis/modules/CSSRenderer/CSSView.hpp 2011-04-14 19:07:55 UTC (rev 646)
+++ trunk/themis/modules/CSSRenderer/CSSView.hpp 2011-04-14 20:22:22 UTC (rev 647)
@@ -100,6 +100,9 @@
BRect mListStyleRect;
void RetrieveLink();
+
+ protected:
+ void ApplyStyle(const TElementPtr aElement);
public:
CSSView(CSSRendererView * aBaseView,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|