diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 6ce71c9e0e9..2b62b52921c 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -1957,6 +1957,11 @@ nsCSSFrameConstructor::ConstructFrameByTag(nsIPresContext* aPresContext, } else if (nsHTMLAtoms::button == aTag) { rv = NS_NewHTMLButtonControlFrame(newFrame); + // the html4 button needs to act just like a + // regular button except contain html content + // so it must be replaced or html outside it will + // draw into its borders. -EDV + isReplaced = PR_TRUE; processChildren = PR_TRUE; } else if (nsHTMLAtoms::label == aTag) { diff --git a/layout/forms/nsButtonFrameRenderer.cpp b/layout/forms/nsButtonFrameRenderer.cpp index f753a7d347a..e931eaf2b80 100644 --- a/layout/forms/nsButtonFrameRenderer.cpp +++ b/layout/forms/nsButtonFrameRenderer.cpp @@ -3,12 +3,12 @@ #include "nsCSSRendering.h" #include "nsIPresContext.h" #include "nsGenericHTMLElement.h" +#include "nsIView.h" +#include "nsIViewManager.h" -#define ACTIVE "active" -#define HOVER "hover" -#define NORMAL "" -#define FOCUS "focus" -#define ENABLED "enabled" +#define ACTIVE "active" +#define HOVER "hover" +#define FOCUS "focus" #define DISABLED "disabled" nsButtonFrameRenderer::nsButtonFrameRenderer() @@ -83,32 +83,16 @@ nsButtonFrameRenderer::SetPseudoClassAttribute(const nsString& value, PRBool not */ } +void +nsButtonFrameRenderer::SetHover(PRBool aHover, PRBool notify) +{ + ToggleClass(aHover, HOVER, notify); +} void -nsButtonFrameRenderer::SetState(ButtonState state, PRBool notify) +nsButtonFrameRenderer::SetActive(PRBool aActive, 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); + ToggleClass(aActive, ACTIVE, notify); } void @@ -120,35 +104,29 @@ nsButtonFrameRenderer::SetFocus(PRBool aFocus, PRBool notify) void nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify) { - // 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); + ToggleClass(aDisabled, DISABLED, notify); } -nsButtonFrameRenderer::ButtonState -nsButtonFrameRenderer::GetState() +PRBool +nsButtonFrameRenderer::isHover() { nsString pseudo = GetPseudoClassAttribute(); PRInt32 index = IndexOfClass(pseudo, HOVER); if (index != -1) - return hover; + return PR_TRUE; + else + return PR_FALSE; +} - index = IndexOfClass(pseudo, ACTIVE); +PRBool +nsButtonFrameRenderer::isActive() +{ + nsString pseudo = GetPseudoClassAttribute(); + PRInt32 index = IndexOfClass(pseudo, ACTIVE); if (index != -1) - return active; - - return normal; + return PR_TRUE; + else + return PR_FALSE; } PRBool @@ -260,41 +238,47 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext, nsCOMPtr content; mFrame->GetContent(getter_AddRefs(content)); -/* View support has removed because views don't seem to be supporting - Transpancy and the manager isn't supporting event grabbing either. // get its view nsIView* view = nsnull; - GetView(&view); + mFrame->GetView(&view); nsCOMPtr viewMan; - view->GetViewManager(*getter_AddRefs(viewMan)); -*/ + + if (view) + view->GetViewManager(*getter_AddRefs(viewMan)); aEventStatus = nsEventStatus_eIgnore; switch (aEvent->message) { - case NS_MOUSE_ENTER: - SetState(hover, PR_TRUE); - break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - SetState(active, PR_TRUE); - // grab all mouse events - - // PRBool result; - //viewMan->GrabMouseEvents(view,result); - break; + case NS_MOUSE_ENTER: + SetHover(PR_TRUE, PR_TRUE); + break; - case NS_MOUSE_LEFT_BUTTON_UP: - SetState(hover, PR_TRUE); - // stop grabbing mouse events - //viewMan->GrabMouseEvents(nsnull,result); - break; - case NS_MOUSE_EXIT: - SetState(normal, PR_TRUE); - break; - } + case NS_MOUSE_LEFT_BUTTON_DOWN: + SetActive(PR_TRUE, PR_TRUE); + // grab all mouse events - //aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } @@ -416,6 +400,7 @@ nsButtonFrameRenderer::PaintBorderAndBackground(nsIPresContext& aPresContext, // paint the border and background + nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, mFrame, aDirtyRect, buttonRect, *color, *spacing, 0, 0); @@ -534,6 +519,12 @@ nsButtonFrameRenderer::GetButtonOutlineBorderAndPadding() return borderAndPadding; } +nsMargin +nsButtonFrameRenderer::GetFullButtonBorderAndPadding() +{ + return GetButtonOuterFocusBorderAndPadding() + GetButtonBorderAndPadding() + GetButtonInnerFocusMargin() + GetButtonInnerFocusBorderAndPadding(); +} + void nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext) { @@ -573,13 +564,15 @@ nsButtonFrameRenderer::AddFocusBordersAndPadding(nsIPresContext& aPresContext, nsMargin& aBorderPadding) { aBorderPadding = aReflowState.mComputedBorderPadding; + + nsMargin m = GetButtonOuterFocusBorderAndPadding(); + m += GetButtonInnerFocusMargin(); + m += GetButtonInnerFocusBorderAndPadding(); - aBorderPadding += GetButtonOuterFocusBorderAndPadding(); - aBorderPadding += GetButtonInnerFocusMargin(); - aBorderPadding += GetButtonInnerFocusBorderAndPadding(); + aBorderPadding += m; - aMetrics.width += aBorderPadding.left + aBorderPadding.right; - aMetrics.height += aBorderPadding.top + aBorderPadding.bottom; + aMetrics.width += m.left + m.right; + aMetrics.height += m.top + m.bottom; aMetrics.ascent = aMetrics.height; aMetrics.descent = 0; diff --git a/layout/forms/nsButtonFrameRenderer.h b/layout/forms/nsButtonFrameRenderer.h index 6fcd028269e..2076015711b 100644 --- a/layout/forms/nsButtonFrameRenderer.h +++ b/layout/forms/nsButtonFrameRenderer.h @@ -67,11 +67,13 @@ public: virtual void SetNameSpace(PRInt32 aNameSpace); virtual void SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext); - virtual void SetState(ButtonState state, PRBool notify); + 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); - ButtonState GetState(); + PRBool isActive(); + PRBool isHover(); PRBool isDisabled(); PRBool isFocus(); @@ -85,6 +87,7 @@ public: virtual nsMargin GetButtonInnerFocusMargin(); virtual nsMargin GetButtonInnerFocusBorderAndPadding(); virtual nsMargin GetButtonOutlineBorderAndPadding(); + virtual nsMargin GetFullButtonBorderAndPadding(); virtual void ReResolveStyles(nsIPresContext& aPresContext); diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index fd66aeb3119..ba3c2c85b20 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -883,4 +883,10 @@ NS_IMETHODIMP nsComboboxControlFrame::GetProperty(nsIAtom* aName, nsString& aVal return NS_OK; } +nsresult nsComboboxControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + diff --git a/layout/forms/nsComboboxControlFrame.h b/layout/forms/nsComboboxControlFrame.h index 114cf251bf1..5dc5b598987 100644 --- a/layout/forms/nsComboboxControlFrame.h +++ b/layout/forms/nsComboboxControlFrame.h @@ -107,6 +107,10 @@ public: nscoord aInnerWidth, nscoord aCharWidth) const; + + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame); diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp index 1b5b96c3428..c619f43d117 100644 --- a/layout/forms/nsFileControlFrame.cpp +++ b/layout/forms/nsFileControlFrame.cpp @@ -389,6 +389,12 @@ nsFileControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext, return 0; } +nsresult nsFileControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + NS_IMETHODIMP nsFileControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) { diff --git a/layout/forms/nsFileControlFrame.h b/layout/forms/nsFileControlFrame.h index 75a2b1784f6..53846054fdc 100644 --- a/layout/forms/nsFileControlFrame.h +++ b/layout/forms/nsFileControlFrame.h @@ -78,6 +78,9 @@ public: nscoord aInnerWidth, nscoord aCharWidth) const; + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + PRBool HasWidget(); // nsIFormMouseListener diff --git a/layout/forms/nsFormControlHelper.cpp b/layout/forms/nsFormControlHelper.cpp index ae77c16f75f..48a26214394 100644 --- a/layout/forms/nsFormControlHelper.cpp +++ b/layout/forms/nsFormControlHelper.cpp @@ -296,16 +296,25 @@ nsFormControlHelper::CalculateSize (nsIPresContext* aPresContext, } } - // add inside padding if necessary - if (!aWidthExplicit) { - PRInt32 hPadding = (2 * aFrame->GetHorizontalInsidePadding(*aPresContext, p2t, aDesiredSize.width, charWidth)); - aDesiredSize.width += hPadding; - aMinSize.width += hPadding; - } - if (!aHeightExplicit) { - PRInt32 vPadding = (2 * aFrame->GetVerticalInsidePadding(p2t, aRowHeight)); - aDesiredSize.height += vPadding; - aMinSize.height += vPadding; + nsWidgetRendering mode; + aPresContext->GetWidgetRenderingMode(&mode); + + // only add in padding if we are not Gfx + PRBool requiresWidget = PR_FALSE; + + aFrame->RequiresWidget(requiresWidget); + + if (PR_TRUE == requiresWidget || eWidgetRendering_Gfx != mode) { + if (!aWidthExplicit) { + PRInt32 hPadding = (2 * aFrame->GetHorizontalInsidePadding(*aPresContext, p2t, aDesiredSize.width, charWidth)); + aDesiredSize.width += hPadding; + aMinSize.width += hPadding; + } + if (!aHeightExplicit) { + PRInt32 vPadding = (2 * aFrame->GetVerticalInsidePadding(p2t, aRowHeight)); + aDesiredSize.height += vPadding; + aMinSize.height += vPadding; + } } NS_RELEASE(hContent); @@ -328,6 +337,19 @@ nsFormControlHelper::GetFont(nsIFormControlFrame * aFormFrame, { const nsStyleFont* styleFont = (const nsStyleFont*)aStyleContext->GetStyleData(eStyleStruct_Font); + nsWidgetRendering m; + aPresContext->GetWidgetRenderingMode(&m); + + // only add in padding if we are not Gfx + PRBool requiresWidget = PR_FALSE; + + aFormFrame->RequiresWidget(requiresWidget); + + if (PR_TRUE != requiresWidget && eWidgetRendering_Gfx == m) { + aFont = styleFont->mFont; + return; + } + nsCompatibility mode; aPresContext->GetCompatibilityMode(&mode); diff --git a/layout/forms/nsHTMLButtonControlFrame.cpp b/layout/forms/nsHTMLButtonControlFrame.cpp index ec77ef9baca..f6d15684bdf 100644 --- a/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/layout/forms/nsHTMLButtonControlFrame.cpp @@ -46,15 +46,7 @@ #include "nsViewsCID.h" #include "nsColor.h" #include "nsIDocument.h" - -//Enumeration of possible mouse states used to detect mouse clicks -/*enum nsMouseState { - eMouseNone, - eMouseEnter, - eMouseExit, - eMouseDown, - eMouseUp -};*/ +#include "nsButtonFrameRenderer.h" static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID); @@ -67,6 +59,8 @@ class nsHTMLButtonControlFrame : public nsHTMLContainerFrame, public: nsHTMLButtonControlFrame(); + + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD Paint(nsIPresContext& aPresContext, @@ -89,10 +83,24 @@ public: nsIAtom* aListName, nsIFrame* aChildList); + NS_IMETHOD Init(nsIPresContext& aPresContext, + nsIContent* aContent, + nsIFrame* aParent, + nsIStyleContext* aContext, + nsIFrame* asPrevInFlow); + + NS_IMETHOD ReResolveStyleContext ( nsIPresContext* aPresContext, + nsIStyleContext* aParentContext) ; + + + NS_IMETHOD GetFrameName(nsString& aResult) const { return MakeFrameName("ButtonControl", aResult); } + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + virtual PRBool IsSuccessful(nsIFormControlFrame* aSubmitter); NS_IMETHOD GetType(PRInt32* aType) const; NS_IMETHOD GetName(nsString* aName); @@ -126,19 +134,15 @@ public: protected: NS_IMETHOD_(nsrefcnt) AddRef(void); NS_IMETHOD_(nsrefcnt) Release(void); - void AddToPadding(nsIPresContext& aPresContext, nsStyleUnit aStyleUnit, - nscoord aValue, nscoord aLength, nsStyleCoord& aStyleCoord); - void ShiftContents(nsIPresContext& aPresContext, PRBool aDown); void GetTranslatedRect(nsRect& aRect); PRIntn GetSkipSides() const; PRBool mInline; nsFormFrame* mFormFrame; - nsMouseState mLastMouseState; nsCursor mPreviousCursor; - PRBool mGotFocus; nsRect mTranslatedRect; PRBool mDidInit; + nsButtonFrameRenderer mRenderer; }; nsresult @@ -155,11 +159,22 @@ nsHTMLButtonControlFrame::nsHTMLButtonControlFrame() : nsHTMLContainerFrame() { mInline = PR_TRUE; - mLastMouseState = eMouseNone; mPreviousCursor = eCursor_standard; - mGotFocus = PR_FALSE; mTranslatedRect = nsRect(0,0,0,0); mDidInit = PR_FALSE; + mRenderer.SetNameSpace(kNameSpaceID_None); +} + +NS_IMETHODIMP +nsHTMLButtonControlFrame::Init(nsIPresContext& aPresContext, + nsIContent* aContent, + nsIFrame* aParent, + nsIStyleContext* aContext, + nsIFrame* aPrevInFlow) +{ + nsresult rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); + mRenderer.SetFrame(this,aPresContext); + return rv; } nsrefcnt nsHTMLButtonControlFrame::AddRef(void) @@ -335,118 +350,10 @@ nsHTMLButtonControlFrame::MouseClicked(nsIPresContext* aPresContext) } } -#if 0 -// XXX temporary hack code until new style rules are added -static -void ReflowTemp(nsIPresContext& aPresContext, nsHTMLButtonControlFrame* aFrame, nsRect& aRect) -{ - // XXX You can't do this. Incremental reflow commands are dispatched from the - // root frame downward... -#if 0 - nsHTMLReflowMetrics metrics(nsnull); - nsSize size; - aFrame->GetSize(size); - nsIPresShell *shell; - nsIRenderingContext *acx; - shell = aPresContext.GetShell(); - shell->CreateRenderingContext(aFrame, acx); - NS_RELEASE(shell); - nsIReflowCommand* cmd; - nsresult result = NS_NewHTMLReflowCommand(&cmd, aFrame, nsIReflowCommand::ContentChanged); - nsHTMLReflowState state(aPresContext, aFrame, *cmd, size, acx); - //nsHTMLReflowState state(aPresContext, aFrame, eReflowReason_Initial, - // size, acx); - state.reason = eReflowReason_Incremental; - nsReflowStatus status; - nsDidReflowStatus didStatus; - aFrame->WillReflow(aPresContext); - aFrame->Reflow(aPresContext, metrics, state, status); - aFrame->DidReflow(aPresContext, didStatus); - NS_IF_RELEASE(acx); - aFrame->Invalidate(aRect, PR_TRUE); - NS_RELEASE(cmd); -#else - nsIContent* content; - aFrame->GetContent(&content); - if (nsnull != content) { - nsIDocument* document; - - content->GetDocument(document); - document->ContentChanged(content, nsnull); - NS_RELEASE(document); - NS_RELEASE(content); - } -#endif -} -#endif - void nsHTMLButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) { - mGotFocus = aOn; - if (aRepaint) { - nsRect rect(0, 0, mRect.width, mRect.height); - Invalidate(rect, PR_TRUE); - } -} - -// XXX temporary hack code until new style rules are added -void -nsHTMLButtonControlFrame::AddToPadding(nsIPresContext& aPresContext, - nsStyleUnit aStyleUnit, - nscoord aValue, - nscoord aLength, - nsStyleCoord& aStyleCoord) -{ - if (eStyleUnit_Coord == aStyleUnit) { - nscoord coord; - coord = aStyleCoord.GetCoordValue(); - coord += aValue; - aStyleCoord.SetCoordValue(coord); - } else if (eStyleUnit_Percent == aStyleUnit) { - float increment = ((float)aValue) / ((float)aLength); - float percent = aStyleCoord.GetPercentValue(); - percent += increment; - aStyleCoord.SetPercentValue(percent); - } -} - -// XXX temporary hack code until new style rules are added -void -nsHTMLButtonControlFrame::ShiftContents(nsIPresContext& aPresContext, PRBool aDown) -{ - nsStyleSpacing* spacing = - (nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); // cast deliberate - - float p2t; - aPresContext.GetScaledPixelsToTwips(&p2t); - nscoord shift = (aDown) ? NSIntPixelsToTwips(1, p2t) : -NSIntPixelsToTwips(1, p2t); - nsStyleCoord styleCoord; - - // alter the padding so the content shifts down and to the right one pixel - AddToPadding(aPresContext, spacing->mPadding.GetLeftUnit(), shift, mRect.width, - spacing->mPadding.GetLeft(styleCoord)); - spacing->mPadding.SetLeft(styleCoord); - AddToPadding(aPresContext, spacing->mPadding.GetTopUnit(), shift, mRect.height, - spacing->mPadding.GetTop(styleCoord)); - spacing->mPadding.SetTop(styleCoord); - AddToPadding(aPresContext, spacing->mPadding.GetRightUnit(), -shift, mRect.width, - spacing->mPadding.GetRight(styleCoord)); - spacing->mPadding.SetRight(styleCoord); - AddToPadding(aPresContext, spacing->mPadding.GetBottomUnit(), -shift, mRect.height, - spacing->mPadding.GetBottom(styleCoord)); - spacing->mPadding.SetBottom(styleCoord); - - // XXX change the border, border-left, border-right, etc are not working. Instead change inset to outset, vice versa - for (PRInt32 i = 0; i < 4; i++) { - spacing->SetBorderStyle(i,(spacing->GetBorderStyle(i) == NS_STYLE_BORDER_STYLE_INSET) ? - NS_STYLE_BORDER_STYLE_OUTSET : NS_STYLE_BORDER_STYLE_INSET); - } - - mStyleContext->RecalcAutomaticData(&aPresContext); - - //nsRect rect(0, 0, mRect.width, mRect.height); - //ReflowTemp(aPresContext, this, rect); + mRenderer.SetFocus(aOn, aRepaint); } void @@ -465,59 +372,46 @@ nsHTMLButtonControlFrame::GetTranslatedRect(nsRect& aRect) } + NS_IMETHODIMP nsHTMLButtonControlFrame::HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus) { - if (nsFormFrame::GetDisabled(this)) { // XXX cache disabled + 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; - nsIView* view; - GetView(&view); - if (view) { - nsIViewManager* viewMan; - view->GetViewManager(viewMan); - if (viewMan) { - nsIView* grabber; - viewMan->GetMouseEventGrabber(grabber); - if ((grabber == view) || (nsnull == grabber)) { - switch (aEvent->message) { - case NS_MOUSE_ENTER: - //mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "ROLLOVER", PR_TRUE); - if (mLastMouseState == eMouseDown) { - ShiftContents(aPresContext, PR_TRUE); - } - break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - mGotFocus = PR_TRUE; - ShiftContents(aPresContext, PR_TRUE); - mLastMouseState = eMouseDown; - break; - case NS_MOUSE_LEFT_BUTTON_UP: - if (eMouseDown == mLastMouseState) { - if (nsEventStatus_eConsumeNoDefault != aEventStatus) { - ShiftContents(aPresContext, PR_FALSE); - MouseClicked(&aPresContext); - } - mLastMouseState = eMouseUp; - } - break; - case NS_MOUSE_EXIT: - //mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "", PR_TRUE); - if (mLastMouseState == eMouseDown) { - ShiftContents(aPresContext, PR_FALSE); - } - break; - } - aEventStatus = nsEventStatus_eConsumeNoDefault; - NS_RELEASE(viewMan); - } - } + + 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_MOUSE_EXIT: + break; } + return NS_OK; + } @@ -569,40 +463,12 @@ nsHTMLButtonControlFrame::Paint(nsIPresContext& aPresContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) { - nsresult result = nsHTMLContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); - if (NS_FAILED(result)) { - return result; - } - if (eFramePaintLayer_Overlay == aWhichLayer) { - if (mGotFocus) { // draw dashed line to indicate selection, XXX don't calc rect every time - const nsStyleSpacing* spacing = - (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); - nsMargin border; - spacing->CalcBorderFor(this, border); - float p2t; - aPresContext.GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nsRect rect(0, 0, mRect.width, mRect.height); + mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect); + PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); - nsRect outside(0, 0, mRect.width, mRect.height); - outside.Deflate(border); - outside.Deflate(onePixel, onePixel); - - nsRect inside(outside); - inside.Deflate(onePixel, onePixel); - - PRUint8 borderStyles[4]; - nscolor borderColors[4]; - nscolor black = NS_RGB(0,0,0); - for (PRInt32 i = 0; i < 4; i++) { - borderStyles[i] = NS_STYLE_BORDER_STYLE_DOTTED; - borderColors[i] = black; - } - nsCSSRendering::DrawDashedSides(0, aRenderingContext, borderStyles, borderColors, outside, - inside, PR_FALSE, nsnull); - } - } - return result; + return NS_OK; } // XXX a hack until the reflow state does this correctly @@ -640,6 +506,14 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext& aPresContext, { // XXX remove the following when the reflow state is fixed ButtonHack((nsHTMLReflowState&)aReflowState, "html4 button"); + + // commenting this out for now. We need a view to do mouse grabbing but + // it doesn't really seem to work correctly. When you press the only event + // you can get after that is a release. You need mouse enter and exit. + // the view also breaks the outline code. For some reason you can not reset + // the clip rect to draw outside you bounds if you have a view. And you need to + // because the outline must be drawn outside of our bounds according to CSS. -EDV +#if 0 if (!mDidInit) { // create our view, we need a view to grab the mouse nsIView* view; @@ -668,16 +542,13 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext& aPresContext, } mDidInit = PR_TRUE; } +#endif // reflow the child nsIFrame* firstKid = mFrames.FirstChild(); nsSize availSize(aReflowState.computedWidth, aReflowState.computedHeight); - // get border and padding - const nsStyleSpacing* spacing = - (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); - nsMargin borderPadding; - spacing->CalcBorderPaddingFor(this, borderPadding); + nsMargin borderPadding = mRenderer.GetFullButtonBorderAndPadding(); if (NS_INTRINSICSIZE != availSize.width) { availSize.width -= borderPadding.left + borderPadding.right; @@ -781,6 +652,13 @@ nsHTMLButtonControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContex return 0; } +nsresult nsHTMLButtonControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + + NS_IMETHODIMP nsHTMLButtonControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) { return NS_OK; @@ -791,5 +669,29 @@ NS_IMETHODIMP nsHTMLButtonControlFrame::GetProperty(nsIAtom* aName, nsString& aV return NS_OK; } +// +// ReResolveStyleContext +// +// When the style context changes, make sure that all of our styles are still up to date. +// +NS_IMETHODIMP +nsHTMLButtonControlFrame::ReResolveStyleContext ( nsIPresContext* aPresContext, nsIStyleContext* aParentContext) +{ + + nsCOMPtr old ( dont_QueryInterface(mStyleContext) ); + + // this re-resolves |mStyleContext|, so it may change + nsresult rv = nsHTMLContainerFrame::ReResolveStyleContext(aPresContext, aParentContext); + if (NS_FAILED(rv)) { + return rv; + } + + mRenderer.ReResolveStyles(*aPresContext); + + return NS_OK; + +} // ReResolveStyleContext + + diff --git a/layout/forms/nsIFormControlFrame.h b/layout/forms/nsIFormControlFrame.h index 11e0c6adf47..d2c68cd42fb 100644 --- a/layout/forms/nsIFormControlFrame.h +++ b/layout/forms/nsIFormControlFrame.h @@ -67,6 +67,16 @@ public: nscoord aInnerWidth, nscoord aCharWidth) const = 0; + /** + * Determine if the control uses a native widget for rendering + * @param aRequiresWidget is set to PR_TRUE if it has a native widget, PR_FALSE otherwise. + * @returns NS_OK + */ + + virtual nsresult RequiresWidget(PRBool &aRequiresWidget) = 0; + + + NS_IMETHOD GetFont(nsIPresContext* aPresContext, nsFont& aFont) = 0; /** @@ -95,6 +105,8 @@ public: NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue) = 0; + + }; #endif diff --git a/layout/forms/nsImageControlFrame.cpp b/layout/forms/nsImageControlFrame.cpp index 1e52a528928..5cb3105d4de 100644 --- a/layout/forms/nsImageControlFrame.cpp +++ b/layout/forms/nsImageControlFrame.cpp @@ -105,6 +105,10 @@ public: float aPixToTwip, nscoord aInnerWidth, nscoord aCharWidth) const; + + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + // nsIFormControlFrame NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); @@ -400,6 +404,13 @@ nsImageControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext, return 0; } +nsresult nsImageControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + + NS_IMETHODIMP nsImageControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) { return NS_OK; diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index d3a5064fc5e..70ee313b3d4 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -1621,6 +1621,14 @@ NS_IMETHODIMP nsListControlFrame::GetProperty(nsIAtom* aName, nsString& aValue) return NS_OK; } +nsresult nsListControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + + + #if 0 //---------------------------------------------------------------------- diff --git a/layout/forms/nsListControlFrame.h b/layout/forms/nsListControlFrame.h index 87de183a500..738817b089c 100644 --- a/layout/forms/nsListControlFrame.h +++ b/layout/forms/nsListControlFrame.h @@ -180,6 +180,9 @@ public: nscoord aInnerWidth, nscoord aCharWidth) const; + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + NS_IMETHOD GetFont(nsIPresContext* aPresContext, nsFont& aFont); diff --git a/layout/html/document/src/ua.css b/layout/html/document/src/ua.css index 679d1bbb45d..6e6aef687a9 100644 --- a/layout/html/document/src/ua.css +++ b/layout/html/document/src/ua.css @@ -33,58 +33,74 @@ frameset { p { display: block; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } address { display: block; font-style: italic; + margin-bottom: 0; + margin-top: 0; } blockquote { display: block; - margin-left: 1em 40px; + margin-left: 40px; + margin-right: 40px; + margin-top: auto; + margin-bottom: auto; } center { display: block; text-align: center; + margin-bottom: 0; + margin-top: 0; } div { display: block; + margin-bottom: 0; + margin-top: 0; } h1 { display: block; font-size: xx-large; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h2 { display: block; font-size: x-large; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h3 { display: block; font-size: large; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h4 { display: block; font-size: medium; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h5 { display: block; font-size: small; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h6 { display: block; font-size: x-small; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } layer { display: block; @@ -95,17 +111,20 @@ listing { font-family: monospace; font-size: medium; white-space: pre; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } plaintext, xmp, pre { display: block; font-family: monospace; white-space: pre; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } multicol { display: block; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } /* tables */ @@ -297,14 +316,20 @@ fieldset { ul, menu, dir { display: block; + margin-right: 0; + margin-bottom: auto; + margin-top: auto; list-style-type: disc; - margin: 1em 0 1em 40px; + margin-left: 40px; } ol { display: block; + margin-right: 0; + margin-bottom: auto; + margin-top: auto; list-style-type: decimal; - margin: 1em 0 1em 40px; + margin-left: 40px; } li { @@ -356,7 +381,8 @@ dir ol dir, dir ul dir, dir menu dir, dir dir dir dl { display: block; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } dt { display: block; @@ -373,6 +399,9 @@ embed { } hr { display: block; + margin-top: 0; + margin-bottom: 0; + text-align: center; border: 1px -moz-bg-inset; } br { @@ -407,6 +436,7 @@ input[type=radio] { width:12px; height:12px; } + input[type=checkbox] { border: 2px inset rgb(192, 192, 192); width:11px; @@ -415,51 +445,202 @@ input[type=checkbox] { color:black; } -input[type=button] { - border: 2px outset rgb(192, 192, 192); - color:black; - background-color: rgb(192, 192, 192); +input[type="submit"] { + border: 2px outset rgb(156, 154, 156); + background-color: rgb(206, 207, 206); + color:black; + + padding: 1px; } -input[type=submit] { - border: 1px outset rgb(156, 154, 156); - background-color:rgb(206, 207, 206); - color:black; +input[type="submit"][pseudoclass~="active"] { + border-style: inset; + + padding-left: 2px; + padding-right: 0px; + padding-top: 2px; + padding-bottom: 0px; } -input[type=submit].rollover { +input[type="submit"][pseudoclass~="active"]:-moz-outline { + border : 1px solid black; } -input[type=submit].pressed { - border-style : inset; +input[type="submit"][pseudoclass~="hover"]:-moz-outline { + border : 1px solid black; } -input[type=submit].disabled { - border-style : solid; +input[type="submit"][pseudoclass~="disabled"] { + border-style: solid; +} + +input[type="submit"]:-moz-focus-inner { + padding-left : 2px; + padding-right : 2px; + padding-top : 1px; + padding-bottom: 1px; + margin: 0px; +} + +input[type="submit"][pseudoclass~="focus"]:-moz-focus-inner { + padding-left : 1px; + padding-right : 1px; + padding-top : 0px; + padding-bottom: 0px; + + margin: 0px; + border : 1px dotted black; +} + +input[type="reset"] { + border: 2px outset rgb(156, 154, 156); + background-color: rgb(206, 207, 206); + color:black; + + padding: 1px; +} + +input[type="reset"][pseudoclass~="active"] { + border-style: inset; + + padding-left: 2px; + padding-right: 0px; + padding-top: 2px; + padding-bottom: 0px; +} + +input[type="reset"][pseudoclass~="active"]:-moz-outline { + border : 1px solid black; +} + +input[type="reset"][pseudoclass~="hover"]:-moz-outline { + border : 1px solid black; +} + +input[type="reset"][pseudoclass~="disabled"] { + border-style: solid; +} + +input[type="reset"]:-moz-focus-inner { + padding-left : 2px; + padding-right : 2px; + padding-top : 1px; + padding-bottom: 1px; + margin: 0px; +} + +input[type="reset"][pseudoclass~="focus"]:-moz-focus-inner { + padding-left : 1px; + padding-right : 1px; + padding-top : 0px; + padding-bottom: 0px; + + margin: 0px; + border : 1px dotted black; +} + +input[type="button"] { + border: 2px outset rgb(156, 154, 156); + background-color: rgb(206, 207, 206); + color:black; + + padding: 1px; +} + +input[type="button"][pseudoclass~="active"] { + border-style: inset; + + padding-left: 2px; + padding-right: 0px; + padding-top: 2px; + padding-bottom: 0px; + + background-color: rgb(220, 207, 206); +} + +input[type="button"][pseudoclass~="active"]:-moz-outline { + border : 1px solid black; +} + +input[type="button"][pseudoclass~="hover"]:-moz-outline { + border : 1px solid black; +} + +input[type="button"][pseudoclass~="disabled"] { + border-style: solid; +} + +input[type="button"]:-moz-focus-inner { + padding-left : 2px; + padding-right : 2px; + padding-top : 1px; + padding-bottom: 1px; + margin: 0px; +} + +input[type="button"][pseudoclass~="focus"]:-moz-focus-inner { + padding-left : 1px; + padding-right : 1px; + padding-top : 0px; + padding-bottom: 0px; + + margin: 0px; + border : 1px dotted black; } -input[type=reset] { - border: 1px outset rgb(156, 154, 156); - background-color:rgb(206, 207, 206); - color:black; +button { + display: inline; + vertical-align: bottom; + cursor: default; + + border: 2px outset rgb(156, 154, 156); + background-color: rgb(206, 207, 206); + color:black; + + padding: 1px; } -input[type=reset].rollover { +button[pseudoclass~="active"] { + border-style: inset; + + padding-left: 2px; + padding-right: 0px; + padding-top: 2px; + padding-bottom: 0px; } -input[type=reset].pressed { - border-style : inset; +button[pseudoclass~="hover"] { } -input[type=reset].disabled { - border-style : solid; +button[pseudoclass~="active"]:-moz-outline { + border : 1px solid black; } -input[type=file] { - border: 1px outset rgb(156, 154, 156); - background-color:rgb(206, 207, 206); - color:black; +button[pseudoclass~="hover"]:-moz-outline { + border : 1px solid black; +} + +button[pseudoclass~="disabled"] { + border-style: solid; +} + +button:-moz-focus-inner { + padding-left : 2px; + padding-right : 2px; + padding-top : 1px; + padding-bottom: 1px; + margin: 0px; +} + +button[pseudoclass~="focus"]:-moz-focus-inner { + padding-left : 1px; + padding-right : 1px; + padding-top : 0px; + padding-bottom: 0px; + + margin: 0px; + border : 1px dotted black; } :-moz-file-button { @@ -470,40 +651,20 @@ input[type=file] { :-moz-file-text { border: 2px inset rgb(192, 192, 192); - margin-right: 10px; + margin-right:10px; background-color: white; color: black; } -input[type=file].rollover { -} - -input[type=file].pressed { - border-style : inset; -} - -input[type=file].disabled { - border-style : solid; -} - - -:button-outline { - border: 1px solid black; -} - -:button-focus { - border: 2px solid salmon; -} - input[type=text] { border: 2px inset rgb(192, 192, 192); - margin-right: 10px; + margin-right:10px; background-color: white; color: black; } input[type=password] { border: 2px inset rgb(192, 192, 192); - margin-right: 10px; + margin-right:10px; background-color: white; color:black; } @@ -516,29 +677,7 @@ label { padding-left: 3px; padding-right: 3px; } -button { - display: inline; - vertical-align: bottom; - cursor: default; -} -button { - display: inline; - vertical-align: bottom; - /*background-color: white; */ - /*border: 3px outset gray;*/ - /*padding: 3px;*/ - background-color: rgb(192,192,192); - border: 2px solid rgb(192,192,192); - padding: 2px; - cursor: default; -} -button.rollover { - border: 2px outset rgb(192,192,192); -} -button.disabled { - border: 2px solid rgb(192,192,192); - color: rgb(225,225,225); -} + select { vertical-align: bottom; border: 1px inset #c0c0c0; @@ -660,7 +799,6 @@ param { /* XXX Temporary until @page is supported... */ :-moz-page { background: none; - display: block; } :root { diff --git a/layout/html/forms/public/nsIFormControlFrame.h b/layout/html/forms/public/nsIFormControlFrame.h index 11e0c6adf47..d2c68cd42fb 100644 --- a/layout/html/forms/public/nsIFormControlFrame.h +++ b/layout/html/forms/public/nsIFormControlFrame.h @@ -67,6 +67,16 @@ public: nscoord aInnerWidth, nscoord aCharWidth) const = 0; + /** + * Determine if the control uses a native widget for rendering + * @param aRequiresWidget is set to PR_TRUE if it has a native widget, PR_FALSE otherwise. + * @returns NS_OK + */ + + virtual nsresult RequiresWidget(PRBool &aRequiresWidget) = 0; + + + NS_IMETHOD GetFont(nsIPresContext* aPresContext, nsFont& aFont) = 0; /** @@ -95,6 +105,8 @@ public: NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue) = 0; + + }; #endif diff --git a/layout/html/forms/src/nsButtonControlFrame.cpp b/layout/html/forms/src/nsButtonControlFrame.cpp index 8b327fbd83f..67b4f02caa1 100644 --- a/layout/html/forms/src/nsButtonControlFrame.cpp +++ b/layout/html/forms/src/nsButtonControlFrame.cpp @@ -54,6 +54,23 @@ static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID); static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); +nsButtonControlFrame::nsButtonControlFrame() +{ + mRenderer.SetNameSpace(kNameSpaceID_None); +} + +NS_IMETHODIMP +nsButtonControlFrame::Init(nsIPresContext& aPresContext, + nsIContent* aContent, + nsIFrame* aParent, + nsIStyleContext* aContext, + nsIFrame* aPrevInFlow) +{ + nsresult rv = nsFormControlFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); + mRenderer.SetFrame(this,aPresContext); + return rv; +} + void nsButtonControlFrame::GetDefaultLabel(nsString& aString) { @@ -124,14 +141,6 @@ nsButtonControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, } } -nsButtonControlFrame::nsButtonControlFrame() -{ - // Initialize GFX-rendered state - mPressed = PR_FALSE; - mGotFocus = PR_FALSE; - mDisabled = PR_FALSE; -} - nsresult NS_NewButtonControlFrame(nsIFrame*& aResult) { @@ -193,6 +202,30 @@ nsButtonControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext, } } +// +// ReResolveStyleContext +// +// When the style context changes, make sure that all of our styles are still up to date. +// +NS_IMETHODIMP +nsButtonControlFrame::ReResolveStyleContext ( nsIPresContext* aPresContext, nsIStyleContext* aParentContext) +{ + + nsCOMPtr old ( dont_QueryInterface(mStyleContext) ); + + // this re-resolves |mStyleContext|, so it may change + nsresult rv = nsFrame::ReResolveStyleContext(aPresContext, aParentContext); + if (NS_FAILED(rv)) { + return rv; + } + + mRenderer.ReResolveStyles(*aPresContext); + + return NS_OK; + +} // ReResolveStyleContext + + NS_IMETHODIMP nsButtonControlFrame::AttributeChanged(nsIPresContext* aPresContext, @@ -231,16 +264,41 @@ nsButtonControlFrame::Paint(nsIPresContext& aPresContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) { - if (eFramePaintLayer_Content == aWhichLayer) { - nsString label; - nsresult result = GetValue(&label); - - if (NS_CONTENT_ATTR_HAS_VALUE != result) { - GetDefaultLabel(label); - } nsRect rect(0, 0, mRect.width, mRect.height); - PaintButton(aPresContext, aRenderingContext, aDirtyRect, label, rect); - } + mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect); + + if (eFramePaintLayer_Content == aWhichLayer) { + nsString label; + nsresult result = GetValue(&label); + + if (NS_CONTENT_ATTR_HAS_VALUE != result) { + GetDefaultLabel(label); + } + + nsRect content; + mRenderer.GetButtonContentRect(rect,content); + + // paint the title + const nsStyleFont* fontStyle = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font); + const nsStyleColor* colorStyle = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); + + aRenderingContext.SetFont(fontStyle->mFont); + + // if disabled paint + if (PR_TRUE == mRenderer.isDisabled()) + { + float p2t; + aPresContext.GetScaledPixelsToTwips(&p2t); + nscoord pixel = NSIntPixelsToTwips(1, p2t); + + aRenderingContext.SetColor(NS_RGB(255,255,255)); + aRenderingContext.DrawString(label, content.x + pixel, content.y+ pixel); + } + + aRenderingContext.SetColor(colorStyle->mColor); + aRenderingContext.DrawString(label, content.x, content.y); + } + return NS_OK; } @@ -294,11 +352,16 @@ nsButtonControlFrame::Reflow(nsIPresContext& aPresContext, PRInt32 type; GetType(&type); - if (NS_FORM_INPUT_IMAGE == type) { + nsWidgetRendering mode; + aPresContext.GetWidgetRenderingMode(&mode); + + if (eWidgetRendering_Gfx == mode || NS_FORM_INPUT_IMAGE == type) { nsSize ignore; GetDesiredSize(&aPresContext, aReflowState, aDesiredSize, ignore); - nsMargin bp; + nsMargin bp(0,0,0,0); AddBordersAndPadding(&aPresContext, aReflowState, aDesiredSize, bp); + mRenderer.AddFocusBordersAndPadding(aPresContext, aReflowState, aDesiredSize, bp); + if (nsnull != aDesiredSize.maxElementSize) { aDesiredSize.AddBorderPaddingToMaxElementSize(bp); } @@ -319,23 +382,12 @@ nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext, PRInt32 type; GetType(&type); - nsWidgetRendering mode; - aPresContext->GetWidgetRenderingMode(&mode); - if (NS_FORM_INPUT_HIDDEN == type) { // there is no physical rep aDesiredLayoutSize.width = 0; aDesiredLayoutSize.height = 0; aDesiredLayoutSize.ascent = 0; aDesiredLayoutSize.descent = 0; } else { - nsMargin outlineBorder; - if (eWidgetRendering_Gfx == mode) { - nsCOMPtr outlineStyle( dont_QueryInterface(mStyleContext)); - nsCOMPtr sbAtom ( dont_QueryInterface(NS_NewAtom(":button-outline")) ); - aPresContext->ProbePseudoStyleContextFor(mContent, sbAtom, mStyleContext, PR_FALSE, getter_AddRefs(outlineStyle)); - const nsStyleSpacing* outline = (const nsStyleSpacing*)outlineStyle->GetStyleData(eStyleStruct_Spacing); - outline->CalcBorderFor(this, outlineBorder); - } nsSize styleSize; GetStyleSize(*aPresContext, aReflowState, styleSize); // a browse button shares its style context with its parent nsInputFile @@ -352,7 +404,7 @@ nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext, nsInputDimensionSpec spec(nsHTMLAtoms::size, PR_TRUE, nsHTMLAtoms::value, &defaultLabel, 1, PR_FALSE, nsnull, 1); nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize, - spec, desiredSize, minSize, widthExplicit, heightExplicit, ignore); + spec, desiredSize, minSize, widthExplicit, heightExplicit, ignore); // set desired size, max element size aDesiredLayoutSize.width = desiredSize.width; @@ -361,16 +413,6 @@ nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext, aDesiredLayoutSize.maxElementSize->width = minSize.width; aDesiredLayoutSize.maxElementSize->height = minSize.height; } - if (eWidgetRendering_Gfx == mode) { - nscoord horOutline = outlineBorder.left + outlineBorder.right; - nscoord verOutline = outlineBorder.top + outlineBorder.bottom; - aDesiredLayoutSize.width += horOutline; - aDesiredLayoutSize.height += verOutline; - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->width += horOutline; - aDesiredLayoutSize.maxElementSize->height += verOutline; - } - } } aDesiredWidgetSize.width = aDesiredLayoutSize.width; @@ -428,41 +470,7 @@ nsButtonControlFrame::PaintButton(nsIPresContext& aPresContext, const nsRect& aDirtyRect, nsString& aLabel, const nsRect& aRect) { - PRBool disabled = nsFormFrame::GetDisabled(this); - if ( disabled != mDisabled) - { - if (disabled) - mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "DISABLED", PR_TRUE); - else - mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "", PR_TRUE); - - mDisabled = disabled; - } - - //nsIStyleContext* kidSC; - - nsCOMPtr outlineStyle( dont_QueryInterface(mStyleContext) ); - nsCOMPtr outlineAtom ( dont_QueryInterface(NS_NewAtom(":button-outline")) ); - aPresContext.ProbePseudoStyleContextFor(mContent, outlineAtom, mStyleContext, - PR_FALSE, - getter_AddRefs(outlineStyle)); - - nsCOMPtr focusStyle( dont_QueryInterface(mStyleContext) ); - nsCOMPtr focusAtom ( dont_QueryInterface(NS_NewAtom(":button-focus")) ); - aPresContext.ProbePseudoStyleContextFor(mContent, focusAtom, mStyleContext, - PR_FALSE, - getter_AddRefs(focusStyle)); - - nsFormControlHelper::PaintRectangularButton(aPresContext, - aRenderingContext, - aDirtyRect, aRect, - mPressed && mInside, mGotFocus, - nsFormFrame::GetDisabled(this), - mInside, - outlineStyle, - focusStyle, - mStyleContext, aLabel, this); - + } NS_IMETHODIMP @@ -478,70 +486,34 @@ nsButtonControlFrame::HandleEvent(nsIPresContext& aPresContext, } // if disabled do nothing - if (nsFormFrame::GetDisabled(this)) { + if (mRenderer.isDisabled()) { return NS_OK; } - // get parent with view - nsIFrame *frame = nsnull; - - GetParentWithView(&frame); - if (!frame) - return NS_OK; - - // get its view - nsIView* view = nsnull; - frame->GetView(&view); - nsCOMPtr viewMan; - view->GetViewManager(*getter_AddRefs(viewMan)); - + nsresult result = mRenderer.HandleEvent(aPresContext, aEvent, aEventStatus); + if (NS_OK != result) + return result; + aEventStatus = nsEventStatus_eIgnore; - nsresult result = NS_OK; switch (aEvent->message) { - case NS_MOUSE_ENTER: - mInside = PR_TRUE; - if (mPressed) - mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "PRESSED", PR_TRUE); - else - mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "ROLLOVER", PR_TRUE); - break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - mGotFocus = PR_TRUE; - mPressed = PR_TRUE; - mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "PRESSED", PR_TRUE); + case NS_MOUSE_ENTER: + break; + + case NS_MOUSE_LEFT_BUTTON_DOWN: + mRenderer.SetFocus(PR_TRUE, PR_TRUE); + break; - // grab all mouse events - - PRBool result; - viewMan->GrabMouseEvents(view,result); - break; - - case NS_MOUSE_LEFT_BUTTON_UP: - mPressed = PR_FALSE; - mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "", PR_TRUE); - - // stop grabbing mouse events - viewMan->GrabMouseEvents(nsnull,result); - - if (mInside) + case NS_MOUSE_LEFT_BUTTON_UP: + if (mRenderer.isHover()) MouseClicked(&aPresContext); + break; - break; - case NS_MOUSE_EXIT: - mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "", PR_TRUE); - mInside = PR_FALSE; - - // KLUDGE make is false when you exit because grabbing mouse events doesn't - // seem to work. If it did we would know when the mouse was released outside of - // us. And we could set this to false. - mPressed = PR_FALSE; - break; + case NS_MOUSE_EXIT: + break; } - aEventStatus = nsEventStatus_eConsumeNoDefault; - return NS_OK; } @@ -549,9 +521,7 @@ nsButtonControlFrame::HandleEvent(nsIPresContext& aPresContext, void nsButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) { - mGotFocus = aOn; - if (aRepaint) - Redraw(); + mRenderer.SetFocus(aOn, aRepaint); } void diff --git a/layout/html/forms/src/nsButtonControlFrame.h b/layout/html/forms/src/nsButtonControlFrame.h index 03a01c01d2c..b2be923fe44 100644 --- a/layout/html/forms/src/nsButtonControlFrame.h +++ b/layout/html/forms/src/nsButtonControlFrame.h @@ -20,6 +20,7 @@ #define nsButtonControlFrame_h___ #include "nsFormControlFrame.h" +#include "nsButtonFrameRenderer.h" class nsButtonControlFrame : public nsFormControlFrame { public: @@ -47,6 +48,15 @@ public: nsIAtom* aAttribute, PRInt32 aHint); + NS_IMETHOD Init(nsIPresContext& aPresContext, + nsIContent* aContent, + nsIFrame* aParent, + nsIStyleContext* aContext, + nsIFrame* asPrevInFlow); + + NS_IMETHOD ReResolveStyleContext ( nsIPresContext* aPresContext, + nsIStyleContext* aParentContext) ; + NS_IMETHOD GetFrameName(nsString& aResult) const; virtual void PostCreateWidget(nsIPresContext* aPresContext, @@ -104,13 +114,7 @@ protected: nsIFormControlFrame* mMouseListener; // for browse buttons only //GFX-rendered state variables - nsMouseState mLastMouseState; - PRBool mGotFocus; - PRBool mPressed; - PRBool mInside; - - // KLUDGE variable to make sure disabling works. - PRBool mDisabled; + nsButtonFrameRenderer mRenderer; }; diff --git a/layout/html/forms/src/nsButtonFrameRenderer.cpp b/layout/html/forms/src/nsButtonFrameRenderer.cpp index f753a7d347a..e931eaf2b80 100644 --- a/layout/html/forms/src/nsButtonFrameRenderer.cpp +++ b/layout/html/forms/src/nsButtonFrameRenderer.cpp @@ -3,12 +3,12 @@ #include "nsCSSRendering.h" #include "nsIPresContext.h" #include "nsGenericHTMLElement.h" +#include "nsIView.h" +#include "nsIViewManager.h" -#define ACTIVE "active" -#define HOVER "hover" -#define NORMAL "" -#define FOCUS "focus" -#define ENABLED "enabled" +#define ACTIVE "active" +#define HOVER "hover" +#define FOCUS "focus" #define DISABLED "disabled" nsButtonFrameRenderer::nsButtonFrameRenderer() @@ -83,32 +83,16 @@ nsButtonFrameRenderer::SetPseudoClassAttribute(const nsString& value, PRBool not */ } +void +nsButtonFrameRenderer::SetHover(PRBool aHover, PRBool notify) +{ + ToggleClass(aHover, HOVER, notify); +} void -nsButtonFrameRenderer::SetState(ButtonState state, PRBool notify) +nsButtonFrameRenderer::SetActive(PRBool aActive, 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); + ToggleClass(aActive, ACTIVE, notify); } void @@ -120,35 +104,29 @@ nsButtonFrameRenderer::SetFocus(PRBool aFocus, PRBool notify) void nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify) { - // 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); + ToggleClass(aDisabled, DISABLED, notify); } -nsButtonFrameRenderer::ButtonState -nsButtonFrameRenderer::GetState() +PRBool +nsButtonFrameRenderer::isHover() { nsString pseudo = GetPseudoClassAttribute(); PRInt32 index = IndexOfClass(pseudo, HOVER); if (index != -1) - return hover; + return PR_TRUE; + else + return PR_FALSE; +} - index = IndexOfClass(pseudo, ACTIVE); +PRBool +nsButtonFrameRenderer::isActive() +{ + nsString pseudo = GetPseudoClassAttribute(); + PRInt32 index = IndexOfClass(pseudo, ACTIVE); if (index != -1) - return active; - - return normal; + return PR_TRUE; + else + return PR_FALSE; } PRBool @@ -260,41 +238,47 @@ nsButtonFrameRenderer::HandleEvent(nsIPresContext& aPresContext, nsCOMPtr content; mFrame->GetContent(getter_AddRefs(content)); -/* View support has removed because views don't seem to be supporting - Transpancy and the manager isn't supporting event grabbing either. // get its view nsIView* view = nsnull; - GetView(&view); + mFrame->GetView(&view); nsCOMPtr viewMan; - view->GetViewManager(*getter_AddRefs(viewMan)); -*/ + + if (view) + view->GetViewManager(*getter_AddRefs(viewMan)); aEventStatus = nsEventStatus_eIgnore; switch (aEvent->message) { - case NS_MOUSE_ENTER: - SetState(hover, PR_TRUE); - break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - SetState(active, PR_TRUE); - // grab all mouse events - - // PRBool result; - //viewMan->GrabMouseEvents(view,result); - break; + case NS_MOUSE_ENTER: + SetHover(PR_TRUE, PR_TRUE); + break; - case NS_MOUSE_LEFT_BUTTON_UP: - SetState(hover, PR_TRUE); - // stop grabbing mouse events - //viewMan->GrabMouseEvents(nsnull,result); - break; - case NS_MOUSE_EXIT: - SetState(normal, PR_TRUE); - break; - } + case NS_MOUSE_LEFT_BUTTON_DOWN: + SetActive(PR_TRUE, PR_TRUE); + // grab all mouse events - //aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } @@ -416,6 +400,7 @@ nsButtonFrameRenderer::PaintBorderAndBackground(nsIPresContext& aPresContext, // paint the border and background + nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, mFrame, aDirtyRect, buttonRect, *color, *spacing, 0, 0); @@ -534,6 +519,12 @@ nsButtonFrameRenderer::GetButtonOutlineBorderAndPadding() return borderAndPadding; } +nsMargin +nsButtonFrameRenderer::GetFullButtonBorderAndPadding() +{ + return GetButtonOuterFocusBorderAndPadding() + GetButtonBorderAndPadding() + GetButtonInnerFocusMargin() + GetButtonInnerFocusBorderAndPadding(); +} + void nsButtonFrameRenderer::ReResolveStyles(nsIPresContext& aPresContext) { @@ -573,13 +564,15 @@ nsButtonFrameRenderer::AddFocusBordersAndPadding(nsIPresContext& aPresContext, nsMargin& aBorderPadding) { aBorderPadding = aReflowState.mComputedBorderPadding; + + nsMargin m = GetButtonOuterFocusBorderAndPadding(); + m += GetButtonInnerFocusMargin(); + m += GetButtonInnerFocusBorderAndPadding(); - aBorderPadding += GetButtonOuterFocusBorderAndPadding(); - aBorderPadding += GetButtonInnerFocusMargin(); - aBorderPadding += GetButtonInnerFocusBorderAndPadding(); + aBorderPadding += m; - aMetrics.width += aBorderPadding.left + aBorderPadding.right; - aMetrics.height += aBorderPadding.top + aBorderPadding.bottom; + aMetrics.width += m.left + m.right; + aMetrics.height += m.top + m.bottom; aMetrics.ascent = aMetrics.height; aMetrics.descent = 0; diff --git a/layout/html/forms/src/nsButtonFrameRenderer.h b/layout/html/forms/src/nsButtonFrameRenderer.h index 6fcd028269e..2076015711b 100644 --- a/layout/html/forms/src/nsButtonFrameRenderer.h +++ b/layout/html/forms/src/nsButtonFrameRenderer.h @@ -67,11 +67,13 @@ public: virtual void SetNameSpace(PRInt32 aNameSpace); virtual void SetFrame(nsIFrame* aFrame, nsIPresContext& aPresContext); - virtual void SetState(ButtonState state, PRBool notify); + 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); - ButtonState GetState(); + PRBool isActive(); + PRBool isHover(); PRBool isDisabled(); PRBool isFocus(); @@ -85,6 +87,7 @@ public: virtual nsMargin GetButtonInnerFocusMargin(); virtual nsMargin GetButtonInnerFocusBorderAndPadding(); virtual nsMargin GetButtonOutlineBorderAndPadding(); + virtual nsMargin GetFullButtonBorderAndPadding(); virtual void ReResolveStyles(nsIPresContext& aPresContext); diff --git a/layout/html/forms/src/nsComboboxControlFrame.cpp b/layout/html/forms/src/nsComboboxControlFrame.cpp index fd66aeb3119..ba3c2c85b20 100644 --- a/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -883,4 +883,10 @@ NS_IMETHODIMP nsComboboxControlFrame::GetProperty(nsIAtom* aName, nsString& aVal return NS_OK; } +nsresult nsComboboxControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + diff --git a/layout/html/forms/src/nsComboboxControlFrame.h b/layout/html/forms/src/nsComboboxControlFrame.h index 114cf251bf1..5dc5b598987 100644 --- a/layout/html/forms/src/nsComboboxControlFrame.h +++ b/layout/html/forms/src/nsComboboxControlFrame.h @@ -107,6 +107,10 @@ public: nscoord aInnerWidth, nscoord aCharWidth) const; + + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame); diff --git a/layout/html/forms/src/nsFileControlFrame.cpp b/layout/html/forms/src/nsFileControlFrame.cpp index 1b5b96c3428..c619f43d117 100644 --- a/layout/html/forms/src/nsFileControlFrame.cpp +++ b/layout/html/forms/src/nsFileControlFrame.cpp @@ -389,6 +389,12 @@ nsFileControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext, return 0; } +nsresult nsFileControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + NS_IMETHODIMP nsFileControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) { diff --git a/layout/html/forms/src/nsFileControlFrame.h b/layout/html/forms/src/nsFileControlFrame.h index 75a2b1784f6..53846054fdc 100644 --- a/layout/html/forms/src/nsFileControlFrame.h +++ b/layout/html/forms/src/nsFileControlFrame.h @@ -78,6 +78,9 @@ public: nscoord aInnerWidth, nscoord aCharWidth) const; + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + PRBool HasWidget(); // nsIFormMouseListener diff --git a/layout/html/forms/src/nsFormControlHelper.cpp b/layout/html/forms/src/nsFormControlHelper.cpp index ae77c16f75f..48a26214394 100644 --- a/layout/html/forms/src/nsFormControlHelper.cpp +++ b/layout/html/forms/src/nsFormControlHelper.cpp @@ -296,16 +296,25 @@ nsFormControlHelper::CalculateSize (nsIPresContext* aPresContext, } } - // add inside padding if necessary - if (!aWidthExplicit) { - PRInt32 hPadding = (2 * aFrame->GetHorizontalInsidePadding(*aPresContext, p2t, aDesiredSize.width, charWidth)); - aDesiredSize.width += hPadding; - aMinSize.width += hPadding; - } - if (!aHeightExplicit) { - PRInt32 vPadding = (2 * aFrame->GetVerticalInsidePadding(p2t, aRowHeight)); - aDesiredSize.height += vPadding; - aMinSize.height += vPadding; + nsWidgetRendering mode; + aPresContext->GetWidgetRenderingMode(&mode); + + // only add in padding if we are not Gfx + PRBool requiresWidget = PR_FALSE; + + aFrame->RequiresWidget(requiresWidget); + + if (PR_TRUE == requiresWidget || eWidgetRendering_Gfx != mode) { + if (!aWidthExplicit) { + PRInt32 hPadding = (2 * aFrame->GetHorizontalInsidePadding(*aPresContext, p2t, aDesiredSize.width, charWidth)); + aDesiredSize.width += hPadding; + aMinSize.width += hPadding; + } + if (!aHeightExplicit) { + PRInt32 vPadding = (2 * aFrame->GetVerticalInsidePadding(p2t, aRowHeight)); + aDesiredSize.height += vPadding; + aMinSize.height += vPadding; + } } NS_RELEASE(hContent); @@ -328,6 +337,19 @@ nsFormControlHelper::GetFont(nsIFormControlFrame * aFormFrame, { const nsStyleFont* styleFont = (const nsStyleFont*)aStyleContext->GetStyleData(eStyleStruct_Font); + nsWidgetRendering m; + aPresContext->GetWidgetRenderingMode(&m); + + // only add in padding if we are not Gfx + PRBool requiresWidget = PR_FALSE; + + aFormFrame->RequiresWidget(requiresWidget); + + if (PR_TRUE != requiresWidget && eWidgetRendering_Gfx == m) { + aFont = styleFont->mFont; + return; + } + nsCompatibility mode; aPresContext->GetCompatibilityMode(&mode); diff --git a/layout/html/forms/src/nsHTMLButtonControlFrame.cpp b/layout/html/forms/src/nsHTMLButtonControlFrame.cpp index ec77ef9baca..f6d15684bdf 100644 --- a/layout/html/forms/src/nsHTMLButtonControlFrame.cpp +++ b/layout/html/forms/src/nsHTMLButtonControlFrame.cpp @@ -46,15 +46,7 @@ #include "nsViewsCID.h" #include "nsColor.h" #include "nsIDocument.h" - -//Enumeration of possible mouse states used to detect mouse clicks -/*enum nsMouseState { - eMouseNone, - eMouseEnter, - eMouseExit, - eMouseDown, - eMouseUp -};*/ +#include "nsButtonFrameRenderer.h" static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID); @@ -67,6 +59,8 @@ class nsHTMLButtonControlFrame : public nsHTMLContainerFrame, public: nsHTMLButtonControlFrame(); + + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD Paint(nsIPresContext& aPresContext, @@ -89,10 +83,24 @@ public: nsIAtom* aListName, nsIFrame* aChildList); + NS_IMETHOD Init(nsIPresContext& aPresContext, + nsIContent* aContent, + nsIFrame* aParent, + nsIStyleContext* aContext, + nsIFrame* asPrevInFlow); + + NS_IMETHOD ReResolveStyleContext ( nsIPresContext* aPresContext, + nsIStyleContext* aParentContext) ; + + + NS_IMETHOD GetFrameName(nsString& aResult) const { return MakeFrameName("ButtonControl", aResult); } + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + virtual PRBool IsSuccessful(nsIFormControlFrame* aSubmitter); NS_IMETHOD GetType(PRInt32* aType) const; NS_IMETHOD GetName(nsString* aName); @@ -126,19 +134,15 @@ public: protected: NS_IMETHOD_(nsrefcnt) AddRef(void); NS_IMETHOD_(nsrefcnt) Release(void); - void AddToPadding(nsIPresContext& aPresContext, nsStyleUnit aStyleUnit, - nscoord aValue, nscoord aLength, nsStyleCoord& aStyleCoord); - void ShiftContents(nsIPresContext& aPresContext, PRBool aDown); void GetTranslatedRect(nsRect& aRect); PRIntn GetSkipSides() const; PRBool mInline; nsFormFrame* mFormFrame; - nsMouseState mLastMouseState; nsCursor mPreviousCursor; - PRBool mGotFocus; nsRect mTranslatedRect; PRBool mDidInit; + nsButtonFrameRenderer mRenderer; }; nsresult @@ -155,11 +159,22 @@ nsHTMLButtonControlFrame::nsHTMLButtonControlFrame() : nsHTMLContainerFrame() { mInline = PR_TRUE; - mLastMouseState = eMouseNone; mPreviousCursor = eCursor_standard; - mGotFocus = PR_FALSE; mTranslatedRect = nsRect(0,0,0,0); mDidInit = PR_FALSE; + mRenderer.SetNameSpace(kNameSpaceID_None); +} + +NS_IMETHODIMP +nsHTMLButtonControlFrame::Init(nsIPresContext& aPresContext, + nsIContent* aContent, + nsIFrame* aParent, + nsIStyleContext* aContext, + nsIFrame* aPrevInFlow) +{ + nsresult rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); + mRenderer.SetFrame(this,aPresContext); + return rv; } nsrefcnt nsHTMLButtonControlFrame::AddRef(void) @@ -335,118 +350,10 @@ nsHTMLButtonControlFrame::MouseClicked(nsIPresContext* aPresContext) } } -#if 0 -// XXX temporary hack code until new style rules are added -static -void ReflowTemp(nsIPresContext& aPresContext, nsHTMLButtonControlFrame* aFrame, nsRect& aRect) -{ - // XXX You can't do this. Incremental reflow commands are dispatched from the - // root frame downward... -#if 0 - nsHTMLReflowMetrics metrics(nsnull); - nsSize size; - aFrame->GetSize(size); - nsIPresShell *shell; - nsIRenderingContext *acx; - shell = aPresContext.GetShell(); - shell->CreateRenderingContext(aFrame, acx); - NS_RELEASE(shell); - nsIReflowCommand* cmd; - nsresult result = NS_NewHTMLReflowCommand(&cmd, aFrame, nsIReflowCommand::ContentChanged); - nsHTMLReflowState state(aPresContext, aFrame, *cmd, size, acx); - //nsHTMLReflowState state(aPresContext, aFrame, eReflowReason_Initial, - // size, acx); - state.reason = eReflowReason_Incremental; - nsReflowStatus status; - nsDidReflowStatus didStatus; - aFrame->WillReflow(aPresContext); - aFrame->Reflow(aPresContext, metrics, state, status); - aFrame->DidReflow(aPresContext, didStatus); - NS_IF_RELEASE(acx); - aFrame->Invalidate(aRect, PR_TRUE); - NS_RELEASE(cmd); -#else - nsIContent* content; - aFrame->GetContent(&content); - if (nsnull != content) { - nsIDocument* document; - - content->GetDocument(document); - document->ContentChanged(content, nsnull); - NS_RELEASE(document); - NS_RELEASE(content); - } -#endif -} -#endif - void nsHTMLButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) { - mGotFocus = aOn; - if (aRepaint) { - nsRect rect(0, 0, mRect.width, mRect.height); - Invalidate(rect, PR_TRUE); - } -} - -// XXX temporary hack code until new style rules are added -void -nsHTMLButtonControlFrame::AddToPadding(nsIPresContext& aPresContext, - nsStyleUnit aStyleUnit, - nscoord aValue, - nscoord aLength, - nsStyleCoord& aStyleCoord) -{ - if (eStyleUnit_Coord == aStyleUnit) { - nscoord coord; - coord = aStyleCoord.GetCoordValue(); - coord += aValue; - aStyleCoord.SetCoordValue(coord); - } else if (eStyleUnit_Percent == aStyleUnit) { - float increment = ((float)aValue) / ((float)aLength); - float percent = aStyleCoord.GetPercentValue(); - percent += increment; - aStyleCoord.SetPercentValue(percent); - } -} - -// XXX temporary hack code until new style rules are added -void -nsHTMLButtonControlFrame::ShiftContents(nsIPresContext& aPresContext, PRBool aDown) -{ - nsStyleSpacing* spacing = - (nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); // cast deliberate - - float p2t; - aPresContext.GetScaledPixelsToTwips(&p2t); - nscoord shift = (aDown) ? NSIntPixelsToTwips(1, p2t) : -NSIntPixelsToTwips(1, p2t); - nsStyleCoord styleCoord; - - // alter the padding so the content shifts down and to the right one pixel - AddToPadding(aPresContext, spacing->mPadding.GetLeftUnit(), shift, mRect.width, - spacing->mPadding.GetLeft(styleCoord)); - spacing->mPadding.SetLeft(styleCoord); - AddToPadding(aPresContext, spacing->mPadding.GetTopUnit(), shift, mRect.height, - spacing->mPadding.GetTop(styleCoord)); - spacing->mPadding.SetTop(styleCoord); - AddToPadding(aPresContext, spacing->mPadding.GetRightUnit(), -shift, mRect.width, - spacing->mPadding.GetRight(styleCoord)); - spacing->mPadding.SetRight(styleCoord); - AddToPadding(aPresContext, spacing->mPadding.GetBottomUnit(), -shift, mRect.height, - spacing->mPadding.GetBottom(styleCoord)); - spacing->mPadding.SetBottom(styleCoord); - - // XXX change the border, border-left, border-right, etc are not working. Instead change inset to outset, vice versa - for (PRInt32 i = 0; i < 4; i++) { - spacing->SetBorderStyle(i,(spacing->GetBorderStyle(i) == NS_STYLE_BORDER_STYLE_INSET) ? - NS_STYLE_BORDER_STYLE_OUTSET : NS_STYLE_BORDER_STYLE_INSET); - } - - mStyleContext->RecalcAutomaticData(&aPresContext); - - //nsRect rect(0, 0, mRect.width, mRect.height); - //ReflowTemp(aPresContext, this, rect); + mRenderer.SetFocus(aOn, aRepaint); } void @@ -465,59 +372,46 @@ nsHTMLButtonControlFrame::GetTranslatedRect(nsRect& aRect) } + NS_IMETHODIMP nsHTMLButtonControlFrame::HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus) { - if (nsFormFrame::GetDisabled(this)) { // XXX cache disabled + 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; - nsIView* view; - GetView(&view); - if (view) { - nsIViewManager* viewMan; - view->GetViewManager(viewMan); - if (viewMan) { - nsIView* grabber; - viewMan->GetMouseEventGrabber(grabber); - if ((grabber == view) || (nsnull == grabber)) { - switch (aEvent->message) { - case NS_MOUSE_ENTER: - //mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "ROLLOVER", PR_TRUE); - if (mLastMouseState == eMouseDown) { - ShiftContents(aPresContext, PR_TRUE); - } - break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - mGotFocus = PR_TRUE; - ShiftContents(aPresContext, PR_TRUE); - mLastMouseState = eMouseDown; - break; - case NS_MOUSE_LEFT_BUTTON_UP: - if (eMouseDown == mLastMouseState) { - if (nsEventStatus_eConsumeNoDefault != aEventStatus) { - ShiftContents(aPresContext, PR_FALSE); - MouseClicked(&aPresContext); - } - mLastMouseState = eMouseUp; - } - break; - case NS_MOUSE_EXIT: - //mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, "", PR_TRUE); - if (mLastMouseState == eMouseDown) { - ShiftContents(aPresContext, PR_FALSE); - } - break; - } - aEventStatus = nsEventStatus_eConsumeNoDefault; - NS_RELEASE(viewMan); - } - } + + 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_MOUSE_EXIT: + break; } + return NS_OK; + } @@ -569,40 +463,12 @@ nsHTMLButtonControlFrame::Paint(nsIPresContext& aPresContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) { - nsresult result = nsHTMLContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); - if (NS_FAILED(result)) { - return result; - } - if (eFramePaintLayer_Overlay == aWhichLayer) { - if (mGotFocus) { // draw dashed line to indicate selection, XXX don't calc rect every time - const nsStyleSpacing* spacing = - (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); - nsMargin border; - spacing->CalcBorderFor(this, border); - float p2t; - aPresContext.GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); + nsRect rect(0, 0, mRect.width, mRect.height); + mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect); + PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); - nsRect outside(0, 0, mRect.width, mRect.height); - outside.Deflate(border); - outside.Deflate(onePixel, onePixel); - - nsRect inside(outside); - inside.Deflate(onePixel, onePixel); - - PRUint8 borderStyles[4]; - nscolor borderColors[4]; - nscolor black = NS_RGB(0,0,0); - for (PRInt32 i = 0; i < 4; i++) { - borderStyles[i] = NS_STYLE_BORDER_STYLE_DOTTED; - borderColors[i] = black; - } - nsCSSRendering::DrawDashedSides(0, aRenderingContext, borderStyles, borderColors, outside, - inside, PR_FALSE, nsnull); - } - } - return result; + return NS_OK; } // XXX a hack until the reflow state does this correctly @@ -640,6 +506,14 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext& aPresContext, { // XXX remove the following when the reflow state is fixed ButtonHack((nsHTMLReflowState&)aReflowState, "html4 button"); + + // commenting this out for now. We need a view to do mouse grabbing but + // it doesn't really seem to work correctly. When you press the only event + // you can get after that is a release. You need mouse enter and exit. + // the view also breaks the outline code. For some reason you can not reset + // the clip rect to draw outside you bounds if you have a view. And you need to + // because the outline must be drawn outside of our bounds according to CSS. -EDV +#if 0 if (!mDidInit) { // create our view, we need a view to grab the mouse nsIView* view; @@ -668,16 +542,13 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext& aPresContext, } mDidInit = PR_TRUE; } +#endif // reflow the child nsIFrame* firstKid = mFrames.FirstChild(); nsSize availSize(aReflowState.computedWidth, aReflowState.computedHeight); - // get border and padding - const nsStyleSpacing* spacing = - (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); - nsMargin borderPadding; - spacing->CalcBorderPaddingFor(this, borderPadding); + nsMargin borderPadding = mRenderer.GetFullButtonBorderAndPadding(); if (NS_INTRINSICSIZE != availSize.width) { availSize.width -= borderPadding.left + borderPadding.right; @@ -781,6 +652,13 @@ nsHTMLButtonControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContex return 0; } +nsresult nsHTMLButtonControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + + NS_IMETHODIMP nsHTMLButtonControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) { return NS_OK; @@ -791,5 +669,29 @@ NS_IMETHODIMP nsHTMLButtonControlFrame::GetProperty(nsIAtom* aName, nsString& aV return NS_OK; } +// +// ReResolveStyleContext +// +// When the style context changes, make sure that all of our styles are still up to date. +// +NS_IMETHODIMP +nsHTMLButtonControlFrame::ReResolveStyleContext ( nsIPresContext* aPresContext, nsIStyleContext* aParentContext) +{ + + nsCOMPtr old ( dont_QueryInterface(mStyleContext) ); + + // this re-resolves |mStyleContext|, so it may change + nsresult rv = nsHTMLContainerFrame::ReResolveStyleContext(aPresContext, aParentContext); + if (NS_FAILED(rv)) { + return rv; + } + + mRenderer.ReResolveStyles(*aPresContext); + + return NS_OK; + +} // ReResolveStyleContext + + diff --git a/layout/html/forms/src/nsImageControlFrame.cpp b/layout/html/forms/src/nsImageControlFrame.cpp index 1e52a528928..5cb3105d4de 100644 --- a/layout/html/forms/src/nsImageControlFrame.cpp +++ b/layout/html/forms/src/nsImageControlFrame.cpp @@ -105,6 +105,10 @@ public: float aPixToTwip, nscoord aInnerWidth, nscoord aCharWidth) const; + + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + // nsIFormControlFrame NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); @@ -400,6 +404,13 @@ nsImageControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext, return 0; } +nsresult nsImageControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + + NS_IMETHODIMP nsImageControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) { return NS_OK; diff --git a/layout/html/forms/src/nsListControlFrame.cpp b/layout/html/forms/src/nsListControlFrame.cpp index d3a5064fc5e..70ee313b3d4 100644 --- a/layout/html/forms/src/nsListControlFrame.cpp +++ b/layout/html/forms/src/nsListControlFrame.cpp @@ -1621,6 +1621,14 @@ NS_IMETHODIMP nsListControlFrame::GetProperty(nsIAtom* aName, nsString& aValue) return NS_OK; } +nsresult nsListControlFrame::RequiresWidget(PRBool& aRequiresWidget) +{ + aRequiresWidget = PR_FALSE; + return NS_OK; +} + + + #if 0 //---------------------------------------------------------------------- diff --git a/layout/html/forms/src/nsListControlFrame.h b/layout/html/forms/src/nsListControlFrame.h index 87de183a500..738817b089c 100644 --- a/layout/html/forms/src/nsListControlFrame.h +++ b/layout/html/forms/src/nsListControlFrame.h @@ -180,6 +180,9 @@ public: nscoord aInnerWidth, nscoord aCharWidth) const; + virtual nsresult RequiresWidget(PRBool &aRequiresWidget); + + NS_IMETHOD GetFont(nsIPresContext* aPresContext, nsFont& aFont); diff --git a/layout/html/style/src/nsCSSFrameConstructor.cpp b/layout/html/style/src/nsCSSFrameConstructor.cpp index 6ce71c9e0e9..2b62b52921c 100644 --- a/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -1957,6 +1957,11 @@ nsCSSFrameConstructor::ConstructFrameByTag(nsIPresContext* aPresContext, } else if (nsHTMLAtoms::button == aTag) { rv = NS_NewHTMLButtonControlFrame(newFrame); + // the html4 button needs to act just like a + // regular button except contain html content + // so it must be replaced or html outside it will + // draw into its borders. -EDV + isReplaced = PR_TRUE; processChildren = PR_TRUE; } else if (nsHTMLAtoms::label == aTag) { diff --git a/layout/style/ua.css b/layout/style/ua.css index 679d1bbb45d..6e6aef687a9 100644 --- a/layout/style/ua.css +++ b/layout/style/ua.css @@ -33,58 +33,74 @@ frameset { p { display: block; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } address { display: block; font-style: italic; + margin-bottom: 0; + margin-top: 0; } blockquote { display: block; - margin-left: 1em 40px; + margin-left: 40px; + margin-right: 40px; + margin-top: auto; + margin-bottom: auto; } center { display: block; text-align: center; + margin-bottom: 0; + margin-top: 0; } div { display: block; + margin-bottom: 0; + margin-top: 0; } h1 { display: block; font-size: xx-large; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h2 { display: block; font-size: x-large; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h3 { display: block; font-size: large; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h4 { display: block; font-size: medium; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h5 { display: block; font-size: small; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } h6 { display: block; font-size: x-small; font-weight: bold; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } layer { display: block; @@ -95,17 +111,20 @@ listing { font-family: monospace; font-size: medium; white-space: pre; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } plaintext, xmp, pre { display: block; font-family: monospace; white-space: pre; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } multicol { display: block; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } /* tables */ @@ -297,14 +316,20 @@ fieldset { ul, menu, dir { display: block; + margin-right: 0; + margin-bottom: auto; + margin-top: auto; list-style-type: disc; - margin: 1em 0 1em 40px; + margin-left: 40px; } ol { display: block; + margin-right: 0; + margin-bottom: auto; + margin-top: auto; list-style-type: decimal; - margin: 1em 0 1em 40px; + margin-left: 40px; } li { @@ -356,7 +381,8 @@ dir ol dir, dir ul dir, dir menu dir, dir dir dir dl { display: block; - margin: 1em 0; + margin-bottom: auto; + margin-top: auto; } dt { display: block; @@ -373,6 +399,9 @@ embed { } hr { display: block; + margin-top: 0; + margin-bottom: 0; + text-align: center; border: 1px -moz-bg-inset; } br { @@ -407,6 +436,7 @@ input[type=radio] { width:12px; height:12px; } + input[type=checkbox] { border: 2px inset rgb(192, 192, 192); width:11px; @@ -415,51 +445,202 @@ input[type=checkbox] { color:black; } -input[type=button] { - border: 2px outset rgb(192, 192, 192); - color:black; - background-color: rgb(192, 192, 192); +input[type="submit"] { + border: 2px outset rgb(156, 154, 156); + background-color: rgb(206, 207, 206); + color:black; + + padding: 1px; } -input[type=submit] { - border: 1px outset rgb(156, 154, 156); - background-color:rgb(206, 207, 206); - color:black; +input[type="submit"][pseudoclass~="active"] { + border-style: inset; + + padding-left: 2px; + padding-right: 0px; + padding-top: 2px; + padding-bottom: 0px; } -input[type=submit].rollover { +input[type="submit"][pseudoclass~="active"]:-moz-outline { + border : 1px solid black; } -input[type=submit].pressed { - border-style : inset; +input[type="submit"][pseudoclass~="hover"]:-moz-outline { + border : 1px solid black; } -input[type=submit].disabled { - border-style : solid; +input[type="submit"][pseudoclass~="disabled"] { + border-style: solid; +} + +input[type="submit"]:-moz-focus-inner { + padding-left : 2px; + padding-right : 2px; + padding-top : 1px; + padding-bottom: 1px; + margin: 0px; +} + +input[type="submit"][pseudoclass~="focus"]:-moz-focus-inner { + padding-left : 1px; + padding-right : 1px; + padding-top : 0px; + padding-bottom: 0px; + + margin: 0px; + border : 1px dotted black; +} + +input[type="reset"] { + border: 2px outset rgb(156, 154, 156); + background-color: rgb(206, 207, 206); + color:black; + + padding: 1px; +} + +input[type="reset"][pseudoclass~="active"] { + border-style: inset; + + padding-left: 2px; + padding-right: 0px; + padding-top: 2px; + padding-bottom: 0px; +} + +input[type="reset"][pseudoclass~="active"]:-moz-outline { + border : 1px solid black; +} + +input[type="reset"][pseudoclass~="hover"]:-moz-outline { + border : 1px solid black; +} + +input[type="reset"][pseudoclass~="disabled"] { + border-style: solid; +} + +input[type="reset"]:-moz-focus-inner { + padding-left : 2px; + padding-right : 2px; + padding-top : 1px; + padding-bottom: 1px; + margin: 0px; +} + +input[type="reset"][pseudoclass~="focus"]:-moz-focus-inner { + padding-left : 1px; + padding-right : 1px; + padding-top : 0px; + padding-bottom: 0px; + + margin: 0px; + border : 1px dotted black; +} + +input[type="button"] { + border: 2px outset rgb(156, 154, 156); + background-color: rgb(206, 207, 206); + color:black; + + padding: 1px; +} + +input[type="button"][pseudoclass~="active"] { + border-style: inset; + + padding-left: 2px; + padding-right: 0px; + padding-top: 2px; + padding-bottom: 0px; + + background-color: rgb(220, 207, 206); +} + +input[type="button"][pseudoclass~="active"]:-moz-outline { + border : 1px solid black; +} + +input[type="button"][pseudoclass~="hover"]:-moz-outline { + border : 1px solid black; +} + +input[type="button"][pseudoclass~="disabled"] { + border-style: solid; +} + +input[type="button"]:-moz-focus-inner { + padding-left : 2px; + padding-right : 2px; + padding-top : 1px; + padding-bottom: 1px; + margin: 0px; +} + +input[type="button"][pseudoclass~="focus"]:-moz-focus-inner { + padding-left : 1px; + padding-right : 1px; + padding-top : 0px; + padding-bottom: 0px; + + margin: 0px; + border : 1px dotted black; } -input[type=reset] { - border: 1px outset rgb(156, 154, 156); - background-color:rgb(206, 207, 206); - color:black; +button { + display: inline; + vertical-align: bottom; + cursor: default; + + border: 2px outset rgb(156, 154, 156); + background-color: rgb(206, 207, 206); + color:black; + + padding: 1px; } -input[type=reset].rollover { +button[pseudoclass~="active"] { + border-style: inset; + + padding-left: 2px; + padding-right: 0px; + padding-top: 2px; + padding-bottom: 0px; } -input[type=reset].pressed { - border-style : inset; +button[pseudoclass~="hover"] { } -input[type=reset].disabled { - border-style : solid; +button[pseudoclass~="active"]:-moz-outline { + border : 1px solid black; } -input[type=file] { - border: 1px outset rgb(156, 154, 156); - background-color:rgb(206, 207, 206); - color:black; +button[pseudoclass~="hover"]:-moz-outline { + border : 1px solid black; +} + +button[pseudoclass~="disabled"] { + border-style: solid; +} + +button:-moz-focus-inner { + padding-left : 2px; + padding-right : 2px; + padding-top : 1px; + padding-bottom: 1px; + margin: 0px; +} + +button[pseudoclass~="focus"]:-moz-focus-inner { + padding-left : 1px; + padding-right : 1px; + padding-top : 0px; + padding-bottom: 0px; + + margin: 0px; + border : 1px dotted black; } :-moz-file-button { @@ -470,40 +651,20 @@ input[type=file] { :-moz-file-text { border: 2px inset rgb(192, 192, 192); - margin-right: 10px; + margin-right:10px; background-color: white; color: black; } -input[type=file].rollover { -} - -input[type=file].pressed { - border-style : inset; -} - -input[type=file].disabled { - border-style : solid; -} - - -:button-outline { - border: 1px solid black; -} - -:button-focus { - border: 2px solid salmon; -} - input[type=text] { border: 2px inset rgb(192, 192, 192); - margin-right: 10px; + margin-right:10px; background-color: white; color: black; } input[type=password] { border: 2px inset rgb(192, 192, 192); - margin-right: 10px; + margin-right:10px; background-color: white; color:black; } @@ -516,29 +677,7 @@ label { padding-left: 3px; padding-right: 3px; } -button { - display: inline; - vertical-align: bottom; - cursor: default; -} -button { - display: inline; - vertical-align: bottom; - /*background-color: white; */ - /*border: 3px outset gray;*/ - /*padding: 3px;*/ - background-color: rgb(192,192,192); - border: 2px solid rgb(192,192,192); - padding: 2px; - cursor: default; -} -button.rollover { - border: 2px outset rgb(192,192,192); -} -button.disabled { - border: 2px solid rgb(192,192,192); - color: rgb(225,225,225); -} + select { vertical-align: bottom; border: 1px inset #c0c0c0; @@ -660,7 +799,6 @@ param { /* XXX Temporary until @page is supported... */ :-moz-page { background: none; - display: block; } :root { diff --git a/layout/xul/base/src/nsProgressMeterFrame.cpp b/layout/xul/base/src/nsProgressMeterFrame.cpp index 0c3d96d3578..32d3f813ab4 100644 --- a/layout/xul/base/src/nsProgressMeterFrame.cpp +++ b/layout/xul/base/src/nsProgressMeterFrame.cpp @@ -41,6 +41,9 @@ static int ANIMATION_SPEED = 50; // miliseconds #include "nsITimer.h" #include "nsIView.h" #include "nsIViewManager.h" +#include "nsIReflowCommand.h" +#include "nsHTMLParts.h" +#include "nsIPresShell.h" class StripeTimer : public nsITimerCallback { public: @@ -244,7 +247,7 @@ nsProgressMeterFrame::setProgress(nsAutoString progress) else if (v > 100) v = 100; - printf("ProgressMeter value=%d\n", v); +// printf("ProgressMeter value=%d\n", v); mProgress = float(v)/float(100); } @@ -685,12 +688,53 @@ nsProgressMeterFrame::AttributeChanged(nsIPresContext* aPresContext, aChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, newValue); setProgress(newValue); - // redraw + Redraw(aPresContext); + + } else if (nsXULAtoms::mode == aAttribute) { + nsAutoString newValue; + + aChild->GetAttribute(kNameSpaceID_None, nsXULAtoms::mode, newValue); + setMode(newValue); + + // needs to reflow so we start the timer. + Reflow(aPresContext); + } else if (nsHTMLAtoms::align == aAttribute) { + nsAutoString newValue; + + // get attribute and set it + aChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::align, newValue); + setAlignment(newValue); + + + Reflow(aPresContext); } return NS_OK; } +void +nsProgressMeterFrame::Reflow(nsIPresContext* aPresContext) +{ + // reflow + nsCOMPtr shell; + aPresContext->GetShell(getter_AddRefs(shell)); + + nsCOMPtr reflowCmd; + nsresult rv = NS_NewHTMLReflowCommand(getter_AddRefs(reflowCmd), this, + nsIReflowCommand::StyleChanged); + if (NS_SUCCEEDED(rv)) + shell->AppendReflowCommand(reflowCmd); +} + +void +nsProgressMeterFrame::Redraw(nsIPresContext* aPresContext) +{ + nsRect frameRect; + GetRect(frameRect); + nsRect rect(0, 0, frameRect.width, frameRect.height); + Invalidate(rect, PR_TRUE); +} + // // RefreshStyleContext // diff --git a/layout/xul/base/src/nsProgressMeterFrame.h b/layout/xul/base/src/nsProgressMeterFrame.h index fab5664cc8a..a7a669ccc3f 100644 --- a/layout/xul/base/src/nsProgressMeterFrame.h +++ b/layout/xul/base/src/nsProgressMeterFrame.h @@ -83,6 +83,10 @@ public: virtual void animate(); + virtual void Reflow(nsIPresContext* aPresContext); + + virtual void Redraw(nsIPresContext* aPresContext); + protected: nsProgressMeterFrame(); virtual ~nsProgressMeterFrame(); diff --git a/layout/xul/base/src/nsTitledButtonFrame.cpp b/layout/xul/base/src/nsTitledButtonFrame.cpp index da5d9972783..ce7e8186bae 100644 --- a/layout/xul/base/src/nsTitledButtonFrame.cpp +++ b/layout/xul/base/src/nsTitledButtonFrame.cpp @@ -991,22 +991,16 @@ nsTitledButtonFrame::HandleEvent(nsIPresContext& aPresContext, switch (aEvent->message) { - case NS_MOUSE_ENTER: - break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - if (mRenderer.GetState() == nsButtonFrameRenderer::active) - { // do mouse click - mRenderer.SetFocus(PR_TRUE, PR_TRUE); - } - break; + 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_LEFT_BUTTON_UP: + break; + case NS_MOUSE_EXIT: + break; } //aEventStatus = nsEventStatus_eConsumeNoDefault; diff --git a/webshell/tests/viewer/samples/test8.html b/webshell/tests/viewer/samples/test8.html index b7d8c302174..9f6a1df3dd9 100644 --- a/webshell/tests/viewer/samples/test8.html +++ b/webshell/tests/viewer/samples/test8.html @@ -16,9 +16,7 @@ TEXTAREA#textarea1 { SELECT#select1 { font-size: large; } -BUTTON { - background-image: url(rock_gra.gif); -} + @@ -38,7 +36,7 @@ BUTTON {

html 4 button
-