Bug 269410 - Create a new attribute, "toggletoolbar", which can be used to control whether the toolbar pill collapse button is shown on the window. r=Neil, r=josh, sr=roc
If the attribute is not specified, the button is hidden by default.
--- a/widget/public/nsIWidget.h
+++ b/widget/public/nsIWidget.h
@@ -97,20 +97,20 @@ typedef nsEventStatus (* EVENT_CALLBACK)
#define NS_NATIVE_PLUGIN_PORT_CG 101
#endif
#ifdef XP_WIN
#define NS_NATIVE_TSF_THREAD_MGR 100
#define NS_NATIVE_TSF_CATEGORY_MGR 101
#define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
#endif
-// {5FF2CD19-4F73-4935-8EA2-7A2C33166D4C}
+// {A16A3387-A529-439C-A127-A5893351FD24}
#define NS_IWIDGET_IID \
-{ 0x5FF2CD19, 0x4F73, 0x4935, \
- { 0x8E, 0xA2, 0x7A, 0x2C, 0x33, 0x16, 0x6D, 0x4C } }
+{ 0xA16A3387, 0xA529, 0x439C, \
+ { 0xA1, 0x27, 0xA5, 0x89, 0x33, 0x51, 0xFD, 0x24 } }
/*
* Window shadow styles
* Also used for the -moz-window-shadow CSS property
*/
#define NS_STYLE_WINDOW_SHADOW_NONE 0
#define NS_STYLE_WINDOW_SHADOW_DEFAULT 1
@@ -639,16 +639,24 @@ class nsIWidget : public nsISupports {
*/
virtual void GetWindowClipRegion(nsTArray<nsIntRect>* aRects) = 0;
/**
* Set the shadow style of the window.
*/
NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle) = 0;
+ /*
+ * On Mac OS X, this method shows or hides the pill button in the titlebar
+ * that's used to collapse the toolbar.
+ *
+ * Ignored on child widgets and on non-Mac platforms.
+ */
+ virtual void SetShowsToolbarButton(PRBool aShow) = 0;
+
/**
* Hide window chrome (borders, buttons) for this widget.
*
*/
NS_IMETHOD HideWindowChrome(PRBool aShouldHide) = 0;
/**
* Put the toplevel window into or out of fullscreen mode.
--- a/widget/src/cocoa/nsCocoaWindow.h
+++ b/widget/src/cocoa/nsCocoaWindow.h
@@ -230,16 +230,17 @@ public:
const nsTArray<Configuration>& aConfigurations);
NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) ;
NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
NS_IMETHOD GetAttention(PRInt32 aCycleCount);
virtual PRBool HasPendingInputEvent();
virtual nsTransparencyMode GetTransparencyMode();
virtual void SetTransparencyMode(nsTransparencyMode aMode);
NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle);
+ virtual void SetShowsToolbarButton(PRBool aShow);
NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, PRBool aActive);
// dispatch an NS_SIZEMODE event on miniaturize or deminiaturize
void DispatchSizeModeEvent(nsSizeMode aSizeMode);
virtual gfxASurface* GetThebesSurface();
// be notified that a some form of drag event needs to go into Gecko
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -1419,16 +1419,25 @@ NS_IMETHODIMP nsCocoaWindow::SetWindowSh
if ([mWindow hasShadow] != (aStyle != NS_STYLE_WINDOW_SHADOW_NONE))
[mWindow setHasShadow:(aStyle != NS_STYLE_WINDOW_SHADOW_NONE)];
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
+void nsCocoaWindow::SetShowsToolbarButton(PRBool aShow)
+{
+ NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
+
+ [mWindow setShowsToolbarButton:aShow];
+
+ NS_OBJC_END_TRY_ABORT_BLOCK;
+}
+
NS_IMETHODIMP nsCocoaWindow::SetWindowTitlebarColor(nscolor aColor, PRBool aActive)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
// If our cocoa window isn't a ToolbarWindow, something is wrong.
if (![mWindow isKindOfClass:[ToolbarWindow class]]) {
// Don't output a warning for the hidden window.
NS_WARN_IF_FALSE(SameCOMIdentity(nsCocoaUtils::GetHiddenWindowWidget(), (nsIWidget*)this),
@@ -1899,17 +1908,18 @@ nsCocoaWindow::UnifiedShading(void* aInf
}
- (float)titlebarHeight
{
NSRect frameRect = [self frame];
return frameRect.size.height - [self contentRectForFrameRect:frameRect].size.height;
}
-// Always show the toolbar pill button.
+// Returning YES here makes the setShowsToolbarButton method work even though
+// the window doesn't contain an NSToolbar.
- (BOOL)_hasToolbar
{
return YES;
}
// Dispatch a toolbar pill button clicked message to Gecko.
- (void)_toolbarPillButtonClicked:(id)sender
{
--- a/widget/src/xpwidgets/nsBaseWidget.h
+++ b/widget/src/xpwidgets/nsBaseWidget.h
@@ -102,16 +102,17 @@ public:
NS_IMETHOD SetCursor(imgIContainer* aCursor,
PRUint32 aHotspotX, PRUint32 aHotspotY);
NS_IMETHOD GetWindowType(nsWindowType& aWindowType);
NS_IMETHOD SetWindowType(nsWindowType aWindowType);
virtual void SetTransparencyMode(nsTransparencyMode aMode);
virtual nsTransparencyMode GetTransparencyMode();
virtual void GetWindowClipRegion(nsTArray<nsIntRect>* aRects);
NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle);
+ virtual void SetShowsToolbarButton(PRBool aShow) {}
NS_IMETHOD HideWindowChrome(PRBool aShouldHide);
NS_IMETHOD MakeFullScreen(PRBool aFullScreen);
virtual nsIRenderingContext* GetRenderingContext();
virtual nsIDeviceContext* GetDeviceContext();
virtual nsIToolkit* GetToolkit();
virtual gfxASurface* GetThebesSurface();
NS_IMETHOD SetModal(PRBool aModal);
NS_IMETHOD SetWindowClass(const nsAString& xulWinType);
--- a/xpfe/appshell/src/nsXULWindow.cpp
+++ b/xpfe/appshell/src/nsXULWindow.cpp
@@ -989,16 +989,17 @@ void nsXULWindow::OnChromeLoaded()
// (however, we think the benefits of intelligent dependent window placement
// trump that override.)
if (!parentWindow)
positionSet = PR_FALSE;
#endif
if (positionSet)
positionSet = LoadPositionFromXUL();
LoadMiscPersistentAttributesFromXUL();
+ LoadToolbarButtonPresenceFromXUL();
//LoadContentAreas();
if (mCenterAfterLoad && !positionSet)
Center(parentWindow, parentWindow ? PR_FALSE : PR_TRUE, PR_FALSE);
if (mShowAfterLoad)
SetVisibility(PR_TRUE);
@@ -1431,16 +1432,29 @@ NS_IMETHODIMP nsXULWindow::LoadIconFromX
if (id.IsEmpty()) {
id.AssignLiteral("default");
}
mWindow->SetIcon(id);
return NS_OK;
}
+NS_IMETHODIMP nsXULWindow::LoadToolbarButtonPresenceFromXUL()
+{
+ nsCOMPtr<nsIDOMElement> windowElement;
+ GetWindowDOMElement(getter_AddRefs(windowElement));
+ NS_ENSURE_TRUE(windowElement, NS_ERROR_FAILURE);
+ nsAutoString attr;
+ nsresult rv = windowElement->GetAttribute(NS_LITERAL_STRING("toggletoolbar"), attr);
+ if (NS_SUCCEEDED(rv)) {
+ mWindow->SetShowsToolbarButton(attr.LowerCaseEqualsLiteral("true"));
+ }
+ return NS_OK;
+}
+
NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
{
// can happen when the persistence timer fires at an inopportune time
// during window shutdown
if (!mDocShell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMElement> docShellElement;
--- a/xpfe/appshell/src/nsXULWindow.h
+++ b/xpfe/appshell/src/nsXULWindow.h
@@ -117,16 +117,17 @@ protected:
void StaggerPosition(PRInt32 &aRequestedX, PRInt32 &aRequestedY,
PRInt32 aSpecWidth, PRInt32 aSpecHeight);
PRBool LoadPositionFromXUL();
PRBool LoadSizeFromXUL();
PRBool LoadMiscPersistentAttributesFromXUL();
nsresult LoadChromeHidingFromXUL();
NS_IMETHOD LoadWindowClassFromXUL();
NS_IMETHOD LoadIconFromXUL();
+ NS_IMETHOD LoadToolbarButtonPresenceFromXUL();
NS_IMETHOD SavePersistentAttributes();
NS_IMETHOD GetWindowDOMWindow(nsIDOMWindowInternal** aDOMWindow);
NS_IMETHOD GetWindowDOMElement(nsIDOMElement** aDOMElement);
// See nsIDocShellTreeOwner for docs on next two methods
NS_HIDDEN_(nsresult) ContentShellAdded(nsIDocShellTreeItem* aContentShell,
PRBool aPrimary, PRBool aTargetable,