http://bugzilla.opendarwin.org/show_bug.cgi?id=10676
@charset rules not accessible via DOM
Test: fast/encoding/css-charset-dom.html
* WebCore.xcodeproj/project.pbxproj: Added CSSCharsetRule.cpp
* bindings/js/kjs_css.cpp:
(KJS::DOMCSSStyleSheet::getValueProperty):
Separated Rules and CssRules, since now they behave differently.
* css/CSSCharsetRule.h: Make the constructor take an encoding.
* css/CSSCharsetRule.cpp: Added.
* css/CSSGrammar.y: Create CSSStylesheetRules as necessary.
* css/CSSRuleList.cpp:
(WebCore::CSSRuleList::CSSRuleList):
* css/CSSRuleList.h:
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::cssRules):
* css/CSSStyleSheet.h:
Skip charset rules in IE compatibility mode.
* css/StyleBase.h:
(WebCore::StyleBase::isCharsetRule): Fixed a typo.
* css/cssparser.cpp:
(WebCore::CSSParser::createCharsetRule):
* css/cssparser.h:
Added createCharsetRule().
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16217
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-09-04 Alexey Proskuryakov <ap@nypop.com>
+
+ Reviewed by Darin.
+
+ Test for http://bugzilla.opendarwin.org/show_bug.cgi?id=10676
+ @charset rules not accessible via DOM
+
+ * fast/encoding/css-charset-dom-expected.txt: Added.
+ * fast/encoding/css-charset-dom.html: Added.
+
2006-09-04 Rob Buis <buis@kde.org>
Reviewed by Eric.
--- /dev/null
+Test for bug 10676: @charset rules not accessible via DOM
+
+cssText: @charset "utf-8";
+encoding: utf-8
+Resetting encoding...
+cssText: @charset "koi8-r";
+encoding: koi8-r
+
+
--- /dev/null
+<html>
+<head>
+ <meta content="text/html; charset=windows-1251" http-equiv="Content-Type"/>
+ <link rel="stylesheet" type="text/css" href="css-charset.css" charset="windows-1251">
+ <!-- The document charset and link charset have lower priority than @charset, so they
+ shouldn't affect anything. -->
+</head>
+<body onload="test()">
+<p>Test for <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=10676">bug 10676</a>:
+@charset rules not accessible via DOM</p>
+
+<p id="result"></p>
+
+<script>
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+function test() {
+ try {
+ charsetRule = document.styleSheets[0].cssRules[0];
+ document.getElementById("result").innerHTML = "cssText: " + charsetRule.cssText + "<br>encoding: " + charsetRule.encoding;
+ document.getElementById("result").innerHTML += "<br>Resetting encoding...";
+ charsetRule.encoding = "koi8-r";
+ document.getElementById("result").innerHTML += "<br>cssText: " + charsetRule.cssText + "<br>encoding: " + charsetRule.encoding;
+ } catch (ex) {
+ document.getElementById("result").textContent = ex.toString();
+ }
+}
+</script>
+
+</body>
+</html>
+2006-09-04 Alexey Proskuryakov <ap@nypop.com>
+
+ Reviewed by Darin.
+
+ http://bugzilla.opendarwin.org/show_bug.cgi?id=10676
+ @charset rules not accessible via DOM
+
+ Test: fast/encoding/css-charset-dom.html
+
+ * WebCore.xcodeproj/project.pbxproj: Added CSSCharsetRule.cpp
+ * bindings/js/kjs_css.cpp:
+ (KJS::DOMCSSStyleSheet::getValueProperty):
+ Separated Rules and CssRules, since now they behave differently.
+
+ * css/CSSCharsetRule.h: Make the constructor take an encoding.
+ * css/CSSCharsetRule.cpp: Added.
+
+ * css/CSSGrammar.y: Create CSSStylesheetRules as necessary.
+
+ * css/CSSRuleList.cpp:
+ (WebCore::CSSRuleList::CSSRuleList):
+ * css/CSSRuleList.h:
+ * css/CSSStyleSheet.cpp:
+ (WebCore::CSSStyleSheet::cssRules):
+ * css/CSSStyleSheet.h:
+ Skip charset rules in IE compatibility mode.
+
+ * css/StyleBase.h:
+ (WebCore::StyleBase::isCharsetRule): Fixed a typo.
+
+ * css/cssparser.cpp:
+ (WebCore::CSSParser::createCharsetRule):
+ * css/cssparser.h:
+ Added createCharsetRule().
+
2006-09-04 Nikolas Zimmermann <zimmermann@kde.org>
Reviewed by Darin.
case OwnerRule:
return toJS(exec, static_cast<CSSStyleSheet*>(impl())->ownerRule());
case CssRules:
- case Rules:
return toJS(exec, static_cast<CSSStyleSheet*>(impl())->cssRules());
+ case Rules:
+ return toJS(exec, static_cast<CSSStyleSheet*>(impl())->cssRules(true));
default:
assert(0);
return jsUndefined();
--- /dev/null
+/**
+ * This file is part of the DOM implementation for KDE.
+ *
+ * Copyright (C) 2006 Apple Computer, Inc.
+ * Copyright (C) 2006 Alexey Proskuryakov (ap@macrules.ru)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "config.h"
+#include "CSSCharsetRule.h"
+
+namespace WebCore {
+
+CSSCharsetRule::CSSCharsetRule(StyleBase* parent, const String& encoding)
+ : CSSRule(parent)
+ , m_encoding(encoding)
+{
+ m_type = CHARSET_RULE;
+}
+
+CSSCharsetRule::~CSSCharsetRule()
+{
+}
+
+String CSSCharsetRule::cssText() const
+{
+ return "@charset \"" + m_encoding + "\";";
+}
+
+}
class CSSCharsetRule : public CSSRule
{
public:
- CSSCharsetRule(StyleBase* parent) : CSSRule(parent) { m_type = CHARSET_RULE; }
+ CSSCharsetRule(StyleBase* parent, const String& encoding);
+ virtual ~CSSCharsetRule();
virtual bool isCharsetRule() { return true; }
virtual String cssText() const;
String encoding() const { return m_encoding; }
- void setEncoding(String _encoding) { m_encoding = _encoding; }
+ void setEncoding(const String& encoding) { m_encoding = encoding; }
protected:
String m_encoding;
%type <relation> combinator
+%type <rule> charset
%type <rule> ruleset
%type <rule> media
%type <rule> import
maybe_charset:
/* empty */
- | CHARSET_SYM maybe_space STRING maybe_space ';'
- | CHARSET_SYM error invalid_block
- | CHARSET_SYM error ';'
- ;
+ | charset {
+ }
+;
+
+charset:
+ CHARSET_SYM maybe_space STRING maybe_space ';' {
+ CSSParser* p = static_cast<CSSParser*>(parser);
+ $$ = static_cast<CSSParser *>(parser)->createCharsetRule($3);
+ if ($$ && p->styleElement && p->styleElement->isCSSStyleSheet())
+ p->styleElement->append($$);
+ }
+ | CHARSET_SYM error invalid_block {
+ }
+ | CHARSET_SYM error ';' {
+ }
+;
import_list:
/* empty */
{
}
-CSSRuleList::CSSRuleList(StyleList* lst)
+CSSRuleList::CSSRuleList(StyleList* lst, bool omitCharsetRules)
{
if (lst) {
unsigned len = lst->length();
for (unsigned i = 0; i < len; ++i) {
StyleBase* style = lst->item(i);
- if (style->isRule())
+ if (style->isRule() && !(omitCharsetRules && style->isCharsetRule()))
append(static_cast<CSSRule*>(style));
}
}
{
public:
CSSRuleList();
- CSSRuleList(StyleList*);
+ CSSRuleList(StyleList*, bool omitCharsetRules = false);
~CSSRuleList();
unsigned length() const { return m_lstCSSRules.count(); }
return insertRule(selector + " { " + style + " }", index, ec);
}
-CSSRuleList *CSSStyleSheet::cssRules()
+CSSRuleList *CSSStyleSheet::cssRules(bool omitCharsetRules)
{
- return new CSSRuleList(this);
+ return new CSSRuleList(this, omitCharsetRules);
}
void CSSStyleSheet::deleteRule(unsigned index, ExceptionCode& ec)
virtual String type() const { return "text/css"; }
CSSRule* ownerRule() const;
- CSSRuleList* cssRules();
+ CSSRuleList* cssRules(bool omitCharsetRules = false);
unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
void deleteRule(unsigned index, ExceptionCode&);
unsigned addRule(const String& selector, const String& style, int index, ExceptionCode&);
virtual bool isRuleList() { return false; }
virtual bool isRule() { return false; }
virtual bool isStyleRule() { return false; }
- virtual bool isCharetRule() { return false; }
+ virtual bool isCharsetRule() { return false; }
virtual bool isImportRule() { return false; }
virtual bool isMediaRule() { return false; }
virtual bool isFontFaceRule() { return false; }
#include "CSSBorderImageValue.h"
#include "CSSImageValue.h"
+#include "CSSCharsetRule.h"
#include "CSSImportRule.h"
#include "CSSInheritedValue.h"
#include "CSSInitialValue.h"
return list;
}
+CSSRule* CSSParser::createCharsetRule(const ParseString& charset)
+{
+ if (!styleElement)
+ return 0;
+ if (!styleElement->isCSSStyleSheet())
+ return 0;
+ CSSCharsetRule* rule = new CSSCharsetRule(styleElement, domString(charset));
+ m_parsedStyleObjects.append(rule);
+ return rule;
+}
+
CSSRule* CSSParser::createImportRule(const ParseString& URL, MediaList* media)
{
if (!media)
Value& sinkFloatingValue(Value&);
MediaList* createMediaList();
+ CSSRule* createCharsetRule(const ParseString&);
CSSRule* createImportRule(const ParseString&, MediaList*);
CSSRule* createMediaRule(MediaList*, CSSRuleList*);
CSSRuleList* createRuleList();