2
* Copyright (C) 2012 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are
8
* * Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above
11
* copyright notice, this list of conditions and the following disclaimer
12
* in the documentation and/or other materials provided with the
14
* * Neither the name of Google Inc. nor the names of its
15
* contributors may be used to endorse or promote products derived from
16
* this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
#include "TextFieldDecoratorImpl.h"
34
#include "CachedImage.h"
35
#include "HTMLInputElement.h"
37
#include "WebInputElement.h"
38
#include "WebTextFieldDecoratorClient.h"
42
using namespace WebCore;
44
inline TextFieldDecoratorImpl::TextFieldDecoratorImpl(WebTextFieldDecoratorClient* client)
50
PassOwnPtr<TextFieldDecoratorImpl> TextFieldDecoratorImpl::create(WebTextFieldDecoratorClient* client)
52
return adoptPtr(new TextFieldDecoratorImpl(client));
55
TextFieldDecoratorImpl::~TextFieldDecoratorImpl()
59
WebTextFieldDecoratorClient* TextFieldDecoratorImpl::decoratorClient()
64
bool TextFieldDecoratorImpl::willAddDecorationTo(HTMLInputElement* input)
67
return m_client->shouldAddDecorationTo(WebInputElement(input));
70
bool TextFieldDecoratorImpl::visibleByDefault()
72
return m_client->visibleByDefault();
75
CachedImage* TextFieldDecoratorImpl::imageForNormalState()
77
if (!m_cachedImageForNormalState) {
78
WebCString imageName = m_client->imageNameForNormalState();
79
ASSERT(!imageName.isEmpty());
80
RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
81
m_cachedImageForNormalState = new CachedImage(image.get());
82
// The CachedImage owns a RefPtr to the Image.
84
return m_cachedImageForNormalState.get();
87
CachedImage* TextFieldDecoratorImpl::imageForDisabledState()
89
if (!m_cachedImageForDisabledState) {
90
WebCString imageName = m_client->imageNameForDisabledState();
91
if (imageName.isEmpty())
92
m_cachedImageForDisabledState = imageForNormalState();
94
RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
95
m_cachedImageForDisabledState = new CachedImage(image.get());
98
return m_cachedImageForDisabledState.get();
101
CachedImage* TextFieldDecoratorImpl::imageForReadonlyState()
103
if (!m_cachedImageForReadonlyState) {
104
WebCString imageName = m_client->imageNameForReadOnlyState();
105
if (imageName.isEmpty())
106
m_cachedImageForReadonlyState = imageForDisabledState();
108
RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
109
m_cachedImageForReadonlyState = new CachedImage(image.get());
112
return m_cachedImageForReadonlyState.get();
115
CachedImage* TextFieldDecoratorImpl::imageForHoverState()
117
if (!m_cachedImageForHoverState) {
118
WebCString imageName = m_client->imageNameForHoverState();
119
if (imageName.isEmpty())
120
m_cachedImageForHoverState = imageForNormalState();
122
RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
123
m_cachedImageForHoverState = new CachedImage(image.get());
126
return m_cachedImageForHoverState.get();
129
void TextFieldDecoratorImpl::handleClick(HTMLInputElement* input)
132
WebInputElement webInput(input);
133
m_client->handleClick(webInput);
136
void TextFieldDecoratorImpl::willDetach(HTMLInputElement* input)
139
WebInputElement webInput(input);
140
m_client->willDetach(webInput);