[Git][wxwidgets/wxwidgets][master] 3 commits: Edge GetZoomFactor() should return 1.0 on failure, not 0.0

2 views
Skip to first unread message

Vadim Zeitlin (@_VZ_)

unread,
Aug 15, 2026, 12:44:48 PMAug 15
to wx-commi...@googlegroups.com

Vadim Zeitlin pushed to branch master at wxWidgets / wxWidgets

Commits:

  • ca1f168c
    by Blake-Madden at 2026-08-15T18:17:23+02:00
    Edge GetZoomFactor() should return 1.0 on failure, not 0.0
    
    Also, add missing pointer checks
    
    Closes #26835.
    
  • 04bb7e30
    by Richard at 2026-08-15T18:24:55+02:00
    Respect swapped mouse buttons in wxUIActionSimulator
    
    On MSW, translate logical left and right mouse buttons to their physical
    buttons before passing them to mouse_event(). This keeps MouseClick() as
    a primary-button click and MouseClick(wxMOUSE_BTN_RIGHT) as a secondary
    click when the user swaps the mouse buttons.
    
    Document this behavior for GUI tests.
    
    Closes #26833.
    
  • 01fdfa2b
    by Blake-Madden at 2026-08-15T18:25:56+02:00
    Use wxGtkObject instead of manual memory management in WebKit2
    
    Modernize/simplify code, no real changes.
    
    Closes #26836.
    

4 changed files:

