зеркало из https://github.com/mozilla/gecko-dev.git
honor width and height on the color picker and size intrinsically if thats what you want
This commit is contained in:
Родитель
22456ab859
Коммит
9900e1bac0
|
@ -23,6 +23,7 @@
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
#include "prtypes.h"
|
#include "prtypes.h"
|
||||||
#include "nsIAtom.h"
|
#include "nsIAtom.h"
|
||||||
|
#include "nsHTMLAtoms.h"
|
||||||
#include "nsIPresContext.h"
|
#include "nsIPresContext.h"
|
||||||
#include "nsIStyleContext.h"
|
#include "nsIStyleContext.h"
|
||||||
#include "nsCSSRendering.h"
|
#include "nsCSSRendering.h"
|
||||||
|
@ -57,12 +58,12 @@ static NS_DEFINE_IID(kDefColorPickerCID, NS_DEFCOLORPICKER_CID);
|
||||||
//
|
//
|
||||||
nsColorPickerFrame::nsColorPickerFrame()
|
nsColorPickerFrame::nsColorPickerFrame()
|
||||||
{
|
{
|
||||||
mColorPicker = new nsStdColorPicker();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsColorPickerFrame::~nsColorPickerFrame()
|
nsColorPickerFrame::~nsColorPickerFrame()
|
||||||
{
|
{
|
||||||
|
delete mColorPicker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,26 +78,18 @@ nsColorPickerFrame::Init(nsIPresContext& aPresContext,
|
||||||
nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext,
|
nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext,
|
||||||
aPrevInFlow);
|
aPrevInFlow);
|
||||||
|
|
||||||
#if 0
|
|
||||||
// get the value
|
nsAutoString type;
|
||||||
nsAutoString value;
|
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, type);
|
||||||
if ((NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value)) &&
|
|
||||||
(value.Length() > 0)) {
|
if (type.EqualsIgnoreCase("swatch") || type.Equals(""))
|
||||||
setProgress(value);
|
mColorPicker = new nsStdColorPicker();
|
||||||
|
if (type.EqualsIgnoreCase("nose"))
|
||||||
|
{
|
||||||
|
printf("nose picker!\n");
|
||||||
|
mColorPicker = new nsStdColorPicker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// get the alignment
|
|
||||||
nsAutoString align;
|
|
||||||
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::align, align);
|
|
||||||
setAlignment(align);
|
|
||||||
|
|
||||||
// get the mode
|
|
||||||
nsAutoString mode;
|
|
||||||
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::mode, mode);
|
|
||||||
setMode(mode);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,27 +159,25 @@ nsColorPickerFrame::Paint(nsIPresContext& aPresContext,
|
||||||
aWhichLayer);
|
aWhichLayer);
|
||||||
|
|
||||||
// get our border
|
// get our border
|
||||||
const nsStyleSpacing* spacing =
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
||||||
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
|
||||||
nsMargin border(0,0,0,0);
|
nsMargin border(0,0,0,0);
|
||||||
spacing->CalcBorderFor(this, border);
|
spacing->CalcBorderFor(this, border);
|
||||||
|
|
||||||
const nsStyleColor* colorStyle =
|
/*
|
||||||
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
const nsStyleColor* colorStyle = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
||||||
|
|
||||||
nscolor color = colorStyle->mColor;
|
nscolor color = colorStyle->mColor;
|
||||||
|
*/
|
||||||
|
|
||||||
aRenderingContext.PushState();
|
aRenderingContext.PushState();
|
||||||
|
|
||||||
|
// set the clip region
|
||||||
PRInt32 width, height;
|
PRInt32 width, height;
|
||||||
|
|
||||||
mColorPicker->GetSize(&width, &height);
|
mColorPicker->GetSize(&width, &height);
|
||||||
nsRect rect(0, 0, width*p2t, height*p2t);
|
nsRect rect(0, 0, width*p2t, height*p2t);
|
||||||
|
|
||||||
PRBool clipState;
|
PRBool clipState;
|
||||||
|
|
||||||
// Clip so we don't render outside the inner rect
|
// Clip so we don't render outside the inner rect
|
||||||
aRenderingContext.PushState();
|
|
||||||
aRenderingContext.SetClipRect(rect, nsClipCombine_kIntersect, clipState);
|
aRenderingContext.SetClipRect(rect, nsClipCombine_kIntersect, clipState);
|
||||||
|
|
||||||
// call the color picker's paint method
|
// call the color picker's paint method
|
||||||
|
@ -207,52 +198,36 @@ nsColorPickerFrame::Paint(nsIPresContext& aPresContext,
|
||||||
void
|
void
|
||||||
nsColorPickerFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
nsColorPickerFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||||
const nsHTMLReflowState& aReflowState,
|
const nsHTMLReflowState& aReflowState,
|
||||||
nsHTMLReflowMetrics& aDesiredLayoutSize)
|
nsHTMLReflowMetrics& aDesiredSize)
|
||||||
{
|
{
|
||||||
float p2t;
|
float p2t;
|
||||||
|
|
||||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||||
|
|
||||||
const int CSS_NOTSET = -1;
|
|
||||||
// const int ATTR_NOTSET = -1;
|
|
||||||
|
|
||||||
nsSize styleSize;
|
// if the width is set use it
|
||||||
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) {
|
if (NS_INTRINSICSIZE != aReflowState.mComputedWidth)
|
||||||
styleSize.width = aReflowState.mComputedWidth;
|
aDesiredSize.width = aReflowState.mComputedWidth;
|
||||||
}
|
else
|
||||||
else {
|
aDesiredSize.width = -1;
|
||||||
styleSize.width = CSS_NOTSET;
|
|
||||||
}
|
|
||||||
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedHeight) {
|
|
||||||
styleSize.height = aReflowState.mComputedHeight;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
styleSize.height = CSS_NOTSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
// subclasses should always override this method, but if not and no css, make it small
|
// if the height is set use it
|
||||||
// XXX ???
|
if (NS_INTRINSICSIZE != aReflowState.mComputedHeight)
|
||||||
/*
|
aDesiredSize.height = aReflowState.mComputedHeight;
|
||||||
aDesiredLayoutSize.width = (styleSize.width > CSS_NOTSET) ? styleSize.width : 200;
|
else
|
||||||
aDesiredLayoutSize.height = (styleSize.height > CSS_NOTSET) ? styleSize.height : 200;
|
aDesiredSize.height = -1;
|
||||||
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
|
|
||||||
aDesiredLayoutSize.descent = 0;
|
|
||||||
if (aDesiredLayoutSize.maxElementSize) {
|
|
||||||
aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width;
|
|
||||||
aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
PRInt32 width, height;
|
mColorPicker->SetSize((aDesiredSize.width == -1) ? -1 : aDesiredSize.width/p2t,
|
||||||
|
(aDesiredSize.height == -1) ? -1 : aDesiredSize.height/p2t);
|
||||||
|
|
||||||
|
|
||||||
|
int width, height;
|
||||||
|
|
||||||
mColorPicker->GetSize(&width, &height);
|
mColorPicker->GetSize(&width, &height);
|
||||||
|
|
||||||
// convert to twips
|
aDesiredSize.width = nscoord(width * p2t);
|
||||||
|
aDesiredSize.height = nscoord(height * p2t);
|
||||||
aDesiredLayoutSize.width = nscoord(width * p2t);
|
aDesiredSize.ascent = nscoord(height * p2t);
|
||||||
aDesiredLayoutSize.height = nscoord(height * p2t);
|
aDesiredSize.descent = 0;
|
||||||
aDesiredLayoutSize.ascent = nscoord(height * p2t);
|
|
||||||
aDesiredLayoutSize.descent = 0;
|
|
||||||
|
|
||||||
|
|
||||||
} // GetDesiredSize
|
} // GetDesiredSize
|
||||||
|
|
|
@ -47,6 +47,9 @@ class nsIColorPicker : public nsISupports {
|
||||||
/* void GetColor (in PRInt32 aX, in PRInt32 aY, out string aColor); */
|
/* void GetColor (in PRInt32 aX, in PRInt32 aY, out string aColor); */
|
||||||
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) = 0;
|
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) = 0;
|
||||||
|
|
||||||
|
/* void SetColor (in PRInt32 aWidth, in PRInt32 aHeight); */
|
||||||
|
NS_IMETHOD SetSize(PRInt32 aWidth, PRInt32 aHeight) = 0;
|
||||||
|
|
||||||
/* void GetSize (out PRInt32 aWidth, out PRInt32 aHeight); */
|
/* void GetSize (out PRInt32 aWidth, out PRInt32 aHeight); */
|
||||||
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) = 0;
|
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) = 0;
|
||||||
};
|
};
|
||||||
|
@ -55,12 +58,14 @@ class nsIColorPicker : public nsISupports {
|
||||||
#define NS_DECL_NSICOLORPICKER \
|
#define NS_DECL_NSICOLORPICKER \
|
||||||
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext); \
|
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext); \
|
||||||
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor); \
|
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor); \
|
||||||
|
NS_IMETHOD SetSize(PRInt32 aWidth, PRInt32 aHeight); \
|
||||||
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight);
|
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight);
|
||||||
|
|
||||||
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
|
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
|
||||||
#define NS_FORWARD_NSICOLORPICKER(_to) \
|
#define NS_FORWARD_NSICOLORPICKER(_to) \
|
||||||
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext) { return _to ## Paint(aPresContext, aRenderingContext); } \
|
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext) { return _to ## Paint(aPresContext, aRenderingContext); } \
|
||||||
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) { return _to ## GetColor(aX, aY, aColor); } \
|
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) { return _to ## GetColor(aX, aY, aColor); } \
|
||||||
|
NS_IMETHOD SetSize(PRInt32 aWidth, PRInt32 aHeight) { return _to ## SetSize(aWidth, aHeight); } \
|
||||||
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) { return _to ## GetSize(aWidth, aHeight); }
|
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) { return _to ## GetSize(aWidth, aHeight); }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,10 +50,12 @@ NS_IMPL_ISUPPORTS1(nsStdColorPicker, nsIColorPicker)
|
||||||
|
|
||||||
nsStdColorPicker::nsStdColorPicker()
|
nsStdColorPicker::nsStdColorPicker()
|
||||||
{
|
{
|
||||||
mNumRows = 0;
|
mNumCols = 10; // NSToIntRound(sqrt(nColors));
|
||||||
mNumCols = 0;
|
mNumRows = NSToIntRound(nColors/mNumCols);
|
||||||
|
|
||||||
mFrameWidth = 0;
|
mFrameWidth = 0;
|
||||||
mFrameHeight = 0;
|
mFrameHeight = 0;
|
||||||
|
|
||||||
mBlockWidth = 20;
|
mBlockWidth = 20;
|
||||||
mBlockHeight = 20;
|
mBlockHeight = 20;
|
||||||
}
|
}
|
||||||
|
@ -117,10 +119,22 @@ NS_IMETHODIMP nsStdColorPicker::GetColor(PRInt32 aX, PRInt32 aY, char **aColor)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsStdColorPicker::SetSize(PRInt32 aWidth, PRInt32 aHeight)
|
||||||
|
{
|
||||||
|
mFrameWidth = aWidth;
|
||||||
|
mFrameHeight = aHeight;
|
||||||
|
|
||||||
|
if (aWidth != -1)
|
||||||
|
mBlockWidth = NSToIntRound(mFrameWidth / mNumCols);
|
||||||
|
|
||||||
|
if (aWidth != -1)
|
||||||
|
mBlockHeight = NSToIntRound(mFrameHeight / mNumRows);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsStdColorPicker::GetSize(PRInt32 *aWidth, PRInt32 *aHeight)
|
NS_IMETHODIMP nsStdColorPicker::GetSize(PRInt32 *aWidth, PRInt32 *aHeight)
|
||||||
{
|
{
|
||||||
mNumCols = 10; // NSToIntRound(sqrt(nColors));
|
|
||||||
mNumRows = NSToIntRound(nColors/mNumCols);
|
|
||||||
mFrameWidth = NSToIntRound((mNumCols) * mBlockWidth);
|
mFrameWidth = NSToIntRound((mNumCols) * mBlockWidth);
|
||||||
mFrameHeight = NSToIntRound((mNumRows) * mBlockHeight);
|
mFrameHeight = NSToIntRound((mNumRows) * mBlockHeight);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче