⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 188386 in webkit


Ignore:
Timestamp:
Aug 13, 2015, 10:37:27 AM (11 years ago)
Author:
andersca@apple.com
Message:

Use WTF::Optional in WindowFeatures
https://bugs.webkit.org/show_bug.cgi?id=147956

Reviewed by Sam Weinig.

Source/WebCore:

  • loader/FrameLoader.cpp:

(WebCore::createWindow):

  • page/WindowFeatures.cpp:

(WebCore::WindowFeatures::WindowFeatures):
(WebCore::WindowFeatures::setWindowFeature):
(WebCore::WindowFeatures::boolFeature):
(WebCore::WindowFeatures::floatFeature):
(WebCore::WindowFeatures::parseDialogFeatures):

  • page/WindowFeatures.h:

(WebCore::WindowFeatures::WindowFeatures):

Source/WebKit/mac:

  • WebCoreSupport/WebChromeClient.mm:

(WebChromeClient::createWindow):

Source/WebKit/win:

  • WebCoreSupport/WebChromeClient.cpp:

(createWindowFeaturesPropertyBag):

Source/WebKit2:

  • Shared/WebCoreArgumentCoders.cpp:

(IPC::ArgumentCoder<WindowFeatures>::encode): Deleted.
(IPC::ArgumentCoder<WindowFeatures>::decode): Deleted.

  • UIProcess/API/C/WKPage.cpp:

(WKPageSetPageUIClient):

  • UIProcess/API/Cocoa/WKWindowFeatures.mm:

(-[WKWindowFeatures _initWithWindowFeatures:]):

Source/WTF:

Add new operators to WTF::Optional to make it more like std::optional.

  • wtf/Optional.h:

(WTF::Optional::operator->):
(WTF::Optional::operator*):

