diff options
author | Leon Scroggins <scroggo@google.com> | 2011-02-01 17:15:19 -0500 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2011-02-03 10:28:58 -0500 |
commit | 82160d9cd33152498ed3f4e701e713c15e50d7e5 (patch) | |
tree | 6393fcdc9e967b4df9e30a05b0689f4d304bfb93 /WebCore | |
parent | a5bca47a4e69875e8de101751842c94b7ec9803c (diff) | |
download | external_webkit-82160d9cd33152498ed3f4e701e713c15e50d7e5.zip external_webkit-82160d9cd33152498ed3f4e701e713c15e50d7e5.tar.gz external_webkit-82160d9cd33152498ed3f4e701e713c15e50d7e5.tar.bz2 |
Use ListBoxPopupMenuClient for listboxes.
Bug:2754767
Enables us to remove some layering violations.
Change-Id: Iea184c7946bca9d840c708918f545a9d9b436254
Diffstat (limited to 'WebCore')
-rw-r--r-- | WebCore/config.h | 2 | ||||
-rw-r--r-- | WebCore/html/HTMLOptionElement.h | 12 | ||||
-rw-r--r-- | WebCore/platform/android/PopupMenuAndroid.cpp | 33 | ||||
-rw-r--r-- | WebCore/platform/android/PopupMenuAndroid.h | 6 | ||||
-rw-r--r-- | WebCore/platform/android/RenderThemeAndroid.cpp | 77 | ||||
-rw-r--r-- | WebCore/rendering/RenderTheme.cpp | 2 | ||||
-rw-r--r-- | WebCore/rendering/RenderTheme.h | 2 |
7 files changed, 41 insertions, 93 deletions
diff --git a/WebCore/config.h b/WebCore/config.h index 7174c4b..6117fef 100644 --- a/WebCore/config.h +++ b/WebCore/config.h @@ -160,7 +160,7 @@ #define ANDROID_META_SUPPORT // Converts ListBoxes to dropdown popup lists. -#define ANDROID_LISTBOX_USES_MENU_LIST +#define ENABLE_NO_LISTBOX_RENDERING 1 #define ANDROID_MULTIPLE_WINDOWS #define ANDROID_CSS_RING diff --git a/WebCore/html/HTMLOptionElement.h b/WebCore/html/HTMLOptionElement.h index deac66a..c1791d7 100644 --- a/WebCore/html/HTMLOptionElement.h +++ b/WebCore/html/HTMLOptionElement.h @@ -27,13 +27,6 @@ #include "HTMLFormControlElement.h" #include "OptionElement.h" -#if PLATFORM(ANDROID) -namespace android { -class WebViewCore; -class ListBoxReply; -}; -#endif - namespace WebCore { class HTMLSelectElement; @@ -41,11 +34,6 @@ class HTMLSelectElement; class HTMLOptionElement : public HTMLFormControlElement, public OptionElement { friend class HTMLSelectElement; friend class RenderMenuList; -#if PLATFORM(ANDROID) - friend class RenderThemeAndroid; - friend class android::WebViewCore; - friend class android::ListBoxReply; -#endif public: static PassRefPtr<HTMLOptionElement> create(Document*, HTMLFormElement*); diff --git a/WebCore/platform/android/PopupMenuAndroid.cpp b/WebCore/platform/android/PopupMenuAndroid.cpp index 2bae724..f4c351f 100644 --- a/WebCore/platform/android/PopupMenuAndroid.cpp +++ b/WebCore/platform/android/PopupMenuAndroid.cpp @@ -31,7 +31,7 @@ class PopupReply : public android::WebCoreReply { public: - PopupReply(const IntRect& rect, android::WebViewCore* view, PopupMenuClient* client) + PopupReply(const IntRect& rect, android::WebViewCore* view, ListPopupMenuClient* client) : m_rect(rect) , m_viewImpl(view) , m_popupClient(client) @@ -53,9 +53,23 @@ public: m_viewImpl->contentInvalidate(m_rect); } - virtual void replyIntArray(const int*, int) { - // Should never be called. - SkASSERT(false); + virtual void replyIntArray(const int* values, int count) + { + if (m_popupClient) { + m_popupClient->popupDidHide(); + if (0 == count) { + m_popupClient->valueChanged(-1, true); + } else { + for (int i = 0; i < count; i++) { + m_popupClient->listBoxSelectItem(values[i], + i != 0 /* allowMultiplySelection */, + false /* shift */, + i == count - 1 /* fireOnChangeNow */); + } + } + } + if (m_viewImpl) + m_viewImpl->contentInvalidate(m_rect); } void disconnectClient() @@ -67,12 +81,12 @@ private: IntRect m_rect; // FIXME: Do not need this if we handle ChromeClientAndroid::formStateDidChange android::WebViewCore* m_viewImpl; - PopupMenuClient* m_popupClient; + ListPopupMenuClient* m_popupClient; }; namespace WebCore { -PopupMenuAndroid::PopupMenuAndroid(PopupMenuClient* menuList) +PopupMenuAndroid::PopupMenuAndroid(ListPopupMenuClient* menuList) : m_popupClient(menuList) , m_reply(0) { @@ -91,8 +105,7 @@ void PopupMenuAndroid::disconnectClient() m_reply = 0; } } -// 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) @@ -122,9 +135,7 @@ void PopupMenuAndroid::show(const IntRect& rect, FrameView* frameView, int) 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; + bool multiple = m_popupClient->multiple(); for (int i = 0; i < size; i++) { *names.append() = stringConverter(m_popupClient->itemText(i)); if (m_popupClient->itemIsSeparator(i)) { diff --git a/WebCore/platform/android/PopupMenuAndroid.h b/WebCore/platform/android/PopupMenuAndroid.h index 48bce44..6c2c015 100644 --- a/WebCore/platform/android/PopupMenuAndroid.h +++ b/WebCore/platform/android/PopupMenuAndroid.h @@ -34,18 +34,18 @@ class PopupReply; namespace WebCore { class FrameView; -class PopupMenuClient; +class ListPopupMenuClient; class PopupMenuAndroid : public PopupMenu { public: - PopupMenuAndroid(PopupMenuClient*); + PopupMenuAndroid(ListPopupMenuClient*); virtual ~PopupMenuAndroid(); virtual void show(const IntRect&, FrameView*, int); virtual void hide() { } virtual void updateFromElement() { } virtual void disconnectClient(); private: - PopupMenuClient* m_popupClient; + ListPopupMenuClient* m_popupClient; PopupReply* m_reply; }; diff --git a/WebCore/platform/android/RenderThemeAndroid.cpp b/WebCore/platform/android/RenderThemeAndroid.cpp index 87e7a6d..b43e0e6 100644 --- a/WebCore/platform/android/RenderThemeAndroid.cpp +++ b/WebCore/platform/android/RenderThemeAndroid.cpp @@ -351,57 +351,9 @@ void RenderThemeAndroid::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle* sty bool RenderThemeAndroid::paintTextArea(RenderObject* obj, const PaintInfo& info, const IntRect& rect) { - if (!obj->isListBox()) - return true; - - paintCombo(obj, info, rect); - RenderStyle* style = obj->style(); - if (style) - style->setColor(Color::transparent); - Node* node = obj->node(); - if (!node || !node->hasTagName(HTMLNames::selectTag)) - return true; - - HTMLSelectElement* select = static_cast<HTMLSelectElement*>(node); - // The first item may be visible. Make sure it does not draw. - // If it has a style, it overrides the RenderListBox's style, so we - // need to make sure both are set to transparent. - node = select->item(0); - if (node) { - RenderObject* renderer = node->renderer(); - if (renderer) { - RenderStyle* renderStyle = renderer->style(); - if (renderStyle) - renderStyle->setColor(Color::transparent); - } - } - // Find the first selected option, and draw its text. - // FIXME: In a later change, if there is more than one item selected, - // draw a string that says "X items" like iPhone Safari does - int index = select->selectedIndex(); - node = select->item(index); - if (!node || !node->hasTagName(HTMLNames::optionTag)) - return true; - - HTMLOptionElement* option = static_cast<HTMLOptionElement*>(node); - String label = option->textIndentedToRespectGroupLabel(); - SkRect r(rect); - - SkPaint paint; - paint.setAntiAlias(true); - paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); - // Values for text size and positioning determined by trial and error - paint.setTextSize(r.height() - SkIntToScalar(6)); - - SkCanvas* canvas = getCanvasFromInfo(info); - int saveCount = canvas->save(); - r.fRight -= SkIntToScalar(RenderSkinCombo::extraWidth()); - canvas->clipRect(r); - canvas->drawText(label.characters(), label.length() << 1, - r.fLeft + SkIntToScalar(5), r.fBottom - SkIntToScalar(5), paint); - canvas->restoreToCount(saveCount); - - return true; + if (obj->isMenuList()) + paintCombo(obj, info, rect); + return true; } void RenderThemeAndroid::adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const @@ -414,16 +366,7 @@ bool RenderThemeAndroid::paintSearchField(RenderObject*, const PaintInfo&, const return true; } -void RenderThemeAndroid::adjustListboxStyle(CSSStyleSelector*, RenderStyle* style, Element*) const -{ - style->setPaddingRight(Length(RenderSkinCombo::extraWidth(), Fixed)); - style->setMaxHeight(Length(style->fontSize() + listboxPadding, Fixed)); - // Make webkit draw invisible, since it will simply draw the first element - style->setColor(Color::transparent); - addIntrinsicMargins(style); -} - -static void adjustMenuListStyleCommon(RenderStyle* style, Element* e) +static void adjustMenuListStyleCommon(RenderStyle* style) { // Added to make room for our arrow and make the touch target less cramped. style->setPaddingLeft(Length(RenderSkinCombo::padding(), Fixed)); @@ -432,9 +375,14 @@ static void adjustMenuListStyleCommon(RenderStyle* style, Element* e) style->setPaddingRight(Length(RenderSkinCombo::extraWidth(), Fixed)); } +void RenderThemeAndroid::adjustListboxStyle(CSSStyleSelector*, RenderStyle* style, Element*) const +{ + adjustMenuListButtonStyle(0, style, 0); +} + void RenderThemeAndroid::adjustMenuListStyle(CSSStyleSelector*, RenderStyle* style, Element* e) const { - adjustMenuListStyleCommon(style, e); + adjustMenuListStyleCommon(style); addIntrinsicMargins(style); } @@ -450,7 +398,8 @@ bool RenderThemeAndroid::paintMenuList(RenderObject* obj, const PaintInfo& info, return paintCombo(obj, info, rect); } -void RenderThemeAndroid::adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle* style, Element* e) const +void RenderThemeAndroid::adjustMenuListButtonStyle(CSSStyleSelector*, + RenderStyle* style, Element*) const { // Copied from RenderThemeSafari. const float baseFontSize = 11.0f; @@ -468,7 +417,7 @@ void RenderThemeAndroid::adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyl const int padding = 4; style->setPaddingTop(Length(padding, Fixed)); style->setPaddingLeft(Length(padding, Fixed)); - adjustMenuListStyleCommon(style, e); + adjustMenuListStyleCommon(style); } bool RenderThemeAndroid::paintMenuListButton(RenderObject* obj, const PaintInfo& info, const IntRect& rect) diff --git a/WebCore/rendering/RenderTheme.cpp b/WebCore/rendering/RenderTheme.cpp index 522bd4d..538b6c6 100644 --- a/WebCore/rendering/RenderTheme.cpp +++ b/WebCore/rendering/RenderTheme.cpp @@ -198,7 +198,7 @@ void RenderTheme::adjustStyle(CSSStyleSelector* selector, RenderStyle* style, El return adjustTextFieldStyle(selector, style, e); case TextAreaPart: return adjustTextAreaStyle(selector, style, e); -#ifdef ANDROID_LISTBOX_USES_MENU_LIST +#if ENABLE(NO_LISTBOX_RENDERING) case ListboxPart: return adjustListboxStyle(selector, style, e); #endif diff --git a/WebCore/rendering/RenderTheme.h b/WebCore/rendering/RenderTheme.h index aedb8eb..13c69e6 100644 --- a/WebCore/rendering/RenderTheme.h +++ b/WebCore/rendering/RenderTheme.h @@ -236,7 +236,7 @@ protected: virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const; virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&) { return true; } -#ifdef ANDROID_LISTBOX_USES_MENU_LIST +#if ENABLE(NO_LISTBOX_RENDERING) virtual void adjustListboxStyle(CSSStyleSelector*, RenderStyle*, Element*) const {} #endif virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const; |