зеркало из https://github.com/mozilla/gecko-dev.git
Bug 442419 - allow custom max for progressmeter; r=enndeakin, sr=roc
This commit is contained in:
Родитель
c37ce49fde
Коммит
a3c8811bc4
|
@ -129,15 +129,27 @@ nsProgressMeterFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|||
nsCOMPtr<nsIContent> remainderContent = remainderChild->GetContent();
|
||||
if (!remainderContent) return NS_OK;
|
||||
|
||||
nsAutoString value;
|
||||
nsAutoString value, maxValue;
|
||||
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, value);
|
||||
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxValue);
|
||||
|
||||
PRInt32 error;
|
||||
PRInt32 flex = value.ToInteger(&error);
|
||||
if (flex < 0) flex = 0;
|
||||
if (flex > 100) flex = 100;
|
||||
PRInt32 maxFlex = maxValue.ToInteger(&error);
|
||||
if (NS_FAILED(error) || maxValue.IsEmpty()) {
|
||||
maxFlex = 100;
|
||||
}
|
||||
if (maxFlex < 1) {
|
||||
maxFlex = 1;
|
||||
}
|
||||
if (flex < 0) {
|
||||
flex = 0;
|
||||
}
|
||||
if (flex > maxFlex) {
|
||||
flex = maxFlex;
|
||||
}
|
||||
|
||||
PRInt32 remainder = 100 - flex;
|
||||
PRInt32 remainder = maxFlex - flex;
|
||||
|
||||
nsAutoString leftFlex, rightFlex;
|
||||
leftFlex.AppendInt(flex);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
|
||||
|
||||
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<progressmeter value="50"/> <!-- default is max = 100 -->
|
||||
</window>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
|
||||
|
||||
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<progressmeter max="198" value="99"/> <!-- 50% -->
|
||||
</window>
|
||||
|
|
@ -0,0 +1 @@
|
|||
== bug-442419-progressmeter-max.xul bug-442419-progressmeter-max-ref.xul
|
|
@ -22,16 +22,17 @@
|
|||
<property name="value" onget="return this.getAttribute('value') || '0';">
|
||||
<setter><![CDATA[
|
||||
var p = Math.round(val);
|
||||
var max = Math.round(this.max);
|
||||
if (p < 0)
|
||||
p = 0;
|
||||
else if (p > 100)
|
||||
p = 100;
|
||||
else if (p > max)
|
||||
p = max;
|
||||
var c = this.value;
|
||||
if (p != c) {
|
||||
var delta = p - c;
|
||||
if (delta < 0)
|
||||
delta = -delta;
|
||||
if (delta > 3 || p == 0 || p == 100) {
|
||||
if (delta > 3 || p == 0 || p == max) {
|
||||
this.setAttribute("value", p);
|
||||
// Fire DOM event so that accessible value change events occur
|
||||
var event = document.createEvent('Events');
|
||||
|
@ -43,6 +44,11 @@
|
|||
return val;
|
||||
]]></setter>
|
||||
</property>
|
||||
<property name="max"
|
||||
onget="return this.getAttribute('max') || '100';"
|
||||
onset="this.setAttribute("max", isNaN(val) ? 100 : Math.max(val, 1);
|
||||
this.value = this.value;
|
||||
return val;" />
|
||||
|
||||
<property name="accessibleType" readonly="true">
|
||||
<getter>
|
||||
|
|
|
@ -100,7 +100,7 @@ protected:
|
|||
PRInt32 inState);
|
||||
void DrawProgress(CGContextRef context, const HIRect& inBoxRect,
|
||||
PRBool inIsIndeterminate, PRBool inIsHorizontal,
|
||||
PRInt32 inValue, nsIFrame* aFrame);
|
||||
PRInt32 inValue, PRInt32 inMaxValue, nsIFrame* aFrame);
|
||||
void DrawTab(CGContextRef context, const HIRect& inBoxRect,
|
||||
PRBool inIsDisabled, PRBool inIsFrontmost,
|
||||
PRBool inIsHorizontal, PRBool inTabBottom,
|
||||
|
|
|
@ -850,7 +850,8 @@ nsNativeThemeCocoa::DrawFrame(CGContextRef cgContext, HIThemeFrameKind inKind,
|
|||
void
|
||||
nsNativeThemeCocoa::DrawProgress(CGContextRef cgContext, const HIRect& inBoxRect,
|
||||
PRBool inIsIndeterminate, PRBool inIsHorizontal,
|
||||
PRInt32 inValue, nsIFrame* aFrame)
|
||||
PRInt32 inValue, PRInt32 inMaxValue,
|
||||
nsIFrame* aFrame)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
|
@ -863,7 +864,7 @@ nsNativeThemeCocoa::DrawProgress(CGContextRef cgContext, const HIRect& inBoxRect
|
|||
tdi.kind = inIsIndeterminate ? kThemeMediumIndeterminateBar: kThemeMediumProgressBar;
|
||||
tdi.bounds = inBoxRect;
|
||||
tdi.min = 0;
|
||||
tdi.max = 100;
|
||||
tdi.max = inMaxValue;
|
||||
tdi.value = inValue;
|
||||
tdi.attributes = inIsHorizontal ? kThemeTrackHorizontal : 0;
|
||||
tdi.enableState = FrameIsInActiveWindow(aFrame) ? kThemeTrackActive : kThemeTrackInactive;
|
||||
|
@ -1431,12 +1432,14 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsIRenderingContext* aContext, nsIFrame
|
|||
|
||||
case NS_THEME_PROGRESSBAR:
|
||||
DrawProgress(cgContext, macRect, IsIndeterminateProgress(aFrame),
|
||||
PR_TRUE, GetProgressValue(aFrame), aFrame);
|
||||
PR_TRUE, GetProgressValue(aFrame),
|
||||
GetProgressMaxValue(aFrame), aFrame);
|
||||
break;
|
||||
|
||||
case NS_THEME_PROGRESSBAR_VERTICAL:
|
||||
DrawProgress(cgContext, macRect, IsIndeterminateProgress(aFrame),
|
||||
PR_FALSE, GetProgressValue(aFrame), aFrame);
|
||||
PR_FALSE, GetProgressValue(aFrame),
|
||||
GetProgressMaxValue(aFrame), aFrame);
|
||||
break;
|
||||
|
||||
case NS_THEME_PROGRESSBAR_CHUNK:
|
||||
|
|
|
@ -133,6 +133,10 @@ class nsNativeTheme
|
|||
PRInt32 GetProgressValue(nsIFrame* aFrame) {
|
||||
return CheckIntAttr(aFrame, nsWidgetAtoms::value, 0);
|
||||
}
|
||||
|
||||
PRInt32 GetProgressMaxValue(nsIFrame* aFrame) {
|
||||
return PR_MAX(CheckIntAttr(aFrame, nsWidgetAtoms::max, 100), 1);
|
||||
}
|
||||
|
||||
// textfield:
|
||||
PRBool IsReadOnly(nsIFrame* aFrame) {
|
||||
|
|
|
@ -85,6 +85,7 @@ WIDGET_ATOM(input, "input")
|
|||
WIDGET_ATOM(key, "key") // The key element / attribute
|
||||
WIDGET_ATOM(label, "label")
|
||||
WIDGET_ATOM(lasttab, "last-tab")
|
||||
WIDGET_ATOM(max, "max")
|
||||
WIDGET_ATOM(maxpos, "maxpos")
|
||||
WIDGET_ATOM(menu, "menu") // Represents an XP menu
|
||||
WIDGET_ATOM(menuitem, "menuitem") // Represents an XP menu item
|
||||
|
|
Загрузка…
Ссылка в новой задаче