diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /widget/gtk | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/gtk')
-rw-r--r-- | widget/gtk/AsyncGtkClipboardRequest.cpp | 38 | ||||
-rw-r--r-- | widget/gtk/GfxInfo.cpp | 20 | ||||
-rw-r--r-- | widget/gtk/GtkCompositorWidget.cpp | 13 | ||||
-rw-r--r-- | widget/gtk/MozContainerWayland.cpp | 70 | ||||
-rw-r--r-- | widget/gtk/MozContainerWayland.h | 4 | ||||
-rw-r--r-- | widget/gtk/WidgetStyleCache.cpp | 9 | ||||
-rw-r--r-- | widget/gtk/WindowSurfaceProvider.cpp | 1 | ||||
-rw-r--r-- | widget/gtk/gtk3drawing.cpp | 103 | ||||
-rw-r--r-- | widget/gtk/gtkdrawing.h | 49 | ||||
-rw-r--r-- | widget/gtk/nsAppShell.cpp | 1 | ||||
-rw-r--r-- | widget/gtk/nsClipboard.cpp | 339 | ||||
-rw-r--r-- | widget/gtk/nsClipboard.h | 14 | ||||
-rw-r--r-- | widget/gtk/nsClipboardWayland.cpp | 21 | ||||
-rw-r--r-- | widget/gtk/nsClipboardX11.cpp | 25 | ||||
-rw-r--r-- | widget/gtk/nsDragService.cpp | 2 | ||||
-rw-r--r-- | widget/gtk/nsLookAndFeel.cpp | 8 | ||||
-rw-r--r-- | widget/gtk/nsNativeThemeGTK.cpp | 33 | ||||
-rw-r--r-- | widget/gtk/nsWaylandDisplay.cpp | 4 | ||||
-rw-r--r-- | widget/gtk/nsWindow.cpp | 185 | ||||
-rw-r--r-- | widget/gtk/nsWindow.h | 13 |
20 files changed, 420 insertions, 532 deletions
diff --git a/widget/gtk/AsyncGtkClipboardRequest.cpp b/widget/gtk/AsyncGtkClipboardRequest.cpp index 75801c698d..872b005bfd 100644 --- a/widget/gtk/AsyncGtkClipboardRequest.cpp +++ b/widget/gtk/AsyncGtkClipboardRequest.cpp @@ -17,17 +17,17 @@ AsyncGtkClipboardRequest::AsyncGtkClipboardRequest(ClipboardDataType aDataType, switch (aDataType) { case ClipboardDataType::Data: - LOGCLIP(" getting DATA MIME %s\n", aMimeType); + MOZ_CLIPBOARD_LOG(" getting DATA MIME %s\n", aMimeType); gtk_clipboard_request_contents(clipboard, gdk_atom_intern(aMimeType, FALSE), OnDataReceived, mRequest.get()); break; case ClipboardDataType::Text: - LOGCLIP(" getting TEXT\n"); + MOZ_CLIPBOARD_LOG(" getting TEXT\n"); gtk_clipboard_request_text(clipboard, OnTextReceived, mRequest.get()); break; case ClipboardDataType::Targets: - LOGCLIP(" getting TARGETS\n"); + MOZ_CLIPBOARD_LOG(" getting TARGETS\n"); gtk_clipboard_request_contents(clipboard, gdk_atom_intern("TARGETS", FALSE), OnDataReceived, mRequest.get()); @@ -39,9 +39,10 @@ void AsyncGtkClipboardRequest::OnDataReceived(GtkClipboard* clipboard, GtkSelectionData* selection_data, gpointer data) { int whichClipboard = GetGeckoClipboardType(clipboard); - LOGCLIP("OnDataReceived(%s) callback\n", - whichClipboard == nsClipboard::kSelectionClipboard ? "primary" - : "clipboard"); + MOZ_CLIPBOARD_LOG("OnDataReceived(%s) callback\n", + whichClipboard == nsClipboard::kSelectionClipboard + ? "primary" + : "clipboard"); static_cast<Request*>(data)->Complete(selection_data); } @@ -49,14 +50,16 @@ void AsyncGtkClipboardRequest::OnTextReceived(GtkClipboard* clipboard, const gchar* text, gpointer data) { int whichClipboard = GetGeckoClipboardType(clipboard); - LOGCLIP("OnTextReceived(%s) callback\n", - whichClipboard == nsClipboard::kSelectionClipboard ? "primary" - : "clipboard"); + MOZ_CLIPBOARD_LOG("OnTextReceived(%s) callback\n", + whichClipboard == nsClipboard::kSelectionClipboard + ? "primary" + : "clipboard"); static_cast<Request*>(data)->Complete(text); } void AsyncGtkClipboardRequest::Request::Complete(const void* aData) { - LOGCLIP("Request::Complete(), aData = %p, timedOut = %d\n", aData, mTimedOut); + MOZ_CLIPBOARD_LOG("Request::Complete(), aData = %p, timedOut = %d\n", aData, + mTimedOut); if (mTimedOut) { delete this; @@ -75,13 +78,14 @@ void AsyncGtkClipboardRequest::Request::Complete(const void* aData) { // Negative size means no data or data error. if (dataLength <= 0) { - LOGCLIP(" zero dataLength, quit.\n"); + MOZ_CLIPBOARD_LOG(" zero dataLength, quit.\n"); return; } switch (mDataType) { case ClipboardDataType::Targets: { - LOGCLIP(" getting %d bytes of clipboard targets.\n", dataLength); + MOZ_CLIPBOARD_LOG(" getting %d bytes of clipboard targets.\n", + dataLength); gint n_targets = 0; GdkAtom* targets = nullptr; if (!gtk_selection_data_get_targets((GtkSelectionData*)aData, &targets, @@ -95,16 +99,18 @@ void AsyncGtkClipboardRequest::Request::Complete(const void* aData) { break; } case ClipboardDataType::Text: { - LOGCLIP(" getting %d bytes of text.\n", dataLength); + MOZ_CLIPBOARD_LOG(" getting %d bytes of text.\n", dataLength); mData->SetText(Span(static_cast<const char*>(aData), dataLength)); - LOGCLIP(" done, mClipboardData = %p\n", mData->AsSpan().data()); + MOZ_CLIPBOARD_LOG(" done, mClipboardData = %p\n", + mData->AsSpan().data()); break; } case ClipboardDataType::Data: { - LOGCLIP(" getting %d bytes of data.\n", dataLength); + MOZ_CLIPBOARD_LOG(" getting %d bytes of data.\n", dataLength); mData->SetData(Span(gtk_selection_data_get_data((GtkSelectionData*)aData), dataLength)); - LOGCLIP(" done, mClipboardData = %p\n", mData->AsSpan().data()); + MOZ_CLIPBOARD_LOG(" done, mClipboardData = %p\n", + mData->AsSpan().data()); break; } } diff --git a/widget/gtk/GfxInfo.cpp b/widget/gtk/GfxInfo.cpp index 457b2c72ce..9c4faa26bb 100644 --- a/widget/gtk/GfxInfo.cpp +++ b/widget/gtk/GfxInfo.cpp @@ -1042,30 +1042,14 @@ const nsTArray<GfxDriverInfo>& GfxInfo::GetGfxDriverInfo() { //////////////////////////////////// // FEATURE_DMABUF_SURFACE_EXPORT - // Disabled due to: + // Disabled on all Mesa drivers due to various issue, among them: // https://gitlab.freedesktop.org/mesa/mesa/-/issues/6666 // https://gitlab.freedesktop.org/mesa/mesa/-/issues/6796 - APPEND_TO_DRIVER_BLOCKLIST_EXT( - OperatingSystem::Linux, ScreenSizeStatus::All, BatteryStatus::All, - WindowProtocol::All, DriverVendor::MesaAll, DeviceFamily::AtiAll, - nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT, - nsIGfxInfo::FEATURE_BLOCKED_DEVICE, DRIVER_COMPARISON_IGNORED, - V(0, 0, 0, 0), "FEATURE_FAILURE_BROKEN_DRIVER", ""); - - // Disabled due to: // https://gitlab.freedesktop.org/mesa/mesa/-/issues/6688 - APPEND_TO_DRIVER_BLOCKLIST_EXT( - OperatingSystem::Linux, ScreenSizeStatus::All, BatteryStatus::All, - WindowProtocol::All, DriverVendor::MesaAll, DeviceFamily::IntelAll, - nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT, - nsIGfxInfo::FEATURE_BLOCKED_DEVICE, DRIVER_COMPARISON_IGNORED, - V(0, 0, 0, 0), "FEATURE_FAILURE_BROKEN_DRIVER", ""); - - // Disabled due to: // https://gitlab.freedesktop.org/mesa/mesa/-/issues/6988 APPEND_TO_DRIVER_BLOCKLIST_EXT( OperatingSystem::Linux, ScreenSizeStatus::All, BatteryStatus::All, - WindowProtocol::All, DriverVendor::MesaAll, DeviceFamily::QualcommAll, + WindowProtocol::All, DriverVendor::MesaAll, DeviceFamily::All, nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT, nsIGfxInfo::FEATURE_BLOCKED_DEVICE, DRIVER_COMPARISON_IGNORED, V(0, 0, 0, 0), "FEATURE_FAILURE_BROKEN_DRIVER", ""); diff --git a/widget/gtk/GtkCompositorWidget.cpp b/widget/gtk/GtkCompositorWidget.cpp index 073ad5248f..50eb90a0c8 100644 --- a/widget/gtk/GtkCompositorWidget.cpp +++ b/widget/gtk/GtkCompositorWidget.cpp @@ -141,15 +141,12 @@ bool GtkCompositorWidget::SetEGLNativeWindowSize( } LayoutDeviceIntRegion GtkCompositorWidget::GetTransparentRegion() { - // We need to clear target buffer alpha values of popup windows as - // SW-WR paints with alpha blending (see Bug 1674473). - if (!mWidget || mWidget->IsPopup()) { - return LayoutDeviceIntRect(LayoutDeviceIntPoint(0, 0), GetClientSize()); + LayoutDeviceIntRegion fullRegion( + LayoutDeviceIntRect(LayoutDeviceIntPoint(), GetClientSize())); + if (mWidget) { + fullRegion.SubOut(mWidget->GetOpaqueRegion()); } - - // Clear background of titlebar area to render titlebar - // transparent corners correctly. - return mWidget->GetTitlebarRect(); + return fullRegion; } #ifdef MOZ_WAYLAND diff --git a/widget/gtk/MozContainerWayland.cpp b/widget/gtk/MozContainerWayland.cpp index 39e8a48390..3a4660f4e0 100644 --- a/widget/gtk/MozContainerWayland.cpp +++ b/widget/gtk/MozContainerWayland.cpp @@ -84,7 +84,8 @@ using namespace mozilla::widget; static bool moz_container_wayland_surface_create_locked( const MutexAutoLock& aProofOfLock, MozContainer* container); static void moz_container_wayland_set_opaque_region_locked( - const MutexAutoLock& aProofOfLock, MozContainer* container); + const MutexAutoLock& aProofOfLock, MozContainer* container, + const LayoutDeviceIntRegion&); // Lock mozcontainer and get wayland surface of it. You need to pair with // moz_container_wayland_surface_unlock() even @@ -413,7 +414,10 @@ gboolean moz_container_wayland_map_event(GtkWidget* widget, nsWindow* window = moz_container_get_nsWindow(MOZ_CONTAINER(widget)); moz_container_wayland_set_scale_factor_locked(lock, MOZ_CONTAINER(widget), window->GdkCeiledScaleFactor()); - moz_container_wayland_set_opaque_region_locked(lock, MOZ_CONTAINER(widget)); + if (container->data.wl_container.opaque_region_needs_updates) { + moz_container_wayland_set_opaque_region_locked(lock, container, + window->GetOpaqueRegion()); + } moz_container_clear_input_region(MOZ_CONTAINER(widget)); moz_container_wayland_invalidate(MOZ_CONTAINER(widget)); return FALSE; @@ -456,7 +460,10 @@ void moz_container_wayland_size_allocate(GtkWidget* widget, nsWindow* window = moz_container_get_nsWindow(container); moz_container_wayland_set_scale_factor_locked( lock, container, window->GdkCeiledScaleFactor()); - moz_container_wayland_set_opaque_region_locked(lock, container); + if (container->data.wl_container.opaque_region_needs_updates) { + moz_container_wayland_set_opaque_region_locked(lock, container, + window->GetOpaqueRegion()); + } moz_container_wayland_move_locked(lock, container, allocation->x, allocation->y); moz_container_clear_input_region(container); @@ -465,54 +472,28 @@ void moz_container_wayland_size_allocate(GtkWidget* widget, } } -static wl_region* moz_container_wayland_create_opaque_region( - int aX, int aY, int aWidth, int aHeight, int aCornerRadius) { - struct wl_compositor* compositor = WaylandDisplayGet()->GetCompositor(); - wl_region* region = wl_compositor_create_region(compositor); - wl_region_add(region, aX, aY, aWidth, aHeight); - if (aCornerRadius) { - wl_region_subtract(region, aX, aY, aCornerRadius, aCornerRadius); - wl_region_subtract(region, aX + aWidth - aCornerRadius, aY, aCornerRadius, - aCornerRadius); - wl_region_subtract(region, aX, aY + aHeight - aCornerRadius, aCornerRadius, - aCornerRadius); - wl_region_subtract(region, aX + aWidth - aCornerRadius, - aY + aHeight - aCornerRadius, aCornerRadius, - aCornerRadius); - } - return region; -} - static void moz_container_wayland_set_opaque_region_locked( - const MutexAutoLock& aProofOfLock, MozContainer* container) { + const MutexAutoLock& aProofOfLock, MozContainer* container, + const LayoutDeviceIntRegion& aRegion) { MozContainerWayland* wl_container = &container->data.wl_container; - - if (!wl_container->opaque_region_needs_updates) { + MOZ_ASSERT(wl_container->opaque_region_needs_updates); + if (!wl_container->surface) { return; } + wl_container->opaque_region_needs_updates = false; if (!wl_container->opaque_region_used) { - wl_container->opaque_region_needs_updates = false; return; } - GtkAllocation allocation; - gtk_widget_get_allocation(GTK_WIDGET(container), &allocation); - - wl_region* region = moz_container_wayland_create_opaque_region( - 0, 0, allocation.width, allocation.height, - wl_container->opaque_region_corner_radius); + wl_region* region = + wl_compositor_create_region(WaylandDisplayGet()->GetCompositor()); + for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) { + const auto& rect = iter.Get(); + wl_region_add(region, rect.x, rect.y, rect.Width(), rect.Height()); + } wl_surface_set_opaque_region(wl_container->surface, region); wl_region_destroy(region); - wl_container->opaque_region_needs_updates = false; -} - -static void moz_container_wayland_set_opaque_region(MozContainer* container) { - MozContainerWayland* wl_container = &container->data.wl_container; - MutexAutoLock lock(wl_container->container_lock); - if (wl_container->surface) { - moz_container_wayland_set_opaque_region_locked(lock, container); - } } static void moz_container_wayland_surface_set_scale_locked( @@ -757,17 +738,18 @@ gboolean moz_container_wayland_has_egl_window(MozContainer* container) { return !!container->data.wl_container.eglwindow; } -void moz_container_wayland_update_opaque_region(MozContainer* container, - int corner_radius) { +void moz_container_wayland_update_opaque_region(MozContainer* container) { MozContainerWayland* wl_container = &container->data.wl_container; + MutexAutoLock lock(wl_container->container_lock); wl_container->opaque_region_needs_updates = true; - wl_container->opaque_region_corner_radius = corner_radius; // When GL compositor / WebRender is used, // moz_container_wayland_get_egl_window() is called only once when window // is created or resized so update opaque region now. if (moz_container_wayland_has_egl_window(container)) { - moz_container_wayland_set_opaque_region(container); + nsWindow* window = moz_container_get_nsWindow(container); + moz_container_wayland_set_opaque_region_locked(lock, container, + window->GetOpaqueRegion()); } } diff --git a/widget/gtk/MozContainerWayland.h b/widget/gtk/MozContainerWayland.h index 068c674256..6a33df2642 100644 --- a/widget/gtk/MozContainerWayland.h +++ b/widget/gtk/MozContainerWayland.h @@ -42,7 +42,6 @@ struct MozContainerWayland { struct wp_viewport* viewport = nullptr; struct wp_fractional_scale_v1* fractional_scale = nullptr; gboolean opaque_region_needs_updates = false; - int opaque_region_corner_radius = 0; gboolean opaque_region_used = false; gboolean ready_to_draw = false; gboolean commit_to_parent = false; @@ -97,8 +96,7 @@ void moz_container_wayland_add_or_fire_initial_draw_callback( void moz_container_wayland_clear_initial_draw_callback(MozContainer* container); wl_surface* moz_gtk_widget_get_wl_surface(GtkWidget* aWidget); -void moz_container_wayland_update_opaque_region(MozContainer* container, - int corner_radius); +void moz_container_wayland_update_opaque_region(MozContainer* container); gboolean moz_container_wayland_can_draw(MozContainer* container); double moz_container_wayland_get_scale(MozContainer* container); double moz_container_wayland_get_fractional_scale(MozContainer* container); diff --git a/widget/gtk/WidgetStyleCache.cpp b/widget/gtk/WidgetStyleCache.cpp index 13b194a64e..b3d9bfcbbd 100644 --- a/widget/gtk/WidgetStyleCache.cpp +++ b/widget/gtk/WidgetStyleCache.cpp @@ -1079,11 +1079,6 @@ static GtkStyleContext* GetCssNodeStyleInternal(WidgetNodeType aNodeType) { // TODO - create from CSS node style = CreateSubStyleWithClass(MOZ_GTK_TREEVIEW, GTK_STYLE_CLASS_VIEW); break; - case MOZ_GTK_TREEVIEW_EXPANDER: - // TODO - create from CSS node - style = - CreateSubStyleWithClass(MOZ_GTK_TREEVIEW, GTK_STYLE_CLASS_EXPANDER); - break; case MOZ_GTK_SPLITTER_SEPARATOR_HORIZONTAL: style = CreateChildCSSNode("separator", MOZ_GTK_SPLITTER_HORIZONTAL); break; @@ -1218,10 +1213,6 @@ static GtkStyleContext* GetWidgetStyleInternal(WidgetNodeType aNodeType) { case MOZ_GTK_TREEVIEW_VIEW: style = CreateSubStyleWithClass(MOZ_GTK_TREEVIEW, GTK_STYLE_CLASS_VIEW); break; - case MOZ_GTK_TREEVIEW_EXPANDER: - style = - CreateSubStyleWithClass(MOZ_GTK_TREEVIEW, GTK_STYLE_CLASS_EXPANDER); - break; case MOZ_GTK_SPLITTER_SEPARATOR_HORIZONTAL: style = CreateSubStyleWithClass(MOZ_GTK_SPLITTER_HORIZONTAL, GTK_STYLE_CLASS_PANE_SEPARATOR); diff --git a/widget/gtk/WindowSurfaceProvider.cpp b/widget/gtk/WindowSurfaceProvider.cpp index c8b2c5a7d6..204718bd49 100644 --- a/widget/gtk/WindowSurfaceProvider.cpp +++ b/widget/gtk/WindowSurfaceProvider.cpp @@ -12,6 +12,7 @@ #include "mozilla/layers/LayersTypes.h" #include "nsWindow.h" #include "mozilla/ScopeExit.h" +#include "WidgetUtilsGtk.h" #ifdef MOZ_WAYLAND # include "mozilla/StaticPrefs_widget.h" diff --git a/widget/gtk/gtk3drawing.cpp b/widget/gtk/gtk3drawing.cpp index 122b43d688..c67716b90e 100644 --- a/widget/gtk/gtk3drawing.cpp +++ b/widget/gtk/gtk3drawing.cpp @@ -260,7 +260,8 @@ gint moz_gtk_splitter_get_metrics(gint orientation, gint* size) { } static void CalculateToolbarButtonMetrics(WidgetNodeType aAppearance, - ToolbarButtonGTKMetrics* aMetrics) { + ToolbarButtonGTKMetrics* aMetrics, + gint* aMaxInlineMargin) { gint iconWidth, iconHeight; if (!gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &iconWidth, &iconHeight)) { NS_WARNING("Failed to get Gtk+ icon size for titlebar button!"); @@ -292,6 +293,11 @@ static void CalculateToolbarButtonMetrics(WidgetNodeType aAppearance, aMetrics->iconXPosition = (width - iconWidth) / 2; aMetrics->iconYPosition = (height - iconHeight) / 2; aMetrics->minSizeWithBorder = {width, height}; + + GtkBorder margin = {0}; + gtk_style_context_get_margin(style, gtk_style_context_get_state(style), + &margin); + *aMaxInlineMargin = std::max(*aMaxInlineMargin, margin.left + margin.right); } size_t GetGtkHeaderBarButtonLayout(Span<ButtonLayout> aButtonLayout, @@ -353,8 +359,7 @@ static void EnsureToolbarMetrics() { if (sToolbarMetrics.initialized) { return; } - // Make sure we have clean cache after theme reset, etc. - memset(&sToolbarMetrics, 0, sizeof(sToolbarMetrics)); + sToolbarMetrics = {}; // Calculate titlebar button visibility and positions. ButtonLayout buttonLayout[TOOLBAR_BUTTONS]; @@ -364,9 +369,15 @@ static void EnsureToolbarMetrics() { for (const auto& layout : Span(buttonLayout, activeButtonNums)) { int buttonIndex = layout.mType - MOZ_GTK_HEADER_BAR_BUTTON_CLOSE; ToolbarButtonGTKMetrics* metrics = &sToolbarMetrics.button[buttonIndex]; - CalculateToolbarButtonMetrics(layout.mType, metrics); + CalculateToolbarButtonMetrics(layout.mType, metrics, + &sToolbarMetrics.inlineSpacing); } + // Account for the spacing property in the header bar. + // Default to 6 pixels (gtk/gtkheaderbar.c) + gint spacing = 6; + g_object_get(GetWidget(MOZ_GTK_HEADER_BAR), "spacing", &spacing, nullptr); + sToolbarMetrics.inlineSpacing += spacing; sToolbarMetrics.initialized = true; } @@ -380,6 +391,11 @@ const ToolbarButtonGTKMetrics* GetToolbarButtonMetrics( return sToolbarMetrics.button + buttonIndex; } +gint moz_gtk_get_titlebar_button_spacing() { + EnsureToolbarMetrics(); + return sToolbarMetrics.inlineSpacing; +} + static gint moz_gtk_window_decoration_paint(cairo_t* cr, const GdkRectangle* rect, GtkWidgetState* state, @@ -937,54 +953,7 @@ static gint moz_gtk_treeview_paint(cairo_t* cr, GdkRectangle* rect, return MOZ_GTK_SUCCESS; } -static gint moz_gtk_tree_header_cell_paint(cairo_t* cr, - const GdkRectangle* aRect, - GtkWidgetState* state, - gboolean isSorted, - GtkTextDirection direction) { - moz_gtk_button_paint(cr, aRect, state, GTK_RELIEF_NORMAL, - GetWidget(MOZ_GTK_TREE_HEADER_CELL), direction); - return MOZ_GTK_SUCCESS; -} - -/* See gtk_expander_paint() for reference. - */ -static gint moz_gtk_treeview_expander_paint(cairo_t* cr, GdkRectangle* rect, - GtkWidgetState* state, - GtkExpanderStyle expander_state, - GtkTextDirection direction) { - /* Because the frame we get is of the entire treeview, we can't get the - * precise event state of one expander, thus rendering hover and active - * feedback useless. */ - GtkStateFlags state_flags = - state->disabled ? GTK_STATE_FLAG_INSENSITIVE : GTK_STATE_FLAG_NORMAL; - - if (state->inHover) - state_flags = - static_cast<GtkStateFlags>(state_flags | GTK_STATE_FLAG_PRELIGHT); - if (state->selected) - state_flags = - static_cast<GtkStateFlags>(state_flags | GTK_STATE_FLAG_SELECTED); - - /* GTK_STATE_FLAG_ACTIVE controls expanded/colapsed state rendering - * in gtk_render_expander() - */ - if (expander_state == GTK_EXPANDER_EXPANDED) - state_flags = - static_cast<GtkStateFlags>(state_flags | checkbox_check_state); - else - state_flags = - static_cast<GtkStateFlags>(state_flags & ~(checkbox_check_state)); - - GtkStyleContext* style = GetStyleContext( - MOZ_GTK_TREEVIEW_EXPANDER, state->image_scale, direction, state_flags); - gtk_render_expander(style, cr, rect->x, rect->y, rect->width, rect->height); - - return MOZ_GTK_SUCCESS; -} - -/* See gtk_separator_draw() for reference. - */ +/* See gtk_separator_draw() for reference. */ static gint moz_gtk_combo_box_paint(cairo_t* cr, const GdkRectangle* aRect, GtkWidgetState* state, GtkTextDirection direction) { @@ -1572,18 +1541,6 @@ gint moz_gtk_get_widget_border(WidgetNodeType widget, gint* left, gint* top, moz_gtk_add_style_border(style, left, top, right, bottom); return MOZ_GTK_SUCCESS; } - case MOZ_GTK_TREE_HEADER_CELL: { - /* A Tree Header in GTK is just a different styled button - * It must be placed in a TreeView for getting the correct style - * assigned. - * That is why the following code is the same as for MOZ_GTK_BUTTON. - * */ - *left = *top = *right = *bottom = gtk_container_get_border_width( - GTK_CONTAINER(GetWidget(MOZ_GTK_TREE_HEADER_CELL))); - style = GetStyleContext(MOZ_GTK_TREE_HEADER_CELL); - moz_gtk_add_border_padding(style, left, top, right, bottom); - return MOZ_GTK_SUCCESS; - } case MOZ_GTK_DROPDOWN: { /* We need to account for the arrow on the dropdown, so text * doesn't come too close to the arrow, or in some cases spill @@ -1669,7 +1626,6 @@ gint moz_gtk_get_widget_border(WidgetNodeType widget, gint* left, gint* top, case MOZ_GTK_PROGRESS_CHUNK: case MOZ_GTK_PROGRESS_CHUNK_INDETERMINATE: case MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE: - case MOZ_GTK_TREEVIEW_EXPANDER: case MOZ_GTK_HEADER_BAR: case MOZ_GTK_HEADER_BAR_MAXIMIZED: case MOZ_GTK_HEADER_BAR_BUTTON_CLOSE: @@ -1777,18 +1733,6 @@ void moz_gtk_get_arrow_size(WidgetNodeType widgetType, gint* width, } } -gint moz_gtk_get_expander_size(gint* size) { - GtkStyleContext* style = GetStyleContext(MOZ_GTK_EXPANDER); - gtk_style_context_get_style(style, "expander-size", size, NULL); - return MOZ_GTK_SUCCESS; -} - -gint moz_gtk_get_treeview_expander_size(gint* size) { - GtkStyleContext* style = GetStyleContext(MOZ_GTK_TREEVIEW); - gtk_style_context_get_style(style, "expander-size", size, NULL); - return MOZ_GTK_SUCCESS; -} - void moz_gtk_get_entry_min_height(gint* min_content_height, gint* border_padding_height) { GtkStyleContext* style = GetStyleContext(MOZ_GTK_ENTRY); @@ -2057,11 +2001,6 @@ gint moz_gtk_widget_paint(WidgetNodeType widget, cairo_t* cr, } case MOZ_GTK_TREEVIEW: return moz_gtk_treeview_paint(cr, rect, state, direction); - case MOZ_GTK_TREE_HEADER_CELL: - return moz_gtk_tree_header_cell_paint(cr, rect, state, flags, direction); - case MOZ_GTK_TREEVIEW_EXPANDER: - return moz_gtk_treeview_expander_paint( - cr, rect, state, (GtkExpanderStyle)flags, direction); case MOZ_GTK_ENTRY: case MOZ_GTK_DROPDOWN_ENTRY: { GtkStyleContext* style = diff --git a/widget/gtk/gtkdrawing.h b/widget/gtk/gtkdrawing.h index 4ca226d9c7..227a33d9a9 100644 --- a/widget/gtk/gtkdrawing.h +++ b/widget/gtk/gtkdrawing.h @@ -69,38 +69,39 @@ struct MozGtkSize { } }; -typedef struct { +struct ToggleGTKMetrics { bool initialized; MozGtkSize minSizeWithBorder; GtkBorder borderAndPadding; -} ToggleGTKMetrics; +}; -typedef struct { - MozGtkSize minSizeWithBorder; - gint iconXPosition; - gint iconYPosition; -} ToolbarButtonGTKMetrics; +struct ToolbarButtonGTKMetrics { + MozGtkSize minSizeWithBorder{}; + gint iconXPosition = 0; + gint iconYPosition = 0; +}; #define TOOLBAR_BUTTONS 3 -typedef struct { - bool initialized; +struct ToolbarGTKMetrics { + bool initialized = false; + gint inlineSpacing = 0; ToolbarButtonGTKMetrics button[TOOLBAR_BUTTONS]; -} ToolbarGTKMetrics; +}; -typedef struct { +struct CSDWindowDecorationSize { bool initialized; GtkBorder decorationSize; -} CSDWindowDecorationSize; +}; /** flags for tab state **/ -typedef enum { +enum GtkTabFlags { /* first eight bits are used to pass a margin */ MOZ_GTK_TAB_MARGIN_MASK = 0xFF, /* the first tab in the group */ MOZ_GTK_TAB_FIRST = 1 << 9, /* the selected tab */ MOZ_GTK_TAB_SELECTED = 1 << 10 -} GtkTabFlags; +}; /*** result/error codes ***/ #define MOZ_GTK_SUCCESS 0 @@ -211,8 +212,6 @@ enum WidgetNodeType : int { MOZ_GTK_TREEVIEW_VIEW, /* Paints treeheader cells */ MOZ_GTK_TREE_HEADER_CELL, - /* Paints an expander for a GtkTreeView */ - MOZ_GTK_TREEVIEW_EXPANDER, /* Paints the background of menus, context menus. */ MOZ_GTK_MENUPOPUP, /* Menubar for -moz-headerbar colors */ @@ -458,22 +457,6 @@ void moz_gtk_get_entry_min_height(gint* min_content_height, gint moz_gtk_get_toolbar_separator_width(gint* size); /** - * Get the size of a regular GTK expander that shows/hides content - * size: [OUT] the size of the GTK expander, size = width = height. - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint moz_gtk_get_expander_size(gint* size); - -/** - * Get the size of a treeview's expander (we call them twisties) - * size: [OUT] the size of the GTK expander, size = width = height. - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint moz_gtk_get_treeview_expander_size(gint* size); - -/** * Get the desired size of a splitter * orientation: [IN] GTK_ORIENTATION_HORIZONTAL or GTK_ORIENTATION_VERTICAL * size: [OUT] width or height of the splitter handle @@ -493,6 +476,8 @@ gint moz_gtk_get_tab_thickness(WidgetNodeType aNodeType); const ToolbarButtonGTKMetrics* GetToolbarButtonMetrics( WidgetNodeType aAppearance); +gint moz_gtk_get_titlebar_button_spacing(); + /** * Get toolbar button layout. * aButtonLayout: [OUT] An array which will be filled by ButtonLayout diff --git a/widget/gtk/nsAppShell.cpp b/widget/gtk/nsAppShell.cpp index d26b43737d..652801fe69 100644 --- a/widget/gtk/nsAppShell.cpp +++ b/widget/gtk/nsAppShell.cpp @@ -53,7 +53,6 @@ LazyLogModule gWidgetWaylandLog("WidgetWayland"); LazyLogModule gWidgetPopupLog("WidgetPopup"); LazyLogModule gWidgetVsync("WidgetVsync"); LazyLogModule gDmabufLog("Dmabuf"); -LazyLogModule gClipboardLog("WidgetClipboard"); static GPollFunc sPollFunc; diff --git a/widget/gtk/nsClipboard.cpp b/widget/gtk/nsClipboard.cpp index 571b43f1cc..206c8ddeb3 100644 --- a/widget/gtk/nsClipboard.cpp +++ b/widget/gtk/nsClipboard.cpp @@ -88,7 +88,8 @@ static void SetTransferableData(nsITransferable* aTransferable, const nsACString& aFlavor, const char* aClipboardData, uint32_t aClipboardDataLength) { - LOGCLIP("SetTransferableData MIME %s\n", PromiseFlatCString(aFlavor).get()); + MOZ_CLIPBOARD_LOG("SetTransferableData MIME %s\n", + PromiseFlatCString(aFlavor).get()); nsCOMPtr<nsISupports> wrapper; nsPrimitiveHelpers::CreatePrimitiveForData( aFlavor, aClipboardData, aClipboardDataLength, getter_AddRefs(wrapper)); @@ -161,29 +162,30 @@ int GetGeckoClipboardType(GtkClipboard* aGtkClipboard) { void nsRetrievalContext::ClearCachedTargetsClipboard(GtkClipboard* aClipboard, GdkEvent* aEvent, gpointer data) { - LOGCLIP("nsRetrievalContext::ClearCachedTargetsClipboard()"); + MOZ_CLIPBOARD_LOG("nsRetrievalContext::ClearCachedTargetsClipboard()"); sClipboardTargets.Clear(); } void nsRetrievalContext::ClearCachedTargetsPrimary(GtkClipboard* aClipboard, GdkEvent* aEvent, gpointer data) { - LOGCLIP("nsRetrievalContext::ClearCachedTargetsPrimary()"); + MOZ_CLIPBOARD_LOG("nsRetrievalContext::ClearCachedTargetsPrimary()"); sPrimaryTargets.Clear(); } ClipboardTargets nsRetrievalContext::GetTargets(int32_t aWhichClipboard) { - LOGCLIP("nsRetrievalContext::GetTargets(%s)\n", - aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary" - : "clipboard"); + MOZ_CLIPBOARD_LOG("nsRetrievalContext::GetTargets(%s)\n", + aWhichClipboard == nsClipboard::kSelectionClipboard + ? "primary" + : "clipboard"); ClipboardTargets& storedTargets = (aWhichClipboard == nsClipboard::kSelectionClipboard) ? sPrimaryTargets : sClipboardTargets; if (!storedTargets) { - LOGCLIP(" getting targets from system"); + MOZ_CLIPBOARD_LOG(" getting targets from system"); storedTargets.Set(GetTargetsImpl(aWhichClipboard)); } else { - LOGCLIP(" using cached targets"); + MOZ_CLIPBOARD_LOG(" using cached targets"); } return storedTargets.Clone(); } @@ -249,7 +251,7 @@ nsClipboard::Observe(nsISupports* aSubject, const char* aTopic, // runnable. return SchedulerGroup::Dispatch( NS_NewRunnableFunction("gtk_clipboard_store()", []() { - LOGCLIP("nsClipboard storing clipboard content\n"); + MOZ_CLIPBOARD_LOG("nsClipboard storing clipboard content\n"); gtk_clipboard_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); })); } @@ -269,8 +271,9 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable, return NS_OK; } - LOGCLIP("nsClipboard::SetNativeClipboardData (%s)\n", - aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); + MOZ_CLIPBOARD_LOG( + "nsClipboard::SetNativeClipboardData (%s)\n", + aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); // List of suported targets GtkTargetList* list = gtk_target_list_new(nullptr, 0); @@ -279,7 +282,7 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable, nsTArray<nsCString> flavors; nsresult rv = aTransferable->FlavorsTransferableCanExport(flavors); if (NS_FAILED(rv)) { - LOGCLIP(" FlavorsTransferableCanExport failed!\n"); + MOZ_CLIPBOARD_LOG(" FlavorsTransferableCanExport failed!\n"); // Fall through. |gtkTargets| will be null below. } @@ -287,11 +290,11 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable, bool imagesAdded = false; for (uint32_t i = 0; i < flavors.Length(); i++) { nsCString& flavorStr = flavors[i]; - LOGCLIP(" processing target %s\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" processing target %s\n", flavorStr.get()); // Special case text/plain since we can handle all of the string types. if (flavorStr.EqualsLiteral(kTextMime)) { - LOGCLIP(" adding TEXT targets\n"); + MOZ_CLIPBOARD_LOG(" adding TEXT targets\n"); gtk_target_list_add_text_targets(list, 0); continue; } @@ -300,7 +303,7 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable, // Don't bother adding image targets twice if (!imagesAdded) { // accept any writable image type - LOGCLIP(" adding IMAGE targets\n"); + MOZ_CLIPBOARD_LOG(" adding IMAGE targets\n"); gtk_target_list_add_image_targets(list, 0, TRUE); imagesAdded = true; } @@ -308,14 +311,14 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable, } if (flavorStr.EqualsLiteral(kFileMime)) { - LOGCLIP(" adding text/uri-list target\n"); + MOZ_CLIPBOARD_LOG(" adding text/uri-list target\n"); GdkAtom atom = gdk_atom_intern(kURIListMime, FALSE); gtk_target_list_add(list, atom, 0, 0); continue; } // Add this to our list of valid targets - LOGCLIP(" adding OTHER target %s\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" adding OTHER target %s\n", flavorStr.get()); GdkAtom atom = gdk_atom_intern(flavorStr.get(), FALSE); gtk_target_list_add(list, atom, 0, 0); } @@ -328,7 +331,7 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable, GtkTargetEntry* gtkTargets = gtk_target_table_new_from_list(list, &numTargets); if (!gtkTargets || numTargets == 0) { - LOGCLIP( + MOZ_CLIPBOARD_LOG( " gtk_target_table_new_from_list() failed or empty list of " "targets!\n"); // Clear references to the any old data and let GTK know that it is no @@ -356,7 +359,7 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable, rv = NS_OK; } else { - LOGCLIP(" gtk_clipboard_set_with_data() failed!\n"); + MOZ_CLIPBOARD_LOG(" gtk_clipboard_set_with_data() failed!\n"); EmptyNativeClipboardData(aWhichClipboard); rv = NS_ERROR_FAILURE; } @@ -390,11 +393,11 @@ static bool IsMIMEAtFlavourList(const nsTArray<nsCString>& aFlavourList, // So if clipboard contains images only remove text MIME offer. bool nsClipboard::FilterImportedFlavors(int32_t aWhichClipboard, nsTArray<nsCString>& aFlavors) { - LOGCLIP("nsClipboard::FilterImportedFlavors"); + MOZ_CLIPBOARD_LOG("nsClipboard::FilterImportedFlavors"); auto targets = mContext->GetTargets(aWhichClipboard); if (!targets) { - LOGCLIP(" X11: no targes at clipboard (null), quit.\n"); + MOZ_CLIPBOARD_LOG(" X11: no targes at clipboard (null), quit.\n"); return true; } @@ -419,7 +422,8 @@ bool nsClipboard::FilterImportedFlavors(int32_t aWhichClipboard, } // We have some other MIME type on clipboard which can be hopefully // converted to text without any problem. - LOGCLIP(" X11: text types in clipboard, no need to filter them.\n"); + MOZ_CLIPBOARD_LOG( + " X11: text types in clipboard, no need to filter them.\n"); return true; } @@ -436,9 +440,9 @@ bool nsClipboard::FilterImportedFlavors(int32_t aWhichClipboard, } aFlavors.SwapElements(clipboardFlavors); #ifdef MOZ_LOGGING - LOGCLIP(" X11: Flavors which match clipboard content:\n"); + MOZ_CLIPBOARD_LOG(" X11: Flavors which match clipboard content:\n"); for (uint32_t i = 0; i < aFlavors.Length(); i++) { - LOGCLIP(" %s\n", aFlavors[i].get()); + MOZ_CLIPBOARD_LOG(" %s\n", aFlavors[i].get()); } #endif return true; @@ -452,13 +456,13 @@ static nsresult GetTransferableFlavors(nsITransferable* aTransferable, // Get a list of flavors this transferable can import nsresult rv = aTransferable->FlavorsTransferableCanImport(aFlavors); if (NS_FAILED(rv)) { - LOGCLIP(" FlavorsTransferableCanImport falied!\n"); + MOZ_CLIPBOARD_LOG(" FlavorsTransferableCanImport falied!\n"); return rv; } #ifdef MOZ_LOGGING - LOGCLIP(" Flavors which can be imported:"); + MOZ_CLIPBOARD_LOG(" Flavors which can be imported:"); for (const auto& flavor : aFlavors) { - LOGCLIP(" %s", flavor.get()); + MOZ_CLIPBOARD_LOG(" %s", flavor.get()); } #endif return NS_OK; @@ -476,7 +480,7 @@ static bool TransferableSetFile(nsITransferable* aTransferable, rv = fileURL->GetFile(getter_AddRefs(file)); if (NS_SUCCEEDED(rv)) { aTransferable->SetTransferData(kFileMime, file); - LOGCLIP(" successfully set file to clipboard\n"); + MOZ_CLIPBOARD_LOG(" successfully set file to clipboard\n"); return true; } } @@ -492,17 +496,20 @@ static bool TransferableSetHTML(nsITransferable* aTransferable, nsAutoCString charset; if (!GetHTMLCharset(aData, charset)) { // Fall back to utf-8 in case html/data is missing kHTMLMarkupPrefix. - LOGCLIP("Failed to get html/text encoding, fall back to utf-8.\n"); + MOZ_CLIPBOARD_LOG( + "Failed to get html/text encoding, fall back to utf-8.\n"); charset.AssignLiteral("utf-8"); } - LOGCLIP("TransferableSetHTML: HTML detected charset %s", charset.get()); + MOZ_CLIPBOARD_LOG("TransferableSetHTML: HTML detected charset %s", + charset.get()); // app which use "text/html" to copy&paste // get the decoder auto encoding = Encoding::ForLabelNoReplacement(charset); if (!encoding) { - LOGCLIP("TransferableSetHTML: get unicode decoder error (charset: %s)", - charset.get()); + MOZ_CLIPBOARD_LOG( + "TransferableSetHTML: get unicode decoder error (charset: %s)", + charset.get()); return false; } @@ -523,16 +530,15 @@ static bool TransferableSetHTML(nsITransferable* aTransferable, nsAutoString unicodeData; auto [rv, enc] = encoding->Decode(AsBytes(aData), unicodeData); #if MOZ_LOGGING - if (enc != UTF_8_ENCODING && - MOZ_LOG_TEST(gClipboardLog, mozilla::LogLevel::Debug)) { + if (enc != UTF_8_ENCODING && MOZ_CLIPBOARD_LOG_ENABLED()) { nsCString decoderName; enc->Name(decoderName); - LOGCLIP("TransferableSetHTML: expected UTF-8 decoder but got %s", - decoderName.get()); + MOZ_CLIPBOARD_LOG("TransferableSetHTML: expected UTF-8 decoder but got %s", + decoderName.get()); } #endif if (NS_FAILED(rv)) { - LOGCLIP("TransferableSetHTML: failed to decode HTML"); + MOZ_CLIPBOARD_LOG("TransferableSetHTML: failed to decode HTML"); return false; } SetTransferableData(aTransferable, mimeType, @@ -548,8 +554,9 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, MOZ_DIAGNOSTIC_ASSERT( nsIClipboard::IsClipboardTypeSupported(aWhichClipboard)); - LOGCLIP("nsClipboard::GetNativeClipboardData (%s)\n", - aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); + MOZ_CLIPBOARD_LOG( + "nsClipboard::GetNativeClipboardData (%s)\n", + aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); // TODO: Ensure we don't re-enter here. if (!mContext) { @@ -564,7 +571,7 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, // see Bug 1611407 if (widget::GdkIsX11Display() && !FilterImportedFlavors(aWhichClipboard, flavors)) { - LOGCLIP(" Missing suitable clipboard data, quit."); + MOZ_CLIPBOARD_LOG(" Missing suitable clipboard data, quit."); return NS_OK; } @@ -580,12 +587,13 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, flavorStr.Assign(kJPEGImageMime); } - LOGCLIP(" Getting image %s MIME clipboard data\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" Getting image %s MIME clipboard data\n", + flavorStr.get()); auto clipboardData = mContext->GetClipboardData(flavorStr.get(), aWhichClipboard); if (!clipboardData) { - LOGCLIP(" %s type is missing\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" %s type is missing\n", flavorStr.get()); continue; } @@ -593,18 +601,19 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, NS_NewByteInputStream(getter_AddRefs(byteStream), clipboardData.AsSpan(), NS_ASSIGNMENT_COPY); aTransferable->SetTransferData(flavorStr.get(), byteStream); - LOGCLIP(" got %s MIME data\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" got %s MIME data\n", flavorStr.get()); return NS_OK; } // Special case text/plain since we can convert any // string into text/plain if (flavorStr.EqualsLiteral(kTextMime)) { - LOGCLIP(" Getting text %s MIME clipboard data\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" Getting text %s MIME clipboard data\n", + flavorStr.get()); auto clipboardData = mContext->GetClipboardText(aWhichClipboard); if (!clipboardData) { - LOGCLIP(" failed to get text data\n"); + MOZ_CLIPBOARD_LOG(" failed to get text data\n"); // If the type was text/plain and we couldn't get // text off the clipboard, run the next loop // iteration. @@ -617,17 +626,18 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, (const char*)ucs2string.BeginReading(), ucs2string.Length() * 2); - LOGCLIP(" got text data, length %zd\n", ucs2string.Length()); + MOZ_CLIPBOARD_LOG(" got text data, length %zd\n", ucs2string.Length()); return NS_OK; } if (flavorStr.EqualsLiteral(kFileMime)) { - LOGCLIP(" Getting %s file clipboard data\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" Getting %s file clipboard data\n", + flavorStr.get()); auto clipboardData = mContext->GetClipboardData(kURIListMime, aWhichClipboard); if (!clipboardData) { - LOGCLIP(" text/uri-list type is missing\n"); + MOZ_CLIPBOARD_LOG(" text/uri-list type is missing\n"); continue; } @@ -638,19 +648,19 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, return NS_OK; } - LOGCLIP(" Getting %s MIME clipboard data\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" Getting %s MIME clipboard data\n", flavorStr.get()); auto clipboardData = mContext->GetClipboardData(flavorStr.get(), aWhichClipboard); #ifdef MOZ_LOGGING if (!clipboardData) { - LOGCLIP(" %s type is missing\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" %s type is missing\n", flavorStr.get()); } #endif if (clipboardData) { - LOGCLIP(" got %s mime type data.\n", flavorStr.get()); + MOZ_CLIPBOARD_LOG(" got %s mime type data.\n", flavorStr.get()); // Special case text/html since we can convert into UCS2 if (flavorStr.EqualsLiteral(kHTMLMime)) { @@ -666,7 +676,7 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, } } - LOGCLIP(" failed to get clipboard content.\n"); + MOZ_CLIPBOARD_LOG(" failed to get clipboard content.\n"); return NS_OK; } @@ -692,11 +702,11 @@ struct DataCallbackHandler { mMimeType(aMimeType), mDataType(aDataType) { MOZ_COUNT_CTOR(DataCallbackHandler); - LOGCLIP("DataCallbackHandler created [%p] MIME %s type %d", this, - mMimeType.get(), mDataType); + MOZ_CLIPBOARD_LOG("DataCallbackHandler created [%p] MIME %s type %d", this, + mMimeType.get(), mDataType); } ~DataCallbackHandler() { - LOGCLIP("DataCallbackHandler deleted [%p]", this); + MOZ_CLIPBOARD_LOG("DataCallbackHandler deleted [%p]", this); MOZ_COUNT_DTOR(DataCallbackHandler); } }; @@ -704,20 +714,21 @@ struct DataCallbackHandler { static void AsyncGetTextImpl(nsITransferable* aTransferable, int32_t aWhichClipboard, nsBaseClipboard::GetDataCallback&& aCallback) { - LOGCLIP("AsyncGetText() type '%s'", - aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary" - : "clipboard"); + MOZ_CLIPBOARD_LOG("AsyncGetText() type '%s'", + aWhichClipboard == nsClipboard::kSelectionClipboard + ? "primary" + : "clipboard"); gtk_clipboard_request_text( gtk_clipboard_get(GetSelectionAtom(aWhichClipboard)), [](GtkClipboard* aClipboard, const gchar* aText, gpointer aData) -> void { UniquePtr<DataCallbackHandler> ref( static_cast<DataCallbackHandler*>(aData)); - LOGCLIP("AsyncGetText async handler of [%p]", aData); + MOZ_CLIPBOARD_LOG("AsyncGetText async handler of [%p]", aData); size_t dataLength = aText ? strlen(aText) : 0; if (dataLength <= 0) { - LOGCLIP(" quit, text is not available"); + MOZ_CLIPBOARD_LOG(" quit, text is not available"); ref->mDataCallback(NS_OK); return; } @@ -728,7 +739,7 @@ static void AsyncGetTextImpl(nsITransferable* aTransferable, SetTransferableData(ref->mTransferable, flavor, (const char*)utf16string.BeginReading(), utf16string.Length() * 2); - LOGCLIP(" text is set, length = %d", (int)dataLength); + MOZ_CLIPBOARD_LOG(" text is set, length = %d", (int)dataLength); ref->mDataCallback(NS_OK); }, new DataCallbackHandler(aTransferable, std::move(aCallback), kTextMime)); @@ -738,9 +749,10 @@ static void AsyncGetDataImpl(nsITransferable* aTransferable, int32_t aWhichClipboard, const char* aMimeType, DataType aDataType, nsBaseClipboard::GetDataCallback&& aCallback) { - LOGCLIP("AsyncGetData() type '%s'", - aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary" - : "clipboard"); + MOZ_CLIPBOARD_LOG("AsyncGetData() type '%s'", + aWhichClipboard == nsClipboard::kSelectionClipboard + ? "primary" + : "clipboard"); const char* gtkMIMEType = nullptr; switch (aDataType) { @@ -762,8 +774,8 @@ static void AsyncGetDataImpl(nsITransferable* aTransferable, gpointer aData) -> void { UniquePtr<DataCallbackHandler> ref( static_cast<DataCallbackHandler*>(aData)); - LOGCLIP("AsyncGetData async handler [%p] MIME %s type %d", aData, - ref->mMimeType.get(), ref->mDataType); + MOZ_CLIPBOARD_LOG("AsyncGetData async handler [%p] MIME %s type %d", + aData, ref->mMimeType.get(), ref->mDataType); int dataLength = gtk_selection_data_get_length(aSelection); if (dataLength <= 0) { @@ -777,7 +789,7 @@ static void AsyncGetDataImpl(nsITransferable* aTransferable, } switch (ref->mDataType) { case DATATYPE_IMAGE: { - LOGCLIP(" set image clipboard data"); + MOZ_CLIPBOARD_LOG(" set image clipboard data"); nsCOMPtr<nsIInputStream> byteStream; NS_NewByteInputStream(getter_AddRefs(byteStream), Span(data, dataLength), NS_ASSIGNMENT_COPY); @@ -786,19 +798,19 @@ static void AsyncGetDataImpl(nsITransferable* aTransferable, break; } case DATATYPE_FILE: { - LOGCLIP(" set file clipboard data"); + MOZ_CLIPBOARD_LOG(" set file clipboard data"); nsDependentCSubstring file(data, dataLength); TransferableSetFile(ref->mTransferable, file); break; } case DATATYPE_HTML: { - LOGCLIP(" html clipboard data"); + MOZ_CLIPBOARD_LOG(" html clipboard data"); Span dataSpan(data, dataLength); TransferableSetHTML(ref->mTransferable, dataSpan); break; } case DATATYPE_RAW: { - LOGCLIP(" raw clipboard data %s", ref->mMimeType.get()); + MOZ_CLIPBOARD_LOG(" raw clipboard data %s", ref->mMimeType.get()); SetTransferableData(ref->mTransferable, ref->mMimeType, data, dataLength); break; @@ -821,7 +833,8 @@ static void AsyncGetDataFlavor(nsITransferable* aTransferable, if (aFlavorStr.EqualsLiteral(kJPGImageMime)) { aFlavorStr.Assign(kJPEGImageMime); } - LOGCLIP(" Getting image %s MIME clipboard data", aFlavorStr.get()); + MOZ_CLIPBOARD_LOG(" Getting image %s MIME clipboard data", + aFlavorStr.get()); AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(), DATATYPE_IMAGE, std::move(aCallback)); return; @@ -829,23 +842,23 @@ static void AsyncGetDataFlavor(nsITransferable* aTransferable, // Special case text/plain since we can convert any // string into text/plain if (aFlavorStr.EqualsLiteral(kTextMime)) { - LOGCLIP(" Getting unicode clipboard data"); + MOZ_CLIPBOARD_LOG(" Getting unicode clipboard data"); AsyncGetTextImpl(aTransferable, aWhichClipboard, std::move(aCallback)); return; } if (aFlavorStr.EqualsLiteral(kFileMime)) { - LOGCLIP(" Getting file clipboard data\n"); + MOZ_CLIPBOARD_LOG(" Getting file clipboard data\n"); AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(), DATATYPE_FILE, std::move(aCallback)); return; } if (aFlavorStr.EqualsLiteral(kHTMLMime)) { - LOGCLIP(" Getting HTML clipboard data"); + MOZ_CLIPBOARD_LOG(" Getting HTML clipboard data"); AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(), DATATYPE_HTML, std::move(aCallback)); return; } - LOGCLIP(" Getting raw %s MIME clipboard data\n", aFlavorStr.get()); + MOZ_CLIPBOARD_LOG(" Getting raw %s MIME clipboard data\n", aFlavorStr.get()); AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(), DATATYPE_RAW, std::move(aCallback)); } @@ -857,9 +870,10 @@ void nsClipboard::AsyncGetNativeClipboardData(nsITransferable* aTransferable, MOZ_DIAGNOSTIC_ASSERT( nsIClipboard::IsClipboardTypeSupported(aWhichClipboard)); - LOGCLIP("nsClipboard::AsyncGetNativeClipboardData (%s)", - aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary" - : "clipboard"); + MOZ_CLIPBOARD_LOG("nsClipboard::AsyncGetNativeClipboardData (%s)", + aWhichClipboard == nsClipboard::kSelectionClipboard + ? "primary" + : "clipboard"); nsTArray<nsCString> importedFlavors; nsresult rv = GetTransferableFlavors(aTransferable, importedFlavors); if (NS_FAILED(rv)) { @@ -874,8 +888,9 @@ void nsClipboard::AsyncGetNativeClipboardData(nsITransferable* aTransferable, } #ifdef MOZ_LOGGING if (flavorsNum > 1) { - LOGCLIP(" Only first MIME type (%s) will be imported from clipboard!", - importedFlavors[0].get()); + MOZ_CLIPBOARD_LOG( + " Only first MIME type (%s) will be imported from clipboard!", + importedFlavors[0].get()); } #endif @@ -894,7 +909,7 @@ void nsClipboard::AsyncGetNativeClipboardData(nsITransferable* aTransferable, nsTArray<nsCString> clipboardFlavors = std::move(aResultOrError.unwrap()); if (!clipboardFlavors.Length()) { - LOGCLIP(" no flavors in clipboard, quit."); + MOZ_CLIPBOARD_LOG(" no flavors in clipboard, quit."); callback(NS_OK); return; } @@ -914,8 +929,9 @@ nsresult nsClipboard::EmptyNativeClipboardData(int32_t aWhichClipboard) { MOZ_DIAGNOSTIC_ASSERT( nsIClipboard::IsClipboardTypeSupported(aWhichClipboard)); - LOGCLIP("nsClipboard::EmptyNativeClipboardData (%s)\n", - aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); + MOZ_CLIPBOARD_LOG( + "nsClipboard::EmptyNativeClipboardData (%s)\n", + aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); if (aWhichClipboard == kSelectionClipboard) { if (mSelectionTransferable) { gtk_clipboard_clear(gtk_clipboard_get(GDK_SELECTION_PRIMARY)); @@ -947,20 +963,21 @@ static bool FlavorMatchesTarget(const nsACString& aFlavor, GdkAtom aTarget) { return false; } if (aFlavor.Equals(atom_name.get())) { - LOGCLIP(" has %s\n", atom_name.get()); + MOZ_CLIPBOARD_LOG(" has %s\n", atom_name.get()); return true; } // X clipboard supports image/jpeg, but we want to emulate support // for image/jpg as well if (aFlavor.EqualsLiteral(kJPGImageMime) && !strcmp(atom_name.get(), kJPEGImageMime)) { - LOGCLIP(" has image/jpg\n"); + MOZ_CLIPBOARD_LOG(" has image/jpg\n"); return true; } // application/x-moz-file should be treated like text/uri-list if (aFlavor.EqualsLiteral(kFileMime) && !strcmp(atom_name.get(), kURIListMime)) { - LOGCLIP(" has text/uri-list treating as application/x-moz-file"); + MOZ_CLIPBOARD_LOG( + " has text/uri-list treating as application/x-moz-file"); return true; } return false; @@ -972,8 +989,9 @@ nsClipboard::HasNativeClipboardDataMatchingFlavors( MOZ_DIAGNOSTIC_ASSERT( nsIClipboard::IsClipboardTypeSupported(aWhichClipboard)); - LOGCLIP("nsClipboard::HasNativeClipboardDataMatchingFlavors (%s)\n", - aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); + MOZ_CLIPBOARD_LOG( + "nsClipboard::HasNativeClipboardDataMatchingFlavors (%s)\n", + aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); if (!mContext) { return Err(NS_ERROR_FAILURE); @@ -981,25 +999,25 @@ nsClipboard::HasNativeClipboardDataMatchingFlavors( auto targets = mContext->GetTargets(aWhichClipboard); if (!targets) { - LOGCLIP(" no targes at clipboard (null)\n"); + MOZ_CLIPBOARD_LOG(" no targes at clipboard (null)\n"); return false; } #ifdef MOZ_LOGGING - if (LOGCLIP_ENABLED()) { - LOGCLIP(" Asking for content:\n"); + if (MOZ_CLIPBOARD_LOG_ENABLED()) { + MOZ_CLIPBOARD_LOG(" Asking for content:\n"); for (auto& flavor : aFlavorList) { - LOGCLIP(" MIME %s\n", flavor.get()); + MOZ_CLIPBOARD_LOG(" MIME %s\n", flavor.get()); } - LOGCLIP(" Clipboard content (target nums %zu):\n", - targets.AsSpan().Length()); + MOZ_CLIPBOARD_LOG(" Clipboard content (target nums %zu):\n", + targets.AsSpan().Length()); for (const auto& target : targets.AsSpan()) { GUniquePtr<gchar> atom_name(gdk_atom_name(target)); if (!atom_name) { - LOGCLIP(" failed to get MIME\n"); + MOZ_CLIPBOARD_LOG(" failed to get MIME\n"); continue; } - LOGCLIP(" MIME %s\n", atom_name.get()); + MOZ_CLIPBOARD_LOG(" MIME %s\n", atom_name.get()); } } #endif @@ -1011,7 +1029,7 @@ nsClipboard::HasNativeClipboardDataMatchingFlavors( if (flavor.EqualsLiteral(kTextMime) && gtk_targets_include_text(targets.AsSpan().data(), targets.AsSpan().Length())) { - LOGCLIP(" has kTextMime\n"); + MOZ_CLIPBOARD_LOG(" has kTextMime\n"); return true; } for (const auto& target : targets.AsSpan()) { @@ -1021,7 +1039,7 @@ nsClipboard::HasNativeClipboardDataMatchingFlavors( } } - LOGCLIP(" no targes at clipboard (bad match)\n"); + MOZ_CLIPBOARD_LOG(" no targes at clipboard (bad match)\n"); return false; } @@ -1030,10 +1048,10 @@ struct TragetCallbackHandler { nsBaseClipboard::HasMatchingFlavorsCallback&& aCallback) : mAcceptedFlavorList(aAcceptedFlavorList.Clone()), mCallback(std::move(aCallback)) { - LOGCLIP("TragetCallbackHandler(%p) created", this); + MOZ_CLIPBOARD_LOG("TragetCallbackHandler(%p) created", this); } ~TragetCallbackHandler() { - LOGCLIP("TragetCallbackHandler(%p) deleted", this); + MOZ_CLIPBOARD_LOG("TragetCallbackHandler(%p) deleted", this); } nsTArray<nsCString> mAcceptedFlavorList; nsBaseClipboard::HasMatchingFlavorsCallback mCallback; @@ -1045,15 +1063,17 @@ void nsClipboard::AsyncHasNativeClipboardDataMatchingFlavors( MOZ_DIAGNOSTIC_ASSERT( nsIClipboard::IsClipboardTypeSupported(aWhichClipboard)); - LOGCLIP("nsClipboard::AsyncHasNativeClipboardDataMatchingFlavors (%s)", - aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); + MOZ_CLIPBOARD_LOG( + "nsClipboard::AsyncHasNativeClipboardDataMatchingFlavors (%s)", + aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard"); gtk_clipboard_request_contents( gtk_clipboard_get(GetSelectionAtom(aWhichClipboard)), gdk_atom_intern("TARGETS", FALSE), [](GtkClipboard* aClipboard, GtkSelectionData* aSelection, gpointer aData) -> void { - LOGCLIP("gtk_clipboard_request_contents async handler (%p)", aData); + MOZ_CLIPBOARD_LOG("gtk_clipboard_request_contents async handler (%p)", + aData); UniquePtr<TragetCallbackHandler> handler( static_cast<TragetCallbackHandler*>(aData)); @@ -1061,15 +1081,30 @@ void nsClipboard::AsyncHasNativeClipboardDataMatchingFlavors( gint targetsNum = 0; if (gtk_selection_data_get_length(aSelection) > 0) { gtk_selection_data_get_targets(aSelection, &targets, &targetsNum); + +#ifdef MOZ_LOGGING + if (MOZ_CLIPBOARD_LOG_ENABLED()) { + MOZ_CLIPBOARD_LOG(" Clipboard content (target nums %d):\n", + targetsNum); + for (int i = 0; i < targetsNum; i++) { + GUniquePtr<gchar> atom_name(gdk_atom_name(targets[i])); + if (!atom_name) { + MOZ_CLIPBOARD_LOG(" failed to get MIME\n"); + continue; + } + MOZ_CLIPBOARD_LOG(" MIME %s\n", atom_name.get()); + } + } +#endif } nsTArray<nsCString> results; if (targetsNum) { for (auto& flavor : handler->mAcceptedFlavorList) { - LOGCLIP(" looking for %s", flavor.get()); + MOZ_CLIPBOARD_LOG(" looking for %s", flavor.get()); if (flavor.EqualsLiteral(kTextMime) && gtk_targets_include_text(targets, targetsNum)) { results.AppendElement(flavor); - LOGCLIP(" has kTextMime\n"); + MOZ_CLIPBOARD_LOG(" has kTextMime\n"); continue; } for (int i = 0; i < targetsNum; i++) { @@ -1113,14 +1148,16 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, else return; // THAT AIN'T NO CLIPBOARD I EVER HEARD OF - LOGCLIP("nsClipboard::SelectionGetEvent (%s)\n", - whichClipboard == kSelectionClipboard ? "primary" : "clipboard"); + MOZ_CLIPBOARD_LOG( + "nsClipboard::SelectionGetEvent (%s)\n", + whichClipboard == kSelectionClipboard ? "primary" : "clipboard"); nsCOMPtr<nsITransferable> trans = GetTransferable(whichClipboard); if (!trans) { // We have nothing to serve - LOGCLIP("nsClipboard::SelectionGetEvent() - %s clipboard is empty!\n", - whichClipboard == kSelectionClipboard ? "Primary" : "Clipboard"); + MOZ_CLIPBOARD_LOG( + "nsClipboard::SelectionGetEvent() - %s clipboard is empty!\n", + whichClipboard == kSelectionClipboard ? "Primary" : "Clipboard"); return; } @@ -1128,18 +1165,18 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, nsCOMPtr<nsISupports> item; GdkAtom selectionTarget = gtk_selection_data_get_target(aSelectionData); - LOGCLIP(" selection target %s\n", - GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get()); + MOZ_CLIPBOARD_LOG(" selection target %s\n", + GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get()); // Check to see if the selection data is some text type. if (gtk_targets_include_text(&selectionTarget, 1)) { - LOGCLIP(" providing text/plain data\n"); + MOZ_CLIPBOARD_LOG(" providing text/plain data\n"); // Try to convert our internal type into a text string. Get // the transferable for this clipboard and try to get the // text/plain type for it. rv = trans->GetTransferData("text/plain", getter_AddRefs(item)); if (NS_FAILED(rv) || !item) { - LOGCLIP(" GetTransferData() failed to get text/plain!\n"); + MOZ_CLIPBOARD_LOG(" GetTransferData() failed to get text/plain!\n"); return; } @@ -1151,9 +1188,9 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, wideString->GetData(ucs2string); NS_ConvertUTF16toUTF8 utf8string(ucs2string); - LOGCLIP(" sent %zd bytes of utf-8 data\n", utf8string.Length()); + MOZ_CLIPBOARD_LOG(" sent %zd bytes of utf-8 data\n", utf8string.Length()); if (selectionTarget == gdk_atom_intern("text/plain;charset=utf-8", FALSE)) { - LOGCLIP( + MOZ_CLIPBOARD_LOG( " using gtk_selection_data_set for 'text/plain;charset=utf-8'\n"); // Bypass gtk_selection_data_set_text, which will convert \n to \r\n // in some versions of GTK. @@ -1169,7 +1206,7 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, // Check to see if the selection data is an image type if (gtk_targets_include_image(&selectionTarget, 1, TRUE)) { - LOGCLIP(" providing image data\n"); + MOZ_CLIPBOARD_LOG(" providing image data\n"); // Look through our transfer data for the image static const char* const imageMimeTypes[] = {kNativeImageMime, kPNGImageMime, kJPEGImageMime, @@ -1179,47 +1216,50 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, for (uint32_t i = 0; i < ArrayLength(imageMimeTypes); i++) { rv = trans->GetTransferData(imageMimeTypes[i], getter_AddRefs(imageItem)); if (NS_FAILED(rv)) { - LOGCLIP(" %s is missing at GetTransferData()\n", imageMimeTypes[i]); + MOZ_CLIPBOARD_LOG(" %s is missing at GetTransferData()\n", + imageMimeTypes[i]); continue; } image = do_QueryInterface(imageItem); if (image) { - LOGCLIP(" %s is available at GetTransferData()\n", - imageMimeTypes[i]); + MOZ_CLIPBOARD_LOG(" %s is available at GetTransferData()\n", + imageMimeTypes[i]); break; } } if (!image) { // Not getting an image for an image mime type!? - LOGCLIP(" Failed to get any image mime from GetTransferData()!\n"); + MOZ_CLIPBOARD_LOG( + " Failed to get any image mime from GetTransferData()!\n"); return; } RefPtr<GdkPixbuf> pixbuf = nsImageToPixbuf::ImageToPixbuf(image); if (!pixbuf) { - LOGCLIP(" nsImageToPixbuf::ImageToPixbuf() failed!\n"); + MOZ_CLIPBOARD_LOG(" nsImageToPixbuf::ImageToPixbuf() failed!\n"); return; } - LOGCLIP(" Setting pixbuf image data as %s\n", - GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get()); + MOZ_CLIPBOARD_LOG(" Setting pixbuf image data as %s\n", + GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get()); gtk_selection_data_set_pixbuf(aSelectionData, pixbuf); return; } if (selectionTarget == gdk_atom_intern(kHTMLMime, FALSE)) { - LOGCLIP(" providing %s data\n", kHTMLMime); + MOZ_CLIPBOARD_LOG(" providing %s data\n", kHTMLMime); rv = trans->GetTransferData(kHTMLMime, getter_AddRefs(item)); if (NS_FAILED(rv) || !item) { - LOGCLIP(" failed to get %s data by GetTransferData()!\n", kHTMLMime); + MOZ_CLIPBOARD_LOG(" failed to get %s data by GetTransferData()!\n", + kHTMLMime); return; } nsCOMPtr<nsISupportsString> wideString; wideString = do_QueryInterface(item); if (!wideString) { - LOGCLIP(" failed to get wideString interface!"); + MOZ_CLIPBOARD_LOG(" failed to get wideString interface!"); return; } @@ -1231,8 +1271,8 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, html.AppendLiteral(kHTMLMarkupPrefix); AppendUTF16toUTF8(ucs2string, html); - LOGCLIP(" Setting %zd bytes of %s data\n", html.Length(), - GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get()); + MOZ_CLIPBOARD_LOG(" Setting %zd bytes of %s data\n", html.Length(), + GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get()); gtk_selection_data_set(aSelectionData, selectionTarget, 8, (const guchar*)html.get(), html.Length()); return; @@ -1240,53 +1280,54 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, // We put kFileMime onto the clipboard as kURIListMime. if (selectionTarget == gdk_atom_intern(kURIListMime, FALSE)) { - LOGCLIP(" providing %s data\n", kURIListMime); + MOZ_CLIPBOARD_LOG(" providing %s data\n", kURIListMime); rv = trans->GetTransferData(kFileMime, getter_AddRefs(item)); if (NS_FAILED(rv) || !item) { - LOGCLIP(" failed to get %s data by GetTransferData()!\n", kFileMime); + MOZ_CLIPBOARD_LOG(" failed to get %s data by GetTransferData()!\n", + kFileMime); return; } nsCOMPtr<nsIFile> file = do_QueryInterface(item); if (!file) { - LOGCLIP(" failed to get nsIFile interface!"); + MOZ_CLIPBOARD_LOG(" failed to get nsIFile interface!"); return; } nsCOMPtr<nsIURI> fileURI; rv = NS_NewFileURI(getter_AddRefs(fileURI), file); if (NS_FAILED(rv)) { - LOGCLIP(" failed to get fileURI\n"); + MOZ_CLIPBOARD_LOG(" failed to get fileURI\n"); return; } nsAutoCString uri; if (NS_FAILED(fileURI->GetSpec(uri))) { - LOGCLIP(" failed to get fileURI spec\n"); + MOZ_CLIPBOARD_LOG(" failed to get fileURI spec\n"); return; } - LOGCLIP(" Setting %zd bytes of data\n", uri.Length()); + MOZ_CLIPBOARD_LOG(" Setting %zd bytes of data\n", uri.Length()); gtk_selection_data_set(aSelectionData, selectionTarget, 8, (const guchar*)uri.get(), uri.Length()); return; } - LOGCLIP(" Try if we have anything at GetTransferData() for %s\n", - GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get()); + MOZ_CLIPBOARD_LOG(" Try if we have anything at GetTransferData() for %s\n", + GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get()); // Try to match up the selection data target to something our // transferable provides. GUniquePtr<gchar> target_name(gdk_atom_name(selectionTarget)); if (!target_name) { - LOGCLIP(" Failed to get target name!\n"); + MOZ_CLIPBOARD_LOG(" Failed to get target name!\n"); return; } rv = trans->GetTransferData(target_name.get(), getter_AddRefs(item)); // nothing found? if (NS_FAILED(rv) || !item) { - LOGCLIP(" Failed to get anything from GetTransferData()!\n"); + MOZ_CLIPBOARD_LOG(" Failed to get anything from GetTransferData()!\n"); return; } @@ -1295,12 +1336,12 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, nsPrimitiveHelpers::CreateDataFromPrimitive( nsDependentCString(target_name.get()), item, &primitive_data, &dataLen); if (!primitive_data) { - LOGCLIP(" Failed to get primitive data!\n"); + MOZ_CLIPBOARD_LOG(" Failed to get primitive data!\n"); return; } - LOGCLIP(" Setting %s as a primitive data type, %d bytes\n", - target_name.get(), dataLen); + MOZ_CLIPBOARD_LOG(" Setting %s as a primitive data type, %d bytes\n", + target_name.get(), dataLen); gtk_selection_data_set(aSelectionData, selectionTarget, 8, /* 8 bits in a unit */ (const guchar*)primitive_data, dataLen); @@ -1320,8 +1361,9 @@ void nsClipboard::SelectionClearEvent(GtkClipboard* aGtkClipboard) { if (whichClipboard < 0) { return; } - LOGCLIP("nsClipboard::SelectionClearEvent (%s)\n", - whichClipboard == kSelectionClipboard ? "primary" : "clipboard"); + MOZ_CLIPBOARD_LOG( + "nsClipboard::SelectionClearEvent (%s)\n", + whichClipboard == kSelectionClipboard ? "primary" : "clipboard"); ClearCachedTargets(whichClipboard); ClearTransferable(whichClipboard); ClearClipboardCache(whichClipboard); @@ -1333,8 +1375,9 @@ void nsClipboard::OwnerChangedEvent(GtkClipboard* aGtkClipboard, if (whichClipboard < 0) { return; } - LOGCLIP("nsClipboard::OwnerChangedEvent (%s)\n", - whichClipboard == kSelectionClipboard ? "primary" : "clipboard"); + MOZ_CLIPBOARD_LOG( + "nsClipboard::OwnerChangedEvent (%s)\n", + whichClipboard == kSelectionClipboard ? "primary" : "clipboard"); GtkWidget* gtkWidget = [aEvent]() -> GtkWidget* { if (!aEvent->owner) { return nullptr; @@ -1360,13 +1403,13 @@ void nsClipboard::OwnerChangedEvent(GtkClipboard* aGtkClipboard, void clipboard_get_cb(GtkClipboard* aGtkClipboard, GtkSelectionData* aSelectionData, guint info, gpointer user_data) { - LOGCLIP("clipboard_get_cb() callback\n"); + MOZ_CLIPBOARD_LOG("clipboard_get_cb() callback\n"); nsClipboard* clipboard = static_cast<nsClipboard*>(user_data); clipboard->SelectionGetEvent(aGtkClipboard, aSelectionData); } void clipboard_clear_cb(GtkClipboard* aGtkClipboard, gpointer user_data) { - LOGCLIP("clipboard_clear_cb() callback\n"); + MOZ_CLIPBOARD_LOG("clipboard_clear_cb() callback\n"); nsClipboard* clipboard = static_cast<nsClipboard*>(user_data); clipboard->SelectionClearEvent(aGtkClipboard); } @@ -1374,7 +1417,7 @@ void clipboard_clear_cb(GtkClipboard* aGtkClipboard, gpointer user_data) { void clipboard_owner_change_cb(GtkClipboard* aGtkClipboard, GdkEventOwnerChange* aEvent, gpointer aUserData) { - LOGCLIP("clipboard_owner_change_cb() callback\n"); + MOZ_CLIPBOARD_LOG("clipboard_owner_change_cb() callback\n"); nsClipboard* clipboard = static_cast<nsClipboard*>(aUserData); clipboard->OwnerChangedEvent(aGtkClipboard, aEvent); } diff --git a/widget/gtk/nsClipboard.h b/widget/gtk/nsClipboard.h index 0ddbb59827..358136ae4e 100644 --- a/widget/gtk/nsClipboard.h +++ b/widget/gtk/nsClipboard.h @@ -17,20 +17,6 @@ #include "GUniquePtr.h" #include <gtk/gtk.h> -#ifdef MOZ_LOGGING -# include "mozilla/Logging.h" -# include "nsTArray.h" -# include "Units.h" -extern mozilla::LazyLogModule gClipboardLog; -# define LOGCLIP(...) \ - MOZ_LOG(gClipboardLog, mozilla::LogLevel::Debug, (__VA_ARGS__)) -# define LOGCLIP_ENABLED() \ - MOZ_LOG_TEST(gClipboardLog, mozilla::LogLevel::Debug) -#else -# define LOGCLIP(...) -# define LOGCLIP_ENABLED() false -#endif /* MOZ_LOGGING */ - class ClipboardTargets { friend class ClipboardData; diff --git a/widget/gtk/nsClipboardWayland.cpp b/widget/gtk/nsClipboardWayland.cpp index d179f242dd..316fcf90b6 100644 --- a/widget/gtk/nsClipboardWayland.cpp +++ b/widget/gtk/nsClipboardWayland.cpp @@ -22,7 +22,7 @@ nsRetrievalContextWayland::nsRetrievalContextWayland() = default; ClipboardTargets nsRetrievalContextWayland::GetTargetsImpl( int32_t aWhichClipboard) { - LOGCLIP("nsRetrievalContextWayland::GetTargetsImpl()\n"); + MOZ_CLIPBOARD_LOG("nsRetrievalContextWayland::GetTargetsImpl()\n"); return WaitForClipboardData(ClipboardDataType::Targets, aWhichClipboard) .ExtractTargets(); @@ -30,7 +30,8 @@ ClipboardTargets nsRetrievalContextWayland::GetTargetsImpl( ClipboardData nsRetrievalContextWayland::GetClipboardData( const char* aMimeType, int32_t aWhichClipboard) { - LOGCLIP("nsRetrievalContextWayland::GetClipboardData() mime %s\n", aMimeType); + MOZ_CLIPBOARD_LOG("nsRetrievalContextWayland::GetClipboardData() mime %s\n", + aMimeType); return WaitForClipboardData(ClipboardDataType::Data, aWhichClipboard, aMimeType); @@ -40,8 +41,9 @@ GUniquePtr<char> nsRetrievalContextWayland::GetClipboardText( int32_t aWhichClipboard) { GdkAtom selection = GetSelectionAtom(aWhichClipboard); - LOGCLIP("nsRetrievalContextWayland::GetClipboardText(), clipboard %s\n", - (selection == GDK_SELECTION_PRIMARY) ? "Primary" : "Selection"); + MOZ_CLIPBOARD_LOG( + "nsRetrievalContextWayland::GetClipboardText(), clipboard %s\n", + (selection == GDK_SELECTION_PRIMARY) ? "Primary" : "Selection"); return WaitForClipboardData(ClipboardDataType::Text, aWhichClipboard) .ExtractText(); @@ -50,8 +52,8 @@ GUniquePtr<char> nsRetrievalContextWayland::GetClipboardText( ClipboardData nsRetrievalContextWayland::WaitForClipboardData( ClipboardDataType aDataType, int32_t aWhichClipboard, const char* aMimeType) { - LOGCLIP("nsRetrievalContextWayland::WaitForClipboardData, MIME %s\n", - aMimeType); + MOZ_CLIPBOARD_LOG( + "nsRetrievalContextWayland::WaitForClipboardData, MIME %s\n", aMimeType); AsyncGtkClipboardRequest request(aDataType, aWhichClipboard, aMimeType); int iteration = 1; @@ -62,12 +64,13 @@ ClipboardData nsRetrievalContextWayland::WaitForClipboardData( /* sleep for 10 ms/iteration */ PR_Sleep(PR_MillisecondsToInterval(10)); if (PR_Now() - entryTime > kClipboardTimeout) { - LOGCLIP(" failed to get async clipboard data in time limit\n"); + MOZ_CLIPBOARD_LOG( + " failed to get async clipboard data in time limit\n"); break; } } - LOGCLIP("doing iteration %d msec %ld ...\n", (iteration - 1), - (long)((PR_Now() - entryTime) / 1000)); + MOZ_CLIPBOARD_LOG("doing iteration %d msec %ld ...\n", (iteration - 1), + (long)((PR_Now() - entryTime) / 1000)); gtk_main_iteration(); } diff --git a/widget/gtk/nsClipboardX11.cpp b/widget/gtk/nsClipboardX11.cpp index db12d1e69c..2693622922 100644 --- a/widget/gtk/nsClipboardX11.cpp +++ b/widget/gtk/nsClipboardX11.cpp @@ -138,25 +138,27 @@ ClipboardData nsRetrievalContextX11::WaitForClipboardData( (poll_result == -1 && errno == EINTR)); } - LOGCLIP("exceeded clipboard timeout"); + MOZ_CLIPBOARD_LOG("exceeded clipboard timeout"); return {}; } ClipboardTargets nsRetrievalContextX11::GetTargetsImpl( int32_t aWhichClipboard) { - LOGCLIP("nsRetrievalContextX11::GetTargetsImpl(%s)\n", - aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary" - : "clipboard"); + MOZ_CLIPBOARD_LOG("nsRetrievalContextX11::GetTargetsImpl(%s)\n", + aWhichClipboard == nsClipboard::kSelectionClipboard + ? "primary" + : "clipboard"); return WaitForClipboardData(ClipboardDataType::Targets, aWhichClipboard) .ExtractTargets(); } ClipboardData nsRetrievalContextX11::GetClipboardData(const char* aMimeType, int32_t aWhichClipboard) { - LOGCLIP("nsRetrievalContextX11::GetClipboardData(%s) MIME %s\n", - aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary" - : "clipboard", - aMimeType); + MOZ_CLIPBOARD_LOG("nsRetrievalContextX11::GetClipboardData(%s) MIME %s\n", + aWhichClipboard == nsClipboard::kSelectionClipboard + ? "primary" + : "clipboard", + aMimeType); return WaitForClipboardData(ClipboardDataType::Data, aWhichClipboard, aMimeType); @@ -164,9 +166,10 @@ ClipboardData nsRetrievalContextX11::GetClipboardData(const char* aMimeType, GUniquePtr<char> nsRetrievalContextX11::GetClipboardText( int32_t aWhichClipboard) { - LOGCLIP("nsRetrievalContextX11::GetClipboardText(%s)\n", - aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary" - : "clipboard"); + MOZ_CLIPBOARD_LOG("nsRetrievalContextX11::GetClipboardText(%s)\n", + aWhichClipboard == nsClipboard::kSelectionClipboard + ? "primary" + : "clipboard"); return WaitForClipboardData(ClipboardDataType::Text, aWhichClipboard) .ExtractText(); diff --git a/widget/gtk/nsDragService.cpp b/widget/gtk/nsDragService.cpp index 6cabfbbe2e..c3a3136013 100644 --- a/widget/gtk/nsDragService.cpp +++ b/widget/gtk/nsDragService.cpp @@ -1750,7 +1750,7 @@ nsresult nsDragService::CreateTempFile(nsITransferable* aItem, } // create and open channel for source uri - nsCOMPtr<nsIPrincipal> principal = aItem->GetRequestingPrincipal(); + nsCOMPtr<nsIPrincipal> principal = aItem->GetDataPrincipal(); nsContentPolicyType contentPolicyType = aItem->GetContentPolicyType(); nsCOMPtr<nsICookieJarSettings> cookieJarSettings = aItem->GetCookieJarSettings(); diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index 8702c154d6..bfd3f1b6f4 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -904,8 +904,7 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) { break; } case IntID::MenusCanOverlapOSBar: - // we want XUL popups to be able to overlap the task bar. - aResult = 1; + aResult = 0; break; case IntID::SkipNavigatingDisabledMenuItem: aResult = 1; @@ -1975,10 +1974,7 @@ void nsLookAndFeel::PerThemeData::Init() { mTitlebar = GetColorPair(style, GTK_STATE_FLAG_NORMAL); mTitlebarInactive = GetColorPair(style, GTK_STATE_FLAG_BACKDROP); mTitlebarRadius = IsSolidCSDStyleUsed() ? 0 : GetBorderRadius(style); - // Get titlebar spacing, a default one is 6 pixels (gtk/gtkheaderbar.c) - mTitlebarButtonSpacing = 6; - g_object_get(GetWidget(MOZ_GTK_HEADER_BAR), "spacing", - &mTitlebarButtonSpacing, nullptr); + mTitlebarButtonSpacing = moz_gtk_get_titlebar_button_spacing(); } // We special-case the header bar color in Adwaita, Yaru and Breeze to be the diff --git a/widget/gtk/nsNativeThemeGTK.cpp b/widget/gtk/nsNativeThemeGTK.cpp index 78d4e925fe..5c858d2313 100644 --- a/widget/gtk/nsNativeThemeGTK.cpp +++ b/widget/gtk/nsNativeThemeGTK.cpp @@ -195,14 +195,6 @@ bool nsNativeThemeGTK::GetGtkWidgetAndState(StyleAppearance aAppearance, aAppearance == StyleAppearance::Menulist || aAppearance == StyleAppearance::MenulistButton) { aState->active &= aState->inHover; - } else if (aAppearance == StyleAppearance::Treetwisty || - aAppearance == StyleAppearance::Treetwistyopen) { - if (nsTreeBodyFrame* treeBodyFrame = do_QueryFrame(aFrame)) { - const mozilla::AtomArray& atoms = - treeBodyFrame->GetPropertyArrayForCurrentDrawingItem(); - aState->selected = atoms.Contains(nsGkAtoms::selected); - aState->inHover = atoms.Contains(nsGkAtoms::hover); - } } if (IsFrameContentNodeInNamespace(aFrame, kNameSpaceID_XUL)) { @@ -292,6 +284,7 @@ bool nsNativeThemeGTK::GetGtkWidgetAndState(StyleAppearance aAppearance, break; } case StyleAppearance::NumberInput: + case StyleAppearance::PasswordInput: case StyleAppearance::Textfield: aGtkWidgetType = MOZ_GTK_ENTRY; break; @@ -299,17 +292,8 @@ bool nsNativeThemeGTK::GetGtkWidgetAndState(StyleAppearance aAppearance, aGtkWidgetType = MOZ_GTK_TEXT_VIEW; break; case StyleAppearance::Listbox: - case StyleAppearance::Treeview: aGtkWidgetType = MOZ_GTK_TREEVIEW; break; - case StyleAppearance::Treetwisty: - aGtkWidgetType = MOZ_GTK_TREEVIEW_EXPANDER; - if (aWidgetFlags) *aWidgetFlags = GTK_EXPANDER_COLLAPSED; - break; - case StyleAppearance::Treetwistyopen: - aGtkWidgetType = MOZ_GTK_TREEVIEW_EXPANDER; - if (aWidgetFlags) *aWidgetFlags = GTK_EXPANDER_EXPANDED; - break; case StyleAppearance::MenulistButton: case StyleAppearance::Menulist: aGtkWidgetType = MOZ_GTK_DROPDOWN; @@ -1091,6 +1075,7 @@ LayoutDeviceIntSize nsNativeThemeGTK::GetMinimumWidgetSize( result.height += border.TopBottom(); } break; case StyleAppearance::NumberInput: + case StyleAppearance::PasswordInput: case StyleAppearance::Textfield: { gint contentHeight = 0; gint borderPaddingHeight = 0; @@ -1135,12 +1120,6 @@ LayoutDeviceIntSize nsNativeThemeGTK::GetMinimumWidgetSize( result.width = 14; result.height = 13; break; - case StyleAppearance::Treetwisty: - case StyleAppearance::Treetwistyopen: { - gint expander_size; - moz_gtk_get_treeview_expander_size(&expander_size); - result.width = result.height = expander_size; - } break; default: break; } @@ -1243,12 +1222,6 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsPresContext* aPresContext, case StyleAppearance::ButtonArrowNext: case StyleAppearance::ButtonArrowPrevious: case StyleAppearance::Listbox: - case StyleAppearance::Treeview: - // case StyleAppearance::Treeitem: - case StyleAppearance::Treetwisty: - // case StyleAppearance::Treeline: - // case StyleAppearance::Treeheader: - case StyleAppearance::Treetwistyopen: case StyleAppearance::ProgressBar: case StyleAppearance::Progresschunk: case StyleAppearance::Tab: @@ -1262,6 +1235,7 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsPresContext* aPresContext, case StyleAppearance::SpinnerDownbutton: case StyleAppearance::SpinnerTextfield: case StyleAppearance::NumberInput: + case StyleAppearance::PasswordInput: case StyleAppearance::Textfield: case StyleAppearance::Textarea: case StyleAppearance::Range: @@ -1315,6 +1289,7 @@ bool nsNativeThemeGTK::ThemeDrawsFocusForWidget(nsIFrame* aFrame, case StyleAppearance::Textarea: case StyleAppearance::Textfield: case StyleAppearance::NumberInput: + case StyleAppearance::PasswordInput: return true; default: return false; diff --git a/widget/gtk/nsWaylandDisplay.cpp b/widget/gtk/nsWaylandDisplay.cpp index 1ea87b3bc5..c63c8f6564 100644 --- a/widget/gtk/nsWaylandDisplay.cpp +++ b/widget/gtk/nsWaylandDisplay.cpp @@ -28,7 +28,6 @@ void WaylandDisplayRelease() { MOZ_RELEASE_ASSERT(NS_IsMainThread(), "WaylandDisplay can be released in main thread only!"); if (!gWaylandDisplay) { - NS_WARNING("WaylandDisplayRelease(): Wayland display is missing!"); return; } delete gWaylandDisplay; @@ -151,7 +150,6 @@ static void global_registry_handler(void* data, wl_registry* registry, registry, id, &xdg_dbus_annotation_manager_v1_interface, 1); display->SetXdgDbusAnnotationManager(annotationManager); } else if (iface.EqualsLiteral("wl_seat")) { - // Install keyboard handlers for main thread only auto* seat = WaylandRegistryBind<wl_seat>(registry, id, &wl_seat_interface, 1); KeymapWrapper::SetSeat(seat, id); @@ -173,7 +171,7 @@ static void global_registry_remover(void* data, wl_registry* registry, static const struct wl_registry_listener registry_listener = { global_registry_handler, global_registry_remover}; -nsWaylandDisplay::~nsWaylandDisplay() {} +nsWaylandDisplay::~nsWaylandDisplay() = default; static void WlLogHandler(const char* format, va_list args) { char error[1000]; diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 0a78d0c8ec..2971497969 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -389,8 +389,7 @@ static void GtkWindowSetTransientFor(GtkWindow* aWindow, GtkWindow* aParent) { } nsWindow::nsWindow() - : mTitlebarRectMutex("nsWindow::mTitlebarRectMutex"), - mWindowVisibilityMutex("nsWindow::mWindowVisibilityMutex"), + : mWindowVisibilityMutex("nsWindow::mWindowVisibilityMutex"), mIsMapped(false), mIsDestroyed(false), mIsShown(false), @@ -514,10 +513,6 @@ void nsWindow::MaybeDispatchResized() { << mBounds << " size state " << mSizeMode; } - if (IsTopLevelWindowType()) { - UpdateTopLevelOpaqueRegion(); - } - // Notify the GtkCompositorWidget of a ClientSizeChange if (mCompositorWidgetDelegate) { mCompositorWidgetDelegate->NotifyClientSizeChanged(GetClientSize()); @@ -591,6 +586,7 @@ void nsWindow::Destroy() { mWaylandVsyncSource = nullptr; } mWaylandVsyncDispatcher = nullptr; + UnlockNativePointer(); #endif // dragService will be null after shutdown of the service manager. @@ -3216,9 +3212,7 @@ LayoutDeviceIntRect nsWindow::GetScreenBounds() { return rect; } -LayoutDeviceIntSize nsWindow::GetClientSize() { - return LayoutDeviceIntSize(mBounds.width, mBounds.height); -} +LayoutDeviceIntSize nsWindow::GetClientSize() { return mBounds.Size(); } LayoutDeviceIntRect nsWindow::GetClientBounds() { // GetBounds returns a rect whose top left represents the top left of the @@ -5379,8 +5373,6 @@ void nsWindow::OnWindowStateEvent(GtkWidget* aWidget, } else { ClearTransparencyBitmap(); } - } else { - SetTitlebarRect(); } } @@ -5391,7 +5383,6 @@ void nsWindow::OnDPIChanged() { if (PresShell* presShell = mWidgetListener->GetPresShell()) { presShell->BackingScaleFactorChanged(); } - mWidgetListener->UIResolutionChanged(); } NotifyAPZOfDPIChange(); } @@ -6934,80 +6925,99 @@ LayoutDeviceIntCoord nsWindow::GetTitlebarRadius() { return GdkCoordToDevicePixels(cssCoord); } +LayoutDeviceIntRegion nsWindow::GetOpaqueRegion() const { + AutoReadLock r(mOpaqueRegionLock); + return mOpaqueRegion; +} + // See subtract_corners_from_region() at gtk/gtkwindow.c // We need to subtract corners from toplevel window opaque region // to draw transparent corners of default Gtk titlebar. // Both implementations (cairo_region_t and wl_region) needs to be synced. -static void SubtractTitlebarCorners(cairo_region_t* aRegion, int aX, int aY, - int aWindowWidth, int aWindowHeight, - int aTitlebarRadius) { - if (!aTitlebarRadius) { - return; - } - cairo_rectangle_int_t rect = {aX, aY, aTitlebarRadius, aTitlebarRadius}; - cairo_region_subtract_rectangle(aRegion, &rect); - rect = { - aX + aWindowWidth - aTitlebarRadius, - aY, - aTitlebarRadius, - aTitlebarRadius, - }; - cairo_region_subtract_rectangle(aRegion, &rect); - rect = { - aX, - aY + aWindowHeight - aTitlebarRadius, - aTitlebarRadius, - aTitlebarRadius, - }; - cairo_region_subtract_rectangle(aRegion, &rect); - rect = { - aX + aWindowWidth - aTitlebarRadius, - aY + aWindowHeight - aTitlebarRadius, - aTitlebarRadius, - aTitlebarRadius, - }; - cairo_region_subtract_rectangle(aRegion, &rect); +static void SubtractTitlebarCorners(LayoutDeviceIntRegion& aRegion, + const LayoutDeviceIntRect& aRect, + LayoutDeviceIntCoord aRadius) { + if (!aRadius) { + return; + } + const LayoutDeviceIntSize size(aRadius, aRadius); + aRegion.SubOut(LayoutDeviceIntRect(aRect.TopLeft(), size)); + aRegion.SubOut(LayoutDeviceIntRect( + aRect.TopRight() - LayoutDeviceIntPoint(aRadius, 0), size)); + aRegion.SubOut(LayoutDeviceIntRect( + aRect.BottomLeft() - LayoutDeviceIntPoint(0, aRadius), size)); + aRegion.SubOut(LayoutDeviceIntRect( + aRect.BottomRight() - LayoutDeviceIntPoint(aRadius, aRadius), size)); +} + +void nsWindow::UpdateOpaqueRegion(const LayoutDeviceIntRegion& aRegion) { + LayoutDeviceIntRegion region = aRegion; + SubtractTitlebarCorners(region, LayoutDeviceIntRect({}, mBounds.Size()), + GetTitlebarRadius()); + { + AutoReadLock r(mOpaqueRegionLock); + if (mOpaqueRegion == region) { + return; + } + } + { + AutoWriteLock w(mOpaqueRegionLock); + mOpaqueRegion = region; + } + UpdateOpaqueRegionInternal(); } -void nsWindow::UpdateTopLevelOpaqueRegion() { +void nsWindow::UpdateOpaqueRegionInternal() { if (!mCompositedScreen) { return; } + if (!IsTopLevelWindowType()) { + // We need to clear target buffer alpha values of popup windows as + // SW-WR paints with alpha blending (see Bug 1674473). + return; + } + GdkWindow* window = GetToplevelGdkWindow(); if (!window) { return; } MOZ_ASSERT(gdk_window_get_window_type(window) == GDK_WINDOW_TOPLEVEL); - int x = 0; - int y = 0; - - gdk_window_get_position(mGdkWindow, &x, &y); - - int width = DevicePixelsToGdkCoordRoundDown(mBounds.width); - int height = DevicePixelsToGdkCoordRoundDown(mBounds.height); - - cairo_region_t* region = cairo_region_create(); - cairo_rectangle_int_t rect = {x, y, width, height}; - cairo_region_union_rectangle(region, &rect); - - // TODO: We actually could get a proper opaque region from layout, see - // nsIWidget::UpdateOpaqueRegion. This could simplify titlebar drawing. - int radius = DoDrawTilebarCorners() ? int(GetTitlebarRadius()) : 0; - SubtractTitlebarCorners(region, x, y, width, height, radius); - - gdk_window_set_opaque_region(window, region); - - cairo_region_destroy(region); + { + AutoReadLock lock(mOpaqueRegionLock); + cairo_region_t* region = nullptr; + if (!mOpaqueRegion.IsEmpty()) { + // NOTE(emilio): The opaque region is relative to our mContainer / + // mGdkWindow / inner window, but we're setting it on the top level + // GdkWindow / mShell. + // + // So we need to offset the rects by the position of mGdkWindow, in order + // for them to be in the right coordinate system. + GdkPoint offset{0, 0}; + gdk_window_get_position(mGdkWindow, &offset.x, &offset.y); + + region = cairo_region_create(); + + for (auto iter = mOpaqueRegion.RectIter(); !iter.Done(); iter.Next()) { + auto gdkRect = DevicePixelsToGdkRectRoundIn(iter.Get()); + cairo_rectangle_int_t rect = {gdkRect.x + offset.x, + gdkRect.y + offset.y, gdkRect.width, + gdkRect.height}; + cairo_region_union_rectangle(region, &rect); + } + } + gdk_window_set_opaque_region(window, region); + if (region) { + cairo_region_destroy(region); + } + } #ifdef MOZ_WAYLAND if (GdkIsWaylandDisplay()) { - moz_container_wayland_update_opaque_region(mContainer, radius); + moz_container_wayland_update_opaque_region(mContainer); } #endif - - SetTitlebarRect(); } bool nsWindow::IsChromeWindowTitlebar() { @@ -7181,24 +7191,6 @@ nsresult nsWindow::UpdateTranslucentWindowAlphaInternal(const nsIntRect& aRect, return NS_OK; } -#define TITLEBAR_HEIGHT 10 - -void nsWindow::SetTitlebarRect() { - MutexAutoLock lock(mTitlebarRectMutex); - - if (!mGdkWindow || !DoDrawTilebarCorners()) { - mTitlebarRect = LayoutDeviceIntRect(); - return; - } - mTitlebarRect = LayoutDeviceIntRect(0, 0, mBounds.width, - GdkCeiledScaleFactor() * TITLEBAR_HEIGHT); -} - -LayoutDeviceIntRect nsWindow::GetTitlebarRect() { - MutexAutoLock lock(mTitlebarRectMutex); - return mTitlebarRect; -} - void nsWindow::UpdateTitlebarTransparencyBitmap() { NS_ASSERTION(mTransparencyBitmapForTitlebar, "Transparency bitmap is already used to draw window shape"); @@ -8243,7 +8235,9 @@ static void toplevel_window_size_allocate_cb(GtkWidget* widget, return; } - window->UpdateTopLevelOpaqueRegion(); + // NOTE(emilio): We need to do this here to override GTK's own opaque region + // setting (which would clobber ours). + window->UpdateOpaqueRegionInternal(); } static gboolean delete_event_cb(GtkWidget* widget, GdkEventAny* event) { @@ -9180,9 +9174,11 @@ void nsWindow::SetDrawsInTitlebar(bool aState) { } else { ClearTransparencyBitmap(); } - } else { - SetTitlebarRect(); } + + // Recompute the input region (which should generally be null, but this is + // enough to work around bug 1844497, which is probably a gtk bug). + SetInputRegion(mInputRegion); } GtkWindow* nsWindow::GetCurrentTopmostWindow() const { @@ -9249,6 +9245,16 @@ GdkRectangle nsWindow::DevicePixelsToGdkRectRoundOut( return {x, y, right - x, bottom - y}; } +GdkRectangle nsWindow::DevicePixelsToGdkRectRoundIn( + const LayoutDeviceIntRect& aRect) { + double scale = FractionalScaleFactor(); + int x = ceil(aRect.x / scale); + int y = ceil(aRect.y / scale); + int right = floor((aRect.x + aRect.width) / scale); + int bottom = floor((aRect.y + aRect.height) / scale); + return {x, y, std::max(right - x, 0), std::max(bottom - y, 0)}; +} + GdkRectangle nsWindow::DevicePixelsToGdkSizeRoundUp( const LayoutDeviceIntSize& aSize) { double scale = FractionalScaleFactor(); @@ -9843,9 +9849,7 @@ void nsWindow::LockNativePointer() { return; } - if (mLockedPointer || mRelativePointer) { - UnlockNativePointer(); - } + UnlockNativePointer(); mLockedPointer = zwp_pointer_constraints_v1_lock_pointer( pointerConstraints, surface, pointer, nullptr, @@ -9869,9 +9873,6 @@ void nsWindow::LockNativePointer() { } void nsWindow::UnlockNativePointer() { - if (!GdkIsWaylandDisplay()) { - return; - } if (mRelativePointer) { zwp_relative_pointer_v1_destroy(mRelativePointer); mRelativePointer = nullptr; diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index 25d68129d8..1dd1f1dce8 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -19,6 +19,7 @@ #include "mozilla/RefPtr.h" #include "mozilla/TouchEvents.h" #include "mozilla/UniquePtr.h" +#include "mozilla/RWLock.h" #include "mozilla/widget/WindowSurface.h" #include "mozilla/widget/WindowSurfaceProvider.h" #include "nsBaseWidget.h" @@ -257,7 +258,9 @@ class nsWindow final : public nsBaseWidget { gint GetInputRegionMarginInGdkCoords(); - void UpdateTopLevelOpaqueRegion(); + void UpdateOpaqueRegionInternal(); + void UpdateOpaqueRegion(const LayoutDeviceIntRegion&) override; + LayoutDeviceIntRegion GetOpaqueRegion() const; already_AddRefed<mozilla::gfx::DrawTarget> StartRemoteDrawingInRegion( const LayoutDeviceIntRegion& aInvalidRegion, @@ -369,9 +372,7 @@ class nsWindow final : public nsBaseWidget { nsresult SetNonClientMargins(const LayoutDeviceIntMargin&) override; void SetDrawsInTitlebar(bool aState); - void SetTitlebarRect(); mozilla::LayoutDeviceIntCoord GetTitlebarRadius(); - LayoutDeviceIntRect GetTitlebarRect(); void UpdateWindowDraggingRegion( const LayoutDeviceIntRegion& aRegion) override; @@ -389,6 +390,7 @@ class nsWindow final : public nsBaseWidget { GdkPoint DevicePixelsToGdkPointRoundDown(const LayoutDeviceIntPoint&); GdkRectangle DevicePixelsToGdkSizeRoundUp(const LayoutDeviceIntSize&); GdkRectangle DevicePixelsToGdkRectRoundOut(const LayoutDeviceIntRect&); + GdkRectangle DevicePixelsToGdkRectRoundIn(const LayoutDeviceIntRect&); // From GDK int GdkCoordToDevicePixels(gint); @@ -631,9 +633,6 @@ class nsWindow final : public nsBaseWidget { // If true, draw our own window titlebar. bool mDrawInTitlebar = false; - mozilla::Mutex mTitlebarRectMutex; - LayoutDeviceIntRect mTitlebarRect MOZ_GUARDED_BY(mTitlebarRectMutex); - // This mutex protect window visibility changes. mozilla::Mutex mWindowVisibilityMutex; @@ -1018,6 +1017,8 @@ class nsWindow final : public nsBaseWidget { // Running in kiosk mode and requested to stay on specified monitor. // If monitor is removed minimize the window. mozilla::Maybe<int> mKioskMonitor; + LayoutDeviceIntRegion mOpaqueRegion MOZ_GUARDED_BY(mOpaqueRegionLock); + mutable mozilla::RWLock mOpaqueRegionLock{"nsWindow::mOpaqueRegion"}; }; #endif /* __nsWindow_h__ */ |