OLD | NEW |
1 /* | 1 /* |
2 * This file is part of the select element layoutObject in WebCore. | 2 * This file is part of the select element layoutObject 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 LayoutBlock::styleDidChange(diff, oldStyle); | 152 LayoutBlock::styleDidChange(diff, oldStyle); |
153 | 153 |
154 if (!m_innerBlock) | 154 if (!m_innerBlock) |
155 createInnerBlock(); | 155 createInnerBlock(); |
156 | 156 |
157 m_buttonText->setStyle(mutableStyle()); | 157 m_buttonText->setStyle(mutableStyle()); |
158 adjustInnerStyle(); | 158 adjustInnerStyle(); |
159 | 159 |
160 bool fontChanged = !oldStyle || oldStyle->font() != style()->font(); | 160 bool fontChanged = !oldStyle || oldStyle->font() != style()->font(); |
161 if (fontChanged) | 161 if (fontChanged) |
162 updateOptionsWidth(); | 162 m_optionsChanged = true; |
163 } | 163 } |
164 | 164 |
165 void LayoutMenuList::updateOptionsWidth() | 165 void LayoutMenuList::updateOptionsWidth() const |
166 { | 166 { |
| 167 if (!m_optionsChanged) |
| 168 return; |
| 169 |
167 float maxOptionWidth = 0; | 170 float maxOptionWidth = 0; |
168 const HeapVector<Member<HTMLElement>>& listItems = selectElement()->listItem
s(); | 171 const HeapVector<Member<HTMLElement>>& listItems = selectElement()->listItem
s(); |
169 int size = listItems.size(); | 172 int size = listItems.size(); |
170 | 173 |
171 for (int i = 0; i < size; ++i) { | 174 for (int i = 0; i < size; ++i) { |
172 HTMLElement* element = listItems[i]; | 175 HTMLElement* element = listItems[i]; |
173 if (!isHTMLOptionElement(*element)) | 176 if (!isHTMLOptionElement(*element)) |
174 continue; | 177 continue; |
175 | 178 |
176 String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLa
bel(); | 179 String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLa
bel(); |
177 applyTextTransform(style(), text, ' '); | 180 applyTextTransform(style(), text, ' '); |
178 if (LayoutTheme::theme().popupOptionSupportsTextIndent()) { | 181 if (LayoutTheme::theme().popupOptionSupportsTextIndent()) { |
179 // Add in the option's text indent. We can't calculate percentage v
alues for now. | 182 // Add in the option's text indent. We can't calculate percentage v
alues for now. |
180 float optionWidth = 0; | 183 float optionWidth = 0; |
181 if (const ComputedStyle* optionStyle = element->computedStyle()) | 184 if (const ComputedStyle* optionStyle = element->computedStyle()) |
182 optionWidth += minimumValueForLength(optionStyle->textIndent(),
LayoutUnit()); | 185 optionWidth += minimumValueForLength(optionStyle->textIndent(),
LayoutUnit()); |
183 if (!text.isEmpty()) | 186 if (!text.isEmpty()) |
184 optionWidth += computeTextWidth(text); | 187 optionWidth += computeTextWidth(text); |
185 maxOptionWidth = std::max(maxOptionWidth, optionWidth); | 188 maxOptionWidth = std::max(maxOptionWidth, optionWidth); |
186 } else if (!text.isEmpty()) { | 189 } else if (!text.isEmpty()) { |
187 maxOptionWidth = std::max(maxOptionWidth, computeTextWidth(text)); | 190 maxOptionWidth = std::max(maxOptionWidth, computeTextWidth(text)); |
188 } | 191 } |
189 } | 192 } |
190 | 193 |
191 int width = static_cast<int>(ceilf(maxOptionWidth)); | 194 m_optionsWidth = static_cast<int>(ceilf(maxOptionWidth)); |
192 if (m_optionsWidth == width) | 195 m_optionsChanged = false; |
193 return; | 196 } |
194 | 197 |
195 m_optionsWidth = width; | 198 void LayoutMenuList::setOptionsChanged(bool changed) |
196 if (parent()) | 199 { |
197 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalida
tionReason::MenuWidthChanged); | 200 m_optionsChanged = changed; |
| 201 if (changed && parent()) |
| 202 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalida
tionReason::MenuOptionsChanged); |
198 } | 203 } |
199 | 204 |
200 float LayoutMenuList::computeTextWidth(const String& text) const | 205 float LayoutMenuList::computeTextWidth(const String& text) const |
201 { | 206 { |
202 return style()->font().width(constructTextRun(style()->font(), text, styleRe
f())); | 207 return style()->font().width(constructTextRun(style()->font(), text, styleRe
f())); |
203 } | 208 } |
204 | 209 |
205 void LayoutMenuList::updateFromElement() | 210 void LayoutMenuList::updateFromElement() |
206 { | 211 { |
207 if (m_optionsChanged) { | |
208 updateOptionsWidth(); | |
209 m_optionsChanged = false; | |
210 } | |
211 | |
212 updateText(); | |
213 } | |
214 | |
215 void LayoutMenuList::updateText() | |
216 { | |
217 setTextFromOption(selectElement()->optionIndexToBeShown()); | 212 setTextFromOption(selectElement()->optionIndexToBeShown()); |
218 } | 213 } |
219 | 214 |
220 void LayoutMenuList::setTextFromOption(int optionIndex) | 215 void LayoutMenuList::setTextFromOption(int optionIndex) |
221 { | 216 { |
222 HTMLSelectElement* select = selectElement(); | 217 HTMLSelectElement* select = selectElement(); |
223 const HeapVector<Member<HTMLElement>>& listItems = select->listItems(); | 218 const HeapVector<Member<HTMLElement>>& listItems = select->listItems(); |
224 const int size = listItems.size(); | 219 const int size = listItems.size(); |
225 | 220 |
226 String text = emptyString(); | 221 String text = emptyString(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 296 |
302 LayoutRect innerBox(additionalOffset + m_innerBlock->location() | 297 LayoutRect innerBox(additionalOffset + m_innerBlock->location() |
303 + LayoutSize(m_innerBlock->paddingLeft(), m_innerBlock->paddingTop()) | 298 + LayoutSize(m_innerBlock->paddingLeft(), m_innerBlock->paddingTop()) |
304 , m_innerBlock->contentSize()); | 299 , m_innerBlock->contentSize()); |
305 | 300 |
306 return intersection(outerBox, innerBox); | 301 return intersection(outerBox, innerBox); |
307 } | 302 } |
308 | 303 |
309 void LayoutMenuList::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
LayoutUnit& maxLogicalWidth) const | 304 void LayoutMenuList::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
LayoutUnit& maxLogicalWidth) const |
310 { | 305 { |
| 306 updateOptionsWidth(); |
311 maxLogicalWidth = std::max(m_optionsWidth, LayoutTheme::theme().minimumMenuL
istSize(styleRef())) + m_innerBlock->paddingLeft() + m_innerBlock->paddingRight(
); | 307 maxLogicalWidth = std::max(m_optionsWidth, LayoutTheme::theme().minimumMenuL
istSize(styleRef())) + m_innerBlock->paddingLeft() + m_innerBlock->paddingRight(
); |
312 if (!style()->width().hasPercent()) | 308 if (!style()->width().hasPercent()) |
313 minLogicalWidth = maxLogicalWidth; | 309 minLogicalWidth = maxLogicalWidth; |
314 } | 310 } |
315 | 311 |
316 void LayoutMenuList::didSetSelectedIndex(int optionIndex) | 312 void LayoutMenuList::didSetSelectedIndex(int optionIndex) |
317 { | 313 { |
318 didUpdateActiveOption(optionIndex); | 314 didUpdateActiveOption(optionIndex); |
319 } | 315 } |
320 | 316 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // space appear on the side of the popup menu. | 353 // space appear on the side of the popup menu. |
358 return LayoutUnit(endOfLinePadding); | 354 return LayoutUnit(endOfLinePadding); |
359 } | 355 } |
360 | 356 |
361 // If the appearance isn't MenulistPart, then the select is styled (non-nati
ve), so | 357 // If the appearance isn't MenulistPart, then the select is styled (non-nati
ve), so |
362 // we want to return the user specified padding. | 358 // we want to return the user specified padding. |
363 return paddingRight() + m_innerBlock->paddingRight(); | 359 return paddingRight() + m_innerBlock->paddingRight(); |
364 } | 360 } |
365 | 361 |
366 } // namespace blink | 362 } // namespace blink |
OLD | NEW |