2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-02-04 01:34:15 +00:00
|
|
|
|
|
|
|
//
|
2000-03-15 03:16:43 +00:00
|
|
|
// David Hyatt & Eric Vaughan
|
1999-02-04 01:34:15 +00:00
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsProgressMeterFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
1999-04-13 01:15:16 +00:00
|
|
|
#include "nsIContent.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1999-02-04 01:34:15 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2004-09-17 18:36:30 +00:00
|
|
|
#include "nsBoxLayoutState.h"
|
2007-10-05 19:06:54 +00:00
|
|
|
#include "nsIReflowCallback.h"
|
2009-01-19 09:29:48 +00:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-11 04:03:55 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-30 21:26:04 +00:00
|
|
|
|
|
|
|
class nsReflowFrameRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsReflowFrameRunnable(nsIFrame* aFrame,
|
|
|
|
nsIPresShell::IntrinsicDirty aIntrinsicDirty,
|
|
|
|
nsFrameState aBitToAdd);
|
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
nsWeakFrame mWeakFrame;
|
|
|
|
nsIPresShell::IntrinsicDirty mIntrinsicDirty;
|
|
|
|
nsFrameState mBitToAdd;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsReflowFrameRunnable::nsReflowFrameRunnable(nsIFrame* aFrame,
|
|
|
|
nsIPresShell::IntrinsicDirty aIntrinsicDirty,
|
|
|
|
nsFrameState aBitToAdd)
|
|
|
|
: mWeakFrame(aFrame),
|
|
|
|
mIntrinsicDirty(aIntrinsicDirty),
|
|
|
|
mBitToAdd(aBitToAdd)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsReflowFrameRunnable::Run()
|
|
|
|
{
|
|
|
|
if (mWeakFrame.IsAlive()) {
|
|
|
|
mWeakFrame->PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(mWeakFrame, mIntrinsicDirty, mBitToAdd);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-04 01:34:15 +00:00
|
|
|
//
|
|
|
|
// NS_NewToolbarFrame
|
|
|
|
//
|
2005-10-26 21:46:39 +00:00
|
|
|
// Creates a new Toolbar frame and returns it
|
1999-02-04 01:34:15 +00:00
|
|
|
//
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewProgressMeterFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-02-04 01:34:15 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsProgressMeterFrame(aPresShell, aContext);
|
2009-09-12 16:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsProgressMeterFrame)
|
1999-02-04 01:34:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsProgressMeterFrame dstr
|
|
|
|
//
|
|
|
|
// Cleanup, if necessary
|
|
|
|
//
|
|
|
|
nsProgressMeterFrame :: ~nsProgressMeterFrame ( )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-11 04:03:55 +00:00
|
|
|
class nsAsyncProgressMeterInit MOZ_FINAL : public nsIReflowCallback
|
2007-10-05 19:06:54 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAsyncProgressMeterInit(nsIFrame* aFrame) : mWeakFrame(aFrame) {}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool ReflowFinished()
|
2007-10-05 19:06:54 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool shouldFlush = false;
|
2007-10-05 19:06:54 +00:00
|
|
|
nsIFrame* frame = mWeakFrame.GetFrame();
|
|
|
|
if (frame) {
|
2009-02-23 14:15:31 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2012-04-27 07:42:10 +00:00
|
|
|
frame->AttributeChanged(kNameSpaceID_None, nsGkAtoms::mode, 0);
|
2011-10-17 14:59:28 +00:00
|
|
|
shouldFlush = true;
|
2007-10-05 19:06:54 +00:00
|
|
|
}
|
|
|
|
delete this;
|
|
|
|
return shouldFlush;
|
|
|
|
}
|
|
|
|
|
2007-12-01 07:22:44 +00:00
|
|
|
virtual void ReflowCallbackCanceled()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2007-10-05 19:06:54 +00:00
|
|
|
nsWeakFrame mWeakFrame;
|
|
|
|
};
|
|
|
|
|
1999-02-04 01:34:15 +00:00
|
|
|
NS_IMETHODIMP
|
2007-10-05 19:06:54 +00:00
|
|
|
nsProgressMeterFrame::DoLayout(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
if (mNeedsReflowCallback) {
|
|
|
|
nsIReflowCallback* cb = new nsAsyncProgressMeterInit(this);
|
|
|
|
if (cb) {
|
|
|
|
PresContext()->PresShell()->PostReflowCallback(cb);
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mNeedsReflowCallback = false;
|
2007-10-05 19:06:54 +00:00
|
|
|
}
|
|
|
|
return nsBoxFrame::DoLayout(aState);
|
1999-02-04 01:34:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsProgressMeterFrame::AttributeChanged(int32_t aNameSpaceID,
|
2003-07-11 21:16:12 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
1999-02-04 01:34:15 +00:00
|
|
|
{
|
2009-02-23 14:15:31 +00:00
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Scripts not blocked in nsProgressMeterFrame::AttributeChanged!");
|
2005-09-07 16:49:21 +00:00
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
1999-02-04 01:34:15 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// did the progress change?
|
2012-04-27 07:42:10 +00:00
|
|
|
bool undetermined = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mode,
|
|
|
|
nsGkAtoms::undetermined, eCaseMatters);
|
|
|
|
if (nsGkAtoms::mode == aAttribute ||
|
|
|
|
(!undetermined &&
|
|
|
|
(nsGkAtoms::value == aAttribute || nsGkAtoms::max == aAttribute))) {
|
2011-08-24 20:54:30 +00:00
|
|
|
nsIFrame* barChild = GetFirstPrincipalChild();
|
2001-12-21 01:41:32 +00:00
|
|
|
if (!barChild) return NS_OK;
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIFrame* remainderChild = barChild->GetNextSibling();
|
2001-12-21 01:41:32 +00:00
|
|
|
if (!remainderChild) return NS_OK;
|
2006-09-03 20:25:58 +00:00
|
|
|
nsCOMPtr<nsIContent> remainderContent = remainderChild->GetContent();
|
|
|
|
if (!remainderContent) return NS_OK;
|
1999-02-04 01:34:15 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t flex = 1, maxFlex = 1;
|
2012-04-27 07:42:10 +00:00
|
|
|
if (!undetermined) {
|
|
|
|
nsAutoString value, maxValue;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, value);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxValue);
|
1999-03-06 19:43:13 +00:00
|
|
|
|
2012-04-27 07:42:10 +00:00
|
|
|
nsresult error;
|
|
|
|
flex = value.ToInteger(&error);
|
|
|
|
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;
|
|
|
|
}
|
2008-10-30 09:34:23 +00:00
|
|
|
}
|
1999-03-06 19:43:13 +00:00
|
|
|
|
2009-01-19 09:29:48 +00:00
|
|
|
nsContentUtils::AddScriptRunner(new nsSetAttrRunnable(
|
2010-05-03 13:23:36 +00:00
|
|
|
barChild->GetContent(), nsGkAtoms::flex, flex));
|
2009-01-19 09:29:48 +00:00
|
|
|
nsContentUtils::AddScriptRunner(new nsSetAttrRunnable(
|
2010-05-03 13:23:36 +00:00
|
|
|
remainderContent, nsGkAtoms::flex, maxFlex - flex));
|
2009-01-19 09:29:48 +00:00
|
|
|
nsContentUtils::AddScriptRunner(new nsReflowFrameRunnable(
|
|
|
|
this, nsIPresShell::eTreeChange, NS_FRAME_IS_DIRTY));
|
1999-02-04 01:34:15 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-11 23:55:15 +00:00
|
|
|
|
2012-06-25 19:59:42 +00:00
|
|
|
#ifdef DEBUG
|
2000-04-11 23:55:15 +00:00
|
|
|
NS_IMETHODIMP
|
2001-11-14 01:33:42 +00:00
|
|
|
nsProgressMeterFrame::GetFrameName(nsAString& aResult) const
|
2000-04-11 23:55:15 +00:00
|
|
|
{
|
2001-11-14 01:33:42 +00:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ProgressMeter"), aResult);
|
2000-04-11 23:55:15 +00:00
|
|
|
}
|
|
|
|
#endif
|