2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
3 * Copyright (C) 2010 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
23 #include "WebPopupMenu.h"
25 #include "PlatformPopupMenuData.h"
26 #include "WebCoreArgumentCoders.h"
28 #include "WebPageProxyMessages.h"
29 #include "WebProcess.h"
30 #include <WebCore/FrameView.h>
31 #include <WebCore/PopupMenuClient.h>
33 #if ENABLE(TIZEN_LINK_EFFECT)
34 #include <WebCore/TizenLinkEffect.h>
37 using namespace WebCore;
41 PassRefPtr<WebPopupMenu> WebPopupMenu::create(WebPage* page, PopupMenuClient* client)
43 return adoptRef(new WebPopupMenu(page, client));
46 WebPopupMenu::WebPopupMenu(WebPage* page, PopupMenuClient* client)
47 : m_popupClient(client)
52 WebPopupMenu::~WebPopupMenu()
56 void WebPopupMenu::disconnectClient()
58 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
61 // Check whether it is valid on other platform
67 void WebPopupMenu::didChangeSelectedIndex(int newIndex)
74 m_popupClient->listBoxSelectItem(newIndex, m_popupClient->multiple(), false);
76 #if ENABLE(TIZEN_MULTIPLE_SELECT)
77 TIZEN_LOGI("multiple:%d, newIndex:%d", m_popupClient->multiple(), newIndex);
78 if (m_popupClient->multiple()){
80 m_popupClient->listBoxSelectItem(newIndex, m_popupClient->multiple(), false);
84 m_popupClient->popupDidHide();
86 m_popupClient->valueChanged(newIndex);
90 void WebPopupMenu::setTextForIndex(int index)
95 m_popupClient->setTextFromItem(index);
98 Vector<WebPopupItem> WebPopupMenu::populateItems()
100 size_t size = m_popupClient->listSize();
101 TIZEN_LOGI("size:%d", size);
103 Vector<WebPopupItem> items;
104 items.reserveInitialCapacity(size);
106 for (size_t i = 0; i < size; ++i) {
107 if (m_popupClient->itemIsSeparator(i))
108 items.append(WebPopupItem(WebPopupItem::Separator));
110 // FIXME: Add support for styling the font.
111 // FIXME: Add support for styling the foreground and background colors.
112 // FIXME: Find a way to customize text color when an item is highlighted.
113 PopupMenuStyle itemStyle = m_popupClient->itemStyle(i);
114 items.append(WebPopupItem(WebPopupItem::Item, m_popupClient->itemText(i), itemStyle.textDirection(), itemStyle.hasTextDirectionOverride(), m_popupClient->itemToolTip(i), m_popupClient->itemAccessibilityText(i), m_popupClient->itemIsEnabled(i), m_popupClient->itemIsLabel(i), m_popupClient->itemIsSelected(i)));
121 void WebPopupMenu::show(const IntRect& rect, FrameView* view, int index)
123 #if ENABLE(TIZEN_LINK_EFFECT)
124 TizenLinkEffect::playLinkEffect();
127 // FIXME: We should probably inform the client to also close the menu.
128 Vector<WebPopupItem> items = populateItems();
130 if (items.isEmpty() || !m_page) {
131 m_popupClient->popupDidHide();
135 m_page->setActivePopupMenu(this);
137 // Move to page coordinates
138 IntRect pageCoordinates(view->contentsToWindow(rect.location()), rect.size());
140 PlatformPopupMenuData platformData;
141 setUpPlatformData(pageCoordinates, platformData);
143 WebProcess::shared().connection()->send(Messages::WebPageProxy::ShowPopupMenu(pageCoordinates, m_popupClient->menuStyle().textDirection(), items, index, platformData), m_page->pageID());
146 void WebPopupMenu::hide()
149 if (!m_page || !m_popupClient)
152 WebProcess::shared().connection()->send(Messages::WebPageProxy::HidePopupMenu(), m_page->pageID());
153 #if ENABLE(TIZEN_WEBKIT2_POPUP)
154 m_popupClient->popupDidHide();
156 m_page->setActivePopupMenu(0);
159 void WebPopupMenu::updateFromElement()
162 if (!m_page || !m_popupClient)
165 int selectedIndex = m_popupClient->selectedIndex();
166 WebProcess::shared().connection()->send(Messages::WebPageProxy::SetPopupMenuSelectedIndex(selectedIndex), m_page->pageID());
169 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
171 if (!m_page || !m_popupClient)
174 Vector<WebPopupItem> items = populateItems();
175 if (items.isEmpty()) {
176 WebProcess::shared().connection()->send(Messages::WebPageProxy::HidePopupMenu(), m_page->pageID());
177 m_popupClient->popupDidHide();
181 WebProcess::shared().connection()->send(Messages::WebPageProxy::UpdatePopupMenu(m_popupClient->menuStyle().textDirection(), items, m_popupClient->selectedIndex()), m_page->pageID());
185 } // namespace WebKit