2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 04:34:15 +03:00
|
|
|
|
|
|
|
//
|
2000-03-15 06:16:43 +03:00
|
|
|
// David Hyatt & Eric Vaughan
|
1999-02-04 04:34:15 +03:00
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsProgressMeterFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
1999-04-13 05:15:16 +04:00
|
|
|
#include "nsIContent.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.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-10 01:02:40 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2004-09-17 22:36:30 +04:00
|
|
|
#include "nsBoxLayoutState.h"
|
2007-10-05 23:06:54 +04:00
|
|
|
#include "nsIReflowCallback.h"
|
2009-01-19 12:29:48 +03:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-11 08:03:55 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-10-01 01:26:04 +04: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 04:34:15 +03:00
|
|
|
//
|
|
|
|
// NS_NewToolbarFrame
|
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
// Creates a new Toolbar frame and returns it
|
1999-02-04 04:34:15 +03:00
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewProgressMeterFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-02-04 04:34:15 +03:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsProgressMeterFrame(aPresShell, aContext);
|
2009-09-12 20:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsProgressMeterFrame)
|
1999-02-04 04:34:15 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsProgressMeterFrame dstr
|
|
|
|
//
|
|
|
|
// Cleanup, if necessary
|
|
|
|
//
|
|
|
|
nsProgressMeterFrame :: ~nsProgressMeterFrame ( )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-11 08:03:55 +04:00
|
|
|
class nsAsyncProgressMeterInit MOZ_FINAL : public nsIReflowCallback
|
2007-10-05 23:06:54 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAsyncProgressMeterInit(nsIFrame* aFrame) : mWeakFrame(aFrame) {}
|
|
|
|
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual bool ReflowFinished() MOZ_OVERRIDE
|
2007-10-05 23:06:54 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shouldFlush = false;
|
2007-10-05 23:06:54 +04:00
|
|
|
nsIFrame* frame = mWeakFrame.GetFrame();
|
|
|
|
if (frame) {
|
2009-02-23 17:15:31 +03:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2012-04-27 11:42:10 +04:00
|
|
|
frame->AttributeChanged(kNameSpaceID_None, nsGkAtoms::mode, 0);
|
2011-10-17 18:59:28 +04:00
|
|
|
shouldFlush = true;
|
2007-10-05 23:06:54 +04:00
|
|
|
}
|
|
|
|
delete this;
|
|
|
|
return shouldFlush;
|
|
|
|
}
|
|
|
|
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual void ReflowCallbackCanceled() MOZ_OVERRIDE
|
2007-12-01 10:22:44 +03:00
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2007-10-05 23:06:54 +04:00
|
|
|
nsWeakFrame mWeakFrame;
|
|
|
|
};
|
|
|
|
|
1999-02-04 04:34:15 +03:00
|
|
|
NS_IMETHODIMP
|
2007-10-05 23:06:54 +04:00
|
|
|
nsProgressMeterFrame::DoLayout(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
if (mNeedsReflowCallback) {
|
|
|
|
nsIReflowCallback* cb = new nsAsyncProgressMeterInit(this);
|
|
|
|
if (cb) {
|
|
|
|
PresContext()->PresShell()->PostReflowCallback(cb);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsReflowCallback = false;
|
2007-10-05 23:06:54 +04:00
|
|
|
}
|
|
|
|
return nsBoxFrame::DoLayout(aState);
|
1999-02-04 04:34:15 +03:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsProgressMeterFrame::AttributeChanged(int32_t aNameSpaceID,
|
2003-07-12 01:16:12 +04:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
1999-02-04 04:34:15 +03:00
|
|
|
{
|
2009-02-23 17:15:31 +03:00
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Scripts not blocked in nsProgressMeterFrame::AttributeChanged!");
|
2005-09-07 20:49:21 +04:00
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
1999-02-04 04:34:15 +03:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// did the progress change?
|
2012-04-27 11:42:10 +04: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-25 00:54:30 +04:00
|
|
|
nsIFrame* barChild = GetFirstPrincipalChild();
|
2001-12-21 04:41:32 +03:00
|
|
|
if (!barChild) return NS_OK;
|
2003-08-04 16:39:51 +04:00
|
|
|
nsIFrame* remainderChild = barChild->GetNextSibling();
|
2001-12-21 04:41:32 +03:00
|
|
|
if (!remainderChild) return NS_OK;
|
2006-09-04 00:25:58 +04:00
|
|
|
nsCOMPtr<nsIContent> remainderContent = remainderChild->GetContent();
|
|
|
|
if (!remainderContent) return NS_OK;
|
1999-02-04 04:34:15 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t flex = 1, maxFlex = 1;
|
2012-04-27 11:42:10 +04:00
|
|
|
if (!undetermined) {
|
|
|
|
nsAutoString value, maxValue;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, value);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxValue);
|
1999-03-06 22:43:13 +03:00
|
|
|
|
2012-04-27 11:42:10 +04: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 12:34:23 +03:00
|
|
|
}
|
1999-03-06 22:43:13 +03:00
|
|
|
|
2009-01-19 12:29:48 +03:00
|
|
|
nsContentUtils::AddScriptRunner(new nsSetAttrRunnable(
|
2010-05-03 17:23:36 +04:00
|
|
|
barChild->GetContent(), nsGkAtoms::flex, flex));
|
2009-01-19 12:29:48 +03:00
|
|
|
nsContentUtils::AddScriptRunner(new nsSetAttrRunnable(
|
2010-05-03 17:23:36 +04:00
|
|
|
remainderContent, nsGkAtoms::flex, maxFlex - flex));
|
2009-01-19 12:29:48 +03:00
|
|
|
nsContentUtils::AddScriptRunner(new nsReflowFrameRunnable(
|
|
|
|
this, nsIPresShell::eTreeChange, NS_FRAME_IS_DIRTY));
|
1999-02-04 04:34:15 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-12 03:55:15 +04:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2001-11-14 04:33:42 +03:00
|
|
|
nsProgressMeterFrame::GetFrameName(nsAString& aResult) const
|
2000-04-12 03:55:15 +04:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ProgressMeter"), aResult);
|
2000-04-12 03:55:15 +04:00
|
|
|
}
|
|
|
|
#endif
|