File indexing completed on 2024-04-28 11:39:36
0001 /* 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com) 0005 * (C) 2009 Vyacheslav Tokarev (tsjoker@gmail.com) 0006 * 0007 * This library is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU Library General Public 0009 * License as published by the Free Software Foundation; either 0010 * version 2 of the License, or (at your option) any later version. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Library General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Library General Public License 0018 * along with this library; see the file COPYING.LIB. If not, write to 0019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 * 0022 */ 0023 0024 #include "dom_restyler.h" 0025 0026 namespace khtml 0027 { 0028 0029 DynamicDomRestyler::DynamicDomRestyler() 0030 { 0031 } 0032 0033 void DynamicDomRestyler::addDependency(ElementImpl *subject, ElementImpl *dependency, StructuralDependencyType type) 0034 { 0035 assert(type < LastStructuralDependency); 0036 if (subject == dependency && type == HoverDependency) { 0037 subject->setHasHoverDependency(true); 0038 return; 0039 } 0040 0041 dependency_map[type].add(dependency, subject); 0042 reverse_map.add(subject, dependency); 0043 } 0044 0045 void DynamicDomRestyler::resetDependencies(ElementImpl *subject) 0046 { 0047 subject->setHasHoverDependency(false); 0048 0049 ElementMap::ElementsList list; 0050 reverse_map.getElements(subject, list); 0051 if (list.isEmpty()) { 0052 return; 0053 } 0054 for (int i = 0; i < list.size(); ++i) 0055 for (int type = 0; type < LastStructuralDependency; ++type) { 0056 dependency_map[type].remove(list[i], subject); 0057 } 0058 reverse_map.remove(subject); 0059 } 0060 0061 void DynamicDomRestyler::restyleDependent(ElementImpl *dependency, StructuralDependencyType type) 0062 { 0063 assert(type < LastStructuralDependency); 0064 if (type == HoverDependency && dependency->hasHoverDependency()) { 0065 dependency->setChanged(true); 0066 } 0067 0068 ElementMap::ElementsList list; 0069 dependency_map[type].getElements(dependency, list); 0070 for (int i = 0; i < list.size(); ++i) { 0071 list[i]->setChanged(true); 0072 } 0073 } 0074 0075 void DynamicDomRestyler::dumpStats() const 0076 { 0077 /* 0078 // qCDebug(KHTML_LOG) << "Keys in structural dependencies: " << dependency_map[StructuralDependency].size(); 0079 // qCDebug(KHTML_LOG) << "Keys in attribute dependencies: " << dependency_map[AttributeDependency].size(); 0080 0081 // qCDebug(KHTML_LOG) << "Keys in reverse map: " << reverse_map.size(); 0082 */ 0083 } 0084 0085 void DynamicDomRestyler::addDependency(uint attrID, AttributeDependencyType type) 0086 { 0087 assert(type < LastAttributeDependency); 0088 0089 unsigned int hash = (attrID * 257) % 512; 0090 attribute_map[type][hash] = true; 0091 } 0092 0093 bool DynamicDomRestyler::checkDependency(uint attrID, AttributeDependencyType type) 0094 { 0095 assert(type < LastAttributeDependency); 0096 0097 unsigned int hash = (attrID * 257) % 512; 0098 // ### gives false positives, but that's okay. 0099 return attribute_map[type][hash]; 0100 } 0101 0102 } // namespace