~ubuntu-branches/ubuntu/oneiric/thunderbird/oneiric-updates

« back to all changes in this revision

Viewing changes to debian/globalmenu/components/src/uGlobalMenuObject.cpp

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-09-15 00:30:12 UTC
  • Revision ID: package-import@ubuntu.com-20110915003012-upbtjw901m5kwm8a
Tags: 7.0~b2+build2+nobinonly1-0ubuntu2
* Update globalmenu-extension to 2.0.1
  - Fixes broken labels in the Edit menu
  - Fixes radio item siblings not always being correctly unchecked
* Update messagingmenu-extension to 0.8
  - Fix a bug in inbox-only mode where we displayed non-inbox folders when
    clearing inbox-indicators
  - Add support for libunity6 ABI
  - Provide a utility module for loading libraries and binding symbols
  - Hide the internal implementation details from other chrome code
  - Fix some small memory leaks
  - Only destroy the IndicateServer on shutdown rather than when toggling
    the pref to disable the indicator, as recreating it seems to result in
    weird crashes. When disabling the indicator, just hide it (which doesn't
    work in any case)
  - Hide the prefs if the required libraries aren't installed
  - Fallback gracefully if the required libraries aren't installed
  - Trap all exceptions during initialization. Throwing exceptions in to a
    document load handler is bad, as it can prevent the entire UI from loading
* Fix broken icon URI for the reply button in the message header (LP: #844606)
  - update debian/patches/theme-refresh-message-header-buttons.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include <nsIImageToPixbuf.h>
48
48
#include <nsIDOMNSElement.h>
49
49
#include <nsIDOMDOMTokenList.h>
50
 
#include <nsILookAndFeel.h>
51
50
#include <nsIDOMDocument.h>
52
51
#include <nsIDOMWindow.h>
53
52
#include <nsIDOMElement.h>
59
58
#include <nsUnicharUtilCIID.h>
60
59
 
61
60
#include <libdbusmenu-gtk/menuitem.h>
 
61
#include <gtk/gtk.h>
62
62
 
63
63
#include "uGlobalMenuObject.h"
64
64
#include "uGlobalMenuBar.h"
72
72
 
73
73
NS_IMPL_ISUPPORTS3(uGlobalMenuIconLoader, imgIDecoderObserver, imgIContainerObserver, nsIRunnable)
74
74
 
75
 
PRInt32 uGlobalMenuIconLoader::sImagesInMenus = -1;
 
75
// Yes, we're abusing PRPackedBool a bit here. We initialize it to a value
 
76
// that is neither true or false, so that we don't need another static member
 
77
// to indicate the intialization status of it.
 
78
PRPackedBool uGlobalMenuIconLoader::sImagesInMenus = -1;
76
79
nsCOMPtr<imgILoader> uGlobalMenuIconLoader::sLoader = 0;
77
80
 
78
81
PRBool
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......
90
93
 
91
 
  nsresult rv;
 
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);
92
101
 
93
 
  if (sImagesInMenus == -1) {
94
 
    nsCOMPtr<nsILookAndFeel> laf =
95
 
      do_GetService("@mozilla.org/widget/lookandfeel;1");
96
 
    if (laf) {
97
 
      rv = laf->GetMetric(nsILookAndFeel::eMetric_ImagesInMenus,
98
 
                          sImagesInMenus);
99
 
      if (NS_FAILED(rv)) {
100
 
        NS_WARNING("Failed to get ImagesInMenus metric from nsILookAndFeel");
101
 
        sImagesInMenus = 0;
102
 
      }
103
 
    } else {
104
 
      NS_WARNING("No nsILookAndFeel service?");
105
 
      sImagesInMenus = 0;
106
 
    }
 
102
    sImagesInMenus = !!menus_have_icons;
107
103
  }
108
104
 
109
105
  if (sImagesInMenus) {
454
450
  NS_IF_ADDREF(*_retval);
455
451
}
456
452
 
457
 
// Synchronize the 'label' and 'accesskey' attributes on the DOM node
458
 
// with the 'label' property on the dbusmenu node
459
453
void
460
 
uGlobalMenuObject::SyncLabelFromContent()
 
454
uGlobalMenuObject::SyncLabelFromContent(nsIContent *aContent)
461
455
{
 
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
465
460
 
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);
 
467
  } else {
 
468
    mContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::label, label);
 
469
  }
468
470
 
469
471
  nsAutoString accesskey;
470
472
  mContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::accesskey, accesskey);
535
537
 
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,
540
543
                                 clabel.get());
541
544
}
542
545
 
 
546
void
 
547
uGlobalMenuObject::SyncLabelFromContent()
 
548
{
 
549
  SyncLabelFromContent(nsnull);
 
550
}
 
551
 
