Bug 513162 - Add support for 'chromemargin' property on XUL windows. r=smaug.

This commit is contained in:
Jim Mathies 2010-06-24 21:01:07 -05:00
Родитель bd66b36461
Коммит e758581cd0
4 изменённых файлов: 72 добавлений и 8 удалений

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

@ -194,6 +194,7 @@ GK_ATOM(checked, "checked")
GK_ATOM(child, "child")
GK_ATOM(children, "children")
GK_ATOM(choose, "choose")
GK_ATOM(chromemargin, "chromemargin")
GK_ATOM(circ, "circ")
GK_ATOM(circle, "circle")
GK_ATOM(cite, "cite")

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

@ -1076,6 +1076,17 @@ nsXULElement::BeforeSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
RemoveBroadcaster(oldValue);
}
}
else if (aNamespaceID == kNameSpaceID_None &&
aValue &&
mNodeInfo->Equals(nsGkAtoms::window) &&
aName == nsGkAtoms::chromemargin) {
nsAttrValue attrValue;
nsIntMargin margins;
// Make sure the margin format is valid first
if (!attrValue.ParseIntMarginValue(*aValue)) {
return NS_ERROR_INVALID_ARG;
}
}
return nsStyledElement::BeforeSetAttr(aNamespaceID, aName,
aValue, aNotify);
@ -1103,10 +1114,13 @@ nsXULElement::AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
}
// Hide chrome if needed
if (aName == nsGkAtoms::hidechrome &&
mNodeInfo->Equals(nsGkAtoms::window) &&
aValue) {
HideWindowChrome(aValue->EqualsLiteral("true"));
if (mNodeInfo->Equals(nsGkAtoms::window) && aValue) {
if (aName == nsGkAtoms::hidechrome) {
HideWindowChrome(aValue->EqualsLiteral("true"));
}
else if (aName == nsGkAtoms::chromemargin) {
SetChromeMargins(aValue);
}
}
// title, (in)activetitlebarcolor and drawintitlebar are settable on
@ -1368,9 +1382,13 @@ nsXULElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, PRBool aNotify)
}
if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::hidechrome &&
mNodeInfo->Equals(nsGkAtoms::window)) {
HideWindowChrome(PR_FALSE);
if (mNodeInfo->Equals(nsGkAtoms::window)) {
if (aName == nsGkAtoms::hidechrome) {
HideWindowChrome(PR_FALSE);
}
else if (aName == nsGkAtoms::chromemargin) {
ResetChromeMargins();
}
}
if (doc && doc->GetRootElement() == this) {
@ -2395,6 +2413,39 @@ nsXULElement::SetDrawsInTitlebar(PRBool aState)
}
}
void
nsXULElement::SetChromeMargins(const nsAString* aValue)
{
if (!aValue)
return;
nsIWidget* mainWidget = GetWindowWidget();
if (!mainWidget)
return;
// top, right, bottom, left - see nsAttrValue
nsAttrValue attrValue;
nsIntMargin margins;
nsAutoString data;
data.Assign(*aValue);
if (attrValue.ParseIntMarginValue(data) &&
attrValue.GetIntMarginValue(margins)) {
mainWidget->SetNonClientMargins(margins);
}
}
void
nsXULElement::ResetChromeMargins()
{
nsIWidget* mainWidget = GetWindowWidget();
if (!mainWidget)
return;
// See nsIWidget
nsIntMargin margins(-1,-1,-1,-1);
mainWidget->SetNonClientMargins(margins);
}
PRBool
nsXULElement::BoolAttrIsTrue(nsIAtom* aName)
{

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

@ -671,8 +671,10 @@ protected:
nsIWidget* GetWindowWidget();
// attribute setters for widget
nsresult HideWindowChrome(PRBool aShouldHide);
void SetChromeMargins(const nsAString* aValue);
void ResetChromeMargins();
void SetTitlebarColor(nscolor aColor, PRBool aActive);
void SetDrawsInTitlebar(PRBool aState);

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

@ -92,6 +92,7 @@
#include "nsReadableUtils.h"
#include "nsStyleConsts.h"
#include "nsPresContext.h"
#include "nsIContentUtils.h"
#include "nsWebShellWindow.h" // get rid of this one, too...
@ -1375,6 +1376,15 @@ void nsXULWindow::SyncAttributesToWidget()
mWindow->HideWindowChrome(PR_TRUE);
}
// "chromemargin" attribute
nsIntMargin margins;
nsCOMPtr<nsIContentUtils> cutils =
do_GetService("@mozilla.org/content/contentutils;1");
rv = windowElement->GetAttribute(NS_LITERAL_STRING("chromemargin"), attr);
if (NS_SUCCEEDED(rv) && cutils && cutils->ParseIntMarginValue(attr, margins)) {
mWindow->SetNonClientMargins(margins);
}
// "accelerated" attribute
PRBool isAccelerated;
rv = windowElement->HasAttribute(NS_LITERAL_STRING("accelerated"), &isAccelerated);