TextFieldDecoratorImpl.cpp [plain text]
#include "config.h"
#include "TextFieldDecoratorImpl.h"
#include "CachedImage.h"
#include "HTMLInputElement.h"
#include "Image.h"
#include "WebInputElement.h"
#include "WebTextFieldDecoratorClient.h"
namespace WebKit {
using namespace WebCore;
inline TextFieldDecoratorImpl::TextFieldDecoratorImpl(WebTextFieldDecoratorClient* client)
: m_client(client)
{
ASSERT(client);
}
PassOwnPtr<TextFieldDecoratorImpl> TextFieldDecoratorImpl::create(WebTextFieldDecoratorClient* client)
{
return adoptPtr(new TextFieldDecoratorImpl(client));
}
TextFieldDecoratorImpl::~TextFieldDecoratorImpl()
{
}
bool TextFieldDecoratorImpl::willAddDecorationTo(HTMLInputElement* input)
{
ASSERT(input);
return m_client->shouldAddDecorationTo(WebInputElement(input));
}
CachedImage* TextFieldDecoratorImpl::imageForNormalState()
{
if (!m_cachedImageForNormalState) {
WebCString imageName = m_client->imageNameForNormalState();
ASSERT(!imageName.isEmpty());
RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
m_cachedImageForNormalState = new CachedImage(image.get());
}
return m_cachedImageForNormalState.get();
}
CachedImage* TextFieldDecoratorImpl::imageForDisabledState()
{
if (!m_cachedImageForDisabledState) {
WebCString imageName = m_client->imageNameForDisabledState();
if (imageName.isEmpty())
m_cachedImageForDisabledState = imageForNormalState();
else {
RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
m_cachedImageForDisabledState = new CachedImage(image.get());
}
}
return m_cachedImageForDisabledState.get();
}
CachedImage* TextFieldDecoratorImpl::imageForReadonlyState()
{
if (!m_cachedImageForReadonlyState) {
WebCString imageName = m_client->imageNameForReadOnlyState();
if (imageName.isEmpty())
m_cachedImageForDisabledState = imageForDisabledState();
else {
RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
m_cachedImageForReadonlyState = new CachedImage(image.get());
}
}
return m_cachedImageForReadonlyState.get();
}
void TextFieldDecoratorImpl::handleClick(HTMLInputElement* input)
{
ASSERT(input);
WebInputElement webInput(input);
m_client->handleClick(webInput);
}
void TextFieldDecoratorImpl::willDetach(HTMLInputElement* input)
{
ASSERT(input);
WebInputElement webInput(input);
m_client->willDetach(webInput);
}
}