Commit f3933de7 authored by darin@apple.com's avatar darin@apple.com

2008-05-20 Darin Adler <darin@apple.com>

        Reviewed by Mitz.

        - a first small step of CSS DOM refactoring -- the eventual goal is to
          reduce StyleBase and possibly eliminate it, since it has multiple
          purposes and unneccessarily ties many classes together

        * css/CSSCursorImageValue.cpp:
        (WebCore::isSVGCursorIdentifier): Mark static so it has internal linkage.
        (WebCore::resourceReferencedByCursorElement): Ditto.
        (WebCore::CSSCursorImageValue::CSSCursorImageValue): Removed unused style
        argument.
        (WebCore::CSSCursorImageValue::updateIfSVGCursorIsUsed): Removed code to
        check if X and Y changed before changing them -- there's no reason to do
        that. Removed code that depended on the internals of CSSImageValue. The
        new code uses only protected functions rather than going right at the
        fields and uing internal knowledge of the base class.
        * css/CSSCursorImageValue.h: Added a create function, made constructor
        private, removed unused style argument.

        * css/CSSImageValue.cpp:
        (WebCore::CSSImageValue::CSSImageValue): Removed unused style argument.
        (WebCore::CSSImageValue::cachedImageURL): Added. A protected function for
        use by CSSCursorImageValue that gives the URL.
        (WebCore::CSSImageValue::clearCachedImage): Added. A protected function for
        use by CSSCursorImageValue that clears the CachedImage.
        * css/CSSImageValue.h: Added create functions, made constructors protected
        and private, removed unused style argument, made data members private, added
        some protected functions for use by CSSCursorImageValue.

        * css/CSSImportRule.cpp:
        (WebCore::CSSImportRule::setCSSStyleSheet): Changed to call checkLoaded on
        the parent. This is part of preparation to move the checkLoaded function from
        StyleBase to StyleSheet.
        (WebCore::CSSImportRule::insertedIntoParent): Changed code to check the URL
        of the style sheet to use the href function of the style sheet rather than
        the baseURL function. This eliminates an O(n^2) algorithm here and reduces
        the use of baseURL, part of preparation to move it from StyleBase
        to CSSStyleSheet.

        * css/CSSMutableStyleDeclaration.cpp:
        (WebCore::CSSMutableStyleDeclaration::setImageProperty): Changed to use create
        function instead of a direct call to new for the CSSImageValue classes.
        * css/CSSParser.cpp:
        (WebCore::CSSParser::parseValue): Ditto.
        (WebCore::CSSParser::parseContent): Ditto.
        (WebCore::CSSParser::parseFillImage): Ditto.
        (WebCore::CSSParser::parseBorderImage): Ditto.

        * css/CSSStyleSelector.cpp: Removed unneeded include of CSSImageValue.h.
        * rendering/style/RenderStyle.h: Removed unneeded include of
        CSSCursorImageValue.h, which was causing us to rebuild the world way too often.

        * xml/XSLImportRule.cpp:
        (WebCore::XSLImportRule::setXSLStyleSheet): See change to CSSImportRule above.
        (WebCore::XSLImportRule::loadSheet): Ditto.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33934 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fe9d0e7b
