[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/4.1/kdelibs/khtml
From:       Maks Orlovich <maksim () kde ! org>
Date:       2008-08-30 20:59:32
Message-ID: 1220129972.532197.9345.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 854972 by orlovich:

Pick up infrastructure for supporting getComputedStyle on display:none 
things from WebCore. Not hooked up yet --- RenderStyleDeclarationImpl 
needs to be taught not to use the renderer when not available.


 M  +3 -2      css/cssstyleselector.cpp  
 M  +2 -1      css/cssstyleselector.h  
 M  +99 -2     xml/dom_elementimpl.cpp  
 M  +12 -2     xml/dom_elementimpl.h  
 M  +10 -3     xml/dom_nodeimpl.cpp  
 M  +4 -2      xml/dom_nodeimpl.h  


--- branches/KDE/4.1/kdelibs/khtml/css/cssstyleselector.cpp #854971:854972
@@ -554,7 +554,7 @@
     }
 }
 
-RenderStyle *CSSStyleSelector::styleForElement(ElementImpl *e)
+RenderStyle *CSSStyleSelector::styleForElement(ElementImpl *e, RenderStyle* \
fallbackParentStyle)  {
     if (!e->document()->haveStylesheetsLoaded() || !e->document()->view()) {
         if (!styleNotYetAvailable) {
@@ -570,7 +570,8 @@
 
     element = e;
     parentNode = e->parentNode();
-    parentStyle = ( parentNode && parentNode->renderer()) ? \
parentNode->renderer()->style() : 0; +    parentStyle = ( parentNode && \
parentNode->renderer()) ? +                            \
parentNode->renderer()->style() : fallbackParentStyle;  view = \
element->document()->view();  part = view->part();
     settings = part->settings();
--- branches/KDE/4.1/kdelibs/khtml/css/cssstyleselector.h #854971:854972
@@ -180,7 +180,8 @@
 
 	static void loadDefaultStyle(const KHTMLSettings *s, DOM::DocumentImpl *doc);
 
-	RenderStyle *styleForElement(DOM::ElementImpl *e);
+	// fallbackParentStyle will be inheritted from if the parent doesn't have style \
info +	RenderStyle *styleForElement(DOM::ElementImpl *e, RenderStyle* \
fallbackParentStyle = 0);  
         QVector<int> fontSizes() const { return m_fontSizes; }
 	QVector<int> fixedFontSizes() const { return m_fixedFontSizes; }
--- branches/KDE/4.1/kdelibs/khtml/xml/dom_elementimpl.cpp #854971:854972
@@ -5,6 +5,8 @@
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Peter Kelly (pmk@post.com)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
+  *          (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *           (C) 2005, 2008 Maksim Orlovich (maksim@kde.org)  
  *           (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com)
  *
  * This library is free software; you can redistribute it and/or
@@ -54,13 +56,16 @@
 #include <kdebug.h>
 #include <stdlib.h>
 
+#include <wtf/HashMap.h>
+
 // ### support default attributes
 // ### dispatch mutation events
 // ### check for INVALID_CHARACTER_ERR where appropriate
 
-using namespace DOM;
 using namespace khtml;
 
+namespace DOM {
+
 AttrImpl::AttrImpl(ElementImpl* element, DocumentImpl* docPtr, NodeImpl::Id attrId,
 		   DOMStringImpl *value, DOMStringImpl *prefix)
     : NodeBaseImpl(docPtr),
@@ -72,7 +77,6 @@
     m_prefix = prefix;
     if (m_prefix)
 	m_prefix->ref();
-    m_specified = true; // we don't yet support default attributes
 
     // When creating the text node initially, we want element = 0,
     // so we don't attempt to update the getElementById cache or
@@ -361,6 +365,40 @@
 
 // -------------------------------------------------------------------------
 
+class ElementRareDataImpl {
+public:
+    ElementRareDataImpl();
+    void resetComputedStyle();
+    RenderStyle* m_computedStyle;
+};
+
+typedef WTF::HashMap<const ElementImpl*, ElementRareDataImpl*> ElementRareDataMap;
+
+static ElementRareDataMap& rareDataMap()
+{
+    static ElementRareDataMap* dataMap = new ElementRareDataMap;
+    return *dataMap;
+}
+
+static ElementRareDataImpl* rareDataFromMap(const ElementImpl* element)
+{
+    return rareDataMap().get(element);
+}
+
+inline ElementRareDataImpl::ElementRareDataImpl()
+    : m_computedStyle(0)
+{}
+
+void ElementRareDataImpl::resetComputedStyle()
+{
+    if (!m_computedStyle)
+        return;
+    m_computedStyle->deref();
+    m_computedStyle = 0;
+}
+
+// -------------------------------------------------------------------------
+
 ElementImpl::ElementImpl(DocumentImpl *doc)
     : NodeBaseImpl(doc)
 {
@@ -394,8 +432,39 @@
 
     if (m_prefix)
         m_prefix->deref();
+
+    if (!m_elementHasRareData) {
+        ASSERT(!rareDataMap().contains(this));
+    } else {
+        ElementRareDataMap& dataMap = rareDataMap();
+        ElementRareDataMap::iterator it = dataMap.find(this);
+        ASSERT(it != dataMap.end());
+        delete it->second;
+        dataMap.remove(it);
+    }
 }
 
+ElementRareDataImpl* ElementImpl::rareData()
+{
+    return m_elementHasRareData ? rareDataFromMap(this) : 0;
+}
+
+const ElementRareDataImpl* ElementImpl::rareData() const
+{
+    return m_elementHasRareData ? rareDataFromMap(this) : 0;
+}
+
+ElementRareDataImpl* ElementImpl::createRareData()
+{
+    if (m_elementHasRareData)
+        return rareDataMap().get(this);
+    ASSERT(!rareDataMap().contains(this));
+    ElementRareDataImpl* data = new ElementRareDataImpl();
+    rareDataMap().set(this, data);
+    m_elementHasRareData = true;
+    return data;
+}
+
 void ElementImpl::removeAttribute( NodeImpl::Id id, int &exceptioncode )
 {
     if (namedAttrMap) {
@@ -788,6 +857,9 @@
 {
     document()->dynamicDomRestyler().resetDependencies(this);
 
+    if (ElementRareDataImpl* rd = rareData())
+        rd->resetComputedStyle();
+
     NodeBaseImpl::detach();
 }
 
@@ -838,6 +910,11 @@
     RenderStyle* _style = m_render ? m_render->style() : 0;
     bool hasParentRenderer = parent() ? parent()->attached() : false;
 
+    if ((change > NoChange || changed())) {
+        if (ElementRareDataImpl* rd = rareData())
+            rd->resetComputedStyle();
+    }
+
 #if 0
     const char* debug;
     switch(change) {
@@ -1174,6 +1251,24 @@
     return result;
 }
 
+RenderStyle* ElementImpl::computedStyle()
+{
+    if (m_render && m_render->style())
+	return m_render->style();
+
+    if (!attached())
+        // FIXME: Try to do better than this. Ensure that styleForElement() works \
for elements that are not in the +        // document tree and figure out when to \
destroy the computed style for such elements. +        return 0;
+
+    ElementRareDataImpl* rd = createRareData();
+    if (!rd->m_computedStyle) {
+        rd->m_computedStyle = document()->styleSelector()->styleForElement(this, \
parent() ? parent()->computedStyle() : 0); +        rd->m_computedStyle->ref();
+    }
+    return rd->m_computedStyle;
+}
+
 // -------------------------------------------------------------------------
 
 XMLElementImpl::XMLElementImpl(DocumentImpl *doc, NodeImpl::Id id)
@@ -1572,3 +1667,5 @@
     m_attrs = 0;
     m_attrCount = 0;
 }
+
+}
\ No newline at end of file
--- branches/KDE/4.1/kdelibs/khtml/xml/dom_elementimpl.h #854971:854972
@@ -5,7 +5,7 @@
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Peter Kelly (pmk@post.com)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
- *           (C) 2003 Apple Computer, Inc.
+ *           (C) 2003, 2004, 2005, 2006, 2007 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
@@ -41,6 +41,7 @@
 class ElementImpl;
 class DocumentImpl;
 class NamedAttrMapImpl;
+class ElementRareDataImpl;
 
 // Attr can have Text and EntityReference children
 // therefore it has to be a fullblown Node. The plan
@@ -64,7 +65,7 @@
 public:
 
     // DOM methods & attributes for Attr
-    bool specified() const { return m_specified; }
+    bool specified() const { return true; /* we don't yet support default \
attributes*/ }  ElementImpl* ownerElement() const { return m_element; }
     void setOwnerElement( ElementImpl* impl ) { m_element = impl; }
     DOMString name() const;
@@ -245,6 +246,7 @@
     virtual khtml::RenderStyle *styleForRenderer(khtml::RenderObject *parent);
     virtual khtml::RenderObject *createRenderer(khtml::RenderArena *, \
khtml::RenderStyle *);  virtual void recalcStyle( StyleChange = NoChange );
+    virtual khtml::RenderStyle* computedStyle();
 
     virtual void mouseEventHandler( MouseEvent* /*ev*/, bool /*inside*/ ) {}
 
@@ -298,6 +300,14 @@
     // in the DTD
     virtual NamedAttrMapImpl* defaultMap() const;
 
+    // There is some information such as computed style for display:none
+    // elements that is needed only for a few elements. We store it
+    // in one of these. 
+    ElementRareDataImpl* rareData();
+    const ElementRareDataImpl* rareData() const;
+    ElementRareDataImpl* createRareData();
+
+
 protected: // member variables
     mutable NamedAttrMapImpl *namedAttrMap;
 
--- branches/KDE/4.1/kdelibs/khtml/xml/dom_nodeimpl.cpp #854971:854972
@@ -4,7 +4,8 @@
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
- *           (C) 2003-2006 Apple Computer, Inc.
+ *           (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *           (C) 2005 Maksim Orlovich (maksim@kde.org)
  *           (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com)
  *
  * This library is free software; you can redistribute it and/or
@@ -77,7 +78,7 @@
       m_changedAscendentAttribute( false ),
       m_inDocument( false ),
       m_hasAnchor( false ),
-      m_specified( false ),
+      m_elementHasRareData( false ),
       m_hovered( false ),
       m_focused( false ),
       m_active( false ),
@@ -1112,6 +1113,11 @@
     return 0;
 }
 
+RenderStyle *NodeImpl::computedStyle()
+{
+    return parentNode() ? parentNode()->computedStyle() : 0;
+}
+
 NodeImpl *NodeImpl::previousLeafNode() const
 {
     NodeImpl *node = traversePreviousNode();
@@ -2010,8 +2016,9 @@
                 len++;
         if (recurse)
             len+= NodeListImpl::calcLength(n);
-        }
+    }
 
+
     return len;
 }
 
--- branches/KDE/4.1/kdelibs/khtml/xml/dom_nodeimpl.h #854971:854972
@@ -4,7 +4,7 @@
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
- *           (C) 2003 Apple Computer, Inc.
+ *           (C) 2003, 2004, 2005, 2006, 2007 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
@@ -422,6 +422,8 @@
     virtual bool rendererIsNeeded(khtml::RenderStyle *);
     virtual khtml::RenderObject *createRenderer(khtml::RenderArena *, \
khtml::RenderStyle *);  
+    virtual khtml::RenderStyle* computedStyle();
+
     // -----------------------------------------------------------------------------
     // Methods for maintaining the state of the element between history navigation
 
@@ -520,7 +522,7 @@
     bool m_changedAscendentAttribute : 1;
     bool m_inDocument : 1;
     bool m_hasAnchor : 1;
-    bool m_specified : 1; // used in AttrImpl. Accessor functions there
+    bool m_elementHasRareData : 1;
 
     bool m_hovered : 1;
     bool m_focused : 1;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic