46177 Show icons in native Mac menu items. r=josh sr=bryner

This commit is contained in:
mark%moxienet.com 2006-08-01 00:13:24 +00:00
Родитель 8aae7e81d3
Коммит 553b503658
19 изменённых файлов: 692 добавлений и 732 удалений

Просмотреть файл

@ -180,6 +180,10 @@ padding: 4px 4px 3px 2px;
list-style-image: url("chrome://browser/skin/bookmarks/livemark-folder-hover.png");
}
.bookmark-item[livemark] {
list-style-image: url("chrome://browser/skin/page-livemarks.png");
}
.bookmark-item[livemark] .menuitem-iconic {
list-style-image: url("chrome://browser/skin/bookmarks/livemark-item.png");
}
@ -876,6 +880,10 @@ toolbarbutton.chevron > .toolbarbutton-menu-dropmarker {
list-style-image: url("chrome://browser/skin/bookmarks/bookmark-item.png");
}
.openintabs-menuitem {
list-style-image: none;
}
.tabs-left {
display: none !important;
}

Просмотреть файл

@ -34,6 +34,7 @@ classic.jar:
skin/classic/browser/Secure-background.gif
skin/classic/browser/Toolbar-small.png
skin/classic/browser/Toolbar.png
skin/classic/browser/bookmarks/bookmark-item.png (bookmarks/bookmark-item.png)
#ifdef MOZ_FEEDS
skin/classic/browser/feeds/subscribe.css (feeds/subscribe.css)
skin/classic/browser/feeds/feedIcon.png (feeds/feedIcon.png)
@ -60,7 +61,6 @@ classic.jar:
skin/classic/browser/bookmarks/addBookmark.css (bookmarks/addBookmark.css)
skin/classic/browser/bookmarks/bookmarksProperties.css (bookmarks/bookmarksProperties.css)
skin/classic/browser/bookmarks/bookmark-folder.png (bookmarks/bookmark-folder.png)
skin/classic/browser/bookmarks/bookmark-item.png (bookmarks/bookmark-item.png)
skin/classic/browser/bookmarks/Bookmarks-toolbar.png (bookmarks/Bookmarks-toolbar.png)
skin/classic/browser/bookmarks/bookmarksManager.css (bookmarks/bookmarksManager.css)
skin/classic/browser/bookmarks/expander-closed-active.png (bookmarks/expander-closed-active.png)

Просмотреть файл

@ -1,33 +0,0 @@
/* Tell the bookmarks toolbar where to find the new icons.
These settings complement and override settings in browser.css.
They should be merged into chrome://browser/skin/browser.css
when the pre-Places bookmark system is no longer needed. */
.bookmark-item > .toolbarbutton-menu-dropmarker {
list-style-image: url("chrome://browser/skin/places/folderDropArrow.png") !important;
}
.bookmark-item:hover > .toolbarbutton-menu-dropmarker, .bookmark-item[open] > .toolbarbutton-menu-dropmarker {
list-style-image: url("chrome://browser/skin/places/folderDropHoverArrow.png") !important;
}
.bookmark-item[livemark] > .toolbarbutton-menu-dropmarker {
list-style-image: url("chrome://browser/skin/places/livemarkFolder.png") !important;
}
.bookmark-item[livemark]:hover > .toolbarbutton-menu-dropmarker, .bookmark-item[livemark][open] > .toolbarbutton-menu-dropmarker {
list-style-image: url("chrome://browser/skin/places/livemarkFolderHover.png") !important;
}
.bookmark-item[livemark] .menuitem-iconic {
list-style-image: url("chrome://browser/skin/places/livemarkItem.png") !important;
}
#page-proxy-button {
list-style-image: url("chrome://browser/skin/places/defaultFavicon.png") !important;
}
.bookmark-item {
list-style-image: url("chrome://browser/skin/places/defaultFavicon.png") !important;
}

Просмотреть файл

