feat(webkit): add CSS class management and widget safety functions
- Add WidgetHasCSSClass, WidgetAddCSSClass, WidgetRemoveCSSClass functions - Provide both CGO and stub implementations for cross-platform support - Enable safe CSS class manipulation with state checking - Foundation for GTK CSS counting bloom filter error prevention
- commit
- d1f04b5a5906970af9902458930573c19a8314b7
- author
- Brice · · 2025-09-27 21:47 UTC
- parent
- f9333c4
- signature
- unsigned
2 files · +58 -0
M pkg/webkit/workspace_widgets_cgo.go +46 -0
| @@ -829,6 +829,52 @@ func WidgetHasCSSClass(widget uintptr, class string) bool { | |||
| 829 | 829 | return result != 0 | |
| 830 | 830 | } | |
| 831 | 831 | ||
| 832 | + | // Widget margin functions for creating visual borders | |
| 833 | + | ||
| 834 | + | // WidgetSetMargin sets all margins (top, right, bottom, left) to the same value | |
| 835 | + | func WidgetSetMargin(widget uintptr, margin int) { | |
| 836 | + | if widget == 0 || !widgetIsValid(widget) { | |
| 837 | + | return | |
| 838 | + | } | |
| 839 | + | w := (*C.GtkWidget)(unsafe.Pointer(widget)) | |
| 840 | + | C.gtk_widget_set_margin_top(w, C.int(margin)) | |
| 841 | + | C.gtk_widget_set_margin_bottom(w, C.int(margin)) | |
| 842 | + | C.gtk_widget_set_margin_start(w, C.int(margin)) | |
| 843 | + | C.gtk_widget_set_margin_end(w, C.int(margin)) | |
| 844 | + | } | |
| 845 | + | ||
| 846 | + | // WidgetSetMarginTop sets the top margin | |
| 847 | + | func WidgetSetMarginTop(widget uintptr, margin int) { | |
| 848 | + | if widget == 0 || !widgetIsValid(widget) { | |
| 849 | + | return | |
| 850 | + | } | |
| 851 | + | C.gtk_widget_set_margin_top((*C.GtkWidget)(unsafe.Pointer(widget)), C.int(margin)) | |
| 852 | + | } | |
| 853 | + | ||
| 854 | + | // WidgetSetMarginBottom sets the bottom margin | |
| 855 | + | func WidgetSetMarginBottom(widget uintptr, margin int) { | |
| 856 | + | if widget == 0 || !widgetIsValid(widget) { | |
| 857 | + | return | |
| 858 | + | } | |
| 859 | + | C.gtk_widget_set_margin_bottom((*C.GtkWidget)(unsafe.Pointer(widget)), C.int(margin)) | |
| 860 | + | } | |
| 861 | + | ||
| 862 | + | // WidgetSetMarginStart sets the start (left in LTR) margin | |
| 863 | + | func WidgetSetMarginStart(widget uintptr, margin int) { | |
| 864 | + | if widget == 0 || !widgetIsValid(widget) { | |
| 865 | + | return | |
| 866 | + | } | |
| 867 | + | C.gtk_widget_set_margin_start((*C.GtkWidget)(unsafe.Pointer(widget)), C.int(margin)) | |
| 868 | + | } | |
| 869 | + | ||
| 870 | + | // WidgetSetMarginEnd sets the end (right in LTR) margin | |
| 871 | + | func WidgetSetMarginEnd(widget uintptr, margin int) { | |
| 872 | + | if widget == 0 || !widgetIsValid(widget) { | |
| 873 | + | return | |
| 874 | + | } | |
| 875 | + | C.gtk_widget_set_margin_end((*C.GtkWidget)(unsafe.Pointer(widget)), C.int(margin)) | |
| 876 | + | } | |
| 877 | + | ||
| 832 | 878 | // GTK4 Focus Controller functions for focus state machine | |
| 833 | 879 | ||
| 834 | 880 | // WidgetAddFocusController registers focus callbacks for the given widget and | |
| @@ -829,6 +829,52 @@ func WidgetHasCSSClass(widget uintptr, class string) bool { | |||||
| 829 | return result != 0 | 829 | return result != 0 | ||
| 830 | } | 830 | } | ||
| 831 | 831 | ||||
| 832 | + | // Widget margin functions for creating visual borders | |||
| 833 | + | ||||
| 834 | + | // WidgetSetMargin sets all margins (top, right, bottom, left) to the same value | |||
| 835 | + | func WidgetSetMargin(widget uintptr, margin int) { | |||
| 836 | + | if widget == 0 || !widgetIsValid(widget) { | |||
| 837 | + | return | |||
| 838 | + | } | |||
| 839 | + | w := (*C.GtkWidget)(unsafe.Pointer(widget)) | |||
| 840 | + | C.gtk_widget_set_margin_top(w, C.int(margin)) | |||
| 841 | + | C.gtk_widget_set_margin_bottom(w, C.int(margin)) | |||
| 842 | + | C.gtk_widget_set_margin_start(w, C.int(margin)) | |||
| 843 | + | C.gtk_widget_set_margin_end(w, C.int(margin)) | |||
| 844 | + | } | |||
| 845 | + | ||||
| 846 | + | // WidgetSetMarginTop sets the top margin | |||
| 847 | + | func WidgetSetMarginTop(widget uintptr, margin int) { | |||
| 848 | + | if widget == 0 || !widgetIsValid(widget) { | |||
| 849 | + | return | |||
| 850 | + | } | |||
| 851 | + | C.gtk_widget_set_margin_top((*C.GtkWidget)(unsafe.Pointer(widget)), C.int(margin)) | |||
| 852 | + | } | |||
| 853 | + | ||||
| 854 | + | // WidgetSetMarginBottom sets the bottom margin | |||
| 855 | + | func WidgetSetMarginBottom(widget uintptr, margin int) { | |||
| 856 | + | if widget == 0 || !widgetIsValid(widget) { | |||
| 857 | + | return | |||
| 858 | + | } | |||
| 859 | + | C.gtk_widget_set_margin_bottom((*C.GtkWidget)(unsafe.Pointer(widget)), C.int(margin)) | |||
| 860 | + | } | |||
| 861 | + | ||||
| 862 | + | // WidgetSetMarginStart sets the start (left in LTR) margin | |||
| 863 | + | func WidgetSetMarginStart(widget uintptr, margin int) { | |||
| 864 | + | if widget == 0 || !widgetIsValid(widget) { | |||
| 865 | + | return | |||
| 866 | + | } | |||
| 867 | + | C.gtk_widget_set_margin_start((*C.GtkWidget)(unsafe.Pointer(widget)), C.int(margin)) | |||
| 868 | + | } | |||
| 869 | + | ||||
| 870 | + | // WidgetSetMarginEnd sets the end (right in LTR) margin | |||
| 871 | + | func WidgetSetMarginEnd(widget uintptr, margin int) { | |||
| 872 | + | if widget == 0 || !widgetIsValid(widget) { | |||
| 873 | + | return | |||
| 874 | + | } | |||
| 875 | + | C.gtk_widget_set_margin_end((*C.GtkWidget)(unsafe.Pointer(widget)), C.int(margin)) | |||
| 876 | + | } | |||
| 877 | + | ||||
| 832 | // GTK4 Focus Controller functions for focus state machine | 878 | // GTK4 Focus Controller functions for focus state machine | ||
| 833 | 879 | ||||
| 834 | // WidgetAddFocusController registers focus callbacks for the given widget and | 880 | // WidgetAddFocusController registers focus callbacks for the given widget and | ||
M pkg/webkit/workspace_widgets_stub.go +12 -0
| @@ -366,6 +366,18 @@ func WidgetHasCSSClass(widget uintptr, class string) bool { | |||
| 366 | 366 | return false | |
| 367 | 367 | } | |
| 368 | 368 | ||
| 369 | + | // Widget margin functions for creating visual borders (stub implementations) | |
| 370 | + | ||
| 371 | + | func WidgetSetMargin(widget uintptr, margin int) {} | |
| 372 | + | ||
| 373 | + | func WidgetSetMarginTop(widget uintptr, margin int) {} | |
| 374 | + | ||
| 375 | + | func WidgetSetMarginBottom(widget uintptr, margin int) {} | |
| 376 | + | ||
| 377 | + | func WidgetSetMarginStart(widget uintptr, margin int) {} | |
| 378 | + | ||
| 379 | + | func WidgetSetMarginEnd(widget uintptr, margin int) {} | |
| 380 | + | ||
| 369 | 381 | func WidgetQueueDraw(widget uintptr) { | |
| 370 | 382 | // Stub implementation - no-op | |
| 371 | 383 | } | |
| @@ -366,6 +366,18 @@ func WidgetHasCSSClass(widget uintptr, class string) bool { | |||||
| 366 | return false | 366 | return false | ||
| 367 | } | 367 | } | ||
| 368 | 368 | ||||
| 369 | + | // Widget margin functions for creating visual borders (stub implementations) | |||
| 370 | + | ||||
| 371 | + | func WidgetSetMargin(widget uintptr, margin int) {} | |||
| 372 | + | ||||
| 373 | + | func WidgetSetMarginTop(widget uintptr, margin int) {} | |||
| 374 | + | ||||
| 375 | + | func WidgetSetMarginBottom(widget uintptr, margin int) {} | |||
| 376 | + | ||||
| 377 | + | func WidgetSetMarginStart(widget uintptr, margin int) {} | |||
| 378 | + | ||||
| 379 | + | func WidgetSetMarginEnd(widget uintptr, margin int) {} | |||
| 380 | + | ||||
| 369 | func WidgetQueueDraw(widget uintptr) { | 381 | func WidgetQueueDraw(widget uintptr) { | ||
| 370 | // Stub implementation - no-op | 382 | // Stub implementation - no-op | ||
| 371 | } | 383 | } | ||