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

Side by Side Diff: Source/core/layout/LayoutMenuList.cpp

Issue 966883002: renderer/RenderMenuList.* -> layout/LayoutMenuList.* (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove OWNERS, allowing Source/core/rendering to be deleted. Created 5 years, 9 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
« no previous file with comments | « Source/core/layout/LayoutMenuList.h ('k') | Source/core/layout/LayoutThemeDefault.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 * 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
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 * 22 *
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/rendering/RenderMenuList.h" 26 #include "core/layout/LayoutMenuList.h"
27 27
28 #include "core/HTMLNames.h" 28 #include "core/HTMLNames.h"
29 #include "core/css/CSSFontSelector.h" 29 #include "core/css/CSSFontSelector.h"
30 #include "core/css/resolver/StyleResolver.h" 30 #include "core/css/resolver/StyleResolver.h"
31 #include "core/dom/AXObjectCache.h" 31 #include "core/dom/AXObjectCache.h"
32 #include "core/dom/NodeLayoutStyle.h" 32 #include "core/dom/NodeLayoutStyle.h"
33 #include "core/frame/FrameHost.h" 33 #include "core/frame/FrameHost.h"
34 #include "core/frame/FrameView.h" 34 #include "core/frame/FrameView.h"
35 #include "core/frame/LocalFrame.h" 35 #include "core/frame/LocalFrame.h"
36 #include "core/frame/Settings.h" 36 #include "core/frame/Settings.h"
37 #include "core/html/HTMLOptGroupElement.h" 37 #include "core/html/HTMLOptGroupElement.h"
38 #include "core/html/HTMLOptionElement.h" 38 #include "core/html/HTMLOptionElement.h"
39 #include "core/html/HTMLSelectElement.h" 39 #include "core/html/HTMLSelectElement.h"
40 #include "core/layout/LayoutBR.h" 40 #include "core/layout/LayoutBR.h"
41 #include "core/layout/LayoutScrollbar.h" 41 #include "core/layout/LayoutScrollbar.h"
42 #include "core/layout/LayoutTheme.h" 42 #include "core/layout/LayoutTheme.h"
43 #include "core/layout/LayoutView.h" 43 #include "core/layout/LayoutView.h"
44 #include "core/page/Chrome.h" 44 #include "core/page/Chrome.h"
45 #include "platform/fonts/FontCache.h" 45 #include "platform/fonts/FontCache.h"
46 #include "platform/geometry/IntSize.h" 46 #include "platform/geometry/IntSize.h"
47 #include "platform/text/PlatformLocale.h" 47 #include "platform/text/PlatformLocale.h"
48 #include <math.h> 48 #include <math.h>
49 49
50 namespace blink { 50 namespace blink {
51 51
52 using namespace HTMLNames; 52 using namespace HTMLNames;
53 53
54 RenderMenuList::RenderMenuList(Element* element) 54 LayoutMenuList::LayoutMenuList(Element* element)
55 : LayoutFlexibleBox(element) 55 : LayoutFlexibleBox(element)
56 , m_buttonText(nullptr) 56 , m_buttonText(nullptr)
57 , m_innerBlock(nullptr) 57 , m_innerBlock(nullptr)
58 , m_optionsChanged(true) 58 , m_optionsChanged(true)
59 , m_optionsWidth(0) 59 , m_optionsWidth(0)
60 , m_lastActiveIndex(-1) 60 , m_lastActiveIndex(-1)
61 , m_popupIsVisible(false) 61 , m_popupIsVisible(false)
62 { 62 {
63 ASSERT(isHTMLSelectElement(element)); 63 ASSERT(isHTMLSelectElement(element));
64 } 64 }
65 65
66 RenderMenuList::~RenderMenuList() 66 LayoutMenuList::~LayoutMenuList()
67 { 67 {
68 ASSERT(!m_popup); 68 ASSERT(!m_popup);
69 } 69 }
70 70
71 void RenderMenuList::destroy() 71 void LayoutMenuList::destroy()
72 { 72 {
73 if (m_popup) 73 if (m_popup)
74 m_popup->disconnectClient(); 74 m_popup->disconnectClient();
75 m_popup = nullptr; 75 m_popup = nullptr;
76 LayoutFlexibleBox::destroy(); 76 LayoutFlexibleBox::destroy();
77 } 77 }
78 78
79 // FIXME: Instead of this hack we should add a ShadowRoot to <select> with no in sertion point 79 // FIXME: Instead of this hack we should add a ShadowRoot to <select> with no in sertion point
80 // to prevent children from rendering. 80 // to prevent children from rendering.
81 bool RenderMenuList::isChildAllowed(LayoutObject* object, const LayoutStyle&) co nst 81 bool LayoutMenuList::isChildAllowed(LayoutObject* object, const LayoutStyle&) co nst
82 { 82 {
83 return object->isAnonymous() && !object->isLayoutFullScreen(); 83 return object->isAnonymous() && !object->isLayoutFullScreen();
84 } 84 }
85 85
86 void RenderMenuList::createInnerBlock() 86 void LayoutMenuList::createInnerBlock()
87 { 87 {
88 if (m_innerBlock) { 88 if (m_innerBlock) {
89 ASSERT(firstChild() == m_innerBlock); 89 ASSERT(firstChild() == m_innerBlock);
90 ASSERT(!m_innerBlock->nextSibling()); 90 ASSERT(!m_innerBlock->nextSibling());
91 return; 91 return;
92 } 92 }
93 93
94 // Create an anonymous block. 94 // Create an anonymous block.
95 ASSERT(!firstChild()); 95 ASSERT(!firstChild());
96 m_innerBlock = createAnonymousBlock(); 96 m_innerBlock = createAnonymousBlock();
97 adjustInnerStyle(); 97 adjustInnerStyle();
98 LayoutFlexibleBox::addChild(m_innerBlock); 98 LayoutFlexibleBox::addChild(m_innerBlock);
99 } 99 }
100 100
101 void RenderMenuList::adjustInnerStyle() 101 void LayoutMenuList::adjustInnerStyle()
102 { 102 {
103 LayoutStyle& innerStyle = m_innerBlock->mutableStyleRef(); 103 LayoutStyle& innerStyle = m_innerBlock->mutableStyleRef();
104 innerStyle.setFlexGrow(1); 104 innerStyle.setFlexGrow(1);
105 innerStyle.setFlexShrink(1); 105 innerStyle.setFlexShrink(1);
106 // Use margin:auto instead of align-items:center to get safe centering, i.e. 106 // Use margin:auto instead of align-items:center to get safe centering, i.e.
107 // when the content overflows, treat it the same as align-items: flex-start. 107 // when the content overflows, treat it the same as align-items: flex-start.
108 // But we only do that for the cases where html.css would otherwise use cent er. 108 // But we only do that for the cases where html.css would otherwise use cent er.
109 if (style()->alignItems() == ItemPositionCenter) { 109 if (style()->alignItems() == ItemPositionCenter) {
110 innerStyle.setMarginTop(Length()); 110 innerStyle.setMarginTop(Length());
111 innerStyle.setMarginBottom(Length()); 111 innerStyle.setMarginBottom(Length());
112 innerStyle.setAlignSelf(ItemPositionFlexStart); 112 innerStyle.setAlignSelf(ItemPositionFlexStart);
113 } 113 }
114 114
115 innerStyle.setPaddingLeft(Length(LayoutTheme::theme().popupInternalPaddingLe ft(styleRef()), Fixed)); 115 innerStyle.setPaddingLeft(Length(LayoutTheme::theme().popupInternalPaddingLe ft(styleRef()), Fixed));
116 innerStyle.setPaddingRight(Length(LayoutTheme::theme().popupInternalPaddingR ight(styleRef()), Fixed)); 116 innerStyle.setPaddingRight(Length(LayoutTheme::theme().popupInternalPaddingR ight(styleRef()), Fixed));
117 innerStyle.setPaddingTop(Length(LayoutTheme::theme().popupInternalPaddingTop (styleRef()), Fixed)); 117 innerStyle.setPaddingTop(Length(LayoutTheme::theme().popupInternalPaddingTop (styleRef()), Fixed));
118 innerStyle.setPaddingBottom(Length(LayoutTheme::theme().popupInternalPadding Bottom(styleRef()), Fixed)); 118 innerStyle.setPaddingBottom(Length(LayoutTheme::theme().popupInternalPadding Bottom(styleRef()), Fixed));
119 119
120 if (m_optionStyle) { 120 if (m_optionStyle) {
121 if ((m_optionStyle->direction() != innerStyle.direction() || m_optionSty le->unicodeBidi() != innerStyle.unicodeBidi())) 121 if ((m_optionStyle->direction() != innerStyle.direction() || m_optionSty le->unicodeBidi() != innerStyle.unicodeBidi()))
122 m_innerBlock->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidat ion(); 122 m_innerBlock->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidat ion();
123 innerStyle.setTextAlign(style()->isLeftToRightDirection() ? LEFT : RIGHT ); 123 innerStyle.setTextAlign(style()->isLeftToRightDirection() ? LEFT : RIGHT );
124 innerStyle.setDirection(m_optionStyle->direction()); 124 innerStyle.setDirection(m_optionStyle->direction());
125 innerStyle.setUnicodeBidi(m_optionStyle->unicodeBidi()); 125 innerStyle.setUnicodeBidi(m_optionStyle->unicodeBidi());
126 } 126 }
127 } 127 }
128 128
129 inline HTMLSelectElement* RenderMenuList::selectElement() const 129 inline HTMLSelectElement* LayoutMenuList::selectElement() const
130 { 130 {
131 return toHTMLSelectElement(node()); 131 return toHTMLSelectElement(node());
132 } 132 }
133 133
134 void RenderMenuList::addChild(LayoutObject* newChild, LayoutObject* beforeChild) 134 void LayoutMenuList::addChild(LayoutObject* newChild, LayoutObject* beforeChild)
135 { 135 {
136 createInnerBlock(); 136 createInnerBlock();
137 m_innerBlock->addChild(newChild, beforeChild); 137 m_innerBlock->addChild(newChild, beforeChild);
138 ASSERT(m_innerBlock == firstChild()); 138 ASSERT(m_innerBlock == firstChild());
139 139
140 if (AXObjectCache* cache = document().existingAXObjectCache()) 140 if (AXObjectCache* cache = document().existingAXObjectCache())
141 cache->childrenChanged(this); 141 cache->childrenChanged(this);
142 } 142 }
143 143
144 void RenderMenuList::removeChild(LayoutObject* oldChild) 144 void LayoutMenuList::removeChild(LayoutObject* oldChild)
145 { 145 {
146 if (oldChild == m_innerBlock || !m_innerBlock) { 146 if (oldChild == m_innerBlock || !m_innerBlock) {
147 LayoutFlexibleBox::removeChild(oldChild); 147 LayoutFlexibleBox::removeChild(oldChild);
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
153 void RenderMenuList::styleDidChange(StyleDifference diff, const LayoutStyle* old Style) 154 void LayoutMenuList::styleDidChange(StyleDifference diff, const LayoutStyle* old Style)
154 { 155 {
155 LayoutBlock::styleDidChange(diff, oldStyle); 156 LayoutBlock::styleDidChange(diff, oldStyle);
156 157
157 if (m_buttonText) 158 if (m_buttonText)
158 m_buttonText->setStyle(style()); 159 m_buttonText->setStyle(style());
159 if (m_innerBlock) // LayoutBlock handled updating the anonymous block's styl e. 160 if (m_innerBlock) // LayoutBlock handled updating the anonymous block's styl e.
160 adjustInnerStyle(); 161 adjustInnerStyle();
161 162
162 bool fontChanged = !oldStyle || oldStyle->font() != style()->font(); 163 bool fontChanged = !oldStyle || oldStyle->font() != style()->font();
163 if (fontChanged) 164 if (fontChanged)
164 updateOptionsWidth(); 165 updateOptionsWidth();
165 } 166 }
166 167
167 void RenderMenuList::updateOptionsWidth() 168 void LayoutMenuList::updateOptionsWidth()
168 { 169 {
169 float maxOptionWidth = 0; 170 float maxOptionWidth = 0;
170 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems(); 171 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = selectE lement()->listItems();
171 int size = listItems.size(); 172 int size = listItems.size();
172 173
173 for (int i = 0; i < size; ++i) { 174 for (int i = 0; i < size; ++i) {
174 HTMLElement* element = listItems[i]; 175 HTMLElement* element = listItems[i];
175 if (!isHTMLOptionElement(*element)) 176 if (!isHTMLOptionElement(*element))
176 continue; 177 continue;
177 178
178 String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLa bel(); 179 String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLa bel();
179 applyTextTransform(style(), text, ' '); 180 applyTextTransform(style(), text, ' ');
180 if (LayoutTheme::theme().popupOptionSupportsTextIndent()) { 181 if (LayoutTheme::theme().popupOptionSupportsTextIndent()) {
(...skipping 11 matching lines...) Expand all
192 193
193 int width = static_cast<int>(ceilf(maxOptionWidth)); 194 int width = static_cast<int>(ceilf(maxOptionWidth));
194 if (m_optionsWidth == width) 195 if (m_optionsWidth == width)
195 return; 196 return;
196 197
197 m_optionsWidth = width; 198 m_optionsWidth = width;
198 if (parent()) 199 if (parent())
199 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(); 200 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
200 } 201 }
201 202
202 void RenderMenuList::updateFromElement() 203 void LayoutMenuList::updateFromElement()
203 { 204 {
204 if (m_optionsChanged) { 205 if (m_optionsChanged) {
205 updateOptionsWidth(); 206 updateOptionsWidth();
206 m_optionsChanged = false; 207 m_optionsChanged = false;
207 } 208 }
208 209
209 if (m_popupIsVisible) 210 if (m_popupIsVisible)
210 m_popup->updateFromElement(); 211 m_popup->updateFromElement();
211 212
212 if (selectElement()->suggestedIndex() >= 0) 213 if (selectElement()->suggestedIndex() >= 0)
213 setTextFromOption(selectElement()->suggestedIndex()); 214 setTextFromOption(selectElement()->suggestedIndex());
214 else 215 else
215 setTextFromOption(selectElement()->selectedIndex()); 216 setTextFromOption(selectElement()->selectedIndex());
216 } 217 }
217 218
218 void RenderMenuList::setTextFromOption(int optionIndex) 219 void LayoutMenuList::setTextFromOption(int optionIndex)
219 { 220 {
220 HTMLSelectElement* select = selectElement(); 221 HTMLSelectElement* select = selectElement();
221 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select ->listItems(); 222 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = select- >listItems();
222 const int size = listItems.size(); 223 const int size = listItems.size();
223 224
224 String text = emptyString(); 225 String text = emptyString();
225 m_optionStyle.clear(); 226 m_optionStyle.clear();
226 227
227 if (multiple()) { 228 if (multiple()) {
228 unsigned selectedCount = 0; 229 unsigned selectedCount = 0;
229 int firstSelectedIndex = -1; 230 int firstSelectedIndex = -1;
230 for (int i = 0; i < size; ++i) { 231 for (int i = 0; i < size; ++i) {
231 Element* element = listItems[i]; 232 Element* element = listItems[i];
(...skipping 28 matching lines...) Expand all
260 m_optionStyle = element->layoutStyle(); 261 m_optionStyle = element->layoutStyle();
261 } 262 }
262 } 263 }
263 } 264 }
264 265
265 setText(text.stripWhiteSpace()); 266 setText(text.stripWhiteSpace());
266 267
267 didUpdateActiveOption(optionIndex); 268 didUpdateActiveOption(optionIndex);
268 } 269 }
269 270
270 void RenderMenuList::setText(const String& s) 271 void LayoutMenuList::setText(const String& s)
271 { 272 {
272 if (s.isEmpty()) { 273 if (s.isEmpty()) {
273 if (!m_buttonText || !m_buttonText->isBR()) { 274 if (!m_buttonText || !m_buttonText->isBR()) {
274 // FIXME: We should not modify the structure of the render tree 275 // FIXME: We should not modify the structure of the render tree
275 // during layout. crbug.com/370462 276 // during layout. crbug.com/370462
276 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; 277 DeprecatedDisableModifyRenderTreeStructureAsserts disabler;
277 if (m_buttonText) 278 if (m_buttonText)
278 m_buttonText->destroy(); 279 m_buttonText->destroy();
279 m_buttonText = new LayoutBR(&document()); 280 m_buttonText = new LayoutBR(&document());
280 m_buttonText->setStyle(style()); 281 m_buttonText->setStyle(style());
281 addChild(m_buttonText); 282 addChild(m_buttonText);
282 } 283 }
283 } else { 284 } else {
284 if (m_buttonText && !m_buttonText->isBR()) 285 if (m_buttonText && !m_buttonText->isBR()) {
285 m_buttonText->setText(s.impl(), true); 286 m_buttonText->setText(s.impl(), true);
286 else { 287 } else {
287 // FIXME: We should not modify the structure of the render tree 288 // FIXME: We should not modify the structure of the render tree
288 // during layout. crbug.com/370462 289 // during layout. crbug.com/370462
289 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; 290 DeprecatedDisableModifyRenderTreeStructureAsserts disabler;
290 if (m_buttonText) 291 if (m_buttonText)
291 m_buttonText->destroy(); 292 m_buttonText->destroy();
292 m_buttonText = new LayoutText(&document(), s.impl()); 293 m_buttonText = new LayoutText(&document(), s.impl());
293 m_buttonText->setStyle(style()); 294 m_buttonText->setStyle(style());
294 // We need to set the text explicitly though it was specified in the 295 // We need to set the text explicitly though it was specified in the
295 // constructor because LayoutText doesn't refer to the text 296 // constructor because LayoutText doesn't refer to the text
296 // specified in the constructor in a case of re-transforming. 297 // specified in the constructor in a case of re-transforming.
297 m_buttonText->setText(s.impl(), true); 298 m_buttonText->setText(s.impl(), true);
298 addChild(m_buttonText); 299 addChild(m_buttonText);
299 } 300 }
300 adjustInnerStyle(); 301 adjustInnerStyle();
301 } 302 }
302 } 303 }
303 304
304 String RenderMenuList::text() const 305 String LayoutMenuList::text() const
305 { 306 {
306 return m_buttonText ? m_buttonText->text() : String(); 307 return m_buttonText ? m_buttonText->text() : String();
307 } 308 }
308 309
309 LayoutRect RenderMenuList::controlClipRect(const LayoutPoint& additionalOffset) const 310 LayoutRect LayoutMenuList::controlClipRect(const LayoutPoint& additionalOffset) const
310 { 311 {
311 // Clip to the intersection of the content box and the content box for the i nner box 312 // Clip to the intersection of the content box and the content box for the i nner box
312 // This will leave room for the arrows which sit in the inner box padding, 313 // This will leave room for the arrows which sit in the inner box padding,
313 // and if the inner box ever spills out of the outer box, that will get clip ped too. 314 // and if the inner box ever spills out of the outer box, that will get clip ped too.
314 LayoutRect outerBox = contentBoxRect(); 315 LayoutRect outerBox = contentBoxRect();
315 outerBox.moveBy(additionalOffset); 316 outerBox.moveBy(additionalOffset);
316 317
317 LayoutRect innerBox(additionalOffset + m_innerBlock->location() 318 LayoutRect innerBox(additionalOffset + m_innerBlock->location()
318 + LayoutSize(m_innerBlock->paddingLeft(), m_innerBlock->paddingTop()) 319 + LayoutSize(m_innerBlock->paddingLeft(), m_innerBlock->paddingTop())
319 , m_innerBlock->contentSize()); 320 , m_innerBlock->contentSize());
320 321
321 return intersection(outerBox, innerBox); 322 return intersection(outerBox, innerBox);
322 } 323 }
323 324
324 void RenderMenuList::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const 325 void LayoutMenuList::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
325 { 326 {
326 maxLogicalWidth = std::max(m_optionsWidth, LayoutTheme::theme().minimumMenuL istSize(styleRef())) + m_innerBlock->paddingLeft() + m_innerBlock->paddingRight( ); 327 maxLogicalWidth = std::max(m_optionsWidth, LayoutTheme::theme().minimumMenuL istSize(styleRef())) + m_innerBlock->paddingLeft() + m_innerBlock->paddingRight( );
327 if (!style()->width().isPercent()) 328 if (!style()->width().isPercent())
328 minLogicalWidth = maxLogicalWidth; 329 minLogicalWidth = maxLogicalWidth;
329 } 330 }
330 331
331 void RenderMenuList::showPopup() 332 void LayoutMenuList::showPopup()
332 { 333 {
333 if (m_popupIsVisible) 334 if (m_popupIsVisible)
334 return; 335 return;
335 336
336 if (document().frameHost()->chrome().hasOpenedPopup()) 337 if (document().frameHost()->chrome().hasOpenedPopup())
337 return; 338 return;
338 339
339 // Create m_innerBlock here so it ends up as the first child. 340 // Create m_innerBlock here so it ends up as the first child.
340 // This is important because otherwise we might try to create m_innerBlock 341 // This is important because otherwise we might try to create m_innerBlock
341 // inside the showPopup call and it would fail. 342 // inside the showPopup call and it would fail.
342 createInnerBlock(); 343 createInnerBlock();
343 if (!m_popup) 344 if (!m_popup)
344 m_popup = document().frameHost()->chrome().createPopupMenu(*document().f rame(), this); 345 m_popup = document().frameHost()->chrome().createPopupMenu(*document().f rame(), this);
345 m_popupIsVisible = true; 346 m_popupIsVisible = true;
346 347
347 FloatQuad quad(localToAbsoluteQuad(FloatQuad(borderBoundingBox()))); 348 FloatQuad quad(localToAbsoluteQuad(FloatQuad(borderBoundingBox())));
348 IntSize size = pixelSnappedIntRect(frameRect()).size(); 349 IntSize size = pixelSnappedIntRect(frameRect()).size();
349 HTMLSelectElement* select = selectElement(); 350 HTMLSelectElement* select = selectElement();
350 m_popup->show(quad, size, select->optionToListIndex(select->selectedIndex()) ); 351 m_popup->show(quad, size, select->optionToListIndex(select->selectedIndex()) );
351 } 352 }
352 353
353 void RenderMenuList::hidePopup() 354 void LayoutMenuList::hidePopup()
354 { 355 {
355 if (m_popup) 356 if (m_popup)
356 m_popup->hide(); 357 m_popup->hide();
357 } 358 }
358 359
359 void RenderMenuList::valueChanged(unsigned listIndex, bool fireOnChange) 360 void LayoutMenuList::valueChanged(unsigned listIndex, bool fireOnChange)
360 { 361 {
361 // Check to ensure a page navigation has not occurred while 362 // Check to ensure a page navigation has not occurred while
362 // the popup was up. 363 // the popup was up.
363 Document& doc = toElement(node())->document(); 364 Document& doc = toElement(node())->document();
364 if (&doc != doc.frame()->document()) 365 if (&doc != doc.frame()->document())
365 return; 366 return;
366 367
367 HTMLSelectElement* select = selectElement(); 368 HTMLSelectElement* select = selectElement();
368 select->optionSelectedByUser(select->listToOptionIndex(listIndex), fireOnCha nge); 369 select->optionSelectedByUser(select->listToOptionIndex(listIndex), fireOnCha nge);
369 } 370 }
370 371
371 void RenderMenuList::listBoxSelectItem(int listIndex, bool allowMultiplySelectio ns, bool shift, bool fireOnChangeNow) 372 void LayoutMenuList::listBoxSelectItem(int listIndex, bool allowMultiplySelectio ns, bool shift, bool fireOnChangeNow)
372 { 373 {
373 selectElement()->listBoxSelectItem(listIndex, allowMultiplySelections, shift , fireOnChangeNow); 374 selectElement()->listBoxSelectItem(listIndex, allowMultiplySelections, shift , fireOnChangeNow);
374 } 375 }
375 376
376 bool RenderMenuList::multiple() const 377 bool LayoutMenuList::multiple() const
377 { 378 {
378 return selectElement()->multiple(); 379 return selectElement()->multiple();
379 } 380 }
380 381
381 IntRect RenderMenuList::elementRectRelativeToViewport() const 382 IntRect LayoutMenuList::elementRectRelativeToViewport() const
382 { 383 {
383 return selectElement()->document().view()->contentsToWindow(absoluteBounding BoxRect()); 384 return selectElement()->document().view()->contentsToWindow(absoluteBounding BoxRect());
384 } 385 }
385 386
386 Element& RenderMenuList::ownerElement() const 387 Element& LayoutMenuList::ownerElement() const
387 { 388 {
388 return *selectElement(); 389 return *selectElement();
389 } 390 }
390 391
391 const LayoutStyle* RenderMenuList::layoutStyleForItem(Element& element) const 392 const LayoutStyle* LayoutMenuList::layoutStyleForItem(Element& element) const
392 { 393 {
393 document().updateRenderTreeIfNeeded(); 394 document().updateRenderTreeIfNeeded();
394 return element.layoutStyle() ? element.layoutStyle() : element.computedStyle (); 395 return element.layoutStyle() ? element.layoutStyle() : element.computedStyle ();
395 } 396 }
396 397
397 void RenderMenuList::didSetSelectedIndex(int listIndex) 398 void LayoutMenuList::didSetSelectedIndex(int listIndex)
398 { 399 {
399 didUpdateActiveOption(selectElement()->listToOptionIndex(listIndex)); 400 didUpdateActiveOption(selectElement()->listToOptionIndex(listIndex));
400 } 401 }
401 402
402 void RenderMenuList::didUpdateActiveOption(int optionIndex) 403 void LayoutMenuList::didUpdateActiveOption(int optionIndex)
403 { 404 {
404 if (!document().existingAXObjectCache()) 405 if (!document().existingAXObjectCache())
405 return; 406 return;
406 407
407 if (m_lastActiveIndex == optionIndex) 408 if (m_lastActiveIndex == optionIndex)
408 return; 409 return;
409 m_lastActiveIndex = optionIndex; 410 m_lastActiveIndex = optionIndex;
410 411
411 HTMLSelectElement* select = selectElement(); 412 HTMLSelectElement* select = selectElement();
412 int listIndex = select->optionToListIndex(optionIndex); 413 int listIndex = select->optionToListIndex(optionIndex);
413 if (listIndex < 0 || listIndex >= static_cast<int>(select->listItems().size( ))) 414 if (listIndex < 0 || listIndex >= static_cast<int>(select->listItems().size( )))
414 return; 415 return;
415 document().existingAXObjectCache()->handleUpdateActiveMenuOption(this, optio nIndex); 416 document().existingAXObjectCache()->handleUpdateActiveMenuOption(this, optio nIndex);
416 } 417 }
417 418
418 String RenderMenuList::itemText(unsigned listIndex) const 419 String LayoutMenuList::itemText(unsigned listIndex) const
419 { 420 {
420 HTMLSelectElement* select = selectElement(); 421 HTMLSelectElement* select = selectElement();
421 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select ->listItems(); 422 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = select- >listItems();
422 if (listIndex >= listItems.size()) 423 if (listIndex >= listItems.size())
423 return String(); 424 return String();
424 425
425 String itemString; 426 String itemString;
426 Element* element = listItems[listIndex]; 427 Element* element = listItems[listIndex];
427 if (isHTMLOptGroupElement(*element)) 428 if (isHTMLOptGroupElement(*element))
428 itemString = toHTMLOptGroupElement(*element).groupLabelText(); 429 itemString = toHTMLOptGroupElement(*element).groupLabelText();
429 else if (isHTMLOptionElement(*element)) 430 else if (isHTMLOptionElement(*element))
430 itemString = toHTMLOptionElement(*element).textIndentedToRespectGroupLab el(); 431 itemString = toHTMLOptionElement(*element).textIndentedToRespectGroupLab el();
431 432
432 applyTextTransform(style(), itemString, ' '); 433 applyTextTransform(style(), itemString, ' ');
433 return itemString; 434 return itemString;
434 } 435 }
435 436
436 String RenderMenuList::itemAccessibilityText(unsigned listIndex) const 437 String LayoutMenuList::itemAccessibilityText(unsigned listIndex) const
437 { 438 {
438 // Allow the accessible name be changed if necessary. 439 // Allow the accessible name be changed if necessary.
439 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems(); 440 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = selectE lement()->listItems();
440 if (listIndex >= listItems.size()) 441 if (listIndex >= listItems.size())
441 return String(); 442 return String();
442 return listItems[listIndex]->fastGetAttribute(aria_labelAttr); 443 return listItems[listIndex]->fastGetAttribute(aria_labelAttr);
443 } 444 }
444 445
445 String RenderMenuList::itemToolTip(unsigned listIndex) const 446 String LayoutMenuList::itemToolTip(unsigned listIndex) const
446 { 447 {
447 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems(); 448 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = selectE lement()->listItems();
448 if (listIndex >= listItems.size()) 449 if (listIndex >= listItems.size())
449 return String(); 450 return String();
450 return listItems[listIndex]->title(); 451 return listItems[listIndex]->title();
451 } 452 }
452 453
453 bool RenderMenuList::itemIsEnabled(unsigned listIndex) const 454 bool LayoutMenuList::itemIsEnabled(unsigned listIndex) const
454 { 455 {
455 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems(); 456 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = selectE lement()->listItems();
456 if (listIndex >= listItems.size()) 457 if (listIndex >= listItems.size())
457 return false; 458 return false;
458 HTMLElement* element = listItems[listIndex]; 459 HTMLElement* element = listItems[listIndex];
459 if (!isHTMLOptionElement(*element)) 460 if (!isHTMLOptionElement(*element))
460 return false; 461 return false;
461 462
462 bool groupEnabled = true; 463 bool groupEnabled = true;
463 if (Element* parentElement = element->parentElement()) { 464 if (Element* parentElement = element->parentElement()) {
464 if (isHTMLOptGroupElement(*parentElement)) 465 if (isHTMLOptGroupElement(*parentElement))
465 groupEnabled = !parentElement->isDisabledFormControl(); 466 groupEnabled = !parentElement->isDisabledFormControl();
466 } 467 }
467 if (!groupEnabled) 468 if (!groupEnabled)
468 return false; 469 return false;
469 470
470 return !element->isDisabledFormControl(); 471 return !element->isDisabledFormControl();
471 } 472 }
472 473
473 PopupMenuStyle RenderMenuList::itemStyle(unsigned listIndex) const 474 PopupMenuStyle LayoutMenuList::itemStyle(unsigned listIndex) const
474 { 475 {
475 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems(); 476 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = selectE lement()->listItems();
476 if (listIndex >= listItems.size()) { 477 if (listIndex >= listItems.size()) {
477 // If we are making an out of bounds access, then we want to use the sty le 478 // If we are making an out of bounds access, then we want to use the sty le
478 // of a different option element (index 0). However, if there isn't an o ption element 479 // of a different option element (index 0). However, if there isn't an o ption element
479 // before at index 0, we fall back to the menu's style. 480 // before at index 0, we fall back to the menu's style.
480 if (!listIndex) 481 if (!listIndex)
481 return menuStyle(); 482 return menuStyle();
482 483
483 // Try to retrieve the style of an option element we know exists (index 0). 484 // Try to retrieve the style of an option element we know exists (index 0).
484 listIndex = 0; 485 listIndex = 0;
485 } 486 }
486 HTMLElement* element = listItems[listIndex]; 487 HTMLElement* element = listItems[listIndex];
487 488
488 Color itemBackgroundColor; 489 Color itemBackgroundColor;
489 bool itemHasCustomBackgroundColor; 490 bool itemHasCustomBackgroundColor;
490 getItemBackgroundColor(listIndex, itemBackgroundColor, itemHasCustomBackgrou ndColor); 491 getItemBackgroundColor(listIndex, itemBackgroundColor, itemHasCustomBackgrou ndColor);
491 492
492 const LayoutStyle* style = element->layoutStyle() ? element->layoutStyle() : element->computedStyle(); 493 const LayoutStyle* style = element->layoutStyle() ? element->layoutStyle() : element->computedStyle();
493 return style ? PopupMenuStyle(resolveColor(*style, CSSPropertyColor), itemBa ckgroundColor, style->font(), style->visibility() == VISIBLE, 494 return style ? PopupMenuStyle(resolveColor(*style, CSSPropertyColor), itemBa ckgroundColor, style->font(), style->visibility() == VISIBLE,
494 isHTMLOptionElement(*element) ? toHTMLOptionElement(*element).isDisplayN one() : style->display() == NONE, 495 isHTMLOptionElement(*element) ? toHTMLOptionElement(*element).isDisplayN one() : style->display() == NONE,
495 style->textIndent(), style->direction(), isOverride(style->unicodeBidi() ), 496 style->textIndent(), style->direction(), isOverride(style->unicodeBidi() ),
496 itemHasCustomBackgroundColor ? PopupMenuStyle::CustomBackgroundColor : P opupMenuStyle::DefaultBackgroundColor) : menuStyle(); 497 itemHasCustomBackgroundColor ? PopupMenuStyle::CustomBackgroundColor : P opupMenuStyle::DefaultBackgroundColor) : menuStyle();
497 } 498 }
498 499
499 void RenderMenuList::getItemBackgroundColor(unsigned listIndex, Color& itemBackg roundColor, bool& itemHasCustomBackgroundColor) const 500 void LayoutMenuList::getItemBackgroundColor(unsigned listIndex, Color& itemBackg roundColor, bool& itemHasCustomBackgroundColor) const
500 { 501 {
501 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems(); 502 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = selectE lement()->listItems();
502 if (listIndex >= listItems.size()) { 503 if (listIndex >= listItems.size()) {
503 itemBackgroundColor = resolveColor(CSSPropertyBackgroundColor); 504 itemBackgroundColor = resolveColor(CSSPropertyBackgroundColor);
504 itemHasCustomBackgroundColor = false; 505 itemHasCustomBackgroundColor = false;
505 return; 506 return;
506 } 507 }
507 HTMLElement* element = listItems[listIndex]; 508 HTMLElement* element = listItems[listIndex];
508 509
509 Color backgroundColor; 510 Color backgroundColor;
510 if (const LayoutStyle* style = element->layoutStyle()) 511 if (const LayoutStyle* style = element->layoutStyle())
511 backgroundColor = resolveColor(*style, CSSPropertyBackgroundColor); 512 backgroundColor = resolveColor(*style, CSSPropertyBackgroundColor);
512 itemHasCustomBackgroundColor = backgroundColor.alpha(); 513 itemHasCustomBackgroundColor = backgroundColor.alpha();
513 // If the item has an opaque background color, return that. 514 // If the item has an opaque background color, return that.
514 if (!backgroundColor.hasAlpha()) { 515 if (!backgroundColor.hasAlpha()) {
515 itemBackgroundColor = backgroundColor; 516 itemBackgroundColor = backgroundColor;
516 return; 517 return;
517 } 518 }
518 519
519 // Otherwise, the item's background is overlayed on top of the menu backgrou nd. 520 // Otherwise, the item's background is overlayed on top of the menu backgrou nd.
520 backgroundColor = resolveColor(CSSPropertyBackgroundColor).blend(backgroundC olor); 521 backgroundColor = resolveColor(CSSPropertyBackgroundColor).blend(backgroundC olor);
521 if (!backgroundColor.hasAlpha()) { 522 if (!backgroundColor.hasAlpha()) {
522 itemBackgroundColor = backgroundColor; 523 itemBackgroundColor = backgroundColor;
523 return; 524 return;
524 } 525 }
525 526
526 // If the menu background is not opaque, then add an opaque white background behind. 527 // If the menu background is not opaque, then add an opaque white background behind.
527 itemBackgroundColor = Color(Color::white).blend(backgroundColor); 528 itemBackgroundColor = Color(Color::white).blend(backgroundColor);
528 } 529 }
529 530
530 PopupMenuStyle RenderMenuList::menuStyle() const 531 PopupMenuStyle LayoutMenuList::menuStyle() const
531 { 532 {
532 const LayoutObject* o = m_innerBlock ? m_innerBlock : this; 533 const LayoutObject* o = m_innerBlock ? m_innerBlock : this;
533 const LayoutStyle& style = o->styleRef(); 534 const LayoutStyle& style = o->styleRef();
534 return PopupMenuStyle(o->resolveColor(CSSPropertyColor), o->resolveColor(CSS PropertyBackgroundColor), style.font(), style.visibility() == VISIBLE, 535 return PopupMenuStyle(o->resolveColor(CSSPropertyColor), o->resolveColor(CSS PropertyBackgroundColor), style.font(), style.visibility() == VISIBLE,
535 style.display() == NONE, style.textIndent(), style.direction(), isOverri de(style.unicodeBidi())); 536 style.display() == NONE, style.textIndent(), style.direction(), isOverri de(style.unicodeBidi()));
536 } 537 }
537 538
538 LayoutUnit RenderMenuList::clientPaddingLeft() const 539 LayoutUnit LayoutMenuList::clientPaddingLeft() const
539 { 540 {
540 return paddingLeft() + m_innerBlock->paddingLeft(); 541 return paddingLeft() + m_innerBlock->paddingLeft();
541 } 542 }
542 543
543 const int endOfLinePadding = 2; 544 const int endOfLinePadding = 2;
544 LayoutUnit RenderMenuList::clientPaddingRight() const 545 LayoutUnit LayoutMenuList::clientPaddingRight() const
545 { 546 {
546 if (style()->appearance() == MenulistPart || style()->appearance() == Menuli stButtonPart) { 547 if (style()->appearance() == MenulistPart || style()->appearance() == Menuli stButtonPart) {
547 // For these appearance values, the theme applies padding to leave room for the 548 // For these appearance values, the theme applies padding to leave room for the
548 // drop-down button. But leaving room for the button inside the popup me nu itself 549 // drop-down button. But leaving room for the button inside the popup me nu itself
549 // looks strange, so we return a small default padding to avoid having a large empty 550 // looks strange, so we return a small default padding to avoid having a large empty
550 // space appear on the side of the popup menu. 551 // space appear on the side of the popup menu.
551 return endOfLinePadding; 552 return endOfLinePadding;
552 } 553 }
553 554
554 // If the appearance isn't MenulistPart, then the select is styled (non-nati ve), so 555 // If the appearance isn't MenulistPart, then the select is styled (non-nati ve), so
555 // we want to return the user specified padding. 556 // we want to return the user specified padding.
556 return paddingRight() + m_innerBlock->paddingRight(); 557 return paddingRight() + m_innerBlock->paddingRight();
557 } 558 }
558 559
559 int RenderMenuList::listSize() const 560 int LayoutMenuList::listSize() const
560 { 561 {
561 return selectElement()->listItems().size(); 562 return selectElement()->listItems().size();
562 } 563 }
563 564
564 int RenderMenuList::selectedIndex() const 565 int LayoutMenuList::selectedIndex() const
565 { 566 {
566 HTMLSelectElement* select = selectElement(); 567 HTMLSelectElement* select = selectElement();
567 return select->optionToListIndex(select->selectedIndex()); 568 return select->optionToListIndex(select->selectedIndex());
568 } 569 }
569 570
570 void RenderMenuList::popupDidHide() 571 void LayoutMenuList::popupDidHide()
571 { 572 {
572 m_popupIsVisible = false; 573 m_popupIsVisible = false;
573 } 574 }
574 575
575 bool RenderMenuList::itemIsSeparator(unsigned listIndex) const 576 bool LayoutMenuList::itemIsSeparator(unsigned listIndex) const
576 { 577 {
577 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems(); 578 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = selectE lement()->listItems();
578 return listIndex < listItems.size() && isHTMLHRElement(*listItems[listIndex] ); 579 return listIndex < listItems.size() && isHTMLHRElement(*listItems[listIndex] );
579 } 580 }
580 581
581 bool RenderMenuList::itemIsLabel(unsigned listIndex) const 582 bool LayoutMenuList::itemIsLabel(unsigned listIndex) const
582 { 583 {
583 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems(); 584 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = selectE lement()->listItems();
584 return listIndex < listItems.size() && isHTMLOptGroupElement(*listItems[list Index]); 585 return listIndex < listItems.size() && isHTMLOptGroupElement(*listItems[list Index]);
585 } 586 }
586 587
587 bool RenderMenuList::itemIsSelected(unsigned listIndex) const 588 bool LayoutMenuList::itemIsSelected(unsigned listIndex) const
588 { 589 {
589 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems(); 590 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = selectE lement()->listItems();
590 if (listIndex >= listItems.size()) 591 if (listIndex >= listItems.size())
591 return false; 592 return false;
592 HTMLElement* element = listItems[listIndex]; 593 HTMLElement* element = listItems[listIndex];
593 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select ed(); 594 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select ed();
594 } 595 }
595 596
596 void RenderMenuList::setTextFromItem(unsigned listIndex) 597 void LayoutMenuList::setTextFromItem(unsigned listIndex)
597 { 598 {
598 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); 599 setTextFromOption(selectElement()->listToOptionIndex(listIndex));
599 } 600 }
600 601
601 } // namespace blink 602 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutMenuList.h ('k') | Source/core/layout/LayoutThemeDefault.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698