Debian Codegraph @

gtk/a11y/gtkwidgetaccessible.c

raw
1 /* GTK+ - accessibility implementations
2 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "config.h"
19
20 #include <gtk/gtk.h>
21 #ifdef GDK_WINDOWING_X11
22 #include <gdk/x11/gdkx.h>
23 #endif
24 #include "gtkwidgetaccessibleprivate.h"
25 #include "gtknotebookpageaccessible.h"
26
27 struct _GtkWidgetAccessiblePrivate
28 {
29 AtkLayer layer;
30 };
31
32 #define TOOLTIP_KEY "tooltip"
33
34 extern GtkWidget *_focus_widget;
35
36
37 static gboolean gtk_widget_accessible_on_screen (GtkWidget *widget);
38 static gboolean gtk_widget_accessible_all_parents_visible (GtkWidget *widget);
39
40 static void atk_component_interface_init (AtkComponentIface *iface);
41
42 G_DEFINE_TYPE_WITH_CODE (GtkWidgetAccessible, gtk_widget_accessible, GTK_TYPE_ACCESSIBLE,
43 G_ADD_PRIVATE (GtkWidgetAccessible)
44 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
45
46 /* Translate GtkWidget::focus-in/out-event to AtkObject::focus-event */
47 static gboolean
48 focus_cb (GtkWidget *widget,
49 GdkEventFocus *event)
50 {
51 AtkObject *obj;
52
53 obj = gtk_widget_get_accessible (widget);
54
55 g_signal_emit_by_name (obj, "focus-event", event->in);
56
57 return FALSE;
58 }
59
60 /* Translate GtkWidget property change notification to the notify_gtk vfunc */
61 static void
62 notify_cb (GObject *obj,
63 GParamSpec *pspec)
64 {
65 GtkWidgetAccessible *widget;
66 GtkWidgetAccessibleClass *klass;
67
68 widget = GTK_WIDGET_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (obj)));
69 klass = GTK_WIDGET_ACCESSIBLE_GET_CLASS (widget);
70 if (klass->notify_gtk)
71 klass->notify_gtk (obj, pspec);
72 }
73
74 /* Translate GtkWidget::size-allocate to AtkComponent::bounds-changed */
75 static void
76 size_allocate_cb (GtkWidget *widget,
77 GtkAllocation *allocation)
78 {
79 AtkObject* accessible;
80 AtkRectangle rect;
81
82 accessible = gtk_widget_get_accessible (widget);
83 if (ATK_IS_COMPONENT (accessible))
84 {
85 rect.x = allocation->x;
86 rect.y = allocation->y;
87 rect.width = allocation->width;
88 rect.height = allocation->height;
89 g_signal_emit_by_name (accessible, "bounds-changed", &rect);
90 }
91 }
92
93 /* Translate GtkWidget mapped state into AtkObject showing */
94 static gint
95 map_cb (GtkWidget *widget)
96 {
97 AtkObject *accessible;
98
99 accessible = gtk_widget_get_accessible (widget);
100 atk_object_notify_state_change (accessible, ATK_STATE_SHOWING,
101 gtk_widget_get_mapped (widget));
102 return 1;
103 }
104
105 static void
106 gtk_widget_accessible_focus_event (AtkObject *obj,
107 gboolean focus_in)
108 {
109 AtkObject *focus_obj;
110
111 focus_obj = g_object_get_data (G_OBJECT (obj), "gail-focus-object");
112 if (focus_obj == NULL)
113 focus_obj = obj;
114 atk_object_notify_state_change (focus_obj, ATK_STATE_FOCUSED, focus_in);
115 }
116
117 static void
118 gtk_widget_accessible_update_tooltip (GtkWidgetAccessible *accessible,
119 GtkWidget *widget)
120 {
121 g_object_set_data_full (G_OBJECT (accessible),
122 TOOLTIP_KEY,
123 gtk_widget_get_tooltip_text (widget),
124 g_free);
125 }
126
127 static void
128 gtk_widget_accessible_initialize (AtkObject *obj,
129 gpointer data)
130 {
131 GtkWidget *widget;
132
133 widget = GTK_WIDGET (data);
134
135 g_signal_connect_after (widget, "focus-in-event", G_CALLBACK (focus_cb), NULL);
136 g_signal_connect_after (widget, "focus-out-event", G_CALLBACK (focus_cb), NULL);
137 g_signal_connect (widget, "notify", G_CALLBACK (notify_cb), NULL);
138 g_signal_connect (widget, "size-allocate", G_CALLBACK (size_allocate_cb), NULL);
139 g_signal_connect (widget, "map", G_CALLBACK (map_cb), NULL);
140 g_signal_connect (widget, "unmap", G_CALLBACK (map_cb), NULL);
141
142 GTK_WIDGET_ACCESSIBLE (obj)->priv->layer = ATK_LAYER_WIDGET;
143 obj->role = ATK_ROLE_UNKNOWN;
144
145 gtk_widget_accessible_update_tooltip (GTK_WIDGET_ACCESSIBLE (obj), widget);
146 }
147
148 static const gchar *
149 gtk_widget_accessible_get_description (AtkObject *accessible)
150 {
151 GtkWidget *widget;
152
153 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
154 if (widget == NULL)
155 return NULL;
156
157 if (accessible->description)
158 return accessible->description;
159
160 return g_object_get_data (G_OBJECT (accessible), TOOLTIP_KEY);
161 }
162
163 static AtkObject *
164 gtk_widget_accessible_get_parent (AtkObject *accessible)
165 {
166 AtkObject *parent;
167 GtkWidget *widget, *parent_widget;
168
169 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
170 if (widget == NULL)
171 return NULL;
172
173 parent = accessible->accessible_parent;
174 if (parent != NULL)
175 return parent;
176
177 parent_widget = gtk_widget_get_parent (widget);
178 if (parent_widget == NULL)
179 return NULL;
180
181 /* For a widget whose parent is a GtkNoteBook, we return the
182 * accessible object corresponding the GtkNotebookPage containing
183 * the widget as the accessible parent.
184 */
185 if (GTK_IS_NOTEBOOK (parent_widget))
186 {
187 gint page_num;
188 GtkWidget *child;
189 GtkNotebook *notebook;
190
191 page_num = 0;
192 notebook = GTK_NOTEBOOK (parent_widget);
193 while (TRUE)
194 {
195 child = gtk_notebook_get_nth_page (notebook, page_num);
196 if (!child)
197 break;
198 if (child == widget)
199 {
200 parent = gtk_widget_get_accessible (parent_widget);
201 parent = atk_object_ref_accessible_child (parent, page_num);
202 g_object_unref (parent);
203 return parent;
204 }
205 page_num++;
206 }
207 }
208 parent = gtk_widget_get_accessible (parent_widget);
209 return parent;
210 }
211
212 static GtkWidget *
213 find_label (GtkWidget *widget)
214 {
215 GList *labels;
216 GtkWidget *label;
217 GtkWidget *temp_widget;
218 GList *ptr;
219
220 labels = gtk_widget_list_mnemonic_labels (widget);
221 label = NULL;
222 ptr = labels;
223 while (ptr)
224 {
225 if (ptr->data)
226 {
227 label = ptr->data;
228 break;
229 }
230 ptr = ptr->next;
231 }
232 g_list_free (labels);
233
234 /* Ignore a label within a button; bug #136602 */
235 if (label && GTK_IS_BUTTON (widget))
236 {
237 temp_widget = label;
238 while (temp_widget)
239 {
240 if (temp_widget == widget)
241 {
242 label = NULL;
243 break;
244 }
245 temp_widget = gtk_widget_get_parent (temp_widget);
246 }
247 }
248 return label;
249 }
250
251 static AtkRelationSet *
252 gtk_widget_accessible_ref_relation_set (AtkObject *obj)
253 {
254 GtkWidget *widget;
255 AtkRelationSet *relation_set;
256 GtkWidget *label;
257 AtkObject *array[1];
258 AtkRelation* relation;
259
260 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
261 if (widget == NULL)
262 return NULL;
263
264 relation_set = ATK_OBJECT_CLASS (gtk_widget_accessible_parent_class)->ref_relation_set (obj);
265
266 if (GTK_IS_BOX (widget))
267 return relation_set;
268
269 if (!atk_relation_set_contains (relation_set, ATK_RELATION_LABELLED_BY))
270 {
271 label = find_label (widget);
272 if (label == NULL)
273 {
274 if (GTK_IS_BUTTON (widget) && gtk_widget_get_mapped (widget))
275 /*
276 * Handle the case where GnomeIconEntry is the mnemonic widget.
277 * The GtkButton which is a grandchild of the GnomeIconEntry
278 * should really be the mnemonic widget. See bug #133967.
279 */
280 {
281 GtkWidget *temp_widget;
282
283 temp_widget = gtk_widget_get_parent (widget);
284 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
285 if (GTK_IS_ALIGNMENT (temp_widget))
286 {
287 temp_widget = gtk_widget_get_parent (temp_widget);
288 if (GTK_IS_BOX (temp_widget))
289 {
290 label = find_label (temp_widget);
291 if (!label)
292 label = find_label (gtk_widget_get_parent (temp_widget));
293 }
294 }
295 G_GNUC_END_IGNORE_DEPRECATIONS
296 }
297 else if (GTK_IS_COMBO_BOX (widget))
298 /*
299 * Handle the case when GtkFileChooserButton is the mnemonic
300 * widget. The GtkComboBox which is a child of the
301 * GtkFileChooserButton should be the mnemonic widget.
302 * See bug #359843.
303 */
304 {
305 GtkWidget *temp_widget;
306
307 temp_widget = gtk_widget_get_parent (widget);
308 if (GTK_IS_BOX (temp_widget))
309 {
310 label = find_label (temp_widget);
311 }
312 }
313 }
314
315 if (label)
316 {
317 array[0] = gtk_widget_get_accessible (label);
318
319 relation = atk_relation_new (array, 1, ATK_RELATION_LABELLED_BY);
320 atk_relation_set_add (relation_set, relation);
321 g_object_unref (relation);
322 }
323 }
324
325 return relation_set;
326 }
327
328 static AtkStateSet *
329 gtk_widget_accessible_ref_state_set (AtkObject *accessible)
330 {
331 GtkWidget *widget;
332 AtkStateSet *state_set;
333
334 state_set = ATK_OBJECT_CLASS (gtk_widget_accessible_parent_class)->ref_state_set (accessible);
335
336 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
337 if (widget == NULL)
338 atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
339 else
340 {
341 if (gtk_widget_is_sensitive (widget))
342 {
343 atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE);
344 atk_state_set_add_state (state_set, ATK_STATE_ENABLED);
345 }
346
347 if (gtk_widget_get_can_focus (widget))
348 {
349 atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
350 }
351 /*
352 * We do not currently generate notifications when an ATK object
353 * corresponding to a GtkWidget changes visibility by being scrolled
354 * on or off the screen. The testcase for this is the main window
355 * of the testgtk application in which a set of buttons in a GtkVBox
356 * is in a scrolled window with a viewport.
357 *
358 * To generate the notifications we would need to do the following:
359 * 1) Find the GtkViewport among the ancestors of the objects
360 * 2) Create an accessible for the viewport
361 * 3) Connect to the value-changed signal on the viewport
362 * 4) When the signal is received we need to traverse the children
363 * of the viewport and check whether the children are visible or not
364 * visible; we may want to restrict this to the widgets for which
365 * accessible objects have been created.
366 * 5) We probably need to store a variable on_screen in the
367 * GtkWidgetAccessible data structure so we can determine whether
368 * the value has changed.
369 */
370 if (gtk_widget_get_visible (widget))
371 {
372 atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
373 if (gtk_widget_accessible_on_screen (widget) &&
374 gtk_widget_get_mapped (widget) &&
375 gtk_widget_accessible_all_parents_visible (widget))
376 atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
377 }
378
379 if (gtk_widget_has_focus (widget) && (widget == _focus_widget))
380 {
381 AtkObject *focus_obj;
382
383 focus_obj = g_object_get_data (G_OBJECT (accessible), "gail-focus-object");
384 if (focus_obj == NULL)
385 atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
386 }
387
388 if (gtk_widget_has_default (widget))
389 atk_state_set_add_state (state_set, ATK_STATE_DEFAULT);
390
391 if (GTK_IS_ORIENTABLE (widget))
392 {
393 if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL)
394 atk_state_set_add_state (state_set, ATK_STATE_HORIZONTAL);
395 else
396 atk_state_set_add_state (state_set, ATK_STATE_VERTICAL);
397 }
398
399 if (gtk_widget_get_has_tooltip (widget))
400 atk_state_set_add_state (state_set, ATK_STATE_HAS_TOOLTIP);
401 }
402 return state_set;
403 }
404
405 static gint
406 gtk_widget_accessible_get_index_in_parent (AtkObject *accessible)
407 {
408 GtkWidget *widget;
409 GtkWidget *parent_widget;
410 gint index;
411 GList *children;
412
413 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
414
415 if (widget == NULL)
416 return -1;
417
418 if (accessible->accessible_parent)
419 {
420 AtkObject *parent;
421
422 parent = accessible->accessible_parent;
423
424 if (GTK_IS_NOTEBOOK_PAGE_ACCESSIBLE (parent))
425 return 0;
426 else
427 {
428 gint n_children, i;
429 gboolean found = FALSE;
430
431 n_children = atk_object_get_n_accessible_children (parent);
432 for (i = 0; i < n_children; i++)
433 {
434 AtkObject *child;
435
436 child = atk_object_ref_accessible_child (parent, i);
437 if (child == accessible)
438 found = TRUE;
439
440 g_object_unref (child);
441 if (found)
442 return i;
443 }
444 }
445 }
446
447 if (!GTK_IS_WIDGET (widget))
448 return -1;
449 parent_widget = gtk_widget_get_parent (widget);
450 if (!GTK_IS_CONTAINER (parent_widget))
451 return -1;
452
453 children = gtk_container_get_children (GTK_CONTAINER (parent_widget));
454
455 index = g_list_index (children, widget);
456 g_list_free (children);
457 return index;
458 }
459
460 /* This function is the default implementation for the notify_gtk
461 * vfunc which gets called when a property changes value on the
462 * GtkWidget associated with a GtkWidgetAccessible. It constructs
463 * an AtkPropertyValues structure and emits a “property_changed”
464 * signal which causes the user specified AtkPropertyChangeHandler
465 * to be called.
466 */
467 static void
468 gtk_widget_accessible_notify_gtk (GObject *obj,
469 GParamSpec *pspec)
470 {
471 GtkWidget* widget = GTK_WIDGET (obj);
472 AtkObject* atk_obj = gtk_widget_get_accessible (widget);
473 AtkState state;
474 gboolean value;
475
476 if (g_strcmp0 (pspec->name, "has-focus") == 0)
477 /*
478 * We use focus-in-event and focus-out-event signals to catch
479 * focus changes so we ignore this.
480 */
481 return;
482 else if (g_strcmp0 (pspec->name, "tooltip-text") == 0)
483 {
484 gtk_widget_accessible_update_tooltip (GTK_WIDGET_ACCESSIBLE (atk_obj),
485 widget);
486
487 if (atk_obj->description == NULL)
488 g_object_notify (G_OBJECT (atk_obj), "accessible-description");
489 return;
490 }
491 else if (g_strcmp0 (pspec->name, "visible") == 0)
492 {
493 state = ATK_STATE_VISIBLE;
494 value = gtk_widget_get_visible (widget);
495 }
496 else if (g_strcmp0 (pspec->name, "sensitive") == 0)
497 {
498 state = ATK_STATE_SENSITIVE;
499 value = gtk_widget_get_sensitive (widget);
500 }
501 else if (g_strcmp0 (pspec->name, "orientation") == 0 &&
502 GTK_IS_ORIENTABLE (widget))
503 {
504 GtkOrientable *orientable;
505
506 orientable = GTK_ORIENTABLE (widget);
507
508 state = ATK_STATE_HORIZONTAL;
509 value = (gtk_orientable_get_orientation (orientable) == GTK_ORIENTATION_HORIZONTAL);
510 }
511 else if (g_strcmp0 (pspec->name, "has-tooltip") == 0)
512 {
513 state = ATK_STATE_HAS_TOOLTIP;
514 value = gtk_widget_get_has_tooltip (widget);
515 }
516 else
517 return;
518
519 atk_object_notify_state_change (atk_obj, state, value);
520 if (state == ATK_STATE_SENSITIVE)
521 atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, value);
522
523 if (state == ATK_STATE_HORIZONTAL)
524 atk_object_notify_state_change (atk_obj, ATK_STATE_VERTICAL, !value);
525 }
526
527 static AtkAttributeSet *
528 gtk_widget_accessible_get_attributes (AtkObject *obj)
529 {
530 AtkAttributeSet *attributes;
531 AtkAttribute *toolkit;
532
533 toolkit = g_new (AtkAttribute, 1);
534 toolkit->name = g_strdup ("toolkit");
535 toolkit->value = g_strdup ("gtk");
536
537 attributes = g_slist_append (NULL, toolkit);
538
539 return attributes;
540 }
541
542 static void
543 gtk_widget_accessible_class_init (GtkWidgetAccessibleClass *klass)
544 {
545 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
546
547 klass->notify_gtk = gtk_widget_accessible_notify_gtk;
548
549 class->get_description = gtk_widget_accessible_get_description;
550 class->get_parent = gtk_widget_accessible_get_parent;
551 class->ref_relation_set = gtk_widget_accessible_ref_relation_set;
552 class->ref_state_set = gtk_widget_accessible_ref_state_set;
553 class->get_index_in_parent = gtk_widget_accessible_get_index_in_parent;
554 class->initialize = gtk_widget_accessible_initialize;
555 class->get_attributes = gtk_widget_accessible_get_attributes;
556 class->focus_event = gtk_widget_accessible_focus_event;
557 }
558
559 static void
560 gtk_widget_accessible_init (GtkWidgetAccessible *accessible)
561 {
562 accessible->priv = gtk_widget_accessible_get_instance_private (accessible);
563 }
564
565 static void
566 gtk_widget_accessible_get_extents (AtkComponent *component,
567 gint *x,
568 gint *y,
569 gint *width,
570 gint *height,
571 AtkCoordType coord_type)
572 {
573 GdkWindow *window;
574 gint x_window, y_window;
575 gint x_toplevel, y_toplevel;
576 GtkWidget *widget;
577 GtkAllocation allocation;
578
579 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
580 if (widget == NULL)
581 return;
582
583 gtk_widget_get_allocation (widget, &allocation);
584 *width = allocation.width;
585 *height = allocation.height;
586 if (!gtk_widget_accessible_on_screen (widget) || (!gtk_widget_is_drawable (widget)))
587 {
588 *x = G_MININT;
589 *y = G_MININT;
590 return;
591 }
592
593 if (gtk_widget_get_parent (widget))
594 {
595 *x = allocation.x;
596 *y = allocation.y;
597 window = gtk_widget_get_parent_window (widget);
598 }
599 else
600 {
601 *x = 0;
602 *y = 0;
603 window = gtk_widget_get_window (widget);
604 }
605 gdk_window_get_origin (window, &x_window, &y_window);
606 *x += x_window;
607 *y += y_window;
608
609 if (coord_type == ATK_XY_WINDOW)
610 {
611 window = gdk_window_get_toplevel (gtk_widget_get_window (widget));
612 gdk_window_get_origin (window, &x_toplevel, &y_toplevel);
613
614 *x -= x_toplevel;
615 *y -= y_toplevel;
616 }
617 }
618
619 static AtkLayer
620 gtk_widget_accessible_get_layer (AtkComponent *component)
621 {
622 GtkWidgetAccessible *accessible = GTK_WIDGET_ACCESSIBLE (component);
623
624 return accessible->priv->layer;
625 }
626
627 static gboolean
628 gtk_widget_accessible_grab_focus (AtkComponent *component)
629 {
630 GtkWidget *widget;
631 GtkWidget *toplevel;
632
633 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
634 if (!widget)
635 return FALSE;
636
637 if (!gtk_widget_get_can_focus (widget))
638 return FALSE;
639
640 gtk_widget_grab_focus (widget);
641 toplevel = gtk_widget_get_toplevel (widget);
642 if (gtk_widget_is_toplevel (toplevel))
643 {
644 #ifdef GDK_WINDOWING_X11
645 if (GDK_IS_X11_DISPLAY (gtk_widget_get_display (toplevel)))
646 gtk_window_present_with_time (GTK_WINDOW (toplevel),
647 gdk_x11_get_server_time (gtk_widget_get_window (widget)));
648 else
649 #endif
650 {
651 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
652 gtk_window_present (GTK_WINDOW (toplevel));
653 G_GNUC_END_IGNORE_DEPRECATIONS
654 }
655 }
656
657 return TRUE;
658 }
659
660 static gboolean
661 gtk_widget_accessible_set_extents (AtkComponent *component,
662 gint x,
663 gint y,
664 gint width,
665 gint height,
666 AtkCoordType coord_type)
667 {
668 GtkWidget *widget;
669
670 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
671 if (widget == NULL)
672 return FALSE;
673
674 if (!gtk_widget_is_toplevel (widget))
675 return FALSE;
676
677 if (coord_type == ATK_XY_WINDOW)
678 {
679 gint x_current, y_current;
680 GdkWindow *window = gtk_widget_get_window (widget);
681
682 gdk_window_get_origin (window, &x_current, &y_current);
683 x_current += x;
684 y_current += y;
685 if (x_current < 0 || y_current < 0)
686 return FALSE;
687 else
688 {
689 gtk_window_move (GTK_WINDOW (widget), x_current, y_current);
690 gtk_widget_set_size_request (widget, width, height);
691 return TRUE;
692 }
693 }
694 else if (coord_type == ATK_XY_SCREEN)
695 {
696 gtk_window_move (GTK_WINDOW (widget), x, y);
697 gtk_widget_set_size_request (widget, width, height);
698 return TRUE;
699 }
700 return FALSE;
701 }
702
703 static gboolean
704 gtk_widget_accessible_set_position (AtkComponent *component,
705 gint x,
706 gint y,
707 AtkCoordType coord_type)
708 {
709 GtkWidget *widget;
710
711 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
712 if (widget == NULL)
713 return FALSE;
714
715 if (gtk_widget_is_toplevel (widget))
716 {
717 if (coord_type == ATK_XY_WINDOW)
718 {
719 gint x_current, y_current;
720 GdkWindow *window = gtk_widget_get_window (widget);
721
722 gdk_window_get_origin (window, &x_current, &y_current);
723 x_current += x;
724 y_current += y;
725 if (x_current < 0 || y_current < 0)
726 return FALSE;
727 else
728 {
729 gtk_window_move (GTK_WINDOW (widget), x_current, y_current);
730 return TRUE;
731 }
732 }
733 else if (coord_type == ATK_XY_SCREEN)
734 {
735 gtk_window_move (GTK_WINDOW (widget), x, y);
736 return TRUE;
737 }
738 }
739 return FALSE;
740 }
741
742 static gboolean
743 gtk_widget_accessible_set_size (AtkComponent *component,
744 gint width,
745 gint height)
746 {
747 GtkWidget *widget;
748
749 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
750 if (widget == NULL)
751 return FALSE;
752
753 if (gtk_widget_is_toplevel (widget))
754 {
755 gtk_widget_set_size_request (widget, width, height);
756 return TRUE;
757 }
758 else
759 return FALSE;
760 }
761
762 static void
763 atk_component_interface_init (AtkComponentIface *iface)
764 {
765 iface->get_extents = gtk_widget_accessible_get_extents;
766 iface->get_layer = gtk_widget_accessible_get_layer;
767 iface->grab_focus = gtk_widget_accessible_grab_focus;
768 iface->set_extents = gtk_widget_accessible_set_extents;
769 iface->set_position = gtk_widget_accessible_set_position;
770 iface->set_size = gtk_widget_accessible_set_size;
771 }
772
773 /* This function checks whether the widget has an ancestor which is
774 * a GtkViewport and, if so, whether any part of the widget intersects
775 * the visible rectangle of the GtkViewport.
776 */
777 static gboolean
778 gtk_widget_accessible_on_screen (GtkWidget *widget)
779 {
780 GtkAllocation allocation;
781 GtkWidget *viewport;
782 gboolean return_value;
783
784 gtk_widget_get_allocation (widget, &allocation);
785
786 if (!gtk_widget_get_mapped (widget))
787 return FALSE;
788
789 viewport = gtk_widget_get_ancestor (widget, GTK_TYPE_VIEWPORT);
790 if (viewport)
791 {
792 GtkAllocation viewport_allocation;
793 GtkAdjustment *adjustment;
794 GdkRectangle visible_rect;
795
796 gtk_widget_get_allocation (viewport, &viewport_allocation);
797
798 adjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (viewport));
799 visible_rect.y = gtk_adjustment_get_value (adjustment);
800 adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (viewport));
801 visible_rect.x = gtk_adjustment_get_value (adjustment);
802 visible_rect.width = viewport_allocation.width;
803 visible_rect.height = viewport_allocation.height;
804
805 if (((allocation.x + allocation.width) < visible_rect.x) ||
806 ((allocation.y + allocation.height) < visible_rect.y) ||
807 (allocation.x > (visible_rect.x + visible_rect.width)) ||
808 (allocation.y > (visible_rect.y + visible_rect.height)))
809 return_value = FALSE;
810 else
811 return_value = TRUE;
812 }
813 else
814 {
815 /* Check whether the widget has been placed of the screen.
816 * The widget may be MAPPED as when toolbar items do not
817 * fit on the toolbar.
818 */
819 if (allocation.x + allocation.width <= 0 &&
820 allocation.y + allocation.height <= 0)
821 return_value = FALSE;
822 else
823 return_value = TRUE;
824 }
825
826 return return_value;
827 }
828
829 /* Checks if all the predecessors (the parent widget, his parent, etc)
830 * are visible Used to check properly the SHOWING state.
831 */
832 static gboolean
833 gtk_widget_accessible_all_parents_visible (GtkWidget *widget)
834 {
835 GtkWidget *iter_parent = NULL;
836 gboolean result = TRUE;
837
838 for (iter_parent = gtk_widget_get_parent (widget); iter_parent;
839 iter_parent = gtk_widget_get_parent (iter_parent))
840 {
841 if (!gtk_widget_get_visible (iter_parent))
842 {
843 result = FALSE;
844 break;
845 }
846 }
847
848 return result;
849 }
850
851 void
852 _gtk_widget_accessible_set_layer (GtkWidgetAccessible *accessible,
853 AtkLayer layer)
854 {
855 accessible->priv->layer = layer;
856 }