Changeset 79818 in webkit
- Timestamp:
- Feb 27, 2011 7:56:01 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r79817 r79818 1 2011-02-27 Andreas Kling <kling@webkit.org> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 [Qt] Use WTF ref counting for FontPlatformDataPrivate 6 https://bugs.webkit.org/show_bug.cgi?id=55303 7 8 Make FontPlatformDataPrivate a RefCounted<FPDP>. 9 Incidentally fixes an uninitialized member bug in FontPlatformData(). 10 11 * platform/graphics/qt/FontPlatformData.h: 12 (WebCore::FontPlatformDataPrivate::FontPlatformDataPrivate): 13 (WebCore::FontPlatformData::FontPlatformData): 14 (WebCore::FontPlatformData::isHashTableDeletedValue): 15 (WebCore::FontPlatformData::font): 16 (WebCore::FontPlatformData::size): 17 (WebCore::FontPlatformData::family): 18 (WebCore::FontPlatformData::bold): 19 (WebCore::FontPlatformData::italic): 20 (WebCore::FontPlatformData::smallCaps): 21 (WebCore::FontPlatformData::pixelSize): 22 * platform/graphics/qt/FontPlatformDataQt.cpp: 23 (WebCore::toQFontWeight): 24 (WebCore::FontPlatformData::operator==): 25 (WebCore::FontPlatformData::hash): 26 1 27 2011-02-27 Benjamin Poulain <ikipou@gmail.com> 2 28 -
trunk/Source/WebCore/platform/graphics/qt/FontPlatformData.h
r76248 r79818 25 25 #define FontPlatformData_h 26 26 27 #include <wtf/Forward.h>28 27 #include "FontDescription.h" 29 28 #include "FontOrientation.h" 30 29 #include <QFont> 31 30 #include <QHash> 31 #include <wtf/Forward.h> 32 #include <wtf/RefCounted.h> 32 33 33 34 namespace WebCore { 34 35 35 class FontPlatformDataPrivate {36 class FontPlatformDataPrivate : public RefCounted<FontPlatformDataPrivate> { 36 37 WTF_MAKE_NONCOPYABLE(FontPlatformDataPrivate); WTF_MAKE_FAST_ALLOCATED; 37 38 public: 38 39 FontPlatformDataPrivate() 39 : refCount(1) 40 : size(font.pixelSize()) 41 , bold(font.bold()) 42 , oblique(false) 43 , isDeletedValue(false) 44 { } 45 FontPlatformDataPrivate(const float size, const bool bold, const bool oblique) 46 : size(size) 47 , bold(bold) 48 , oblique(oblique) 49 , isDeletedValue(false) 50 { } 51 FontPlatformDataPrivate(const QFont& font) 52 : font(font) 40 53 , size(font.pixelSize()) 41 54 , bold(font.bold()) 42 55 , oblique(false) 43 {} 44 FontPlatformDataPrivate(const float size, const bool bold, const bool oblique) 45 : refCount(1) 46 , size(size) 47 , bold(bold) 48 , oblique(oblique) 49 {} 50 FontPlatformDataPrivate(const QFont& font) 51 : refCount(1) 52 , font(font) 53 , size(font.pixelSize()) 54 , bold(font.bold()) 55 , oblique(false) 56 {} 57 unsigned refCount; 56 , isDeletedValue(false) 57 { } 58 FontPlatformDataPrivate(WTF::HashTableDeletedValueType) 59 : isDeletedValue(true) 60 { } 61 58 62 QFont font; 59 63 float size; 60 64 bool bold : 1; 61 65 bool oblique : 1; 66 bool isDeletedValue : 1; 62 67 }; 63 64 65 68 66 69 class FontPlatformData { 67 70 WTF_MAKE_FAST_ALLOCATED; 68 71 public: 69 FontPlatformData() { }70 72 FontPlatformData(float size, bool bold, bool oblique); 71 FontPlatformData(const FontPlatformData &);72 73 FontPlatformData(const FontDescription&, const AtomicString& familyName, int wordSpacing = 0, int letterSpacing = 0); 73 74 FontPlatformData(const QFont& font) 74 : m_data( new FontPlatformDataPrivate(font))75 { }75 : m_data(adoptRef(new FontPlatformDataPrivate(font))) 76 { } 76 77 FontPlatformData(WTF::HashTableDeletedValueType) 77 : m_data(reinterpret_cast<FontPlatformDataPrivate*>(-1)) 78 {} 78 : m_data(adoptRef(new FontPlatformDataPrivate())) 79 { 80 m_data->isDeletedValue = true; 81 } 79 82 80 ~FontPlatformData();81 82 FontPlatformData& operator=(const FontPlatformData&);83 83 bool operator==(const FontPlatformData&) const; 84 84 85 85 bool isHashTableDeletedValue() const 86 86 { 87 return m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1); 88 } 89 90 static inline QFont::Weight toQFontWeight(FontWeight fontWeight) 91 { 92 switch (fontWeight) { 93 case FontWeight100: 94 case FontWeight200: 95 return QFont::Light; // QFont::Light == Weight of 25 96 case FontWeight600: 97 return QFont::DemiBold; // QFont::DemiBold == Weight of 63 98 case FontWeight700: 99 case FontWeight800: 100 return QFont::Bold; // QFont::Bold == Weight of 75 101 case FontWeight900: 102 return QFont::Black; // QFont::Black == Weight of 87 103 case FontWeight300: 104 case FontWeight400: 105 case FontWeight500: 106 default: 107 return QFont::Normal; // QFont::Normal == Weight of 50 108 } 87 return m_data && m_data->isDeletedValue; 109 88 } 110 89 111 90 QFont font() const 112 91 { 113 Q_ASSERT( m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));114 if ( m_data)115 return m_data->font;116 return QFont();92 Q_ASSERT(!isHashTableDeletedValue()); 93 if (!m_data) 94 return QFont(); 95 return m_data->font; 117 96 } 118 97 float size() const 119 98 { 120 Q_ASSERT( m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));121 if ( m_data)122 return m_data->size;123 return 0.0f;99 Q_ASSERT(!isHashTableDeletedValue()); 100 if (!m_data) 101 return 0; 102 return m_data->size; 124 103 } 125 104 QString family() const 126 105 { 127 Q_ASSERT( m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));128 if ( m_data)129 return m_data->font.family();130 return QString();106 Q_ASSERT(!isHashTableDeletedValue()); 107 if (!m_data) 108 return QString(); 109 return m_data->font.family(); 131 110 } 132 111 bool bold() const 133 112 { 134 Q_ASSERT( m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));135 if ( m_data)136 return m_data->bold;137 return false;113 Q_ASSERT(!isHashTableDeletedValue()); 114 if (!m_data) 115 return false; 116 return m_data->bold; 138 117 } 139 118 bool italic() const 140 119 { 141 Q_ASSERT( m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));142 if ( m_data)143 return m_data->font.italic();144 return false;120 Q_ASSERT(!isHashTableDeletedValue()); 121 if (!m_data) 122 return false; 123 return m_data->font.italic(); 145 124 } 146 125 bool smallCaps() const 147 126 { 148 Q_ASSERT( m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));149 if ( m_data)150 return m_data->font.capitalization() == QFont::SmallCaps;151 return false;127 Q_ASSERT(!isHashTableDeletedValue()); 128 if (!m_data) 129 return false; 130 return m_data->font.capitalization() == QFont::SmallCaps; 152 131 } 153 132 int pixelSize() const 154 133 { 155 Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)); 156 if (m_data) { 157 // WebKit allows font size zero but QFont does not. 158 if (!m_data->size) 159 return m_data->size; 160 return m_data->font.pixelSize(); 161 } 162 return 0; 134 Q_ASSERT(!isHashTableDeletedValue()); 135 if (!m_data) 136 return 0; 137 // WebCore allows a font size of zero, but QFont does not. 138 if (!m_data->size) 139 return 0; 140 return m_data->font.pixelSize(); 163 141 } 164 142 … … 171 149 #endif 172 150 private: 173 FontPlatformDataPrivate*m_data;151 RefPtr<FontPlatformDataPrivate> m_data; 174 152 }; 175 153 -
trunk/Source/WebCore/platform/graphics/qt/FontPlatformDataQt.cpp
r73341 r79818 2 2 Copyright (C) 2008 Holger Hans Peter Freyther 3 3 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 4 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) 4 5 5 6 This library is free software; you can redistribute it and/or … … 27 28 namespace WebCore { 28 29 30 static inline QFont::Weight toQFontWeight(FontWeight fontWeight) 31 { 32 switch (fontWeight) { 33 case FontWeight100: 34 case FontWeight200: 35 return QFont::Light; // QFont::Light == Weight of 25 36 case FontWeight600: 37 return QFont::DemiBold; // QFont::DemiBold == Weight of 63 38 case FontWeight700: 39 case FontWeight800: 40 return QFont::Bold; // QFont::Bold == Weight of 75 41 case FontWeight900: 42 return QFont::Black; // QFont::Black == Weight of 87 43 case FontWeight300: 44 case FontWeight400: 45 case FontWeight500: 46 default: 47 return QFont::Normal; // QFont::Normal == Weight of 50 48 } 49 } 50 29 51 static inline bool isEmptyValue(const float size, const bool bold, const bool oblique) 30 52 { … … 35 57 FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) 36 58 { 37 if (isEmptyValue(size, bold, oblique)) 38 m_data = 0; 39 else 40 m_data = new FontPlatformDataPrivate(size, bold, oblique); 41 } 42 43 FontPlatformData::FontPlatformData(const FontPlatformData &other) : m_data(other.m_data) 44 { 45 if (m_data && m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)) 46 ++m_data->refCount; 59 if (!isEmptyValue(size, bold, oblique)) 60 m_data = adoptRef(new FontPlatformDataPrivate(size, bold, oblique)); 47 61 } 48 62 49 63 FontPlatformData::FontPlatformData(const FontDescription& description, const AtomicString& familyName, int wordSpacing, int letterSpacing) 50 : m_data( new FontPlatformDataPrivate())64 : m_data(adoptRef(new FontPlatformDataPrivate())) 51 65 { 52 66 QFont& font = m_data->font; … … 71 85 } 72 86 73 FontPlatformData::~FontPlatformData()74 {75 if (!m_data || m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1))76 return;77 --m_data->refCount;78 if (!m_data->refCount)79 delete m_data;80 }81 82 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other)83 {84 if (m_data == other.m_data)85 return *this;86 if (m_data && m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)) {87 --m_data->refCount;88 if (!m_data->refCount)89 delete m_data;90 }91 m_data = other.m_data;92 if (m_data && m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1))93 ++m_data->refCount;94 return *this;95 }96 97 87 bool FontPlatformData::operator==(const FontPlatformData& other) const 98 88 { … … 100 90 return true; 101 91 102 if (!m_data || !other.m_data 103 || m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1) || other.m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1)) 104 return false; 92 if (!m_data || !other.m_data || m_data->isDeletedValue || other.m_data->isDeletedValue) 93 return false; 105 94 106 95 const bool equals = (m_data->size == other.m_data->size … … 115 104 if (!m_data) 116 105 return 0; 117 if (m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1))106 if (m_data->isDeletedValue) 118 107 return 1; 119 108 return qHash(m_data->font.toString())
Note: See TracChangeset
for help on using the changeset viewer.