2008-05-20 Darin Adler <darin@apple.com>
Reviewed by Mitz.
- a first small step of CSS DOM refactoring -- the eventual goal is to
reduce StyleBase and possibly eliminate it, since it has multiple
purposes and unneccessarily ties many classes together
* css/CSSCursorImageValue.cpp:
(WebCore::isSVGCursorIdentifier): Mark static so it has internal linkage.
(WebCore::resourceReferencedByCursorElement): Ditto.
(WebCore::CSSCursorImageValue::CSSCursorImageValue): Removed unused style
argument.
(WebCore::CSSCursorImageValue::updateIfSVGCursorIsUsed): Removed code to
check if X and Y changed before changing them -- there's no reason to do
that. Removed code that depended on the internals of CSSImageValue. The
new code uses only protected functions rather than going right at the
fields and uing internal knowledge of the base class.
* css/CSSCursorImageValue.h: Added a create function, made constructor
private, removed unused style argument.
* css/CSSImageValue.cpp:
(WebCore::CSSImageValue::CSSImageValue): Removed unused style argument.
(WebCore::CSSImageValue::cachedImageURL): Added. A protected function for
use by CSSCursorImageValue that gives the URL.
(WebCore::CSSImageValue::clearCachedImage): Added. A protected function for
use by CSSCursorImageValue that clears the CachedImage.
* css/CSSImageValue.h: Added create functions, made constructors protected
and private, removed unused style argument, made data members private, added
some protected functions for use by CSSCursorImageValue.
* css/CSSImportRule.cpp:
(WebCore::CSSImportRule::setCSSStyleSheet): Changed to call checkLoaded on
the parent. This is part of preparation to move the checkLoaded function from
StyleBase to StyleSheet.
(WebCore::CSSImportRule::insertedIntoParent): Changed code to check the URL
of the style sheet to use the href function of the style sheet rather than
the baseURL function. This eliminates an O(n^2) algorithm here and reduces
the use of baseURL, part of preparation to move it from StyleBase
to CSSStyleSheet.
* css/CSSMutableStyleDeclaration.cpp:
(WebCore::CSSMutableStyleDeclaration::setImageProperty): Changed to use create
function instead of a direct call to new for the CSSImageValue classes.
* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue): Ditto.
(WebCore::CSSParser::parseContent): Ditto.
(WebCore::CSSParser::parseFillImage): Ditto.
(WebCore::CSSParser::parseBorderImage): Ditto.
* css/CSSStyleSelector.cpp: Removed unneeded include of CSSImageValue.h.
* rendering/style/RenderStyle.h: Removed unneeded include of
CSSCursorImageValue.h, which was causing us to rebuild the world way too often.
* xml/XSLImportRule.cpp:
(WebCore::XSLImportRule::setXSLStyleSheet): See change to CSSImportRule above.
(WebCore::XSLImportRule::loadSheet): Ditto.
2008-05-20 Kevin McCullough <kmccullough@apple.com>
Rubber stamped by Adam.
/**
* This file is part of the DOM implementation for KDE.
*
/*
* Copyright (C) 2006 Rob Buis <buis@kde.org>
* (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -23,29 +22,26 @@
#include "config.h"
#include "CSSCursorImageValue.h"
#include "CachedImage.h"
#include "DocLoader.h"
#include "PlatformString.h"
#include "RenderStyle.h"
#include <wtf/MathExtras.h>
#if ENABLE(SVG)
#include "SVGCursorElement.h"
#include "SVGURIReference.h"
#endif
#include <wtf/MathExtras.h>
namespace WebCore {
#if ENABLE(SVG)
inline bool isSVGCursorIdentifier(const String& url)
static inline bool isSVGCursorIdentifier(const String& url)
{
KURL kurl(url);
return kurl.hasRef();
}
inline SVGCursorElement* resourceReferencedByCursorElement(const String& fragmentId, Document* document)
static inline SVGCursorElement* resourceReferencedByCursorElement(const String& fragmentId, Document* document)
{
Element* element = document->getElementById(SVGURIReference::getTarget(fragmentId));
if (element && element->hasTagName(SVGNames::cursorTag))
......@@ -55,8 +51,8 @@ inline SVGCursorElement* resourceReferencedByCursorElement(const String& fragmen
}
#endif
CSSCursorImageValue::CSSCursorImageValue(const String& url, const IntPoint& hotspot, StyleBase* style)
: CSSImageValue(url, style)
CSSCursorImageValue::CSSCursorImageValue(const String& url, const IntPoint& hotspot)
: CSSImageValue(url)
, m_hotspot(hotspot)
{
}
......@@ -91,19 +87,13 @@ bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element)
if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url, element->document())) {
int x = roundf(cursorElement->x().value());
if (x != m_hotspot.x())
m_hotspot.setX(x);
m_hotspot.setX(x);
int y = roundf(cursorElement->y().value());
if (y != m_hotspot.y())
m_hotspot.setY(y);
if (m_image && m_image->cachedImage()->url() != element->document()->completeURL(cursorElement->href())) {
m_image->cachedImage()->removeClient(this);
m_image = 0;
m_hotspot.setY(y);
m_accessedImage = false;
}
if (cachedImageURL() != element->document()->completeURL(cursorElement->href()))
clearCachedImage();
SVGElement* svgElement = static_cast<SVGElement*>(element);
m_referencedElements.add(svgElement);
......
/*
* This file is part of the DOM implementation for KDE.
*
* Copyright (C) 2006 Rob Buis <buis@kde.org>
* Copyright (C) 2008 Apple Inc. All right reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -24,7 +23,6 @@
#include "CSSImageValue.h"
#include "IntPoint.h"
#include <wtf/HashSet.h>
namespace WebCore {
......@@ -34,7 +32,11 @@ class SVGElement;
class CSSCursorImageValue : public CSSImageValue {
public:
CSSCursorImageValue(const String& url, const IntPoint& hotspot, StyleBase*);
static PassRefPtr<CSSCursorImageValue> create(const String& url, const IntPoint& hotspot)
{
return new CSSCursorImageValue(url, hotspot);
}
virtual ~CSSCursorImageValue();
IntPoint hotspot() const { return m_hotspot; }
......@@ -43,6 +45,8 @@ public:
virtual StyleCachedImage* cachedImage(DocLoader*);
private:
CSSCursorImageValue(const String& url, const IntPoint& hotspot);
IntPoint m_hotspot;
#if ENABLE(SVG)
......
......@@ -29,7 +29,7 @@
namespace WebCore {
CSSImageValue::CSSImageValue(const String& url, StyleBase* style)
CSSImageValue::CSSImageValue(const String& url)
: CSSPrimitiveValue(url, CSS_URI)
, m_accessedImage(false)
{
......@@ -74,4 +74,19 @@ StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader, const String& ur
return m_image.get();
}
String CSSImageValue::cachedImageURL()
{
if (!m_image)
return String();
return m_image->cachedImage()->url();
}
void CSSImageValue::clearCachedImage()
{
if (m_image)
m_image->cachedImage()->removeClient(this);
m_image = 0;
m_accessedImage = false;
}
} // namespace WebCore
/*
* This file is part of the DOM implementation for KDE.
*
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
* Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
* Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -32,11 +30,10 @@ namespace WebCore {
class DocLoader;
class StyleCachedImage;
class CSSImageValue : public CSSPrimitiveValue,
public CachedResourceClient {
class CSSImageValue : public CSSPrimitiveValue, private CachedResourceClient {
public:
CSSImageValue();
CSSImageValue(const String& url, StyleBase*);
static PassRefPtr<CSSImageValue> create() { return new CSSImageValue; }
static PassRefPtr<CSSImageValue> create(const String& url) { return new CSSImageValue(url); }
virtual ~CSSImageValue();
virtual StyleCachedImage* cachedImage(DocLoader*);
......@@ -44,7 +41,14 @@ public:
virtual bool isImageValue() const { return true; }
protected:
CSSImageValue(const String& url);
StyleCachedImage* cachedImage(DocLoader*, const String& url);
String cachedImageURL();
void clearCachedImage();
private:
CSSImageValue();
RefPtr<StyleCachedImage> m_image;
bool m_accessedImage;
......
......@@ -66,7 +66,8 @@ void CSSImportRule::setCSSStyleSheet(const String& url, const String& charset, c
m_styleSheet->parseString(sheet->sheetText(strict), strict);
m_loading = false;
checkLoaded();
if (parent)
parent->checkLoaded();
}
bool CSSImportRule::isLoading() const
......@@ -95,7 +96,7 @@ void CSSImportRule::insertedIntoParent()
// Check for a cycle in our import chain. If we encounter a stylesheet
// in our parent chain with the same URL, then just bail.
for (parent = static_cast<StyleBase*>(this)->parent(); parent; parent = parent->parent()) {
if (absHref == parent->baseURL())
if (parent->isCSSStyleSheet() && absHref == static_cast<CSSStyleSheet*>(parent)->href())
return;
}
......
......@@ -584,7 +584,7 @@ void CSSMutableStyleDeclaration::setStringProperty(int propertyId, const String
void CSSMutableStyleDeclaration::setImageProperty(int propertyId, const String& url, bool important)
{
removeProperty(propertyId);
m_values.append(CSSProperty(propertyId, new CSSImageValue(url, this), important));
m_values.append(CSSProperty(propertyId, CSSImageValue::create(url), important));
setChanged();
}
......
......@@ -843,10 +843,8 @@ bool CSSParser::parseValue(int propId, bool important)
} else if(strict && nrcoords == 2)
hotspot = IntPoint(coords[0], coords[1]);
if (strict || coords.size() == 0) {
if (!uri.isEmpty()) {
list->append(new CSSCursorImageValue(KURL(styleElement->baseURL(), uri).string(),
hotspot, styleElement));
}
if (!uri.isEmpty())
list->append(CSSCursorImageValue::create(KURL(styleElement->baseURL(), uri).string(), hotspot));
}
if ((strict && !value) || (value && !(value->unit == Value::Operator && value->iValue == ',')))
return false;
......@@ -906,13 +904,13 @@ bool CSSParser::parseValue(int propId, bool important)
}
case CSSPropertyListStyleImage: // <uri> | none | inherit
if (id == CSSValueNone) {
parsedValue = new CSSImageValue();
parsedValue = CSSImageValue::create();
valueList->next();
} else if (value->unit == CSSPrimitiveValue::CSS_URI) {
// ### allow string in non strict mode?
String uri = parseURL(value->string);
if (!uri.isEmpty()) {
parsedValue = new CSSImageValue(KURL(styleElement->baseURL(), uri).string(), styleElement);
parsedValue = CSSImageValue::create(KURL(styleElement->baseURL(), uri).string());
valueList->next();
}
} else if (value->unit == Value::Function && equalIgnoringCase(value->function->name, "-webkit-gradient(")) {
......@@ -1906,7 +1904,7 @@ bool CSSParser::parseContent(int propId, bool important)
if (val->unit == CSSPrimitiveValue::CSS_URI) {
// url
String value = parseURL(val->string);
parsedValue = new CSSImageValue(KURL(styleElement->baseURL(), value).string(), styleElement);
parsedValue = CSSImageValue::create(KURL(styleElement->baseURL(), value).string());
} else if (val->unit == Value::Function) {
// attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradient(...)
ValueList* args = val->function->args;
......@@ -1971,13 +1969,13 @@ PassRefPtr<CSSValue> CSSParser::parseBackgroundColor()
bool CSSParser::parseFillImage(RefPtr<CSSValue>& value)
{
if (valueList->current()->id == CSSValueNone) {
value = new CSSImageValue();
value = CSSImageValue::create();
return true;
}
if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
String uri = parseURL(valueList->current()->string);
if (!uri.isEmpty())
value = new CSSImageValue(KURL(styleElement->baseURL(), uri).string(), styleElement);
value = CSSImageValue::create(KURL(styleElement->baseURL(), uri).string());
return true;
}
if (valueList->current()->unit == Value::Function) {
......@@ -3421,7 +3419,7 @@ bool CSSParser::parseBorderImage(int propId, bool important, RefPtr<CSSValue>& r
String uri = parseURL(val->string);
if (uri.isEmpty())
return false;
context.commitImage(new CSSImageValue(KURL(styleElement->baseURL(), uri).string(), styleElement));
context.commitImage(CSSImageValue::create(KURL(styleElement->baseURL(), uri).string()));
} else if (val->unit == Value::Function) {
RefPtr<CSSValue> value;
if ((equalIgnoringCase(val->function->name, "-webkit-gradient(") && parseGradient(value)) ||
......
......@@ -30,7 +30,6 @@
#include "CSSFontFace.h"
#include "CSSFontFaceRule.h"
#include "CSSFontFaceSource.h"
#include "CSSImageValue.h"
#include "CSSImportRule.h"
#include "CSSMediaRule.h"
#include "CSSPrimitiveValueMappings.h"
......
......@@ -135,7 +135,7 @@ void Console::profile(ExecState* exec, const List& arguments) const
if (!page)
return;
const UString title = arguments[0]->toString(exec);
UString title = arguments[0]->toString(exec);
Profiler::profiler()->startProfiling(exec, page->group().identifier(), title);
}
......
......@@ -41,7 +41,6 @@
#include "CSSReflectionDirection.h"
#include "CSSValueList.h"
#include "Color.h"
#include "CSSCursorImageValue.h"
#include "CSSTransformValue.h"
#include "DataRef.h"
#include "Font.h"
......
......@@ -66,7 +66,8 @@ void XSLImportRule::setXSLStyleSheet(const String& url, const String& sheet)
m_styleSheet->parseString(sheet);
m_loading = false;
checkLoaded();
if (parent)
parent->checkLoaded();
}
bool XSLImportRule::isLoading()
......@@ -92,8 +93,8 @@ void XSLImportRule::loadSheet()
// Check for a cycle in our import chain. If we encounter a stylesheet
// in our parent chain with the same URL, then just bail.
for (parent = static_cast<StyleBase*>(this)->parent(); parent; parent = parent->parent()) {
if (absHref == parent->baseURL())
for (parent = this->parent(); parent; parent = parent->parent()) {
if (parent->isXSLStyleSheet() && absHref == static_cast<XSLStyleSheet*>(parent)->href())
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment