#ifndef TextAutoSizing_h
#define TextAutoSizing_h
#if ENABLE(IOS_TEXT_AUTOSIZING)
#include "RenderStyle.h"
#include <wtf/HashSet.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class Document;
class Node;
class TextAutoSizingKey {
public:
TextAutoSizingKey();
TextAutoSizingKey(RenderStyle*, Document*);
~TextAutoSizingKey();
TextAutoSizingKey(const TextAutoSizingKey&);
TextAutoSizingKey& operator=(const TextAutoSizingKey&);
Document* doc() const { return m_doc; }
RenderStyle* style() const { return m_style; }
inline bool isValidDoc() const { return m_doc && m_doc != deletedKeyDoc(); }
inline bool isValidStyle() const { return m_style && m_style != deletedKeyStyle(); }
static Document* deletedKeyDoc() { return reinterpret_cast<Document*>(-1); }
static RenderStyle* deletedKeyStyle() { return reinterpret_cast<RenderStyle*>(-1); }
private:
void ref() const;
void deref() const;
RenderStyle* m_style;
Document* m_doc;
};
inline bool operator==(const TextAutoSizingKey& a, const TextAutoSizingKey& b)
{
if (a.isValidStyle() && b.isValidStyle())
return a.style()->equalForTextAutosizing(b.style());
return a.style() == b.style();
}
struct TextAutoSizingHash {
static unsigned hash(const TextAutoSizingKey& key) { return key.style()->hashForTextAutosizing(); }
static bool equal(const TextAutoSizingKey& a, const TextAutoSizingKey& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = true;
};
class TextAutoSizingValue : public RefCounted<TextAutoSizingValue> {
public:
static PassRefPtr<TextAutoSizingValue> create()
{
return adoptRef(new TextAutoSizingValue);
}
void addNode(Node*, float size);
bool adjustNodeSizes();
int numNodes() const;
void reset();
private:
TextAutoSizingValue() { }
HashSet<RefPtr<Node> > m_autoSizedNodes;
};
}
#endif // ENABLE(IOS_TEXT_AUTOSIZING)
#endif // TextAutoSizing_h