Compare commits

...

4 Commits

Author SHA1 Message Date
Matthias Clasen
1a14b6f7c3 Always draw outline
We can now control with CSS where there the outline
is drawn.
2017-08-29 11:20:57 -04:00
Matthias Clasen
3fc619cd32 Support the new state in CSS selectors
Make :focus(visible) match the new state.
2017-08-29 11:20:57 -04:00
Matthias Clasen
667b944766 Set the new state flag
For now, we only set the new visible focus state
on the focus widget, when we have visible focus.
Later on, we will allow setting it on other widgets.
2017-08-29 11:20:57 -04:00
Matthias Clasen
dedd54d849 Add a state flag for visible focus
The new flag is called GTK_STATE_FLAGS_FOCUS_VISIBLE.
2017-08-28 22:22:57 -04:00
4 changed files with 38 additions and 27 deletions

View File

@@ -683,7 +683,8 @@ gtk_css_pseudoclass_name (GtkStateFlags state)
"link",
"visited",
"checked",
"drop(active)"
"drop(active)",
"focus(visible)"
};
guint i;
@@ -1116,6 +1117,7 @@ parse_selector_pseudo_class (GtkCssParser *parser,
{ "selected", 0, GTK_STATE_FLAG_SELECTED, },
{ "disabled", 0, GTK_STATE_FLAG_INSENSITIVE, },
{ "indeterminate", 0, GTK_STATE_FLAG_INCONSISTENT, },
{ "focus(visible)",0, GTK_STATE_FLAG_FOCUS_VISIBLE, },
{ "focus", 0, GTK_STATE_FLAG_FOCUSED, },
{ "backdrop", 0, GTK_STATE_FLAG_BACKDROP, },
{ "dir(ltr)", 0, GTK_STATE_FLAG_DIR_LTR, },

View File

@@ -786,6 +786,7 @@ typedef enum
* @GTK_STATE_FLAG_VISITED: The location the widget points to has already been visited. Since 3.12
* @GTK_STATE_FLAG_CHECKED: Widget is checked. Since 3.14
* @GTK_STATE_FLAG_DROP_ACTIVE: Widget is highlighted as a drop target for DND. Since 3.20
* @GTK_STATE_FLAG_FOCUS_VISIBLE: Widget has the visible focus. Since: 3.92
*
* Describes a widget state. Widget states are used to match the widget
* against CSS pseudo-classes. Note that GTK extends the regular CSS
@@ -793,20 +794,21 @@ typedef enum
*/
typedef enum
{
GTK_STATE_FLAG_NORMAL = 0,
GTK_STATE_FLAG_ACTIVE = 1 << 0,
GTK_STATE_FLAG_PRELIGHT = 1 << 1,
GTK_STATE_FLAG_SELECTED = 1 << 2,
GTK_STATE_FLAG_INSENSITIVE = 1 << 3,
GTK_STATE_FLAG_INCONSISTENT = 1 << 4,
GTK_STATE_FLAG_FOCUSED = 1 << 5,
GTK_STATE_FLAG_BACKDROP = 1 << 6,
GTK_STATE_FLAG_DIR_LTR = 1 << 7,
GTK_STATE_FLAG_DIR_RTL = 1 << 8,
GTK_STATE_FLAG_LINK = 1 << 9,
GTK_STATE_FLAG_VISITED = 1 << 10,
GTK_STATE_FLAG_CHECKED = 1 << 11,
GTK_STATE_FLAG_DROP_ACTIVE = 1 << 12
GTK_STATE_FLAG_NORMAL = 0,
GTK_STATE_FLAG_ACTIVE = 1 << 0,
GTK_STATE_FLAG_PRELIGHT = 1 << 1,
GTK_STATE_FLAG_SELECTED = 1 << 2,
GTK_STATE_FLAG_INSENSITIVE = 1 << 3,
GTK_STATE_FLAG_INCONSISTENT = 1 << 4,
GTK_STATE_FLAG_FOCUSED = 1 << 5,
GTK_STATE_FLAG_BACKDROP = 1 << 6,
GTK_STATE_FLAG_DIR_LTR = 1 << 7,
GTK_STATE_FLAG_DIR_RTL = 1 << 8,
GTK_STATE_FLAG_LINK = 1 << 9,
GTK_STATE_FLAG_VISITED = 1 << 10,
GTK_STATE_FLAG_CHECKED = 1 << 11,
GTK_STATE_FLAG_DROP_ACTIVE = 1 << 12,
GTK_STATE_FLAG_FOCUS_VISIBLE = 1 << 13
} GtkStateFlags;
/**

View File

@@ -15197,15 +15197,12 @@ gtk_widget_snapshot (GtkWidget *widget,
cairo_destroy (cr);
}
if (gtk_widget_has_visible_focus (widget))
{
gtk_snapshot_offset (snapshot, margin.left, margin.top);
gtk_css_style_snapshot_outline (style,
snapshot,
allocation.width - margin.left - margin.right,
allocation.height - margin.top - margin.bottom);
gtk_snapshot_offset (snapshot, - margin.left, - margin.top);
}
gtk_snapshot_offset (snapshot, margin.left, margin.top);
gtk_css_style_snapshot_outline (style,
snapshot,
allocation.width - margin.left - margin.right,
allocation.height - margin.top - margin.bottom);
gtk_snapshot_offset (snapshot, - margin.left, - margin.top);
if (opacity < 1.0)
gtk_snapshot_pop (snapshot);
@@ -15486,10 +15483,20 @@ gtk_widget_set_focus_child (GtkWidget *widget,
}
if (priv->focus_child)
gtk_widget_unset_state_flags (priv->focus_child, GTK_STATE_FLAG_FOCUSED);
gtk_widget_unset_state_flags (priv->focus_child,
GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_VISIBLE);
if (child)
gtk_widget_set_state_flags (child, GTK_STATE_FLAG_FOCUSED, FALSE);
{
GtkWidget *toplevel;
GtkStateFlags flags = GTK_STATE_FLAG_FOCUSED;
toplevel = _gtk_widget_get_toplevel (widget);
if (!GTK_IS_WINDOW (toplevel) || gtk_window_get_focus_visible (GTK_WINDOW (toplevel)))
flags |= GTK_STATE_FLAG_FOCUS_VISIBLE;
gtk_widget_set_state_flags (child, flags, FALSE);
}
g_set_object (&priv->focus_child, child);

View File

@@ -34,7 +34,7 @@
G_BEGIN_DECLS
#define GTK_STATE_FLAGS_BITS 13
#define GTK_STATE_FLAGS_BITS 14
struct _GtkWidgetPrivate
{