Fixed pseudoclass hack to actually use active, hover, focus pseudoclasses.
git-svn-id: svn://10.0.0.236/trunk@31365 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -274,6 +274,11 @@ nsHTMLButtonElement::Focus()
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonElement::SetFocus(nsIPresContext* aPresContext)
|
||||
{
|
||||
// first see if we are disabled or not. If disabled then do nothing.
|
||||
nsAutoString disabled;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled))
|
||||
return NS_OK;
|
||||
|
||||
nsIEventStateManager* esm;
|
||||
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
|
||||
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
|
||||
|
||||
@@ -423,6 +423,11 @@ nsHTMLInputElement::Focus()
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext)
|
||||
{
|
||||
// first see if we are disabled or not. If disabled then do nothing.
|
||||
nsAutoString disabled;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled))
|
||||
return NS_OK;
|
||||
|
||||
nsIEventStateManager* esm;
|
||||
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
|
||||
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
|
||||
|
||||
@@ -33,79 +33,6 @@ nsButtonFrameRenderer::SetFrame(nsFrame* aFrame, nsIPresContext& aPresContext)
|
||||
ReResolveStyles(aPresContext);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::Redraw()
|
||||
{
|
||||
mFrame->Invalidate(mOutlineRect, PR_TRUE);
|
||||
}
|
||||
|
||||
nsString
|
||||
nsButtonFrameRenderer::GetPseudoClassAttribute()
|
||||
{
|
||||
// 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"));
|
||||
|
||||
// get the attribute
|
||||
nsAutoString value;
|
||||
content->GetAttribute(mNameSpace, atom, value);
|
||||
|
||||
/*
|
||||
char ch[256];
|
||||
value.ToCString(ch,256);
|
||||
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"));
|
||||
|
||||
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::SetHover(PRBool aHover, PRBool notify)
|
||||
{
|
||||
ToggleClass(aHover, HOVER, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetActive(PRBool aActive, PRBool notify)
|
||||
{
|
||||
ToggleClass(aActive, ACTIVE, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetFocus(PRBool aFocus, PRBool notify)
|
||||
{
|
||||
ToggleClass(aFocus, FOCUS, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
|
||||
{
|
||||
@@ -120,28 +47,6 @@ nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
|
||||
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isHover()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, HOVER);
|
||||
if (index != -1)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isActive()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, ACTIVE);
|
||||
if (index != -1)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isDisabled()
|
||||
{
|
||||
@@ -155,159 +60,15 @@ nsButtonFrameRenderer::isDisabled()
|
||||
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::ToggleClass(PRBool aValue, const nsString& c, PRBool notify)
|
||||
{
|
||||
// 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 (PR_TRUE == isDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mFrame->GetContent(getter_AddRefs(content));
|
||||
|
||||
// get its view
|
||||
nsIView* view = nsnull;
|
||||
mFrame->GetView(&view);
|
||||
nsCOMPtr<nsIViewManager> viewMan;
|
||||
|
||||
if (view)
|
||||
view->GetViewManager(*getter_AddRefs(viewMan));
|
||||
|
||||
aEventStatus = nsEventStatus_eIgnore;
|
||||
|
||||
switch (aEvent->message) {
|
||||
|
||||
case NS_MOUSE_ENTER:
|
||||
SetHover(PR_TRUE, PR_TRUE);
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
SetActive(PR_TRUE, PR_TRUE);
|
||||
// grab all mouse events
|
||||
|
||||
PRBool result;
|
||||
if (viewMan)
|
||||
viewMan->GrabMouseEvents(view,result);
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
SetActive(PR_FALSE, PR_TRUE);
|
||||
// stop grabbing mouse events
|
||||
if (viewMan)
|
||||
viewMan->GrabMouseEvents(nsnull,result);
|
||||
break;
|
||||
case NS_MOUSE_EXIT:
|
||||
// if we don't have a view then we might not know when they release
|
||||
// the button. So on exit go back to the normal state.
|
||||
if (!viewMan)
|
||||
SetActive(PR_FALSE, PR_TRUE);
|
||||
|
||||
SetHover(PR_FALSE, PR_TRUE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
nsButtonFrameRenderer::Redraw()
|
||||
{
|
||||
nsRect frameRect;
|
||||
mFrame->GetRect(frameRect);
|
||||
nsRect rect(0, 0, frameRect.width, frameRect.height);
|
||||
mFrame->Invalidate(rect, PR_TRUE);
|
||||
{
|
||||
nsRect rect;
|
||||
mFrame->GetRect(rect);
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
mFrame->Invalidate(rect, PR_TRUE);
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::PaintButton (nsIPresContext& aPresContext,
|
||||
@@ -319,10 +80,10 @@ nsButtonFrameRenderer::PaintButton (nsIPresContext& aPresContext,
|
||||
//printf("painted width='%d' height='%d'\n",aRect.width, aRect.height);
|
||||
|
||||
// draw the border and background inside the focus and outline borders
|
||||
PaintBorderAndBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
||||
PaintBorderAndBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
||||
|
||||
// draw the focus and outline borders
|
||||
PaintOutlineAndFocusBorders(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
||||
PaintOutlineAndFocusBorders(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -341,13 +102,6 @@ nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsIPresContext& aPresContext,
|
||||
|
||||
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer)
|
||||
{
|
||||
// because we have and outline rect we need to
|
||||
// store our bounds for redraw. We will change
|
||||
// these bounds when outline appears
|
||||
mOutlineRect = rect;
|
||||
mOutlineRect.width = 0;
|
||||
mOutlineRect.height= 0;
|
||||
|
||||
if (mOuterFocusStyle) {
|
||||
// ---------- paint the outer focus border -------------
|
||||
|
||||
@@ -373,10 +127,13 @@ nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsIPresContext& aPresContext,
|
||||
|
||||
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer)
|
||||
{
|
||||
/*
|
||||
if (mOutlineStyle) {
|
||||
|
||||
GetButtonOutlineRect(aRect, mOutlineRect);
|
||||
|
||||
GetButtonOutlineRect(aRect, rect);
|
||||
|
||||
mOutlineRect = rect;
|
||||
|
||||
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mOutlineStyle ->GetStyleData(eStyleStruct_Spacing);
|
||||
|
||||
// set the clipping area so we can draw outside our bounds.
|
||||
@@ -385,10 +142,11 @@ nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsIPresContext& aPresContext,
|
||||
|
||||
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
|
||||
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
||||
aDirtyRect, mOutlineRect, *spacing, mOutlineStyle, 0);
|
||||
aDirtyRect, rect, *spacing, mOutlineStyle, 0);
|
||||
|
||||
aRenderingContext.PopState(clipEmpty);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,21 +312,36 @@ nsButtonFrameRenderer::GetAddedButtonBorderAndPadding()
|
||||
return GetButtonOuterFocusBorderAndPadding() + GetButtonInnerFocusMargin() + GetButtonInnerFocusBorderAndPadding();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this when styles change
|
||||
*/
|
||||
void
|
||||
nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext)
|
||||
{
|
||||
|
||||
// get all the styles
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mFrame->GetContent(getter_AddRefs(content));
|
||||
nsCOMPtr<nsIStyleContext> context;
|
||||
mFrame->GetStyleContext(getter_AddRefs(context));
|
||||
|
||||
// style that draw an outline around the button
|
||||
// style that draw an outline around the button
|
||||
|
||||
// see if the outline has changed.
|
||||
// nsCOMPtr<nsIStyleContext> oldOutline = mOutlineStyle;
|
||||
|
||||
nsCOMPtr<nsIAtom> atom (do_QueryInterface(NS_NewAtom(":-moz-outline")));
|
||||
aPresContext.ProbePseudoStyleContextFor(content, atom, context,
|
||||
PR_FALSE,
|
||||
getter_AddRefs(mOutlineStyle));
|
||||
|
||||
/*
|
||||
if (mOutlineStyle != oldOutline)
|
||||
{
|
||||
// if changed redraw the old rect
|
||||
mFrame->Invalidate(mOutlineRect, PR_TRUE);
|
||||
}
|
||||
*/
|
||||
|
||||
// style for the inner such as a dotted line (Windows)
|
||||
atom = do_QueryInterface(NS_NewAtom(":-moz-focus-inner"));
|
||||
@@ -584,29 +357,3 @@ nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext)
|
||||
PR_FALSE,
|
||||
getter_AddRefs(mOuterFocusStyle));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::AddFocusBordersAndPadding(nsIPresContext& aPresContext,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsHTMLReflowMetrics& aMetrics,
|
||||
nsMargin& aBorderPadding)
|
||||
{
|
||||
aBorderPadding = aReflowState.mComputedBorderPadding;
|
||||
|
||||
nsMargin m = GetButtonOuterFocusBorderAndPadding();
|
||||
m += GetButtonInnerFocusMargin();
|
||||
m += GetButtonInnerFocusBorderAndPadding();
|
||||
|
||||
aBorderPadding += m;
|
||||
|
||||
aMetrics.width += m.left + m.right;
|
||||
aMetrics.height += m.top + m.bottom;
|
||||
|
||||
aMetrics.ascent = aMetrics.height;
|
||||
aMetrics.descent = 0;
|
||||
|
||||
// printf("requested width='%d' height='%d'\n",aMetrics.width, aMetrics.height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,18 +33,9 @@
|
||||
class nsButtonFrameRenderer {
|
||||
public:
|
||||
|
||||
enum ButtonState {
|
||||
active,
|
||||
hover,
|
||||
normal
|
||||
};
|
||||
nsButtonFrameRenderer();
|
||||
virtual ~nsButtonFrameRenderer();
|
||||
|
||||
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
|
||||
virtual void PaintButton(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
@@ -67,15 +58,10 @@ public:
|
||||
virtual void SetNameSpace(PRInt32 aNameSpace);
|
||||
virtual void SetFrame(nsFrame* aFrame, nsIPresContext& aPresContext);
|
||||
|
||||
virtual void SetActive(PRBool aActive, PRBool notify);
|
||||
virtual void SetHover(PRBool aHover, PRBool notify);
|
||||
virtual void SetFocus(PRBool aFocus, PRBool notify);
|
||||
virtual void SetDisabled(PRBool aDisabled, PRBool notify);
|
||||
|
||||
PRBool isActive();
|
||||
PRBool isHover();
|
||||
PRBool isDisabled();
|
||||
PRBool isFocus();
|
||||
|
||||
virtual void GetButtonOutlineRect(const nsRect& aRect, nsRect& aResult);
|
||||
virtual void GetButtonOuterFocusRect(const nsRect& aRect, nsRect& aResult);
|
||||
@@ -92,25 +78,10 @@ public:
|
||||
|
||||
virtual void ReResolveStyles(nsIPresContext& aPresContext);
|
||||
|
||||
/**
|
||||
* Subroutine to add in borders and padding
|
||||
*/
|
||||
virtual void AddFocusBordersAndPadding(nsIPresContext& aPresContext,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
nsMargin& aBorderPadding);
|
||||
|
||||
virtual void Redraw();
|
||||
|
||||
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:
|
||||
|
||||
// cached styles for focus and outline.
|
||||
|
||||
@@ -571,6 +571,15 @@ NS_METHOD nsFormControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
}
|
||||
}
|
||||
|
||||
// lets see if the button was clicked. -EDV
|
||||
switch (aEvent->message) {
|
||||
case NS_MOUSE_LEFT_CLICK:
|
||||
MouseClicked(&aPresContext);
|
||||
break;
|
||||
}
|
||||
|
||||
/* All this this now done internally in Gecko.
|
||||
|
||||
//printf(" %d %d %d %d (%d,%d) \n", this, aEvent->widget, aEvent->widgetSupports,
|
||||
// aEvent->message, aEvent->point.x, aEvent->point.y);
|
||||
|
||||
@@ -608,6 +617,7 @@ NS_METHOD nsFormControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
}
|
||||
break;
|
||||
}
|
||||
*/
|
||||
aEventStatus = nsEventStatus_eConsumeDoDefault;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,6 @@ nsHTMLButtonControlFrame::MouseClicked(nsIPresContext* aPresContext)
|
||||
void
|
||||
nsHTMLButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
||||
{
|
||||
mRenderer.SetFocus(aOn, aRepaint);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -293,49 +292,20 @@ nsHTMLButtonControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
nsWidgetRendering mode;
|
||||
aPresContext.GetWidgetRenderingMode(&mode);
|
||||
|
||||
// if disabled do nothing
|
||||
if (mRenderer.isDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult result = mRenderer.HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
if (NS_OK != result)
|
||||
return result;
|
||||
|
||||
aEventStatus = nsEventStatus_eIgnore;
|
||||
|
||||
// lets see if the button was clicked. -EDV
|
||||
switch (aEvent->message) {
|
||||
|
||||
case NS_MOUSE_ENTER:
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
mRenderer.SetFocus(PR_TRUE, PR_TRUE);
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
if (mRenderer.isHover())
|
||||
MouseClicked(&aPresContext);
|
||||
break;
|
||||
|
||||
case NS_KEY_DOWN:
|
||||
if (NS_KEY_EVENT == aEvent->eventStructType) {
|
||||
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
|
||||
if (NS_VK_SPACE == keyEvent->keyCode) {
|
||||
MouseClicked(&aPresContext);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NS_MOUSE_EXIT:
|
||||
break;
|
||||
case NS_MOUSE_LEFT_CLICK:
|
||||
MouseClicked(&aPresContext);
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
// we don't want our children to get any events. So just pass it to frame.
|
||||
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -274,6 +274,11 @@ nsHTMLButtonElement::Focus()
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonElement::SetFocus(nsIPresContext* aPresContext)
|
||||
{
|
||||
// first see if we are disabled or not. If disabled then do nothing.
|
||||
nsAutoString disabled;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled))
|
||||
return NS_OK;
|
||||
|
||||
nsIEventStateManager* esm;
|
||||
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
|
||||
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
|
||||
|
||||
@@ -423,6 +423,11 @@ nsHTMLInputElement::Focus()
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext)
|
||||
{
|
||||
// first see if we are disabled or not. If disabled then do nothing.
|
||||
nsAutoString disabled;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled))
|
||||
return NS_OK;
|
||||
|
||||
nsIEventStateManager* esm;
|
||||
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
|
||||
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
|
||||
|
||||
@@ -460,7 +460,7 @@ input[type="submit"] {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="submit"][pseudoclass~="active"] {
|
||||
input[type="submit"]:active {
|
||||
border-style: inset;
|
||||
|
||||
padding-left: 2px;
|
||||
@@ -469,11 +469,11 @@ input[type="submit"][pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
input[type="submit"][pseudoclass~="active"]:-moz-outline {
|
||||
input[type="submit"]:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
input[type="submit"][pseudoclass~="hover"]:-moz-outline {
|
||||
input[type="submit"]:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -481,6 +481,11 @@ input[type="submit"][disabled] {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
input[type="submit"][disabled]:active {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
|
||||
input[type="submit"]:-moz-focus-inner {
|
||||
padding-left : 2px;
|
||||
padding-right : 2px;
|
||||
@@ -489,7 +494,7 @@ input[type="submit"]:-moz-focus-inner {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
input[type="submit"][pseudoclass~="focus"]:-moz-focus-inner {
|
||||
input[type="submit"]:focus:-moz-focus-inner {
|
||||
padding-left : 1px;
|
||||
padding-right : 1px;
|
||||
padding-top : 0px;
|
||||
@@ -507,7 +512,7 @@ input[type="reset"] {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="reset"][pseudoclass~="active"] {
|
||||
input[type="reset"]:active {
|
||||
border-style: inset;
|
||||
|
||||
padding-left: 2px;
|
||||
@@ -516,11 +521,11 @@ input[type="reset"][pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
input[type="reset"][pseudoclass~="active"]:-moz-outline {
|
||||
input[type="reset"]:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
input[type="reset"][pseudoclass~="hover"]:-moz-outline {
|
||||
input[type="reset"]:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -528,6 +533,10 @@ input[type="reset"][disabled] {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
input[type="reset"][disabled]:active {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="reset"]:-moz-focus-inner {
|
||||
padding-left : 2px;
|
||||
padding-right : 2px;
|
||||
@@ -536,7 +545,7 @@ input[type="reset"]:-moz-focus-inner {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
input[type="reset"][pseudoclass~="focus"]:-moz-focus-inner {
|
||||
input[type="reset"]:focus:-moz-focus-inner {
|
||||
padding-left : 1px;
|
||||
padding-right : 1px;
|
||||
padding-top : 0px;
|
||||
@@ -554,7 +563,7 @@ input[type="button"] {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="button"][pseudoclass~="active"] {
|
||||
input[type="button"]:active {
|
||||
border-style: inset;
|
||||
|
||||
padding-left: 2px;
|
||||
@@ -563,11 +572,11 @@ input[type="button"][pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
input[type="button"][pseudoclass~="active"]:-moz-outline {
|
||||
input[type="button"]:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
input[type="button"][pseudoclass~="hover"]:-moz-outline {
|
||||
input[type="button"]:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -575,6 +584,10 @@ input[type="button"][disabled] {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
input[type="button"][disabled]:active {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="button"]:-moz-focus-inner {
|
||||
padding-left : 2px;
|
||||
padding-right : 2px;
|
||||
@@ -583,7 +596,7 @@ input[type="button"]:-moz-focus-inner {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
input[type="button"][pseudoclass~="focus"]:-moz-focus-inner {
|
||||
input[type="button"]:focus:-moz-focus-inner {
|
||||
padding-left : 1px;
|
||||
padding-right : 1px;
|
||||
padding-top : 0px;
|
||||
@@ -606,7 +619,7 @@ button {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
button[pseudoclass~="active"] {
|
||||
button:active {
|
||||
border-style: inset;
|
||||
|
||||
padding-left: 2px;
|
||||
@@ -615,14 +628,14 @@ button[pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
button[pseudoclass~="hover"] {
|
||||
button:hover {
|
||||
}
|
||||
|
||||
button[pseudoclass~="active"]:-moz-outline {
|
||||
button:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
button[pseudoclass~="hover"]:-moz-outline {
|
||||
button:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -630,6 +643,10 @@ button[disabled] {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
button[disabled]:active {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
button:-moz-focus-inner {
|
||||
padding-left : 2px;
|
||||
padding-right : 2px;
|
||||
@@ -638,7 +655,7 @@ button:-moz-focus-inner {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
button[pseudoclass~="focus"]:-moz-focus-inner {
|
||||
button:focus:-moz-focus-inner {
|
||||
padding-left : 1px;
|
||||
padding-right : 1px;
|
||||
padding-top : 0px;
|
||||
|
||||
@@ -521,57 +521,17 @@ nsButtonControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
nsWidgetRendering mode;
|
||||
aPresContext.GetWidgetRenderingMode(&mode);
|
||||
|
||||
if (eWidgetRendering_Native == mode) {
|
||||
return nsFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
}
|
||||
|
||||
// if disabled do nothing
|
||||
if (mRenderer.isDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult result = mRenderer.HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
if (NS_OK != result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
aEventStatus = nsEventStatus_eIgnore;
|
||||
|
||||
switch (aEvent->message) {
|
||||
|
||||
case NS_MOUSE_ENTER:
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
mRenderer.SetFocus(PR_TRUE, PR_TRUE);
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
if (mRenderer.isHover()) {
|
||||
MouseClicked(&aPresContext);
|
||||
}
|
||||
break;
|
||||
|
||||
case NS_KEY_DOWN:
|
||||
if (NS_KEY_EVENT == aEvent->eventStructType) {
|
||||
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
|
||||
if (NS_VK_SPACE == keyEvent->keyCode || NS_VK_RETURN == keyEvent->keyCode) {
|
||||
MouseClicked(&aPresContext);
|
||||
}
|
||||
}
|
||||
|
||||
case NS_MOUSE_EXIT:
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
return nsFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
||||
{
|
||||
mRenderer.SetFocus(aOn, aRepaint);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -33,79 +33,6 @@ nsButtonFrameRenderer::SetFrame(nsFrame* aFrame, nsIPresContext& aPresContext)
|
||||
ReResolveStyles(aPresContext);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::Redraw()
|
||||
{
|
||||
mFrame->Invalidate(mOutlineRect, PR_TRUE);
|
||||
}
|
||||
|
||||
nsString
|
||||
nsButtonFrameRenderer::GetPseudoClassAttribute()
|
||||
{
|
||||
// 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"));
|
||||
|
||||
// get the attribute
|
||||
nsAutoString value;
|
||||
content->GetAttribute(mNameSpace, atom, value);
|
||||
|
||||
/*
|
||||
char ch[256];
|
||||
value.ToCString(ch,256);
|
||||
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"));
|
||||
|
||||
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::SetHover(PRBool aHover, PRBool notify)
|
||||
{
|
||||
ToggleClass(aHover, HOVER, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetActive(PRBool aActive, PRBool notify)
|
||||
{
|
||||
ToggleClass(aActive, ACTIVE, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetFocus(PRBool aFocus, PRBool notify)
|
||||
{
|
||||
ToggleClass(aFocus, FOCUS, notify);
|
||||
}
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
|
||||
{
|
||||
@@ -120,28 +47,6 @@ nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
|
||||
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isHover()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, HOVER);
|
||||
if (index != -1)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isActive()
|
||||
{
|
||||
nsString pseudo = GetPseudoClassAttribute();
|
||||
PRInt32 index = IndexOfClass(pseudo, ACTIVE);
|
||||
if (index != -1)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsButtonFrameRenderer::isDisabled()
|
||||
{
|
||||
@@ -155,159 +60,15 @@ nsButtonFrameRenderer::isDisabled()
|
||||
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::ToggleClass(PRBool aValue, const nsString& c, PRBool notify)
|
||||
{
|
||||
// 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 (PR_TRUE == isDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mFrame->GetContent(getter_AddRefs(content));
|
||||
|
||||
// get its view
|
||||
nsIView* view = nsnull;
|
||||
mFrame->GetView(&view);
|
||||
nsCOMPtr<nsIViewManager> viewMan;
|
||||
|
||||
if (view)
|
||||
view->GetViewManager(*getter_AddRefs(viewMan));
|
||||
|
||||
aEventStatus = nsEventStatus_eIgnore;
|
||||
|
||||
switch (aEvent->message) {
|
||||
|
||||
case NS_MOUSE_ENTER:
|
||||
SetHover(PR_TRUE, PR_TRUE);
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
SetActive(PR_TRUE, PR_TRUE);
|
||||
// grab all mouse events
|
||||
|
||||
PRBool result;
|
||||
if (viewMan)
|
||||
viewMan->GrabMouseEvents(view,result);
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
SetActive(PR_FALSE, PR_TRUE);
|
||||
// stop grabbing mouse events
|
||||
if (viewMan)
|
||||
viewMan->GrabMouseEvents(nsnull,result);
|
||||
break;
|
||||
case NS_MOUSE_EXIT:
|
||||
// if we don't have a view then we might not know when they release
|
||||
// the button. So on exit go back to the normal state.
|
||||
if (!viewMan)
|
||||
SetActive(PR_FALSE, PR_TRUE);
|
||||
|
||||
SetHover(PR_FALSE, PR_TRUE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
nsButtonFrameRenderer::Redraw()
|
||||
{
|
||||
nsRect frameRect;
|
||||
mFrame->GetRect(frameRect);
|
||||
nsRect rect(0, 0, frameRect.width, frameRect.height);
|
||||
mFrame->Invalidate(rect, PR_TRUE);
|
||||
{
|
||||
nsRect rect;
|
||||
mFrame->GetRect(rect);
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
mFrame->Invalidate(rect, PR_TRUE);
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::PaintButton (nsIPresContext& aPresContext,
|
||||
@@ -319,10 +80,10 @@ nsButtonFrameRenderer::PaintButton (nsIPresContext& aPresContext,
|
||||
//printf("painted width='%d' height='%d'\n",aRect.width, aRect.height);
|
||||
|
||||
// draw the border and background inside the focus and outline borders
|
||||
PaintBorderAndBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
||||
PaintBorderAndBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
||||
|
||||
// draw the focus and outline borders
|
||||
PaintOutlineAndFocusBorders(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
||||
PaintOutlineAndFocusBorders(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -341,13 +102,6 @@ nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsIPresContext& aPresContext,
|
||||
|
||||
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer)
|
||||
{
|
||||
// because we have and outline rect we need to
|
||||
// store our bounds for redraw. We will change
|
||||
// these bounds when outline appears
|
||||
mOutlineRect = rect;
|
||||
mOutlineRect.width = 0;
|
||||
mOutlineRect.height= 0;
|
||||
|
||||
if (mOuterFocusStyle) {
|
||||
// ---------- paint the outer focus border -------------
|
||||
|
||||
@@ -373,10 +127,13 @@ nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsIPresContext& aPresContext,
|
||||
|
||||
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer)
|
||||
{
|
||||
/*
|
||||
if (mOutlineStyle) {
|
||||
|
||||
GetButtonOutlineRect(aRect, mOutlineRect);
|
||||
|
||||
GetButtonOutlineRect(aRect, rect);
|
||||
|
||||
mOutlineRect = rect;
|
||||
|
||||
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mOutlineStyle ->GetStyleData(eStyleStruct_Spacing);
|
||||
|
||||
// set the clipping area so we can draw outside our bounds.
|
||||
@@ -385,10 +142,11 @@ nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsIPresContext& aPresContext,
|
||||
|
||||
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
|
||||
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
||||
aDirtyRect, mOutlineRect, *spacing, mOutlineStyle, 0);
|
||||
aDirtyRect, rect, *spacing, mOutlineStyle, 0);
|
||||
|
||||
aRenderingContext.PopState(clipEmpty);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,21 +312,36 @@ nsButtonFrameRenderer::GetAddedButtonBorderAndPadding()
|
||||
return GetButtonOuterFocusBorderAndPadding() + GetButtonInnerFocusMargin() + GetButtonInnerFocusBorderAndPadding();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this when styles change
|
||||
*/
|
||||
void
|
||||
nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext)
|
||||
{
|
||||
|
||||
// get all the styles
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mFrame->GetContent(getter_AddRefs(content));
|
||||
nsCOMPtr<nsIStyleContext> context;
|
||||
mFrame->GetStyleContext(getter_AddRefs(context));
|
||||
|
||||
// style that draw an outline around the button
|
||||
// style that draw an outline around the button
|
||||
|
||||
// see if the outline has changed.
|
||||
// nsCOMPtr<nsIStyleContext> oldOutline = mOutlineStyle;
|
||||
|
||||
nsCOMPtr<nsIAtom> atom (do_QueryInterface(NS_NewAtom(":-moz-outline")));
|
||||
aPresContext.ProbePseudoStyleContextFor(content, atom, context,
|
||||
PR_FALSE,
|
||||
getter_AddRefs(mOutlineStyle));
|
||||
|
||||
/*
|
||||
if (mOutlineStyle != oldOutline)
|
||||
{
|
||||
// if changed redraw the old rect
|
||||
mFrame->Invalidate(mOutlineRect, PR_TRUE);
|
||||
}
|
||||
*/
|
||||
|
||||
// style for the inner such as a dotted line (Windows)
|
||||
atom = do_QueryInterface(NS_NewAtom(":-moz-focus-inner"));
|
||||
@@ -584,29 +357,3 @@ nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext)
|
||||
PR_FALSE,
|
||||
getter_AddRefs(mOuterFocusStyle));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsButtonFrameRenderer::AddFocusBordersAndPadding(nsIPresContext& aPresContext,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsHTMLReflowMetrics& aMetrics,
|
||||
nsMargin& aBorderPadding)
|
||||
{
|
||||
aBorderPadding = aReflowState.mComputedBorderPadding;
|
||||
|
||||
nsMargin m = GetButtonOuterFocusBorderAndPadding();
|
||||
m += GetButtonInnerFocusMargin();
|
||||
m += GetButtonInnerFocusBorderAndPadding();
|
||||
|
||||
aBorderPadding += m;
|
||||
|
||||
aMetrics.width += m.left + m.right;
|
||||
aMetrics.height += m.top + m.bottom;
|
||||
|
||||
aMetrics.ascent = aMetrics.height;
|
||||
aMetrics.descent = 0;
|
||||
|
||||
// printf("requested width='%d' height='%d'\n",aMetrics.width, aMetrics.height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,18 +33,9 @@
|
||||
class nsButtonFrameRenderer {
|
||||
public:
|
||||
|
||||
enum ButtonState {
|
||||
active,
|
||||
hover,
|
||||
normal
|
||||
};
|
||||
nsButtonFrameRenderer();
|
||||
virtual ~nsButtonFrameRenderer();
|
||||
|
||||
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
|
||||
virtual void PaintButton(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
@@ -67,15 +58,10 @@ public:
|
||||
virtual void SetNameSpace(PRInt32 aNameSpace);
|
||||
virtual void SetFrame(nsFrame* aFrame, nsIPresContext& aPresContext);
|
||||
|
||||
virtual void SetActive(PRBool aActive, PRBool notify);
|
||||
virtual void SetHover(PRBool aHover, PRBool notify);
|
||||
virtual void SetFocus(PRBool aFocus, PRBool notify);
|
||||
virtual void SetDisabled(PRBool aDisabled, PRBool notify);
|
||||
|
||||
PRBool isActive();
|
||||
PRBool isHover();
|
||||
PRBool isDisabled();
|
||||
PRBool isFocus();
|
||||
|
||||
virtual void GetButtonOutlineRect(const nsRect& aRect, nsRect& aResult);
|
||||
virtual void GetButtonOuterFocusRect(const nsRect& aRect, nsRect& aResult);
|
||||
@@ -92,25 +78,10 @@ public:
|
||||
|
||||
virtual void ReResolveStyles(nsIPresContext& aPresContext);
|
||||
|
||||
/**
|
||||
* Subroutine to add in borders and padding
|
||||
*/
|
||||
virtual void AddFocusBordersAndPadding(nsIPresContext& aPresContext,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
nsMargin& aBorderPadding);
|
||||
|
||||
virtual void Redraw();
|
||||
|
||||
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:
|
||||
|
||||
// cached styles for focus and outline.
|
||||
|
||||
@@ -571,6 +571,15 @@ NS_METHOD nsFormControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
}
|
||||
}
|
||||
|
||||
// lets see if the button was clicked. -EDV
|
||||
switch (aEvent->message) {
|
||||
case NS_MOUSE_LEFT_CLICK:
|
||||
MouseClicked(&aPresContext);
|
||||
break;
|
||||
}
|
||||
|
||||
/* All this this now done internally in Gecko.
|
||||
|
||||
//printf(" %d %d %d %d (%d,%d) \n", this, aEvent->widget, aEvent->widgetSupports,
|
||||
// aEvent->message, aEvent->point.x, aEvent->point.y);
|
||||
|
||||
@@ -608,6 +617,7 @@ NS_METHOD nsFormControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
}
|
||||
break;
|
||||
}
|
||||
*/
|
||||
aEventStatus = nsEventStatus_eConsumeDoDefault;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,6 @@ nsHTMLButtonControlFrame::MouseClicked(nsIPresContext* aPresContext)
|
||||
void
|
||||
nsHTMLButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
||||
{
|
||||
mRenderer.SetFocus(aOn, aRepaint);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -293,49 +292,20 @@ nsHTMLButtonControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
nsWidgetRendering mode;
|
||||
aPresContext.GetWidgetRenderingMode(&mode);
|
||||
|
||||
// if disabled do nothing
|
||||
if (mRenderer.isDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult result = mRenderer.HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
if (NS_OK != result)
|
||||
return result;
|
||||
|
||||
aEventStatus = nsEventStatus_eIgnore;
|
||||
|
||||
// lets see if the button was clicked. -EDV
|
||||
switch (aEvent->message) {
|
||||
|
||||
case NS_MOUSE_ENTER:
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
mRenderer.SetFocus(PR_TRUE, PR_TRUE);
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
if (mRenderer.isHover())
|
||||
MouseClicked(&aPresContext);
|
||||
break;
|
||||
|
||||
case NS_KEY_DOWN:
|
||||
if (NS_KEY_EVENT == aEvent->eventStructType) {
|
||||
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
|
||||
if (NS_VK_SPACE == keyEvent->keyCode) {
|
||||
MouseClicked(&aPresContext);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NS_MOUSE_EXIT:
|
||||
break;
|
||||
case NS_MOUSE_LEFT_CLICK:
|
||||
MouseClicked(&aPresContext);
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
// we don't want our children to get any events. So just pass it to frame.
|
||||
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -460,7 +460,7 @@ input[type="submit"] {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="submit"][pseudoclass~="active"] {
|
||||
input[type="submit"]:active {
|
||||
border-style: inset;
|
||||
|
||||
padding-left: 2px;
|
||||
@@ -469,11 +469,11 @@ input[type="submit"][pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
input[type="submit"][pseudoclass~="active"]:-moz-outline {
|
||||
input[type="submit"]:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
input[type="submit"][pseudoclass~="hover"]:-moz-outline {
|
||||
input[type="submit"]:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -481,6 +481,11 @@ input[type="submit"][disabled] {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
input[type="submit"][disabled]:active {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
|
||||
input[type="submit"]:-moz-focus-inner {
|
||||
padding-left : 2px;
|
||||
padding-right : 2px;
|
||||
@@ -489,7 +494,7 @@ input[type="submit"]:-moz-focus-inner {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
input[type="submit"][pseudoclass~="focus"]:-moz-focus-inner {
|
||||
input[type="submit"]:focus:-moz-focus-inner {
|
||||
padding-left : 1px;
|
||||
padding-right : 1px;
|
||||
padding-top : 0px;
|
||||
@@ -507,7 +512,7 @@ input[type="reset"] {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="reset"][pseudoclass~="active"] {
|
||||
input[type="reset"]:active {
|
||||
border-style: inset;
|
||||
|
||||
padding-left: 2px;
|
||||
@@ -516,11 +521,11 @@ input[type="reset"][pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
input[type="reset"][pseudoclass~="active"]:-moz-outline {
|
||||
input[type="reset"]:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
input[type="reset"][pseudoclass~="hover"]:-moz-outline {
|
||||
input[type="reset"]:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -528,6 +533,10 @@ input[type="reset"][disabled] {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
input[type="reset"][disabled]:active {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="reset"]:-moz-focus-inner {
|
||||
padding-left : 2px;
|
||||
padding-right : 2px;
|
||||
@@ -536,7 +545,7 @@ input[type="reset"]:-moz-focus-inner {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
input[type="reset"][pseudoclass~="focus"]:-moz-focus-inner {
|
||||
input[type="reset"]:focus:-moz-focus-inner {
|
||||
padding-left : 1px;
|
||||
padding-right : 1px;
|
||||
padding-top : 0px;
|
||||
@@ -554,7 +563,7 @@ input[type="button"] {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="button"][pseudoclass~="active"] {
|
||||
input[type="button"]:active {
|
||||
border-style: inset;
|
||||
|
||||
padding-left: 2px;
|
||||
@@ -563,11 +572,11 @@ input[type="button"][pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
input[type="button"][pseudoclass~="active"]:-moz-outline {
|
||||
input[type="button"]:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
input[type="button"][pseudoclass~="hover"]:-moz-outline {
|
||||
input[type="button"]:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -575,6 +584,10 @@ input[type="button"][disabled] {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
input[type="button"][disabled]:active {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
input[type="button"]:-moz-focus-inner {
|
||||
padding-left : 2px;
|
||||
padding-right : 2px;
|
||||
@@ -583,7 +596,7 @@ input[type="button"]:-moz-focus-inner {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
input[type="button"][pseudoclass~="focus"]:-moz-focus-inner {
|
||||
input[type="button"]:focus:-moz-focus-inner {
|
||||
padding-left : 1px;
|
||||
padding-right : 1px;
|
||||
padding-top : 0px;
|
||||
@@ -606,7 +619,7 @@ button {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
button[pseudoclass~="active"] {
|
||||
button:active {
|
||||
border-style: inset;
|
||||
|
||||
padding-left: 2px;
|
||||
@@ -615,14 +628,14 @@ button[pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
button[pseudoclass~="hover"] {
|
||||
button:hover {
|
||||
}
|
||||
|
||||
button[pseudoclass~="active"]:-moz-outline {
|
||||
button:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
button[pseudoclass~="hover"]:-moz-outline {
|
||||
button:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -630,6 +643,10 @@ button[disabled] {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
button[disabled]:active {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
button:-moz-focus-inner {
|
||||
padding-left : 2px;
|
||||
padding-right : 2px;
|
||||
@@ -638,7 +655,7 @@ button:-moz-focus-inner {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
button[pseudoclass~="focus"]:-moz-focus-inner {
|
||||
button:focus:-moz-focus-inner {
|
||||
padding-left : 1px;
|
||||
padding-right : 1px;
|
||||
padding-top : 0px;
|
||||
|
||||
@@ -889,43 +889,13 @@ nsTitledButtonFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
nsLeafFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
|
||||
// if disabled do nothing
|
||||
if (PR_TRUE == mRenderer.isDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// let the renderer handle the UI stuff
|
||||
mRenderer.HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
|
||||
aEventStatus = nsEventStatus_eIgnore;
|
||||
|
||||
switch (aEvent->message) {
|
||||
|
||||
case NS_MOUSE_ENTER:
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
mRenderer.SetFocus(PR_TRUE, PR_TRUE);
|
||||
break;
|
||||
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
break;
|
||||
|
||||
case NS_MOUSE_EXIT:
|
||||
break;
|
||||
|
||||
case NS_MOUSE_MOVE:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//aEventStatus = nsEventStatus_eConsumeNoDefault;
|
||||
|
||||
return NS_OK;
|
||||
return nsLeafFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ toolbar#taskbar titledbutton{
|
||||
color:#CCCCFF;
|
||||
}
|
||||
|
||||
toolbar#taskbar titledbutton[pseudoclass~="active"] {
|
||||
toolbar#taskbar titledbutton:active {
|
||||
|
||||
text-decoration:none;
|
||||
border: 1px inset;
|
||||
@@ -65,7 +65,7 @@ toolbar#taskbar titledbutton[pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
toolbar#taskbar titledbutton[pseudoclass~="hover"] {
|
||||
toolbar#taskbar titledbutton:active {
|
||||
border: 1px outset #666699;
|
||||
color:white;
|
||||
//text-decoration:underline;
|
||||
@@ -107,7 +107,7 @@ titledbutton[class=insecure] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
toolbar#taskbar titledbutton[pseudoclass~="active"] {
|
||||
toolbar#taskbar titledbutton:active {
|
||||
|
||||
text-decoration:none;
|
||||
border: 1px inset;
|
||||
|
||||
@@ -119,18 +119,18 @@ toolbar titledbutton {
|
||||
font: 2.5mm sans-serif;
|
||||
}
|
||||
|
||||
toolbar titledbutton[pseudoclass~="hover"] {
|
||||
toolbar titledbutton:hover {
|
||||
border: 1px outset white;
|
||||
color:blue;
|
||||
//text-decoration:underline;
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
toolbar titledbutton[pseudoclass~="hover"]:-moz-outline {
|
||||
toolbar titledbutton:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
toolbar titledbutton[pseudoclass~="active"] {
|
||||
toolbar titledbutton:active {
|
||||
|
||||
text-decoration:none;
|
||||
border: 1px inset;
|
||||
@@ -141,7 +141,7 @@ toolbar titledbutton[pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
toolbar titledbutton[pseudoclass~="active"]:-moz-outline {
|
||||
toolbar titledbutton:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ titledbutton[class=push] {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
titledbutton[class=push][pseudoclass~="active"] {
|
||||
titledbutton[class=push]:active {
|
||||
border-style: inset;
|
||||
|
||||
padding-left: 2px;
|
||||
@@ -171,14 +171,14 @@ titledbutton[class=push][pseudoclass~="active"] {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
titledbutton[class=push][pseudoclass~="hover"] {
|
||||
titledbutton[class=push]:hover {
|
||||
}
|
||||
|
||||
titledbutton[class=push][pseudoclass~="active"]:-moz-outline {
|
||||
titledbutton[class=push]:active:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
titledbutton[class=push][pseudoclass~="hover"]:-moz-outline {
|
||||
titledbutton[class=push]:hover:-moz-outline {
|
||||
border : 1px solid black;
|
||||
}
|
||||
|
||||
@@ -186,6 +186,10 @@ titledbutton[class=push][disabled] {
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
titledbutton[class=push][disabled]:active {
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
titledbutton[class=push]:-moz-focus-inner {
|
||||
padding-left : 2px;
|
||||
padding-right : 2px;
|
||||
@@ -194,7 +198,7 @@ titledbutton[class=push]:-moz-focus-inner {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
titledbutton[class=push][pseudoclass~="focus"]:-moz-focus-inner {
|
||||
titledbutton[class=push]:focus:-moz-focus-inner {
|
||||
padding-left : 1px;
|
||||
padding-right : 1px;
|
||||
padding-top : 0px;
|
||||
@@ -275,7 +279,7 @@ tabcontrol[align="horizontal"] tabpanel + tabbox[align="vertical"] tab {
|
||||
}
|
||||
|
||||
|
||||
tab[pseudoclass~="hover"] {
|
||||
tab:hover {
|
||||
background-color: rgb(230, 207, 206);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user