Removed state info from button renderer.
git-svn-id: svn://10.0.0.236/trunk@22090 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
b364ac0639
commit
a39632b9af
@ -4,11 +4,15 @@
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
|
||||
#define ACTIVE "active"
|
||||
#define HOVER "hover"
|
||||
#define NORMAL ""
|
||||
#define FOCUS "focus"
|
||||
#define ENABLED "enabled"
|
||||
#define DISABLED "disabled"
|
||||
|
||||
nsButtonFrameRenderer::nsButtonFrameRenderer()
|
||||
{
|
||||
mState = normal;
|
||||
mFocus = PR_FALSE;
|
||||
mEnabled = PR_TRUE;
|
||||
mNameSpace = kNameSpaceID_HTML;
|
||||
}
|
||||
|
||||
@ -26,83 +30,230 @@ void
|
||||
nsButtonFrameRenderer::SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext)
|
||||
{
|
||||
mFrame = aFrame;
|
||||
UpdateStyles(aPresContext);
|
||||
ReResolveStyles(aPresContext);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::Update(PRBool notify)
|
||||
|
||||
nsString
|
||||
nsButtonFrameRenderer::GetPseudoClassAttribute()
|
||||
{
|
||||
// get the content
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mFrame->GetContent(getter_AddRefs(content));
|
||||
|
||||
nsString state ="";
|
||||
// create and atom for the pseudo class
|
||||
nsCOMPtr<nsIAtom> atom = do_QueryInterface(NS_NewAtom("pseudoclass"));
|
||||
|
||||
switch (mState)
|
||||
{
|
||||
case hover:
|
||||
state = "hover";
|
||||
break;
|
||||
case active:
|
||||
state = "active";
|
||||
break;
|
||||
case normal:
|
||||
state = "";
|
||||
break;
|
||||
}
|
||||
|
||||
nsString enabled;
|
||||
|
||||
if (mEnabled)
|
||||
enabled = "enabled";
|
||||
else
|
||||
enabled = "disabled";
|
||||
|
||||
nsString focus;
|
||||
if (mFocus)
|
||||
focus = "focus";
|
||||
else
|
||||
focus = "";
|
||||
|
||||
nsString value = state + " " + focus + " " + enabled;
|
||||
value.Trim(" ");
|
||||
value.CompressWhitespace();
|
||||
// get the attribute
|
||||
nsAutoString value;
|
||||
content->GetAttribute(mNameSpace, atom, value);
|
||||
|
||||
/*
|
||||
char ch[256];
|
||||
value.ToCString(ch,256);
|
||||
printf("selector='%s'\n",ch);
|
||||
printf("getting pseudo='%s'\n",ch);
|
||||
*/
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetPseudoClassAttribute(const nsString& value, PRBool notify)
|
||||
{
|
||||
// get the content
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mFrame->GetContent(getter_AddRefs(content));
|
||||
|
||||
// create and atom for the pseudo class
|
||||
nsCOMPtr<nsIAtom> atom = do_QueryInterface(NS_NewAtom("pseudoclass"));
|
||||
content->SetAttribute(mNameSpace, atom, value, notify);
|
||||
|
||||
nsString pseudo = value;
|
||||
// remove whitespace
|
||||
pseudo.Trim(" ");
|
||||
pseudo.CompressWhitespace();
|
||||
|
||||
// set it
|
||||
content->SetAttribute(mNameSpace, atom, pseudo, notify);
|
||||
|
||||
/*
|
||||
char ch[256];
|
||||
pseudo.ToCString(ch,256);
|
||||
printf("setting pseudo='%s'\n",ch);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetState(ButtonState state, PRBool notify)
|
||||
{
|
||||
// get the pseudo class
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
|
||||
// remove all other states and add new state
|
||||
switch (state)
|
||||
{
|
||||
case hover:
|
||||
RemoveClass(pseudo, ACTIVE);
|
||||
AddClass(pseudo, HOVER);
|
||||
break;
|
||||
case active:
|
||||
RemoveClass(pseudo, HOVER);
|
||||
AddClass(pseudo, ACTIVE);
|
||||
break;
|
||||
case normal:
|
||||
RemoveClass(pseudo, HOVER);
|
||||
RemoveClass(pseudo, ACTIVE);
|
||||
break;
|
||||
}
|
||||
|
||||
// set the pseudo class
|
||||
SetPseudoClassAttribute(pseudo, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetState(ButtonState state)
|
||||
nsButtonFrameRenderer::SetFocus(PRBool aFocus, PRBool notify)
|
||||
{
|
||||
mState = state;
|
||||
ToggleClass(aFocus, FOCUS, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetFocus(PRBool aFocus)
|
||||
nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
|
||||
{
|
||||
mFocus = aFocus;
|
||||
// get the pseudo class
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
|
||||
// if focus add it
|
||||
if (aDisabled) {
|
||||
AddClass(pseudo, DISABLED);
|
||||
RemoveClass(pseudo, ENABLED);
|
||||
} else {
|
||||
RemoveClass(pseudo, DISABLED);
|
||||
AddClass(pseudo, ENABLED);
|
||||
}
|
||||
|
||||
// set pseudo class
|
||||
SetPseudoClassAttribute(pseudo, notify);
|
||||
}
|
||||
|
||||
nsButtonFrameRenderer::ButtonState
|
||||
nsButtonFrameRenderer::GetState()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, HOVER);
|
||||
if (index != -1)
|
||||
return hover;
|
||||
|
||||
index = IndexOfClass(pseudo, ACTIVE);
|
||||
if (index != -1)
|
||||
return active;
|
||||
|
||||
return normal;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isDisabled()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, DISABLED);
|
||||
if (index != -1)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isFocus()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, FOCUS);
|
||||
if (index != -1)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetEnabled(PRBool aEnabled)
|
||||
nsButtonFrameRenderer::ToggleClass(PRBool aValue, const nsString& c, PRBool notify)
|
||||
{
|
||||
mEnabled = aEnabled;
|
||||
// get the pseudo class
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
|
||||
// if focus add it
|
||||
if (aValue)
|
||||
AddClass(pseudo, c);
|
||||
else
|
||||
RemoveClass(pseudo, c);
|
||||
|
||||
// set pseudo class
|
||||
SetPseudoClassAttribute(pseudo, notify);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::AddClass(nsString& pseudoclass, const nsString newClass)
|
||||
{
|
||||
// see if the class is already there
|
||||
// if not add it
|
||||
|
||||
PRInt32 index = IndexOfClass(pseudoclass, newClass);
|
||||
if (index == -1) {
|
||||
pseudoclass += " ";
|
||||
pseudoclass += newClass;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::RemoveClass(nsString& pseudoclass, const nsString newClass)
|
||||
{
|
||||
// see if the class is there
|
||||
// if so remove it
|
||||
PRInt32 index = IndexOfClass(pseudoclass, newClass);
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
// remove it
|
||||
pseudoclass.Cut(index, newClass.Length());
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsButtonFrameRenderer::IndexOfClass(nsString& pseudoclass, const nsString& c)
|
||||
{
|
||||
// easy first case
|
||||
if (pseudoclass.Equals(c))
|
||||
return 0;
|
||||
|
||||
// look on left
|
||||
PRInt32 index = pseudoclass.Find(nsString(c) + " ");
|
||||
if (index == -1 || index > 0) {
|
||||
// look on right
|
||||
index = pseudoclass.Find(nsString(" ") + c);
|
||||
if (index == -1 || index != pseudoclass.Length() - (c.Length()+1))
|
||||
{
|
||||
// look in center
|
||||
index = pseudoclass.Find(nsString(" ") + c + " ");
|
||||
if (index == -1)
|
||||
return -1;
|
||||
else
|
||||
index++;
|
||||
} else
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
// if disabled do nothing
|
||||
if (nsnull == mEnabled) {
|
||||
if (PR_TRUE == isDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -123,12 +274,10 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
||||
switch (aEvent->message) {
|
||||
|
||||
case NS_MOUSE_ENTER:
|
||||
SetState(hover);
|
||||
Update(PR_TRUE);
|
||||
SetState(hover, PR_TRUE);
|
||||
break;
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
SetState(active);
|
||||
Update(PR_TRUE);
|
||||
SetState(active, PR_TRUE);
|
||||
// grab all mouse events
|
||||
|
||||
// PRBool result;
|
||||
@ -136,14 +285,12 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
SetState(hover);
|
||||
Update(PR_TRUE);
|
||||
SetState(hover, PR_TRUE);
|
||||
// stop grabbing mouse events
|
||||
//viewMan->GrabMouseEvents(nsnull,result);
|
||||
break;
|
||||
case NS_MOUSE_EXIT:
|
||||
SetState(normal);
|
||||
Update(PR_TRUE);
|
||||
SetState(normal, PR_TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -386,7 +533,7 @@ nsButtonFrameRenderer::GetButtonOutlineBorderAndPadding()
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::UpdateStyles(nsIPresContext& aPresContext)
|
||||
nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext)
|
||||
{
|
||||
// get all the styles
|
||||
nsCOMPtr<nsIContent> content;
|
||||
|
||||
@ -66,15 +66,14 @@ public:
|
||||
|
||||
virtual void SetNameSpace(PRInt32 aNameSpace);
|
||||
virtual void SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext);
|
||||
virtual void Update(PRBool notify);
|
||||
|
||||
virtual void SetState(ButtonState state);
|
||||
virtual void SetFocus(PRBool focus);
|
||||
virtual void SetEnabled(PRBool enabled);
|
||||
virtual void SetState(ButtonState state, PRBool notify);
|
||||
virtual void SetFocus(PRBool aFocus, PRBool notify);
|
||||
virtual void SetDisabled(PRBool aDisabled, PRBool notify);
|
||||
|
||||
ButtonState GetState() { return mState; }
|
||||
PRBool isEnabled() { return mEnabled; }
|
||||
PRBool isFocus() { return mFocus; }
|
||||
ButtonState GetState();
|
||||
PRBool isDisabled();
|
||||
PRBool isFocus();
|
||||
|
||||
virtual void GetButtonOutlineRect(const nsRect& aRect, nsRect& aResult);
|
||||
virtual void GetButtonOuterFocusRect(const nsRect& aRect, nsRect& aResult);
|
||||
@ -87,7 +86,7 @@ public:
|
||||
virtual nsMargin GetButtonInnerFocusBorderAndPadding();
|
||||
virtual nsMargin GetButtonOutlineBorderAndPadding();
|
||||
|
||||
virtual void UpdateStyles(nsIPresContext& aPresContext);
|
||||
virtual void ReResolveStyles(nsIPresContext& aPresContext);
|
||||
|
||||
/**
|
||||
* Subroutine to add in borders and padding
|
||||
@ -100,13 +99,15 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
virtual nsString GetPseudoClassAttribute();
|
||||
virtual void SetPseudoClassAttribute(const nsString& value, PRBool notify);
|
||||
virtual void ToggleClass(PRBool aEnabled, const nsString& c, PRBool notify);
|
||||
virtual void AddClass(nsString& pseudoclass, const nsString newClass);
|
||||
virtual void RemoveClass(nsString& pseudoclass, const nsString newClass);
|
||||
virtual PRInt32 IndexOfClass(nsString& pseudoclass, const nsString& c);
|
||||
|
||||
private:
|
||||
|
||||
ButtonState mState;
|
||||
|
||||
PRBool mFocus;
|
||||
PRBool mEnabled;
|
||||
|
||||
// cached styles for focus and outline.
|
||||
nsCOMPtr<nsIStyleContext> mBorderStyle;
|
||||
nsCOMPtr<nsIStyleContext> mInnerFocusStyle;
|
||||
|
||||
@ -4,11 +4,15 @@
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
|
||||
#define ACTIVE "active"
|
||||
#define HOVER "hover"
|
||||
#define NORMAL ""
|
||||
#define FOCUS "focus"
|
||||
#define ENABLED "enabled"
|
||||
#define DISABLED "disabled"
|
||||
|
||||
nsButtonFrameRenderer::nsButtonFrameRenderer()
|
||||
{
|
||||
mState = normal;
|
||||
mFocus = PR_FALSE;
|
||||
mEnabled = PR_TRUE;
|
||||
mNameSpace = kNameSpaceID_HTML;
|
||||
}
|
||||
|
||||
@ -26,83 +30,230 @@ void
|
||||
nsButtonFrameRenderer::SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext)
|
||||
{
|
||||
mFrame = aFrame;
|
||||
UpdateStyles(aPresContext);
|
||||
ReResolveStyles(aPresContext);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::Update(PRBool notify)
|
||||
|
||||
nsString
|
||||
nsButtonFrameRenderer::GetPseudoClassAttribute()
|
||||
{
|
||||
// get the content
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mFrame->GetContent(getter_AddRefs(content));
|
||||
|
||||
nsString state ="";
|
||||
// create and atom for the pseudo class
|
||||
nsCOMPtr<nsIAtom> atom = do_QueryInterface(NS_NewAtom("pseudoclass"));
|
||||
|
||||
switch (mState)
|
||||
{
|
||||
case hover:
|
||||
state = "hover";
|
||||
break;
|
||||
case active:
|
||||
state = "active";
|
||||
break;
|
||||
case normal:
|
||||
state = "";
|
||||
break;
|
||||
}
|
||||
|
||||
nsString enabled;
|
||||
|
||||
if (mEnabled)
|
||||
enabled = "enabled";
|
||||
else
|
||||
enabled = "disabled";
|
||||
|
||||
nsString focus;
|
||||
if (mFocus)
|
||||
focus = "focus";
|
||||
else
|
||||
focus = "";
|
||||
|
||||
nsString value = state + " " + focus + " " + enabled;
|
||||
value.Trim(" ");
|
||||
value.CompressWhitespace();
|
||||
// get the attribute
|
||||
nsAutoString value;
|
||||
content->GetAttribute(mNameSpace, atom, value);
|
||||
|
||||
/*
|
||||
char ch[256];
|
||||
value.ToCString(ch,256);
|
||||
printf("selector='%s'\n",ch);
|
||||
printf("getting pseudo='%s'\n",ch);
|
||||
*/
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetPseudoClassAttribute(const nsString& value, PRBool notify)
|
||||
{
|
||||
// get the content
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mFrame->GetContent(getter_AddRefs(content));
|
||||
|
||||
// create and atom for the pseudo class
|
||||
nsCOMPtr<nsIAtom> atom = do_QueryInterface(NS_NewAtom("pseudoclass"));
|
||||
content->SetAttribute(mNameSpace, atom, value, notify);
|
||||
|
||||
nsString pseudo = value;
|
||||
// remove whitespace
|
||||
pseudo.Trim(" ");
|
||||
pseudo.CompressWhitespace();
|
||||
|
||||
// set it
|
||||
content->SetAttribute(mNameSpace, atom, pseudo, notify);
|
||||
|
||||
/*
|
||||
char ch[256];
|
||||
pseudo.ToCString(ch,256);
|
||||
printf("setting pseudo='%s'\n",ch);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetState(ButtonState state, PRBool notify)
|
||||
{
|
||||
// get the pseudo class
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
|
||||
// remove all other states and add new state
|
||||
switch (state)
|
||||
{
|
||||
case hover:
|
||||
RemoveClass(pseudo, ACTIVE);
|
||||
AddClass(pseudo, HOVER);
|
||||
break;
|
||||
case active:
|
||||
RemoveClass(pseudo, HOVER);
|
||||
AddClass(pseudo, ACTIVE);
|
||||
break;
|
||||
case normal:
|
||||
RemoveClass(pseudo, HOVER);
|
||||
RemoveClass(pseudo, ACTIVE);
|
||||
break;
|
||||
}
|
||||
|
||||
// set the pseudo class
|
||||
SetPseudoClassAttribute(pseudo, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetState(ButtonState state)
|
||||
nsButtonFrameRenderer::SetFocus(PRBool aFocus, PRBool notify)
|
||||
{
|
||||
mState = state;
|
||||
ToggleClass(aFocus, FOCUS, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetFocus(PRBool aFocus)
|
||||
nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
|
||||
{
|
||||
mFocus = aFocus;
|
||||
// get the pseudo class
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
|
||||
// if focus add it
|
||||
if (aDisabled) {
|
||||
AddClass(pseudo, DISABLED);
|
||||
RemoveClass(pseudo, ENABLED);
|
||||
} else {
|
||||
RemoveClass(pseudo, DISABLED);
|
||||
AddClass(pseudo, ENABLED);
|
||||
}
|
||||
|
||||
// set pseudo class
|
||||
SetPseudoClassAttribute(pseudo, notify);
|
||||
}
|
||||
|
||||
nsButtonFrameRenderer::ButtonState
|
||||
nsButtonFrameRenderer::GetState()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, HOVER);
|
||||
if (index != -1)
|
||||
return hover;
|
||||
|
||||
index = IndexOfClass(pseudo, ACTIVE);
|
||||
if (index != -1)
|
||||
return active;
|
||||
|
||||
return normal;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isDisabled()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, DISABLED);
|
||||
if (index != -1)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isFocus()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, FOCUS);
|
||||
if (index != -1)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetEnabled(PRBool aEnabled)
|
||||
nsButtonFrameRenderer::ToggleClass(PRBool aValue, const nsString& c, PRBool notify)
|
||||
{
|
||||
mEnabled = aEnabled;
|
||||
// get the pseudo class
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
|
||||
// if focus add it
|
||||
if (aValue)
|
||||
AddClass(pseudo, c);
|
||||
else
|
||||
RemoveClass(pseudo, c);
|
||||
|
||||
// set pseudo class
|
||||
SetPseudoClassAttribute(pseudo, notify);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::AddClass(nsString& pseudoclass, const nsString newClass)
|
||||
{
|
||||
// see if the class is already there
|
||||
// if not add it
|
||||
|
||||
PRInt32 index = IndexOfClass(pseudoclass, newClass);
|
||||
if (index == -1) {
|
||||
pseudoclass += " ";
|
||||
pseudoclass += newClass;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::RemoveClass(nsString& pseudoclass, const nsString newClass)
|
||||
{
|
||||
// see if the class is there
|
||||
// if so remove it
|
||||
PRInt32 index = IndexOfClass(pseudoclass, newClass);
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
// remove it
|
||||
pseudoclass.Cut(index, newClass.Length());
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsButtonFrameRenderer::IndexOfClass(nsString& pseudoclass, const nsString& c)
|
||||
{
|
||||
// easy first case
|
||||
if (pseudoclass.Equals(c))
|
||||
return 0;
|
||||
|
||||
// look on left
|
||||
PRInt32 index = pseudoclass.Find(nsString(c) + " ");
|
||||
if (index == -1 || index > 0) {
|
||||
// look on right
|
||||
index = pseudoclass.Find(nsString(" ") + c);
|
||||
if (index == -1 || index != pseudoclass.Length() - (c.Length()+1))
|
||||
{
|
||||
// look in center
|
||||
index = pseudoclass.Find(nsString(" ") + c + " ");
|
||||
if (index == -1)
|
||||
return -1;
|
||||
else
|
||||
index++;
|
||||
} else
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
// if disabled do nothing
|
||||
if (nsnull == mEnabled) {
|
||||
if (PR_TRUE == isDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -123,12 +274,10 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
||||
switch (aEvent->message) {
|
||||
|
||||
case NS_MOUSE_ENTER:
|
||||
SetState(hover);
|
||||
Update(PR_TRUE);
|
||||
SetState(hover, PR_TRUE);
|
||||
break;
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
SetState(active);
|
||||
Update(PR_TRUE);
|
||||
SetState(active, PR_TRUE);
|
||||
// grab all mouse events
|
||||
|
||||
// PRBool result;
|
||||
@ -136,14 +285,12 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
SetState(hover);
|
||||
Update(PR_TRUE);
|
||||
SetState(hover, PR_TRUE);
|
||||
// stop grabbing mouse events
|
||||
//viewMan->GrabMouseEvents(nsnull,result);
|
||||
break;
|
||||
case NS_MOUSE_EXIT:
|
||||
SetState(normal);
|
||||
Update(PR_TRUE);
|
||||
SetState(normal, PR_TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -386,7 +533,7 @@ nsButtonFrameRenderer::GetButtonOutlineBorderAndPadding()
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::UpdateStyles(nsIPresContext& aPresContext)
|
||||
nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext)
|
||||
{
|
||||
// get all the styles
|
||||
nsCOMPtr<nsIContent> content;
|
||||
|
||||
@ -66,15 +66,14 @@ public:
|
||||
|
||||
virtual void SetNameSpace(PRInt32 aNameSpace);
|
||||
virtual void SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext);
|
||||
virtual void Update(PRBool notify);
|
||||
|
||||
virtual void SetState(ButtonState state);
|
||||
virtual void SetFocus(PRBool focus);
|
||||
virtual void SetEnabled(PRBool enabled);
|
||||
virtual void SetState(ButtonState state, PRBool notify);
|
||||
virtual void SetFocus(PRBool aFocus, PRBool notify);
|
||||
virtual void SetDisabled(PRBool aDisabled, PRBool notify);
|
||||
|
||||
ButtonState GetState() { return mState; }
|
||||
PRBool isEnabled() { return mEnabled; }
|
||||
PRBool isFocus() { return mFocus; }
|
||||
ButtonState GetState();
|
||||
PRBool isDisabled();
|
||||
PRBool isFocus();
|
||||
|
||||
virtual void GetButtonOutlineRect(const nsRect& aRect, nsRect& aResult);
|
||||
virtual void GetButtonOuterFocusRect(const nsRect& aRect, nsRect& aResult);
|
||||
@ -87,7 +86,7 @@ public:
|
||||
virtual nsMargin GetButtonInnerFocusBorderAndPadding();
|
||||
virtual nsMargin GetButtonOutlineBorderAndPadding();
|
||||
|
||||
virtual void UpdateStyles(nsIPresContext& aPresContext);
|
||||
virtual void ReResolveStyles(nsIPresContext& aPresContext);
|
||||
|
||||
/**
|
||||
* Subroutine to add in borders and padding
|
||||
@ -100,13 +99,15 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
virtual nsString GetPseudoClassAttribute();
|
||||
virtual void SetPseudoClassAttribute(const nsString& value, PRBool notify);
|
||||
virtual void ToggleClass(PRBool aEnabled, const nsString& c, PRBool notify);
|
||||
virtual void AddClass(nsString& pseudoclass, const nsString newClass);
|
||||
virtual void RemoveClass(nsString& pseudoclass, const nsString newClass);
|
||||
virtual PRInt32 IndexOfClass(nsString& pseudoclass, const nsString& c);
|
||||
|
||||
private:
|
||||
|
||||
ButtonState mState;
|
||||
|
||||
PRBool mFocus;
|
||||
PRBool mEnabled;
|
||||
|
||||
// cached styles for focus and outline.
|
||||
nsCOMPtr<nsIStyleContext> mBorderStyle;
|
||||
nsCOMPtr<nsIStyleContext> mInnerFocusStyle;
|
||||
|
||||
@ -246,15 +246,16 @@ nsTitledButtonFrame::Init(nsIPresContext& aPresContext,
|
||||
mContent->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::align, align);
|
||||
setAlignment(align);
|
||||
|
||||
|
||||
/*
|
||||
// get the alignment
|
||||
nsAutoString disabled;
|
||||
mContent->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::disabled, disabled);
|
||||
SetDisabled(disabled);
|
||||
|
||||
// defer the update
|
||||
if (!mRenderer.isEnabled())
|
||||
if (mRenderer.isDisabled())
|
||||
mUpdateHappendedInInit = PR_TRUE;
|
||||
*/
|
||||
|
||||
return rv;
|
||||
}
|
||||
@ -263,9 +264,9 @@ void
|
||||
nsTitledButtonFrame::SetDisabled(nsAutoString aDisabled)
|
||||
{
|
||||
if (aDisabled.EqualsIgnoreCase("true"))
|
||||
mRenderer.SetEnabled(PR_FALSE);
|
||||
mRenderer.SetDisabled(PR_TRUE, PR_TRUE);
|
||||
else
|
||||
mRenderer.SetEnabled(PR_TRUE);
|
||||
mRenderer.SetDisabled(PR_FALSE, PR_TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
@ -365,12 +366,14 @@ nsTitledButtonFrame::AttributeChanged(nsIPresContext* aPresContext,
|
||||
nsAutoString align;
|
||||
aChild->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::value, align);
|
||||
setAlignment(align);
|
||||
} else if (nsHTMLAtoms::disabled == aAttribute) {
|
||||
}
|
||||
/*
|
||||
else if (nsHTMLAtoms::disabled == aAttribute) {
|
||||
nsAutoString disabled;
|
||||
aChild->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::value, disabled);
|
||||
SetDisabled(disabled);
|
||||
mRenderer.Update(PR_TRUE);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
return NS_OK;
|
||||
@ -389,11 +392,13 @@ nsTitledButtonFrame::Paint(nsIPresContext& aPresContext,
|
||||
|
||||
// if we changed an attribute in our Init method then we need to update the
|
||||
// styles now.
|
||||
/*
|
||||
if (PR_TRUE == mUpdateHappendedInInit)
|
||||
{
|
||||
mUpdateHappendedInInit = PR_FALSE;
|
||||
mRenderer.Update(PR_TRUE);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
nsRect rect (0,0, mRect.width, mRect.height);
|
||||
mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect);
|
||||
@ -651,7 +656,7 @@ nsTitledButtonFrame::PaintTitle(nsIPresContext& aPresContext,
|
||||
aRenderingContext.SetFont(fontStyle->mFont);
|
||||
|
||||
// if disabled paint
|
||||
if (PR_FALSE == mRenderer.isEnabled())
|
||||
if (PR_TRUE == mRenderer.isDisabled())
|
||||
{
|
||||
// place 4 pixels of spacing
|
||||
float p2t;
|
||||
@ -1048,7 +1053,7 @@ nsTitledButtonFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
nsLeafFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
|
||||
// if disabled do nothing
|
||||
if (nsnull == mRenderer.isEnabled()) {
|
||||
if (PR_TRUE == mRenderer.isDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1064,8 +1069,7 @@ nsTitledButtonFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
if (mRenderer.GetState() == nsButtonFrameRenderer::active)
|
||||
{ // do mouse click
|
||||
mRenderer.SetFocus(PR_TRUE);
|
||||
mRenderer.Update(PR_TRUE);
|
||||
mRenderer.SetFocus(PR_TRUE, PR_TRUE);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1100,7 +1104,7 @@ nsTitledButtonFrame :: ReResolveStyleContext ( nsIPresContext* aPresContext, nsI
|
||||
return rv;
|
||||
}
|
||||
|
||||
mRenderer.UpdateStyles(*aPresContext);
|
||||
mRenderer.ReResolveStyles(*aPresContext);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user