#ifndef BidiContext_h
#define BidiContext_h
#include "platform/PlatformExport.h"
#include "wtf/Assertions.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
#include "wtf/unicode/Unicode.h"
namespace WebCore {
enum BidiEmbeddingSource {
FromStyleOrDOM,
FromUnicode
};
class PLATFORM_EXPORT BidiContext : public RefCounted<BidiContext> {
public:
static PassRefPtr<BidiContext> create(unsigned char level, WTF::Unicode::Direction, bool override = false, BidiEmbeddingSource = FromStyleOrDOM, BidiContext* parent = 0);
BidiContext* parent() const { return m_parent.get(); }
unsigned char level() const { return m_level; }
WTF::Unicode::Direction dir() const { return static_cast<WTF::Unicode::Direction>(m_direction); }
bool override() const { return m_override; }
BidiEmbeddingSource source() const { return static_cast<BidiEmbeddingSource>(m_source); }
PassRefPtr<BidiContext> copyStackRemovingUnicodeEmbeddingContexts();
static const unsigned char kMaxLevel = 125;
private:
BidiContext(unsigned char level, WTF::Unicode::Direction direction, bool override, BidiEmbeddingSource source, BidiContext* parent)
: m_level(level)
, m_direction(direction)
, m_override(override)
, m_source(source)
, m_parent(parent)
{
ASSERT(level <= kMaxLevel);
}
static PassRefPtr<BidiContext> createUncached(unsigned char level, WTF::Unicode::Direction, bool override, BidiEmbeddingSource, BidiContext* parent);
unsigned m_level : 7;
unsigned m_direction : 5;
unsigned m_override : 1;
unsigned m_source : 1;
RefPtr<BidiContext> m_parent;
};
inline unsigned char nextGreaterOddLevel(unsigned char level)
{
return (level + 1) | 1;
}
inline unsigned char nextGreaterEvenLevel(unsigned char level)
{
return (level + 2) & ~1;
}
PLATFORM_EXPORT bool operator==(const BidiContext&, const BidiContext&);
}
#endif