1999-02-20 09:05:15 +03:00
|
|
|
#include "nsButtonFrameRenderer.h"
|
1999-02-19 21:23:02 +03:00
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsCSSRendering.h"
|
1999-02-26 09:41:10 +03:00
|
|
|
#include "nsIPresContext.h"
|
1999-02-19 21:23:02 +03:00
|
|
|
#include "nsGenericHTMLElement.h"
|
1999-03-06 22:43:13 +03:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
1999-03-13 02:47:52 +03:00
|
|
|
#include "nsHTMLAtoms.h"
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
#define ACTIVE "active"
|
|
|
|
#define HOVER "hover"
|
|
|
|
#define FOCUS "focus"
|
1999-02-26 11:48:24 +03:00
|
|
|
|
1999-02-19 21:23:02 +03:00
|
|
|
nsButtonFrameRenderer::nsButtonFrameRenderer()
|
|
|
|
{
|
|
|
|
mNameSpace = kNameSpaceID_HTML;
|
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsButtonFrameRenderer::~nsButtonFrameRenderer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-02-19 21:23:02 +03:00
|
|
|
void
|
1999-02-26 09:41:10 +03:00
|
|
|
nsButtonFrameRenderer::SetNameSpace(PRInt32 aNameSpace)
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-02-26 09:41:10 +03:00
|
|
|
mNameSpace = aNameSpace;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
1999-03-26 22:39:23 +03:00
|
|
|
nsButtonFrameRenderer::SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext)
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-02-26 09:41:10 +03:00
|
|
|
mFrame = aFrame;
|
1999-02-26 11:48:24 +03:00
|
|
|
ReResolveStyles(aPresContext);
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 11:48:24 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
1999-02-26 11:48:24 +03:00
|
|
|
nsButtonFrameRenderer::SetPseudoClassAttribute(const nsString& value, PRBool notify)
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-02-26 11:48:24 +03:00
|
|
|
// get the content
|
1999-02-26 09:41:10 +03:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mFrame->GetContent(getter_AddRefs(content));
|
1999-02-26 11:48:24 +03:00
|
|
|
|
|
|
|
// create and atom for the pseudo class
|
|
|
|
nsCOMPtr<nsIAtom> atom = do_QueryInterface(NS_NewAtom("pseudoclass"));
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-02-26 11:48:24 +03:00
|
|
|
nsString pseudo = value;
|
|
|
|
// remove whitespace
|
|
|
|
pseudo.Trim(" ");
|
|
|
|
pseudo.CompressWhitespace();
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-02-26 11:48:24 +03:00
|
|
|
// set it
|
|
|
|
content->SetAttribute(mNameSpace, atom, pseudo, notify);
|
|
|
|
|
|
|
|
/*
|
|
|
|
char ch[256];
|
|
|
|
pseudo.ToCString(ch,256);
|
|
|
|
printf("setting pseudo='%s'\n",ch);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-03-06 22:43:13 +03:00
|
|
|
nsButtonFrameRenderer::SetHover(PRBool aHover, PRBool notify)
|
1999-02-26 11:48:24 +03:00
|
|
|
{
|
1999-03-06 22:43:13 +03:00
|
|
|
ToggleClass(aHover, HOVER, notify);
|
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::SetActive(PRBool aActive, PRBool notify)
|
|
|
|
{
|
|
|
|
ToggleClass(aActive, ACTIVE, notify);
|
1999-02-26 11:48:24 +03:00
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-02-26 11:48:24 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::SetFocus(PRBool aFocus, PRBool notify)
|
|
|
|
{
|
|
|
|
ToggleClass(aFocus, FOCUS, notify);
|
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-02-26 11:48:24 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
|
|
|
|
{
|
1999-03-13 02:47:52 +03:00
|
|
|
// get the content
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mFrame->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
if (aDisabled)
|
|
|
|
content->SetAttribute(mNameSpace, nsHTMLAtoms::disabled, "", notify);
|
|
|
|
else
|
|
|
|
content->UnsetAttribute(mNameSpace, nsHTMLAtoms::disabled, notify);
|
|
|
|
|
1999-02-26 11:48:24 +03:00
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
PRBool
|
|
|
|
nsButtonFrameRenderer::isHover()
|
1999-02-26 11:48:24 +03:00
|
|
|
{
|
|
|
|
nsString pseudo = GetPseudoClassAttribute();
|
|
|
|
PRInt32 index = IndexOfClass(pseudo, HOVER);
|
|
|
|
if (index != -1)
|
1999-03-06 22:43:13 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-02-26 11:48:24 +03:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
PRBool
|
|
|
|
nsButtonFrameRenderer::isActive()
|
|
|
|
{
|
|
|
|
nsString pseudo = GetPseudoClassAttribute();
|
|
|
|
PRInt32 index = IndexOfClass(pseudo, ACTIVE);
|
1999-02-26 11:48:24 +03:00
|
|
|
if (index != -1)
|
1999-03-06 22:43:13 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
1999-02-26 11:48:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsButtonFrameRenderer::isDisabled()
|
|
|
|
{
|
1999-03-13 02:47:52 +03:00
|
|
|
// get the content
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
mFrame->GetContent(getter_AddRefs(content));
|
|
|
|
nsString value;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(mNameSpace, nsHTMLAtoms::disabled, value))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
return PR_FALSE;
|
1999-02-26 11:48:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsButtonFrameRenderer::isFocus()
|
|
|
|
{
|
|
|
|
nsString pseudo = GetPseudoClassAttribute();
|
|
|
|
PRInt32 index = IndexOfClass(pseudo, FOCUS);
|
|
|
|
if (index != -1)
|
|
|
|
return PR_TRUE;
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
1999-02-26 11:48:24 +03:00
|
|
|
nsButtonFrameRenderer::ToggleClass(PRBool aValue, const nsString& c, PRBool notify)
|
1999-02-26 09:41:10 +03:00
|
|
|
{
|
1999-02-26 11:48:24 +03:00
|
|
|
// 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);
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 11:48:24 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
1999-02-26 11:48:24 +03:00
|
|
|
nsButtonFrameRenderer::AddClass(nsString& pseudoclass, const nsString newClass)
|
1999-02-26 09:41:10 +03:00
|
|
|
{
|
1999-02-26 11:48:24 +03:00
|
|
|
// see if the class is already there
|
|
|
|
// if not add it
|
|
|
|
|
|
|
|
PRInt32 index = IndexOfClass(pseudoclass, newClass);
|
|
|
|
if (index == -1) {
|
|
|
|
pseudoclass += " ";
|
|
|
|
pseudoclass += newClass;
|
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-26 11:48:24 +03:00
|
|
|
nsButtonFrameRenderer::RemoveClass(nsString& pseudoclass, const nsString newClass)
|
1999-02-26 09:41:10 +03:00
|
|
|
{
|
1999-02-26 11:48:24 +03:00
|
|
|
// 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());
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 11:48:24 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-02-19 21:23:02 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-26 09:41:10 +03:00
|
|
|
nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext,
|
1999-02-19 21:23:02 +03:00
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
|
|
|
{
|
|
|
|
// if disabled do nothing
|
1999-02-26 11:48:24 +03:00
|
|
|
if (PR_TRUE == isDisabled()) {
|
1999-02-19 21:23:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
1999-02-26 09:41:10 +03:00
|
|
|
mFrame->GetContent(getter_AddRefs(content));
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
// get its view
|
|
|
|
nsIView* view = nsnull;
|
1999-03-06 22:43:13 +03:00
|
|
|
mFrame->GetView(&view);
|
1999-02-19 21:23:02 +03:00
|
|
|
nsCOMPtr<nsIViewManager> viewMan;
|
1999-03-06 22:43:13 +03:00
|
|
|
|
|
|
|
if (view)
|
|
|
|
view->GetViewManager(*getter_AddRefs(viewMan));
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
aEventStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
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;
|
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
/*
|
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::Redraw()
|
|
|
|
{
|
|
|
|
nsRect frameRect;
|
|
|
|
mFrame->GetRect(frameRect);
|
|
|
|
nsRect rect(0, 0, frameRect.width, frameRect.height);
|
|
|
|
mFrame->Invalidate(rect, PR_TRUE);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
1999-02-19 21:23:02 +03:00
|
|
|
void
|
1999-02-26 09:41:10 +03:00
|
|
|
nsButtonFrameRenderer::PaintButton (nsIPresContext& aPresContext,
|
1999-02-19 21:23:02 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
const nsRect& aRect)
|
|
|
|
{
|
1999-03-02 08:00:51 +03:00
|
|
|
//printf("painted width='%d' height='%d'\n",aRect.width, aRect.height);
|
1999-03-02 04:25:33 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
// draw the border and background inside the focus and outline borders
|
|
|
|
PaintBorderAndBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
|
|
|
|
|
|
|
// draw the focus and outline borders
|
|
|
|
PaintOutlineAndFocusBorders(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect);
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsIPresContext& aPresContext,
|
1999-02-19 21:23:02 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
const nsRect& aRect)
|
|
|
|
{
|
1999-02-26 09:41:10 +03:00
|
|
|
// once we have all that let draw the focus if we have it. We will need to draw 2 focuses.
|
|
|
|
// the inner and the outer. This is so we can do any kind of look and feel some buttons have
|
|
|
|
// focus on the outside like mac and motif. While others like windows have it inside (dotted line).
|
|
|
|
// Usually only one will be specifed. But I guess you could have both if you wanted to.
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsRect rect;
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-03-26 22:39:23 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer)
|
1999-02-26 09:41:10 +03:00
|
|
|
{
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
if (mOuterFocusStyle) {
|
|
|
|
// ---------- paint the outer focus border -------------
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
GetButtonOuterFocusRect(aRect, rect);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mOuterFocusStyle ->GetStyleData(eStyleStruct_Spacing);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
|
|
|
aDirtyRect, rect, *spacing, mOuterFocusStyle, 0);
|
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
// ---------- paint the inner focus border -------------
|
|
|
|
if (mInnerFocusStyle) {
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
GetButtonInnerFocusRect(aRect, rect);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mInnerFocusStyle ->GetStyleData(eStyleStruct_Spacing);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
|
|
|
aDirtyRect, rect, *spacing, mInnerFocusStyle, 0);
|
|
|
|
}
|
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-03-26 22:39:23 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer)
|
1999-02-26 09:41:10 +03:00
|
|
|
{
|
1999-03-26 22:39:23 +03:00
|
|
|
if /*(mOutlineStyle) */ (PR_FALSE) {
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-03-26 22:39:23 +03:00
|
|
|
GetButtonOutlineRect(aRect, rect);
|
1999-02-26 09:41:10 +03:00
|
|
|
|
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mOutlineStyle ->GetStyleData(eStyleStruct_Spacing);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
// set the clipping area so we can draw outside our bounds.
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
PRBool clipEmpty;
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
|
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
1999-03-26 22:39:23 +03:00
|
|
|
aDirtyRect, rect, *spacing, mOutlineStyle, 0);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
aRenderingContext.PopState(clipEmpty);
|
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::PaintBorderAndBackground(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
const nsRect& aRect)
|
|
|
|
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
|
|
|
|
1999-03-26 03:39:35 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND != aWhichLayer)
|
1999-02-26 09:41:10 +03:00
|
|
|
return;
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
// get the button rect this is inside the focus and outline rects
|
|
|
|
nsRect buttonRect;
|
|
|
|
GetButtonRect(aRect, buttonRect);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsCOMPtr<nsIStyleContext> context;
|
|
|
|
mFrame->GetStyleContext(getter_AddRefs(context));
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
|
|
|
|
// get the styles
|
1999-02-19 21:23:02 +03:00
|
|
|
const nsStyleSpacing* spacing =
|
|
|
|
(const nsStyleSpacing*)context->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
const nsStyleColor* color =
|
|
|
|
(const nsStyleColor*)context->GetStyleData(eStyleStruct_Color);
|
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
// paint the border and background
|
1999-03-06 22:43:13 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, mFrame,
|
|
|
|
aDirtyRect, buttonRect, *color, *spacing, 0, 0);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
|
|
|
aDirtyRect, buttonRect, *spacing, context, 0);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonOutlineRect(const nsRect& aRect, nsRect& outlineRect)
|
|
|
|
{
|
|
|
|
outlineRect = aRect;
|
|
|
|
outlineRect.Inflate(GetButtonOutlineBorderAndPadding());
|
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonOuterFocusRect(const nsRect& aRect, nsRect& focusRect)
|
|
|
|
{
|
|
|
|
focusRect = aRect;
|
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonRect(const nsRect& aRect, nsRect& r)
|
|
|
|
{
|
|
|
|
r = aRect;
|
|
|
|
r.Deflate(GetButtonOuterFocusBorderAndPadding());
|
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusRect(const nsRect& aRect, nsRect& focusRect)
|
|
|
|
{
|
|
|
|
GetButtonRect(aRect, focusRect);
|
|
|
|
focusRect.Deflate(GetButtonBorderAndPadding());
|
|
|
|
focusRect.Deflate(GetButtonInnerFocusMargin());
|
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonContentRect(const nsRect& aRect, nsRect& r)
|
|
|
|
{
|
|
|
|
GetButtonInnerFocusRect(aRect, r);
|
|
|
|
r.Deflate(GetButtonInnerFocusBorderAndPadding());
|
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonOuterFocusBorderAndPadding()
|
|
|
|
{
|
|
|
|
nsMargin focusBorderAndPadding(0,0,0,0);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
if (mOuterFocusStyle) {
|
|
|
|
// get the outer focus border and padding
|
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mOuterFocusStyle ->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
spacing->GetBorderPadding(focusBorderAndPadding);
|
|
|
|
}
|
|
|
|
|
|
|
|
return focusBorderAndPadding;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonBorderAndPadding()
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-02-26 09:41:10 +03:00
|
|
|
nsCOMPtr<nsIStyleContext> context;
|
|
|
|
mFrame->GetStyleContext(getter_AddRefs(context));
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin borderAndPadding(0,0,0,0);
|
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)context ->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
spacing->GetBorderPadding(borderAndPadding);
|
|
|
|
return borderAndPadding;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
/**
|
|
|
|
* Gets the size of the buttons border this is the union of the normal and disabled borders.
|
|
|
|
*/
|
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusMargin()
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin innerFocusMargin(0,0,0,0);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
if (mInnerFocusStyle) {
|
|
|
|
// get the outer focus border and padding
|
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mInnerFocusStyle ->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
spacing->GetMargin(innerFocusMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
return innerFocusMargin;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusBorderAndPadding()
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin innerFocusBorderAndPadding(0,0,0,0);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
if (mInnerFocusStyle) {
|
|
|
|
// get the outer focus border and padding
|
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mInnerFocusStyle ->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
spacing->GetBorderPadding(innerFocusBorderAndPadding);
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
|
|
|
return innerFocusBorderAndPadding;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonOutlineBorderAndPadding()
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin borderAndPadding(0,0,0,0);
|
|
|
|
|
|
|
|
if (mOutlineStyle) {
|
|
|
|
// get the outline border and padding
|
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mOutlineStyle ->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
spacing->GetBorderPadding(borderAndPadding);
|
|
|
|
}
|
|
|
|
|
|
|
|
return borderAndPadding;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetFullButtonBorderAndPadding()
|
|
|
|
{
|
1999-03-26 22:39:23 +03:00
|
|
|
return GetButtonOuterFocusBorderAndPadding() + GetButtonBorderAndPadding() + GetButtonInnerFocusMargin() + GetButtonInnerFocusBorderAndPadding();
|
1999-03-06 22:43:13 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
1999-02-26 11:48:24 +03:00
|
|
|
nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext)
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-02-26 09:41:10 +03:00
|
|
|
// 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
|
|
|
|
nsCOMPtr<nsIAtom> atom (do_QueryInterface(NS_NewAtom(":-moz-outline")));
|
|
|
|
aPresContext.ProbePseudoStyleContextFor(content, atom, context,
|
|
|
|
PR_FALSE,
|
|
|
|
getter_AddRefs(mOutlineStyle));
|
|
|
|
|
|
|
|
|
|
|
|
// style for the inner such as a dotted line (Windows)
|
|
|
|
atom = do_QueryInterface(NS_NewAtom(":-moz-focus-inner"));
|
|
|
|
aPresContext.ProbePseudoStyleContextFor(content, atom, context,
|
|
|
|
PR_FALSE,
|
|
|
|
getter_AddRefs(mInnerFocusStyle));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// style for outer focus like a ridged border (MAC).
|
|
|
|
atom = do_QueryInterface(NS_NewAtom(":-moz-focus-outer"));
|
|
|
|
aPresContext.ProbePseudoStyleContextFor(content, atom, context,
|
|
|
|
PR_FALSE,
|
|
|
|
getter_AddRefs(mOuterFocusStyle));
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-02-19 21:23:02 +03:00
|
|
|
void
|
1999-03-02 04:25:33 +03:00
|
|
|
nsButtonFrameRenderer::AddFocusBordersAndPadding(nsIPresContext& aPresContext,
|
1999-02-26 09:41:10 +03:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
nsMargin& aBorderPadding)
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-03-06 04:48:28 +03:00
|
|
|
aBorderPadding = aReflowState.mComputedBorderPadding;
|
1999-03-06 22:43:13 +03:00
|
|
|
|
|
|
|
nsMargin m = GetButtonOuterFocusBorderAndPadding();
|
|
|
|
m += GetButtonInnerFocusMargin();
|
|
|
|
m += GetButtonInnerFocusBorderAndPadding();
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
aBorderPadding += m;
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
aMetrics.width += m.left + m.right;
|
|
|
|
aMetrics.height += m.top + m.bottom;
|
1999-03-03 07:04:48 +03:00
|
|
|
|
|
|
|
aMetrics.ascent = aMetrics.height;
|
|
|
|
aMetrics.descent = 0;
|
1999-03-02 04:25:33 +03:00
|
|
|
|
1999-03-02 08:00:51 +03:00
|
|
|
// printf("requested width='%d' height='%d'\n",aMetrics.width, aMetrics.height);
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
|