Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: Source/core/html/forms/SearchInputType.cpp

Issue 27746003: Have InputType factories take an HTMLInputElement reference in parameter (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/forms/SearchInputType.h ('k') | Source/core/html/forms/SubmitInputType.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 28 matching lines...) Expand all
39 #include "core/html/forms/InputTypeNames.h" 39 #include "core/html/forms/InputTypeNames.h"
40 #include "core/html/shadow/ShadowElementNames.h" 40 #include "core/html/shadow/ShadowElementNames.h"
41 #include "core/html/shadow/TextControlInnerElements.h" 41 #include "core/html/shadow/TextControlInnerElements.h"
42 #include "core/rendering/RenderSearchField.h" 42 #include "core/rendering/RenderSearchField.h"
43 #include "wtf/PassOwnPtr.h" 43 #include "wtf/PassOwnPtr.h"
44 44
45 namespace WebCore { 45 namespace WebCore {
46 46
47 using namespace HTMLNames; 47 using namespace HTMLNames;
48 48
49 inline SearchInputType::SearchInputType(HTMLInputElement* element) 49 inline SearchInputType::SearchInputType(HTMLInputElement& element)
50 : BaseTextInputType(element) 50 : BaseTextInputType(element)
51 , m_searchEventTimer(this, &SearchInputType::searchEventTimerFired) 51 , m_searchEventTimer(this, &SearchInputType::searchEventTimerFired)
52 { 52 {
53 } 53 }
54 54
55 PassRefPtr<InputType> SearchInputType::create(HTMLInputElement* element) 55 PassRefPtr<InputType> SearchInputType::create(HTMLInputElement& element)
56 { 56 {
57 return adoptRef(new SearchInputType(element)); 57 return adoptRef(new SearchInputType(element));
58 } 58 }
59 59
60 void SearchInputType::countUsage() 60 void SearchInputType::countUsage()
61 { 61 {
62 observeFeatureIfVisible(UseCounter::InputTypeSearch); 62 observeFeatureIfVisible(UseCounter::InputTypeSearch);
63 } 63 }
64 64
65 RenderObject* SearchInputType::createRenderer(RenderStyle*) const 65 RenderObject* SearchInputType::createRenderer(RenderStyle*) const
66 { 66 {
67 return new RenderSearchField(element()); 67 return new RenderSearchField(&element());
68 } 68 }
69 69
70 const AtomicString& SearchInputType::formControlType() const 70 const AtomicString& SearchInputType::formControlType() const
71 { 71 {
72 return InputTypeNames::search(); 72 return InputTypeNames::search();
73 } 73 }
74 74
75 bool SearchInputType::shouldRespectSpeechAttribute() 75 bool SearchInputType::shouldRespectSpeechAttribute()
76 { 76 {
77 return true; 77 return true;
78 } 78 }
79 79
80 bool SearchInputType::isSearchField() const 80 bool SearchInputType::isSearchField() const
81 { 81 {
82 return true; 82 return true;
83 } 83 }
84 84
85 bool SearchInputType::needsContainer() const 85 bool SearchInputType::needsContainer() const
86 { 86 {
87 return true; 87 return true;
88 } 88 }
89 89
90 void SearchInputType::createShadowSubtree() 90 void SearchInputType::createShadowSubtree()
91 { 91 {
92 TextFieldInputType::createShadowSubtree(); 92 TextFieldInputType::createShadowSubtree();
93 Element* container = containerElement(); 93 Element* container = containerElement();
94 Element* viewPort = element()->userAgentShadowRoot()->getElementById(ShadowE lementNames::editingViewPort()); 94 Element* viewPort = element().userAgentShadowRoot()->getElementById(ShadowEl ementNames::editingViewPort());
95 ASSERT(container); 95 ASSERT(container);
96 ASSERT(viewPort); 96 ASSERT(viewPort);
97 97
98 container->insertBefore(SearchFieldDecorationElement::create(element()->docu ment()), viewPort); 98 container->insertBefore(SearchFieldDecorationElement::create(element().docum ent()), viewPort);
99 container->insertBefore(SearchFieldCancelButtonElement::create(element()->do cument()), viewPort->nextSibling()); 99 container->insertBefore(SearchFieldCancelButtonElement::create(element().doc ument()), viewPort->nextSibling());
100 } 100 }
101 101
102 void SearchInputType::handleKeydownEvent(KeyboardEvent* event) 102 void SearchInputType::handleKeydownEvent(KeyboardEvent* event)
103 { 103 {
104 if (element()->isDisabledOrReadOnly()) { 104 if (element().isDisabledOrReadOnly()) {
105 TextFieldInputType::handleKeydownEvent(event); 105 TextFieldInputType::handleKeydownEvent(event);
106 return; 106 return;
107 } 107 }
108 108
109 const String& key = event->keyIdentifier(); 109 const String& key = event->keyIdentifier();
110 if (key == "U+001B") { 110 if (key == "U+001B") {
111 RefPtr<HTMLInputElement> input = element(); 111 RefPtr<HTMLInputElement> input(element());
112 input->setValueForUser(""); 112 input->setValueForUser("");
113 input->onSearch(); 113 input->onSearch();
114 event->setDefaultHandled(); 114 event->setDefaultHandled();
115 return; 115 return;
116 } 116 }
117 TextFieldInputType::handleKeydownEvent(event); 117 TextFieldInputType::handleKeydownEvent(event);
118 } 118 }
119 119
120 void SearchInputType::startSearchEventTimer() 120 void SearchInputType::startSearchEventTimer()
121 { 121 {
122 ASSERT(element()->renderer()); 122 ASSERT(element().renderer());
123 unsigned length = element()->innerTextValue().length(); 123 unsigned length = element().innerTextValue().length();
124 124
125 if (!length) { 125 if (!length) {
126 stopSearchEventTimer(); 126 stopSearchEventTimer();
127 element()->onSearch(); 127 element().onSearch();
128 return; 128 return;
129 } 129 }
130 130
131 // After typing the first key, we wait 0.5 seconds. 131 // After typing the first key, we wait 0.5 seconds.
132 // After the second key, 0.4 seconds, then 0.3, then 0.2 from then on. 132 // After the second key, 0.4 seconds, then 0.3, then 0.2 from then on.
133 m_searchEventTimer.startOneShot(max(0.2, 0.6 - 0.1 * length)); 133 m_searchEventTimer.startOneShot(max(0.2, 0.6 - 0.1 * length));
134 } 134 }
135 135
136 void SearchInputType::stopSearchEventTimer() 136 void SearchInputType::stopSearchEventTimer()
137 { 137 {
138 m_searchEventTimer.stop(); 138 m_searchEventTimer.stop();
139 } 139 }
140 140
141 void SearchInputType::searchEventTimerFired(Timer<SearchInputType>*) 141 void SearchInputType::searchEventTimerFired(Timer<SearchInputType>*)
142 { 142 {
143 element()->onSearch(); 143 element().onSearch();
144 } 144 }
145 145
146 bool SearchInputType::searchEventsShouldBeDispatched() const 146 bool SearchInputType::searchEventsShouldBeDispatched() const
147 { 147 {
148 return element()->hasAttribute(incrementalAttr); 148 return element().hasAttribute(incrementalAttr);
149 } 149 }
150 150
151 void SearchInputType::didSetValueByUserEdit(ValueChangeState state) 151 void SearchInputType::didSetValueByUserEdit(ValueChangeState state)
152 { 152 {
153 updateCancelButtonVisibility(); 153 updateCancelButtonVisibility();
154 154
155 // If the incremental attribute is set, then dispatch the search event 155 // If the incremental attribute is set, then dispatch the search event
156 if (searchEventsShouldBeDispatched()) 156 if (searchEventsShouldBeDispatched())
157 startSearchEventTimer(); 157 startSearchEventTimer();
158 158
159 TextFieldInputType::didSetValueByUserEdit(state); 159 TextFieldInputType::didSetValueByUserEdit(state);
160 } 160 }
161 161
162 void SearchInputType::updateInnerTextValue() 162 void SearchInputType::updateInnerTextValue()
163 { 163 {
164 BaseTextInputType::updateInnerTextValue(); 164 BaseTextInputType::updateInnerTextValue();
165 updateCancelButtonVisibility(); 165 updateCancelButtonVisibility();
166 } 166 }
167 167
168 void SearchInputType::updateCancelButtonVisibility() 168 void SearchInputType::updateCancelButtonVisibility()
169 { 169 {
170 Element* button = element()->userAgentShadowRoot()->getElementById(ShadowEle mentNames::clearButton()); 170 Element* button = element().userAgentShadowRoot()->getElementById(ShadowElem entNames::clearButton());
171 if (!button) 171 if (!button)
172 return; 172 return;
173 if (element()->value().isEmpty()) 173 if (element().value().isEmpty())
174 button->setInlineStyleProperty(CSSPropertyVisibility, CSSValueHidden); 174 button->setInlineStyleProperty(CSSPropertyVisibility, CSSValueHidden);
175 else 175 else
176 button->removeInlineStyleProperty(CSSPropertyVisibility); 176 button->removeInlineStyleProperty(CSSPropertyVisibility);
177 } 177 }
178 178
179 bool SearchInputType::supportsInputModeAttribute() const 179 bool SearchInputType::supportsInputModeAttribute() const
180 { 180 {
181 return true; 181 return true;
182 } 182 }
183 183
184 } // namespace WebCore 184 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/forms/SearchInputType.h ('k') | Source/core/html/forms/SubmitInputType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698