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

Side by Side Diff: Source/core/html/HTMLOptionElement.cpp

Issue 19510005: [oilpan] Completely move HTMLFormControlElement's hierarchy to the managed heap Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Created 7 years, 5 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/HTMLOptionElement.h ('k') | Source/core/html/HTMLOptionsCollection.cpp » ('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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 5 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
6 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
7 * Copyright (C) 2010 Google Inc. All rights reserved. 7 * Copyright (C) 2010 Google Inc. All rights reserved.
8 * Copyright (C) 2011 Motorola Mobility, Inc. All rights reserved. 8 * Copyright (C) 2011 Motorola Mobility, Inc. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return document->displayStringModifiedByEncoding(text).stripWhiteSpace(isHTM LSpace).simplifyWhiteSpace(isHTMLSpace); 138 return document->displayStringModifiedByEncoding(text).stripWhiteSpace(isHTM LSpace).simplifyWhiteSpace(isHTMLSpace);
139 } 139 }
140 140
141 void HTMLOptionElement::setText(const String &text, ExceptionCode& ec) 141 void HTMLOptionElement::setText(const String &text, ExceptionCode& ec)
142 { 142 {
143 RefPtr<Node> protectFromMutationEvents(this); 143 RefPtr<Node> protectFromMutationEvents(this);
144 144
145 // Changing the text causes a recalc of a select's items, which will reset t he selected 145 // Changing the text causes a recalc of a select's items, which will reset t he selected
146 // index to the first item if the select is single selection with a menu lis t. We attempt to 146 // index to the first item if the select is single selection with a menu lis t. We attempt to
147 // preserve the selected item. 147 // preserve the selected item.
148 RefPtr<HTMLSelectElement> select = ownerSelectElement(); 148 Handle<HTMLSelectElement> select = ownerSelectElement();
149 bool selectIsMenuList = select && select->usesMenuList(); 149 bool selectIsMenuList = select && select->usesMenuList();
150 int oldSelectedIndex = selectIsMenuList ? select->selectedIndex() : -1; 150 int oldSelectedIndex = selectIsMenuList ? select->selectedIndex() : -1;
151 151
152 // Handle the common special case where there's exactly 1 child node, and it 's a text node. 152 // Handle the common special case where there's exactly 1 child node, and it 's a text node.
153 Node* child = firstChild(); 153 Node* child = firstChild();
154 if (child && child->isTextNode() && !child->nextSibling()) 154 if (child && child->isTextNode() && !child->nextSibling())
155 toText(child)->setData(text, ec); 155 toText(child)->setData(text, ec);
156 else { 156 else {
157 removeChildren(); 157 removeChildren();
158 appendChild(Text::create(document(), text), ec); 158 appendChild(Text::create(document(), text), ec);
159 } 159 }
160 160
161 if (selectIsMenuList && select->selectedIndex() != oldSelectedIndex) 161 if (selectIsMenuList && select->selectedIndex() != oldSelectedIndex)
162 select->setSelectedIndex(oldSelectedIndex); 162 select->setSelectedIndex(oldSelectedIndex);
163 } 163 }
164 164
165 void HTMLOptionElement::accessKeyAction(bool) 165 void HTMLOptionElement::accessKeyAction(bool)
166 { 166 {
167 HTMLSelectElement* select = ownerSelectElement(); 167 Handle<HTMLSelectElement> select = ownerSelectElement();
168 if (select) 168 if (select)
169 select->accessKeySetSelectedIndex(index()); 169 select->accessKeySetSelectedIndex(index());
170 } 170 }
171 171
172 int HTMLOptionElement::index() const 172 int HTMLOptionElement::index() const
173 { 173 {
174 // It would be faster to cache the index, but harder to get it right in all cases. 174 // It would be faster to cache the index, but harder to get it right in all cases.
175 175
176 HTMLSelectElement* selectElement = ownerSelectElement(); 176 Handle<HTMLSelectElement> selectElement = ownerSelectElement();
177 if (!selectElement) 177 if (!selectElement)
178 return 0; 178 return 0;
179 179
180 int optionIndex = 0; 180 int optionIndex = 0;
181 181
182 const Vector<HTMLElement*>& items = selectElement->listItems(); 182 const Vector<HTMLElement*>& items = selectElement->listItems();
183 size_t length = items.size(); 183 size_t length = items.size();
184 for (size_t i = 0; i < length; ++i) { 184 for (size_t i = 0; i < length; ++i) {
185 if (!items[i]->hasTagName(optionTag)) 185 if (!items[i]->hasTagName(optionTag))
186 continue; 186 continue;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 return collectOptionInnerText().stripWhiteSpace(isHTMLSpace).simplifyWhiteSp ace(isHTMLSpace); 228 return collectOptionInnerText().stripWhiteSpace(isHTMLSpace).simplifyWhiteSp ace(isHTMLSpace);
229 } 229 }
230 230
231 void HTMLOptionElement::setValue(const String& value) 231 void HTMLOptionElement::setValue(const String& value)
232 { 232 {
233 setAttribute(valueAttr, value); 233 setAttribute(valueAttr, value);
234 } 234 }
235 235
236 bool HTMLOptionElement::selected() 236 bool HTMLOptionElement::selected()
237 { 237 {
238 if (HTMLSelectElement* select = ownerSelectElement()) 238 if (Handle<HTMLSelectElement> select = ownerSelectElement())
239 select->updateListItemSelectedStates(); 239 select->updateListItemSelectedStates();
240 return m_isSelected; 240 return m_isSelected;
241 } 241 }
242 242
243 void HTMLOptionElement::setSelected(bool selected) 243 void HTMLOptionElement::setSelected(bool selected)
244 { 244 {
245 if (m_isSelected == selected) 245 if (m_isSelected == selected)
246 return; 246 return;
247 247
248 setSelectedState(selected); 248 setSelectedState(selected);
249 249
250 if (HTMLSelectElement* select = ownerSelectElement()) 250 if (Handle<HTMLSelectElement> select = ownerSelectElement())
251 select->optionSelectionStateChanged(this, selected); 251 select->optionSelectionStateChanged(this, selected);
252 } 252 }
253 253
254 void HTMLOptionElement::setSelectedState(bool selected) 254 void HTMLOptionElement::setSelectedState(bool selected)
255 { 255 {
256 if (m_isSelected == selected) 256 if (m_isSelected == selected)
257 return; 257 return;
258 258
259 m_isSelected = selected; 259 m_isSelected = selected;
260 didAffectSelector(AffectedSelectorChecked); 260 didAffectSelector(AffectedSelectorChecked);
261 261
262 if (HTMLSelectElement* select = ownerSelectElement()) 262 if (Handle<HTMLSelectElement> select = ownerSelectElement())
263 select->invalidateSelectedItems(); 263 select->invalidateSelectedItems();
264 } 264 }
265 265
266 void HTMLOptionElement::childrenChanged(bool changedByParser, Node* beforeChange , Node* afterChange, int childCountDelta) 266 void HTMLOptionElement::childrenChanged(bool changedByParser, Node* beforeChange , Node* afterChange, int childCountDelta)
267 { 267 {
268 #if ENABLE(DATALIST_ELEMENT) 268 #if ENABLE(DATALIST_ELEMENT)
269 if (HTMLDataListElement* dataList = ownerDataListElement()) 269 if (HTMLDataListElement* dataList = ownerDataListElement())
270 dataList->optionElementChildrenChanged(); 270 dataList->optionElementChildrenChanged();
271 else 271 else
272 #endif 272 #endif
273 if (HTMLSelectElement* select = ownerSelectElement()) 273 if (Handle<HTMLSelectElement> select = ownerSelectElement())
274 select->optionElementChildrenChanged(); 274 select->optionElementChildrenChanged();
275 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, chi ldCountDelta); 275 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, chi ldCountDelta);
276 } 276 }
277 277
278 #if ENABLE(DATALIST_ELEMENT) 278 #if ENABLE(DATALIST_ELEMENT)
279 HTMLDataListElement* HTMLOptionElement::ownerDataListElement() const 279 HTMLDataListElement* HTMLOptionElement::ownerDataListElement() const
280 { 280 {
281 for (ContainerNode* parent = parentNode(); parent ; parent = parent->parentN ode()) { 281 for (ContainerNode* parent = parentNode(); parent ; parent = parent->parentN ode()) {
282 if (parent->hasTagName(datalistTag)) 282 if (parent->hasTagName(datalistTag))
283 return static_cast<HTMLDataListElement*>(parent); 283 return static_cast<HTMLDataListElement*>(parent);
284 } 284 }
285 return 0; 285 return 0;
286 } 286 }
287 #endif 287 #endif
288 288
289 HTMLSelectElement* HTMLOptionElement::ownerSelectElement() const 289 Result<HTMLSelectElement> HTMLOptionElement::ownerSelectElement() const
290 { 290 {
291 ContainerNode* select = parentNode(); 291 ContainerNode* select = parentNode();
292 while (select && !select->hasTagName(selectTag)) 292 while (select && !select->hasTagName(selectTag))
293 select = select->parentNode(); 293 select = select->parentNode();
294 294
295 if (!select) 295 if (!select)
296 return 0; 296 return nullptr;
297 297
298 return toHTMLSelectElement(select); 298 return toHTMLSelectElement(select);
299 } 299 }
300 300
301 String HTMLOptionElement::label() const 301 String HTMLOptionElement::label() const
302 { 302 {
303 const AtomicString& label = fastGetAttribute(labelAttr); 303 const AtomicString& label = fastGetAttribute(labelAttr);
304 if (!label.isNull()) 304 if (!label.isNull())
305 return label; 305 return label;
306 return collectOptionInnerText().stripWhiteSpace(isHTMLSpace).simplifyWhiteSp ace(isHTMLSpace); 306 return collectOptionInnerText().stripWhiteSpace(isHTMLSpace).simplifyWhiteSp ace(isHTMLSpace);
(...skipping 19 matching lines...) Expand all
326 // styleForRenderer is called whenever a new style should be associated 326 // styleForRenderer is called whenever a new style should be associated
327 // with an Element so now is a good time to update our cached style. 327 // with an Element so now is a good time to update our cached style.
328 updateNonRenderStyle(); 328 updateNonRenderStyle();
329 return m_style; 329 return m_style;
330 } 330 }
331 331
332 void HTMLOptionElement::didRecalcStyle(StyleChange) 332 void HTMLOptionElement::didRecalcStyle(StyleChange)
333 { 333 {
334 // FIXME: This is nasty, we ask our owner select to repaint even if the new 334 // FIXME: This is nasty, we ask our owner select to repaint even if the new
335 // style is exactly the same. 335 // style is exactly the same.
336 if (HTMLSelectElement* select = ownerSelectElement()) { 336 if (Handle<HTMLSelectElement> select = ownerSelectElement()) {
337 if (RenderObject* renderer = select->renderer()) 337 if (RenderObject* renderer = select->renderer())
338 renderer->repaint(); 338 renderer->repaint();
339 } 339 }
340 } 340 }
341 341
342 String HTMLOptionElement::textIndentedToRespectGroupLabel() const 342 String HTMLOptionElement::textIndentedToRespectGroupLabel() const
343 { 343 {
344 ContainerNode* parent = parentNode(); 344 ContainerNode* parent = parentNode();
345 if (parent && parent->hasTagName(optgroupTag)) 345 if (parent && parent->hasTagName(optgroupTag))
346 return " " + text(); 346 return " " + text();
347 return text(); 347 return text();
348 } 348 }
349 349
350 bool HTMLOptionElement::isDisabledFormControl() const 350 bool HTMLOptionElement::isDisabledFormControl() const
351 { 351 {
352 if (ownElementDisabled()) 352 if (ownElementDisabled())
353 return true; 353 return true;
354 354
355 if (!parentNode() || !parentNode()->isHTMLElement()) 355 if (!parentNode() || !parentNode()->isHTMLElement())
356 return false; 356 return false;
357 357
358 HTMLElement* parentElement = static_cast<HTMLElement*>(parentNode()); 358 HTMLElement* parentElement = static_cast<HTMLElement*>(parentNode());
359 return parentElement->hasTagName(optgroupTag) && parentElement->isDisabledFo rmControl(); 359 return parentElement->hasTagName(optgroupTag) && parentElement->isDisabledFo rmControl();
360 } 360 }
361 361
362 Node::InsertionNotificationRequest HTMLOptionElement::insertedInto(ContainerNode * insertionPoint) 362 Node::InsertionNotificationRequest HTMLOptionElement::insertedInto(ContainerNode * insertionPoint)
363 { 363 {
364 if (HTMLSelectElement* select = ownerSelectElement()) { 364 if (Handle<HTMLSelectElement> select = ownerSelectElement()) {
365 select->setRecalcListItems(); 365 select->setRecalcListItems();
366 // Do not call selected() since calling updateListItemSelectedStates() 366 // Do not call selected() since calling updateListItemSelectedStates()
367 // at this time won't do the right thing. (Why, exactly?) 367 // at this time won't do the right thing. (Why, exactly?)
368 // FIXME: Might be better to call this unconditionally, always passing m _isSelected, 368 // FIXME: Might be better to call this unconditionally, always passing m _isSelected,
369 // rather than only calling it if we are selected. 369 // rather than only calling it if we are selected.
370 if (m_isSelected) 370 if (m_isSelected)
371 select->optionSelectionStateChanged(this, true); 371 select->optionSelectionStateChanged(this, true);
372 select->scrollToSelection(); 372 select->scrollToSelection();
373 } 373 }
374 374
(...skipping 25 matching lines...) Expand all
400 400
401 const HTMLOptionElement* toHTMLOptionElement(const Node* node) 401 const HTMLOptionElement* toHTMLOptionElement(const Node* node)
402 { 402 {
403 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(optionTag)); 403 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(optionTag));
404 return static_cast<const HTMLOptionElement*>(node); 404 return static_cast<const HTMLOptionElement*>(node);
405 } 405 }
406 406
407 #endif 407 #endif
408 408
409 } // namespace 409 } // namespace
OLDNEW
« no previous file with comments | « Source/core/html/HTMLOptionElement.h ('k') | Source/core/html/HTMLOptionsCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698