@ -37,19 +37,19 @@
-moz-appearance: listbox;
}
treechildren::-moz-tree-image(title, container) {
treechildren::-moz-tree-image(title, container),
treechildren::-moz-tree-image(title, open) {
padding-right: 2px;
margin: 0px 2px;
list-style-image: url("chrome://global/skin/icons/folder-item.png") !important;
list-style-image: url("chrome://global/skin/tree/folder.png") !important;
-moz-image-region: rect(0px, 16px, 16px, 0px);
}
treechildren::-moz-tree-image(title, container) {
-moz-image-region: rect(0px, 32px, 16px, 16px);
}
treechildren::-moz-tree-image(title, open) {
-moz-image-region: rect(16px, 32px, 32px, 16px);
treechildren::-moz-tree-image(title, separator) {
list-style-image: none;
width: 0px !important;
height: 0px !important;
margin: 0px 0px;
}
treechildren::-moz-tree-row(session-start) {

Просмотреть файл

@ -1,79 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Pinkerton (pinkerton@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIImageMac_h__
#define nsIImageMac_h__
#include "nsISupports.h"
#include "nsRect.h"
#include <Quickdraw.h>
// IID for the nsIImage interface
// {80b2f600-f140-11d4-bb6f-d472847e8dbc}
#define NS_IIMAGEMAC_IID \
{ 0x80b2f600, 0xf140, 0x11d4, { 0xbb, 0x6f, 0xd4, 0x72, 0x84, 0x7e, 0x8d, 0xbc } };
//
// nsIImageMac
//
// MacOS-specific Interface to Images
//
class nsIImageMac : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IIMAGEMAC_IID)
// Convert to the os-native PICT format. Most likely
// used for clipboard. The caller is responsible for
// using ::KillPicture() to dispose of |outPicture|
// when it's done.
NS_IMETHOD ConvertToPICT ( PicHandle* outPicture ) = 0;
// Convert from the os-native PICT format. Most likely
// used for clipboard.
NS_IMETHOD ConvertFromPICT ( PicHandle inPicture ) = 0;
}; // nsIImageMac
NS_DEFINE_STATIC_IID_ACCESSOR(nsIImageMac, NS_IIMAGEMAC_IID)
#endif

Просмотреть файл

@ -794,6 +794,17 @@ nsImageMac::ConvertFromPICT(PicHandle inPicture)
}
NS_IMETHODIMP
nsImageMac::GetCGImageRef(CGImageRef* aCGImageRef)
{
nsresult rv = EnsureCachedImage();
if (NS_FAILED(rv)) return rv;
*aCGImageRef = mImage;
return NS_OK;
}
#pragma mark -
nsresult

Просмотреть файл

@ -1,186 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsImageMac_h___
#define nsImageMac_h___
#include "nsIImage.h"
#include "nsIImageMac.h"
class nsImageMac : public nsIImage, public nsIImageMac
{
public:
nsImageMac();
virtual ~nsImageMac();
NS_DECL_ISUPPORTS
/**
@see nsIImage.h
*/
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
virtual PRInt32 GetBytesPix() { return mBytesPerPixel; } // this is unused
virtual PRBool GetIsRowOrderTopToBottom() { return PR_FALSE; }
virtual PRInt32 GetWidth() { return mWidth; }
virtual PRInt32 GetHeight() { return mHeight; }
virtual PRUint8* GetBits() { return mImageBits; }
virtual PRInt32 GetLineStride() { return mRowBytes; }
virtual PRBool GetHasAlphaMask() { return mAlphaBits != nsnull; }
virtual PRUint8* GetAlphaBits() { return mAlphaBits; }
virtual PRInt32 GetAlphaLineStride() { return mAlphaRowBytes; }
// Called when an image decoder updates the image bits (mImageBits &
// mAlphaBits). 'aFlags' is ignored.
virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags,
nsRect *aUpdateRect);
virtual PRBool GetIsImageComplete();
// Optimizes memory usage for object.
virtual nsresult Optimize(nsIDeviceContext* aContext);
virtual nsColorMap* GetColorMap() { return nsnull; }
NS_IMETHOD Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
NS_IMETHOD DrawTile(nsIRenderingContext &aContext,
nsIDrawingSurface* aSurface,
PRInt32 aSXOffset, PRInt32 aSYOffset,
PRInt32 aPadX, PRInt32 aPadY,
const nsRect &aTileRect);
/**
* Get the alpha depth for the image mask
* @update - lordpixel 2001/05/16
* @return the alpha mask depth for the image, ie, 0, 1 or 8
*/
virtual PRInt8 GetAlphaDepth() { return mAlphaDepth; }
NS_IMETHOD DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY,
nscoord aDWidth, nscoord aDHeight);
virtual void* GetBitInfo() { return nsnull; }
NS_IMETHOD LockImagePixels(PRBool aMaskPixels);
NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels);
// Convert to and from the os-native PICT format. Most likely
// used for clipboard.
NS_IMETHOD ConvertToPICT(PicHandle* outPicture);
NS_IMETHOD ConvertFromPICT(PicHandle inPicture);
protected:
nsresult SlowTile(nsIRenderingContext &aContext,
nsIDrawingSurface* aSurface,
PRInt32 aSXOffset, PRInt32 aSYOffset,
PRInt32 aPadX, PRInt32 aPadY,
const nsRect &aTileRect);
nsresult DrawTileQuickly(nsIRenderingContext &aContext,
nsIDrawingSurface* aSurface,
PRInt32 aSXOffset, PRInt32 aSYOffset,
const nsRect &aTileRect);
nsresult DrawTileWithQuartz(nsIDrawingSurface* aSurface,
PRInt32 aSXOffset, PRInt32 aSYOffset,
PRInt32 aPadX, PRInt32 aPadY,
const nsRect &aTileRect);
static PRInt32 CalculateRowBytes(PRUint32 aWidth, PRUint32 aDepth);
inline static PRInt32 CalculateRowBytesInternal(PRUint32 aWidth,
PRUint32 aDepth,
PRBool aAllow2Bytes);
static PRBool RenderingToPrinter(nsIRenderingContext &aContext);
// Recreate internal image structure from updated image bits.
nsresult EnsureCachedImage();
// Get/Set/Clear alpha bit at position 'x' in the row pointed to by 'rowptr'.
inline PRUint8 GetAlphaBit(PRUint8* rowptr, PRUint32 x) {
return (rowptr[x >> 3] & (1 << (7 - x & 0x7)));
}
inline void SetAlphaBit(PRUint8* rowptr, PRUint32 x) {
rowptr[x >> 3] |= (1 << (7 - x & 0x7));
}
inline void ClearAlphaBit(PRUint8* rowptr, PRUint32 x) {
rowptr[x >> 3] &= ~(1 << (7 - x & 0x7));
}
// Takes ownership of the given image and bitmap. The CGImageRef is retained.
void AdoptImage(CGImageRef aNewImage, PRUint8* aNewBitamp);
private:
PRUint8* mImageBits; // malloc'd block
CGImageRef mImage;
PRInt32 mWidth;
PRInt32 mHeight;
PRInt32 mRowBytes;
PRInt32 mBytesPerPixel;
// alpha layer members
PRUint8* mAlphaBits; // malloc'd block
PRInt32 mAlphaRowBytes; // alpha row bytes
PRInt8 mAlphaDepth; // alpha layer depth
PRPackedBool mPendingUpdate; // true when we need to recreate CGImageRef
PRPackedBool mOptimized; // true when nsImage object has been
// optimized (see |Optimize()|)
PRInt32 mDecodedX1; // Keeps track of what part of image
PRInt32 mDecodedY1; // has been decoded.
PRInt32 mDecodedX2;
PRInt32 mDecodedY2;
};
#endif

Просмотреть файл

@ -125,5 +125,9 @@ private:
friend class FaviconLoadListener;
};
#ifdef XP_MACOSX
#define FAVICON_DEFAULT_URL "chrome://browser/skin/bookmarks/bookmark-item.png"
#else
#define FAVICON_DEFAULT_URL "chrome://browser/skin/places/defaultFavicon.png"
#endif
#define FAVICON_ANNOTATION_NAME "favicon"

Просмотреть файл

