Bug 1085311 - Vertical writing-mode support for single-line <input> fields. r=jfkthame

This commit is contained in:
Xidorn Quan [:xidorn] 2014-11-04 15:45:00 +01:00
Родитель 78d081c21d
Коммит 81efa1ff0f
6 изменённых файлов: 54 добавлений и 44 удалений

Просмотреть файл

@ -143,8 +143,9 @@ nsTextControlFrame::GetType() const
nsresult
nsTextControlFrame::CalcIntrinsicSize(nsRenderingContext* aRenderingContext,
nsSize& aIntrinsicSize,
float aFontSizeInflation)
WritingMode aWM,
LogicalSize& aIntrinsicSize,
float aFontSizeInflation)
{
// Get leading and the Average/MaxAdvance char width
nscoord lineHeight = 0;
@ -165,7 +166,7 @@ nsTextControlFrame::CalcIntrinsicSize(nsRenderingContext* aRenderingContext,
// Set the width equal to the width in characters
int32_t cols = GetCols();
aIntrinsicSize.width = cols * charWidth;
aIntrinsicSize.ISize(aWM) = cols * charWidth;
// To better match IE, take the maximum character width(in twips) and remove
// 4 pixels add this on as additional padding(internalPadding). But only do
@ -182,12 +183,12 @@ nsTextControlFrame::CalcIntrinsicSize(nsRenderingContext* aRenderingContext,
internalPadding += t - rest;
}
// Now add the extra padding on (so that small input sizes work well)
aIntrinsicSize.width += internalPadding;
aIntrinsicSize.ISize(aWM) += internalPadding;
} else {
// This is to account for the anonymous <br> having a 1 twip width
// in Full Standards mode, see BRFrame::Reflow and bug 228752.
if (PresContext()->CompatibilityMode() == eCompatibility_FullStandards) {
aIntrinsicSize.width += 1;
aIntrinsicSize.ISize(aWM) += 1;
}
}
@ -197,14 +198,14 @@ nsTextControlFrame::CalcIntrinsicSize(nsRenderingContext* aRenderingContext,
if (eStyleUnit_Coord == lsCoord.GetUnit()) {
nscoord letterSpacing = lsCoord.GetCoordValue();
if (letterSpacing != 0) {
aIntrinsicSize.width += cols * letterSpacing;
aIntrinsicSize.ISize(aWM) += cols * letterSpacing;
}
}
}
// Set the height equal to total number of rows (times the height of each
// line, of course)
aIntrinsicSize.height = lineHeight * GetRows();
aIntrinsicSize.BSize(aWM) = lineHeight * GetRows();
// Add in the size of the scrollbars for textarea
if (IsTextArea()) {
@ -217,9 +218,8 @@ nsTextControlFrame::CalcIntrinsicSize(nsRenderingContext* aRenderingContext,
nsMargin scrollbarSizes =
scrollableFrame->GetDesiredScrollbarSizes(PresContext(), aRenderingContext);
aIntrinsicSize.width += scrollbarSizes.LeftRight();
aIntrinsicSize.height += scrollbarSizes.TopBottom();;
aIntrinsicSize.Width(aWM) += scrollbarSizes.LeftRight();
aIntrinsicSize.Height(aWM) += scrollbarSizes.TopBottom();
}
}
@ -425,10 +425,11 @@ nsTextControlFrame::GetPrefISize(nsRenderingContext* aRenderingContext)
DISPLAY_PREF_WIDTH(this, result);
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
nsSize autoSize;
CalcIntrinsicSize(aRenderingContext, autoSize, inflation);
WritingMode wm = GetWritingMode();
LogicalSize autoSize(wm);
CalcIntrinsicSize(aRenderingContext, wm, autoSize, inflation);
return autoSize.width;
return autoSize.ISize(wm);
}
nscoord
@ -454,29 +455,32 @@ nsTextControlFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
bool aShrinkWrap)
{
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
// XXX CalcIntrinsicSize needs to be updated to use a LogicalSize
nsSize autoSize;
nsresult rv = CalcIntrinsicSize(aRenderingContext, autoSize, inflation);
LogicalSize autoSize(aWM);
nsresult rv = CalcIntrinsicSize(aRenderingContext, aWM, autoSize, inflation);
if (NS_FAILED(rv)) {
// What now?
autoSize.SizeTo(0, 0);
autoSize.SizeTo(aWM, 0, 0);
}
#ifdef DEBUG
// Note: Ancestor ComputeAutoSize only computes a width if we're auto-width
else if (StylePosition()->mWidth.GetUnit() == eStyleUnit_Auto) {
LogicalSize ancestorAutoSize =
nsContainerFrame::ComputeAutoSize(aRenderingContext, aWM,
aCBSize, aAvailableISize,
aMargin, aBorder,
aPadding, aShrinkWrap);
// Disabled when there's inflation; see comment in GetPrefSize.
NS_ASSERTION(inflation != 1.0f ||
ancestorAutoSize.Width(aWM) == autoSize.width,
else {
const nsStyleCoord& inlineStyleCoord =
aWM.IsVertical() ? StylePosition()->mHeight : StylePosition()->mWidth;
if (inlineStyleCoord.GetUnit() == eStyleUnit_Auto) {
LogicalSize ancestorAutoSize =
nsContainerFrame::ComputeAutoSize(aRenderingContext, aWM,
aCBSize, aAvailableISize,
aMargin, aBorder,
aPadding, aShrinkWrap);
// Disabled when there's inflation; see comment in GetPrefSize.
MOZ_ASSERT(inflation != 1.0f ||
ancestorAutoSize.ISize(aWM) == autoSize.ISize(aWM),
"Incorrect size computed by ComputeAutoSize?");
}
}
#endif
return LogicalSize(aWM, autoSize);
return autoSize;
}
void

Просмотреть файл

@ -272,8 +272,9 @@ protected:
// etc. Just the size of our actual area for the text (and the scrollbars,
// for <textarea>).
nsresult CalcIntrinsicSize(nsRenderingContext* aRenderingContext,
nsSize& aIntrinsicSize,
float aFontSizeInflation);
mozilla::WritingMode aWM,
mozilla::LogicalSize& aIntrinsicSize,
float aFontSizeInflation);
nsresult ScrollSelectionIntoView() MOZ_OVERRIDE;

Просмотреть файл

@ -3800,9 +3800,13 @@ nsFrame::GetCursor(const nsPoint& aPoint,
// If this is editable, I-beam cursor is better for most elements.
aCursor.mCursor =
(mContent && mContent->IsEditable())
? GetWritingMode().IsVertical()
? NS_STYLE_CURSOR_VERTICAL_TEXT : NS_STYLE_CURSOR_TEXT
: NS_STYLE_CURSOR_DEFAULT;
? NS_STYLE_CURSOR_TEXT : NS_STYLE_CURSOR_DEFAULT;
}
if (NS_STYLE_CURSOR_TEXT == aCursor.mCursor &&
GetWritingMode().IsVertical()) {
// Per CSS UI spec, UA may treat value 'text' as
// 'vertical-text' for vertical text.
aCursor.mCursor = NS_STYLE_CURSOR_VERTICAL_TEXT;
}
return NS_OK;

Просмотреть файл

@ -2478,7 +2478,7 @@ GetNormalLineHeight(nsFontMetrics* aFontMetrics)
static inline nscoord
ComputeLineHeight(nsStyleContext* aStyleContext,
nscoord aBlockHeight,
nscoord aBlockBSize,
float aFontSizeInflation)
{
const nsStyleCoord& lhCoord = aStyleContext->StyleText()->mLineHeight;
@ -2505,8 +2505,8 @@ ComputeLineHeight(nsStyleContext* aStyleContext,
if (lhCoord.GetUnit() == eStyleUnit_Enumerated) {
NS_ASSERTION(lhCoord.GetIntValue() == NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT,
"bad line-height value");
if (aBlockHeight != NS_AUTOHEIGHT) {
return aBlockHeight;
if (aBlockBSize != NS_AUTOHEIGHT) {
return aBlockBSize;
}
}
@ -2520,24 +2520,24 @@ ComputeLineHeight(nsStyleContext* aStyleContext,
nscoord
nsHTMLReflowState::CalcLineHeight() const
{
nscoord blockHeight =
nsLayoutUtils::IsNonWrapperBlock(frame) ? ComputedHeight() :
(mCBReflowState ? mCBReflowState->ComputedHeight() : NS_AUTOHEIGHT);
nscoord blockBSize =
nsLayoutUtils::IsNonWrapperBlock(frame) ? ComputedBSize() :
(mCBReflowState ? mCBReflowState->ComputedBSize() : NS_AUTOHEIGHT);
return CalcLineHeight(frame->GetContent(), frame->StyleContext(), blockHeight,
return CalcLineHeight(frame->GetContent(), frame->StyleContext(), blockBSize,
nsLayoutUtils::FontSizeInflationFor(frame));
}
/* static */ nscoord
nsHTMLReflowState::CalcLineHeight(nsIContent* aContent,
nsStyleContext* aStyleContext,
nscoord aBlockHeight,
nscoord aBlockBSize,
float aFontSizeInflation)
{
NS_PRECONDITION(aStyleContext, "Must have a style context");
nscoord lineHeight =
ComputeLineHeight(aStyleContext, aBlockHeight, aFontSizeInflation);
ComputeLineHeight(aStyleContext, aBlockBSize, aFontSizeInflation);
NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up");

Просмотреть файл

@ -637,7 +637,7 @@ public:
*/
static nscoord CalcLineHeight(nsIContent* aContent,
nsStyleContext* aStyleContext,
nscoord aBlockHeight,
nscoord aBlockBSize,
float aFontSizeInflation);

Просмотреть файл

@ -4242,9 +4242,10 @@ nsTextFrame::GetCursor(const nsPoint& aPoint,
}
}
}
return NS_OK;
} else {
return nsFrame::GetCursor(aPoint, aCursor);
}
return NS_OK;
}
nsIFrame*