Bug 101800. Add support for text-transform:uppercase/lowercase (but not other values) on <xul:label value="whatever">. r=dholbert

This commit is contained in:
Boris Zbarsky 2014-05-23 17:32:37 -04:00
parent 873477a08e
commit 12cf0111e5
5 changed files with 58 additions and 2 deletions

View File

@ -208,7 +208,7 @@ nsTextBoxFrame::UpdateAccesskey(nsWeakFrame& aWeakThis)
if (!accesskey.Equals(mAccessKey)) {
// Need to get clean mTitle.
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, mTitle);
RecomputeTitle();
mAccessKey = accesskey;
UpdateAccessTitle();
PresContext()->PresShell()->
@ -258,7 +258,7 @@ nsTextBoxFrame::UpdateAttributes(nsIAtom* aAttribute,
}
if (aAttribute == nullptr || aAttribute == nsGkAtoms::value) {
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, mTitle);
RecomputeTitle();
doUpdateTitle = true;
}
@ -871,6 +871,43 @@ nsTextBoxFrame::UpdateAccessIndex()
}
}
void
nsTextBoxFrame::RecomputeTitle()
{
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, mTitle);
// This doesn't handle language-specific uppercasing/lowercasing
// rules, unlike textruns.
uint8_t textTransform = StyleText()->mTextTransform;
if (textTransform == NS_STYLE_TEXT_TRANSFORM_UPPERCASE) {
ToUpperCase(mTitle);
} else if (textTransform == NS_STYLE_TEXT_TRANSFORM_LOWERCASE) {
ToLowerCase(mTitle);
}
// We can't handle NS_STYLE_TEXT_TRANSFORM_CAPITALIZE because we
// have no clue about word boundaries here. We also don't handle
// NS_STYLE_TEXT_TRANSFORM_FULLWIDTH.
}
void
nsTextBoxFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
{
if (!aOldStyleContext) {
// We're just being initialized
return;
}
const nsStyleText* oldTextStyle = aOldStyleContext->PeekStyleText();
// We should really have oldTextStyle here, since we asked for our
// nsStyleText during Init(), but if it's not there for some reason
// just assume the worst and recompute mTitle.
if (!oldTextStyle ||
oldTextStyle->mTextTransform != StyleText()->mTextTransform) {
RecomputeTitle();
UpdateAccessTitle();
}
}
NS_IMETHODIMP
nsTextBoxFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState)
{

View File

@ -64,6 +64,8 @@ public:
void GetCroppedTitle(nsString& aTitle) const { aTitle = mCroppedTitle; }
virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
protected:
friend class nsAsyncAccesskeyUpdate;
friend class nsDisplayXULTextBox;
@ -73,6 +75,10 @@ protected:
void UpdateAccessTitle();
void UpdateAccessIndex();
// Recompute our title, ignoring the access key but taking into
// account text-transform.
void RecomputeTitle();
// REVIEW: SORRY! Couldn't resist devirtualizing these
void LayoutTitle(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,

View File

@ -3,3 +3,4 @@ fails-if(Android||B2G) == textbox-multiline-noresize.xul textbox-multiline-ref.x
== popup-explicit-size.xul popup-explicit-size-ref.xul
random-if(Android) == image-size.xul image-size-ref.xul
== image-scaling-min-height-1.xul image-scaling-min-height-1-ref.xul
== textbox-text-transform.xul textbox-text-transform-ref.xul

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<label value="UPPERCASE"/>
<label value="lowercase"/>
</window>

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<label style="text-transform: uppercase" value="uppercase"/>
<label style="text-transform: lowercase" value="LOWERCASE"/>
</window>