Changes:

  • docs/contributing/how-to-write-unit-tests.md
    ... ... @@ -96,6 +96,10 @@ clicking buttons or typing text. A simple example of this can be found in
    96 96
     `tests/controls/buttontest.cpp`. After simulating some user input always
    
    97 97
     call `wxYield()` to allow event processing. When writing a test using
    
    98 98
     `wxUIActionSimulator` wrap it in `#if wxUSE_UIACTIONSIMULATOR` block.
    
    99
    +On MSW, `wxUIActionSimulator` respects the user's swapped mouse-button
    
    100
    +configuration, so `MouseClick()` still produces a primary-button click,
    
    101
    +while `MouseClick(wxMOUSE_BTN_RIGHT)` still produces a secondary-button
    
    102
    +click.
    
    99 103
     
    
    100 104
     There are a number of classes that are available to help with testing GUI
    
    101 105
     elements. Firstly throughout the test run there is a frame of type
    

  • src/gtk/webview_webkit2.cpp
    ... ... @@ -507,12 +507,10 @@ wxgtk_webview_webkit_uri_scheme_request_cb(WebKitURISchemeRequest *request,
    507 507
                 gint64 length = file->GetStream()->GetLength();
    
    508 508
                 guint8 *data = g_new(guint8, length);
    
    509 509
                 file->GetStream()->Read(data, length);
    
    510
    -            GInputStream *stream = g_memory_input_stream_new_from_data(data,
    
    511
    -                                                                       length,
    
    512
    -                                                                       g_free);
    
    510
    +            wxGtkObject<GInputStream>
    
    511
    +                stream(g_memory_input_stream_new_from_data(data, length, g_free));
    
    513 512
                 wxString mime = file->GetMimeType();
    
    514 513
                 webkit_uri_scheme_request_finish(request, stream, length, mime.utf8_str());
    
    515
    -            g_object_unref(stream);
    
    516 514
             }
    
    517 515
             else
    
    518 516
             {
    
    ... ... @@ -1239,15 +1237,15 @@ static void wxgtk_can_execute_editing_command_cb(GObject*,
    1239 1237
     
    
    1240 1238
     bool wxWebViewWebKit::CanExecuteEditingCommand(const gchar* command) const
    
    1241 1239
     {
    
    1242
    -    GAsyncResult *result = nullptr;
    
    1240
    +    wxGtkObject<GAsyncResult> result;
    
    1243 1241
         webkit_web_view_can_execute_editing_command(m_web_view,
    
    1244 1242
                                                     command,
    
    1245 1243
                                                     nullptr,
    
    1246 1244
                                                     wxgtk_can_execute_editing_command_cb,
    
    1247
    -                                                &result);
    
    1245
    +                                                result.Out());
    
    1248 1246
     
    
    1249 1247
         GMainContext *main_context = g_main_context_get_thread_default();
    
    1250
    -    while (!result)
    
    1248
    +    while (!result.get())
    
    1251 1249
         {
    
    1252 1250
             g_main_context_iteration(main_context, TRUE);
    
    1253 1251
         }
    
    ... ... @@ -1255,7 +1253,6 @@ bool wxWebViewWebKit::CanExecuteEditingCommand(const gchar* command) const
    1255 1253
         gboolean can_execute = webkit_web_view_can_execute_editing_command_finish(m_web_view,
    
    1256 1254
                                                                                   result,
    
    1257 1255
                                                                                   nullptr);
    
    1258
    -    g_object_unref(result);
    
    1259 1256
     
    
    1260 1257
         return can_execute != 0;
    
    1261 1258
     }
    
    ... ... @@ -1348,13 +1345,13 @@ wxString wxWebViewWebKit::GetPageSource() const
    1348 1345
             return wxString();
    
    1349 1346
         }
    
    1350 1347
     
    
    1351
    -    GAsyncResult *result = nullptr;
    
    1348
    +    wxGtkObject<GAsyncResult> result;
    
    1352 1349
         webkit_web_resource_get_data(resource, nullptr,
    
    1353 1350
                                      wxgtk_web_resource_get_data_cb,
    
    1354
    -                                 &result);
    
    1351
    +                                 result.Out());
    
    1355 1352
     
    
    1356 1353
         GMainContext *main_context = g_main_context_get_thread_default();
    
    1357
    -    while (!result)
    
    1354
    +    while (!result.get())
    
    1358 1355
         {
    
    1359 1356
             g_main_context_iteration(main_context, TRUE);
    
    1360 1357
         }
    
    ... ... @@ -1362,10 +1359,6 @@ wxString wxWebViewWebKit::GetPageSource() const
    1362 1359
         size_t length;
    
    1363 1360
         guchar *source = webkit_web_resource_get_data_finish(resource, result,
    
    1364 1361
                                                              &length, nullptr);
    
    1365
    -    if (result)
    
    1366
    -    {
    
    1367
    -        g_object_unref(result);
    
    1368
    -    }
    
    1369 1362
     
    
    1370 1363
         if (source)
    
    1371 1364
         {
    
    ... ... @@ -1420,9 +1413,8 @@ void wxWebViewWebKit::DoSetPage(const wxString& html, const wxString& baseUri)
    1420 1413
     
    
    1421 1414
     void wxWebViewWebKit::Print()
    
    1422 1415
     {
    
    1423
    -    WebKitPrintOperation* printop = webkit_print_operation_new(m_web_view);
    
    1416
    +    wxGtkObject<WebKitPrintOperation> printop(webkit_print_operation_new(m_web_view));
    
    1424 1417
         webkit_print_operation_run_dialog(printop, nullptr);
    
    1425
    -    g_object_unref(printop);
    
    1426 1418
     }
    
    1427 1419
     
    
    1428 1420
     #if wxUSE_PRINTING_ARCHITECTURE
    
    ... ... @@ -1536,11 +1528,10 @@ struct wxWebViewGtkPDFData
    1536 1528
                             const wxString& filePath_,
    
    1537 1529
                             WebKitPrintOperation* printop_)
    
    1538 1530
             : webView(webView_), filePath(filePath_), printop(printop_) {}
    
    1539
    -    ~wxWebViewGtkPDFData() { g_object_unref(printop); }
    
    1540 1531
     
    
    1541 1532
         wxWeakRef<wxWebViewWebKit> webView;
    
    1542 1533
         wxString filePath;
    
    1543
    -    WebKitPrintOperation* printop;
    
    1534
    +    wxGtkObject<WebKitPrintOperation> printop;
    
    1544 1535
     };
    
    1545 1536
     
    
    1546 1537
     static void wxDoHandlePDFResult(gpointer user_data, int success)
    
    ... ... @@ -1585,6 +1576,7 @@ static bool wxDoStartPDFPrint(wxWebViewWebKit* webView,
    1585 1576
         if (!uri)
    
    1586 1577
             return false;
    
    1587 1578
     
    
    1579
    +    // Not a wxGtkObject; ownership passes to wxWebViewGtkPDFData below
    
    1588 1580
         WebKitPrintOperation* printop = webkit_print_operation_new(
    
    1589 1581
             static_cast<WebKitWebView*>(webView->GetNativeBackend()));
    
    1590 1582
     
    

  • src/msw/uiaction.cpp
    ... ... @@ -54,9 +54,28 @@ private:
    54 54
         wxDECLARE_NO_COPY_CLASS(wxUIActionSimulatorMSWImpl);
    
    55 55
     };
    
    56 56
     
    
    57
    +int PhysicalButtonForLogicalButton(int button)
    
    58
    +{
    
    59
    +    if ( ::GetSystemMetrics(SM_SWAPBUTTON) )
    
    60
    +    {
    
    61
    +        switch ( button )
    
    62
    +        {
    
    63
    +            case wxMOUSE_BTN_LEFT:
    
    64
    +                return wxMOUSE_BTN_RIGHT;
    
    65
    +
    
    66
    +            case wxMOUSE_BTN_RIGHT:
    
    67
    +                return wxMOUSE_BTN_LEFT;
    
    68
    +        }
    
    69
    +    }
    
    70
    +
    
    71
    +    return button;
    
    72
    +}
    
    73
    +
    
    57 74
     DWORD EventTypeForMouseButton(int button, bool isDown)
    
    58 75
     {
    
    59
    -    switch (button)
    
    76
    +    // wxUIActionSimulator uses logical left/right buttons. mouse_event() needs
    
    77
    +    // the physical MSW button producing them when the user swaps buttons.
    
    78
    +    switch ( PhysicalButtonForLogicalButton(button) )
    
    60 79
         {
    
    61 80
             case wxMOUSE_BTN_LEFT:
    
    62 81
                 return isDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
    

  • src/msw/webview_edge.cpp
    ... ... @@ -1552,14 +1552,18 @@ bool wxWebViewEdge::PrintToPDF(const wxString& filePath, const wxPrintData& prin
    1552 1552
     
    
    1553 1553
     float wxWebViewEdge::GetZoomFactor() const
    
    1554 1554
     {
    
    1555
    -    double old_zoom_factor = 0.0;
    
    1556
    -    m_impl->m_webViewController->get_ZoomFactor(&old_zoom_factor);
    
    1557
    -    return old_zoom_factor;
    
    1555
    +    if ( !m_impl->m_webViewController )
    
    1556
    +        return 1.0f;
    
    1557
    +
    
    1558
    +    double zoomFactor = 1.0;
    
    1559
    +    m_impl->m_webViewController->get_ZoomFactor(&zoomFactor);
    
    1560
    +    return zoomFactor;
    
    1558 1561
     }
    
    1559 1562
     
    
    1560 1563
     void wxWebViewEdge::SetZoomFactor(float zoom)
    
    1561 1564
     {
    
    1562
    -    m_impl->m_webViewController->put_ZoomFactor(zoom);
    
    1565
    +    if ( m_impl->m_webViewController )
    
    1566
    +        m_impl->m_webViewController->put_ZoomFactor(zoom);
    
    1563 1567
     }
    
    1564 1568
     
    
    1565 1569
     bool wxWebViewEdge::CanUndo() const
    

Reply all
Reply to author
Forward
0 new messages