| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 LayoutBlock::styleDidChange(diff, oldStyle); | 146 LayoutBlock::styleDidChange(diff, oldStyle); |
| 147 | 147 |
| 148 if (!m_innerBlock) | 148 if (!m_innerBlock) |
| 149 createInnerBlock(); | 149 createInnerBlock(); |
| 150 | 150 |
| 151 m_buttonText->setStyle(mutableStyle()); | 151 m_buttonText->setStyle(mutableStyle()); |
| 152 adjustInnerStyle(); | 152 adjustInnerStyle(); |
| 153 | 153 |
| 154 bool fontChanged = !oldStyle || oldStyle->font() != style()->font(); | 154 bool fontChanged = !oldStyle || oldStyle->font() != style()->font(); |
| 155 if (fontChanged) | 155 if (fontChanged) |
| 156 updateOptionsHeightWidth(); | 156 m_optionsChanged = true; |
| 157 } | 157 } |
| 158 | 158 |
| 159 void LayoutMenuList::updateOptionsHeightWidth() | 159 void LayoutMenuList::updateOptionsHeightWidth() const |
| 160 { | 160 { |
| 161 if (!m_optionsChanged) |
| 162 return; |
| 163 |
| 161 float maxOptionHeight = 0; | 164 float maxOptionHeight = 0; |
| 162 float maxOptionWidth = 0; | 165 float maxOptionWidth = 0; |
| 163 const HeapVector<Member<HTMLElement>>& listItems = selectElement()->listItem
s(); | 166 const HeapVector<Member<HTMLElement>>& listItems = selectElement()->listItem
s(); |
| 164 int size = listItems.size(); | 167 int size = listItems.size(); |
| 165 | 168 |
| 166 for (int i = 0; i < size; ++i) { | 169 for (int i = 0; i < size; ++i) { |
| 167 HTMLElement* element = listItems[i]; | 170 HTMLElement* element = listItems[i]; |
| 168 if (!isHTMLOptionElement(*element)) | 171 if (!isHTMLOptionElement(*element)) |
| 169 continue; | 172 continue; |
| 170 | 173 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 184 if (!text.isEmpty()) { | 187 if (!text.isEmpty()) { |
| 185 TextRun textRun = constructTextRun(itemStyle->font(), text, styl
eRef()); | 188 TextRun textRun = constructTextRun(itemStyle->font(), text, styl
eRef()); |
| 186 optionWidth += computeTextWidth(textRun, *itemStyle); | 189 optionWidth += computeTextWidth(textRun, *itemStyle); |
| 187 } | 190 } |
| 188 maxOptionWidth = std::max(maxOptionWidth, optionWidth); | 191 maxOptionWidth = std::max(maxOptionWidth, optionWidth); |
| 189 } else if (!text.isEmpty()) { | 192 } else if (!text.isEmpty()) { |
| 190 maxOptionWidth = std::max(maxOptionWidth, computeTextWidth(textRun,
*itemStyle)); | 193 maxOptionWidth = std::max(maxOptionWidth, computeTextWidth(textRun,
*itemStyle)); |
| 191 } | 194 } |
| 192 } | 195 } |
| 193 | 196 |
| 194 int height = static_cast<int>(ceilf(maxOptionHeight)); | 197 m_optionsWidth = static_cast<int>(ceilf(maxOptionWidth)); |
| 195 int width = static_cast<int>(ceilf(maxOptionWidth)); | 198 m_optionsHeight = static_cast<int>(ceilf(maxOptionHeight)); |
| 196 if (m_optionsWidth == width && m_optionsHeight == height) | 199 m_optionsChanged = false; |
| 197 return; | 200 } |
| 198 | 201 |
| 199 auto invalidationReason = LayoutInvalidationReason::Unknown; | 202 void LayoutMenuList::setOptionsChanged(bool changed) |
| 200 if (m_optionsWidth != width) { | 203 { |
| 201 m_optionsWidth = width; | 204 m_optionsChanged = changed; |
| 202 invalidationReason = LayoutInvalidationReason::MenuWidthChanged; | 205 if (changed && parent()) |
| 203 } | 206 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalida
tionReason::MenuOptionsChanged); |
| 204 | |
| 205 if (m_optionsHeight != height) { | |
| 206 m_optionsHeight = height; | |
| 207 invalidationReason = LayoutInvalidationReason::MenuHeightChanged; | |
| 208 } | |
| 209 | |
| 210 if (parent()) | |
| 211 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(invalidationRe
ason); | |
| 212 } | 207 } |
| 213 | 208 |
| 214 float LayoutMenuList::computeTextHeight(const TextRun& textRun, const ComputedSt
yle& computedStyle) const | 209 float LayoutMenuList::computeTextHeight(const TextRun& textRun, const ComputedSt
yle& computedStyle) const |
| 215 { | 210 { |
| 216 FloatRect glyphBounds; | 211 FloatRect glyphBounds; |
| 217 computedStyle.font().width(textRun, nullptr /* fallbackFonts */, &glyphBound
s); | 212 computedStyle.font().width(textRun, nullptr /* fallbackFonts */, &glyphBound
s); |
| 218 return glyphBounds.height(); | 213 return glyphBounds.height(); |
| 219 } | 214 } |
| 220 | 215 |
| 221 float LayoutMenuList::computeTextWidth(const TextRun& textRun, const ComputedSty
le& computedStyle) const | 216 float LayoutMenuList::computeTextWidth(const TextRun& textRun, const ComputedSty
le& computedStyle) const |
| 222 { | 217 { |
| 223 return computedStyle.font().width(textRun); | 218 return computedStyle.font().width(textRun); |
| 224 } | 219 } |
| 225 | 220 |
| 226 void LayoutMenuList::updateFromElement() | 221 void LayoutMenuList::updateFromElement() |
| 227 { | 222 { |
| 228 if (m_optionsChanged) { | |
| 229 updateOptionsHeightWidth(); | |
| 230 m_optionsChanged = false; | |
| 231 } | |
| 232 | |
| 233 updateText(); | |
| 234 } | |
| 235 | |
| 236 void LayoutMenuList::updateText() | |
| 237 { | |
| 238 setTextFromOption(selectElement()->optionIndexToBeShown()); | 223 setTextFromOption(selectElement()->optionIndexToBeShown()); |
| 239 } | 224 } |
| 240 | 225 |
| 241 void LayoutMenuList::setTextFromOption(int optionIndex) | 226 void LayoutMenuList::setTextFromOption(int optionIndex) |
| 242 { | 227 { |
| 243 HTMLSelectElement* select = selectElement(); | 228 HTMLSelectElement* select = selectElement(); |
| 244 const HeapVector<Member<HTMLElement>>& listItems = select->listItems(); | 229 const HeapVector<Member<HTMLElement>>& listItems = select->listItems(); |
| 245 const int size = listItems.size(); | 230 const int size = listItems.size(); |
| 246 | 231 |
| 247 String text = emptyString(); | 232 String text = emptyString(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 307 |
| 323 LayoutRect innerBox(additionalOffset + m_innerBlock->location() | 308 LayoutRect innerBox(additionalOffset + m_innerBlock->location() |
| 324 + LayoutSize(m_innerBlock->paddingLeft(), m_innerBlock->paddingTop()) | 309 + LayoutSize(m_innerBlock->paddingLeft(), m_innerBlock->paddingTop()) |
| 325 , m_innerBlock->contentSize()); | 310 , m_innerBlock->contentSize()); |
| 326 | 311 |
| 327 return intersection(outerBox, innerBox); | 312 return intersection(outerBox, innerBox); |
| 328 } | 313 } |
| 329 | 314 |
| 330 void LayoutMenuList::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
LayoutUnit& maxLogicalWidth) const | 315 void LayoutMenuList::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
LayoutUnit& maxLogicalWidth) const |
| 331 { | 316 { |
| 317 updateOptionsHeightWidth(); |
| 332 maxLogicalWidth = std::max(m_optionsWidth, LayoutTheme::theme().minimumMenuL
istSize(styleRef())) + m_innerBlock->paddingLeft() + m_innerBlock->paddingRight(
); | 318 maxLogicalWidth = std::max(m_optionsWidth, LayoutTheme::theme().minimumMenuL
istSize(styleRef())) + m_innerBlock->paddingLeft() + m_innerBlock->paddingRight(
); |
| 333 if (!style()->width().hasPercent()) | 319 if (!style()->width().hasPercent()) |
| 334 minLogicalWidth = maxLogicalWidth; | 320 minLogicalWidth = maxLogicalWidth; |
| 335 } | 321 } |
| 336 | 322 |
| 337 void LayoutMenuList::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit l
ogicalTop, | 323 void LayoutMenuList::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit l
ogicalTop, |
| 338 LogicalExtentComputedValues& computedValues) const | 324 LogicalExtentComputedValues& computedValues) const |
| 339 { | 325 { |
| 326 updateOptionsHeightWidth(); |
| 340 logicalHeight = LayoutUnit(m_optionsHeight) + borderAndPaddingHeight() | 327 logicalHeight = LayoutUnit(m_optionsHeight) + borderAndPaddingHeight() |
| 341 + LayoutUnit(cInnerBlockVerticalPaddingEm * style()->computedFontSize())
; | 328 + LayoutUnit(cInnerBlockVerticalPaddingEm * style()->computedFontSize())
; |
| 342 LayoutBox::computeLogicalHeight(logicalHeight, logicalTop, computedValues); | 329 LayoutBox::computeLogicalHeight(logicalHeight, logicalTop, computedValues); |
| 343 } | 330 } |
| 344 | 331 |
| 345 void LayoutMenuList::didSetSelectedIndex(int optionIndex) | 332 void LayoutMenuList::didSetSelectedIndex(int optionIndex) |
| 346 { | 333 { |
| 347 didUpdateActiveOption(optionIndex); | 334 didUpdateActiveOption(optionIndex); |
| 348 } | 335 } |
| 349 | 336 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 375 { | 362 { |
| 376 return paddingLeft() + m_innerBlock->paddingLeft(); | 363 return paddingLeft() + m_innerBlock->paddingLeft(); |
| 377 } | 364 } |
| 378 | 365 |
| 379 LayoutUnit LayoutMenuList::clientPaddingRight() const | 366 LayoutUnit LayoutMenuList::clientPaddingRight() const |
| 380 { | 367 { |
| 381 return paddingRight() + m_innerBlock->paddingRight(); | 368 return paddingRight() + m_innerBlock->paddingRight(); |
| 382 } | 369 } |
| 383 | 370 |
| 384 } // namespace blink | 371 } // namespace blink |
| OLD | NEW |