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 "nsIPresContext.h"
|
||||||
#include "nsGenericHTMLElement.h"
|
#include "nsGenericHTMLElement.h"
|
||||||
|
|
||||||
|
#define ACTIVE "active"
|
||||||
|
#define HOVER "hover"
|
||||||
|
#define NORMAL ""
|
||||||
|
#define FOCUS "focus"
|
||||||
|
#define ENABLED "enabled"
|
||||||
|
#define DISABLED "disabled"
|
||||||
|
|
||||||
nsButtonFrameRenderer::nsButtonFrameRenderer()
|
nsButtonFrameRenderer::nsButtonFrameRenderer()
|
||||||
{
|
{
|
||||||
mState = normal;
|
|
||||||
mFocus = PR_FALSE;
|
|
||||||
mEnabled = PR_TRUE;
|
|
||||||
mNameSpace = kNameSpaceID_HTML;
|
mNameSpace = kNameSpaceID_HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,83 +30,230 @@ void
|
|||||||
nsButtonFrameRenderer::SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext)
|
nsButtonFrameRenderer::SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext)
|
||||||
{
|
{
|
||||||
mFrame = aFrame;
|
mFrame = aFrame;
|
||||||
UpdateStyles(aPresContext);
|
ReResolveStyles(aPresContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
nsButtonFrameRenderer::Update(PRBool notify)
|
nsString
|
||||||
|
nsButtonFrameRenderer::GetPseudoClassAttribute()
|
||||||
{
|
{
|
||||||
|
// get the content
|
||||||
nsCOMPtr<nsIContent> content;
|
nsCOMPtr<nsIContent> content;
|
||||||
mFrame->GetContent(getter_AddRefs(content));
|
mFrame->GetContent(getter_AddRefs(content));
|
||||||
|
|
||||||
|
// create and atom for the pseudo class
|
||||||
|
nsCOMPtr<nsIAtom> atom = do_QueryInterface(NS_NewAtom("pseudoclass"));
|
||||||
|
|
||||||
nsString state ="";
|
// get the attribute
|
||||||
|
nsAutoString value;
|
||||||
switch (mState)
|
content->GetAttribute(mNameSpace, atom, value);
|
||||||
{
|
|
||||||
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();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
char ch[256];
|
char ch[256];
|
||||||
value.ToCString(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"));
|
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
|
void
|
||||||
nsButtonFrameRenderer::SetState(ButtonState state)
|
nsButtonFrameRenderer::SetFocus(PRBool aFocus, PRBool notify)
|
||||||
{
|
{
|
||||||
mState = state;
|
ToggleClass(aFocus, FOCUS, notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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
|
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
|
NS_IMETHODIMP
|
||||||
nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
||||||
nsGUIEvent* aEvent,
|
nsGUIEvent* aEvent,
|
||||||
nsEventStatus& aEventStatus)
|
nsEventStatus& aEventStatus)
|
||||||
{
|
{
|
||||||
// if disabled do nothing
|
// if disabled do nothing
|
||||||
if (nsnull == mEnabled) {
|
if (PR_TRUE == isDisabled()) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,12 +274,10 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
|||||||
switch (aEvent->message) {
|
switch (aEvent->message) {
|
||||||
|
|
||||||
case NS_MOUSE_ENTER:
|
case NS_MOUSE_ENTER:
|
||||||
SetState(hover);
|
SetState(hover, PR_TRUE);
|
||||||
Update(PR_TRUE);
|
|
||||||
break;
|
break;
|
||||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||||
SetState(active);
|
SetState(active, PR_TRUE);
|
||||||
Update(PR_TRUE);
|
|
||||||
// grab all mouse events
|
// grab all mouse events
|
||||||
|
|
||||||
// PRBool result;
|
// PRBool result;
|
||||||
@ -136,14 +285,12 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||||
SetState(hover);
|
SetState(hover, PR_TRUE);
|
||||||
Update(PR_TRUE);
|
|
||||||
// stop grabbing mouse events
|
// stop grabbing mouse events
|
||||||
//viewMan->GrabMouseEvents(nsnull,result);
|
//viewMan->GrabMouseEvents(nsnull,result);
|
||||||
break;
|
break;
|
||||||
case NS_MOUSE_EXIT:
|
case NS_MOUSE_EXIT:
|
||||||
SetState(normal);
|
SetState(normal, PR_TRUE);
|
||||||
Update(PR_TRUE);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +533,7 @@ nsButtonFrameRenderer::GetButtonOutlineBorderAndPadding()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsButtonFrameRenderer::UpdateStyles(nsIPresContext& aPresContext)
|
nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext)
|
||||||
{
|
{
|
||||||
// get all the styles
|
// get all the styles
|
||||||
nsCOMPtr<nsIContent> content;
|
nsCOMPtr<nsIContent> content;
|
||||||
|
|||||||
@ -66,15 +66,14 @@ public:
|
|||||||
|
|
||||||
virtual void SetNameSpace(PRInt32 aNameSpace);
|
virtual void SetNameSpace(PRInt32 aNameSpace);
|
||||||
virtual void SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext);
|
virtual void SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext);
|
||||||
virtual void Update(PRBool notify);
|
|
||||||
|
virtual void SetState(ButtonState state, PRBool notify);
|
||||||
|
virtual void SetFocus(PRBool aFocus, PRBool notify);
|
||||||
|
virtual void SetDisabled(PRBool aDisabled, PRBool notify);
|
||||||
|
|
||||||
virtual void SetState(ButtonState state);
|
ButtonState GetState();
|
||||||
virtual void SetFocus(PRBool focus);
|
PRBool isDisabled();
|
||||||
virtual void SetEnabled(PRBool enabled);
|
PRBool isFocus();
|
||||||
|
|
||||||
ButtonState GetState() { return mState; }
|
|
||||||
PRBool isEnabled() { return mEnabled; }
|
|
||||||
PRBool isFocus() { return mFocus; }
|
|
||||||
|
|
||||||
virtual void GetButtonOutlineRect(const nsRect& aRect, nsRect& aResult);
|
virtual void GetButtonOutlineRect(const nsRect& aRect, nsRect& aResult);
|
||||||
virtual void GetButtonOuterFocusRect(const nsRect& aRect, nsRect& aResult);
|
virtual void GetButtonOuterFocusRect(const nsRect& aRect, nsRect& aResult);
|
||||||
@ -87,7 +86,7 @@ public:
|
|||||||
virtual nsMargin GetButtonInnerFocusBorderAndPadding();
|
virtual nsMargin GetButtonInnerFocusBorderAndPadding();
|
||||||
virtual nsMargin GetButtonOutlineBorderAndPadding();
|
virtual nsMargin GetButtonOutlineBorderAndPadding();
|
||||||
|
|
||||||
virtual void UpdateStyles(nsIPresContext& aPresContext);
|
virtual void ReResolveStyles(nsIPresContext& aPresContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subroutine to add in borders and padding
|
* Subroutine to add in borders and padding
|
||||||
@ -100,13 +99,15 @@ public:
|
|||||||
|
|
||||||
protected:
|
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:
|
private:
|
||||||
|
|
||||||
ButtonState mState;
|
|
||||||
|
|
||||||
PRBool mFocus;
|
|
||||||
PRBool mEnabled;
|
|
||||||
|
|
||||||
// cached styles for focus and outline.
|
// cached styles for focus and outline.
|
||||||
nsCOMPtr<nsIStyleContext> mBorderStyle;
|
nsCOMPtr<nsIStyleContext> mBorderStyle;
|
||||||
nsCOMPtr<nsIStyleContext> mInnerFocusStyle;
|
nsCOMPtr<nsIStyleContext> mInnerFocusStyle;
|
||||||
|
|||||||
@ -4,11 +4,15 @@
|
|||||||
#include "nsIPresContext.h"
|
#include "nsIPresContext.h"
|
||||||
#include "nsGenericHTMLElement.h"
|
#include "nsGenericHTMLElement.h"
|
||||||
|
|
||||||
|
#define ACTIVE "active"
|
||||||
|
#define HOVER "hover"
|
||||||
|
#define NORMAL ""
|
||||||
|
#define FOCUS "focus"
|
||||||
|
#define ENABLED "enabled"
|
||||||
|
#define DISABLED "disabled"
|
||||||
|
|
||||||
nsButtonFrameRenderer::nsButtonFrameRenderer()
|
nsButtonFrameRenderer::nsButtonFrameRenderer()
|
||||||
{
|
{
|
||||||
mState = normal;
|
|
||||||
mFocus = PR_FALSE;
|
|
||||||
mEnabled = PR_TRUE;
|
|
||||||
mNameSpace = kNameSpaceID_HTML;
|
mNameSpace = kNameSpaceID_HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,83 +30,230 @@ void
|
|||||||
nsButtonFrameRenderer::SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext)
|
nsButtonFrameRenderer::SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext)
|
||||||
{
|
{
|
||||||
mFrame = aFrame;
|
mFrame = aFrame;
|
||||||
UpdateStyles(aPresContext);
|
ReResolveStyles(aPresContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
nsButtonFrameRenderer::Update(PRBool notify)
|
nsString
|
||||||
|
nsButtonFrameRenderer::GetPseudoClassAttribute()
|
||||||
{
|
{
|
||||||
|
// get the content
|
||||||
nsCOMPtr<nsIContent> content;
|
nsCOMPtr<nsIContent> content;
|
||||||
mFrame->GetContent(getter_AddRefs(content));
|
mFrame->GetContent(getter_AddRefs(content));
|
||||||
|
|
||||||
|
// create and atom for the pseudo class
|
||||||
|
nsCOMPtr<nsIAtom> atom = do_QueryInterface(NS_NewAtom("pseudoclass"));
|
||||||
|
|
||||||
nsString state ="";
|
// get the attribute
|
||||||
|
nsAutoString value;
|
||||||
switch (mState)
|
content->GetAttribute(mNameSpace, atom, value);
|
||||||
{
|
|
||||||
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();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
char ch[256];
|
char ch[256];
|
||||||
value.ToCString(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"));
|
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
|
void
|
||||||
nsButtonFrameRenderer::SetState(ButtonState state)
|
nsButtonFrameRenderer::SetFocus(PRBool aFocus, PRBool notify)
|
||||||
{
|
{
|
||||||
mState = state;
|
ToggleClass(aFocus, FOCUS, notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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
|
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
|
NS_IMETHODIMP
|
||||||
nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
||||||
nsGUIEvent* aEvent,
|
nsGUIEvent* aEvent,
|
||||||
nsEventStatus& aEventStatus)
|
nsEventStatus& aEventStatus)
|
||||||
{
|
{
|
||||||
// if disabled do nothing
|
// if disabled do nothing
|
||||||
if (nsnull == mEnabled) {
|
if (PR_TRUE == isDisabled()) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,12 +274,10 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
|||||||
switch (aEvent->message) {
|
switch (aEvent->message) {
|
||||||
|
|
||||||
case NS_MOUSE_ENTER:
|
case NS_MOUSE_ENTER:
|
||||||
SetState(hover);
|
SetState(hover, PR_TRUE);
|
||||||
Update(PR_TRUE);
|
|
||||||
break;
|
break;
|
||||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||||
SetState(active);
|
SetState(active, PR_TRUE);
|
||||||
Update(PR_TRUE);
|
|
||||||
// grab all mouse events
|
// grab all mouse events
|
||||||
|
|
||||||
// PRBool result;
|
// PRBool result;
|
||||||
@ -136,14 +285,12 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||||
SetState(hover);
|
SetState(hover, PR_TRUE);
|
||||||
Update(PR_TRUE);
|
|
||||||
// stop grabbing mouse events
|
// stop grabbing mouse events
|
||||||
//viewMan->GrabMouseEvents(nsnull,result);
|
//viewMan->GrabMouseEvents(nsnull,result);
|
||||||
break;
|
break;
|
||||||
case NS_MOUSE_EXIT:
|
case NS_MOUSE_EXIT:
|
||||||
SetState(normal);
|
SetState(normal, PR_TRUE);
|
||||||
Update(PR_TRUE);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +533,7 @@ nsButtonFrameRenderer::GetButtonOutlineBorderAndPadding()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsButtonFrameRenderer::UpdateStyles(nsIPresContext& aPresContext)
|
nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext)
|
||||||
{
|
{
|
||||||
// get all the styles
|
// get all the styles
|
||||||
nsCOMPtr<nsIContent> content;
|
nsCOMPtr<nsIContent> content;
|
||||||
|
|||||||
@ -66,15 +66,14 @@ public:
|
|||||||
|
|
||||||
virtual void SetNameSpace(PRInt32 aNameSpace);
|
virtual void SetNameSpace(PRInt32 aNameSpace);
|
||||||
virtual void SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext);
|
virtual void SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext);
|
||||||
virtual void Update(PRBool notify);
|
|
||||||
|
virtual void SetState(ButtonState state, PRBool notify);
|
||||||
|
virtual void SetFocus(PRBool aFocus, PRBool notify);
|
||||||
|
virtual void SetDisabled(PRBool aDisabled, PRBool notify);
|
||||||
|
|
||||||
virtual void SetState(ButtonState state);
|
ButtonState GetState();
|
||||||
virtual void SetFocus(PRBool focus);
|
PRBool isDisabled();
|
||||||
virtual void SetEnabled(PRBool enabled);
|
PRBool isFocus();
|
||||||
|
|
||||||
ButtonState GetState() { return mState; }
|
|
||||||
PRBool isEnabled() { return mEnabled; }
|
|
||||||
PRBool isFocus() { return mFocus; }
|
|
||||||
|
|
||||||
virtual void GetButtonOutlineRect(const nsRect& aRect, nsRect& aResult);
|
virtual void GetButtonOutlineRect(const nsRect& aRect, nsRect& aResult);
|
||||||
virtual void GetButtonOuterFocusRect(const nsRect& aRect, nsRect& aResult);
|
virtual void GetButtonOuterFocusRect(const nsRect& aRect, nsRect& aResult);
|
||||||
@ -87,7 +86,7 @@ public:
|
|||||||
virtual nsMargin GetButtonInnerFocusBorderAndPadding();
|
virtual nsMargin GetButtonInnerFocusBorderAndPadding();
|
||||||
virtual nsMargin GetButtonOutlineBorderAndPadding();
|
virtual nsMargin GetButtonOutlineBorderAndPadding();
|
||||||
|
|
||||||
virtual void UpdateStyles(nsIPresContext& aPresContext);
|
virtual void ReResolveStyles(nsIPresContext& aPresContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subroutine to add in borders and padding
|
* Subroutine to add in borders and padding
|
||||||
@ -100,13 +99,15 @@ public:
|
|||||||
|
|
||||||
protected:
|
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:
|
private:
|
||||||
|
|
||||||
ButtonState mState;
|
|
||||||
|
|
||||||
PRBool mFocus;
|
|
||||||
PRBool mEnabled;
|
|
||||||
|
|
||||||
// cached styles for focus and outline.
|
// cached styles for focus and outline.
|
||||||
nsCOMPtr<nsIStyleContext> mBorderStyle;
|
nsCOMPtr<nsIStyleContext> mBorderStyle;
|
||||||
nsCOMPtr<nsIStyleContext> mInnerFocusStyle;
|
nsCOMPtr<nsIStyleContext> mInnerFocusStyle;
|
||||||
|
|||||||
@ -246,15 +246,16 @@ nsTitledButtonFrame::Init(nsIPresContext& aPresContext,
|
|||||||
mContent->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::align, align);
|
mContent->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::align, align);
|
||||||
setAlignment(align);
|
setAlignment(align);
|
||||||
|
|
||||||
|
/*
|
||||||
// get the alignment
|
// get the alignment
|
||||||
nsAutoString disabled;
|
nsAutoString disabled;
|
||||||
mContent->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::disabled, disabled);
|
mContent->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::disabled, disabled);
|
||||||
SetDisabled(disabled);
|
SetDisabled(disabled);
|
||||||
|
|
||||||
// defer the update
|
// defer the update
|
||||||
if (!mRenderer.isEnabled())
|
if (mRenderer.isDisabled())
|
||||||
mUpdateHappendedInInit = PR_TRUE;
|
mUpdateHappendedInInit = PR_TRUE;
|
||||||
|
*/
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -263,9 +264,9 @@ void
|
|||||||
nsTitledButtonFrame::SetDisabled(nsAutoString aDisabled)
|
nsTitledButtonFrame::SetDisabled(nsAutoString aDisabled)
|
||||||
{
|
{
|
||||||
if (aDisabled.EqualsIgnoreCase("true"))
|
if (aDisabled.EqualsIgnoreCase("true"))
|
||||||
mRenderer.SetEnabled(PR_FALSE);
|
mRenderer.SetDisabled(PR_TRUE, PR_TRUE);
|
||||||
else
|
else
|
||||||
mRenderer.SetEnabled(PR_TRUE);
|
mRenderer.SetDisabled(PR_FALSE, PR_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -365,12 +366,14 @@ nsTitledButtonFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|||||||
nsAutoString align;
|
nsAutoString align;
|
||||||
aChild->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::value, align);
|
aChild->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::value, align);
|
||||||
setAlignment(align);
|
setAlignment(align);
|
||||||
} else if (nsHTMLAtoms::disabled == aAttribute) {
|
}
|
||||||
|
/*
|
||||||
|
else if (nsHTMLAtoms::disabled == aAttribute) {
|
||||||
nsAutoString disabled;
|
nsAutoString disabled;
|
||||||
aChild->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::value, disabled);
|
aChild->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::value, disabled);
|
||||||
SetDisabled(disabled);
|
SetDisabled(disabled);
|
||||||
mRenderer.Update(PR_TRUE);
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
return NS_OK;
|
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
|
// if we changed an attribute in our Init method then we need to update the
|
||||||
// styles now.
|
// styles now.
|
||||||
|
/*
|
||||||
if (PR_TRUE == mUpdateHappendedInInit)
|
if (PR_TRUE == mUpdateHappendedInInit)
|
||||||
{
|
{
|
||||||
mUpdateHappendedInInit = PR_FALSE;
|
mUpdateHappendedInInit = PR_FALSE;
|
||||||
mRenderer.Update(PR_TRUE);
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
nsRect rect (0,0, mRect.width, mRect.height);
|
nsRect rect (0,0, mRect.width, mRect.height);
|
||||||
mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect);
|
mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect);
|
||||||
@ -651,7 +656,7 @@ nsTitledButtonFrame::PaintTitle(nsIPresContext& aPresContext,
|
|||||||
aRenderingContext.SetFont(fontStyle->mFont);
|
aRenderingContext.SetFont(fontStyle->mFont);
|
||||||
|
|
||||||
// if disabled paint
|
// if disabled paint
|
||||||
if (PR_FALSE == mRenderer.isEnabled())
|
if (PR_TRUE == mRenderer.isDisabled())
|
||||||
{
|
{
|
||||||
// place 4 pixels of spacing
|
// place 4 pixels of spacing
|
||||||
float p2t;
|
float p2t;
|
||||||
@ -1048,7 +1053,7 @@ nsTitledButtonFrame::HandleEvent(nsIPresContext& aPresContext,
|
|||||||
nsLeafFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
nsLeafFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||||
|
|
||||||
// if disabled do nothing
|
// if disabled do nothing
|
||||||
if (nsnull == mRenderer.isEnabled()) {
|
if (PR_TRUE == mRenderer.isDisabled()) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1064,8 +1069,7 @@ nsTitledButtonFrame::HandleEvent(nsIPresContext& aPresContext,
|
|||||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||||
if (mRenderer.GetState() == nsButtonFrameRenderer::active)
|
if (mRenderer.GetState() == nsButtonFrameRenderer::active)
|
||||||
{ // do mouse click
|
{ // do mouse click
|
||||||
mRenderer.SetFocus(PR_TRUE);
|
mRenderer.SetFocus(PR_TRUE, PR_TRUE);
|
||||||
mRenderer.Update(PR_TRUE);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1100,7 +1104,7 @@ nsTitledButtonFrame :: ReResolveStyleContext ( nsIPresContext* aPresContext, nsI
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
mRenderer.UpdateStyles(*aPresContext);
|
mRenderer.ReResolveStyles(*aPresContext);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user