@ -51,10 +51,10 @@ class nsIContent;
class nsIMenuCommandDispatcher;
// {D0E18BEA-A0B9-4D33-899E-283A4D753F2C}
#define NS_IMENU_IID \
{ 0xD0E18BEA, 0xA0B9, 0x4D33, \
{ 0x89, 0x9E, 0x28, 0x3A, 0x4D, 0x75, 0x3F, 0x2C } }
// {FC5BCA9C-4494-4C0F-BEFD-CB31BEBA1531}
#define NS_IMENU_IID \
{ 0xFC5BCA9C, 0x4494, 0x4C0F, \
{ 0xBE, 0xFD, 0xCB, 0x31, 0xBE, 0xBA, 0x15, 0x31 } }
/**
@ -192,6 +192,19 @@ class nsIMenu : public nsISupports {
*/
NS_IMETHOD ChangeNativeEnabledStatusForMenuItem(nsIMenuItem* aMenuItem,
PRBool aEnabled) = 0;
/**
* Retrieve the native menu and the index of the item within that menu.
*
*/
NS_IMETHOD GetMenuRefAndItemIndexForMenuItem(nsISupports* aMenuItem,
void** aMenuRef,
PRUint16* aMenuItemIndex) = 0;
/**
* Sets an appropriate icon for the menu.
*/
NS_IMETHOD SetupIcon() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIMenu, NS_IMENU_IID)

Просмотреть файл

@ -45,10 +45,10 @@
#include "nsIDocShell.h"
#include "nsIDOMElement.h"
// {F5E4F801-DFD2-4DE3-8708-7914F2D4710D}
#define NS_IMENUITEM_IID \
{ 0xF5E4F801, 0xDFD2, 0x4DE3, \
{ 0x87, 0x08, 0x79, 0x14, 0xF2, 0xD4, 0x71, 0x0D } }
// {4E3931A7-D7E5-47FC-9489-83928536DA9D}
#define NS_IMENUITEM_IID \
{ 0x4E3931A7, 0xD7E5, 0x47FC, \
{ 0x94, 0x89, 0x83, 0x92, 0x85, 0x36, 0xDA, 0x9D } }
class nsIMenu;
class nsIWidget;
@ -165,6 +165,11 @@ class nsIMenuItem : public nsISupports {
*/
NS_IMETHOD SetModifiers(PRUint8 aModifiers) = 0;
NS_IMETHOD GetModifiers(PRUint8 * aModifiers) = 0;
/**
* Sets an appropriate icon for the menu item.
*/
NS_IMETHOD SetupIcon() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIMenuItem, NS_IMENUITEM_IID)

Просмотреть файл

@ -69,6 +69,7 @@ REQUIRES = xpcom \
mimetype \
unicharutil \
exthandler \
imglib2 \
$(NULL)
ifdef ACCESSIBILITY
@ -99,6 +100,7 @@ CPPSRCS = nsAppShell.cpp \
nsMacWindow.cpp \
nsMenuX.cpp \
nsMenuBarX.cpp \
nsMenuItemIcon.cpp \
nsMenuItemX.cpp \
nsMimeMapper.cpp \
nsNativeThemeMac.cpp \

Просмотреть файл

