OLD | NEW |
1 /* | 1 /* |
2 * This file is part of the select element renderer in WebCore. | 2 * This file is part of the select element renderer in WebCore. |
3 * | 3 * |
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
5 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 5 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
6 * 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 6 * 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 m_innerBlock = nullptr; | 148 m_innerBlock = nullptr; |
149 } else | 149 } else |
150 m_innerBlock->removeChild(oldChild); | 150 m_innerBlock->removeChild(oldChild); |
151 } | 151 } |
152 | 152 |
153 void RenderMenuList::styleDidChange(StyleDifference diff, const LayoutStyle* old
Style) | 153 void RenderMenuList::styleDidChange(StyleDifference diff, const LayoutStyle* old
Style) |
154 { | 154 { |
155 RenderBlock::styleDidChange(diff, oldStyle); | 155 RenderBlock::styleDidChange(diff, oldStyle); |
156 | 156 |
157 if (m_buttonText) | 157 if (m_buttonText) |
158 m_buttonText->setStyle(style()); | 158 m_buttonText->setStyle(mutableStyle()); |
159 if (m_innerBlock) // RenderBlock handled updating the anonymous block's styl
e. | 159 if (m_innerBlock) // RenderBlock handled updating the anonymous block's styl
e. |
160 adjustInnerStyle(); | 160 adjustInnerStyle(); |
161 | 161 |
162 bool fontChanged = !oldStyle || oldStyle->font() != style()->font(); | 162 bool fontChanged = !oldStyle || oldStyle->font() != style()->font(); |
163 if (fontChanged) | 163 if (fontChanged) |
164 updateOptionsWidth(); | 164 updateOptionsWidth(); |
165 } | 165 } |
166 | 166 |
167 void RenderMenuList::updateOptionsWidth() | 167 void RenderMenuList::updateOptionsWidth() |
168 { | 168 { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 firstSelectedIndex = i; | 237 firstSelectedIndex = i; |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 if (selectedCount == 1) { | 241 if (selectedCount == 1) { |
242 ASSERT(0 <= firstSelectedIndex); | 242 ASSERT(0 <= firstSelectedIndex); |
243 ASSERT(firstSelectedIndex < size); | 243 ASSERT(firstSelectedIndex < size); |
244 HTMLOptionElement* selectedOptionElement = toHTMLOptionElement(listI
tems[firstSelectedIndex]); | 244 HTMLOptionElement* selectedOptionElement = toHTMLOptionElement(listI
tems[firstSelectedIndex]); |
245 ASSERT(selectedOptionElement->selected()); | 245 ASSERT(selectedOptionElement->selected()); |
246 text = selectedOptionElement->textIndentedToRespectGroupLabel(); | 246 text = selectedOptionElement->textIndentedToRespectGroupLabel(); |
247 m_optionStyle = selectedOptionElement->layoutStyle(); | 247 m_optionStyle = selectedOptionElement->mutableLayoutStyle(); |
248 } else { | 248 } else { |
249 Locale& locale = select->locale(); | 249 Locale& locale = select->locale(); |
250 String localizedNumberString = locale.convertToLocalizedNumber(Strin
g::number(selectedCount)); | 250 String localizedNumberString = locale.convertToLocalizedNumber(Strin
g::number(selectedCount)); |
251 text = locale.queryString(WebLocalizedString::SelectMenuListText, lo
calizedNumberString); | 251 text = locale.queryString(WebLocalizedString::SelectMenuListText, lo
calizedNumberString); |
252 ASSERT(!m_optionStyle); | 252 ASSERT(!m_optionStyle); |
253 } | 253 } |
254 } else { | 254 } else { |
255 const int i = select->optionToListIndex(optionIndex); | 255 const int i = select->optionToListIndex(optionIndex); |
256 if (i >= 0 && i < size) { | 256 if (i >= 0 && i < size) { |
257 Element* element = listItems[i]; | 257 Element* element = listItems[i]; |
258 if (isHTMLOptionElement(*element)) { | 258 if (isHTMLOptionElement(*element)) { |
259 text = toHTMLOptionElement(element)->textIndentedToRespectGroupL
abel(); | 259 text = toHTMLOptionElement(element)->textIndentedToRespectGroupL
abel(); |
260 m_optionStyle = element->layoutStyle(); | 260 m_optionStyle = element->mutableLayoutStyle(); |
261 } | 261 } |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 setText(text.stripWhiteSpace()); | 265 setText(text.stripWhiteSpace()); |
266 | 266 |
267 didUpdateActiveOption(optionIndex); | 267 didUpdateActiveOption(optionIndex); |
268 } | 268 } |
269 | 269 |
270 void RenderMenuList::setText(const String& s) | 270 void RenderMenuList::setText(const String& s) |
271 { | 271 { |
272 if (s.isEmpty()) { | 272 if (s.isEmpty()) { |
273 if (!m_buttonText || !m_buttonText->isBR()) { | 273 if (!m_buttonText || !m_buttonText->isBR()) { |
274 // FIXME: We should not modify the structure of the render tree | 274 // FIXME: We should not modify the structure of the render tree |
275 // during layout. crbug.com/370462 | 275 // during layout. crbug.com/370462 |
276 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; | 276 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; |
277 if (m_buttonText) | 277 if (m_buttonText) |
278 m_buttonText->destroy(); | 278 m_buttonText->destroy(); |
279 m_buttonText = new LayoutBR(&document()); | 279 m_buttonText = new LayoutBR(&document()); |
280 m_buttonText->setStyle(style()); | 280 m_buttonText->setStyle(mutableStyle()); |
281 addChild(m_buttonText); | 281 addChild(m_buttonText); |
282 } | 282 } |
283 } else { | 283 } else { |
284 if (m_buttonText && !m_buttonText->isBR()) | 284 if (m_buttonText && !m_buttonText->isBR()) |
285 m_buttonText->setText(s.impl(), true); | 285 m_buttonText->setText(s.impl(), true); |
286 else { | 286 else { |
287 // FIXME: We should not modify the structure of the render tree | 287 // FIXME: We should not modify the structure of the render tree |
288 // during layout. crbug.com/370462 | 288 // during layout. crbug.com/370462 |
289 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; | 289 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; |
290 if (m_buttonText) | 290 if (m_buttonText) |
291 m_buttonText->destroy(); | 291 m_buttonText->destroy(); |
292 m_buttonText = new RenderText(&document(), s.impl()); | 292 m_buttonText = new RenderText(&document(), s.impl()); |
293 m_buttonText->setStyle(style()); | 293 m_buttonText->setStyle(mutableStyle()); |
294 // We need to set the text explicitly though it was specified in the | 294 // We need to set the text explicitly though it was specified in the |
295 // constructor because RenderText doesn't refer to the text | 295 // constructor because RenderText doesn't refer to the text |
296 // specified in the constructor in a case of re-transforming. | 296 // specified in the constructor in a case of re-transforming. |
297 m_buttonText->setText(s.impl(), true); | 297 m_buttonText->setText(s.impl(), true); |
298 addChild(m_buttonText); | 298 addChild(m_buttonText); |
299 } | 299 } |
300 adjustInnerStyle(); | 300 adjustInnerStyle(); |
301 } | 301 } |
302 } | 302 } |
303 | 303 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 return selectElement()->document().view()->contentsToRootView(pixelSnappedIn
tRect(absoluteBoundingBoxRect())); | 383 return selectElement()->document().view()->contentsToRootView(pixelSnappedIn
tRect(absoluteBoundingBoxRect())); |
384 } | 384 } |
385 | 385 |
386 Element& RenderMenuList::ownerElement() const | 386 Element& RenderMenuList::ownerElement() const |
387 { | 387 { |
388 return *selectElement(); | 388 return *selectElement(); |
389 } | 389 } |
390 | 390 |
391 const LayoutStyle* RenderMenuList::layoutStyleForItem(Element& element) const | 391 const LayoutStyle* RenderMenuList::layoutStyleForItem(Element& element) const |
392 { | 392 { |
393 return element.layoutStyle() ? element.layoutStyle() : element.computedStyle
(); | 393 return element.layoutStyle() ? element.mutableLayoutStyle() : element.comput
edStyle(); |
394 } | 394 } |
395 | 395 |
396 void RenderMenuList::didSetSelectedIndex(int listIndex) | 396 void RenderMenuList::didSetSelectedIndex(int listIndex) |
397 { | 397 { |
398 didUpdateActiveOption(selectElement()->listToOptionIndex(listIndex)); | 398 didUpdateActiveOption(selectElement()->listToOptionIndex(listIndex)); |
399 } | 399 } |
400 | 400 |
401 void RenderMenuList::didUpdateActiveOption(int optionIndex) | 401 void RenderMenuList::didUpdateActiveOption(int optionIndex) |
402 { | 402 { |
403 if (!document().existingAXObjectCache()) | 403 if (!document().existingAXObjectCache()) |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 HTMLElement* element = listItems[listIndex]; | 591 HTMLElement* element = listItems[listIndex]; |
592 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select
ed(); | 592 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select
ed(); |
593 } | 593 } |
594 | 594 |
595 void RenderMenuList::setTextFromItem(unsigned listIndex) | 595 void RenderMenuList::setTextFromItem(unsigned listIndex) |
596 { | 596 { |
597 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); | 597 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); |
598 } | 598 } |
599 | 599 |
600 } // namespace blink | 600 } // namespace blink |
OLD | NEW |