Location:
trunk/Source
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r188374 r188386  
     12015-08-12  Anders Carlsson  <andersca@apple.com>
     2
     3        Use WTF::Optional in WindowFeatures
     4        https://bugs.webkit.org/show_bug.cgi?id=147956
     5
     6        Reviewed by Sam Weinig.
     7
     8        Add new operators to WTF::Optional to make it more like std::optional.
     9
     10        * wtf/Optional.h:
     11        (WTF::Optional::operator->):
     12        (WTF::Optional::operator*):
     13
    1142015-08-12  Filip Pizlo  <fpizlo@apple.com>
    215
  • trunk/Source/WTF/wtf/Optional.h

    r182254 r188386  
    134134    explicit operator bool() const { return m_isEngaged; }
    135135
     136    const T* operator->() const
     137    {
     138        ASSERT(m_isEngaged);
     139        return asPtr()->operator->();
     140    }
     141
     142    T* operator->()
     143    {
     144        ASSERT(m_isEngaged);
     145        return asPtr()->operator->();
     146    }
     147
     148    const T& operator*() const { return value(); }
     149    T& operator*() { return value(); }
     150
    136151    T& value()
    137152    {
  • trunk/Source/WebCore/ChangeLog

    r188385 r188386  
     12015-08-12  Anders Carlsson  <andersca@apple.com>
     2
     3        Use WTF::Optional in WindowFeatures
     4        https://bugs.webkit.org/show_bug.cgi?id=147956
     5
     6        Reviewed by Sam Weinig.
     7
     8        * loader/FrameLoader.cpp:
     9        (WebCore::createWindow):
     10        * page/WindowFeatures.cpp:
     11        (WebCore::WindowFeatures::WindowFeatures):
     12        (WebCore::WindowFeatures::setWindowFeature):
     13        (WebCore::WindowFeatures::boolFeature):
     14        (WebCore::WindowFeatures::floatFeature):
     15        (WebCore::WindowFeatures::parseDialogFeatures):
     16        * page/WindowFeatures.h:
     17        (WebCore::WindowFeatures::WindowFeatures):
     18
    1192015-08-13  Matthew Daiter  <mdaiter@apple.com>
    220
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r187962 r188386  
    35523552    FloatSize viewportSize = page->chrome().pageRect().size();
    35533553    FloatRect windowRect = page->chrome().windowRect();
    3554     if (features.xSet)
    3555         windowRect.setX(features.x);
    3556     if (features.ySet)
    3557         windowRect.setY(features.y);
     3554    if (features.x)
     3555        windowRect.setX(*features.x);
     3556    if (features.y)
     3557        windowRect.setY(*features.y);
    35583558    // Zero width and height mean using default size, not minumum one.
    3559     if (features.widthSet && features.width)
    3560         windowRect.setWidth(features.width + (windowRect.width() - viewportSize.width()));
    3561     if (features.heightSet && features.height)
    3562         windowRect.setHeight(features.height + (windowRect.height() - viewportSize.height()));
     3559    if (features.width && *features.width)
     3560        windowRect.setWidth(*features.width + (windowRect.width() - viewportSize.width()));
     3561    if (features.height && *features.height)
     3562        windowRect.setHeight(*features.height + (windowRect.height() - viewportSize.height()));
    35633563
    35643564    // Ensure non-NaN values, minimum size as well as being within valid screen area.
     
    35723572    ViewportArguments arguments;
    35733573    // Zero width and height mean using default size, not minimum one.
    3574     if (features.widthSet && features.width)
    3575         arguments.width = features.width;
    3576     if (features.heightSet && features.height)
    3577         arguments.height = features.height;
     3574    if (features.width && *features.width)
     3575        arguments.width = *features.width;
     3576    if (features.height && *features.height)
     3577        arguments.height = *features.height;
    35783578    frame->setViewportArguments(arguments);
    35793579#endif
  • trunk/Source/WebCore/page/WindowFeatures.cpp

    r185167 r188386  
    3838
    3939WindowFeatures::WindowFeatures(const String& features)
    40     : x(0)
    41     , xSet(false)
    42     , y(0)
    43     , ySet(false)
    44     , width(0)
    45     , widthSet(false)
    46     , height(0)
    47     , heightSet(false)
    48     , resizable(true)
     40    : resizable(true)
    4941    , fullscreen(false)
    5042    , dialog(false)
     
    135127    // This is consistent with Firefox, but could also be handled at another level.
    136128
    137     if (keyString == "left" || keyString == "screenx") {
    138         xSet = true;
     129    if (keyString == "left" || keyString == "screenx")
    139130        x = value;
    140     } else if (keyString == "top" || keyString == "screeny") {
    141         ySet = true;
     131    else if (keyString == "top" || keyString == "screeny")
    142132        y = value;
    143     } else if (keyString == "width" || keyString == "innerwidth") {
    144         widthSet = true;
     133    else if (keyString == "width" || keyString == "innerwidth")
    145134        width = value;
    146     } else if (keyString == "height" || keyString == "innerheight") {
    147         heightSet = true;
     135    else if (keyString == "height" || keyString == "innerheight")
    148136        height = value;
    149     } else if (keyString == "menubar")
     137    else if (keyString == "menubar")
    150138        menuBarVisible = value;
    151139    else if (keyString == "toolbar")
     
    164152
    165153WindowFeatures::WindowFeatures(const String& dialogFeaturesString, const FloatRect& screenAvailableRect)
    166     : widthSet(true)
    167     , heightSet(true)
    168     , menuBarVisible(false)
     154    : menuBarVisible(false)
    169155    , toolBarVisible(false)
    170156    , locationBarVisible(false)
     
    172158    , dialog(true)
    173159{
    174     DialogFeaturesMap features;
    175     parseDialogFeatures(dialogFeaturesString, features);
     160    auto features = parseDialogFeatures(dialogFeaturesString);
    176161
    177162    const bool trusted = false;
     
    188173    height = floatFeature(features, "dialogheight", 100, screenAvailableRect.height(), 450); // default here came from frame size of dialog in MacIE
    189174
    190     x = floatFeature(features, "dialogleft", screenAvailableRect.x(), screenAvailableRect.maxX() - width, -1);
    191     xSet = x > 0;
    192     y = floatFeature(features, "dialogtop", screenAvailableRect.y(), screenAvailableRect.maxY() - height, -1);
    193     ySet = y > 0;
     175    auto dialogLeft = floatFeature(features, "dialogleft", screenAvailableRect.x(), screenAvailableRect.maxX() - *width, -1);
     176    if (dialogLeft > 0)
     177        x = dialogLeft;
     178
     179    auto dialogTop = floatFeature(features, "dialogtop", screenAvailableRect.y(), screenAvailableRect.maxY() - *height, -1);
     180    if (dialogTop > 0)
     181        y = dialogTop;
    194182
    195183    if (boolFeature(features, "center", true)) {
    196         if (!xSet) {
    197             x = screenAvailableRect.x() + (screenAvailableRect.width() - width) / 2;
    198             xSet = true;
    199         }
    200         if (!ySet) {
    201             y = screenAvailableRect.y() + (screenAvailableRect.height() - height) / 2;
    202             ySet = true;
    203         }
     184        if (!x)
     185            x = screenAvailableRect.x() + (screenAvailableRect.width() - *width) / 2;
     186
     187        if (!y)
     188            y = screenAvailableRect.y() + (screenAvailableRect.height() - *height) / 2;
    204189    }
    205190
     
    209194}
    210195
    211 bool WindowFeatures::boolFeature(const DialogFeaturesMap& features, const char* key, bool defaultValue)
    212 {
    213     DialogFeaturesMap::const_iterator it = features.find(key);
     196bool WindowFeatures::boolFeature(const HashMap<String, String>& features, const char* key, bool defaultValue)
     197{
     198    auto it = features.find(key);
    214199    if (it == features.end())
    215200        return defaultValue;
     201
    216202    const String& value = it->value;
    217203    return value.isNull() || value == "1" || value == "yes" || value == "on";
    218204}
    219205
    220 float WindowFeatures::floatFeature(const DialogFeaturesMap& features, const char* key, float min, float max, float defaultValue)
    221 {
    222     DialogFeaturesMap::const_iterator it = features.find(key);
     206float WindowFeatures::floatFeature(const HashMap<String, String>& features, const char* key, float min, float max, float defaultValue)
     207{
     208    auto it = features.find(key);
    223209    if (it == features.end())
    224210        return defaultValue;
     211
    225212    // FIXME: The toDouble function does not offer a way to tell "0q" from string with no digits in it: Both
    226213    // return the number 0 and false for ok. But "0q" should yield the minimum rather than the default.
     
    233220    if (parsedNumber > max)
    234221        return max;
     222
    235223    // FIXME: Seems strange to cast a double to int and then convert back to a float. Why is this a good idea?
    236224    return static_cast<int>(parsedNumber);
    237225}
    238226
    239 void WindowFeatures::parseDialogFeatures(const String& string, DialogFeaturesMap& map)
    240 {
     227HashMap<String, String> WindowFeatures::parseDialogFeatures(const String& string)
     228{
     229    HashMap<String, String> features;
     230
    241231    Vector<String> vector;
    242232    string.split(';', vector);
     233
    243234    for (auto& featureString : vector) {
    244235        size_t separatorPosition = featureString.find('=');
     
    258249        }
    259250
    260         map.set(key, value);
    261     }
     251        features.set(key, value);
     252    }
     253
     254    return features;
    262255}
    263256
  • trunk/Source/WebCore/page/WindowFeatures.h

    r166072 r188386  
    3030#define WindowFeatures_h
    3131
     32#include <wtf/Forward.h>
    3233#include <wtf/HashMap.h>
    33 #include <wtf/text/WTFString.h>
     34#include <wtf/Optional.h>
     35#include <wtf/Vector.h>
     36#include <wtf/text/StringHash.h>
    3437
    3538namespace WebCore {
     
    3942struct WindowFeatures {
    4043    WindowFeatures()
    41         : x(0)
    42         , xSet(false)
    43         , y(0)
    44         , ySet(false)
    45         , width(0)
    46         , widthSet(false)
    47         , height(0)
    48         , heightSet(false)
    49         , menuBarVisible(true)
     44        : menuBarVisible(true)
    5045        , statusBarVisible(true)
    5146        , toolBarVisible(true)
     
    6055    WindowFeatures(const String& dialogFeaturesString, const FloatRect& screenAvailableRect);
    6156
    62     float x;
    63     bool xSet;
    64     float y;
    65     bool ySet;
    66     float width;
    67     bool widthSet;
    68     float height;
    69     bool heightSet;
     57    Optional<float> x;
     58    Optional<float> y;
     59    Optional<float> width;
     60    Optional<float> height;
    7061
    7162    bool menuBarVisible;
     
    8273
    8374private:
    84     typedef HashMap<String, String> DialogFeaturesMap;
    85     static void parseDialogFeatures(const String&, HashMap<String, String>&);
    86     static bool boolFeature(const DialogFeaturesMap&, const char* key, bool defaultValue = false);
    87     static float floatFeature(const DialogFeaturesMap&, const char* key, float min, float max, float defaultValue);
     75    static HashMap<String, String> parseDialogFeatures(const String&);
     76    static bool boolFeature(const HashMap<String, String>&, const char* key, bool defaultValue = false);
     77    static float floatFeature(const HashMap<String, String>&, const char* key, float min, float max, float defaultValue);
    8878    void setWindowFeature(const String& keyString, const String& valueString);
    8979};
  • trunk/Source/WebKit/mac/ChangeLog

    r188385 r188386  
     12015-08-12  Anders Carlsson  <andersca@apple.com>
     2
     3        Use WTF::Optional in WindowFeatures
     4        https://bugs.webkit.org/show_bug.cgi?id=147956
     5
     6        Reviewed by Sam Weinig.
     7
     8        * WebCoreSupport/WebChromeClient.mm:
     9        (WebChromeClient::createWindow):
     10
    1112015-08-13  Matthew Daiter  <mdaiter@apple.com>
    212
  • trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm

    r187002 r188386  
    241241   
    242242    if ([delegate respondsToSelector:@selector(webView:createWebViewWithRequest:windowFeatures:)]) {
    243         NSNumber *x = features.xSet ? [[NSNumber alloc] initWithFloat:features.x] : nil;
    244         NSNumber *y = features.ySet ? [[NSNumber alloc] initWithFloat:features.y] : nil;
    245         NSNumber *width = features.widthSet ? [[NSNumber alloc] initWithFloat:features.width] : nil;
    246         NSNumber *height = features.heightSet ? [[NSNumber alloc] initWithFloat:features.height] : nil;
     243        NSNumber *x = features.x ? [[NSNumber alloc] initWithFloat:*features.x] : nil;
     244        NSNumber *y = features.y ? [[NSNumber alloc] initWithFloat:*features.y] : nil;
     245        NSNumber *width = features.width ? [[NSNumber alloc] initWithFloat:*features.width] : nil;
     246        NSNumber *height = features.height ? [[NSNumber alloc] initWithFloat:*features.height] : nil;
    247247        NSNumber *menuBarVisible = [[NSNumber alloc] initWithBool:features.menuBarVisible];
    248248        NSNumber *statusBarVisible = [[NSNumber alloc] initWithBool:features.statusBarVisible];
  • trunk/Source/WebKit/win/ChangeLog

    r188215 r188386  
     12015-08-12  Anders Carlsson  <andersca@apple.com>
     2
     3        Use WTF::Optional in WindowFeatures
     4        https://bugs.webkit.org/show_bug.cgi?id=147956
     5
     6        Reviewed by Sam Weinig.
     7
     8        * WebCoreSupport/WebChromeClient.cpp:
     9        (createWindowFeaturesPropertyBag):
     10
    1112015-08-10  Per Arne Vollan  <peavo@outlook.com>
    212
  • trunk/Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp

    r187002 r188386  
    171171{
    172172    HashMap<String, COMVariant> map;
    173     if (features.xSet)
    174         map.set(WebWindowFeaturesXKey, features.x);
    175     if (features.ySet)
    176         map.set(WebWindowFeaturesYKey, features.y);
    177     if (features.widthSet)
    178         map.set(WebWindowFeaturesWidthKey, features.width);
    179     if (features.heightSet)
    180         map.set(WebWindowFeaturesHeightKey, features.height);
     173    if (features.x)
     174        map.set(WebWindowFeaturesXKey, *features.x);
     175    if (features.y)
     176        map.set(WebWindowFeaturesYKey, *features.y);
     177    if (features.width)
     178        map.set(WebWindowFeaturesWidthKey, *features.width);
     179    if (features.height)
     180        map.set(WebWindowFeaturesHeightKey, *features.height);
    181181    map.set(WebWindowFeaturesMenuBarVisibleKey, features.menuBarVisible);
    182182    map.set(WebWindowFeaturesStatusBarVisibleKey, features.statusBarVisible);
  • trunk/Source/WebKit2/ChangeLog

    r188385 r188386  
     12015-08-12  Anders Carlsson  <andersca@apple.com>
     2
     3        Use WTF::Optional in WindowFeatures
     4        https://bugs.webkit.org/show_bug.cgi?id=147956
     5
     6        Reviewed by Sam Weinig.
     7
     8        * Shared/WebCoreArgumentCoders.cpp:
     9        (IPC::ArgumentCoder<WindowFeatures>::encode): Deleted.
     10        (IPC::ArgumentCoder<WindowFeatures>::decode): Deleted.
     11        * UIProcess/API/C/WKPage.cpp:
     12        (WKPageSetPageUIClient):
     13        * UIProcess/API/Cocoa/WKWindowFeatures.mm:
     14        (-[WKWindowFeatures _initWithWindowFeatures:]):
     15
    1162015-08-13  Matthew Daiter  <mdaiter@apple.com>
    217
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

    r188115 r188386  
    957957    encoder << windowFeatures.width;
    958958    encoder << windowFeatures.height;
    959     encoder << windowFeatures.xSet;
    960     encoder << windowFeatures.ySet;
    961     encoder << windowFeatures.widthSet;
    962     encoder << windowFeatures.heightSet;
    963959    encoder << windowFeatures.menuBarVisible;
    964960    encoder << windowFeatures.statusBarVisible;
     
    980976        return false;
    981977    if (!decoder.decode(windowFeatures.height))
    982         return false;
    983     if (!decoder.decode(windowFeatures.xSet))
    984         return false;
    985     if (!decoder.decode(windowFeatures.ySet))
    986         return false;
    987     if (!decoder.decode(windowFeatures.widthSet))
    988         return false;
    989     if (!decoder.decode(windowFeatures.heightSet))
    990978        return false;
    991979    if (!decoder.decode(windowFeatures.menuBarVisible))
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r188348 r188386  
    13511351
    13521352            API::Dictionary::MapType map;
    1353             if (windowFeatures.xSet)
    1354                 map.set("x", API::Double::create(windowFeatures.x));
    1355             if (windowFeatures.ySet)
    1356                 map.set("y", API::Double::create(windowFeatures.y));
    1357             if (windowFeatures.widthSet)
    1358                 map.set("width", API::Double::create(windowFeatures.width));
    1359             if (windowFeatures.heightSet)
    1360                 map.set("height", API::Double::create(windowFeatures.height));
     1353            if (windowFeatures.x)
     1354                map.set("x", API::Double::create(*windowFeatures.x));
     1355            if (windowFeatures.y)
     1356                map.set("y", API::Double::create(*windowFeatures.y));
     1357            if (windowFeatures.width)
     1358                map.set("width", API::Double::create(*windowFeatures.width));
     1359            if (windowFeatures.height)
     1360                map.set("height", API::Double::create(*windowFeatures.height));
    13611361            map.set("menuBarVisible", API::Boolean::create(windowFeatures.menuBarVisible));
    13621362            map.set("statusBarVisible", API::Boolean::create(windowFeatures.statusBarVisible));
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWindowFeatures.mm

    r166267 r188386  
    5656    _allowsResizing = @(windowFeatures.resizable);
    5757
    58     if (windowFeatures.xSet)
    59         _x = @(windowFeatures.x);
    60     if (windowFeatures.ySet)
    61         _y = @(windowFeatures.y);
    62     if (windowFeatures.widthSet)
    63         _width = @(windowFeatures.width);
    64     if (windowFeatures.heightSet)
    65         _height = @(windowFeatures.height);
     58    if (windowFeatures.x)
     59        _x = @(*windowFeatures.x);
     60    if (windowFeatures.y)
     61        _y = @(*windowFeatures.y);
     62    if (windowFeatures.width)
     63        _width = @(*windowFeatures.width);
     64    if (windowFeatures.height)
     65        _height = @(*windowFeatures.height);
    6666
    6767    return self;
Note: See TracChangeset for help on using the changeset viewer.