Changeset 167825 in webkit


Ignore:
Timestamp:
Apr 25, 2014 2:42:48 PM (10 years ago)
Author:
dino@apple.com
Message:

Allow a platform-specific size enumeration to be passed into popup-menu display
https://bugs.webkit.org/show_bug.cgi?id=132195

Reviewed by Brent Fulgham. With some in-person review comments from Sam Weinig.

Platforms like OS X use a set of predefined sizes for built-in controls
used for <select>: normal, small and mini. Expose that information to
the PopupMenuClient via the PopupMenuStyle, allowing it to be passed
into the platform code in WebKitSystemInterface.

Source/WebCore:

  • platform/PopupMenuStyle.h: Add a menu size enum.

(WebCore::PopupMenuStyle::PopupMenuStyle):
(WebCore::PopupMenuStyle::menuSize):

  • platform/mac/WebCoreSystemInterface.h: Pass in NSControlSize as a parameter

to WKPopupMenu.

  • platform/mac/WebCoreSystemInterface.mm: Ditto.
  • rendering/RenderMenuList.cpp:

(RenderMenuList::menuStyle): Ask the RenderTheme to calculate the size
of the menu button, so that it can be added to the PopupMenuStyle.

  • rendering/RenderTheme.h: New method to retrieve the menu size.

(WebCore::RenderTheme::popupMenuSize): Convert an NSControlSize into a PopupMenuSize.

  • rendering/RenderThemeMac.h: Override the base function, and add a

controlSizeForCell helper.

  • rendering/RenderThemeMac.mm:

(WebCore::RenderThemeMac::controlSizeForCell): Used by this new
code and the old setControlSizeForCell to calculate the NSControlSize
that would be used for the button.
(WebCore::RenderThemeMac::setControlSize): Call the new helper.
(WebCore::RenderThemeMac::popupMenuSize): Return the value from the helper.

Source/WebKit/mac:

  • WebCoreSupport/PopupMenuMac.mm:

(PopupMenuMac::show): Convert the WebCore menu size type into the
WebCoreSystemInterface type.

Source/WebKit2:

  • Shared/PlatformPopupMenuData.cpp: Encode and decode the PopupMenuSize enum.

(WebKit::PlatformPopupMenuData::encode):
(WebKit::PlatformPopupMenuData::decode):

  • Shared/PlatformPopupMenuData.h: Add PopupMenuSize member variable.
  • UIProcess/mac/WebPopupMenuProxyMac.mm:

(WebKit::WebPopupMenuProxyMac::showPopupMenu): Convert the PopupMenuSize
into a WKControlSize, and pass that into WKPopupMenu.

  • WebProcess/WebCoreSupport/mac/WebPopupMenuMac.mm:

(WebKit::WebPopupMenu::setUpPlatformData): Add the PopupMenuSize to
the PlatformPopupMenuData.