@ -0,0 +1,559 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is support for icons in native menu items on Mac OS X.
*
* The Initial Developer of the Original Code is Google Inc.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Mentovai <mark@moxienet.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Retrieves and displays icons in native menu items on Mac OS X.
*/
#include "nsMenuItemIcon.h"
#include "prmem.h"
#include "nsIMenu.h"
#include "nsIMenuItem.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsINameSpaceManager.h"
#include "nsWidgetAtoms.h"
#include "nsIDOMDocumentView.h"
#include "nsIDOMViewCSS.h"
#include "nsIDOMElement.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMCSSValue.h"
#include "nsIDOMCSSPrimitiveValue.h"
#include "nsThreadUtils.h"
#include "nsToolkit.h"
#include "nsNetUtil.h"
#include "imgILoader.h"
#include "imgIRequest.h"
#include "gfxIImageFrame.h"
#include "nsIImage.h"
#include "nsIImageMac.h"
#include <Carbon/Carbon.h>
static const PRUint32 kIconWidth = 16;
static const PRUint32 kIconHeight = 16;
static const PRUint32 kIconBitsPerComponent = 8;
static const PRUint32 kIconComponents = 4;
static const PRUint32 kIconBitsPerPixel = kIconBitsPerComponent *
kIconComponents;
static const PRUint32 kIconBytesPerRow = kIconWidth * kIconBitsPerPixel / 8;
static const PRUint32 kIconBytes = kIconBytesPerRow * kIconHeight;
static void
PRAllocCGFree(void* aInfo, const void* aData, size_t aSize) {
PR_Free((void*)aData);
}
NS_IMPL_ISUPPORTS2(nsMenuItemIcon, imgIContainerObserver, imgIDecoderObserver)
nsMenuItemIcon::nsMenuItemIcon(nsISupports* aMenuItem,
nsIMenu* aMenu,
nsIContent* aContent)
: mContent(aContent)
, mMenuItem(aMenuItem)
, mMenu(aMenu)
, mMenuRef(NULL)
, mMenuItemIndex(0)
, mLoadedIcon(PR_FALSE)
, mSetIcon(PR_FALSE)
{
}
nsMenuItemIcon::~nsMenuItemIcon()
{
if (mIconRequest)
mIconRequest->Cancel(NS_BINDING_ABORTED);
}
nsresult
nsMenuItemIcon::SetupIcon()
{
nsresult rv;
if (!mMenuRef || !mMenuItemIndex) {
// These values are initialized here instead of in the constructor
// because they depend on the parent menu, mMenu, having inserted
// this object into its array of children. That can only happen after
// the object is constructed.
rv = mMenu->GetMenuRefAndItemIndexForMenuItem(mMenuItem,
(void**)&mMenuRef,
&mMenuItemIndex);
if (NS_FAILED(rv)) return rv;
}
nsCOMPtr<nsIURI> iconURI;
rv = GetIconURI(getter_AddRefs(iconURI));
if (NS_FAILED(rv)) {
// There is no icon for this menu item. An icon might have been set
// earlier. Clear it.
OSStatus err;
err = ::SetMenuItemIconHandle(mMenuRef, mMenuItemIndex, kMenuNoIcon, NULL);
if (err != noErr) return NS_ERROR_FAILURE;
return NS_OK;
}
rv = LoadIcon(iconURI);
return rv;
}
nsresult
nsMenuItemIcon::GetIconURI(nsIURI** aIconURI)
{
// Mac native menu items support having both a checkmark and an icon
// simultaneously, but this is unheard of in the cross-platform toolkit,
// seemingly because the win32 theme is unable to cope with both at once.
// The downside is that it's possible to get a menu item marked with a
// native checkmark and a checkmark for an icon. Head off that possibility
// by pretending that no icon exists if this is a checkable menu item.
nsCOMPtr<nsIMenuItem> menuItem = do_QueryInterface(mMenuItem);
if (menuItem) {
nsIMenuItem::EMenuItemType menuItemType;
menuItem->GetMenuItemType(&menuItemType);
if (menuItemType == nsIMenuItem::eCheckbox ||
menuItemType == nsIMenuItem::eRadio)
return NS_ERROR_FAILURE;
}
if (!mContent) return NS_ERROR_FAILURE;
// First, look at the content node's "image" attribute.
nsAutoString imageURIString;
PRBool hasImageAttr = mContent->GetAttr(kNameSpaceID_None,
nsWidgetAtoms::image,
imageURIString);
nsresult rv;
if (!hasImageAttr) {
// If the content node has no "image" attribute, get the
// "list-style-image" property from CSS.
nsCOMPtr<nsIDOMDocumentView> domDocumentView =
do_QueryInterface(mContent->GetDocument());
if (!domDocumentView) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMAbstractView> domAbstractView;
rv = domDocumentView->GetDefaultView(getter_AddRefs(domAbstractView));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMViewCSS> domViewCSS = do_QueryInterface(domAbstractView);
if (!domViewCSS) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(mContent);
if (!domElement) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssStyleDecl;
nsAutoString empty;
rv = domViewCSS->GetComputedStyle(domElement, empty,
getter_AddRefs(cssStyleDecl));
if (NS_FAILED(rv)) return rv;
NS_NAMED_LITERAL_STRING(listStyleImage, "list-style-image");
nsCOMPtr<nsIDOMCSSValue> cssValue;
rv = cssStyleDecl->GetPropertyCSSValue(listStyleImage,
getter_AddRefs(cssValue));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue =
do_QueryInterface(cssValue);
if (!primitiveValue) return NS_ERROR_FAILURE;
PRUint16 primitiveType;
rv = primitiveValue->GetPrimitiveType(&primitiveType);
if (NS_FAILED(rv)) return rv;
if (primitiveType != nsIDOMCSSPrimitiveValue::CSS_URI)
return NS_ERROR_FAILURE;
rv = primitiveValue->GetStringValue(imageURIString);
if (NS_FAILED(rv)) return rv;
}
// If this menu item shouldn't have an icon, the string will be empty,
// and NS_NewURI wil fail.
nsCOMPtr<nsIURI> iconURI;
rv = NS_NewURI(getter_AddRefs(iconURI), imageURIString);
if (NS_FAILED(rv)) return rv;
*aIconURI = iconURI;
NS_ADDREF(*aIconURI);
return NS_OK;
}
nsresult
nsMenuItemIcon::LoadIcon(nsIURI* aIconURI)
{
if (mIconRequest) {
// Another icon request is already in flight. Kill it.
mIconRequest->Cancel(NS_BINDING_ABORTED);
mIconRequest = nsnull;
}
mLoadedIcon = PR_FALSE;
if (!mContent) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> document = mContent->GetOwnerDoc();
if (!document) return NS_ERROR_FAILURE;
nsCOMPtr<nsILoadGroup> loadGroup = document->GetDocumentLoadGroup();
if (!loadGroup) return NS_ERROR_FAILURE;
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<imgILoader> loader = do_GetService("@mozilla.org/image/loader;1",
&rv);
if (NS_FAILED(rv)) return rv;
if (!mSetIcon) {
// Set a completely transparent 16x16 image as the icon on this menu item
// as a placeholder. This keeps the menu item text displayed in the same
// position that it will be displayed when the real icon is loaded, and
// prevents it from jumping around or looking misaligned.
static PRBool sInitializedPlaceholder;
static CGImageRef sPlaceholderIconImage;
if (!sInitializedPlaceholder) {
sInitializedPlaceholder = PR_TRUE;
PRUint8* bitmap = (PRUint8*)PR_Malloc(kIconBytes);
CGColorSpaceRef colorSpace = ::CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext;
bitmapContext = ::CGBitmapContextCreate(bitmap, kIconWidth, kIconHeight,
kIconBitsPerComponent,
kIconBytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedFirst);
if (!bitmapContext) {
PR_Free(bitmap);
::CGColorSpaceRelease(colorSpace);
return NS_ERROR_FAILURE;
}
CGRect iconRect = ::CGRectMake(0, 0, kIconWidth, kIconHeight);
::CGContextClearRect(bitmapContext, iconRect);
::CGContextRelease(bitmapContext);
CGDataProviderRef provider;
provider = ::CGDataProviderCreateWithData(NULL, bitmap, kIconBytes,
PRAllocCGFree);
if (!provider) {
PR_Free(bitmap);
::CGColorSpaceRelease(colorSpace);
return NS_ERROR_FAILURE;
}
sPlaceholderIconImage =
::CGImageCreate(kIconWidth, kIconHeight, kIconBitsPerComponent,
kIconBitsPerPixel, kIconBytesPerRow, colorSpace,
kCGImageAlphaPremultipliedFirst, provider, NULL, TRUE,
kCGRenderingIntentDefault);
::CGColorSpaceRelease(colorSpace);
::CGDataProviderRelease(provider);
}
if (!sPlaceholderIconImage) return NS_ERROR_FAILURE;
OSStatus err;
err = ::SetMenuItemIconHandle(mMenuRef, mMenuItemIndex, kMenuCGImageRefType,
(Handle)sPlaceholderIconImage);
if (err != noErr) return NS_ERROR_FAILURE;
}
rv = loader->LoadImage(aIconURI, nsnull, nsnull, loadGroup, this,
nsnull, nsIRequest::LOAD_NORMAL, nsnull,
nsnull, getter_AddRefs(mIconRequest));
if (NS_FAILED(rv)) return rv;
// The icon will be picked up in OnStopFrame, which may be called after
// LoadImage returns. If the load is to be synchronous, ensure that
// it completes now.
if (ShouldLoadSync(aIconURI)) {
// If there are any failures at this point, just return NS_OK and let
// the image load asynchronously to completion.
nsCOMPtr<nsIThread> thread = NS_GetCurrentThread();
if (!thread) return NS_OK;
rv = NS_OK;
while (!mLoadedIcon && mIconRequest && NS_SUCCEEDED(rv)) {
PRBool processed;
rv = thread->ProcessNextEvent(PR_TRUE, &processed);
if (NS_SUCCEEDED(rv) && !processed)
rv = NS_ERROR_UNEXPECTED;
}
}
return NS_OK;
}
PRBool
nsMenuItemIcon::ShouldLoadSync(nsIURI* aURI)
{
#if 0 // bug 338225
// Older menu managers are unable to cope with menu item icons changing
// while a menu is open in tracking. On Panther (10.3), the updated icon
// will not be displayed and highlighting of menu items in the affected
// menu will be incorrect until menu tracking ends and the menu is
// reopened. On Jaguar (10.2), the updated icon will not be displayed
// until the menu item is selected or deselected. Tiger (10.4) does
// not have these problems.
//
// Because icons are set in an imgIDecoderObserver notification, it's
// possible and even likely that some icons will not be set until after the
// menu is open. On systems where this is known to cause trouble,
// LoadIcon is made to set the icon on the menu item synchronously when
// the source of the icon is local, as determined by the URI scheme.
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
return PR_FALSE;
#else
static PRBool sNeedsSync;
static PRBool sInitialized;
if (!sInitialized) {
sInitialized = PR_TRUE;
sNeedsSync = (nsToolkit::OSXVersion() < MAC_OS_X_VERSION_10_4_HEX);
}
if (sNeedsSync) {
PRBool isLocalScheme;
if (NS_SUCCEEDED(aURI->SchemeIs("chrome", &isLocalScheme)) &&
isLocalScheme)
return PR_TRUE;
if (NS_SUCCEEDED(aURI->SchemeIs("data", &isLocalScheme)) &&
isLocalScheme)
return PR_TRUE;
if (NS_SUCCEEDED(aURI->SchemeIs("moz-anno", &isLocalScheme)) &&
isLocalScheme)
return PR_TRUE;
}
return PR_FALSE;
#endif
#else // bug 338225
// Bug 338225 prevents any Gecko events from being processed while
// MenuSelect is tracking the menu. Bug 346108 (duplicate) applies
// specifically to this issue. Make the load synchronous on any OS
// release if it's coming from a local scheme as a workaround.
PRBool isLocalScheme;
if (NS_SUCCEEDED(aURI->SchemeIs("chrome", &isLocalScheme)) &&
isLocalScheme)
return PR_TRUE;
if (NS_SUCCEEDED(aURI->SchemeIs("data", &isLocalScheme)) &&
isLocalScheme)
return PR_TRUE;
if (NS_SUCCEEDED(aURI->SchemeIs("moz-anno", &isLocalScheme)) &&
isLocalScheme)
return PR_TRUE;
return PR_FALSE;
#endif // bug 338225
}
// imgIContainerObserver
NS_IMETHODIMP
nsMenuItemIcon::FrameChanged(imgIContainer* aContainer,
gfxIImageFrame* aFrame,
nsIntRect* aDirtyRect)
{
return NS_OK;
}
// imgIDecoderObserver
NS_IMETHODIMP
nsMenuItemIcon::OnStartRequest(imgIRequest* aRequest)
{
return NS_OK;
}
NS_IMETHODIMP
nsMenuItemIcon::OnStartDecode(imgIRequest* aRequest)
{
return NS_OK;
}
NS_IMETHODIMP
nsMenuItemIcon::OnStartContainer(imgIRequest* aRequest,
imgIContainer* aContainer)
{
return NS_OK;
}
NS_IMETHODIMP
nsMenuItemIcon::OnStartFrame(imgIRequest* aRequest, gfxIImageFrame* aFrame)
{
return NS_OK;
}
NS_IMETHODIMP
nsMenuItemIcon::OnDataAvailable(imgIRequest* aRequest,
gfxIImageFrame* aFrame,
const nsIntRect* aRect)
{
return NS_OK;
}
NS_IMETHODIMP
nsMenuItemIcon::OnStopFrame(imgIRequest* aRequest,
gfxIImageFrame* aFrame)
{
if (aRequest != mIconRequest) return NS_ERROR_FAILURE;
// Only support one frame.
if (mLoadedIcon)
return NS_OK;
nsCOMPtr<gfxIImageFrame> frame = aFrame;
nsCOMPtr<nsIImage> iimage = do_GetInterface(frame);
if (!iimage) return NS_ERROR_FAILURE;
nsCOMPtr<nsIImageMac> imageMac = do_QueryInterface(iimage);
if (!imageMac) return NS_ERROR_FAILURE;
CGImageRef cgImage;
nsresult rv = imageMac->GetCGImageRef(&cgImage);
if (NS_FAILED(rv)) return rv;
::CGImageRetain(cgImage);
// The CGImageRef obtained from the nsIImageMac can't be used as-is.
// It may not be the right size for a menu icon (16x16), and it's
// flipped upside-down. Create a new CGImage for the menu item.
PRUint8* bitmap = (PRUint8*)PR_Malloc(kIconBytes);
CGColorSpaceRef colorSpace = ::CGColorSpaceCreateDeviceRGB();
CGImageAlphaInfo alphaInfo = ::CGImageGetAlphaInfo(cgImage);
CGContextRef bitmapContext;
bitmapContext = ::CGBitmapContextCreate(bitmap, kIconWidth, kIconHeight,
kIconBitsPerComponent,
kIconBytesPerRow,
colorSpace,
alphaInfo);
if (!bitmapContext) {
::CGImageRelease(cgImage);
PR_Free(bitmap);
::CGColorSpaceRelease(colorSpace);
return NS_ERROR_FAILURE;
}
// The menu manager expects the icon flipped vertically from the way it
// comes out of nsIImageMac. Set up a transform to flip it.
::CGContextTranslateCTM(bitmapContext, 0, kIconHeight);
::CGContextScaleCTM(bitmapContext, 1, -1);
CGRect iconRect = ::CGRectMake(0, 0, kIconWidth, kIconHeight);
::CGContextClearRect(bitmapContext, iconRect);
::CGContextDrawImage(bitmapContext, iconRect, cgImage);
::CGImageRelease(cgImage);
::CGContextRelease(bitmapContext);
CGDataProviderRef provider;
provider = ::CGDataProviderCreateWithData(NULL, bitmap, kIconBytes,
PRAllocCGFree);
if (!provider) {
PR_Free(bitmap);
::CGColorSpaceRelease(colorSpace);
return NS_ERROR_FAILURE;
}
CGImageRef iconImage =
::CGImageCreate(kIconWidth, kIconHeight, kIconBitsPerComponent,
kIconBitsPerPixel, kIconBytesPerRow, colorSpace, alphaInfo,
provider, NULL, TRUE, kCGRenderingIntentDefault);
::CGColorSpaceRelease(colorSpace);
::CGDataProviderRelease(provider);
if (!iconImage) return NS_ERROR_FAILURE;
OSStatus err;
err = ::SetMenuItemIconHandle(mMenuRef, mMenuItemIndex, kMenuCGImageRefType,
(Handle)iconImage);
::CGImageRelease(iconImage);
if (err != noErr) return NS_ERROR_FAILURE;
mLoadedIcon = PR_TRUE;
mSetIcon = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsMenuItemIcon::OnStopContainer(imgIRequest* aRequest,
imgIContainer* aContainer)
{
return NS_OK;
}
NS_IMETHODIMP
nsMenuItemIcon::OnStopDecode(imgIRequest* aRequest,
nsresult status,
const PRUnichar* statusArg)
{
return NS_OK;
}
NS_IMETHODIMP
nsMenuItemIcon::OnStopRequest(imgIRequest* aRequest,
PRBool aIsLastPart)
{
mIconRequest->Cancel(NS_BINDING_ABORTED);
mIconRequest = nsnull;
return NS_OK;
}

Просмотреть файл

Просмотреть файл

@ -43,6 +43,7 @@
#include "nsMenuBarX.h" // for MenuHelpers namespace
#include "nsMenuX.h"
#include "nsMenuItemX.h"
#include "nsMenuItemIcon.h"
#include "nsWidgetAtoms.h"
@ -139,7 +140,10 @@ NS_METHOD nsMenuItemX::Create(nsIMenu* aParent, const nsString & aLabel, PRBool
}
}
}
mIcon = new nsMenuItemIcon(NS_STATIC_CAST(nsIMenuItem*, this),
mMenuParent, mContent);
return NS_OK;
}
@ -425,6 +429,9 @@ nsMenuItemX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIC
nsCOMPtr<nsIMenuListener> listener = do_QueryInterface(mMenuParent);
listener->SetRebuild(PR_TRUE);
}
else if (aAttribute == nsWidgetAtoms::image) {
SetupIcon();
}
}
else if (aContent == mCommandContent &&
aAttribute == nsWidgetAtoms::disabled &&
@ -471,3 +478,12 @@ nsMenuItemX :: ContentInserted(nsIDocument *aDocument, nsIContent *aChild, PRInt
return NS_OK;
} // ContentInserted
NS_IMETHODIMP
nsMenuItemX::SetupIcon()
{
if (!mIcon) return NS_ERROR_OUT_OF_MEMORY;
return mIcon->SetupIcon();
}

Просмотреть файл

@ -1,122 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsMenuItemX_h__
#define nsMenuItemX_h__
#include "nsIMenuItem.h"
#include "nsString.h"
#include "nsIMenuListener.h"
#include "nsIChangeManager.h"
#include "nsWeakReference.h"
#include "nsIWidget.h"
class nsIMenu;
/**
* Native Motif MenuItem wrapper
*/
class nsMenuItemX : public nsIMenuItem,
public nsIMenuListener,
public nsIChangeObserver,
public nsSupportsWeakReference
{
public:
nsMenuItemX();
virtual ~nsMenuItemX();
// nsISupports
NS_DECL_ISUPPORTS
NS_DECL_NSICHANGEOBSERVER
// nsIMenuItem Methods
NS_IMETHOD Create(nsIMenu* aParent, const nsString & aLabel, PRBool aIsSeparator,
EMenuItemType aItemType, nsIChangeManager* aManager,
nsIDocShell* aShell, nsIContent* aNode);
NS_IMETHOD GetLabel(nsString &aText);
NS_IMETHOD SetShortcutChar(const nsString &aText);
NS_IMETHOD GetShortcutChar(nsString &aText);
NS_IMETHOD GetEnabled(PRBool *aIsEnabled);
NS_IMETHOD SetChecked(PRBool aIsEnabled);
NS_IMETHOD GetChecked(PRBool *aIsEnabled);
NS_IMETHOD GetMenuItemType(EMenuItemType *aIsCheckbox);
NS_IMETHOD GetNativeData(void*& aData);
NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener);
NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener);
NS_IMETHOD IsSeparator(PRBool & aIsSep);
NS_IMETHOD DoCommand();
NS_IMETHOD DispatchDOMEvent(const nsString &eventName, PRBool *preventDefaultCalled);
NS_IMETHOD SetModifiers(PRUint8 aModifiers);
NS_IMETHOD GetModifiers(PRUint8 * aModifiers);
// nsIMenuListener interface
nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent);
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
void * menuNode, void * aDocShell);
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
nsEventStatus SetRebuild(PRBool aMenuEvent);
protected:
void UncheckRadioSiblings ( nsIContent* inCheckedElement ) ;
nsString mLabel;
nsString mKeyEquivalent;
nsIMenu* mMenuParent; // weak, parent owns us
nsIChangeManager* mManager; // weak
nsCOMPtr<nsIMenuListener> mXULCommandListener;
nsWeakPtr mDocShellWeakRef; // weak ref to docshell
nsCOMPtr<nsIContent> mContent;
nsCOMPtr<nsIContent> mCommandContent;
PRUint8 mModifiers;
PRPackedBool mIsSeparator;
PRPackedBool mEnabled;
PRPackedBool mIsChecked;
EMenuItemType mMenuType;
};
#endif // nsMenuItem_h__

