Source/WebCore: <rdar://problem/4761512> <select> can't display right-to-left (rtl...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Jan 2011 21:34:55 +0000 (21:34 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Jan 2011 21:34:55 +0000 (21:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

Changed <select> pop-up menus on Mac OS X Snow Leopard and later to have their items aligned in the
direction corresponding to the writing direction of the <select> element, with the checkmarks
on the "start" side, and use the <option>'s writing direction rather than "natural". Made the
pop-up button match the menu by adding a Chrome boolean function, selectItemAlignmentFollowsMenuWritingDirection(),
which returns true for this pop-up behavior.

* loader/EmptyClients.h:
(WebCore::EmptyChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added.
* manual-tests/pop-up-alignment-and-direction.html: Added.
* page/Chrome.cpp:
(WebCore::Chrome::selectItemAlignmentFollowsMenuWritingDirection): Added. Calls through to the
client.
* page/Chrome.h:
* page/ChromeClient.h:
* platform/PopupMenuStyle.h:
(WebCore::PopupMenuStyle::PopupMenuStyle): Added hasTextDirectionOverride parameter and member
variable initialization.
(WebCore::PopupMenuStyle::hasTextDirectionOverride): Added this accessor.
* platform/mac/PopupMenuMac.mm:
(WebCore::PopupMenuMac::populate): Set the pop-up's layout direction and items' text alignment
to match the menu's writing direction. Set items' writing direction and direction override
according to their styles.
* rendering/RenderMenuList.cpp:
(WebCore::RenderMenuList::RenderMenuList): Removed unncesaary initialization of a smart pointer.
(WebCore::RenderMenuList::adjustInnerStyle): If the alignment of items in the menu follows the
menu's writing direction, use that alignment for the button as well. Also in this mode, use the
item's writing direction and override setting.
(WebCore::RenderMenuList::setTextFromOption): Store the option element's style.
(WebCore::RenderMenuList::itemStyle): Pass the text direction override value.
(WebCore::RenderMenuList::menuStyle): Ditto. Also use the button's direction, not the inner text's.
* rendering/RenderMenuList.h:
* rendering/RenderTextControlSingleLine.cpp:
(WebCore::RenderTextControlSingleLine::menuStyle): Pass the text direction override value.

Source/WebKit/chromium: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* src/AutoFillPopupMenuClient.cpp:
(WebKit::AutoFillPopupMenuClient::initialize): Pass hasTextDirectionOverride to the PopupMenuStyle
constructor.
* src/ChromeClientImpl.cpp:
(WebKit::ChromeClientImpl::selectItemAlignmentFollowsMenuWritingDirection): Added.
* src/ChromeClientImpl.h:
* tests/PopupMenuTest.cpp:
(WebKit::TestPopupMenuClient::itemStyle): Pass hasTextDirectionOverride to the PopupMenuStyle
constructor.

Source/WebKit/efl: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* WebCoreSupport/ChromeClientEfl.cpp:
(WebCore::ChromeClientEfl::selectItemAlignmentFollowsMenuWritingDirection): Added.
* WebCoreSupport/ChromeClientEfl.h:

Source/WebKit/gtk: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* WebCoreSupport/ChromeClientGtk.cpp:
(WebKit::ChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added.
* WebCoreSupport/ChromeClientGtk.h:

Source/WebKit/haiku: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* WebCoreSupport/ChromeClientHaiku.cpp:
(WebCore::ChromeClientHaiku::selectItemAlignmentFollowsMenuWritingDirection): Added.
* WebCoreSupport/ChromeClientHaiku.h:

Source/WebKit/mac: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* WebCoreSupport/WebChromeClient.h:
* WebCoreSupport/WebChromeClient.mm:
(WebChromeClient::selectItemWritingDirectionIsNatural): Changed to return false.
(WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added. Returns true.

Source/WebKit/qt: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* WebCoreSupport/ChromeClientQt.cpp:
(WebCore::ChromeClientQt::selectItemAlignmentFollowsMenuWritingDirection): Added.
* WebCoreSupport/ChromeClientQt.h:

Source/WebKit/win: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* WebCoreSupport/WebChromeClient.cpp:
(WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added.
* WebCoreSupport/WebChromeClient.h:

Source/WebKit/wince: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* WebCoreSupport/ChromeClientWinCE.cpp:
(WebKit::ChromeClientWinCE::selectItemAlignmentFollowsMenuWritingDirection): Added.
* WebCoreSupport/ChromeClientWinCE.h:

Source/WebKit/wx: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* WebKitSupport/ChromeClientWx.cpp:
(WebCore::ChromeClientWx::selectItemAlignmentFollowsMenuWritingDirection): Added.
* WebKitSupport/ChromeClientWx.h:

Source/WebKit2: <select> can't display right-to-left (rtl) languages
https://bugs.webkit.org/show_bug.cgi?id=19785

Reviewed by Sam Weinig.

* Shared/WebPopupItem.cpp:
(WebKit::WebPopupItem::WebPopupItem): Added initializers for m_textDirection and m_hasTextDirectionOverride.
(WebKit::WebPopupItem::encode): Encode the item's writing direction and direction override values.
(WebKit::WebPopupItem::decode): Decode the item's writing direction and direction override values.
* Shared/WebPopupItem.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::showPopupMenu): Added a parameter for the menu's text direction.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in: Ditto.
* UIProcess/WebPopupMenuProxy.h:
* UIProcess/mac/WebPopupMenuProxyMac.h:
* UIProcess/mac/WebPopupMenuProxyMac.mm:
(WebKit::WebPopupMenuProxyMac::populate): Added a parameter for the menu's text direction.
Set items' text alignment to match the menu's writing direction. Set items' writing direction
and direction override according to their styles.
(WebKit::WebPopupMenuProxyMac::showPopupMenu): Set the pop-up's layout direction.
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::selectItemWritingDirectionIsNatural): Changed to return false.
(WebKit::WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added.
* WebProcess/WebCoreSupport/WebChromeClient.h:
* WebProcess/WebCoreSupport/WebPopupMenu.cpp:
(WebKit::WebPopupMenu::populateItems): Initialize items' writing direction and direction override
values.
(WebKit::WebPopupMenu::show): Pass the menu's writing direction.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@76983 268f45cc-cd09-0410-ab3c-d52691b4dbfc

56 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/EmptyClients.h
Source/WebCore/manual-tests/pop-up-alignment-and-direction.html [new file with mode: 0644]
Source/WebCore/page/Chrome.cpp
Source/WebCore/page/Chrome.h
Source/WebCore/page/ChromeClient.h
Source/WebCore/platform/PopupMenuStyle.h
Source/WebCore/platform/mac/PopupMenuMac.mm
Source/WebCore/rendering/RenderMenuList.cpp
Source/WebCore/rendering/RenderMenuList.h
Source/WebCore/rendering/RenderTextControlSingleLine.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/AutoFillPopupMenuClient.cpp
Source/WebKit/chromium/src/ChromeClientImpl.cpp
Source/WebKit/chromium/src/ChromeClientImpl.h
Source/WebKit/chromium/tests/PopupMenuTest.cpp
Source/WebKit/efl/ChangeLog
Source/WebKit/efl/WebCoreSupport/ChromeClientEfl.cpp
Source/WebKit/efl/WebCoreSupport/ChromeClientEfl.h
Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp
Source/WebKit/gtk/WebCoreSupport/ChromeClientGtk.h
Source/WebKit/haiku/ChangeLog
Source/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.cpp
Source/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebChromeClient.h
Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm
Source/WebKit/qt/ChangeLog
Source/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp
Source/WebKit/qt/WebCoreSupport/ChromeClientQt.h
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp
Source/WebKit/win/WebCoreSupport/WebChromeClient.h
Source/WebKit/wince/ChangeLog
Source/WebKit/wince/WebCoreSupport/ChromeClientWinCE.cpp
Source/WebKit/wince/WebCoreSupport/ChromeClientWinCE.h
Source/WebKit/wx/ChangeLog
Source/WebKit/wx/WebKitSupport/ChromeClientWx.cpp
Source/WebKit/wx/WebKitSupport/ChromeClientWx.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPopupItem.cpp
Source/WebKit2/Shared/WebPopupItem.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/WebPopupMenuProxy.h
Source/WebKit2/UIProcess/mac/WebPopupMenuProxyMac.h
Source/WebKit2/UIProcess/mac/WebPopupMenuProxyMac.mm
Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.cpp
Source/WebKit2/UIProcess/qt/WebPopupMenuProxyQt.h
Source/WebKit2/UIProcess/win/WebPopupMenuProxyWin.cpp
Source/WebKit2/UIProcess/win/WebPopupMenuProxyWin.h
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h
Source/WebKit2/WebProcess/WebCoreSupport/WebPopupMenu.cpp

index 748f4c64b076df5c2e0abc69665b62786d1b406c..35200970be3fbaa8e1c22ec53b9759bc144b5865 100644 (file)
@@ -1,3 +1,44 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <rdar://problem/4761512> <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        Changed <select> pop-up menus on Mac OS X Snow Leopard and later to have their items aligned in the
+        direction corresponding to the writing direction of the <select> element, with the checkmarks
+        on the "start" side, and use the <option>'s writing direction rather than "natural". Made the
+        pop-up button match the menu by adding a Chrome boolean function, selectItemAlignmentFollowsMenuWritingDirection(),
+        which returns true for this pop-up behavior.
+
+        * loader/EmptyClients.h:
+        (WebCore::EmptyChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * manual-tests/pop-up-alignment-and-direction.html: Added.
+        * page/Chrome.cpp:
+        (WebCore::Chrome::selectItemAlignmentFollowsMenuWritingDirection): Added. Calls through to the
+        client.
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        * platform/PopupMenuStyle.h:
+        (WebCore::PopupMenuStyle::PopupMenuStyle): Added hasTextDirectionOverride parameter and member
+        variable initialization.
+        (WebCore::PopupMenuStyle::hasTextDirectionOverride): Added this accessor.
+        * platform/mac/PopupMenuMac.mm:
+        (WebCore::PopupMenuMac::populate): Set the pop-up's layout direction and items' text alignment
+        to match the menu's writing direction. Set items' writing direction and direction override
+        according to their styles.
+        * rendering/RenderMenuList.cpp:
+        (WebCore::RenderMenuList::RenderMenuList): Removed unncesaary initialization of a smart pointer.
+        (WebCore::RenderMenuList::adjustInnerStyle): If the alignment of items in the menu follows the
+        menu's writing direction, use that alignment for the button as well. Also in this mode, use the
+        item's writing direction and override setting.
+        (WebCore::RenderMenuList::setTextFromOption): Store the option element's style.
+        (WebCore::RenderMenuList::itemStyle): Pass the text direction override value.
+        (WebCore::RenderMenuList::menuStyle): Ditto. Also use the button's direction, not the inner text's.
+        * rendering/RenderMenuList.h:
+        * rendering/RenderTextControlSingleLine.cpp:
+        (WebCore::RenderTextControlSingleLine::menuStyle): Pass the text direction override value.
+
 2011-01-28  Adam Barth  <abarth@webkit.org>
 
         Reviewed by Daniel Bates.
index 3e58c7afbbcb3de0567b6892282cd76a44466de1..83f42ad967b0b4aa73c52934d8fc5014a1953fc1 100644 (file)
@@ -137,6 +137,7 @@ public:
     virtual bool shouldInterruptJavaScript() { return false; }
 
     virtual bool selectItemWritingDirectionIsNatural() { return false; }
+    virtual bool selectItemAlignmentFollowsMenuWritingDirection() { return false; }
     virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const { return adoptRef(new EmptyPopupMenu()); }
     virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const { return adoptRef(new EmptySearchPopupMenu()); }
 
diff --git a/Source/WebCore/manual-tests/pop-up-alignment-and-direction.html b/Source/WebCore/manual-tests/pop-up-alignment-and-direction.html
new file mode 100644 (file)
index 0000000..b51798e
Binary files /dev/null and b/Source/WebCore/manual-tests/pop-up-alignment-and-direction.html differ
index d96b6c9840d0989d488e187ae7304c73f118e589..9595fa07775c6b1cbcb4b8c863493d3c58154471 100644 (file)
@@ -508,6 +508,11 @@ bool Chrome::selectItemWritingDirectionIsNatural()
     return m_client->selectItemWritingDirectionIsNatural();
 }
 
+bool Chrome::selectItemAlignmentFollowsMenuWritingDirection()
+{
+    return m_client->selectItemAlignmentFollowsMenuWritingDirection();
+}
+
 PassRefPtr<PopupMenu> Chrome::createPopupMenu(PopupMenuClient* client) const
 {
     return m_client->createPopupMenu(client);
index 0afd807dd0d6c3e6bde600a9ae0fcf1f057edabf..bd43677aa8db46a76a92d1ecd368b82c39ac1b75 100644 (file)
@@ -163,6 +163,7 @@ namespace WebCore {
 #endif
 
         bool selectItemWritingDirectionIsNatural();
+        bool selectItemAlignmentFollowsMenuWritingDirection();
         PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const;
         PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const;
 
index e348afbca4fc68d484b0a9cf6523dfdf178b384f..c2f87e007342491b8e8d95c8cd4ec6fa21d0466f 100644 (file)
@@ -292,6 +292,7 @@ namespace WebCore {
 #endif
 
         virtual bool selectItemWritingDirectionIsNatural() = 0;
+        virtual bool selectItemAlignmentFollowsMenuWritingDirection() = 0;
         virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const = 0;
         virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const = 0;
 
index b9a7abc2ae6bc77d7cc423e793f3155f913d36bc..3cb33cc6af2f725973745bfac5fa742bd28ba095 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc.  All rights reserved.
+ * Copyright (C) 2008, 2011 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -35,7 +35,7 @@ namespace WebCore {
 
 class PopupMenuStyle {
 public:
-    PopupMenuStyle(const Color& foreground, const Color& background, const Font& font, bool visible, bool isDisplayNone, Length textIndent, TextDirection textDirection)
+    PopupMenuStyle(const Color& foreground, const Color& background, const Font& font, bool visible, bool isDisplayNone, Length textIndent, TextDirection textDirection, bool hasTextDirectionOverride)
         : m_foregroundColor(foreground)
         , m_backgroundColor(background)
         , m_font(font)
@@ -43,6 +43,7 @@ public:
         , m_isDisplayNone(isDisplayNone)
         , m_textIndent(textIndent)
         , m_textDirection(textDirection)
+        , m_hasTextDirectionOverride(hasTextDirectionOverride)
     {
     }
     
@@ -53,6 +54,7 @@ public:
     bool isDisplayNone() const { return m_isDisplayNone; }
     Length textIndent() const { return m_textIndent; }
     TextDirection textDirection() const { return m_textDirection; }
+    bool hasTextDirectionOverride() const { return m_hasTextDirectionOverride; }
 
 private:
     Color m_foregroundColor;
@@ -62,6 +64,7 @@ private:
     bool m_isDisplayNone;
     Length m_textIndent;
     TextDirection m_textDirection;
+    bool m_hasTextDirectionOverride;
 };
 
 } // namespace WebCore
index 1bf500b833c417004b829f200420230155471dd1..e69bcb22f172bc4f45969e8a234b5d392c9735d9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2008, 2010, 2011 Apple Inc. All rights reserved.
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
  *
  * This library is free software; you can redistribute it and/or
@@ -75,6 +75,11 @@ void PopupMenuMac::populate()
     if (!client()->shouldPopOver())
         [m_popup.get() addItemWithTitle:@""];
 
+#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
+    TextDirection menuTextDirection = client()->menuStyle().textDirection();
+    [m_popup.get() setUserInterfaceLayoutDirection:menuTextDirection == LTR ? NSUserInterfaceLayoutDirectionLeftToRight : NSUserInterfaceLayoutDirectionRightToLeft];
+#endif // !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
+
     ASSERT(client());
     int size = client()->listSize();
 
@@ -92,13 +97,27 @@ void PopupMenuMac::populate()
                 }
                 [attributes setObject:font forKey:NSFontAttributeName];
             }
+
+#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
+            RetainPtr<NSMutableParagraphStyle> paragraphStyle(AdoptNS, [[NSParagraphStyle defaultParagraphStyle] mutableCopy]);
+            [paragraphStyle.get() setAlignment:menuTextDirection == LTR ? NSLeftTextAlignment : NSRightTextAlignment];
+            NSWritingDirection writingDirection = style.textDirection() == LTR ? NSWritingDirectionLeftToRight : NSWritingDirectionRightToLeft;
+            [paragraphStyle.get() setBaseWritingDirection:writingDirection];
+            if (style.hasTextDirectionOverride()) {
+                RetainPtr<NSNumber> writingDirectionValue(AdoptNS, [[NSNumber alloc] initWithInteger:writingDirection + NSTextWritingDirectionOverride]);
+                RetainPtr<NSArray> writingDirectionArray(AdoptNS, [[NSArray alloc] initWithObjects:writingDirectionValue.get(), nil]);
+                [attributes setObject:writingDirectionArray.get() forKey:NSWritingDirectionAttributeName];
+            }
+            [attributes setObject:paragraphStyle.get() forKey:NSParagraphStyleAttributeName];
+#endif // !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
+
             // FIXME: Add support for styling the foreground and background colors.
             // FIXME: Find a way to customize text color when an item is highlighted.
-            NSAttributedStringstring = [[NSAttributedString alloc] initWithString:client()->itemText(i) attributes:attributes];
+            NSAttributedString *string = [[NSAttributedString alloc] initWithString:client()->itemText(i) attributes:attributes];
             [attributes release];
 
             [m_popup.get() addItemWithTitle:@""];
-            NSMenuItemmenuItem = [m_popup.get() lastItem];
+            NSMenuItem *menuItem = [m_popup.get() lastItem];
             [menuItem setAttributedTitle:string];
             [menuItem setEnabled:client()->itemIsEnabled(i)];
             [menuItem setToolTip:client()->itemToolTip(i)];
index e55b5ca190c6d8a9498bd7eb78be3146d5b606a7..c45e60aa55d73ce7976b5b59e2a9cea33c043ae8 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the select element renderer in WebCore.
  *
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
- * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
  *               2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
  *
  * This library is free software; you can redistribute it and/or
@@ -55,7 +55,6 @@ RenderMenuList::RenderMenuList(Element* element)
     , m_optionsChanged(true)
     , m_optionsWidth(0)
     , m_lastSelectedIndex(-1)
-    , m_popup(0)
     , m_popupIsVisible(false)
 {
 }
@@ -84,19 +83,24 @@ void RenderMenuList::createInnerBlock()
 
 void RenderMenuList::adjustInnerStyle()
 {
-    m_innerBlock->style()->setBoxFlex(1.0f);
+    RenderStyle* innerStyle = m_innerBlock->style();
+    innerStyle->setBoxFlex(1);
     
-    m_innerBlock->style()->setPaddingLeft(Length(theme()->popupInternalPaddingLeft(style()), Fixed));
-    m_innerBlock->style()->setPaddingRight(Length(theme()->popupInternalPaddingRight(style()), Fixed));
-    m_innerBlock->style()->setPaddingTop(Length(theme()->popupInternalPaddingTop(style()), Fixed));
-    m_innerBlock->style()->setPaddingBottom(Length(theme()->popupInternalPaddingBottom(style()), Fixed));
+    innerStyle->setPaddingLeft(Length(theme()->popupInternalPaddingLeft(style()), Fixed));
+    innerStyle->setPaddingRight(Length(theme()->popupInternalPaddingRight(style()), Fixed));
+    innerStyle->setPaddingTop(Length(theme()->popupInternalPaddingTop(style()), Fixed));
+    innerStyle->setPaddingBottom(Length(theme()->popupInternalPaddingBottom(style()), Fixed));
 
     if (document()->page()->chrome()->selectItemWritingDirectionIsNatural()) {
         // Items in the popup will not respect the CSS text-align and direction properties,
         // so we must adjust our own style to match.
-        m_innerBlock->style()->setTextAlign(LEFT);
+        innerStyle->setTextAlign(LEFT);
         TextDirection direction = (m_buttonText && m_buttonText->text()->defaultWritingDirection() == WTF::Unicode::RightToLeft) ? RTL : LTR;
-        m_innerBlock->style()->setDirection(direction);
+        innerStyle->setDirection(direction);
+    } else if (m_optionStyle && document()->page()->chrome()->selectItemAlignmentFollowsMenuWritingDirection()) {
+        innerStyle->setTextAlign(style()->isLeftToRightDirection() ? LEFT : RIGHT);
+        innerStyle->setDirection(m_optionStyle->direction());
+        innerStyle->setUnicodeBidi(m_optionStyle->unicodeBidi());
     }
 }
 
@@ -184,8 +188,11 @@ void RenderMenuList::setTextFromOption(int optionIndex)
     int i = select->optionToListIndex(optionIndex);
     String text = "";
     if (i >= 0 && i < size) {
-        if (OptionElement* optionElement = toOptionElement(listItems[i]))
+        Element* element = listItems[i];
+        if (OptionElement* optionElement = toOptionElement(element)) {
             text = optionElement->textIndentedToRespectGroupLabel();
+            m_optionStyle = element->renderStyle();
+        }
     }
 
     setText(text.stripWhiteSpace());
@@ -418,7 +425,7 @@ PopupMenuStyle RenderMenuList::itemStyle(unsigned listIndex) const
     Element* element = listItems[listIndex];
     
     RenderStyle* style = element->renderStyle() ? element->renderStyle() : element->computedStyle();
-    return style ? PopupMenuStyle(style->visitedDependentColor(CSSPropertyColor), itemBackgroundColor(listIndex), style->font(), style->visibility() == VISIBLE, style->display() == NONE, style->textIndent(), style->direction()) : menuStyle();
+    return style ? PopupMenuStyle(style->visitedDependentColor(CSSPropertyColor), itemBackgroundColor(listIndex), style->font(), style->visibility() == VISIBLE, style->display() == NONE, style->textIndent(), style->direction(), style->unicodeBidi() == Override) : menuStyle();
 }
 
 Color RenderMenuList::itemBackgroundColor(unsigned listIndex) const
@@ -448,7 +455,7 @@ Color RenderMenuList::itemBackgroundColor(unsigned listIndex) const
 PopupMenuStyle RenderMenuList::menuStyle() const
 {
     RenderStyle* s = m_innerBlock ? m_innerBlock->style() : style();
-    return PopupMenuStyle(s->visitedDependentColor(CSSPropertyColor), s->visitedDependentColor(CSSPropertyBackgroundColor), s->font(), s->visibility() == VISIBLE, s->display() == NONE, s->textIndent(), s->direction());
+    return PopupMenuStyle(s->visitedDependentColor(CSSPropertyColor), s->visitedDependentColor(CSSPropertyBackgroundColor), s->font(), s->visibility() == VISIBLE, s->display() == NONE, s->textIndent(), style()->direction(), style()->unicodeBidi() == Override);
 }
 
 HostWindow* RenderMenuList::hostWindow() const
index b84b79953c14cfc5f46b92c74bfcf8d69dcaf183..cd6e56189dd811c712a6b324bb4b347de736e7d9 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the select element renderer in WebCore.
  *
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
- * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -132,6 +132,8 @@ private:
 
     int m_lastSelectedIndex;
 
+    RefPtr<RenderStyle> m_optionStyle;
+
     RefPtr<PopupMenu> m_popup;
     bool m_popupIsVisible;
 };
index bd4d638c24a3eaa848421e6ab466f5e6d3520036..737272256975af8219910dda088e35be8edbb59d 100644 (file)
@@ -924,7 +924,7 @@ PopupMenuStyle RenderTextControlSingleLine::itemStyle(unsigned) const
 
 PopupMenuStyle RenderTextControlSingleLine::menuStyle() const
 {
-    return PopupMenuStyle(style()->visitedDependentColor(CSSPropertyColor), style()->visitedDependentColor(CSSPropertyBackgroundColor), style()->font(), style()->visibility() == VISIBLE, style()->display() == NONE, style()->textIndent(), style()->direction());
+    return PopupMenuStyle(style()->visitedDependentColor(CSSPropertyColor), style()->visitedDependentColor(CSSPropertyBackgroundColor), style()->font(), style()->visibility() == VISIBLE, style()->display() == NONE, style()->textIndent(), style()->direction(), style()->unicodeBidi() == Override);
 }
 
 int RenderTextControlSingleLine::clientInsetLeft() const
index b789d0fbcd079f4066e0501b95f108186f94cc05..553ab780b7dd11dc7cba03a22b5f32d7f040dadc 100644 (file)
@@ -1,3 +1,20 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * src/AutoFillPopupMenuClient.cpp:
+        (WebKit::AutoFillPopupMenuClient::initialize): Pass hasTextDirectionOverride to the PopupMenuStyle
+        constructor.
+        * src/ChromeClientImpl.cpp:
+        (WebKit::ChromeClientImpl::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * src/ChromeClientImpl.h:
+        * tests/PopupMenuTest.cpp:
+        (WebKit::TestPopupMenuClient::itemStyle): Pass hasTextDirectionOverride to the PopupMenuStyle
+        constructor.
+
 2011-01-28  Adam Klein  <adamk@chromium.org>
 
         Reviewed by Kent Tamura.
index 2ce31a953bbf772f9dd2292c60cdd00fd1c012a2..d04c57cb01af008dffef93afe172d1d4af829074 100644 (file)
@@ -293,7 +293,7 @@ void AutoFillPopupMenuClient::initialize(
     // the input element: textField.
     m_regularStyle.set(new PopupMenuStyle(Color::black, Color::white, regularFont,
                                           true, false, Length(WebCore::Fixed),
-                                          textField->renderer()->style()->direction()));
+                                          textField->renderer()->style()->direction(), textField->renderer()->style()->unicodeBidi() == Override));
 
     FontDescription warningFontDescription = regularFont.fontDescription();
     warningFontDescription.setItalic(true);
@@ -305,7 +305,8 @@ void AutoFillPopupMenuClient::initialize(
                                           m_regularStyle->isVisible(),
                                           m_regularStyle->isDisplayNone(),
                                           m_regularStyle->textIndent(),
-                                          m_regularStyle->textDirection()));
+                                          m_regularStyle->textDirection(),
+                                          m_regularStyle->hasTextDirectionOverride()));
 }
 
 void AutoFillPopupMenuClient::setSuggestions(const WebVector<WebString>& names,
index 0e40f1da33be6bd8c48a7c0afe6e14076b52a3ef..adea422827f41c7f0d750d65d3dfa7c6cc16f60a 100644 (file)
@@ -853,6 +853,11 @@ bool ChromeClientImpl::selectItemWritingDirectionIsNatural()
     return false;
 }
 