Location:
trunk/Source
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r167821 r167825  
     12014-04-25  Dean Jackson  <dino@apple.com>
     2
     3        Allow a platform-specific size enumeration to be passed into popup-menu display
     4        https://bugs.webkit.org/show_bug.cgi?id=132195
     5
     6        Reviewed by Brent Fulgham. With some in-person review comments from Sam Weinig.
     7
     8        Platforms like OS X use a set of predefined sizes for built-in controls
     9        used for <select>: normal, small and mini. Expose that information to
     10        the PopupMenuClient via the PopupMenuStyle, allowing it to be passed
     11        into the platform code in WebKitSystemInterface.
     12
     13        * platform/PopupMenuStyle.h: Add a menu size enum.
     14        (WebCore::PopupMenuStyle::PopupMenuStyle):
     15        (WebCore::PopupMenuStyle::menuSize):
     16        * platform/mac/WebCoreSystemInterface.h: Pass in NSControlSize as a parameter
     17        to WKPopupMenu.
     18        * platform/mac/WebCoreSystemInterface.mm: Ditto.
     19        * rendering/RenderMenuList.cpp:
     20        (RenderMenuList::menuStyle): Ask the RenderTheme to calculate the size
     21        of the menu button, so that it can be added to the PopupMenuStyle.
     22        * rendering/RenderTheme.h: New method to retrieve the menu size.
     23        (WebCore::RenderTheme::popupMenuSize): Convert an NSControlSize into a PopupMenuSize.
     24        * rendering/RenderThemeMac.h: Override the base function, and add a
     25        controlSizeForCell helper.
     26        * rendering/RenderThemeMac.mm:
     27        (WebCore::RenderThemeMac::controlSizeForCell): Used by this new
     28        code and the old setControlSizeForCell to calculate the NSControlSize
     29        that would be used for the button.
     30        (WebCore::RenderThemeMac::setControlSize): Call the new helper.
     31        (WebCore::RenderThemeMac::popupMenuSize): Return the value from the helper.
     32
    1332014-04-25  Javier Fernandez  <jfernandez@igalia.com>
    234
  • trunk/Source/WebCore/WebCore.exp.in

    r167793 r167825  
    23142314_wkMeasureMediaUIPart
    23152315_wkPopupMenu
     2316_wkPopupMenuWithSize
    23162317_wkQTClearMediaDownloadCache
    23172318_wkQTClearMediaDownloadCacheForSite
  • trunk/Source/WebCore/platform/PopupMenuStyle.h

    r145406 r167825  
    3838    enum PopupMenuType { SelectPopup, AutofillPopup };
    3939    enum BackgroundColorType { DefaultBackgroundColor, CustomBackgroundColor };
    40     PopupMenuStyle(const Color& foreground, const Color& background, const Font& font, bool visible, bool isDisplayNone, Length textIndent, TextDirection textDirection, bool hasTextDirectionOverride, BackgroundColorType backgroundColorType = DefaultBackgroundColor, PopupMenuType menuType = SelectPopup)
     40    enum PopupMenuSize {
     41        PopupMenuSizeNormal,
     42        PopupMenuSizeSmall,
     43        PopupMenuSizeMini
     44    };
     45
     46    PopupMenuStyle(const Color& foreground, const Color& background, const Font& font, bool visible, bool isDisplayNone, Length textIndent, TextDirection textDirection, bool hasTextDirectionOverride, BackgroundColorType backgroundColorType = DefaultBackgroundColor, PopupMenuType menuType = SelectPopup, PopupMenuSize menuSize = PopupMenuSizeNormal)
    4147        : m_foregroundColor(foreground)
    4248        , m_backgroundColor(background)
     
    4955        , m_backgroundColorType(backgroundColorType)
    5056        , m_menuType(menuType)
     57        , m_menuSize(menuSize)
    5158    {
    5259    }
     
    6269    BackgroundColorType backgroundColorType() const { return m_backgroundColorType; }
    6370    PopupMenuType menuType() const { return m_menuType; }
     71    PopupMenuSize menuSize() const { return m_menuSize; }
     72
    6473private:
    6574    Color m_foregroundColor;
     
    7382    BackgroundColorType m_backgroundColorType;
    7483    PopupMenuType m_menuType;
     84    PopupMenuSize m_menuSize;
    7585};
    7686
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h

    r167609 r167825  
    197197extern void (*wkWindowSetAlpha)(NSWindow *, float);
    198198extern void (*wkWindowSetScaledFrame)(NSWindow *, NSRect, NSRect);
     199
    199200extern void (*wkPopupMenu)(NSMenu*, NSPoint location, float width, NSView*, int selectedItem, NSFont*);
     201#if defined(__OBJC__)
     202extern void (*wkPopupMenuWithSize)(NSMenu*, NSPoint location, float width, NSView*, int selectedItem, NSFont*, NSControlSize controlSize);
     203#endif
     204
    200205extern unsigned (*wkQTIncludeOnlyModernMediaFileTypes)(void);
    201206extern int (*wkQTMovieDataRate)(QTMovie*);
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm

    r167609 r167825  
    6868UInt8 (*wkGetNSEventKeyChar)(NSEvent *);
    6969void (*wkPopupMenu)(NSMenu*, NSPoint location, float width, NSView*, int selectedItem, NSFont*);
     70void (*wkPopupMenuWithSize)(NSMenu*, NSPoint location, float width, NSView*, int selectedItem, NSFont*, NSControlSize controlSize);
    7071unsigned (*wkQTIncludeOnlyModernMediaFileTypes)(void);
    7172int (*wkQTMovieDataRate)(QTMovie*);
  • trunk/Source/WebCore/rendering/RenderMenuList.cpp

    r164441 r167825  
    561561{
    562562    const RenderStyle& styleToUse = m_innerBlock ? m_innerBlock->style() : style();
    563     return PopupMenuStyle(styleToUse.visitedDependentColor(CSSPropertyColor), styleToUse.visitedDependentColor(CSSPropertyBackgroundColor), styleToUse.font(), styleToUse.visibility() == VISIBLE,
    564         styleToUse.display() == NONE, styleToUse.textIndent(), style().direction(), isOverride(style().unicodeBidi()));
     563    IntRect absBounds = absoluteBoundingBoxRectIgnoringTransforms();
     564    return PopupMenuStyle(styleToUse.visitedDependentColor(CSSPropertyColor), styleToUse.visitedDependentColor(CSSPropertyBackgroundColor),
     565        styleToUse.font(), styleToUse.visibility() == VISIBLE, styleToUse.display() == NONE, styleToUse.textIndent(),
     566        style().direction(), isOverride(style().unicodeBidi()), PopupMenuStyle::DefaultBackgroundColor,
     567        PopupMenuStyle::SelectPopup, theme().popupMenuSize(&styleToUse, absBounds));
    565568}
    566569
  • trunk/Source/WebCore/rendering/RenderTheme.h

    r167786 r167825  
    3030#include "ThemeTypes.h"
    3131#endif
     32#include "PopupMenuStyle.h"
    3233#include "RenderObject.h"
    3334#include "ScrollTypes.h"
     
    185186    virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; }
    186187    virtual bool popupOptionSupportsTextIndent() const { return false; }
     188    virtual PopupMenuStyle::PopupMenuSize popupMenuSize(const RenderStyle*, IntRect&) const { return PopupMenuStyle::PopupMenuSizeNormal; }
    187189
    188190    virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; }
  • trunk/Source/WebCore/rendering/RenderThemeMac.h

    r167786 r167825  
    8282    virtual int popupInternalPaddingTop(RenderStyle*) const;
    8383    virtual int popupInternalPaddingBottom(RenderStyle*) const;
     84    virtual PopupMenuStyle::PopupMenuSize popupMenuSize(const RenderStyle*, IntRect&) const;
    8485
    8586    virtual bool paintCapsLockIndicator(const RenderObject&, const PaintInfo&, const IntRect&) override;
     
    180181    NSControlSize controlSizeForFont(RenderStyle*) const;
    181182    NSControlSize controlSizeForSystemFont(RenderStyle*) const;
     183    NSControlSize controlSizeForCell(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f) const;
    182184    void setControlSize(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel = 1.0f);
    183185    void setSizeFromFont(RenderStyle*, const IntSize* sizes) const;
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r167786 r167825  
    741741}
    742742
     743NSControlSize RenderThemeMac::controlSizeForCell(NSCell*, const IntSize* sizes, const IntSize& minSize, float zoomLevel) const
     744{
     745    if (minSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomLevel)
     746        && minSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height() * zoomLevel))
     747        return NSRegularControlSize;
     748
     749    if (minSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width() * zoomLevel)
     750        && minSize.height() >= static_cast<int>(sizes[NSSmallControlSize].height() * zoomLevel))
     751        return NSSmallControlSize;
     752
     753    return NSMiniControlSize;
     754}
     755
    743756void RenderThemeMac::setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minSize, float zoomLevel)
    744757{
    745     NSControlSize size;
    746     if (minSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomLevel) &&
    747         minSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height() * zoomLevel))
    748         size = NSRegularControlSize;
    749     else if (minSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width() * zoomLevel) &&
    750              minSize.height() >= static_cast<int>(sizes[NSSmallControlSize].height() * zoomLevel))
    751         size = NSSmallControlSize;
    752     else
    753         size = NSMiniControlSize;
     758    NSControlSize size = controlSizeForCell(cell, sizes, minSize, zoomLevel);
    754759    if (size != [cell controlSize]) // Only update if we have to, since AppKit does work even if the size is the same.
    755760        [cell setControlSize:size];
     
    13841389}
    13851390
     1391PopupMenuStyle::PopupMenuSize RenderThemeMac::popupMenuSize(const RenderStyle* style, IntRect& rect) const
     1392{
     1393    NSPopUpButtonCell* popupButton = this->popupButton();
     1394    NSControlSize size = controlSizeForCell(popupButton, popupButtonSizes(), rect.size(), style->effectiveZoom());
     1395    switch (size) {
     1396    case NSRegularControlSize:
     1397        return PopupMenuStyle::PopupMenuSizeNormal;
     1398    case NSSmallControlSize:
     1399        return PopupMenuStyle::PopupMenuSizeSmall;
     1400    case NSMiniControlSize:
     1401        return PopupMenuStyle::PopupMenuSizeMini;
     1402    default:
     1403        return PopupMenuStyle::PopupMenuSizeNormal;
     1404    }
     1405}
     1406
    13861407void RenderThemeMac::adjustMenuListButtonStyle(StyleResolver*, RenderStyle* style, Element*) const
    13871408{
  • trunk/Source/WebKit/mac/ChangeLog

    r167788 r167825  
     12014-04-25  Dean Jackson  <dino@apple.com>
     2
     3        Allow a platform-specific size enumeration to be passed into popup-menu display
     4        https://bugs.webkit.org/show_bug.cgi?id=132195
     5
     6        Reviewed by Brent Fulgham. With some in-person review comments from Sam Weinig.
     7
     8        Platforms like OS X use a set of predefined sizes for built-in controls
     9        used for <select>: normal, small and mini. Expose that information to
     10        the PopupMenuClient via the PopupMenuStyle, allowing it to be passed
     11        into the platform code in WebKitSystemInterface.
     12
     13        * WebCoreSupport/PopupMenuMac.mm:
     14        (PopupMenuMac::show): Convert the WebCore menu size type into the
     15        WebCoreSystemInterface type.
     16
    1172014-04-24  Commit Queue  <commit-queue@webkit.org>
    218
  • trunk/Source/WebKit/mac/WebCoreSupport/PopupMenuMac.mm

    r162929 r167825  
    192192    }
    193193
    194     wkPopupMenu(menu, location, roundf(NSWidth(r)), dummyView.get(), index, font);
     194    NSControlSize controlSize;
     195    switch (m_client->menuStyle().menuSize()) {
     196    case PopupMenuStyle::PopupMenuSizeNormal:
     197        controlSize = NSRegularControlSize;
     198        break;
     199    case PopupMenuStyle::PopupMenuSizeSmall:
     200        controlSize = NSSmallControlSize;
     201        break;
     202    case PopupMenuStyle::PopupMenuSizeMini:
     203        controlSize = NSMiniControlSize;
     204        break;
     205    }
     206
     207    wkPopupMenuWithSize(menu, location, roundf(NSWidth(r)), dummyView.get(), index, font, controlSize);
    195208
    196209    [m_popup dismissPopUp];
  • trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm

    r167609 r167825  
    9494    INIT(WindowSetScaledFrame);
    9595    INIT(PopupMenu);
     96    INIT(PopupMenuWithSize);
    9697    INIT(SetCGFontRenderingMode);
    9798#endif
  • trunk/Source/WebKit2/ChangeLog

    r167822 r167825  
     12014-04-25  Dean Jackson  <dino@apple.com>
     2
     3        Allow a platform-specific size enumeration to be passed into popup-menu display
     4        https://bugs.webkit.org/show_bug.cgi?id=132195
     5
     6        Reviewed by Brent Fulgham. With some in-person review comments from Sam Weinig.
     7
     8        Platforms like OS X use a set of predefined sizes for built-in controls
     9        used for <select>: normal, small and mini. Expose that information to
     10        the PopupMenuClient via the PopupMenuStyle, allowing it to be passed
     11        into the platform code in WebKitSystemInterface.
     12
     13        * Shared/PlatformPopupMenuData.cpp: Encode and decode the PopupMenuSize enum.
     14        (WebKit::PlatformPopupMenuData::encode):
     15        (WebKit::PlatformPopupMenuData::decode):
     16        * Shared/PlatformPopupMenuData.h: Add PopupMenuSize member variable.
     17        * UIProcess/mac/WebPopupMenuProxyMac.mm:
     18        (WebKit::WebPopupMenuProxyMac::showPopupMenu): Convert the PopupMenuSize
     19        into a WKControlSize, and pass that into WKPopupMenu.
     20        * WebProcess/WebCoreSupport/mac/WebPopupMenuMac.mm:
     21        (WebKit::WebPopupMenu::setUpPlatformData): Add the PopupMenuSize to
     22        the PlatformPopupMenuData.
     23
    1242014-04-25  Tim Horton  <timothy_horton@apple.com>
    225
  • trunk/Source/WebKit2/Shared/PlatformPopupMenuData.cpp

    r163886 r167825  
    4040    encoder << fontInfo;
    4141    encoder << shouldPopOver;
     42    encoder.encodeEnum(menuSize);
    4243#else
    4344    UNUSED_PARAM(encoder);
     
    5253    if (!decoder.decode(data.shouldPopOver))
    5354        return false;
     55    if (!decoder.decodeEnum(data.menuSize))
     56        return false;
    5457#else
    5558    UNUSED_PARAM(decoder);
  • trunk/Source/WebKit2/Shared/PlatformPopupMenuData.h

    r163886 r167825  
    2929#include "FontInfo.h"
    3030#include "ShareableBitmap.h"
     31#include <WebCore/PopupMenuStyle.h>
    3132#include <wtf/text/WTFString.h>
    3233
     
    4748    FontInfo fontInfo;
    4849    bool shouldPopOver;
     50    WebCore::PopupMenuStyle::PopupMenuSize menuSize;
    4951#endif
    5052};
  • trunk/Source/WebKit2/UIProcess/mac/WebPopupMenuProxyMac.mm

    r162505 r167825  
    135135    location = [dummyView convertPoint:location fromView:m_webView];
    136136
    137     WKPopupMenu(menu, location, roundf(NSWidth(rect)), dummyView.get(), selectedIndex, font);
     137    NSControlSize controlSize;
     138    switch (data.menuSize) {
     139    case WebCore::PopupMenuStyle::PopupMenuSizeNormal:
     140        controlSize = NSRegularControlSize;
     141        break;
     142    case WebCore::PopupMenuStyle::PopupMenuSizeSmall:
     143        controlSize = NSSmallControlSize;
     144        break;
     145    case WebCore::PopupMenuStyle::PopupMenuSizeMini:
     146        controlSize = NSMiniControlSize;
     147        break;
     148    }
     149
     150    WKPopupMenuWithSize(menu, location, roundf(NSWidth(rect)), dummyView.get(), selectedIndex, font, controlSize);
    138151
    139152    [m_popup dismissPopUp];
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebPopupMenuMac.mm

    r117085 r167825  
    5050    data.fontInfo.fontAttributeDictionary = fontDescriptorAttributes;
    5151    data.shouldPopOver = m_popupClient->shouldPopOver();
     52    data.menuSize = m_popupClient->menuStyle().menuSize();
    5253#else
    5354    UNUSED_PARAM(data);
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm

    r167609 r167825  
    9090        INIT(MeasureMediaUIPart);
    9191        INIT(PopupMenu);
     92        INIT(PopupMenuWithSize);
    9293        INIT(QTIncludeOnlyModernMediaFileTypes);
    9394        INIT(QTMovieDataRate);
Note: See TracChangeset for help on using the changeset viewer.