Просмотреть файл

@ -53,6 +53,7 @@
#include "nsIMenuListener.h"
#include "nsPresContext.h"
#include "nsIMenuCommandDispatcher.h"
#include "nsMenuItemIcon.h"
#include "nsString.h"
#include "nsReadableUtils.h"
@ -179,7 +180,11 @@ nsMenuX::Create(nsISupports * aParent, const nsAString &aLabel, const nsAString
// menu gets selected, which is bad.
nsMenuEvent fake(PR_TRUE, 0, nsnull);
MenuConstruct(fake, nsnull, nsnull, nsnull);
if (menu)
mIcon = new nsMenuItemIcon(NS_STATIC_CAST(nsIMenu*, this),
menu, mMenuContent);
return NS_OK;
}
@ -869,6 +874,8 @@ void nsMenuX::LoadMenuItem( nsIMenu* inParentMenu, nsIContent* inMenuItemContent
nsCOMPtr<nsISupports> supports ( do_QueryInterface(pnsMenuItem) );
inParentMenu->AddItem(supports); // Parent now owns menu item
pnsMenuItem->SetupIcon();
}
}
@ -905,6 +912,8 @@ nsMenuX::LoadSubMenu( nsIMenu * pParentMenu, nsIContent* inMenuItemContent )
// Make nsMenu a child of parent nsMenu. The parent takes ownership
nsCOMPtr<nsISupports> supports2 ( do_QueryInterface(pnsMenu) );
pParentMenu->AddItem(supports2);
pnsMenu->SetupIcon();
}
}
@ -1199,25 +1208,45 @@ nsMenuX :: CountVisibleBefore ( PRUint32* outVisibleBefore )
NS_IMETHODIMP
nsMenuX::ChangeNativeEnabledStatusForMenuItem(nsIMenuItem* aMenuItem, PRBool aEnabled)
nsMenuX::ChangeNativeEnabledStatusForMenuItem(nsIMenuItem* aMenuItem,
PRBool aEnabled)
{
MenuRef menuRef;
PRUint16 menuItemIndex;
nsresult rv = GetMenuRefAndItemIndexForMenuItem(aMenuItem,
(void**)&menuRef,
&menuItemIndex);
if (NS_FAILED(rv)) return rv;
if (aEnabled)
::EnableMenuItem(menuRef, menuItemIndex);
else
::DisableMenuItem(menuRef, menuItemIndex);
return NS_OK;
}
NS_IMETHODIMP
nsMenuX::GetMenuRefAndItemIndexForMenuItem(nsISupports* aMenuItem,
void** aMenuRef,
PRUint16* aMenuItemIndex)
{
// look for the menu item given
PRUint32 menuItemCount;
mMenuItemsArray.Count(&menuItemCount);
for (PRUint32 i = 0; i < menuItemCount; i++) {
nsISupports* currItem;
mMenuItemsArray.GetElementAt(i, &currItem);
nsCOMPtr<nsISupports> currItem;
mMenuItemsArray.GetElementAt(i, getter_AddRefs(currItem));
if (currItem == aMenuItem) {
if (aEnabled)
::EnableMenuItem(mMacMenuHandle, i + 1);
else
::DisableMenuItem(mMacMenuHandle, i + 1);
break;
*aMenuRef = (void*)mMacMenuHandle;
*aMenuItemIndex = i + 1;
return NS_OK;
}
}
return NS_OK;
return NS_ERROR_FAILURE;
}
@ -1334,6 +1363,9 @@ nsMenuX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIConte
::DrawMenuBar();
}
}
else if (aAttribute == nsWidgetAtoms::image) {
SetupIcon();
}
return NS_OK;
@ -1367,3 +1399,15 @@ nsMenuX :: ContentInserted(nsIDocument *aDocument, nsIContent *aChild, PRInt32 a
return NS_OK;
} // ContentInserted
NS_IMETHODIMP
nsMenuX::SetupIcon()
{
// In addition to out-of-memory, menus that are children of the menu bar
// will not have mIcon set.
if (!mIcon) return NS_ERROR_OUT_OF_MEMORY;
return mIcon->SetupIcon();
}

