Changeset 11481 in webkit
- Timestamp:
- Dec 6, 2005, 5:12:38 PM (20 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog-2005-12-19
r11472 r11481 1 <<<<<<< ChangeLog 2 2005-12-05 David Hyatt <hyatt@apple.com> 3 4 Add support for more methods for exposing more useful style information. 5 6 getMatchedCSSRules can be used to obtain the matched sheet rules for an element. In Obj-C 7 it will also include user/user agent sheet rules. 8 9 Also add support for tracking the original shorthand in which a property was declared, as well 10 as whether the property was just implicitly set rather than explicitly mentioned (e.g., if it was 11 an omitted piece of a shorthand). The new methods on CSSStyleDeclaration are getPropertyShorthand 12 and isPropertyImplicit. 13 14 Reviewed by mjs 15 16 Test: fast/inspector/style.html 17 18 * khtml/css/css_computedstyle.h: 19 (DOM::CSSComputedStyleDeclarationImpl::getPropertyShorthand): 20 (DOM::CSSComputedStyleDeclarationImpl::isPropertyImplicit): 21 * khtml/css/css_valueimpl.cpp: 22 (DOM::CSSStyleDeclarationImpl::getPropertyShorthand): 23 (DOM::CSSStyleDeclarationImpl::isPropertyImplicit): 24 (DOM::CSSMutableStyleDeclarationImpl::getPropertyPriority): 25 (DOM::CSSMutableStyleDeclarationImpl::getPropertyShorthand): 26 (DOM::CSSMutableStyleDeclarationImpl::isPropertyImplicit): 27 (DOM::CSSProperty::cssText): 28 (DOM::operator==): 29 * khtml/css/css_valueimpl.h: 30 (DOM::CSSProperty::CSSProperty): 31 (DOM::CSSProperty::operator=): 32 (DOM::CSSProperty::~CSSProperty): 33 (DOM::CSSProperty::setValue): 34 (DOM::CSSProperty::shorthandID): 35 (DOM::CSSProperty::isImportant): 36 (DOM::CSSProperty::isImplicit): 37 * khtml/css/cssparser.cpp: 38 (CSSParser::CSSParser): 39 (CSSParser::addProperty): 40 (CSSParser::parseValue): 41 (CSSParser::parseBackgroundShorthand): 42 (CSSParser::parseShorthand): 43 (CSSParser::parse4Values): 44 (CSSParser::parseBackgroundPosition): 45 (CSSParser::parseBackgroundProperty): 46 * khtml/css/cssparser.h: 47 (DOM::CSSParser::enterShorthand): 48 (DOM::CSSParser::exitShorthand): 49 (DOM::CSSParser::inShorthand): 50 * khtml/css/cssstyleselector.cpp: 51 (khtml::CSSStyleSelector::CSSStyleSelector): 52 (khtml::CSSStyleSelector::matchRules): 53 (khtml::CSSStyleSelector::matchRulesForList): 54 (khtml::CSSStyleSelector::initForStyleResolve): 55 (khtml::CSSStyleSelector::styleRulesForElement): 56 (khtml::CSSStyleSelector::pseudoStyleRulesForElement): 57 * khtml/css/cssstyleselector.h: 58 * khtml/ecma/kjs_css.cpp: 59 (KJS::DOMCSSStyleDeclarationProtoFunc::callAsFunction): 60 * khtml/ecma/kjs_css.h: 61 (KJS::DOMCSSStyleDeclaration::): 62 * khtml/ecma/kjs_views.cpp: 63 (KJS::DOMAbstractViewProtoFunc::callAsFunction): 64 * khtml/ecma/kjs_views.h: 65 (KJS::DOMAbstractView::): 66 * khtml/xml/dom2_viewsimpl.cpp: 67 (DOM::AbstractViewImpl::getComputedStyle): 68 (DOM::AbstractViewImpl::getMatchedCSSRules): 69 * khtml/xml/dom2_viewsimpl.h: 70 * kwq/DOM-CSS.mm: 71 (-[DOMCSSStyleDeclaration getPropertyShorthand:]): 72 (-[DOMCSSStyleDeclaration isPropertyImplicit:]): 73 (-[DOMDocument getMatchedCSSRules::]): 74 * kwq/DOMPrivate.h: 75 76 ======= 1 77 2005-12-04 Maciej Stachowiak <mjs@apple.com> 2 78 … … 253 329 logic for the "oldUnder" variable as for the "targetNode" variable. 254 330 331 >>>>>>> 1.482 255 332 2005-12-05 John Sullivan <sullivan@apple.com> 256 333 -
trunk/WebCore/khtml/css/css_computedstyle.h
r11375 r11481 51 51 virtual DOMString getPropertyValue(int propertyID) const; 52 52 virtual bool getPropertyPriority(int propertyID) const; 53 virtual int getPropertyShorthand(int propertyID) const { return -1; } 54 virtual bool isPropertyImplicit(int propertyID) const { return true; } 53 55 54 56 virtual CSSMutableStyleDeclarationImpl *copy() const; -
trunk/WebCore/khtml/css/css_valueimpl.cpp
r11333 r11481 132 132 } 133 133 134 DOMString CSSStyleDeclarationImpl::getPropertyShorthand(const DOMString &propertyName) 135 { 136 int propID = propertyID(propertyName); 137 if (!propID) 138 return DOMString(); 139 int shorthandID = getPropertyShorthand(propID); 140 if (!shorthandID) 141 return DOMString(); 142 return getPropertyName(shorthandID); 143 } 144 145 bool CSSStyleDeclarationImpl::isPropertyImplicit(const DOMString &propertyName) 146 { 147 int propID = propertyID(propertyName); 148 if (!propID) 149 return false; 150 return isPropertyImplicit(propID); 151 } 152 134 153 void CSSStyleDeclarationImpl::setProperty(const DOMString &propertyName, const DOMString &value, const DOMString &priority, int &exception) 135 154 { … … 386 405 QValueListConstIterator<CSSProperty> end; 387 406 for (QValueListConstIterator<CSSProperty> it = m_values.begin(); it != end; ++it) 388 if (propertyID == (*it).m_id) 389 return (*it).m_bImportant; 407 if (propertyID == (*it).id()) 408 return (*it).isImportant(); 409 return false; 410 } 411 412 int CSSMutableStyleDeclarationImpl::getPropertyShorthand(int propertyID) const 413 { 414 QValueListConstIterator<CSSProperty> end; 415 for (QValueListConstIterator<CSSProperty> it = m_values.begin(); it != end; ++it) 416 if (propertyID == (*it).id()) 417 return (*it).shorthandID(); 418 return false; 419 } 420 421 bool CSSMutableStyleDeclarationImpl::isPropertyImplicit(int propertyID) const 422 { 423 QValueListConstIterator<CSSProperty> end; 424 for (QValueListConstIterator<CSSProperty> it = m_values.begin(); it != end; ++it) 425 if (propertyID == (*it).id()) 426 return (*it).isImplicit(); 390 427 return false; 391 428 } … … 1338 1375 DOMString CSSProperty::cssText() const 1339 1376 { 1340 return getPropertyName( m_id) + DOMString(": ") + m_value->cssText() + (m_bImportant? DOMString(" !important") : DOMString()) + DOMString("; ");1377 return getPropertyName(id()) + DOMString(": ") + m_value->cssText() + (isImportant() ? DOMString(" !important") : DOMString()) + DOMString("; "); 1341 1378 } 1342 1379 1343 1380 bool operator==(const CSSProperty &a, const CSSProperty &b) 1344 1381 { 1345 return a.m_id == b.m_id && a.m_ bImportant == b.m_bImportant && a.m_value == b.m_value;1346 } 1347 1348 } 1382 return a.m_id == b.m_id && a.m_important == b.m_important && a.m_value == b.m_value; 1383 } 1384 1385 } -
trunk/WebCore/khtml/css/css_valueimpl.h
r11272 r11481 64 64 DOMString getPropertyValue(const DOMString &propertyName); 65 65 DOMString getPropertyPriority(const DOMString &propertyName); 66 DOMString getPropertyShorthand(const DOMString& propertyName); 67 bool isPropertyImplicit(const DOMString& propertyName); 68 66 69 virtual CSSValueImpl *getPropertyCSSValue(int propertyID) const = 0; 67 70 virtual DOMString getPropertyValue(int propertyID) const = 0; 68 71 virtual bool getPropertyPriority(int propertyID) const = 0; 72 virtual int getPropertyShorthand(int propertyID) const = 0; 73 virtual bool isPropertyImplicit(int propertyID) const = 0; 69 74 70 75 void setProperty(const DOMString &propertyName, const DOMString &value, const DOMString &priority, int &exception); … … 407 412 { 408 413 public: 409 CSSProperty() : m_id(-1), m_bImportant(false), m_value(0) 414 CSSProperty(int propID, CSSValueImpl *value, bool important = false, int shorthandID = 0, bool implicit = false) 415 : m_id(propID), m_shorthandID(shorthandID), m_important(important), m_implicit(implicit), m_value(value) 410 416 { 411 } 412 CSSProperty(int propID, CSSValueImpl *value, bool important = false) 413 : m_id(propID), m_bImportant(important), m_value(value) 414 { 415 if (value) value->ref(); 416 } 417 if (value) 418 value->ref(); 419 } 420 417 421 CSSProperty(const CSSProperty& o) 418 422 { 419 423 m_id = o.m_id; 420 m_bImportant = o.m_bImportant; 424 m_shorthandID = o.m_shorthandID; 425 m_important = o.m_important; 426 m_implicit = o.m_implicit; 421 427 m_value = o.m_value; 422 if (m_value) m_value->ref(); 423 } 428 if (m_value) 429 m_value->ref(); 430 } 431 424 432 CSSProperty &operator=(const CSSProperty& o) 425 433 { 426 if (o.m_value) o.m_value->ref(); 427 if (m_value) m_value->deref(); 434 if (o.m_value) 435 o.m_value->ref(); 436 if (m_value) 437 m_value->deref(); 428 438 m_id = o.m_id; 429 m_bImportant = o.m_bImportant; 439 m_shorthandID = o.m_shorthandID; 440 m_important = o.m_important; 430 441 m_value = o.m_value; 431 442 return *this; 432 443 } 444 433 445 ~CSSProperty() { 434 if(m_value) m_value->deref(); 446 if (m_value) 447 m_value->deref(); 435 448 } 436 449 437 450 void setValue(CSSValueImpl *val) { 438 if (val) val->ref(); 439 if (m_value) m_value->deref(); 451 if (val) 452 val->ref(); 453 if (m_value) 454 m_value->deref(); 440 455 m_value = val; 441 456 } 442 457 443 458 int id() const { return m_id; } 444 bool isImportant() const { return m_bImportant; } 459 int shorthandID() const { return m_shorthandID; } 460 461 bool isImportant() const { return m_important; } 462 bool isImplicit() const { return m_implicit; } 463 445 464 CSSValueImpl *value() const { return m_value; } 446 465 … … 448 467 449 468 // make sure the following fits in 4 bytes. 450 int m_id; 451 bool m_bImportant; 469 int m_id; 470 int m_shorthandID; // If this property was set as part of a shorthand, gives the shorthand. 471 bool m_important : 1; 472 bool m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand. 452 473 453 474 friend bool operator==(const CSSProperty &, const CSSProperty &); … … 479 500 virtual DOMString getPropertyValue(int propertyID) const; 480 501 virtual bool getPropertyPriority(int propertyID) const; 502 virtual int getPropertyShorthand(int propertyID) const; 503 virtual bool isPropertyImplicit(int propertyID) const; 481 504 482 505 virtual void setProperty(int propertyId, const DOMString &value, bool important, int &exceptionCode); -
trunk/WebCore/khtml/css/cssparser.cpp
r11272 r11481 3 3 * 4 4 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 5 * Copyright (C) 2004 Apple Computer, Inc. 5 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 6 * Copyright (C) 2004, 2005 Apple Computer, Inc. 6 7 * 7 8 * This library is free software; you can redistribute it and/or … … 103 104 id = 0; 104 105 important = false; 105 inParseShortHand = false; 106 106 m_inParseShorthand = 0; 107 m_currentShorthand = 0; 108 m_implicitShorthand = false; 109 107 110 defaultNamespace = starAtom; 108 111 … … 313 316 314 317 315 void CSSParser::addProperty( int propId, CSSValueImpl *value, bool important ) 316 { 317 CSSProperty *prop = new CSSProperty; 318 prop->m_id = propId; 319 prop->setValue( value ); 320 prop->m_bImportant = important; 321 322 if ( numParsedProperties >= maxParsedProperties ) { 318 void CSSParser::addProperty(int propId, CSSValueImpl *value, bool important) 319 { 320 CSSProperty *prop = new CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand); 321 if (numParsedProperties >= maxParsedProperties) { 323 322 maxParsedProperties += 32; 324 323 parsedProperties = (CSSProperty **)fastRealloc(parsedProperties, … … 425 424 return false; 426 425 427 int id = 0; 428 id = value->id; 426 int id = value->id; 429 427 430 428 if (id == CSS_VAL_INHERIT) { … … 520 518 break; 521 519 522 /* Start of supported CSS properties with validation. This is needed for parseShort Hand to work520 /* Start of supported CSS properties with validation. This is needed for parseShorthand to work 523 521 * correctly and allows optimization in khtml::applyRule(..) 524 522 */ … … 1044 1042 CSS_PROP__KHTML_MARQUEE_REPETITION, 1045 1043 CSS_PROP__KHTML_MARQUEE_STYLE, CSS_PROP__KHTML_MARQUEE_SPEED }; 1046 return parseShort Hand(properties, 5, important);1044 return parseShorthand(propId, properties, 5, important); 1047 1045 } 1048 1046 case CSS_PROP__KHTML_MARQUEE_DIRECTION: … … 1159 1157 const int properties[3] = { CSS_PROP_BORDER_WIDTH, CSS_PROP_BORDER_STYLE, 1160 1158 CSS_PROP_BORDER_COLOR }; 1161 return parseShort Hand(properties, 3, important);1159 return parseShorthand(propId, properties, 3, important); 1162 1160 } 1163 1161 case CSS_PROP_BORDER_TOP: … … 1166 1164 const int properties[3] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_TOP_STYLE, 1167 1165 CSS_PROP_BORDER_TOP_COLOR}; 1168 return parseShort Hand(properties, 3, important);1166 return parseShorthand(propId, properties, 3, important); 1169 1167 } 1170 1168 case CSS_PROP_BORDER_RIGHT: … … 1173 1171 const int properties[3] = { CSS_PROP_BORDER_RIGHT_WIDTH, CSS_PROP_BORDER_RIGHT_STYLE, 1174 1172 CSS_PROP_BORDER_RIGHT_COLOR }; 1175 return parseShort Hand(properties, 3, important);1173 return parseShorthand(propId, properties, 3, important); 1176 1174 } 1177 1175 case CSS_PROP_BORDER_BOTTOM: … … 1180 1178 const int properties[3] = { CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_BOTTOM_STYLE, 1181 1179 CSS_PROP_BORDER_BOTTOM_COLOR }; 1182 return parseShort Hand(properties, 3, important);1180 return parseShorthand(propId, properties, 3, important); 1183 1181 } 1184 1182 case CSS_PROP_BORDER_LEFT: … … 1187 1185 const int properties[3] = { CSS_PROP_BORDER_LEFT_WIDTH, CSS_PROP_BORDER_LEFT_STYLE, 1188 1186 CSS_PROP_BORDER_LEFT_COLOR }; 1189 return parseShort Hand(properties, 3, important);1187 return parseShorthand(propId, properties, 3, important); 1190 1188 } 1191 1189 case CSS_PROP_OUTLINE: … … 1194 1192 const int properties[3] = { CSS_PROP_OUTLINE_WIDTH, CSS_PROP_OUTLINE_STYLE, 1195 1193 CSS_PROP_OUTLINE_COLOR }; 1196 return parseShort Hand(properties, 3, important);1194 return parseShorthand(propId, properties, 3, important); 1197 1195 } 1198 1196 case CSS_PROP_BORDER_COLOR: … … 1201 1199 const int properties[4] = { CSS_PROP_BORDER_TOP_COLOR, CSS_PROP_BORDER_RIGHT_COLOR, 1202 1200 CSS_PROP_BORDER_BOTTOM_COLOR, CSS_PROP_BORDER_LEFT_COLOR }; 1203 return parse4Values(prop erties, important);1201 return parse4Values(propId, properties, important); 1204 1202 } 1205 1203 case CSS_PROP_BORDER_WIDTH: … … 1208 1206 const int properties[4] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_RIGHT_WIDTH, 1209 1207 CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_LEFT_WIDTH }; 1210 return parse4Values(prop erties, important);1208 return parse4Values(propId, properties, important); 1211 1209 } 1212 1210 case CSS_PROP_BORDER_STYLE: … … 1215 1213 const int properties[4] = { CSS_PROP_BORDER_TOP_STYLE, CSS_PROP_BORDER_RIGHT_STYLE, 1216 1214 CSS_PROP_BORDER_BOTTOM_STYLE, CSS_PROP_BORDER_LEFT_STYLE }; 1217 return parse4Values(prop erties, important);1215 return parse4Values(propId, properties, important); 1218 1216 } 1219 1217 case CSS_PROP_MARGIN: … … 1222 1220 const int properties[4] = { CSS_PROP_MARGIN_TOP, CSS_PROP_MARGIN_RIGHT, 1223 1221 CSS_PROP_MARGIN_BOTTOM, CSS_PROP_MARGIN_LEFT }; 1224 return parse4Values(prop erties, important);1222 return parse4Values(propId, properties, important); 1225 1223 } 1226 1224 case CSS_PROP_PADDING: … … 1229 1227 const int properties[4] = { CSS_PROP_PADDING_TOP, CSS_PROP_PADDING_RIGHT, 1230 1228 CSS_PROP_PADDING_BOTTOM, CSS_PROP_PADDING_LEFT }; 1231 return parse4Values(prop erties, important);1229 return parse4Values(propId, properties, important); 1232 1230 } 1233 1231 case CSS_PROP_FONT: 1234 1232 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 1235 1233 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit 1236 if ( id >= CSS_VAL_CAPTION && id <= CSS_VAL_STATUS_BAR)1234 if (id >= CSS_VAL_CAPTION && id <= CSS_VAL_STATUS_BAR) 1237 1235 valid_primitive = true; 1238 1236 else … … 1243 1241 const int properties[3] = { CSS_PROP_LIST_STYLE_TYPE, CSS_PROP_LIST_STYLE_POSITION, 1244 1242 CSS_PROP_LIST_STYLE_IMAGE }; 1245 return parseShort Hand(properties, 3, important);1243 return parseShorthand(propId, properties, 3, important); 1246 1244 } 1247 1245 default: … … 1307 1305 CSS_PROP_BACKGROUND_ORIGIN, CSS_PROP_BACKGROUND_COLOR }; 1308 1306 1309 inParseShortHand = true;1310 1307 enterShorthand(CSS_PROP_BACKGROUND); 1308 1311 1309 bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary 1312 1310 CSSValueImpl* values[numProperties] = { 0 }; // compiler will repeat 0 as necessary … … 1375 1373 } 1376 1374 1377 inParseShortHand = false;1375 exitShorthand(); 1378 1376 return true; 1379 1377 1380 1378 fail: 1381 inParseShortHand = false;1379 exitShorthand(); 1382 1380 for (int k = 0; k < numProperties; k++) 1383 1381 delete values[k]; … … 1386 1384 } 1387 1385 1388 bool CSSParser::parseShortHand( const int *properties, int numProperties, bool important ) 1389 { 1390 /* We try to match as many properties as possible 1391 * We setup an array of booleans to mark which property has been found, 1392 * and we try to search for properties until it makes no longer any sense 1393 */ 1394 inParseShortHand = true; 1386 bool CSSParser::parseShorthand(int propId, const int *properties, int numProperties, bool important) 1387 { 1388 // We try to match as many properties as possible 1389 // We set up an array of booleans to mark which property has been found, 1390 // and we try to search for properties until it makes no longer any sense. 1391 enterShorthand(propId); 1395 1392 1396 1393 bool found = false; 1397 bool fnd[6]; // Trust me ;)1398 for ( int i = 0; i < numProperties; i++)1394 bool fnd[6]; // Trust me ;) 1395 for (int i = 0; i < numProperties; i++) 1399 1396 fnd[i] = false; 1400 1397 1401 #ifdef CSS_DEBUG 1402 kdDebug(6080) << "PSH: numProperties=" << numProperties << endl; 1403 #endif 1404 1405 while ( valueList->current() ) { 1398 while (valueList->current()) { 1406 1399 found = false; 1407 // qDebug("outer loop" ); 1408 for (int propIndex = 0; !found && propIndex < numProperties; ++propIndex) { 1400 for (int propIndex = 0; !found && propIndex < numProperties; ++propIndex) { 1409 1401 if (!fnd[propIndex]) { 1410 #ifdef CSS_DEBUG 1411 kdDebug(6080) << "LOOKING FOR: " << getPropertyName(properties[propIndex]).qstring() << endl; 1412 #endif 1413 if ( parseValue( properties[propIndex], important ) ) { 1402 if (parseValue( properties[propIndex], important)) 1414 1403 fnd[propIndex] = found = true; 1415 #ifdef CSS_DEBUG1416 kdDebug(6080) << "FOUND: " << getPropertyName(properties[propIndex]).qstring() << endl;1417 #endif1418 }1419 1404 } 1420 1405 } 1406 1421 1407 // if we didn't find at least one match, this is an 1422 1408 // invalid shorthand and we have to ignore it 1423 1409 if (!found) { 1424 #ifdef CSS_DEBUG 1425 qDebug("didn't find anything" ); 1426 #endif 1427 inParseShortHand = false; 1410 exitShorthand(); 1428 1411 return false; 1429 1412 } … … 1431 1414 1432 1415 // Fill in any remaining properties with the initial value. 1416 m_implicitShorthand = true; 1433 1417 for (int i = 0; i < numProperties; ++i) { 1434 1418 if (!fnd[i]) 1435 1419 addProperty(properties[i], new CSSInitialValueImpl(), important); 1436 1420 } 1437 1438 inParseShortHand = false; 1439 #ifdef CSS_DEBUG 1440 kdDebug( 6080 ) << "parsed shorthand" << endl; 1441 #endif 1421 m_implicitShorthand = false; 1422 1423 exitShorthand(); 1442 1424 return true; 1443 1425 } 1444 1426 1445 bool CSSParser::parse4Values( const int *properties, bool important)1427 bool CSSParser::parse4Values(int propId, const int *properties, bool important) 1446 1428 { 1447 1429 /* From the CSS 2 specs, 8.3 … … 1452 1434 * right, bottom, and left, respectively. 1453 1435 */ 1454 1455 int num = inParseShortHand ? 1 : valueList->numValues; 1456 // qDebug("parse4Values: num=%d", num ); 1436 1437 int num = inShorthand() ? 1 : valueList->numValues; 1438 1439 enterShorthand(propId); 1457 1440 1458 1441 // the order is top, right, bottom, left 1459 switch( num ) { 1460 case 1: { 1461 if( !parseValue( properties[0], important ) ) return false; 1462 CSSValueImpl *value = parsedProperties[numParsedProperties-1]->value(); 1463 addProperty( properties[1], value, important ); 1464 addProperty( properties[2], value, important ); 1465 addProperty( properties[3], value, important ); 1466 return true; 1467 } 1468 case 2: { 1469 1470 if( !parseValue( properties[0], important ) ) return false; 1471 if( !parseValue( properties[1], important ) ) return false; 1472 CSSValueImpl *value = parsedProperties[numParsedProperties-2]->value(); 1473 addProperty( properties[2], value, important ); 1474 value = parsedProperties[numParsedProperties-2]->value(); 1475 addProperty( properties[3], value, important ); 1476 return true; 1477 } 1478 case 3: { 1479 if( !parseValue( properties[0], important ) ) return false; 1480 if( !parseValue( properties[1], important ) ) return false; 1481 if( !parseValue( properties[2], important ) ) return false; 1482 CSSValueImpl *value = parsedProperties[numParsedProperties-2]->value(); 1483 addProperty( properties[3], value, important ); 1484 return true; 1485 } 1486 case 4: { 1487 if( !parseValue( properties[0], important ) ) return false; 1488 if( !parseValue( properties[1], important ) ) return false; 1489 if( !parseValue( properties[2], important ) ) return false; 1490 if( !parseValue( properties[3], important ) ) return false; 1491 return true; 1492 } 1493 default: 1494 return false; 1495 } 1442 switch (num) { 1443 case 1: { 1444 if (!parseValue(properties[0], important)) { 1445 exitShorthand(); 1446 return false; 1447 } 1448 CSSValueImpl *value = parsedProperties[numParsedProperties-1]->value(); 1449 m_implicitShorthand = true; 1450 addProperty(properties[1], value, important); 1451 addProperty(properties[2], value, important); 1452 addProperty(properties[3], value, important); 1453 m_implicitShorthand = false; 1454 break; 1455 } 1456 case 2: { 1457 if (!parseValue(properties[0], important) || !parseValue(properties[1], important)) { 1458 exitShorthand(); 1459 return false; 1460 } 1461 CSSValueImpl *value = parsedProperties[numParsedProperties-2]->value(); 1462 m_implicitShorthand = true; 1463 addProperty(properties[2], value, important); 1464 value = parsedProperties[numParsedProperties-2]->value(); 1465 addProperty(properties[3], value, important); 1466 m_implicitShorthand = false; 1467 break; 1468 } 1469 case 3: { 1470 if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || 1471 !parseValue(properties[2], important)) { 1472 exitShorthand(); 1473 return false; 1474 } 1475 CSSValueImpl *value = parsedProperties[numParsedProperties-2]->value(); 1476 m_implicitShorthand = true; 1477 addProperty(properties[3], value, important); 1478 m_implicitShorthand = false; 1479 break; 1480 } 1481 case 4: { 1482 if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || 1483 !parseValue(properties[2], important) || !parseValue(properties[3], important)) { 1484 exitShorthand(); 1485 return false; 1486 } 1487 break; 1488 } 1489 default: { 1490 exitShorthand(); 1491 return false; 1492 } 1493 } 1494 1495 exitShorthand(); 1496 return true; 1496 1497 } 1497 1498 … … 1629 1630 valueList->next(); 1630 1631 else { 1631 if (!in ParseShortHand) {1632 if (!inShorthand()) { 1632 1633 delete value1; 1633 1634 value1 = 0; … … 1757 1758 // When parsing the 'background' shorthand property, we let it handle building up the lists for all 1758 1759 // properties. 1759 if (in ParseShortHand)1760 if (inShorthand()) 1760 1761 break; 1761 1762 } -
trunk/WebCore/khtml/css/cssparser.h
r11272 r11481 120 120 DOM::DocumentImpl *document() const; 121 121 122 void addProperty( int propId, CSSValueImpl *value, bool important);122 void addProperty(int propId, CSSValueImpl *value, bool important); 123 123 bool hasProperties() const { return numParsedProperties > 0; } 124 124 CSSMutableStyleDeclarationImpl *createStyleDeclaration( CSSStyleRuleImpl *rule ); 125 125 void clearProperties(); 126 126 127 bool parseValue( int propId, bool important);128 bool parseShort Hand( const int *properties, int numProperties, bool important);129 bool parse4Values( const int *properties, bool important);130 bool parseContent( int propId, bool important);127 bool parseValue(int propId, bool important); 128 bool parseShorthand(int propId, const int *properties, int numProperties, bool important); 129 bool parse4Values(int propId, const int *properties, bool important); 130 bool parseContent(int propId, bool important); 131 131 132 132 CSSValueImpl* parseBackgroundColor(); … … 171 171 int numParsedProperties; 172 172 int maxParsedProperties; 173 bool inParseShortHand; 173 174 int m_inParseShorthand; 175 int m_currentShorthand; 176 bool m_implicitShorthand; 174 177 175 178 AtomicString defaultNamespace; … … 186 189 private: 187 190 void setupParser(const char *prefix, const DOMString &string, const char *suffix); 188 191 void enterShorthand(int propId) 192 { 193 if (!(m_inParseShorthand++)) 194 m_currentShorthand = propId; 195 } 196 void exitShorthand() 197 { 198 if (!(--m_inParseShorthand)) 199 m_currentShorthand = 0; 200 } 201 bool inShorthand() const { return m_inParseShorthand; } 202 189 203 unsigned short *data; 190 204 unsigned short *yytext; -
trunk/WebCore/khtml/css/cssstyleselector.cpp
r11333 r11481 3 3 * 4 4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 5 * Copyright (C) 2004 Apple Computer, Inc. 5 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 6 * Copyright (C) 2005 Apple Computer, Inc. 6 7 * 7 8 * This library is free software; you can redistribute it and/or … … 255 256 m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheetImpl*>(it.current()), m_medium); 256 257 258 m_ruleList = 0; 259 m_collectRulesOnly = false; 260 257 261 //kdDebug( 6080 ) << "number of style sheets in document " << authorStyleSheets.count() << endl; 258 262 //kdDebug( 6080 ) << "CSSStyleSelector: author style has " << authorStyle->count() << " elements"<< endl; … … 387 391 388 392 // Now transfer the set of matched rules over to our list of decls. 389 for (unsigned i = 0; i < m_matchedRuleCount; i++) 390 addMatchedDeclaration(m_matchedRules[i]->rule()->declaration()); 393 if (!m_collectRulesOnly) { 394 for (unsigned i = 0; i < m_matchedRuleCount; i++) 395 addMatchedDeclaration(m_matchedRules[i]->rule()->declaration()); 396 } else { 397 for (unsigned i = 0; i < m_matchedRuleCount; i++) { 398 if (!m_ruleList) 399 m_ruleList = new CSSRuleListImpl(); 400 m_ruleList->append(m_matchedRules[i]->rule()); 401 } 402 } 391 403 } 392 404 … … 406 418 // If we're matching normal rules, set a pseudo bit if 407 419 // we really just matched a pseudo-element. 408 if ( dynamicPseudo != RenderStyle::NOPSEUDO && pseudoStyle == RenderStyle::NOPSEUDO)420 if (!m_collectRulesOnly && dynamicPseudo != RenderStyle::NOPSEUDO && pseudoStyle == RenderStyle::NOPSEUDO) 409 421 style->setHasPseudoStyle(dynamicPseudo); 410 422 else { … … 530 542 m_matchedDeclCount = 0; 531 543 m_tmpRuleCount = 0; 532 544 m_ruleList = 0; 545 533 546 fontDirty = false; 534 547 } … … 1043 1056 if (style->hasFixedBackgroundImage() && view) 1044 1057 view->useSlowRepaints(); 1058 } 1059 1060 RefPtr<CSSRuleListImpl> CSSStyleSelector::styleRulesForElement(ElementImpl* e, bool authorOnly) 1061 { 1062 if (!e->getDocument()->haveStylesheetsLoaded()) 1063 return 0; 1064 1065 m_collectRulesOnly = true; 1066 1067 initElementAndPseudoState(e); 1068 initForStyleResolve(e, 0); 1069 1070 if (!authorOnly) { 1071 // First we match rules from the user agent sheet. 1072 int firstUARule = -1, lastUARule = -1; 1073 matchRules(defaultStyle, firstUARule, lastUARule); 1074 1075 // In quirks mode, we match rules from the quirks user agent sheet. 1076 if (!strictParsing) 1077 matchRules(defaultQuirksStyle, firstUARule, lastUARule); 1078 1079 // If our medium is print, then we match rules from the print sheet. 1080 if (m_medium == "print") 1081 matchRules(defaultPrintStyle, firstUARule, lastUARule); 1082 1083 // Now we check user sheet rules. 1084 int firstUserRule = -1, lastUserRule = -1; 1085 matchRules(m_userStyle, firstUserRule, lastUserRule); 1086 } 1087 1088 // Check the rules in author sheets. 1089 int firstAuthorRule = -1, lastAuthorRule = -1; 1090 matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule); 1091 1092 m_collectRulesOnly = false; 1093 1094 return m_ruleList; 1095 } 1096 1097 RefPtr<CSSRuleListImpl> CSSStyleSelector::pseudoStyleRulesForElement(ElementImpl* e, DOMStringImpl* pseudoStyle, bool authorOnly) 1098 { 1099 // FIXME: Implement this. 1100 return 0; 1045 1101 } 1046 1102 -
trunk/WebCore/khtml/css/cssstyleselector.h
r11272 r11481 115 115 bool canShareStyleWithElement(DOM::NodeImpl* n); 116 116 117 // These methods will give back the set of rules that matched for a given element (or a pseudo-element). 118 RefPtr<DOM::CSSRuleListImpl> styleRulesForElement(DOM::ElementImpl* e, bool authorOnly); 119 RefPtr<DOM::CSSRuleListImpl> pseudoStyleRulesForElement(DOM::ElementImpl* e, DOM::DOMStringImpl* pseudoStyle, bool authorOnly); 120 117 121 bool strictParsing; 118 122 … … 211 215 QMemArray<CSSRuleData*> m_tmpRules; 212 216 unsigned m_tmpRuleCount; 213 217 DOM::CSSRuleListImpl* m_ruleList; 218 bool m_collectRulesOnly; 219 214 220 QString m_medium; 215 221 -
trunk/WebCore/khtml/ecma/kjs_css.cpp
r11271 r11481 111 111 removeProperty DOMCSSStyleDeclaration::RemoveProperty DontDelete|Function 1 112 112 getPropertyPriority DOMCSSStyleDeclaration::GetPropertyPriority DontDelete|Function 1 113 getPropertyShorthand DOMCSSStyleDeclaration::GetPropertyShorthand DontDelete|Function 1 114 isPropertyImplicit DOMCSSStyleDeclaration::IsPropertyImplicit DontDelete|Function 1 113 115 setProperty DOMCSSStyleDeclaration::SetProperty DontDelete|Function 3 114 116 item DOMCSSStyleDeclaration::Item DontDelete|Function 1 … … 258 260 case DOMCSSStyleDeclaration::GetPropertyPriority: 259 261 return getStringOrNull(styleDecl.getPropertyPriority(s)); 262 case DOMCSSStyleDeclaration::GetPropertyShorthand: 263 return getStringOrNull(styleDecl.getPropertyShorthand(s)); 264 case DOMCSSStyleDeclaration::IsPropertyImplicit: 265 return Boolean(styleDecl.isPropertyImplicit(s)); 260 266 case DOMCSSStyleDeclaration::SetProperty: 261 267 styleDecl.setProperty(s, args[1]->toString(exec).domString(), args[2]->toString(exec).domString(), exception); -
trunk/WebCore/khtml/ecma/kjs_css.h
r11375 r11481 58 58 enum { CssText, Length, ParentRule }; 59 59 enum { GetPropertyValue, GetPropertyCSSValue, RemoveProperty, 60 GetPropertyPriority, SetProperty, Item };60 GetPropertyPriority, GetPropertyShorthand, IsPropertyImplicit, SetProperty, Item }; 61 61 DOM::CSSStyleDeclarationImpl *impl() const { return m_impl.get(); } 62 62 private: -
trunk/WebCore/khtml/ecma/kjs_views.cpp
r11270 r11481 33 33 using DOM::ElementImpl; 34 34 using DOM::NodeImpl; 35 35 using DOM::CSSRuleListImpl; 36 36 37 37 #include "kjs_views.lut.h" … … 48 48 @begin DOMAbstractViewProtoTable 1 49 49 getComputedStyle DOMAbstractView::GetComputedStyle DontDelete|Function 2 50 getMatchedCSSRules DOMAbstractView::GetMatchedCSSRules DontDelete|Function 2 50 51 @end 51 52 */ … … 93 94 } 94 95 } 96 case DOMAbstractView::GetMatchedCSSRules: { 97 ElementImpl *arg0 = toElement(args[0]); 98 if (!arg0) 99 return Undefined(); // throw exception? 100 else { 101 // No need to update layout, since we just want the back-end rules. 102 return getDOMCSSRuleList(exec, abstractView.getMatchedCSSRules(arg0, 103 args[1]->toString(exec).domString().impl()).get()); 104 } 105 } 95 106 } 96 107 return Undefined(); -
trunk/WebCore/khtml/ecma/kjs_views.h
r11375 r11481 40 40 static const ClassInfo info; 41 41 DOM::AbstractViewImpl *impl() const { return m_impl.get(); } 42 enum { Document, GetComputedStyle };42 enum { Document, GetComputedStyle, GetMatchedCSSRules }; 43 43 private: 44 44 RefPtr<DOM::AbstractViewImpl> m_impl; -
trunk/WebCore/khtml/xml/dom2_viewsimpl.cpp
r11270 r11481 27 27 #include "css/css_computedstyle.h" 28 28 #include "dom_elementimpl.h" 29 #include "dom_docimpl.h" 30 #include "cssstyleselector.h" 29 31 30 32 namespace DOM { … … 42 44 { 43 45 // FIXME: This should work even if we do not have a renderer. 44 46 // FIXME: This needs to work with pseudo elements. 45 47 if (!elt || !elt->renderer()) 46 48 return 0; … … 49 51 } 50 52 53 RefPtr<CSSRuleListImpl> AbstractViewImpl::getMatchedCSSRules(ElementImpl* elt, DOMStringImpl* pseudoElt, bool authorOnly) 54 { 55 if (pseudoElt && pseudoElt->l) 56 return m_document->styleSelector()->pseudoStyleRulesForElement(elt, pseudoElt, authorOnly); 57 return m_document->styleSelector()->styleRulesForElement(elt, authorOnly); 51 58 } 59 60 } -
trunk/WebCore/khtml/xml/dom2_viewsimpl.h
r11270 r11481 31 31 class DocumentImpl; 32 32 class CSSStyleDeclarationImpl; 33 class CSSRuleListImpl; 33 34 class ElementImpl; 34 35 class DOMStringImpl; … … 43 44 DocumentImpl *document() const { return m_document; } 44 45 CSSStyleDeclarationImpl *getComputedStyle(ElementImpl *elt, DOMStringImpl *pseudoElt); 46 RefPtr<CSSRuleListImpl> getMatchedCSSRules(ElementImpl *elt, DOMStringImpl *pseudoElt, bool authorOnly = true); 47 45 48 protected: 46 49 DocumentImpl *m_document; -
trunk/WebCore/kwq/DOM-CSS.mm
r11341 r11481 758 758 } 759 759 760 - (NSString *)getPropertyShorthand:(NSString *)propertyName 761 { 762 return [self _styleDeclarationImpl]->getPropertyShorthand(propertyName); 763 } 764 765 - (BOOL)isPropertyImplicit:(NSString *)propertyName 766 { 767 return [self _styleDeclarationImpl]->isPropertyImplicit(propertyName); 768 } 769 760 770 - (void)setProperty:(NSString *)propertyName :(NSString *)value :(NSString *)priority 761 771 { … … 2517 2527 } 2518 2528 2519 @end 2529 - (DOMCSSRuleList *)getMatchedCSSRules:(DOMElement *)elt :(NSString *)pseudoElt 2530 { 2531 // The parameter of "false" is handy for the DOM inspector and lets us see user agent and user rules. 2532 return [DOMCSSRuleList _ruleListWithImpl: AbstractViewImpl([self _documentImpl]).getMatchedCSSRules([elt _elementImpl], DOMString(pseudoElt).impl(), false).get()]; 2533 } 2534 2535 @end -
trunk/WebCore/kwq/DOMPrivate.h
r11285 r11481 86 86 @end 87 87 88 @interface DOMCSSStyleDeclaration (DOMCSSStyleDeclarationExtensions) 89 - (NSString *)getPropertyShorthand:(NSString *)propertyName; 90 - (BOOL)isPropertyImplicit:(NSString *)propertyName; 91 @end 88 92 // END 89 93
Note:
See TracChangeset
for help on using the changeset viewer.