| 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" |
| 11 #include "core/dom/ExecutionContextTask.h" | 11 #include "core/dom/ExecutionContextTask.h" |
| 12 #include "core/dom/NodeComputedStyle.h" | 12 #include "core/dom/NodeComputedStyle.h" |
| 13 #include "core/dom/StyleEngine.h" | 13 #include "core/dom/StyleEngine.h" |
| 14 #include "core/frame/FrameView.h" | 14 #include "core/frame/FrameView.h" |
| 15 #include "core/html/HTMLHRElement.h" | 15 #include "core/html/HTMLHRElement.h" |
| 16 #include "core/html/HTMLOptGroupElement.h" | 16 #include "core/html/HTMLOptGroupElement.h" |
| 17 #include "core/html/HTMLOptionElement.h" | 17 #include "core/html/HTMLOptionElement.h" |
| 18 #include "core/html/HTMLSelectElement.h" |
| 18 #include "core/html/parser/HTMLParserIdioms.h" | 19 #include "core/html/parser/HTMLParserIdioms.h" |
| 19 #include "core/layout/LayoutTheme.h" | 20 #include "core/layout/LayoutTheme.h" |
| 20 #include "core/page/PagePopup.h" | 21 #include "core/page/PagePopup.h" |
| 21 #include "platform/geometry/IntRect.h" | 22 #include "platform/geometry/IntRect.h" |
| 22 #include "platform/text/PlatformLocale.h" | 23 #include "platform/text/PlatformLocale.h" |
| 23 #include "public/platform/Platform.h" | 24 #include "public/platform/Platform.h" |
| 24 #include "public/web/WebColorChooser.h" | 25 #include "public/web/WebColorChooser.h" |
| 25 #include "web/ChromeClientImpl.h" | 26 #include "web/ChromeClientImpl.h" |
| 26 #include "web/WebViewImpl.h" | 27 #include "web/WebViewImpl.h" |
| 27 | 28 |
| 28 namespace blink { | 29 namespace blink { |
| 29 | 30 |
| 30 // We don't make child style information if the popup will have a lot of items | |
| 31 // because of a performance problem. | |
| 32 // TODO(tkent): This is a workaround. We should do a performance optimization. | |
| 33 static const unsigned styledChildrenLimit = 100; | |
| 34 | |
| 35 class PopupMenuCSSFontSelector : public CSSFontSelector { | 31 class PopupMenuCSSFontSelector : public CSSFontSelector { |
| 36 public: | 32 public: |
| 37 static PassRefPtrWillBeRawPtr<PopupMenuCSSFontSelector> create(Document* doc
ument, CSSFontSelector* ownerFontSelector) | 33 static PassRefPtrWillBeRawPtr<PopupMenuCSSFontSelector> create(Document* doc
ument, CSSFontSelector* ownerFontSelector) |
| 38 { | 34 { |
| 39 return adoptRefWillBeNoop(new PopupMenuCSSFontSelector(document, ownerFo
ntSelector)); | 35 return adoptRefWillBeNoop(new PopupMenuCSSFontSelector(document, ownerFo
ntSelector)); |
| 40 } | 36 } |
| 41 | 37 |
| 42 // We don't override willUseFontData() for now because the old PopupListBox | 38 // We don't override willUseFontData() for now because the old PopupListBox |
| 43 // only worked with fonts loaded when opening the popup. | 39 // only worked with fonts loaded when opening the popup. |
| 44 virtual PassRefPtr<FontData> getFontData(const FontDescription&, const Atomi
cString&) override; | 40 virtual PassRefPtr<FontData> getFontData(const FontDescription&, const Atomi
cString&) override; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 PopupMenuImpl::~PopupMenuImpl() | 77 PopupMenuImpl::~PopupMenuImpl() |
| 82 { | 78 { |
| 83 ASSERT(!m_popup); | 79 ASSERT(!m_popup); |
| 84 } | 80 } |
| 85 | 81 |
| 86 IntSize PopupMenuImpl::contentSize() | 82 IntSize PopupMenuImpl::contentSize() |
| 87 { | 83 { |
| 88 return IntSize(); | 84 return IntSize(); |
| 89 } | 85 } |
| 90 | 86 |
| 87 // We don't make child style information if the popup will have a lot of items |
| 88 // because of a performance problem. |
| 89 // TODO(tkent): This is a workaround. We should do a performance optimization. |
| 90 bool PopupMenuImpl::hasTooManyItemsForStyling() |
| 91 { |
| 92 // 300 is enough for world-wide countries. |
| 93 const unsigned styledChildrenLimit = 300; |
| 94 |
| 95 if (!isHTMLSelectElement(ownerElement())) |
| 96 return false; |
| 97 return toHTMLSelectElement(ownerElement()).listItems().size() > styledChildr
enLimit; |
| 98 } |
| 99 |
| 91 void PopupMenuImpl::writeDocument(SharedBuffer* data) | 100 void PopupMenuImpl::writeDocument(SharedBuffer* data) |
| 92 { | 101 { |
| 93 IntRect anchorRectInScreen = m_chromeClient->viewportToScreen(m_client->elem
entRectRelativeToViewport()); | 102 IntRect anchorRectInScreen = m_chromeClient->viewportToScreen(m_client->elem
entRectRelativeToViewport()); |
| 94 | 103 |
| 95 PagePopupClient::addString("<!DOCTYPE html><head><meta charset='UTF-8'><styl
e>\n", data); | 104 PagePopupClient::addString("<!DOCTYPE html><head><meta charset='UTF-8'><styl
e>\n", data); |
| 96 data->append(Platform::current()->loadResource("pickerCommon.css")); | 105 data->append(Platform::current()->loadResource("pickerCommon.css")); |
| 97 data->append(Platform::current()->loadResource("listPicker.css")); | 106 data->append(Platform::current()->loadResource("listPicker.css")); |
| 98 PagePopupClient::addString("</style></head><body><div id=main>Loading...</di
v><script>\n" | 107 PagePopupClient::addString("</style></head><body><div id=main>Loading...</di
v><script>\n" |
| 99 "window.dialogArguments = {\n", data); | 108 "window.dialogArguments = {\n", data); |
| 100 addProperty("selectedIndex", m_client->selectedIndex(), data); | 109 addProperty("selectedIndex", m_client->selectedIndex(), data); |
| 101 PagePopupClient::addString("children: [\n", data); | 110 PagePopupClient::addString("children: [\n", data); |
| 102 bool enableExtraStyling = ownerElement().countChildren() < styledChildrenLim
it; | 111 bool enableExtraStyling = !hasTooManyItemsForStyling(); |
| 103 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(ownerElement())
) { | 112 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(ownerElement())
) { |
| 104 if (isHTMLOptionElement(child)) | 113 if (isHTMLOptionElement(child)) |
| 105 addOption(toHTMLOptionElement(child), enableExtraStyling, data); | 114 addOption(toHTMLOptionElement(child), enableExtraStyling, data); |
| 106 if (isHTMLOptGroupElement(child)) | 115 if (isHTMLOptGroupElement(child)) |
| 107 addOptGroup(toHTMLOptGroupElement(child), enableExtraStyling, data); | 116 addOptGroup(toHTMLOptGroupElement(child), enableExtraStyling, data); |
| 108 if (isHTMLHRElement(child)) | 117 if (isHTMLHRElement(child)) |
| 109 addSeparator(toHTMLHRElement(child), enableExtraStyling, data); | 118 addSeparator(toHTMLHRElement(child), enableExtraStyling, data); |
| 110 } | 119 } |
| 111 PagePopupClient::addString("],\n", data); | 120 PagePopupClient::addString("],\n", data); |
| 112 addProperty("anchorRectInScreen", anchorRectInScreen, data); | 121 addProperty("anchorRectInScreen", anchorRectInScreen, data); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 if (!m_popup || !m_client) | 381 if (!m_popup || !m_client) |
| 373 return; | 382 return; |
| 374 ownerElement().document().updateLayoutTreeIfNeeded(); | 383 ownerElement().document().updateLayoutTreeIfNeeded(); |
| 375 if (!m_client) | 384 if (!m_client) |
| 376 return; | 385 return; |
| 377 m_needsUpdate = false; | 386 m_needsUpdate = false; |
| 378 RefPtr<SharedBuffer> data = SharedBuffer::create(); | 387 RefPtr<SharedBuffer> data = SharedBuffer::create(); |
| 379 PagePopupClient::addString("window.updateData = {\n", data.get()); | 388 PagePopupClient::addString("window.updateData = {\n", data.get()); |
| 380 PagePopupClient::addString("type: \"update\",\n", data.get()); | 389 PagePopupClient::addString("type: \"update\",\n", data.get()); |
| 381 PagePopupClient::addString("children: [", data.get()); | 390 PagePopupClient::addString("children: [", data.get()); |
| 382 bool enableExtraStyling = ownerElement().countChildren() < styledChildrenLim
it; | 391 bool enableExtraStyling = !hasTooManyItemsForStyling(); |
| 383 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(ownerElement())
) { | 392 for (HTMLElement& child : Traversal<HTMLElement>::childrenOf(ownerElement())
) { |
| 384 if (isHTMLOptionElement(child)) | 393 if (isHTMLOptionElement(child)) |
| 385 addOption(toHTMLOptionElement(child), enableExtraStyling, data.get()
); | 394 addOption(toHTMLOptionElement(child), enableExtraStyling, data.get()
); |
| 386 if (isHTMLOptGroupElement(child)) | 395 if (isHTMLOptGroupElement(child)) |
| 387 addOptGroup(toHTMLOptGroupElement(child), enableExtraStyling, data.g
et()); | 396 addOptGroup(toHTMLOptGroupElement(child), enableExtraStyling, data.g
et()); |
| 388 if (isHTMLHRElement(child)) | 397 if (isHTMLHRElement(child)) |
| 389 addSeparator(toHTMLHRElement(child), enableExtraStyling, data.get())
; | 398 addSeparator(toHTMLHRElement(child), enableExtraStyling, data.get())
; |
| 390 } | 399 } |
| 391 PagePopupClient::addString("],\n", data.get()); | 400 PagePopupClient::addString("],\n", data.get()); |
| 392 PagePopupClient::addString("}\n", data.get()); | 401 PagePopupClient::addString("}\n", data.get()); |
| 393 m_popup->postMessage(String::fromUTF8(data->data(), data->size())); | 402 m_popup->postMessage(String::fromUTF8(data->data(), data->size())); |
| 394 } | 403 } |
| 395 | 404 |
| 396 | 405 |
| 397 void PopupMenuImpl::disconnectClient() | 406 void PopupMenuImpl::disconnectClient() |
| 398 { | 407 { |
| 399 m_client = nullptr; | 408 m_client = nullptr; |
| 400 // Cannot be done during finalization, so instead done when the | 409 // Cannot be done during finalization, so instead done when the |
| 401 // layout object is destroyed and disconnected. | 410 // layout object is destroyed and disconnected. |
| 402 dispose(); | 411 dispose(); |
| 403 } | 412 } |
| 404 | 413 |
| 405 } // namespace blink | 414 } // namespace blink |
| OLD | NEW |