mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
158 lines
5.5 KiB
C++
158 lines
5.5 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
*
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at
|
|
* http://www.mozilla.org/MPL/
|
|
*
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
* for the specific language governing rights and limitations under the
|
|
* License.
|
|
*
|
|
* The Original Code is mozilla.org code.
|
|
*
|
|
* The Initial Developer of the Original Code is
|
|
* the Mozilla Foundation.
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
* the Initial Developer. All Rights Reserved.
|
|
*
|
|
* Contributor(s):
|
|
* Boris Zbarsky <bzbarsky@mit.edu> (original author)
|
|
*
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
* the provisions above, a recipient may use your version of this file under
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
*
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "RestyleTracker.h"
|
|
#include "nsCSSFrameConstructor.h"
|
|
#include "nsStyleChangeList.h"
|
|
|
|
namespace mozilla {
|
|
namespace css {
|
|
|
|
#define RESTYLE_ARRAY_STACKSIZE 128
|
|
|
|
static PLDHashOperator
|
|
CollectRestyles(nsISupports* aElement,
|
|
RestyleTracker::RestyleData& aData,
|
|
void* aRestyleArrayPtr)
|
|
{
|
|
RestyleTracker::RestyleEnumerateData** restyleArrayPtr =
|
|
static_cast<RestyleTracker::RestyleEnumerateData**>
|
|
(aRestyleArrayPtr);
|
|
RestyleTracker::RestyleEnumerateData* currentRestyle =
|
|
*restyleArrayPtr;
|
|
currentRestyle->mElement = static_cast<RestyleTracker::Element*>(aElement);
|
|
currentRestyle->mRestyleHint = aData.mRestyleHint;
|
|
currentRestyle->mChangeHint = aData.mChangeHint;
|
|
|
|
// Increment to the next slot in the array
|
|
*restyleArrayPtr = currentRestyle + 1;
|
|
|
|
return PL_DHASH_NEXT;
|
|
}
|
|
|
|
inline void
|
|
RestyleTracker::ProcessOneRestyle(Element* aElement,
|
|
nsRestyleHint aRestyleHint,
|
|
nsChangeHint aChangeHint)
|
|
{
|
|
if (aElement->GetCurrentDoc() != mFrameConstructor->mDocument) {
|
|
// Content node has been removed from our document; nothing else
|
|
// to do here
|
|
return;
|
|
}
|
|
|
|
nsIFrame* primaryFrame = aElement->GetPrimaryFrame();
|
|
if (aRestyleHint & eRestyle_Self) {
|
|
mFrameConstructor->RestyleElement(aElement, primaryFrame, aChangeHint);
|
|
} else if (aChangeHint &&
|
|
(primaryFrame ||
|
|
(aChangeHint & nsChangeHint_ReconstructFrame))) {
|
|
// Don't need to recompute style; just apply the hint
|
|
nsStyleChangeList changeList;
|
|
changeList.AppendChange(primaryFrame, aElement, aChangeHint);
|
|
mFrameConstructor->ProcessRestyledFrames(changeList);
|
|
}
|
|
|
|
if (aRestyleHint & eRestyle_LaterSiblings) {
|
|
for (nsIContent* sibling = aElement->GetNextSibling();
|
|
sibling;
|
|
sibling = sibling->GetNextSibling()) {
|
|
if (!sibling->IsElement())
|
|
continue;
|
|
|
|
mFrameConstructor->RestyleElement(sibling->AsElement(),
|
|
sibling->GetPrimaryFrame(),
|
|
NS_STYLE_HINT_NONE);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
RestyleTracker::ProcessRestyles()
|
|
{
|
|
PRUint32 count = mPendingRestyles.Count();
|
|
|
|
// Make sure to not rebuild quote or counter lists while we're
|
|
// processing restyles
|
|
mFrameConstructor->BeginUpdate();
|
|
|
|
// loop so that we process any restyle events generated by processing
|
|
while (count) {
|
|
// Use the stack if we can, otherwise fall back on heap-allocation.
|
|
nsAutoTArray<RestyleEnumerateData, RESTYLE_ARRAY_STACKSIZE> restyleArr;
|
|
RestyleEnumerateData* restylesToProcess = restyleArr.AppendElements(count);
|
|
|
|
if (!restylesToProcess) {
|
|
return;
|
|
}
|
|
|
|
RestyleEnumerateData* lastRestyle = restylesToProcess;
|
|
mPendingRestyles.Enumerate(CollectRestyles, &lastRestyle);
|
|
|
|
NS_ASSERTION(lastRestyle - restylesToProcess == PRInt32(count),
|
|
"Enumeration screwed up somehow");
|
|
|
|
// Clear the hashtable so we don't end up trying to process a restyle we're
|
|
// already processing, sending us into an infinite loop.
|
|
mPendingRestyles.Clear();
|
|
|
|
for (RestyleEnumerateData* currentRestyle = restylesToProcess;
|
|
currentRestyle != lastRestyle;
|
|
++currentRestyle) {
|
|
ProcessOneRestyle(currentRestyle->mElement,
|
|
currentRestyle->mRestyleHint,
|
|
currentRestyle->mChangeHint);
|
|
}
|
|
|
|
count = mPendingRestyles.Count();
|
|
}
|
|
|
|
// Set mInStyleRefresh to false now, since the EndUpdate call might
|
|
// add more restyles.
|
|
mFrameConstructor->mInStyleRefresh = PR_FALSE;
|
|
|
|
mFrameConstructor->EndUpdate();
|
|
|
|
#ifdef DEBUG
|
|
mFrameConstructor->mPresShell->VerifyStyleTree();
|
|
#endif
|
|
}
|
|
|
|
} // namespace css
|
|
} // namespace mozilla
|