Skip to content

Commit

Permalink
Bug 888615 - [Australis] Add a drawtitle attribute for XUL root eleme…
Browse files Browse the repository at this point in the history
…nts. When drawtitle="true" is set, even drawintitlebar windows will have a window title. r=roc, r=smichaud
  • Loading branch information
mstange committed Dec 17, 2013
1 parent ba2db93 commit 3b7de5f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 2 deletions.
1 change: 1 addition & 0 deletions content/base/src/nsGkAtomList.h
Expand Up @@ -311,6 +311,7 @@ GK_ATOM(dragover, "dragover")
GK_ATOM(dragSession, "dragSession")
GK_ATOM(dragstart, "dragstart")
GK_ATOM(drawintitlebar, "drawintitlebar")
GK_ATOM(drawtitle, "drawtitle")
GK_ATOM(drop, "drop")
GK_ATOM(dropAfter, "dropAfter")
GK_ATOM(dropBefore, "dropBefore")
Expand Down
18 changes: 18 additions & 0 deletions content/xul/content/src/nsXULElement.cpp
Expand Up @@ -1003,6 +1003,10 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
SetDrawsInTitlebar(
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
}
else if (aName == nsGkAtoms::drawtitle) {
SetDrawsTitle(
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
}
else if (aName == nsGkAtoms::localedir) {
// if the localedir changed on the root element, reset the document direction
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(document);
Expand Down Expand Up @@ -1058,6 +1062,9 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
else if (aName == nsGkAtoms::drawintitlebar) {
SetDrawsInTitlebar(false);
}
else if (aName == nsGkAtoms::drawtitle) {
SetDrawsTitle(false);
}
}
}

Expand Down Expand Up @@ -1829,6 +1836,17 @@ nsXULElement::SetDrawsInTitlebar(bool aState)
}
}

void
nsXULElement::SetDrawsTitle(bool aState)
{
nsIWidget* mainWidget = GetWindowWidget();
if (mainWidget) {
// We can do this synchronously because SetDrawsTitle doesn't have any
// synchronous effects apart from a harmless invalidation.
mainWidget->SetDrawsTitle(aState);
}
}

class MarginSetter : public nsRunnable
{
public:
Expand Down
1 change: 1 addition & 0 deletions content/xul/content/src/nsXULElement.h
Expand Up @@ -680,6 +680,7 @@ class nsXULElement MOZ_FINAL : public nsStyledElement,
void SetTitlebarColor(nscolor aColor, bool aActive);

void SetDrawsInTitlebar(bool aState);
void SetDrawsTitle(bool aState);

void RemoveBroadcaster(const nsAString & broadcasterId);

Expand Down
5 changes: 5 additions & 0 deletions widget/cocoa/nsCocoaWindow.h
Expand Up @@ -78,6 +78,7 @@ typedef struct _nsCocoaWindowList {
NSTrackingArea* mTrackingArea;

BOOL mBeingShown;
BOOL mDrawTitle;
}

- (void)importState:(NSDictionary*)aState;
Expand All @@ -104,6 +105,9 @@ typedef struct _nsCocoaWindowList {

- (NSArray*)titlebarControls;

- (void)setWantsTitleDrawn:(BOOL)aDrawTitle;
- (BOOL)wantsTitleDrawn;

@end

@interface NSWindow (Undocumented)
Expand Down Expand Up @@ -294,6 +298,7 @@ class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
virtual void SetShowsToolbarButton(bool aShow);
virtual void SetShowsFullScreenButton(bool aShow);
virtual void SetWindowAnimationType(WindowAnimationType aType);
virtual void SetDrawsTitle(bool aDrawTitle);
NS_IMETHOD SetNonClientMargins(nsIntMargin &margins);
NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive);
virtual void SetDrawsInTitlebar(bool aState);
Expand Down
32 changes: 30 additions & 2 deletions widget/cocoa/nsCocoaWindow.mm
Expand Up @@ -1995,6 +1995,16 @@ nsIntRect newBounds(NSToIntRound(aX), NSToIntRound(aY),
mAnimationType = aType;
}

void
nsCocoaWindow::SetDrawsTitle(bool aDrawTitle)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;

[mWindow setWantsTitleDrawn:aDrawTitle];

NS_OBJC_END_TRY_ABORT_BLOCK;
}

NS_IMETHODIMP nsCocoaWindow::SetNonClientMargins(nsIntMargin &margins)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
Expand Down Expand Up @@ -2630,6 +2640,7 @@ - (id)initWithContentRect:(NSRect)aContentRect styleMask:(NSUInteger)aStyle back
mDPI = GetDPI(self);
mTrackingArea = nil;
mBeingShown = NO;
mDrawTitle = NO;
[self updateTrackingArea];

return self;
Expand Down Expand Up @@ -2703,6 +2714,16 @@ - (BOOL)drawsContentsIntoWindowFrame
return mDrawsIntoWindowFrame;
}

- (void)setWantsTitleDrawn:(BOOL)aDrawTitle
{
mDrawTitle = aDrawTitle;
}

- (BOOL)wantsTitleDrawn
{
return mDrawTitle;
}

// Pass nil here to get the default appearance.
- (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive
{
Expand Down Expand Up @@ -3090,8 +3111,9 @@ - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect sync:(BOOL)aSync

- (NSRect)titlebarRect
{
return NSMakeRect(0, [[self contentView] bounds].size.height,
[self frame].size.width, [self titlebarHeight]);
CGFloat titlebarHeight = [self titlebarHeight];
return NSMakeRect(0, [self frame].size.height - titlebarHeight,
[self frame].size.width, titlebarHeight);
}

// Returns the unified height of titlebar + toolbar.
Expand Down Expand Up @@ -3155,6 +3177,12 @@ - (void)setDrawsContentsIntoWindowFrame:(BOOL)aState
}
}

- (void)setWantsTitleDrawn:(BOOL)aDrawTitle
{
[super setWantsTitleDrawn:aDrawTitle];
[self setTitlebarNeedsDisplayInRect:[self titlebarRect]];
}

- (void)placeWindowButtons:(NSRect)aRect
{
if (!NSEqualRects(mWindowButtonsRect, aRect)) {
Expand Down
7 changes: 7 additions & 0 deletions widget/nsIWidget.h
Expand Up @@ -1152,6 +1152,13 @@ class nsIWidget : public nsISupports {
*/
virtual void SetWindowAnimationType(WindowAnimationType aType) = 0;

/**
* Specifies whether the window title should be drawn even if the window
* contents extend into the titlebar. Ignored on windows that don't draw
* in the titlebar. Only implemented on OS X.
*/
virtual void SetDrawsTitle(bool aDrawTitle) {}

/**
* Hide window chrome (borders, buttons) for this widget.
*
Expand Down
4 changes: 4 additions & 0 deletions xpfe/appshell/src/nsXULWindow.cpp
Expand Up @@ -1410,6 +1410,10 @@ void nsXULWindow::SyncAttributesToWidget()
}
mWindow->SetIcon(attr);

// "drawtitle" attribute
windowElement->GetAttribute(NS_LITERAL_STRING("drawtitle"), attr);
mWindow->SetDrawsTitle(attr.LowerCaseEqualsLiteral("true"));

// "toggletoolbar" attribute
windowElement->GetAttribute(NS_LITERAL_STRING("toggletoolbar"), attr);
mWindow->SetShowsToolbarButton(attr.LowerCaseEqualsLiteral("true"));
Expand Down

0 comments on commit 3b7de5f

Please sign in to comment.