~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/WebCore/dom/CheckedRadioButtons.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Library General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public License
 
15
 * along with this library; see the file COPYING.LIB.  If not, write to
 
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
 * Boston, MA 02110-1301, USA.
 
18
 *
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
#include "CheckedRadioButtons.h"
 
23
 
 
24
#include "HTMLInputElement.h"
 
25
 
 
26
namespace WebCore {
 
27
 
 
28
void CheckedRadioButtons::addButton(HTMLFormControlElement* element)
 
29
{
 
30
    // We only want to add radio buttons.
 
31
    if (!element->isRadioButton())
 
32
        return;
 
33
 
 
34
    // Without a name, there is no group.
 
35
    if (element->name().isEmpty())
 
36
        return;
 
37
 
 
38
    HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(element);
 
39
 
 
40
    // We only track checked buttons.
 
41
    if (!inputElement->checked())
 
42
        return;
 
43
 
 
44
    if (!m_nameToCheckedRadioButtonMap)
 
45
        m_nameToCheckedRadioButtonMap.set(new NameToInputMap);
 
46
 
 
47
    pair<NameToInputMap::iterator, bool> result = m_nameToCheckedRadioButtonMap->add(element->name().impl(), inputElement);
 
48
    if (result.second)
 
49
        return;
 
50
    
 
51
    HTMLInputElement* oldCheckedButton = result.first->second;
 
52
    if (oldCheckedButton == inputElement)
 
53
        return;
 
54
 
 
55
    result.first->second = inputElement;
 
56
    oldCheckedButton->setChecked(false);
 
57
}
 
58
 
 
59
HTMLInputElement* CheckedRadioButtons::checkedButtonForGroup(const AtomicString& name) const
 
60
{
 
61
    if (!m_nameToCheckedRadioButtonMap)
 
62
        return 0;
 
63
    
 
64
    return m_nameToCheckedRadioButtonMap->get(name.impl());
 
65
}
 
66
 
 
67
void CheckedRadioButtons::removeButton(HTMLFormControlElement* element)
 
68
{
 
69
    if (element->name().isEmpty() || !m_nameToCheckedRadioButtonMap)
 
70
        return;
 
71
    
 
72
    NameToInputMap::iterator it = m_nameToCheckedRadioButtonMap->find(element->name().impl());
 
73
    if (it == m_nameToCheckedRadioButtonMap->end() || it->second != element)
 
74
        return;
 
75
    
 
76
    InputElement* inputElement = toInputElement(element);
 
77
    ASSERT_UNUSED(inputElement, inputElement);
 
78
    ASSERT(inputElement->isChecked());
 
79
    ASSERT(element->isRadioButton());
 
80
 
 
81
    m_nameToCheckedRadioButtonMap->remove(it);
 
82
    if (m_nameToCheckedRadioButtonMap->isEmpty())
 
83
        m_nameToCheckedRadioButtonMap.clear();
 
84
}
 
85
 
 
86
} // namespace