Просмотреть файл

@ -1,189 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsMenuX_h__
#define nsMenuX_h__
#include "nsCOMPtr.h"
#include "nsIMenu.h"
#include "nsSupportsArray.h"
#include "nsIMenuListener.h"
#include "nsIChangeManager.h"
#include "nsWeakReference.h"
#include <Carbon/Carbon.h>
class nsIMenuBar;
class nsIMenuListener;
extern PRInt16 mMacMenuIDCount;
#if DEBUG
// utility instance counter class
class nsInstanceCounter
{
public:
nsInstanceCounter(const char* inDesc)
: mInstanceCount(0)
, mDescription(inDesc)
{
}
~nsInstanceCounter()
{
printf("%s %d\n", mDescription, mInstanceCount);
}
nsInstanceCounter& operator ++() // prefix
{
++ mInstanceCount;
return *this;
}
nsInstanceCounter& operator -- () // prefix
{
-- mInstanceCount;
return *this;
}
protected:
PRInt32 mInstanceCount;
const char* mDescription;
};
#endif
class nsMenuX : public nsIMenu,
public nsIMenuListener,
public nsIChangeObserver,
public nsSupportsWeakReference
{
public:
nsMenuX();
virtual ~nsMenuX();
NS_DECL_ISUPPORTS
NS_DECL_NSICHANGEOBSERVER
// nsIMenuListener methods
nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent);
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
nsEventStatus MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
void * menuNode, void * aDocShell);
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
nsEventStatus SetRebuild(PRBool aMenuEvent);
// nsIMenu Methods
NS_IMETHOD Create ( nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey,
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) ;
NS_IMETHOD GetParent(nsISupports *&aParent);
NS_IMETHOD GetLabel(nsString &aText);
NS_IMETHOD SetLabel(const nsAString &aText);
NS_IMETHOD GetAccessKey(nsString &aText);
NS_IMETHOD SetAccessKey(const nsAString &aText);
NS_IMETHOD AddItem(nsISupports* aText);
NS_IMETHOD AddSeparator();
NS_IMETHOD GetItemCount(PRUint32 &aCount);
NS_IMETHOD GetItemAt(const PRUint32 aPos, nsISupports *& aMenuItem);
NS_IMETHOD InsertItemAt(const PRUint32 aPos, nsISupports * aMenuItem);
NS_IMETHOD RemoveItem(const PRUint32 aPos);
NS_IMETHOD RemoveAll();
NS_IMETHOD GetNativeData(void** aData);
NS_IMETHOD SetNativeData(void* aData);
NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener);
NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener);
NS_IMETHOD GetMenuContent(nsIContent ** aMenuNode);
NS_IMETHOD SetEnabled(PRBool aIsEnabled);
NS_IMETHOD GetEnabled(PRBool* aIsEnabled);
NS_IMETHOD AddMenuItem(nsIMenuItem * aMenuItem);
NS_IMETHOD AddMenu(nsIMenu * aMenu);
NS_IMETHOD ChangeNativeEnabledStatusForMenuItem(nsIMenuItem* aMenuItem, PRBool aEnabled);
protected:
// Determines how many menus are visible among the siblings that are before me.
// It doesn't matter if I am visible.
nsresult CountVisibleBefore ( PRUint32* outVisibleBefore ) ;
// fetch the content node associated with the menupopup item
void GetMenuPopupContent ( nsIContent** aResult ) ;
// Insert a new item in this menu with index |inItemIndex| with the text |inItemLabel|,
// middle-truncated to a certain pixel width with an elipsis.
void InsertMenuItemWithTruncation ( nsAutoString & inItemLabel,
PRUint32 inItemIndex ) ;
// fire handlers for oncreate/ondestroy
PRBool OnDestroy() ;
PRBool OnCreate() ;
PRBool OnDestroyed() ;
PRBool OnCreated() ;
void LoadMenuItem ( nsIMenu* pParentMenu, nsIContent* menuitemContent );
void LoadSubMenu ( nsIMenu * pParentMenu, nsIContent* menuitemContent );
void LoadSeparator ( nsIContent* menuitemContent );
MenuHandle NSStringNewMenu(short menuID, nsString& menuTitle);
protected:
nsString mLabel;
PRUint32 mNumMenuItems;
nsSupportsArray mMenuItemsArray; // array holds refs
nsISupports* mParent; // weak, my parent owns me
nsIChangeManager* mManager; // weak ref, it will outlive us [menubar]
nsWeakPtr mDocShellWeakRef; // weak ref to docshell
nsCOMPtr<nsIContent> mMenuContent; // the |menu| tag, strong ref
nsCOMPtr<nsIMenuListener> mListener; // strong ref
// MacSpecific
PRInt16 mMacMenuID;
MenuHandle mMacMenuHandle;
PRPackedBool mIsEnabled;
PRPackedBool mDestroyHandlerCalled;
PRPackedBool mNeedsRebuild;
PRPackedBool mConstructed;
PRPackedBool mVisible; // are we visible to the user?
EventHandlerRef mHandler; // our event handler
};
#endif // nsMenuX_h__

