| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "web/PopupMenuImpl.h" | 6 #include "web/PopupMenuImpl.h" |
| 7 | 7 |
| 8 #include "core/HTMLNames.h" | 8 #include "core/HTMLNames.h" |
| 9 #include "core/css/CSSFontSelector.h" | 9 #include "core/css/CSSFontSelector.h" |
| 10 #include "core/dom/ElementTraversal.h" | 10 #include "core/dom/ElementTraversal.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 IntRect anchorRectInScreen = m_chromeClient->viewportToScreen(m_client->elem
entRectRelativeToViewport()); | 124 IntRect anchorRectInScreen = m_chromeClient->viewportToScreen(m_client->elem
entRectRelativeToViewport()); |
| 125 | 125 |
| 126 PagePopupClient::addString("<!DOCTYPE html><head><meta charset='UTF-8'><styl
e>\n", data); | 126 PagePopupClient::addString("<!DOCTYPE html><head><meta charset='UTF-8'><styl
e>\n", data); |
| 127 data->append(Platform::current()->loadResource("pickerCommon.css")); | 127 data->append(Platform::current()->loadResource("pickerCommon.css")); |
| 128 data->append(Platform::current()->loadResource("listPicker.css")); | 128 data->append(Platform::current()->loadResource("listPicker.css")); |
| 129 PagePopupClient::addString("</style></head><body><div id=main>Loading...</di
v><script>\n" | 129 PagePopupClient::addString("</style></head><body><div id=main>Loading...</di
v><script>\n" |
| 130 "window.dialogArguments = {\n", data); | 130 "window.dialogArguments = {\n", data); |
| 131 addProperty("selectedIndex", m_client->selectedIndex(), data); | 131 addProperty("selectedIndex", m_client->selectedIndex(), data); |
| 132 PagePopupClient::addString("children: [\n", data); | 132 PagePopupClient::addString("children: [\n", data); |
| 133 bool enableExtraStyling = !hasTooManyItemsForStyling(); | 133 bool enableExtraStyling = !hasTooManyItemsForStyling(); |
| 134 int listIndex = 0; |
| 134 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(ownerElement())
) { | 135 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(ownerElement())
) { |
| 135 if (isHTMLOptionElement(child)) | 136 if (isHTMLOptionElement(child)) |
| 136 addOption(toHTMLOptionElement(child), enableExtraStyling, data); | 137 addOption(toHTMLOptionElement(child), listIndex, enableExtraStyling,
data); |
| 137 if (isHTMLOptGroupElement(child)) | 138 if (isHTMLOptGroupElement(child)) |
| 138 addOptGroup(toHTMLOptGroupElement(child), enableExtraStyling, data); | 139 addOptGroup(toHTMLOptGroupElement(child), listIndex, enableExtraStyl
ing, data); |
| 139 if (isHTMLHRElement(child)) | 140 if (isHTMLHRElement(child)) |
| 140 addSeparator(toHTMLHRElement(child), enableExtraStyling, data); | 141 addSeparator(toHTMLHRElement(child), listIndex, enableExtraStyling,
data); |
| 141 } | 142 } |
| 142 PagePopupClient::addString("],\n", data); | 143 PagePopupClient::addString("],\n", data); |
| 143 addProperty("anchorRectInScreen", anchorRectInScreen, data); | 144 addProperty("anchorRectInScreen", anchorRectInScreen, data); |
| 144 const ComputedStyle* ownerStyle = ownerElement().computedStyle(); | 145 const ComputedStyle* ownerStyle = ownerElement().computedStyle(); |
| 145 Color backgroundColor = ownerStyle->visitedDependentColor(CSSPropertyBackgro
undColor); | 146 Color backgroundColor = ownerStyle->visitedDependentColor(CSSPropertyBackgro
undColor); |
| 146 #if OS(LINUX) | 147 #if OS(LINUX) |
| 147 // On other platforms, the <option> background color is the same as the | 148 // On other platforms, the <option> background color is the same as the |
| 148 // <select> background color. On Linux, that makes the <option> | 149 // <select> background color. On Linux, that makes the <option> |
| 149 // background color very dark, so by default, try to use a lighter | 150 // background color very dark, so by default, try to use a lighter |
| 150 // background color for <option>s. | 151 // background color for <option>s. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 PagePopupClient::addString(",\n", data); | 256 PagePopupClient::addString(",\n", data); |
| 256 } | 257 } |
| 257 PagePopupClient::addString("],\n", data); | 258 PagePopupClient::addString("],\n", data); |
| 258 addProperty("fontStyle", String(fontStyleToString(fontDescription.style(
))), data); | 259 addProperty("fontStyle", String(fontStyleToString(fontDescription.style(
))), data); |
| 259 addProperty("fontVariant", String(fontVariantToString(fontDescription.va
riant())), data); | 260 addProperty("fontVariant", String(fontVariantToString(fontDescription.va
riant())), data); |
| 260 addProperty("textTransform", String(textTransformToString(style->textTra
nsform())), data); | 261 addProperty("textTransform", String(textTransformToString(style->textTra
nsform())), data); |
| 261 } | 262 } |
| 262 PagePopupClient::addString("},\n", data); | 263 PagePopupClient::addString("},\n", data); |
| 263 } | 264 } |
| 264 | 265 |
| 265 void PopupMenuImpl::addOption(HTMLOptionElement& element, bool enableExtraStylin
g, SharedBuffer* data) | 266 void PopupMenuImpl::addOption(HTMLOptionElement& element, int& listIndex, bool e
nableExtraStyling, SharedBuffer* data) |
| 266 { | 267 { |
| 267 PagePopupClient::addString("{\n", data); | 268 PagePopupClient::addString("{\n", data); |
| 268 PagePopupClient::addString("type: \"option\",\n", data); | 269 PagePopupClient::addString("type: \"option\",\n", data); |
| 269 addProperty("label", element.text(), data); | 270 addProperty("label", element.text(), data); |
| 270 addProperty("title", element.title(), data); | 271 addProperty("title", element.title(), data); |
| 271 addProperty("value", element.listIndex(), data); | 272 ASSERT(listIndex == element.listIndex()); |
| 273 addProperty("value", listIndex++, data); |
| 272 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); | 274 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); |
| 273 addProperty("disabled", element.isDisabledFormControl(), data); | 275 addProperty("disabled", element.isDisabledFormControl(), data); |
| 274 addElementStyle(element, enableExtraStyling, data); | 276 addElementStyle(element, enableExtraStyling, data); |
| 275 PagePopupClient::addString("},\n", data); | 277 PagePopupClient::addString("},\n", data); |
| 276 } | 278 } |
| 277 | 279 |
| 278 void PopupMenuImpl::addOptGroup(HTMLOptGroupElement& element, bool enableExtraSt
yling, SharedBuffer* data) | 280 void PopupMenuImpl::addOptGroup(HTMLOptGroupElement& element, int& listIndex, bo
ol enableExtraStyling, SharedBuffer* data) |
| 279 { | 281 { |
| 282 ++listIndex; |
| 280 PagePopupClient::addString("{\n", data); | 283 PagePopupClient::addString("{\n", data); |
| 281 PagePopupClient::addString("type: \"optgroup\",\n", data); | 284 PagePopupClient::addString("type: \"optgroup\",\n", data); |
| 282 addProperty("label", element.groupLabelText(), data); | 285 addProperty("label", element.groupLabelText(), data); |
| 283 addProperty("title", element.title(), data); | 286 addProperty("title", element.title(), data); |
| 284 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); | 287 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); |
| 285 addProperty("disabled", element.isDisabledFormControl(), data); | 288 addProperty("disabled", element.isDisabledFormControl(), data); |
| 286 addElementStyle(element, enableExtraStyling, data); | 289 addElementStyle(element, enableExtraStyling, data); |
| 287 PagePopupClient::addString("children: [", data); | 290 PagePopupClient::addString("children: [", data); |
| 288 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(element)) { | 291 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(element)) { |
| 289 if (isHTMLOptionElement(child)) | 292 if (isHTMLOptionElement(child)) |
| 290 addOption(toHTMLOptionElement(child), enableExtraStyling, data); | 293 addOption(toHTMLOptionElement(child), listIndex, enableExtraStyling,
data); |
| 294 // TODO(tkent): Ignore nested OPTGROUP. crbug.com/502101. |
| 291 if (isHTMLOptGroupElement(child)) | 295 if (isHTMLOptGroupElement(child)) |
| 292 addOptGroup(toHTMLOptGroupElement(child), enableExtraStyling, data); | 296 addOptGroup(toHTMLOptGroupElement(child), listIndex, enableExtraStyl
ing, data); |
| 293 if (isHTMLHRElement(child)) | 297 if (isHTMLHRElement(child)) |
| 294 addSeparator(toHTMLHRElement(child), enableExtraStyling, data); | 298 addSeparator(toHTMLHRElement(child), listIndex, enableExtraStyling,
data); |
| 295 } | 299 } |
| 296 PagePopupClient::addString("],\n", data); | 300 PagePopupClient::addString("],\n", data); |
| 297 PagePopupClient::addString("},\n", data); | 301 PagePopupClient::addString("},\n", data); |
| 298 } | 302 } |
| 299 | 303 |
| 300 void PopupMenuImpl::addSeparator(HTMLHRElement& element, bool enableExtraStyling
, SharedBuffer* data) | 304 void PopupMenuImpl::addSeparator(HTMLHRElement& element, int& listIndex, bool en
ableExtraStyling, SharedBuffer* data) |
| 301 { | 305 { |
| 306 ++listIndex; |
| 302 PagePopupClient::addString("{\n", data); | 307 PagePopupClient::addString("{\n", data); |
| 303 PagePopupClient::addString("type: \"separator\",\n", data); | 308 PagePopupClient::addString("type: \"separator\",\n", data); |
| 304 addProperty("title", element.title(), data); | 309 addProperty("title", element.title(), data); |
| 305 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); | 310 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); |
| 306 addProperty("disabled", element.isDisabledFormControl(), data); | 311 addProperty("disabled", element.isDisabledFormControl(), data); |
| 307 addElementStyle(element, enableExtraStyling, data); | 312 addElementStyle(element, enableExtraStyling, data); |
| 308 PagePopupClient::addString("},\n", data); | 313 PagePopupClient::addString("},\n", data); |
| 309 } | 314 } |
| 310 | 315 |
| 311 void PopupMenuImpl::selectFontsFromOwnerDocument(Document& document) | 316 void PopupMenuImpl::selectFontsFromOwnerDocument(Document& document) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 return; | 409 return; |
| 405 ownerElement().document().updateLayoutTreeIfNeeded(); | 410 ownerElement().document().updateLayoutTreeIfNeeded(); |
| 406 if (!m_client) | 411 if (!m_client) |
| 407 return; | 412 return; |
| 408 m_needsUpdate = false; | 413 m_needsUpdate = false; |
| 409 RefPtr<SharedBuffer> data = SharedBuffer::create(); | 414 RefPtr<SharedBuffer> data = SharedBuffer::create(); |
| 410 PagePopupClient::addString("window.updateData = {\n", data.get()); | 415 PagePopupClient::addString("window.updateData = {\n", data.get()); |
| 411 PagePopupClient::addString("type: \"update\",\n", data.get()); | 416 PagePopupClient::addString("type: \"update\",\n", data.get()); |
| 412 PagePopupClient::addString("children: [", data.get()); | 417 PagePopupClient::addString("children: [", data.get()); |
| 413 bool enableExtraStyling = !hasTooManyItemsForStyling(); | 418 bool enableExtraStyling = !hasTooManyItemsForStyling(); |
| 419 int listIndex = 0; |
| 414 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(ownerElement())
) { | 420 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(ownerElement())
) { |
| 415 if (isHTMLOptionElement(child)) | 421 if (isHTMLOptionElement(child)) |
| 416 addOption(toHTMLOptionElement(child), enableExtraStyling, data.get()
); | 422 addOption(toHTMLOptionElement(child), listIndex, enableExtraStyling,
data.get()); |
| 417 if (isHTMLOptGroupElement(child)) | 423 if (isHTMLOptGroupElement(child)) |
| 418 addOptGroup(toHTMLOptGroupElement(child), enableExtraStyling, data.g
et()); | 424 addOptGroup(toHTMLOptGroupElement(child), listIndex, enableExtraStyl
ing, data.get()); |
| 419 if (isHTMLHRElement(child)) | 425 if (isHTMLHRElement(child)) |
| 420 addSeparator(toHTMLHRElement(child), enableExtraStyling, data.get())
; | 426 addSeparator(toHTMLHRElement(child), listIndex, enableExtraStyling,
data.get()); |
| 421 } | 427 } |
| 422 PagePopupClient::addString("],\n", data.get()); | 428 PagePopupClient::addString("],\n", data.get()); |
| 423 PagePopupClient::addString("}\n", data.get()); | 429 PagePopupClient::addString("}\n", data.get()); |
| 424 m_popup->postMessage(String::fromUTF8(data->data(), data->size())); | 430 m_popup->postMessage(String::fromUTF8(data->data(), data->size())); |
| 425 } | 431 } |
| 426 | 432 |
| 427 | 433 |
| 428 void PopupMenuImpl::disconnectClient() | 434 void PopupMenuImpl::disconnectClient() |
| 429 { | 435 { |
| 430 m_client = nullptr; | 436 m_client = nullptr; |
| 431 // Cannot be done during finalization, so instead done when the | 437 // Cannot be done during finalization, so instead done when the |
| 432 // layout object is destroyed and disconnected. | 438 // layout object is destroyed and disconnected. |
| 433 dispose(); | 439 dispose(); |
| 434 } | 440 } |
| 435 | 441 |
| 436 } // namespace blink | 442 } // namespace blink |
| OLD | NEW |