diff options
Diffstat (limited to 'WebCore')
-rw-r--r-- | WebCore/Android.mk | 1 | ||||
-rw-r--r-- | WebCore/platform/android/PopupMenuAndroid.cpp | 101 | ||||
-rw-r--r-- | WebCore/platform/android/PopupMenuAndroid.h | 6 | ||||
-rw-r--r-- | WebCore/platform/android/SearchPopupMenuAndroid.h | 17 |
4 files changed, 104 insertions, 21 deletions
diff --git a/WebCore/Android.mk b/WebCore/Android.mk index 85ac7ee..fda5318 100644 --- a/WebCore/Android.mk +++ b/WebCore/Android.mk @@ -542,6 +542,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ platform/android/LocalizedStringsAndroid.cpp \ platform/android/PlatformTouchEventAndroid.cpp \ platform/android/PlatformTouchPointAndroid.cpp \ + platform/android/PopupMenuAndroid.cpp \ platform/android/RenderThemeAndroid.cpp \ platform/android/PackageNotifier.cpp \ platform/android/ScreenAndroid.cpp \ diff --git a/WebCore/platform/android/PopupMenuAndroid.cpp b/WebCore/platform/android/PopupMenuAndroid.cpp index 8a1ed07..3e36ea4 100644 --- a/WebCore/platform/android/PopupMenuAndroid.cpp +++ b/WebCore/platform/android/PopupMenuAndroid.cpp @@ -23,35 +23,104 @@ */ #include "config.h" -#include "PopupMenu.h" +#include "PopupMenuAndroid.h" + +#include "PopupMenuClient.h" +#include "SkTDArray.h" +#include "WebViewCore.h" + +class PopupReply : public android::WebCoreReply { +public: + PopupReply(const IntRect& rect, android::WebViewCore* view, PopupMenuClient* client) + : m_rect(rect) + , m_viewImpl(view) + , m_popupClient(client) + {} + + virtual ~PopupReply() {} + + virtual void replyInt(int value) { + if (m_popupClient) { + m_popupClient->popupDidHide(); + m_popupClient->valueChanged(value, true); + } + if (m_viewImpl) + m_viewImpl->contentInvalidate(m_rect); + } + + virtual void replyIntArray(const int* array, int count) { + // Should never be called. + } +private: + IntRect m_rect; + // Not needed if we handle ChromeClientAndroid::formStateDidChange + android::WebViewCore* m_viewImpl; + PopupMenuClient* m_popupClient; +}; namespace WebCore { -// Now we handle all of this in WebViewCore.cpp. -PopupMenu::PopupMenu(PopupMenuClient* menuList) +PopupMenuAndroid::PopupMenuAndroid(PopupMenuClient* menuList) : m_popupClient(menuList) { } -PopupMenu::~PopupMenu() -{ -} - -void PopupMenu::show(const IntRect&, FrameView*, int) +// Copied from WebViewCore.cpp. Once we move ListBox handling to this class, +// we can remove the one in WebViewCore.cpp. +// Convert a WTF::String into an array of characters where the first +// character represents the length, for easy conversion to java. +static uint16_t* stringConverter(const WTF::String& text) { + size_t length = text.length(); + uint16_t* itemName = new uint16_t[length+1]; + itemName[0] = (uint16_t)length; + uint16_t* firstChar = &(itemName[1]); + memcpy((void*)firstChar, text.characters(), sizeof(UChar)*length); + return itemName; } -void PopupMenu::hide() +void PopupMenuAndroid::show(const IntRect& rect, FrameView* frameView, int) { -} + android::WebViewCore* viewImpl = android::WebViewCore::getWebViewCore(frameView); + android::WebCoreReply* reply = new PopupReply(rect, viewImpl, m_popupClient); -void PopupMenu::updateFromElement() -{ -} + SkTDArray<const uint16_t*> names; + // Possible values for enabledArray. Keep in Sync with values in + // InvokeListBox.Container in WebView.java + enum OptionStatus { + OPTGROUP = -1, + OPTION_DISABLED = 0, + OPTION_ENABLED = 1, + }; + SkTDArray<int> enabledArray; + SkTDArray<int> selectedArray; + int size = m_popupClient->listSize(); + // If we use this for ListBoxes in addition to MenuLists, we will need to + // account for 'multiple' + bool multiple = false; + for (int i = 0; i < size; i++) { + *names.append() = stringConverter(m_popupClient->itemText(i)); + if (m_popupClient->itemIsSeparator(i)) { + *enabledArray.append() = OPTION_DISABLED; + } else if (m_popupClient->itemIsLabel(i)) { + *enabledArray.append() = OPTGROUP; + } else { + // Must be an Option + *enabledArray.append() = m_popupClient->itemIsEnabled(i) + ? OPTION_ENABLED : OPTION_DISABLED; + if (multiple && m_popupClient->itemIsSelected(i)) + *selectedArray.append() = i; + } + } -bool PopupMenu::itemWritingDirectionIsNatural() -{ - return false; + viewImpl->listBoxRequest(reply, + names.begin(), + size, + enabledArray.begin(), + enabledArray.count(), + multiple, + selectedArray.begin(), + multiple ? selectedArray.count() : m_popupClient->selectedIndex()); } } // namespace WebCore diff --git a/WebCore/platform/android/PopupMenuAndroid.h b/WebCore/platform/android/PopupMenuAndroid.h index 07b1da0..a0a2452 100644 --- a/WebCore/platform/android/PopupMenuAndroid.h +++ b/WebCore/platform/android/PopupMenuAndroid.h @@ -32,13 +32,17 @@ namespace WebCore { class FrameView; +class PopupMenuClient; class PopupMenuAndroid : public PopupMenu { public: - virtual void show(const IntRect&, FrameView*, int) { } + PopupMenuAndroid(PopupMenuClient* client); + virtual void show(const IntRect&, FrameView*, int); virtual void hide() { } virtual void updateFromElement() { } virtual void disconnectClient() { } +private: + PopupMenuClient* m_popupClient; }; } diff --git a/WebCore/platform/android/SearchPopupMenuAndroid.h b/WebCore/platform/android/SearchPopupMenuAndroid.h index 599a2ac..4a7dedb 100644 --- a/WebCore/platform/android/SearchPopupMenuAndroid.h +++ b/WebCore/platform/android/SearchPopupMenuAndroid.h @@ -26,24 +26,33 @@ #ifndef SearchPopupMenuAndroid_h #define SearchPopupMenuAndroid_h -#include "PopupMenuAndroid.h" #include "SearchPopupMenu.h" namespace WebCore { -class PopupMenuClient; +class IntRect; +class PopupMenu; class FrameView; +class DummyPopup : public PopupMenu { + public: + virtual ~DummyPopup() {} + virtual void show(const IntRect&, FrameView*, int index) { } + virtual void hide() { } + virtual void updateFromElement() { } + virtual void disconnectClient() { } +}; + class SearchPopupMenuAndroid : public SearchPopupMenu { public: - SearchPopupMenuAndroid() : m_popup(adoptRef(new PopupMenuAndroid)) { } + SearchPopupMenuAndroid() : m_popup(adoptRef(new DummyPopup)) { } virtual PopupMenu* popupMenu() { return m_popup.get(); } virtual void saveRecentSearches(const AtomicString&, const Vector<String>&) { } virtual void loadRecentSearches(const AtomicString&, Vector<String>&) { } virtual bool enabled() { return false; } private: - RefPtr<PopupMenuAndroid> m_popup; + RefPtr<PopupMenu> m_popup; }; } |