543
552
// Synchronize the 'hidden' attribute on the DOM node with the
544
553
// 'visible' property on the dbusmenu node
545
554
void
546
555
uGlobalMenuObject::SyncVisibilityFromContent()
547
556
{
 
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");
552
563
 
553
564
  dbusmenu_menuitem_property_set_bool(mDbusMenuItem,
554
565
                                      DBUSMENU_MENUITEM_PROP_VISIBLE,
555
566
                                      realVis);
556
567
}
557
568
 
558
 
// Synchronize the 'disabled' attribute on the DOM node with the
559
 
// 'sensitivity' property on the dbusmenu node
 
569
void
 
570
uGlobalMenuObject::SyncSensitivityFromContent(nsIContent *aContent)
 
571
{
 
572
  TRACE_WITH_THIS_MENUOBJECT();
 
573
 
 
574
  nsIContent *content;
 
575
  if (aContent) {
 
576
    content = aContent;
 
577
  } else {
 
578
    content = mContent;
 
579
  }
 
580
  PRBool disabled = content->AttrValueIs(kNameSpaceID_None,
 
581
                                         uWidgetAtoms::disabled,
 
582
                                         uWidgetAtoms::_true,
 
583
                                         eCaseMatters);
 
584
  DEBUG_WITH_THIS_MENUOBJECT("Setting %s", disabled ? "disabled" : "enabled");
 
585
 
 
586
  if (aContent) {
 
587
    UGM_BLOCK_EVENTS_FOR_CURRENT_SCOPE();
 
588
    if (disabled) {
 
589
      mContent->SetAttr(kNameSpaceID_None, uWidgetAtoms::disabled,
 
590
                        NS_LITERAL_STRING("true"), PR_TRUE);
 
591
    } else {
 
592
      mContent->UnsetAttr(kNameSpaceID_None, uWidgetAtoms::disabled, PR_TRUE);
 
593
    }
 
594
  }
 
595
 
 
596
  dbusmenu_menuitem_property_set_bool(mDbusMenuItem,
 
597
                                      DBUSMENU_MENUITEM_PROP_ENABLED,
 
598
                                      !disabled);
 
599
}
 
600
 
560
601
void
561
602
uGlobalMenuObject::SyncSensitivityFromContent()
562
603
{
563
 
  dbusmenu_menuitem_property_set_bool(mDbusMenuItem,
564
 
                                      DBUSMENU_MENUITEM_PROP_ENABLED,
565
 
                                      !mContent->AttrValueIs(kNameSpaceID_None,
566
 
                                                             uWidgetAtoms::disabled,
567
 
                                                             uWidgetAtoms::_true,
568
 
                                                             eCaseMatters));
569
 
}
570
 
 
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
574
 
PRBool
575
 
uGlobalMenuObject::SyncLabelFromCommand(nsIContent *aContent)
576
 
{
577
 
  if (!aContent) {
578
 
    return PR_FALSE;
579
 
  }
580
 
 
581
 
  nsAutoString label;
582
 
  if (aContent->GetAttr(kNameSpaceID_None, uWidgetAtoms::label, label)) {
583
 
    nsresult rv;
584
 
    rv = mContent->SetAttr(kNameSpaceID_None, uWidgetAtoms::label, label, PR_TRUE);
585
 
    return NS_FAILED(rv) ? PR_FALSE : PR_TRUE;
586
 
  }
587
 
 
588
 
  return PR_FALSE;
589
 
}
590
 
 
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
594
 
PRBool
595
 
uGlobalMenuObject::SyncSensitivityFromCommand(nsIContent *aContent)
596
 
{
597
 
  if (!aContent) {
598
 
    return PR_FALSE;
599
 
  }
600
 
 
601
 
  nsresult rv;
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);
606
 
  } else {
607
 
    rv = mContent->UnsetAttr(kNameSpaceID_None, uWidgetAtoms::disabled, PR_TRUE);
608
 
  }
609
 
 
610
 
  return NS_FAILED(rv) ? PR_FALSE : PR_TRUE;
 
604
  SyncSensitivityFromContent(nsnull);
611
605
}
612
606
 
613
607
void
646
640
void
647
641
uGlobalMenuObject::UpdateVisibility()
648
642
{
 
643
  TRACE_WITH_THIS_MENUOBJECT();
649
644
  if (!mMenuBar) {
650
645
    return;
651
646
  }
653
648
  PRBool newVis = (!ShouldShowOnlyForKb() || mMenuBar->OpenedByKeyboard()) ?
654
649
                   mContentVisible : PR_FALSE;
655
650
 
 
651
  DEBUG_WITH_THIS_MENUOBJECT("Setting %s", newVis ? "visible" : "hidden");
656
652
  dbusmenu_menuitem_property_set_bool(mDbusMenuItem,
657
653
                                      DBUSMENU_MENUITEM_PROP_VISIBLE,
658
654
                                      newVis);