~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/chromium/src/TextFieldDecoratorImpl.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Google Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are
 
6
 * met:
 
7
 *
 
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
 
13
 * distribution.
 
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.
 
17
 *
 
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.
 
29
 */
 
30
 
 
31
#include "config.h"
 
32
#include "TextFieldDecoratorImpl.h"
 
33
 
 
34
#include "CachedImage.h"
 
35
#include "HTMLInputElement.h"
 
36
#include "Image.h"
 
37
#include "WebInputElement.h"
 
38
#include "WebTextFieldDecoratorClient.h"
 
39
 
 
40
namespace WebKit {
 
41
 
 
42
using namespace WebCore;
 
43
 
 
44
inline TextFieldDecoratorImpl::TextFieldDecoratorImpl(WebTextFieldDecoratorClient* client)
 
45
    : m_client(client)
 
46
{
 
47
    ASSERT(client);
 
48
}
 
49
 
 
50
PassOwnPtr<TextFieldDecoratorImpl> TextFieldDecoratorImpl::create(WebTextFieldDecoratorClient* client)
 
51
{
 
52
    return adoptPtr(new TextFieldDecoratorImpl(client));
 
53
}
 
54
 
 
55
TextFieldDecoratorImpl::~TextFieldDecoratorImpl()
 
56
{
 
57
}
 
58
 
 
59
WebTextFieldDecoratorClient* TextFieldDecoratorImpl::decoratorClient()
 
60
{
 
61
    return m_client;
 
62
}
 
63
 
 
64
bool TextFieldDecoratorImpl::willAddDecorationTo(HTMLInputElement* input)
 
65
{
 
66
    ASSERT(input);
 
67
    return m_client->shouldAddDecorationTo(WebInputElement(input));
 
68
}
 
69
 
 
70
bool TextFieldDecoratorImpl::visibleByDefault()
 
71
{
 
72
    return m_client->visibleByDefault();
 
73
}
 
74
 
 
75
CachedImage* TextFieldDecoratorImpl::imageForNormalState()
 
76
{
 
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.
 
83
    }
 
84
    return m_cachedImageForNormalState.get();
 
85
}
 
86
 
 
87
CachedImage* TextFieldDecoratorImpl::imageForDisabledState()
 
88
{
 
89
    if (!m_cachedImageForDisabledState) {
 
90
        WebCString imageName = m_client->imageNameForDisabledState();
 
91
        if (imageName.isEmpty())
 
92
            m_cachedImageForDisabledState = imageForNormalState();
 
93
        else {
 
94
            RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
 
95
            m_cachedImageForDisabledState = new CachedImage(image.get());
 
96
        }
 
97
    }
 
98
    return m_cachedImageForDisabledState.get();
 
99
}
 
100
 
 
101
CachedImage* TextFieldDecoratorImpl::imageForReadonlyState()
 
102
{
 
103
    if (!m_cachedImageForReadonlyState) {
 
104
        WebCString imageName = m_client->imageNameForReadOnlyState();
 
105
        if (imageName.isEmpty())
 
106
            m_cachedImageForReadonlyState = imageForDisabledState();
 
107
        else {
 
108
            RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
 
109
            m_cachedImageForReadonlyState = new CachedImage(image.get());
 
110
        }
 
111
    }
 
112
    return m_cachedImageForReadonlyState.get();
 
113
}
 
114
 
 
115
CachedImage* TextFieldDecoratorImpl::imageForHoverState()
 
116
{
 
117
    if (!m_cachedImageForHoverState) {
 
118
        WebCString imageName = m_client->imageNameForHoverState();
 
119
        if (imageName.isEmpty())
 
120
            m_cachedImageForHoverState = imageForNormalState();
 
121
        else {
 
122
            RefPtr<Image> image = Image::loadPlatformResource(imageName.data());
 
123
            m_cachedImageForHoverState = new CachedImage(image.get());
 
124
        }
 
125
    }
 
126
    return m_cachedImageForHoverState.get();
 
127
}
 
128
 
 
129
void TextFieldDecoratorImpl::handleClick(HTMLInputElement* input)
 
130
{
 
131
    ASSERT(input);
 
132
    WebInputElement webInput(input);
 
133
    m_client->handleClick(webInput);
 
134
}
 
135
 
 
136
void TextFieldDecoratorImpl::willDetach(HTMLInputElement* input)
 
137
{
 
138
    ASSERT(input);
 
139
    WebInputElement webInput(input);
 
140
    m_client->willDetach(webInput);
 
141
}
 
142
 
 
143
}