Commit a923be95 authored by Matthias Clasen's avatar Matthias Clasen
Browse files

Merge branch 'matthiasc/for-master' into 'master'

Matthiasc/for master

See merge request !2736
parents daf3b3a3 44c66196
Pipeline #223380 passed with stages
in 37 minutes and 49 seconds
......@@ -56,6 +56,7 @@ progressive_updated_callback (GdkPixbufLoader *loader,
picture = GTK_WIDGET (data);
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
gtk_picture_set_pixbuf (GTK_PICTURE (picture), NULL);
gtk_picture_set_pixbuf (GTK_PICTURE (picture), pixbuf);
}
......@@ -262,7 +263,7 @@ start_progressive_loading (GtkWidget *picture)
* The timeout simply simulates a slow data source by inserting
* pauses in the reading process.
*/
load_timeout = g_timeout_add (1500, progressive_timeout, picture);
load_timeout = g_timeout_add (300, progressive_timeout, picture);
g_source_set_name_by_id (load_timeout, "[gtk] progressive_timeout");
}
......@@ -414,6 +415,7 @@ do_images (GtkWidget *do_widget)
* will create the pixbuf and fill it in.
*/
picture = gtk_picture_new ();
gtk_picture_set_alternative_text (GTK_PICTURE (picture), "A slowly loading image");
gtk_frame_set_child (GTK_FRAME (frame), picture);
start_progressive_loading (picture);
......
......@@ -30,6 +30,7 @@
#include "gtkactionable.h"
#include "gtkactionmuxerprivate.h"
#include "gtkbutton.h"
#include "gtkcolorswatchprivate.h"
#include "gtkentryprivate.h"
#include "gtkexpander.h"
#include "gtkmodelbuttonprivate.h"
......@@ -284,7 +285,6 @@ static const GDBusInterfaceVTable button_action_vtable = {
};
/* }}} */
/* {{{ GtkSwitch */
static const Action switch_actions[] = {
......@@ -336,7 +336,104 @@ static const GDBusInterfaceVTable switch_action_vtable = {
};
/* }}} */
/* {{{ GtkColorSwatch */
static gboolean
color_swatch_select (GtkAtSpiContext *self)
{
GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
gtk_color_swatch_select (GTK_COLOR_SWATCH (accessible));
return TRUE;
}
static gboolean
color_swatch_activate (GtkAtSpiContext *self)
{
GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
gtk_color_swatch_activate (GTK_COLOR_SWATCH (accessible));
return TRUE;
}
static gboolean
color_swatch_customize (GtkAtSpiContext *self)
{
GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
gtk_color_swatch_customize (GTK_COLOR_SWATCH (accessible));
return TRUE;
}
static gboolean
color_swatch_is_enabled (GtkAtSpiContext *self)
{
GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
return gtk_color_swatch_get_selectable (GTK_COLOR_SWATCH (accessible));
}
static const Action color_swatch_actions[] = {
{
.name = "select",
.localized_name = NC_("accessibility", "Select"),
.description = NC_("accessibility", "Selects the color"),
.keybinding = "<Return>",
.activate = color_swatch_select,
.is_enabled = color_swatch_is_enabled,
},
{
.name = "activate",
.localized_name = NC_("accessibility", "Activate"),
.description = NC_("accessibility", "Activates the color"),
.keybinding = "<VoidSymbol>",
.activate = color_swatch_activate,
.is_enabled = color_swatch_is_enabled,
},
{
.name = "customize",
.localized_name = NC_("accessibility", "Customize"),
.description = NC_("accessibility", "Customizes the color"),
.keybinding = "<VoidSymbol>",
.activate = color_swatch_customize,
.is_enabled = color_swatch_is_enabled,
},
};
static void
color_swatch_handle_method (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
GtkAtSpiContext *self = user_data;
action_handle_method (self, method_name, parameters, invocation,
color_swatch_actions,
G_N_ELEMENTS (color_swatch_actions));
}
static GVariant *
color_swatch_handle_get_property (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GError **error,
gpointer user_data)
{
GtkAtSpiContext *self = user_data;
return action_handle_get_property (self, property_name, error,
color_swatch_actions,
G_N_ELEMENTS (color_swatch_actions));
}
static const GDBusInterfaceVTable color_swatch_action_vtable = {
color_swatch_handle_method,
color_swatch_handle_get_property,
NULL,
};
/* }}} */
/* {{{ GtkExpander */
static const Action expander_actions[] = {
......@@ -388,7 +485,6 @@ static const GDBusInterfaceVTable expander_action_vtable = {
};
/* }}} */
/* {{{ GtkEntry */
static gboolean is_primary_icon_enabled (GtkAtSpiContext *self);
......@@ -499,7 +595,6 @@ static const GDBusInterfaceVTable entry_action_vtable = {
};
/* }}} */
/* {{{ GtkPasswordEntry */
static gboolean is_peek_enabled (GtkAtSpiContext *self);
......@@ -822,8 +917,12 @@ gtk_atspi_get_action_vtable (GtkAccessible *accessible)
return &password_entry_action_vtable;
else if (GTK_IS_SWITCH (accessible))
return &switch_action_vtable;
else if (GTK_IS_COLOR_SWATCH (accessible))
return &color_swatch_action_vtable;
else if (GTK_IS_WIDGET (accessible))
return &widget_action_vtable;
return NULL;
}
/* vim:set foldmethod=marker expandtab: */
......@@ -249,10 +249,13 @@ gtk_color_button_init (GtkColorButton *button)
g_signal_connect (button->button, "clicked", G_CALLBACK (gtk_color_button_clicked), button);
gtk_widget_set_parent (button->button, GTK_WIDGET (button));
button->swatch = gtk_color_swatch_new ();
button->swatch = g_object_new (GTK_TYPE_COLOR_SWATCH,
"accessible-role", GTK_ACCESSIBLE_ROLE_IMG,
"selectable", FALSE,
"has-menu", FALSE,
NULL);
gtk_widget_set_can_focus (button->swatch, FALSE);
gtk_widget_remove_css_class (button->swatch, "activatable");
g_object_set (button->swatch, "has-menu", FALSE, NULL);
layout = gtk_widget_create_pango_layout (GTK_WIDGET (button), "Black");
pango_layout_get_pixel_extents (layout, NULL, &rect);
g_object_unref (layout);
......@@ -437,11 +440,37 @@ gtk_color_button_clicked (GtkButton *b,
gtk_window_present (GTK_WINDOW (button->cs_dialog));
}
static guint
scale_round (double value,
double scale)
{
value = floor (value * scale + 0.5);
value = CLAMP (value, 0, scale);
return (guint)value;
}
static char *
accessible_color_name (const GdkRGBA *color)
{
if (color->alpha < 1.0)
return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%"),
scale_round (color->red, 100),
scale_round (color->green, 100),
scale_round (color->blue, 100),
scale_round (color->alpha, 100));
else
return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%"),
scale_round (color->red, 100),
scale_round (color->green, 100),
scale_round (color->blue, 100));
}
static void
gtk_color_button_set_rgba (GtkColorChooser *chooser,
const GdkRGBA *rgba)
{
GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
char *text;
g_return_if_fail (GTK_IS_COLOR_BUTTON (chooser));
g_return_if_fail (rgba != NULL);
......@@ -449,6 +478,12 @@ gtk_color_button_set_rgba (GtkColorChooser *chooser,
button->rgba = *rgba;
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (button->swatch), &button->rgba);
text = accessible_color_name (rgba);
gtk_accessible_update_property (GTK_ACCESSIBLE (button->swatch),
GTK_ACCESSIBLE_PROPERTY_LABEL, text,
-1);
g_free (text);
g_object_notify (G_OBJECT (chooser), "rgba");
}
......
......@@ -144,8 +144,8 @@ swatch_drag_drop (GtkDropTarget *dest,
return TRUE;
}
static void
activate_color (GtkColorSwatch *swatch)
void
gtk_color_swatch_activate (GtkColorSwatch *swatch)
{
double red, green, blue, alpha;
......@@ -158,8 +158,8 @@ activate_color (GtkColorSwatch *swatch)
"color.select", "(dddd)", red, green, blue, alpha);
}
static void
customize_color (GtkColorSwatch *swatch)
void
gtk_color_swatch_customize (GtkColorSwatch *swatch)
{
double red, green, blue, alpha;
......@@ -172,6 +172,18 @@ customize_color (GtkColorSwatch *swatch)
"color.customize", "(dddd)", red, green, blue, alpha);
}
void
gtk_color_swatch_select (GtkColorSwatch *swatch)
{
gtk_widget_set_state_flags (GTK_WIDGET (swatch), GTK_STATE_FLAG_SELECTED, FALSE);
}
static gboolean
gtk_color_swatch_is_selected (GtkColorSwatch *swatch)
{
return (gtk_widget_get_state_flags (GTK_WIDGET (swatch)) & GTK_STATE_FLAG_SELECTED) != 0;
}
static gboolean
key_controller_key_pressed (GtkEventControllerKey *controller,
guint keyval,
......@@ -189,10 +201,10 @@ key_controller_key_pressed (GtkEventControllerKey *controller,
{
if (swatch->has_color &&
swatch->selectable &&
(gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_SELECTED) == 0)
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE);
!gtk_color_swatch_is_selected (swatch))
gtk_color_swatch_select (swatch);
else
customize_color (swatch);
gtk_color_swatch_customize (swatch);
return TRUE;
}
......@@ -245,19 +257,15 @@ do_popup (GtkColorSwatch *swatch)
static gboolean
swatch_primary_action (GtkColorSwatch *swatch)
{
GtkWidget *widget = (GtkWidget *)swatch;
GtkStateFlags flags;
flags = gtk_widget_get_state_flags (widget);
if (!swatch->has_color)
{
customize_color (swatch);
gtk_color_swatch_customize (swatch);
return TRUE;
}
else if (swatch->selectable &&
(flags & GTK_STATE_FLAG_SELECTED) == 0)
!gtk_color_swatch_is_selected (swatch))
{
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE);
gtk_color_swatch_select (swatch);
return TRUE;
}
......@@ -290,7 +298,7 @@ tap_action (GtkGestureClick *gesture,
if (n_press == 1)
swatch_primary_action (swatch);
else if (n_press > 1)
activate_color (swatch);
gtk_color_swatch_activate (swatch);
}
else if (button == GDK_BUTTON_SECONDARY)
{
......@@ -360,12 +368,30 @@ update_icon (GtkColorSwatch *swatch)
if (swatch->icon)
gtk_image_set_from_icon_name (image, swatch->icon);
else if (gtk_widget_get_state_flags (GTK_WIDGET (swatch)) & GTK_STATE_FLAG_SELECTED)
else if (gtk_color_swatch_is_selected (swatch))
gtk_image_set_from_icon_name (image, "object-select-symbolic");
else
gtk_image_clear (image);
}
static void
update_accessible_properties (GtkColorSwatch *swatch)
{
if (swatch->selectable)
{
gboolean selected = gtk_color_swatch_is_selected (swatch);
gtk_accessible_update_state (GTK_ACCESSIBLE (swatch),
GTK_ACCESSIBLE_STATE_CHECKED, selected,
-1);
}
else
{
gtk_accessible_reset_state (GTK_ACCESSIBLE (swatch),
GTK_ACCESSIBLE_STATE_CHECKED);
}
}
static void
swatch_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state)
......@@ -373,6 +399,7 @@ swatch_state_flags_changed (GtkWidget *widget,
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
update_icon (swatch);
update_accessible_properties (swatch);
GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->state_flags_changed (widget, previous_state);
}
......@@ -504,6 +531,7 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
NULL);
gtk_widget_class_set_css_name (widget_class, I_("colorswatch"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_RADIO);
}
static void
......@@ -544,8 +572,9 @@ gtk_color_swatch_init (GtkColorSwatch *swatch)
gtk_widget_add_css_class (GTK_WIDGET (swatch), "activatable");
swatch->overlay_widget = g_object_new (GTK_TYPE_IMAGE,
"css-name", "overlay",
NULL);
"accessible-role", GTK_ACCESSIBLE_ROLE_NONE,
"css-name", "overlay",
NULL);
gtk_widget_set_parent (swatch->overlay_widget, GTK_WIDGET (swatch));
}
......@@ -669,6 +698,8 @@ gtk_color_swatch_set_selectable (GtkColorSwatch *swatch,
return;
swatch->selectable = selectable;
update_accessible_properties (swatch);
g_object_notify (G_OBJECT (swatch), "selectable");
}
......
......@@ -50,6 +50,10 @@ void gtk_color_swatch_set_selectable (GtkColorSwatch *swatch,
gboolean selectable);
gboolean gtk_color_swatch_get_selectable (GtkColorSwatch *swatch);
void gtk_color_swatch_select (GtkColorSwatch *swatch);
void gtk_color_swatch_activate (GtkColorSwatch *swatch);
void gtk_color_swatch_customize (GtkColorSwatch *swatch);
G_END_DECLS
#endif /* __GTK_COLOR_SWATCH_PRIVATE_H__ */
......@@ -969,6 +969,11 @@ gtk_picture_set_alternative_text (GtkPicture *self,
g_free (self->alternative_text);
self->alternative_text = g_strdup (alternative_text);
gtk_accessible_update_property (GTK_ACCESSIBLE (self),
GTK_ACCESSIBLE_PROPERTY_DESCRIPTION, alternative_text,
-1);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ALTERNATIVE_TEXT]);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment