|
1 /* |
|
2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
|
4 * |
|
5 * This library is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU Library General Public |
|
7 * License as published by the Free Software Foundation; either |
|
8 * version 2 of the License, or (at your option) any later version. |
|
9 * |
|
10 * This library is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 * Library General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Library General Public License |
|
16 * along with this library; see the file COPYING.LIB. If not, write to |
|
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
18 * Boston, MA 02110-1301, USA. |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "config.h" |
|
23 #include "ContentData.h" |
|
24 |
|
25 #include "CounterContent.h" |
|
26 #include "StringImpl.h" |
|
27 #include "StyleImage.h" |
|
28 |
|
29 namespace WebCore { |
|
30 |
|
31 void ContentData::clear() |
|
32 { |
|
33 deleteContent(); |
|
34 |
|
35 ContentData* n = m_next; |
|
36 m_next = 0; |
|
37 |
|
38 // Reverse the list so we can delete without recursing. |
|
39 ContentData* last = 0; |
|
40 ContentData* c; |
|
41 while ((c = n)) { |
|
42 n = c->m_next; |
|
43 c->m_next = last; |
|
44 last = c; |
|
45 } |
|
46 for (c = last; c; c = n) { |
|
47 n = c->m_next; |
|
48 c->m_next = 0; |
|
49 delete c; |
|
50 } |
|
51 } |
|
52 |
|
53 bool ContentData::dataEquivalent(const ContentData& other) const |
|
54 { |
|
55 if (type() != other.type()) |
|
56 return false; |
|
57 |
|
58 switch (type()) { |
|
59 case CONTENT_NONE: |
|
60 return true; |
|
61 break; |
|
62 case CONTENT_TEXT: |
|
63 return equal(text(), other.text()); |
|
64 break; |
|
65 case CONTENT_OBJECT: |
|
66 return StyleImage::imagesEquivalent(image(), other.image()); |
|
67 break; |
|
68 case CONTENT_COUNTER: |
|
69 return *counter() == *other.counter(); |
|
70 break; |
|
71 } |
|
72 |
|
73 ASSERT_NOT_REACHED(); |
|
74 return false; |
|
75 } |
|
76 |
|
77 void ContentData::deleteContent() |
|
78 { |
|
79 switch (m_type) { |
|
80 case CONTENT_NONE: |
|
81 break; |
|
82 case CONTENT_OBJECT: |
|
83 m_content.m_image->deref(); |
|
84 break; |
|
85 case CONTENT_TEXT: |
|
86 m_content.m_text->deref(); |
|
87 break; |
|
88 case CONTENT_COUNTER: |
|
89 delete m_content.m_counter; |
|
90 break; |
|
91 } |
|
92 |
|
93 m_type = CONTENT_NONE; |
|
94 } |
|
95 |
|
96 } // namespace WebCore |