Просмотреть файл

@ -1,94 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TOOLKIT_H
#define TOOLKIT_H
#include "nsToolkitBase.h"
/**
* The toolkit abstraction is necessary because the message pump must
* execute within the same thread that created the widget under Win32.
* We don't care about that on Mac: we have only one thread for the UI
* and maybe even for the whole application.
*
* So on the Mac, the nsToolkit used to be a unique object, created once
* at startup along with nsAppShell and passed to all the top-level
* windows and it became a convenient place to throw in everything we
* didn't know where else to put, like the NSPR event queue and
* the handling of global pointers on some special widgets (focused
* widget, widget hit, widget pointed).
*
* All this has changed: the application now usually creates one copy of
* the nsToolkit per window and the special widgets had to be moved
* to the nsMacEventHandler.
*/
#include <MacTypes.h>
#include <MacWindows.h>
class nsIEventSink;
class nsIWidget;
#define MAC_OS_X_VERSION_10_0_HEX 0x00001000
#define MAC_OS_X_VERSION_10_1_HEX 0x00001010
#define MAC_OS_X_VERSION_10_2_HEX 0x00001020
#define MAC_OS_X_VERSION_10_3_HEX 0x00001030
class nsToolkit : public nsToolkitBase
{
public:
nsToolkit();
virtual ~nsToolkit();
protected:
virtual nsresult InitEventQueue(PRThread * aThread);
public:
// utility routines for getting the toplevel widget and event sink
// stashed in properties of the window.
static void GetWindowEventSink ( WindowPtr aWindow, nsIEventSink** outSink ) ;
static void GetTopWidget ( WindowPtr aWindow, nsIWidget** outWidget ) ;
// Returns the OS X version as returned from
// Gestalt(gestaltSystemVersion, ...)
static long OSXVersion ( ) ;
};
#endif // TOOLKIT_H

Просмотреть файл

@ -73,6 +73,7 @@ WIDGET_ATOM(focused, "focused")
WIDGET_ATOM(hidden, "hidden")
WIDGET_ATOM(horizontal, "horizontal")
WIDGET_ATOM(id, "id")
WIDGET_ATOM(image, "image")
WIDGET_ATOM(input, "input")
WIDGET_ATOM(key, "key") // The key element / attribute
WIDGET_ATOM(label, "label")