layout/xul/nsProgressMeterFrame.cpp

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 //
michael@0 7 // David Hyatt & Eric Vaughan
michael@0 8 // Netscape Communications
michael@0 9 //
michael@0 10 // See documentation in associated header file
michael@0 11 //
michael@0 12
michael@0 13 #include "nsProgressMeterFrame.h"
michael@0 14 #include "nsCSSRendering.h"
michael@0 15 #include "nsIContent.h"
michael@0 16 #include "nsPresContext.h"
michael@0 17 #include "nsGkAtoms.h"
michael@0 18 #include "nsNameSpaceManager.h"
michael@0 19 #include "nsCOMPtr.h"
michael@0 20 #include "nsBoxLayoutState.h"
michael@0 21 #include "nsIReflowCallback.h"
michael@0 22 #include "nsContentUtils.h"
michael@0 23 #include "mozilla/Attributes.h"
michael@0 24
michael@0 25 class nsReflowFrameRunnable : public nsRunnable
michael@0 26 {
michael@0 27 public:
michael@0 28 nsReflowFrameRunnable(nsIFrame* aFrame,
michael@0 29 nsIPresShell::IntrinsicDirty aIntrinsicDirty,
michael@0 30 nsFrameState aBitToAdd);
michael@0 31
michael@0 32 NS_DECL_NSIRUNNABLE
michael@0 33
michael@0 34 nsWeakFrame mWeakFrame;
michael@0 35 nsIPresShell::IntrinsicDirty mIntrinsicDirty;
michael@0 36 nsFrameState mBitToAdd;
michael@0 37 };
michael@0 38
michael@0 39 nsReflowFrameRunnable::nsReflowFrameRunnable(nsIFrame* aFrame,
michael@0 40 nsIPresShell::IntrinsicDirty aIntrinsicDirty,
michael@0 41 nsFrameState aBitToAdd)
michael@0 42 : mWeakFrame(aFrame),
michael@0 43 mIntrinsicDirty(aIntrinsicDirty),
michael@0 44 mBitToAdd(aBitToAdd)
michael@0 45 {
michael@0 46 }
michael@0 47
michael@0 48 NS_IMETHODIMP
michael@0 49 nsReflowFrameRunnable::Run()
michael@0 50 {
michael@0 51 if (mWeakFrame.IsAlive()) {
michael@0 52 mWeakFrame->PresContext()->PresShell()->
michael@0 53 FrameNeedsReflow(mWeakFrame, mIntrinsicDirty, mBitToAdd);
michael@0 54 }
michael@0 55 return NS_OK;
michael@0 56 }
michael@0 57
michael@0 58 //
michael@0 59 // NS_NewToolbarFrame
michael@0 60 //
michael@0 61 // Creates a new Toolbar frame and returns it
michael@0 62 //
michael@0 63 nsIFrame*
michael@0 64 NS_NewProgressMeterFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
michael@0 65 {
michael@0 66 return new (aPresShell) nsProgressMeterFrame(aPresShell, aContext);
michael@0 67 }
michael@0 68
michael@0 69 NS_IMPL_FRAMEARENA_HELPERS(nsProgressMeterFrame)
michael@0 70
michael@0 71 //
michael@0 72 // nsProgressMeterFrame dstr
michael@0 73 //
michael@0 74 // Cleanup, if necessary
michael@0 75 //
michael@0 76 nsProgressMeterFrame :: ~nsProgressMeterFrame ( )
michael@0 77 {
michael@0 78 }
michael@0 79
michael@0 80 class nsAsyncProgressMeterInit MOZ_FINAL : public nsIReflowCallback
michael@0 81 {
michael@0 82 public:
michael@0 83 nsAsyncProgressMeterInit(nsIFrame* aFrame) : mWeakFrame(aFrame) {}
michael@0 84
michael@0 85 virtual bool ReflowFinished() MOZ_OVERRIDE
michael@0 86 {
michael@0 87 bool shouldFlush = false;
michael@0 88 nsIFrame* frame = mWeakFrame.GetFrame();
michael@0 89 if (frame) {
michael@0 90 nsAutoScriptBlocker scriptBlocker;
michael@0 91 frame->AttributeChanged(kNameSpaceID_None, nsGkAtoms::mode, 0);
michael@0 92 shouldFlush = true;
michael@0 93 }
michael@0 94 delete this;
michael@0 95 return shouldFlush;
michael@0 96 }
michael@0 97
michael@0 98 virtual void ReflowCallbackCanceled() MOZ_OVERRIDE
michael@0 99 {
michael@0 100 delete this;
michael@0 101 }
michael@0 102
michael@0 103 nsWeakFrame mWeakFrame;
michael@0 104 };
michael@0 105
michael@0 106 NS_IMETHODIMP
michael@0 107 nsProgressMeterFrame::DoLayout(nsBoxLayoutState& aState)
michael@0 108 {
michael@0 109 if (mNeedsReflowCallback) {
michael@0 110 nsIReflowCallback* cb = new nsAsyncProgressMeterInit(this);
michael@0 111 if (cb) {
michael@0 112 PresContext()->PresShell()->PostReflowCallback(cb);
michael@0 113 }
michael@0 114 mNeedsReflowCallback = false;
michael@0 115 }
michael@0 116 return nsBoxFrame::DoLayout(aState);
michael@0 117 }
michael@0 118
michael@0 119 nsresult
michael@0 120 nsProgressMeterFrame::AttributeChanged(int32_t aNameSpaceID,
michael@0 121 nsIAtom* aAttribute,
michael@0 122 int32_t aModType)
michael@0 123 {
michael@0 124 NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
michael@0 125 "Scripts not blocked in nsProgressMeterFrame::AttributeChanged!");
michael@0 126 nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
michael@0 127 aModType);
michael@0 128 if (NS_OK != rv) {
michael@0 129 return rv;
michael@0 130 }
michael@0 131
michael@0 132 // did the progress change?
michael@0 133 bool undetermined = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mode,
michael@0 134 nsGkAtoms::undetermined, eCaseMatters);
michael@0 135 if (nsGkAtoms::mode == aAttribute ||
michael@0 136 (!undetermined &&
michael@0 137 (nsGkAtoms::value == aAttribute || nsGkAtoms::max == aAttribute))) {
michael@0 138 nsIFrame* barChild = GetFirstPrincipalChild();
michael@0 139 if (!barChild) return NS_OK;
michael@0 140 nsIFrame* remainderChild = barChild->GetNextSibling();
michael@0 141 if (!remainderChild) return NS_OK;
michael@0 142 nsCOMPtr<nsIContent> remainderContent = remainderChild->GetContent();
michael@0 143 if (!remainderContent) return NS_OK;
michael@0 144
michael@0 145 int32_t flex = 1, maxFlex = 1;
michael@0 146 if (!undetermined) {
michael@0 147 nsAutoString value, maxValue;
michael@0 148 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, value);
michael@0 149 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxValue);
michael@0 150
michael@0 151 nsresult error;
michael@0 152 flex = value.ToInteger(&error);
michael@0 153 maxFlex = maxValue.ToInteger(&error);
michael@0 154 if (NS_FAILED(error) || maxValue.IsEmpty()) {
michael@0 155 maxFlex = 100;
michael@0 156 }
michael@0 157 if (maxFlex < 1) {
michael@0 158 maxFlex = 1;
michael@0 159 }
michael@0 160 if (flex < 0) {
michael@0 161 flex = 0;
michael@0 162 }
michael@0 163 if (flex > maxFlex) {
michael@0 164 flex = maxFlex;
michael@0 165 }
michael@0 166 }
michael@0 167
michael@0 168 nsContentUtils::AddScriptRunner(new nsSetAttrRunnable(
michael@0 169 barChild->GetContent(), nsGkAtoms::flex, flex));
michael@0 170 nsContentUtils::AddScriptRunner(new nsSetAttrRunnable(
michael@0 171 remainderContent, nsGkAtoms::flex, maxFlex - flex));
michael@0 172 nsContentUtils::AddScriptRunner(new nsReflowFrameRunnable(
michael@0 173 this, nsIPresShell::eTreeChange, NS_FRAME_IS_DIRTY));
michael@0 174 }
michael@0 175 return NS_OK;
michael@0 176 }
michael@0 177
michael@0 178 #ifdef DEBUG_FRAME_DUMP
michael@0 179 nsresult
michael@0 180 nsProgressMeterFrame::GetFrameName(nsAString& aResult) const
michael@0 181 {
michael@0 182 return MakeFrameName(NS_LITERAL_STRING("ProgressMeter"), aResult);
michael@0 183 }
michael@0 184 #endif

mercurial