+bool ChromeClientImpl::selectItemAlignmentFollowsMenuWritingDirection()
+{
+    return false;
+}
+
 PassRefPtr<PopupMenu> ChromeClientImpl::createPopupMenu(PopupMenuClient* client) const
 {
     if (WebViewImpl::useExternalPopupMenus())
index 07f7d1f9ef8cdae504a5f36d948c12eac500a8d7..64335e89a3870934117d95202869ffe037f5b675 100644 (file)
@@ -173,6 +173,7 @@ public:
     void setCursorForPlugin(const WebCursorInfo&);
 
     virtual bool selectItemWritingDirectionIsNatural();
+    virtual bool selectItemAlignmentFollowsMenuWritingDirection();
     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
     virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
 
index 4c9a14948c3b87a163e985066007d29c22db82c8..acfcda59b0ce024676515528904979596b3e78b4 100644 (file)
@@ -76,7 +76,7 @@ public:
     virtual PopupMenuStyle itemStyle(unsigned listIndex) const
     {
         Font font(FontPlatformData(12.0, false, false), false);
-        return PopupMenuStyle(Color::black, Color::white, font, true, false, Length(), TextDirection());
+        return PopupMenuStyle(Color::black, Color::white, font, true, false, Length(), TextDirection(), false /* has text direction override */);
     }
     virtual PopupMenuStyle menuStyle() const { return itemStyle(0); }
     virtual int clientInsetLeft() const { return 0; }
index 17072bc0349b4d60ff5ff9adf6029e77984ca657..e83d1ce2ab8a022bc62063331bb8c088d66cba28 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * WebCoreSupport/ChromeClientEfl.cpp:
+        (WebCore::ChromeClientEfl::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * WebCoreSupport/ChromeClientEfl.h:
+
 2011-01-27  Nate Chapin  <japhet@chromium.org>
 
         Reviewed by Adam Barth.
index e9904c6f235a3b71be530f3f8ee6c37e0e0b6c2b..6425c3942f119cf111508962391238cfd9756b7e 100644 (file)
@@ -532,6 +532,11 @@ bool ChromeClientEfl::selectItemWritingDirectionIsNatural()
     return true;
 }
 
+bool ChromeClientEfl::selectItemAlignmentFollowsMenuWritingDirection()
+{
+    return false;
+}
+
 PassRefPtr<PopupMenu> ChromeClientEfl::createPopupMenu(PopupMenuClient* client) const
 {
     return adoptRef(new PopupMenuEfl(client));
index a714dd424714c6567d0b0444f13a25a292823488..7e4bf0b2ae05f62b7638965d13968f804c905515 100644 (file)
@@ -149,6 +149,7 @@ public:
     virtual void dispatchViewportDataDidChange(const ViewportArguments&) const;
 
     virtual bool selectItemWritingDirectionIsNatural();
+    virtual bool selectItemAlignmentFollowsMenuWritingDirection();
     virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const;
     virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const;
 
index 327cb48bab2b47dc3c949fe244219fb43639324e..ca5840e181f193d2dde474cc5c3c35e16e305849 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * WebCoreSupport/ChromeClientGtk.cpp:
+        (WebKit::ChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * WebCoreSupport/ChromeClientGtk.h:
+
 2011-01-28  Alejandro G. Castro  <alex@igalia.com>
 
         Reviewed by Xan Lopez.
index 04ee8ba79bf657d560d89368508a3b351a7e4c53..bbfdd7231dacc41ac37cc33e0d614f4036b68c93 100644 (file)
@@ -674,6 +674,11 @@ bool ChromeClient::selectItemWritingDirectionIsNatural()
     return true;
 }
 
+bool ChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
+{
+    return false;
+}
+
 PassRefPtr<WebCore::PopupMenu> ChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
 {
     return adoptRef(new PopupMenuGtk(client));
index d607c5459f8971523af2206fb00f8989ad5d6ab3..d525e82e94d03a76ef3ab6e234668dff7ec202f5 100644 (file)
@@ -137,6 +137,7 @@ namespace WebKit {
         virtual void cancelGeolocationPermissionRequestForFrame(WebCore::Frame*, WebCore::Geolocation*);
 
         virtual bool selectItemWritingDirectionIsNatural();
+        virtual bool selectItemAlignmentFollowsMenuWritingDirection();
         virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
         virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
 #if ENABLE(VIDEO)
index fdaafefda0d853c069bd95acdd501119de2ea207..e63e23f48acff0fa043f03256aa30c34feac41b7 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * WebCoreSupport/ChromeClientHaiku.cpp:
+        (WebCore::ChromeClientHaiku::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * WebCoreSupport/ChromeClientHaiku.h:
+
 2011-01-27  Nate Chapin  <japhet@chromium.org>
 
         Reviewed by Adam Barth.
index 01b9c1d3c60e725363059d7be5f0d256cb3ad4f8..f1f42eae8a5c0c71d711766eddc34c58325955e8 100644 (file)
@@ -399,6 +399,11 @@ bool ChromeClientHaiku::selectItemWritingDirectionIsNatural()
     return false;
 }
 
+bool ChromeClientHaiku::selectItemAlignmentFollowsMenuWritingDirection()
+{
+    return false;
+}
+
 PassRefPtr<PopupMenu> ChromeClientHaiku::createPopupMenu(PopupMenuClient* client) const
 {
     return adoptRef(new PopupMenuHaiku(client));
index deb36787e1704ded095be60cd6fc2f13f01e9faf..59d4b283d90f248e252eb2a62ad78083351c1d9f 100644 (file)
@@ -133,6 +133,7 @@ namespace WebCore {
 #endif
 
         virtual bool selectItemWritingDirectionIsNatural();
+        virtual bool selectItemAlignmentFollowsMenuWritingDirection();
         virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const;
         virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const;
 
index 0e5329b78113034ea56fe2349d78028774ce22c0..375959e3a9b72ad7e7044b876a22a4b9de17a1ec 100644 (file)
@@ -1,3 +1,15 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * WebCoreSupport/WebChromeClient.h:
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::selectItemWritingDirectionIsNatural): Changed to return false.
+        (WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added. Returns true.
+
 2011-01-27  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r76891.
index 05db52461b0388fe6c543ff92fbc818cfce5ba67..ea306b2f776428660cdda8f59dfe9d0bdceab480 100644 (file)
@@ -179,6 +179,7 @@ public:
     virtual void cancelGeolocationPermissionRequestForFrame(WebCore::Frame*, WebCore::Geolocation*) { }
 
     virtual bool selectItemWritingDirectionIsNatural();
+    virtual bool selectItemAlignmentFollowsMenuWritingDirection();
     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
     virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
 
index a5fd71af92c92af13c1226766863e8b580b6e9c2..0e7e2f24db646c494b43a8180be855143ec22fc4 100644 (file)
@@ -749,7 +749,20 @@ void WebChromeClient::formDidBlur(const WebCore::Node* node)
 
 bool WebChromeClient::selectItemWritingDirectionIsNatural()
 {
+#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
+    return false;
+#else
     return true;
+#endif
+}
+
+bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
+{
+#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
+    return true;
+#else
+    return false;
+#endif
 }
 
 PassRefPtr<WebCore::PopupMenu> WebChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
index e2e22a581d86163a78c928f8e8701c68d5f71b6d..08cb035367679a9369bc7d90d8be63fa37c7cc08 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * WebCoreSupport/ChromeClientQt.cpp:
+        (WebCore::ChromeClientQt::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * WebCoreSupport/ChromeClientQt.h:
+
 2011-01-27  Nate Chapin  <japhet@chromium.org>
 
         Reviewed by Adam Barth.
index acb136a38ae181cfcc96c061eb4c24216f39b963..5a51b63e3161b9eadc89471e618923368fba8b77 100644 (file)
@@ -736,6 +736,11 @@ bool ChromeClientQt::selectItemWritingDirectionIsNatural()
     return false;
 }
 
+bool ChromeClientQt::selectItemAlignmentFollowsMenuWritingDirection()
+{
+    return false;
+}
+
 PassRefPtr<PopupMenu> ChromeClientQt::createPopupMenu(PopupMenuClient* client) const
 {
     return adoptRef(new PopupMenuQt(client, this));
index d8c2f57a69f8fea17d6b23e1941e5fd2a68c5807..e59f6ae14984445028d76c1e6eaf7ed06c7087a0 100644 (file)
@@ -189,6 +189,7 @@ namespace WebCore {
         virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*);
 
         virtual bool selectItemWritingDirectionIsNatural();
+        virtual bool selectItemAlignmentFollowsMenuWritingDirection();
         virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const;
         virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const;
         virtual void populateVisitedLinks();
index b92bbb3697642c65a847af10c7324901ffeec3c6..26cf0c54a77506e912eca859b99f7d0db645a2a8 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * WebCoreSupport/WebChromeClient.cpp:
+        (WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * WebCoreSupport/WebChromeClient.h:
+
 2011-01-27  Nate Chapin  <japhet@chromium.org>
 
         Reviewed by Adam Barth.
index f5cce4e0948da794d5b98b4e6d2c080c02beb7b6..47ca713330429b2f8b63f694916d4af230be4bf8 100644 (file)
@@ -862,6 +862,11 @@ bool WebChromeClient::selectItemWritingDirectionIsNatural()
     return true;
 }
 
+bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
+{
+    return false;
+}
+
 PassRefPtr<PopupMenu> WebChromeClient::createPopupMenu(PopupMenuClient* client) const
 {
     return adoptRef(new PopupMenuWin(client));
index b6c252509be1397152bacec5e4221709b0d14079..15118b5dda4c6b7d408657856fecad70889ce011 100644 (file)
@@ -175,6 +175,7 @@ public:
 #endif
 
     virtual bool selectItemWritingDirectionIsNatural();
+    virtual bool selectItemAlignmentFollowsMenuWritingDirection();
     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
     virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
 
index 87ca29e8aabf9bf421020bee5c5b26641777aca5..4541a90ba22c3fa3d923574846261dcc44bba774 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * WebCoreSupport/ChromeClientWinCE.cpp:
+        (WebKit::ChromeClientWinCE::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * WebCoreSupport/ChromeClientWinCE.h:
+
 2011-01-25  Patrick Gansterer  <paroga@webkit.org>
 
         Reviewed by Adam Roben.
index 659d2469ead34cffdb6e24a41afc11f51836ae9d..a8604c113a41f757cd161399bcd584c69b7260b3 100644 (file)
@@ -390,6 +390,11 @@ bool ChromeClientWinCE::selectItemWritingDirectionIsNatural()
     return false;
 }
 
+bool ChromeClientWinCE::selectItemAlignmentFollowsMenuWritingDirection()
+{
+    return false;
+}
+
 PassRefPtr<PopupMenu> ChromeClientWinCE::createPopupMenu(PopupMenuClient* client) const
 {
     return adoptRef(new PopupMenuWin(client));
index 4e7fb285c76b65e675cb7c677981f22f14ffeb27..11588af69d00ed0b54a043ba1c98e8df17200756 100644 (file)
@@ -174,6 +174,7 @@ public:
 #endif
 
     virtual bool selectItemWritingDirectionIsNatural();
+    virtual bool selectItemAlignmentFollowsMenuWritingDirection();
     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
     virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
 
index 5face2c06ca23de3f7dfc836896dafcdb9676c8f..e39a6867ea8532df40f4655b9aa191b32f01e398 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * WebKitSupport/ChromeClientWx.cpp:
+        (WebCore::ChromeClientWx::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * WebKitSupport/ChromeClientWx.h:
+
 2011-01-27  Nate Chapin  <japhet@chromium.org>
 
         Reviewed by Adam Barth.
index c89bb17258116341d44ecf3408d600505a2a2271..026d8a6fcadfbfba68d77bdda092454c8e86eeb0 100644 (file)
@@ -476,6 +476,11 @@ bool ChromeClientWx::selectItemWritingDirectionIsNatural()
     return false;
 }
 
+bool ChromeClientWx::selectItemAlignmentFollowsMenuWritingDirection()
+{
+    return false;
+}
+
 PassRefPtr<PopupMenu> ChromeClientWx::createPopupMenu(PopupMenuClient* client) const
 {
     return adoptRef(new PopupMenuWx(client));
index 2ccad43828b11314101ffc9d07f31610a9e53e27..c1aeab03230ae2e3b46fefc75ca9556acbb7e501 100644 (file)
@@ -149,6 +149,7 @@ public:
     virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*) { }
 
     virtual bool selectItemWritingDirectionIsNatural();
+    virtual bool selectItemAlignmentFollowsMenuWritingDirection();
     virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const;
     virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const;
 
index 0b63c7351325a1c7f1c55ec8c851a70ca21a77e1..bbab997dfb2ee1898fa4a1ec22ce6c064379fe32 100644 (file)
@@ -1,3 +1,35 @@
+2011-01-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        <select> can't display right-to-left (rtl) languages
+        https://bugs.webkit.org/show_bug.cgi?id=19785
+
+        * Shared/WebPopupItem.cpp:
+        (WebKit::WebPopupItem::WebPopupItem): Added initializers for m_textDirection and m_hasTextDirectionOverride.
+        (WebKit::WebPopupItem::encode): Encode the item's writing direction and direction override values.
+        (WebKit::WebPopupItem::decode): Decode the item's writing direction and direction override values.
+        * Shared/WebPopupItem.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::showPopupMenu): Added a parameter for the menu's text direction.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in: Ditto.
+        * UIProcess/WebPopupMenuProxy.h:
+        * UIProcess/mac/WebPopupMenuProxyMac.h:
+        * UIProcess/mac/WebPopupMenuProxyMac.mm:
+        (WebKit::WebPopupMenuProxyMac::populate): Added a parameter for the menu's text direction.
+        Set items' text alignment to match the menu's writing direction. Set items' writing direction
+        and direction override according to their styles.
+        (WebKit::WebPopupMenuProxyMac::showPopupMenu): Set the pop-up's layout direction.
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::selectItemWritingDirectionIsNatural): Changed to return false.
+        (WebKit::WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection): Added.
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+        * WebProcess/WebCoreSupport/WebPopupMenu.cpp:
+        (WebKit::WebPopupMenu::populateItems): Initialize items' writing direction and direction override
+        values.
+        (WebKit::WebPopupMenu::show): Pass the menu's writing direction.
+
 2011-01-28  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Adam Roben.
index d9a7cb1082fb7ed8a37d92202ba1ccaa725b5694..a9ac0322525418c8d9e3b2734af908c9648e2426 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "ArgumentCoders.h"
 #include "Arguments.h"
 
+using namespace WebCore;
+
 namespace WebKit {
 
 WebPopupItem::WebPopupItem()
     : m_type(Item)
+    , m_textDirection(LTR)
+    , m_hasTextDirectionOverride(false)
     , m_isEnabled(true)
 {
 }
 
 WebPopupItem::WebPopupItem(Type type)
     : m_type(type)
+    , m_textDirection(LTR)
+    , m_hasTextDirectionOverride(false)
     , m_isEnabled(true)
     , m_isLabel(false)
 {
 }
 
-WebPopupItem::WebPopupItem(Type type, const String& text, const String& toolTip, const String& accessibilityText, bool isEnabled, bool isLabel)
+WebPopupItem::WebPopupItem(Type type, const String& text, TextDirection textDirection, bool hasTextDirectionOverride, const String& toolTip, const String& accessibilityText, bool isEnabled, bool isLabel)
     : m_type(type)
     , m_text(text)
+    , m_textDirection(textDirection)
+    , m_hasTextDirectionOverride(hasTextDirectionOverride)
     , m_toolTip(toolTip)
     , m_accessibilityText(accessibilityText)
     , m_isEnabled(isEnabled)
@@ -57,21 +65,23 @@ WebPopupItem::WebPopupItem(Type type, const String& text, const String& toolTip,
 
 void WebPopupItem::encode(CoreIPC::ArgumentEncoder* encoder) const
 {
-    encoder->encode(CoreIPC::In(static_cast<uint32_t>(m_type), m_text, m_toolTip, m_accessibilityText, m_isEnabled, m_isLabel));
+    encoder->encode(CoreIPC::In(static_cast<uint32_t>(m_type), m_text, static_cast<uint64_t>(m_textDirection), m_hasTextDirectionOverride, m_toolTip, m_accessibilityText, m_isEnabled, m_isLabel));
 }
 
 bool WebPopupItem::decode(CoreIPC::ArgumentDecoder* decoder, WebPopupItem& item)
 {
     uint32_t type;
     String text;
+    uint64_t textDirection;
+    bool hasTextDirectionOverride;
     String toolTip;
     String accessibilityText;
     bool isEnabled;
     bool isLabel;
-    if (!decoder->decode(CoreIPC::Out(type, text, toolTip, accessibilityText, isEnabled, isLabel)))
+    if (!decoder->decode(CoreIPC::Out(type, text, textDirection, hasTextDirectionOverride, toolTip, accessibilityText, isEnabled, isLabel)))
         return false;
 
-    item = WebPopupItem(static_cast<Type>(type), text, toolTip, accessibilityText, isEnabled, isLabel);
+    item = WebPopupItem(static_cast<Type>(type), text, static_cast<TextDirection>(textDirection), hasTextDirectionOverride, toolTip, accessibilityText, isEnabled, isLabel);
     return true;
 }
 
index c6874f8e1d3a70468b578239caa06ebb9d25a3a7..85495a31911d30c66c327b6648adc42deb4115e8 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef WebPopupItem_h
 #define WebPopupItem_h
 
+#include <WebCore/TextDirection.h>
 #include <wtf/text/WTFString.h>
 
 namespace CoreIPC {
@@ -43,13 +44,15 @@ struct WebPopupItem {
 
     WebPopupItem();
     WebPopupItem(Type);
-    WebPopupItem(Type, const String& text, const String& toolTip, const String& accessibilityText, bool isEnabled, bool m_isLabel);
+    WebPopupItem(Type, const String& text, WebCore::TextDirection, bool hasTextDirectionOverride, const String& toolTip, const String& accessibilityText, bool isEnabled, bool m_isLabel);
 
     void encode(CoreIPC::ArgumentEncoder*) const;
     static bool decode(CoreIPC::ArgumentDecoder*, WebPopupItem&);
 
     Type m_type;
     String m_text;
+    WebCore::TextDirection m_textDirection;
+    bool m_hasTextDirectionOverride;
     String m_toolTip;
     String m_accessibilityText;
     bool m_isEnabled;
index c756d2af11e0871d4b68366d2d93dccea51acfe8..7e318828e7632e55fdb5c21d15782cdf31953045 100644 (file)
@@ -1860,7 +1860,7 @@ void WebPageProxy::setTextFromItemForPopupMenu(WebPopupMenuProxy*, int32_t index
     process()->send(Messages::WebPage::SetTextForActivePopupMenu(index), m_pageID);
 }
 
-void WebPageProxy::showPopupMenu(const IntRect& rect, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData& data)
+void WebPageProxy::showPopupMenu(const IntRect& rect, uint64_t textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData& data)
 {
     if (m_activePopupMenu)
         m_activePopupMenu->hidePopupMenu();
@@ -1872,7 +1872,7 @@ void WebPageProxy::showPopupMenu(const IntRect& rect, const Vector<WebPopupItem>
     process()->responsivenessTimer()->stop();
 #endif
 
-    m_activePopupMenu->showPopupMenu(rect, items, data, selectedIndex);
+    m_activePopupMenu->showPopupMenu(rect, static_cast<TextDirection>(textDirection), items, data, selectedIndex);
     m_activePopupMenu = 0;
 }
 
index d0613ac3bb9f91aa59c1bf8c570682dfd35efcfe..197f31c5ef38b369c7bdc7ac873790a79e57665e 100644 (file)
@@ -493,7 +493,7 @@ private:
     void didFailToFindString(const String&);
 
     // Popup Menu.
-    void showPopupMenu(const WebCore::IntRect& rect, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData&);
+    void showPopupMenu(const WebCore::IntRect& rect, uint64_t textDirection, const Vector<WebPopupItem>& items, int32_t selectedIndex, const PlatformPopupMenuData&);
     void hidePopupMenu();
 
     // Context Menu.
index a48ca8f92806110772738344e32fc9e02bc0f44a..ef87728d328d2272c6dc3f9e916e1e472f1b5f74 100644 (file)
@@ -153,7 +153,7 @@ messages -> WebPageProxy {
     DidFailToFindString(WTF::String string)
 
     # PopupMenu messages
-    ShowPopupMenu(WebCore::IntRect rect, Vector<WebKit::WebPopupItem> items, int32_t selectedIndex, WebKit::PlatformPopupMenuData data)
+    ShowPopupMenu(WebCore::IntRect rect, uint64_t textDirection, Vector<WebKit::WebPopupItem> items, int32_t selectedIndex, WebKit::PlatformPopupMenuData data)
     HidePopupMenu()
     
     # ContextMenu messages
index fd849288bc004be7c891550dae6060193e9d5b50..fd86b15cc8ca1a26a0181e798729ae71aec2d0e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,6 +26,7 @@
 #ifndef WebPopupMenuProxy_h
 #define WebPopupMenuProxy_h
 
+#include <WebCore/TextDirection.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
@@ -56,7 +57,7 @@ public:
     {
     }
 
-    virtual void showPopupMenu(const WebCore::IntRect& rect, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex) = 0;
+    virtual void showPopupMenu(const WebCore::IntRect& rect, WebCore::TextDirection, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex) = 0;
     virtual void hidePopupMenu() = 0;
 
 protected:
index 85339d6c827ff1cc8b955a3ce40f95109d9d6257..3c4902c9e76800d3b390c22f34d98bea10ed85d5 100644 (file)
@@ -49,13 +49,13 @@ public:
     }
     ~WebPopupMenuProxyMac();
 
-    virtual void showPopupMenu(const WebCore::IntRect&, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex);
+    virtual void showPopupMenu(const WebCore::IntRect&, WebCore::TextDirection, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex);
     virtual void hidePopupMenu();
 
 private:
     WebPopupMenuProxyMac(WKView*, WebPopupMenuProxy::Client* client);
 
-    void populate(const Vector<WebPopupItem>&);
+    void populate(const Vector<WebPopupItem>&, WebCore::TextDirection);
 
     RetainPtr<NSPopUpButtonCell> m_popup;
     WKView* m_webView;
index 355c115e2645c00afe84fe2d4fa570d89ea289eb..095542ce8cdbae71d76fa2d9921988eee1213579 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -47,7 +47,7 @@ WebPopupMenuProxyMac::~WebPopupMenuProxyMac()
         [m_popup.get() setControlView:nil];
 }
 
-void WebPopupMenuProxyMac::populate(const Vector<WebPopupItem>& items)
+void WebPopupMenuProxyMac::populate(const Vector<WebPopupItem>& items, TextDirection menuTextDirection)
 {
     if (m_popup)
         [m_popup.get() removeAllItems];
@@ -64,20 +64,37 @@ void WebPopupMenuProxyMac::populate(const Vector<WebPopupItem>& items)
             [[m_popup.get() menu] addItem:[NSMenuItem separatorItem]];
         else {
             [m_popup.get() addItemWithTitle:@""];
-            NSMenuItem* menuItem = [m_popup.get() lastItem];
-            [menuItem setTitle:nsStringFromWebCoreString(items[i].m_text)];
+            NSMenuItem *menuItem = [m_popup.get() lastItem];
+
+            RetainPtr<NSMutableParagraphStyle> paragraphStyle(AdoptNS, [[NSParagraphStyle defaultParagraphStyle] mutableCopy]);
+            NSWritingDirection writingDirection = items[i].m_textDirection == LTR ? NSWritingDirectionLeftToRight : NSWritingDirectionRightToLeft;
+            [paragraphStyle.get() setBaseWritingDirection:writingDirection];
+            [paragraphStyle.get() setAlignment:menuTextDirection == LTR ? NSLeftTextAlignment : NSRightTextAlignment];
+            RetainPtr<NSMutableDictionary> attributes(AdoptNS, [[NSMutableDictionary alloc] initWithObjectsAndKeys:
+                paragraphStyle.get(), NSParagraphStyleAttributeName,
+                [m_popup.get() font], NSFontAttributeName,
+            nil]);
+            if (items[i].m_hasTextDirectionOverride) {
+                RetainPtr<NSNumber> writingDirectionValue(AdoptNS, [[NSNumber alloc] initWithInteger:writingDirection + NSTextWritingDirectionOverride]);
+                RetainPtr<NSArray> writingDirectionArray(AdoptNS, [[NSArray alloc] initWithObjects:writingDirectionValue.get(), nil]);
+                [attributes.get() setObject:writingDirectionArray.get() forKey:NSWritingDirectionAttributeName];
+            }
+            RetainPtr<NSAttributedString> string(AdoptNS, [[NSAttributedString alloc] initWithString:nsStringFromWebCoreString(items[i].m_text) attributes:attributes.get()]);
+
+            [menuItem setAttributedTitle:string.get()];
             [menuItem setEnabled:items[i].m_isEnabled];
             [menuItem setToolTip:nsStringFromWebCoreString(items[i].m_toolTip)];
         }
     }
 }
 
-void WebPopupMenuProxyMac::showPopupMenu(const IntRect& rect, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex)
+void WebPopupMenuProxyMac::showPopupMenu(const IntRect& rect, TextDirection textDirection, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex)
 {
-    populate(items);
+    populate(items, textDirection);
 
     [m_popup.get() attachPopUpWithFrame:rect inView:m_webView];
     [m_popup.get() selectItemAtIndex:selectedIndex];
+    [m_popup.get() setUserInterfaceLayoutDirection:textDirection == LTR ? NSUserInterfaceLayoutDirectionLeftToRight : NSUserInterfaceLayoutDirectionRightToLeft];
 
     NSMenu* menu = [m_popup.get() menu];
 
index 1b4426556fd20f49e3029a4c262876d7c581324d..a79cc3c887feb8eadd31e0c8e3f13379432f1e55 100644 (file)
@@ -42,7 +42,7 @@ WebPopupMenuProxyQt::~WebPopupMenuProxyQt()
 {
 }
 
-void WebPopupMenuProxyQt::showPopupMenu(const IntRect& rect, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex)
+void WebPopupMenuProxyQt::showPopupMenu(const IntRect& rect, WebCore::TextDirection, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex)
 {
 }
 
index e6c7a1e1802bdf83beac4912063c6a9bb8fc6be2..f41432cb55d4d9dc10f5c16d8d5ca9ecd316ad41 100644 (file)
@@ -38,7 +38,7 @@ public:
     }
     ~WebPopupMenuProxyQt();
 
-    virtual void showPopupMenu(const WebCore::IntRect&, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex);
+    virtual void showPopupMenu(const WebCore::IntRect&, WebCore::TextDirection, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex);
     virtual void hidePopupMenu();
 
 private:
index 989a04fc6ee1e173b733af0d3eff66c270a46ff7..18f8adeb171f02a3049cf741a5cd289dacaf6213 100644 (file)
@@ -188,7 +188,7 @@ WebPopupMenuProxyWin::~WebPopupMenuProxyWin()
         m_scrollbar->setParent(0);
 }
 
-void WebPopupMenuProxyWin::showPopupMenu(const IntRect& rect, const Vector<WebPopupItem>& items, const PlatformPopupMenuData& data, int32_t selectedIndex)
+void WebPopupMenuProxyWin::showPopupMenu(const IntRect& rect, TextDirection, const Vector<WebPopupItem>& items, const PlatformPopupMenuData& data, int32_t selectedIndex)
 {
     m_items = items;
     m_data = data;
index d1dc4661fcd0e43867b5bd5fb353d75e72832f10..2d09bb9c88130d165cb39c2365959f4c36707f0b 100644 (file)
@@ -48,7 +48,7 @@ public:
     }
     ~WebPopupMenuProxyWin();
 
-    virtual void showPopupMenu(const WebCore::IntRect&, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex);
+    virtual void showPopupMenu(const WebCore::IntRect&, WebCore::TextDirection, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex);
     virtual void hidePopupMenu();
 
     void hide() { hidePopupMenu(); }
index d48e8c85497aaac0092d282cba7f8ebc2697639c..30b32872059075c92aa0e121b70f48e48398db70 100644 (file)
@@ -611,6 +611,11 @@ void WebChromeClient::formDidBlur(const Node*)
 }
 
 bool WebChromeClient::selectItemWritingDirectionIsNatural()
+{
+    return false;
+}
+
+bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
 {
     return true;
 }
index d749833666d8ff042eb0cff77cf2e25b0bd1481f..40d6c6ab652d86020a1cfae64d0c83e753ecebfd 100644 (file)
@@ -175,6 +175,7 @@ private:
     virtual PassOwnPtr<WebCore::HTMLParserQuirks> createHTMLParserQuirks();
 
     virtual bool selectItemWritingDirectionIsNatural();
+    virtual bool selectItemAlignmentFollowsMenuWritingDirection();
     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
     virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
 
index 709063c0489b68f7dc5f5e9a963c679fe33b5061..7242d4f505b1e452e88a39ba814a790b7aed0792 100644 (file)
@@ -86,7 +86,8 @@ Vector<WebPopupItem> WebPopupMenu::populateItems()
             // FIXME: Add support for styling the font.
             // FIXME: Add support for styling the foreground and background colors.
             // FIXME: Find a way to customize text color when an item is highlighted.
-            items.append(WebPopupItem(WebPopupItem::Item, m_popupClient->itemText(i), m_popupClient->itemToolTip(i), m_popupClient->itemAccessibilityText(i), m_popupClient->itemIsEnabled(i), m_popupClient->itemIsLabel(i)));
+            PopupMenuStyle itemStyle = m_popupClient->itemStyle(i);
+            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)));
         }
     }
 
@@ -111,7 +112,7 @@ void WebPopupMenu::show(const IntRect& rect, FrameView* view, int index)
     PlatformPopupMenuData platformData;
     setUpPlatformData(pageCoordinates, platformData);
 
-    WebProcess::shared().connection()->send(Messages::WebPageProxy::ShowPopupMenu(pageCoordinates, items, index, platformData), m_page->pageID());
+    WebProcess::shared().connection()->send(Messages::WebPageProxy::ShowPopupMenu(pageCoordinates, m_popupClient->menuStyle().textDirection(), items, index, platformData), m_page->pageID());
 }
 
 void WebPopupMenu::hide()