OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * Copyright (C) 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "core/html/forms/CheckboxInputType.h" | 33 #include "core/html/forms/CheckboxInputType.h" |
34 | 34 |
35 #include "core/events/KeyboardEvent.h" | 35 #include "core/events/KeyboardEvent.h" |
36 #include "core/html/HTMLInputElement.h" | 36 #include "core/html/HTMLInputElement.h" |
37 #include "core/html/forms/InputTypeNames.h" | 37 #include "core/html/forms/InputTypeNames.h" |
38 #include "platform/text/PlatformLocale.h" | 38 #include "platform/text/PlatformLocale.h" |
39 #include "wtf/PassOwnPtr.h" | 39 #include "wtf/PassOwnPtr.h" |
40 | 40 |
41 namespace WebCore { | 41 namespace WebCore { |
42 | 42 |
43 PassRefPtr<InputType> CheckboxInputType::create(HTMLInputElement* element) | 43 PassRefPtr<InputType> CheckboxInputType::create(HTMLInputElement& element) |
44 { | 44 { |
45 return adoptRef(new CheckboxInputType(element)); | 45 return adoptRef(new CheckboxInputType(element)); |
46 } | 46 } |
47 | 47 |
48 const AtomicString& CheckboxInputType::formControlType() const | 48 const AtomicString& CheckboxInputType::formControlType() const |
49 { | 49 { |
50 return InputTypeNames::checkbox(); | 50 return InputTypeNames::checkbox(); |
51 } | 51 } |
52 | 52 |
53 bool CheckboxInputType::valueMissing(const String&) const | 53 bool CheckboxInputType::valueMissing(const String&) const |
54 { | 54 { |
55 return element()->isRequired() && !element()->checked(); | 55 return element().isRequired() && !element().checked(); |
56 } | 56 } |
57 | 57 |
58 String CheckboxInputType::valueMissingText() const | 58 String CheckboxInputType::valueMissingText() const |
59 { | 59 { |
60 return locale().queryString(WebKit::WebLocalizedString::ValidationValueMissi
ngForCheckbox); | 60 return locale().queryString(WebKit::WebLocalizedString::ValidationValueMissi
ngForCheckbox); |
61 } | 61 } |
62 | 62 |
63 void CheckboxInputType::handleKeyupEvent(KeyboardEvent* event) | 63 void CheckboxInputType::handleKeyupEvent(KeyboardEvent* event) |
64 { | 64 { |
65 const String& key = event->keyIdentifier(); | 65 const String& key = event->keyIdentifier(); |
66 if (key != "U+0020") | 66 if (key != "U+0020") |
67 return; | 67 return; |
68 dispatchSimulatedClickIfActive(event); | 68 dispatchSimulatedClickIfActive(event); |
69 } | 69 } |
70 | 70 |
71 PassOwnPtr<ClickHandlingState> CheckboxInputType::willDispatchClick() | 71 PassOwnPtr<ClickHandlingState> CheckboxInputType::willDispatchClick() |
72 { | 72 { |
73 // An event handler can use preventDefault or "return false" to reverse the
checking we do here. | 73 // An event handler can use preventDefault or "return false" to reverse the
checking we do here. |
74 // The ClickHandlingState object contains what we need to undo what we did h
ere in didDispatchClick. | 74 // The ClickHandlingState object contains what we need to undo what we did h
ere in didDispatchClick. |
75 | 75 |
76 OwnPtr<ClickHandlingState> state = adoptPtr(new ClickHandlingState); | 76 OwnPtr<ClickHandlingState> state = adoptPtr(new ClickHandlingState); |
77 | 77 |
78 state->checked = element()->checked(); | 78 state->checked = element().checked(); |
79 state->indeterminate = element()->indeterminate(); | 79 state->indeterminate = element().indeterminate(); |
80 | 80 |
81 if (state->indeterminate) | 81 if (state->indeterminate) |
82 element()->setIndeterminate(false); | 82 element().setIndeterminate(false); |
83 | 83 |
84 element()->setChecked(!state->checked, DispatchChangeEvent); | 84 element().setChecked(!state->checked, DispatchChangeEvent); |
85 | 85 |
86 return state.release(); | 86 return state.release(); |
87 } | 87 } |
88 | 88 |
89 void CheckboxInputType::didDispatchClick(Event* event, const ClickHandlingState&
state) | 89 void CheckboxInputType::didDispatchClick(Event* event, const ClickHandlingState&
state) |
90 { | 90 { |
91 if (event->defaultPrevented() || event->defaultHandled()) { | 91 if (event->defaultPrevented() || event->defaultHandled()) { |
92 element()->setIndeterminate(state.indeterminate); | 92 element().setIndeterminate(state.indeterminate); |
93 element()->setChecked(state.checked); | 93 element().setChecked(state.checked); |
94 } | 94 } |
95 | 95 |
96 // The work we did in willDispatchClick was default handling. | 96 // The work we did in willDispatchClick was default handling. |
97 event->setDefaultHandled(); | 97 event->setDefaultHandled(); |
98 } | 98 } |
99 | 99 |
100 bool CheckboxInputType::isCheckbox() const | 100 bool CheckboxInputType::isCheckbox() const |
101 { | 101 { |
102 return true; | 102 return true; |
103 } | 103 } |
104 | 104 |
105 bool CheckboxInputType::supportsIndeterminateAppearance() const | 105 bool CheckboxInputType::supportsIndeterminateAppearance() const |
106 { | 106 { |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 } // namespace WebCore | 110 } // namespace WebCore |
OLD | NEW |