/* * Copyright (C) 2012 Research In Motion Limited. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "config.h" #include "SelectPopupClient.h" #include "HTMLOptionElement.h" #include "HTMLSelectElement.h" #include "PopupPicker.h" #include "RenderObject.h" #include "WebPage_p.h" #include #include #include #include using namespace WebCore; namespace BlackBerry { namespace WebKit { DEFINE_STATIC_LOCAL(BlackBerry::Platform::LocalizeResource, s_resource, ()); SelectPopupClient::SelectPopupClient(bool multiple, int size, const ScopeArray& labels, bool* enableds, const int* itemType, bool* selecteds, WebPagePrivate* webPagePrivate, HTMLSelectElement* element) : PagePopupClient(webPagePrivate) , m_multiple(multiple) , m_size(size) , m_element(element) , m_notifyChangeTimer(this, &SelectPopupClient::notifySelectionChange) { generateHTML(multiple, size, labels, enableds, itemType, selecteds); } SelectPopupClient::~SelectPopupClient() { } void SelectPopupClient::generateHTML(bool, int size, const ScopeArray& labels, bool* enableds, const int* itemType, bool* selecteds) { StringBuilder source; source.appendLiteral("\n\n"); source.appendLiteral("\n \n"); m_source = source.toString(); } void SelectPopupClient::setValueAndClosePopup(const String& stringValue) { // Popup closed. if (!m_element) return; static const char* cancelValue = "-1"; if (stringValue == cancelValue) { closePopup(); return; } if (m_size > 0) { bool selecteds[m_size]; for (unsigned i = 0; i < m_size; i++) selecteds[i] = stringValue[i] - '0'; const Vector& items = m_element->listItems(); // If element changed after select UI showed, do nothing but closePopup(). if (items.size() != static_cast(m_size)) { closePopup(); return; } HTMLOptionElement* option; for (unsigned i = 0; i < m_size; i++) { if (isHTMLOptionElement(items[i])) { option = toHTMLOptionElement(items[i]); option->setSelectedState(selecteds[i]); } } } // Force repaint because we do not send mouse events to the select element // and the element doesn't automatically repaint itself. if (m_element->renderer()) m_element->renderer()->repaint(); m_notifyChangeTimer.startOneShot(0); } void SelectPopupClient::didClosePopup() { PagePopupClient::didClosePopup(); m_element = 0; } void SelectPopupClient::notifySelectionChange(WebCore::Timer*) { if (m_element) m_element->dispatchFormControlChangeEvent(); closePopup(); } } }