88
91
// which should work in most cases. But, I guess a theme could override this,
89
92
// and then we ignore the users theme settings. Oh well......
94
if (sImagesInMenus == static_cast<PRPackedBool>(-1)) {
95
// We could get the correct GtkSettings by getting the GdkScreen that our
96
// top-level window is on. However, I don't think this matters, as
97
// nsILookAndFeel never had per-screen settings
98
GtkSettings *settings = gtk_settings_get_default();
99
gboolean menus_have_icons;
100
g_object_get(settings, "gtk-menu-images", &menus_have_icons, NULL);
93
if (sImagesInMenus == -1) {
94
nsCOMPtr<nsILookAndFeel> laf =
95
do_GetService("@mozilla.org/widget/lookandfeel;1");
97
rv = laf->GetMetric(nsILookAndFeel::eMetric_ImagesInMenus,
100
NS_WARNING("Failed to get ImagesInMenus metric from nsILookAndFeel");
104
NS_WARNING("No nsILookAndFeel service?");
102
sImagesInMenus = !!menus_have_icons;
109
105
if (sImagesInMenus) {
454
450
NS_IF_ADDREF(*_retval);
457
// Synchronize the 'label' and 'accesskey' attributes on the DOM node
458
// with the 'label' property on the dbusmenu node
460
uGlobalMenuObject::SyncLabelFromContent()
454
uGlobalMenuObject::SyncLabelFromContent(nsIContent *aContent)
456
TRACE_WITH_THIS_MENUOBJECT();
462
457
// Gecko stores the label and access key in separate attributes
463
458
// so we need to convert label="Foo"/accesskey="F" in to
464
459
// label="_Foo" for dbusmenu
466
461
nsAutoString label;
467
mContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::label, label);
462
if (aContent && aContent->GetAttr(kNameSpaceID_None,
463
uWidgetAtoms::label, label)) {
464
UGM_BLOCK_EVENTS_FOR_CURRENT_SCOPE();
465
DEBUG_WITH_CONTENT(aContent, "Content has label \"%s\"", DEBUG_CSTR_FROM_UTF16(label));
466
mContent->SetAttr(kNameSpaceID_None, uWidgetAtoms::label, label, PR_TRUE);
468
mContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::label, label);
469
471
nsAutoString accesskey;
470
472
mContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::accesskey, accesskey);
536
538
nsCAutoString clabel;
537
539
CopyUTF16toUTF8(label, clabel);
540
DEBUG_WITH_THIS_MENUOBJECT("Setting label to \"%s\"", clabel.get());
538
541
dbusmenu_menuitem_property_set(mDbusMenuItem,
539
542
DBUSMENU_MENUITEM_PROP_LABEL,
547
uGlobalMenuObject::SyncLabelFromContent()
549
SyncLabelFromContent(nsnull);
543
552
// Synchronize the 'hidden' attribute on the DOM node with the
544
553
// 'visible' property on the dbusmenu node
546
555
uGlobalMenuObject::SyncVisibilityFromContent()
557
TRACE_WITH_THIS_MENUOBJECT();
548
558
mContentVisible = !IsHidden();
549
559
PRBool realVis = (!mMenuBar || !ShouldShowOnlyForKb() ||
550
560
mMenuBar->OpenedByKeyboard()) ?
551
561
mContentVisible : PR_FALSE;
562
DEBUG_WITH_THIS_MENUOBJECT("Setting %s", realVis ? "visible" : "hidden");
553
564
dbusmenu_menuitem_property_set_bool(mDbusMenuItem,
554
565
DBUSMENU_MENUITEM_PROP_VISIBLE,
558
// Synchronize the 'disabled' attribute on the DOM node with the
559
// 'sensitivity' property on the dbusmenu node
570
uGlobalMenuObject::SyncSensitivityFromContent(nsIContent *aContent)
572
TRACE_WITH_THIS_MENUOBJECT();
580
PRBool disabled = content->AttrValueIs(kNameSpaceID_None,
581
uWidgetAtoms::disabled,
584
DEBUG_WITH_THIS_MENUOBJECT("Setting %s", disabled ? "disabled" : "enabled");
587
UGM_BLOCK_EVENTS_FOR_CURRENT_SCOPE();
589
mContent->SetAttr(kNameSpaceID_None, uWidgetAtoms::disabled,
590
NS_LITERAL_STRING("true"), PR_TRUE);
592
mContent->UnsetAttr(kNameSpaceID_None, uWidgetAtoms::disabled, PR_TRUE);
596
dbusmenu_menuitem_property_set_bool(mDbusMenuItem,
597
DBUSMENU_MENUITEM_PROP_ENABLED,
561
602
uGlobalMenuObject::SyncSensitivityFromContent()
563
dbusmenu_menuitem_property_set_bool(mDbusMenuItem,
564
DBUSMENU_MENUITEM_PROP_ENABLED,
565
!mContent->AttrValueIs(kNameSpaceID_None,
566
uWidgetAtoms::disabled,
571
// Synchronize the 'label' attribute on our content node with that from
572
// the specified command node. Returns false if nothing was synchronized,
573
// else it returns true and the document is notified
575
uGlobalMenuObject::SyncLabelFromCommand(nsIContent *aContent)
582
if (aContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::label, label)) {
584
rv = mContent->SetAttr(kNameSpaceID_None, uWidgetAtoms::label, label, PR_TRUE);
585
return NS_FAILED(rv) ? PR_FALSE : PR_TRUE;
591
// Synchronize the 'disabled' attribute on our content node with that from
592
// the specified command node. Returns false if nothing was synchronized,
593
// else it returns true and the document is notified
595
uGlobalMenuObject::SyncSensitivityFromCommand(nsIContent *aContent)
602
if (aContent->AttrValueIs(kNameSpaceID_None, uWidgetAtoms::disabled,
603
uWidgetAtoms::_true, eCaseMatters)) {
604
rv = mContent->SetAttr(kNameSpaceID_None, uWidgetAtoms::disabled,
605
NS_LITERAL_STRING("true"), PR_TRUE);
607
rv = mContent->UnsetAttr(kNameSpaceID_None, uWidgetAtoms::disabled, PR_TRUE);
610
return NS_FAILED(rv) ? PR_FALSE : PR_TRUE;
604
SyncSensitivityFromContent(nsnull);