1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com)
5  *           (C) 2009 Vyacheslav Tokarev (tsjoker@gmail.com)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #include "dom_restyler.h"
25 
26 namespace khtml
27 {
28 
DynamicDomRestyler()29 DynamicDomRestyler::DynamicDomRestyler()
30 {
31 }
32 
addDependency(ElementImpl * subject,ElementImpl * dependency,StructuralDependencyType type)33 void DynamicDomRestyler::addDependency(ElementImpl *subject, ElementImpl *dependency, StructuralDependencyType type)
34 {
35     assert(type < LastStructuralDependency);
36     if (subject == dependency && type == HoverDependency) {
37         subject->setHasHoverDependency(true);
38         return;
39     }
40 
41     dependency_map[type].add(dependency, subject);
42     reverse_map.add(subject, dependency);
43 }
44 
resetDependencies(ElementImpl * subject)45 void DynamicDomRestyler::resetDependencies(ElementImpl *subject)
46 {
47     subject->setHasHoverDependency(false);
48 
49     ElementMap::ElementsList list;
50     reverse_map.getElements(subject, list);
51     if (list.isEmpty()) {
52         return;
53     }
54     for (int i = 0; i < list.size(); ++i)
55         for (int type = 0; type < LastStructuralDependency; ++type) {
56             dependency_map[type].remove(list[i], subject);
57         }
58     reverse_map.remove(subject);
59 }
60 
restyleDependent(ElementImpl * dependency,StructuralDependencyType type)61 void DynamicDomRestyler::restyleDependent(ElementImpl *dependency, StructuralDependencyType type)
62 {
63     assert(type < LastStructuralDependency);
64     if (type == HoverDependency && dependency->hasHoverDependency()) {
65         dependency->setChanged(true);
66     }
67 
68     ElementMap::ElementsList list;
69     dependency_map[type].getElements(dependency, list);
70     for (int i = 0; i < list.size(); ++i) {
71         list[i]->setChanged(true);
72     }
73 }
74 
dumpStats() const75 void DynamicDomRestyler::dumpStats() const
76 {
77     /*
78         // qCDebug(KHTML_LOG) << "Keys in structural dependencies: " << dependency_map[StructuralDependency].size();
79         // qCDebug(KHTML_LOG) << "Keys in attribute dependencies: " << dependency_map[AttributeDependency].size();
80 
81         // qCDebug(KHTML_LOG) << "Keys in reverse map: " << reverse_map.size();
82         */
83 }
84 
addDependency(uint attrID,AttributeDependencyType type)85 void DynamicDomRestyler::addDependency(uint attrID, AttributeDependencyType type)
86 {
87     assert(type < LastAttributeDependency);
88 
89     unsigned int hash = (attrID * 257) % 512;
90     attribute_map[type][hash] = true;
91 }
92 
checkDependency(uint attrID,AttributeDependencyType type)93 bool DynamicDomRestyler::checkDependency(uint attrID, AttributeDependencyType type)
94 {
95     assert(type < LastAttributeDependency);
96 
97     unsigned int hash = (attrID * 257) % 512;
98     // ### gives false positives, but that's okay.
99     return attribute_map[type][hash];
100 }
101 
102 } // namespace
103