2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
|
|
|
/* ***** 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 Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of 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 ***** */
|
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
// How boxes layout
|
|
|
|
// ----------------
|
|
|
|
// Boxes layout a bit differently than html. html does a bottom up layout. Where boxes do a top down.
|
|
|
|
// 1) First thing a box does it goes out and askes each child for its min, max, and preferred sizes.
|
|
|
|
// 2) It then adds them up to determine its size.
|
|
|
|
// 3) If the box was asked to layout it self intrinically it will layout its children at their preferred size
|
|
|
|
// otherwise it will layout the child at the size it was told to. It will squeeze or stretch its children if
|
|
|
|
// Necessary.
|
|
|
|
//
|
|
|
|
// However there is a catch. Some html components like block frames can not determine their preferred size.
|
|
|
|
// this is their size if they were laid out intrinsically. So the box will flow the child to determine this can
|
|
|
|
// cache the value.
|
|
|
|
|
|
|
|
// Boxes and Incremental Reflow
|
|
|
|
// ----------------------------
|
|
|
|
// Boxes layout out top down by adding up their children's min, max, and preferred sizes. Only problem is if a incremental
|
|
|
|
// reflow occurs. The preferred size of a child deep in the hierarchy could change. And this could change
|
|
|
|
// any number of syblings around the box. Basically any children in the reflow chain must have their caches cleared
|
|
|
|
// so when asked for there current size they can relayout themselves.
|
|
|
|
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIBoxLayout.h"
|
|
|
|
#include "nsSprocketLayout.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsTransform2D.h"
|
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
// Needed for Print Preview
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
|
|
|
|
//define DEBUG_REDRAW
|
|
|
|
|
|
|
|
#define DEBUG_SPRING_SIZE 8
|
|
|
|
#define DEBUG_BORDER_SIZE 2
|
|
|
|
#define COIL_SIZE 8
|
|
|
|
|
|
|
|
//#define TEST_SANITY
|
|
|
|
|
|
|
|
#ifdef DEBUG_rods
|
|
|
|
//#define DO_NOISY_REFLOW
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PRBool nsBoxFrame::gDebug = PR_FALSE;
|
|
|
|
nsIBox* nsBoxFrame::mDebugChild = nsnull;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot, nsIBoxLayout* aLayoutManager)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsBoxFrame(aPresShell, aContext, aIsRoot, aLayoutManager);
|
2009-09-12 09:49:24 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-19 10:31:33 -08:00
|
|
|
nsIFrame*
|
|
|
|
NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsBoxFrame(aPresShell, aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsBoxFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBoxFrame::nsBoxFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
PRBool aIsRoot,
|
|
|
|
nsIBoxLayout* aLayoutManager) :
|
2007-06-18 16:22:46 -07:00
|
|
|
nsContainerFrame(aContext),
|
|
|
|
mMouseThrough(unset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mState |= NS_STATE_IS_HORIZONTAL;
|
|
|
|
mState |= NS_STATE_AUTO_STRETCH;
|
|
|
|
|
|
|
|
if (aIsRoot)
|
|
|
|
mState |= NS_STATE_IS_ROOT;
|
|
|
|
|
|
|
|
mValign = vAlign_Top;
|
|
|
|
mHalign = hAlign_Left;
|
|
|
|
|
|
|
|
// if no layout manager specified us the static sprocket layout
|
|
|
|
nsCOMPtr<nsIBoxLayout> layout = aLayoutManager;
|
|
|
|
|
|
|
|
if (layout == nsnull) {
|
|
|
|
NS_NewSprocketLayout(aPresShell, layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLayoutManager(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBoxFrame::~nsBoxFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::SetInitialChildList(nsIAtom* aListName,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult r = nsContainerFrame::SetInitialChildList(aListName, aChildList);
|
|
|
|
if (r == NS_OK) {
|
|
|
|
// initialize our list of infos.
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
CheckBoxOrder(state);
|
|
|
|
if (mLayoutManager)
|
|
|
|
mLayoutManager->ChildrenSet(this, state, mFrames.FirstChild());
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Warning add child failed!!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-10-13 15:03:28 -07:00
|
|
|
/* virtual */ void
|
2008-10-26 03:11:34 -07:00
|
|
|
nsBoxFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-26 03:11:34 -07:00
|
|
|
nsContainerFrame::DidSetStyleContext(aOldStyleContext);
|
2008-10-13 15:03:28 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// The values that CacheAttributes() computes depend on our style,
|
|
|
|
// so we need to recompute them here...
|
|
|
|
CacheAttributes();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize us. This is a good time to get the alignment of the box
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-05-13 17:42:38 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
MarkIntrinsicWidthsDirty();
|
|
|
|
|
|
|
|
CacheAttributes();
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
// if we are root and this
|
|
|
|
if (mState & NS_STATE_IS_ROOT)
|
|
|
|
GetDebugPref(GetPresContext());
|
|
|
|
#endif
|
|
|
|
|
2007-06-18 16:22:46 -07:00
|
|
|
mMouseThrough = unset;
|
|
|
|
|
|
|
|
UpdateMouseThrough();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// register access key
|
|
|
|
rv = RegUnregAccessKey(PR_TRUE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-06-18 16:22:46 -07:00
|
|
|
void nsBoxFrame::UpdateMouseThrough()
|
|
|
|
{
|
|
|
|
if (mContent) {
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::never, &nsGkAtoms::always, nsnull};
|
|
|
|
static const eMouseThrough values[] = {never, always};
|
|
|
|
PRInt32 index = mContent->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::mousethrough, strings, eCaseMatters);
|
|
|
|
if (index >= 0) {
|
|
|
|
mMouseThrough = values[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsBoxFrame::GetMouseThrough() const
|
|
|
|
{
|
|
|
|
switch(mMouseThrough)
|
|
|
|
{
|
|
|
|
case always:
|
|
|
|
return PR_TRUE;
|
|
|
|
case never:
|
|
|
|
return PR_FALSE;
|
|
|
|
case unset:
|
|
|
|
if (mParent && mParent->IsBoxFrame())
|
|
|
|
return mParent->GetMouseThrough();
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsBoxFrame::CacheAttributes()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
printf("Caching: ");
|
|
|
|
DumpBox(stdout);
|
|
|
|
printf("\n");
|
|
|
|
*/
|
|
|
|
|
|
|
|
mValign = vAlign_Top;
|
|
|
|
mHalign = hAlign_Left;
|
|
|
|
|
|
|
|
PRBool orient = PR_FALSE;
|
|
|
|
GetInitialOrientation(orient);
|
|
|
|
if (orient)
|
|
|
|
mState |= NS_STATE_IS_HORIZONTAL;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_IS_HORIZONTAL;
|
|
|
|
|
|
|
|
PRBool normal = PR_TRUE;
|
|
|
|
GetInitialDirection(normal);
|
|
|
|
if (normal)
|
|
|
|
mState |= NS_STATE_IS_DIRECTION_NORMAL;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_IS_DIRECTION_NORMAL;
|
|
|
|
|
|
|
|
GetInitialVAlignment(mValign);
|
|
|
|
GetInitialHAlignment(mHalign);
|
|
|
|
|
|
|
|
PRBool equalSize = PR_FALSE;
|
|
|
|
GetInitialEqualSize(equalSize);
|
|
|
|
if (equalSize)
|
|
|
|
mState |= NS_STATE_EQUAL_SIZE;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_EQUAL_SIZE;
|
|
|
|
|
2007-10-09 17:00:05 -07:00
|
|
|
PRBool autostretch = !!(mState & NS_STATE_AUTO_STRETCH);
|
2007-03-22 10:30:00 -07:00
|
|
|
GetInitialAutoStretch(autostretch);
|
|
|
|
if (autostretch)
|
|
|
|
mState |= NS_STATE_AUTO_STRETCH;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_AUTO_STRETCH;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PRBool debug = mState & NS_STATE_SET_TO_DEBUG;
|
|
|
|
PRBool debugSet = GetInitialDebug(debug);
|
|
|
|
if (debugSet) {
|
|
|
|
mState |= NS_STATE_DEBUG_WAS_SET;
|
|
|
|
if (debug)
|
|
|
|
mState |= NS_STATE_SET_TO_DEBUG;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_SET_TO_DEBUG;
|
|
|
|
} else {
|
|
|
|
mState &= ~NS_STATE_DEBUG_WAS_SET;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PRBool
|
|
|
|
nsBoxFrame::GetInitialDebug(PRBool& aDebug)
|
|
|
|
{
|
2007-05-22 20:48:43 -07:00
|
|
|
if (!GetContent())
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::_false, &nsGkAtoms::_true, nsnull};
|
2007-05-22 20:48:43 -07:00
|
|
|
PRInt32 index = GetContent()->FindAttrValueIn(kNameSpaceID_None,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::debug, strings, eCaseMatters);
|
|
|
|
if (index >= 0) {
|
|
|
|
aDebug = index == 1;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsBoxFrame::GetInitialHAlignment(nsBoxFrame::Halignment& aHalign)
|
|
|
|
{
|
2007-05-22 20:48:43 -07:00
|
|
|
if (!GetContent())
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// XXXdwh Everything inside this if statement is deprecated code.
|
|
|
|
static nsIContent::AttrValuesArray alignStrings[] =
|
|
|
|
{&nsGkAtoms::left, &nsGkAtoms::right, nsnull};
|
|
|
|
static const Halignment alignValues[] = {hAlign_Left, hAlign_Right};
|
2007-05-22 20:48:43 -07:00
|
|
|
PRInt32 index = GetContent()->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::align,
|
2007-03-22 10:30:00 -07:00
|
|
|
alignStrings, eCaseMatters);
|
|
|
|
if (index >= 0) {
|
|
|
|
aHalign = alignValues[index];
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that the deprecated stuff is out of the way, we move on to check the appropriate
|
|
|
|
// attribute. For horizontal boxes, we are checking the PACK attribute. For vertical boxes
|
|
|
|
// we are checking the ALIGN attribute.
|
|
|
|
nsIAtom* attrName = IsHorizontal() ? nsGkAtoms::pack : nsGkAtoms::align;
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::_empty, &nsGkAtoms::start, &nsGkAtoms::center, &nsGkAtoms::end, nsnull};
|
|
|
|
static const Halignment values[] =
|
|
|
|
{hAlign_Left/*not used*/, hAlign_Left, hAlign_Center, hAlign_Right};
|
2007-05-22 20:48:43 -07:00
|
|
|
index = GetContent()->FindAttrValueIn(kNameSpaceID_None, attrName,
|
2007-03-22 10:30:00 -07:00
|
|
|
strings, eCaseMatters);
|
|
|
|
|
|
|
|
if (index == nsIContent::ATTR_VALUE_NO_MATCH) {
|
|
|
|
// The attr was present but had a nonsensical value. Revert to the default.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (index > 0) {
|
|
|
|
aHalign = values[index];
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that we've checked for the attribute it's time to check CSS. For
|
|
|
|
// horizontal boxes we're checking PACK. For vertical boxes we are checking
|
|
|
|
// ALIGN.
|
|
|
|
const nsStyleXUL* boxInfo = GetStyleXUL();
|
|
|
|
if (IsHorizontal()) {
|
|
|
|
switch (boxInfo->mBoxPack) {
|
|
|
|
case NS_STYLE_BOX_PACK_START:
|
|
|
|
aHalign = nsBoxFrame::hAlign_Left;
|
|
|
|
return PR_TRUE;
|
|
|
|
case NS_STYLE_BOX_PACK_CENTER:
|
|
|
|
aHalign = nsBoxFrame::hAlign_Center;
|
|
|
|
return PR_TRUE;
|
|
|
|
case NS_STYLE_BOX_PACK_END:
|
|
|
|
aHalign = nsBoxFrame::hAlign_Right;
|
|
|
|
return PR_TRUE;
|
|
|
|
default: // Nonsensical value. Just bail.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (boxInfo->mBoxAlign) {
|
|
|
|
case NS_STYLE_BOX_ALIGN_START:
|
|
|
|
aHalign = nsBoxFrame::hAlign_Left;
|
|
|
|
return PR_TRUE;
|
|
|
|
case NS_STYLE_BOX_ALIGN_CENTER:
|
|
|
|
aHalign = nsBoxFrame::hAlign_Center;
|
|
|
|
return PR_TRUE;
|
|
|
|
case NS_STYLE_BOX_ALIGN_END:
|
|
|
|
aHalign = nsBoxFrame::hAlign_Right;
|
|
|
|
return PR_TRUE;
|
|
|
|
default: // Nonsensical value. Just bail.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsBoxFrame::GetInitialVAlignment(nsBoxFrame::Valignment& aValign)
|
|
|
|
{
|
2007-05-22 20:48:43 -07:00
|
|
|
if (!GetContent())
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
static nsIContent::AttrValuesArray valignStrings[] =
|
|
|
|
{&nsGkAtoms::top, &nsGkAtoms::baseline, &nsGkAtoms::middle, &nsGkAtoms::bottom, nsnull};
|
|
|
|
static const Valignment valignValues[] =
|
|
|
|
{vAlign_Top, vAlign_BaseLine, vAlign_Middle, vAlign_Bottom};
|
2007-05-22 20:48:43 -07:00
|
|
|
PRInt32 index = GetContent()->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::valign,
|
2007-03-22 10:30:00 -07:00
|
|
|
valignStrings, eCaseMatters);
|
|
|
|
if (index >= 0) {
|
|
|
|
aValign = valignValues[index];
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that the deprecated stuff is out of the way, we move on to check the appropriate
|
|
|
|
// attribute. For horizontal boxes, we are checking the ALIGN attribute. For vertical boxes
|
|
|
|
// we are checking the PACK attribute.
|
|
|
|
nsIAtom* attrName = IsHorizontal() ? nsGkAtoms::align : nsGkAtoms::pack;
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::_empty, &nsGkAtoms::start, &nsGkAtoms::center,
|
|
|
|
&nsGkAtoms::baseline, &nsGkAtoms::end, nsnull};
|
|
|
|
static const Valignment values[] =
|
|
|
|
{vAlign_Top/*not used*/, vAlign_Top, vAlign_Middle, vAlign_BaseLine, vAlign_Bottom};
|
2007-05-22 20:48:43 -07:00
|
|
|
index = GetContent()->FindAttrValueIn(kNameSpaceID_None, attrName,
|
2007-03-22 10:30:00 -07:00
|
|
|
strings, eCaseMatters);
|
|
|
|
if (index == nsIContent::ATTR_VALUE_NO_MATCH) {
|
|
|
|
// The attr was present but had a nonsensical value. Revert to the default.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (index > 0) {
|
|
|
|
aValign = values[index];
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that we've checked for the attribute it's time to check CSS. For
|
|
|
|
// horizontal boxes we're checking ALIGN. For vertical boxes we are checking
|
|
|
|
// PACK.
|
|
|
|
const nsStyleXUL* boxInfo = GetStyleXUL();
|
|
|
|
if (IsHorizontal()) {
|
|
|
|
switch (boxInfo->mBoxAlign) {
|
|
|
|
case NS_STYLE_BOX_ALIGN_START:
|
|
|
|
aValign = nsBoxFrame::vAlign_Top;
|
|
|
|
return PR_TRUE;
|
|
|
|
case NS_STYLE_BOX_ALIGN_CENTER:
|
|
|
|
aValign = nsBoxFrame::vAlign_Middle;
|
|
|
|
return PR_TRUE;
|
|
|
|
case NS_STYLE_BOX_ALIGN_BASELINE:
|
|
|
|
aValign = nsBoxFrame::vAlign_BaseLine;
|
|
|
|
return PR_TRUE;
|
|
|
|
case NS_STYLE_BOX_ALIGN_END:
|
|
|
|
aValign = nsBoxFrame::vAlign_Bottom;
|
|
|
|
return PR_TRUE;
|
|
|
|
default: // Nonsensical value. Just bail.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (boxInfo->mBoxPack) {
|
|
|
|
case NS_STYLE_BOX_PACK_START:
|
|
|
|
aValign = nsBoxFrame::vAlign_Top;
|
|
|
|
return PR_TRUE;
|
|
|
|
case NS_STYLE_BOX_PACK_CENTER:
|
|
|
|
aValign = nsBoxFrame::vAlign_Middle;
|
|
|
|
return PR_TRUE;
|
|
|
|
case NS_STYLE_BOX_PACK_END:
|
|
|
|
aValign = nsBoxFrame::vAlign_Bottom;
|
|
|
|
return PR_TRUE;
|
|
|
|
default: // Nonsensical value. Just bail.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::GetInitialOrientation(PRBool& aIsHorizontal)
|
|
|
|
{
|
|
|
|
// see if we are a vertical or horizontal box.
|
2007-05-22 20:48:43 -07:00
|
|
|
if (!GetContent())
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Check the style system first.
|
|
|
|
const nsStyleXUL* boxInfo = GetStyleXUL();
|
|
|
|
if (boxInfo->mBoxOrient == NS_STYLE_BOX_ORIENT_HORIZONTAL)
|
|
|
|
aIsHorizontal = PR_TRUE;
|
|
|
|
else
|
|
|
|
aIsHorizontal = PR_FALSE;
|
|
|
|
|
|
|
|
// Now see if we have an attribute. The attribute overrides
|
|
|
|
// the style system value.
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::vertical, &nsGkAtoms::horizontal, nsnull};
|
2007-05-22 20:48:43 -07:00
|
|
|
PRInt32 index = GetContent()->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::orient,
|
2007-03-22 10:30:00 -07:00
|
|
|
strings, eCaseMatters);
|
|
|
|
if (index >= 0) {
|
|
|
|
aIsHorizontal = index == 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::GetInitialDirection(PRBool& aIsNormal)
|
|
|
|
{
|
2007-05-22 20:48:43 -07:00
|
|
|
if (!GetContent())
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (IsHorizontal()) {
|
|
|
|
// For horizontal boxes only, we initialize our value based off the CSS 'direction' property.
|
|
|
|
// This means that BiDI users will end up with horizontally inverted chrome.
|
|
|
|
aIsNormal = (GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_LTR); // If text runs RTL then so do we.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aIsNormal = PR_TRUE; // Assume a normal direction in the vertical case.
|
|
|
|
|
|
|
|
// Now check the style system to see if we should invert aIsNormal.
|
|
|
|
const nsStyleXUL* boxInfo = GetStyleXUL();
|
|
|
|
if (boxInfo->mBoxDirection == NS_STYLE_BOX_DIRECTION_REVERSE)
|
|
|
|
aIsNormal = !aIsNormal; // Invert our direction.
|
|
|
|
|
|
|
|
// Now see if we have an attribute. The attribute overrides
|
|
|
|
// the style system value.
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::reverse, &nsGkAtoms::ltr, &nsGkAtoms::rtl, nsnull};
|
2007-05-22 20:48:43 -07:00
|
|
|
PRInt32 index = GetContent()->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::dir,
|
2007-03-22 10:30:00 -07:00
|
|
|
strings, eCaseMatters);
|
|
|
|
if (index >= 0) {
|
|
|
|
PRPackedBool values[] = {!aIsNormal, PR_TRUE, PR_FALSE};
|
|
|
|
aIsNormal = values[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns true if it was set.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
nsBoxFrame::GetInitialEqualSize(PRBool& aEqualSize)
|
|
|
|
{
|
|
|
|
// see if we are a vertical or horizontal box.
|
2007-05-22 20:48:43 -07:00
|
|
|
if (!GetContent())
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
2007-05-22 20:48:43 -07:00
|
|
|
|
|
|
|
if (GetContent()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::equalsize,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::always, eCaseMatters)) {
|
|
|
|
aEqualSize = PR_TRUE;
|
|
|
|
return PR_TRUE;
|
2007-05-22 20:48:43 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns true if it was set.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
nsBoxFrame::GetInitialAutoStretch(PRBool& aStretch)
|
|
|
|
{
|
2007-05-22 20:48:43 -07:00
|
|
|
if (!GetContent())
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// Check the align attribute.
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::_empty, &nsGkAtoms::stretch, nsnull};
|
2007-05-22 20:48:43 -07:00
|
|
|
PRInt32 index = GetContent()->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::align,
|
2007-03-22 10:30:00 -07:00
|
|
|
strings, eCaseMatters);
|
|
|
|
if (index != nsIContent::ATTR_MISSING && index != 0) {
|
|
|
|
aStretch = index == 1;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the CSS box-align property.
|
|
|
|
const nsStyleXUL* boxInfo = GetStyleXUL();
|
|
|
|
aStretch = (boxInfo->mBoxAlign == NS_STYLE_BOX_ALIGN_STRETCH);
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::DidReflow(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState* aReflowState,
|
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
|
|
|
nsFrameState preserveBits =
|
|
|
|
mState & (NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
nsresult rv = nsFrame::DidReflow(aPresContext, aReflowState, aStatus);
|
|
|
|
mState |= preserveBits;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-10-12 11:37:51 -07:00
|
|
|
PRBool
|
|
|
|
nsBoxFrame::HonorPrintBackgroundSettings()
|
|
|
|
{
|
2008-02-26 04:40:18 -08:00
|
|
|
return (!mContent || !mContent->IsInNativeAnonymousSubtree()) &&
|
2007-10-12 11:37:51 -07:00
|
|
|
nsContainerFrame::HonorPrintBackgroundSettings();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DO_NOISY_REFLOW
|
|
|
|
static int myCounter = 0;
|
|
|
|
static void printSize(char * aDesc, nscoord aSize)
|
|
|
|
{
|
|
|
|
printf(" %s: ", aDesc);
|
|
|
|
if (aSize == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
printf("UC");
|
|
|
|
} else {
|
|
|
|
printf("%d", aSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
nsBoxFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext(), aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize minSize = GetMinSize(state);
|
|
|
|
|
|
|
|
// GetMinSize returns border-box width, and we want to return content
|
|
|
|
// width. Since Reflow uses the reflow state's border and padding, we
|
|
|
|
// actually just want to subtract what GetMinSize added, which is the
|
|
|
|
// result of GetBorderAndPadding.
|
|
|
|
nsMargin bp;
|
|
|
|
GetBorderAndPadding(bp);
|
|
|
|
|
|
|
|
result = minSize.width - bp.LeftRight();
|
2009-09-16 08:01:36 -07:00
|
|
|
result = NS_MAX(result, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
nsBoxFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext(), aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize prefSize = GetPrefSize(state);
|
|
|
|
|
|
|
|
// GetPrefSize returns border-box width, and we want to return content
|
|
|
|
// width. Since Reflow uses the reflow state's border and padding, we
|
|
|
|
// actually just want to subtract what GetPrefSize added, which is the
|
|
|
|
// result of GetBorderAndPadding.
|
|
|
|
nsMargin bp;
|
|
|
|
GetBorderAndPadding(bp);
|
|
|
|
|
|
|
|
result = prefSize.width - bp.LeftRight();
|
2009-09-16 08:01:36 -07:00
|
|
|
result = NS_MAX(result, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
// If you make changes to this method, please keep nsLeafBoxFrame::Reflow
|
|
|
|
// in sync, if the changes are applicable there.
|
|
|
|
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsBoxFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
2008-08-25 10:21:29 -07:00
|
|
|
NS_ASSERTION(aReflowState.ComputedWidth() >=0 &&
|
|
|
|
aReflowState.ComputedHeight() >= 0, "Computed Size < 0");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DO_NOISY_REFLOW
|
|
|
|
printf("\n-------------Starting BoxFrame Reflow ----------------------------\n");
|
|
|
|
printf("%p ** nsBF::Reflow %d ", this, myCounter++);
|
|
|
|
|
|
|
|
printSize("AW", aReflowState.availableWidth);
|
|
|
|
printSize("AH", aReflowState.availableHeight);
|
|
|
|
printSize("CW", aReflowState.ComputedWidth());
|
2007-08-02 11:08:05 -07:00
|
|
|
printSize("CH", aReflowState.ComputedHeight());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
printf(" *\n");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
// create the layout state
|
2008-04-09 21:39:41 -07:00
|
|
|
nsBoxLayoutState state(aPresContext, aReflowState.rendContext,
|
|
|
|
aReflowState.mReflowDepth);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-02 11:08:05 -07:00
|
|
|
nsSize computedSize(aReflowState.ComputedWidth(),aReflowState.ComputedHeight());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsMargin m;
|
|
|
|
m = aReflowState.mComputedBorderPadding;
|
|
|
|
// GetBorderAndPadding(m);
|
|
|
|
|
|
|
|
nsSize prefSize(0,0);
|
|
|
|
|
|
|
|
// if we are told to layout intrinsic then get our preferred size.
|
|
|
|
NS_ASSERTION(computedSize.width != NS_INTRINSICSIZE,
|
|
|
|
"computed width should always be computed");
|
|
|
|
if (computedSize.height == NS_INTRINSICSIZE) {
|
|
|
|
prefSize = GetPrefSize(state);
|
|
|
|
nsSize minSize = GetMinSize(state);
|
|
|
|
nsSize maxSize = GetMaxSize(state);
|
2009-04-27 14:18:37 -07:00
|
|
|
// XXXbz isn't GetPrefSize supposed to bounds-check for us?
|
2008-01-04 21:49:44 -08:00
|
|
|
prefSize = BoundsCheck(minSize, prefSize, maxSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// get our desiredSize
|
|
|
|
computedSize.width += m.left + m.right;
|
|
|
|
|
2007-08-02 11:08:05 -07:00
|
|
|
if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
computedSize.height = prefSize.height;
|
2009-04-27 14:18:37 -07:00
|
|
|
// prefSize is border-box, so we need to figure out the right
|
|
|
|
// length to apply our min/max constraints to.
|
|
|
|
nscoord outsideBoxSizing = 0;
|
|
|
|
switch (GetStylePosition()->mBoxSizing) {
|
|
|
|
case NS_STYLE_BOX_SIZING_CONTENT:
|
|
|
|
outsideBoxSizing = aReflowState.mComputedBorderPadding.TopBottom();
|
|
|
|
// fall through
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING:
|
|
|
|
outsideBoxSizing -= aReflowState.mComputedPadding.TopBottom();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
computedSize.height -= outsideBoxSizing;
|
|
|
|
// Note: might be negative now, but that's OK because min-width is
|
|
|
|
// never negative.
|
|
|
|
aReflowState.ApplyMinMaxConstraints(nsnull, &computedSize.height);
|
|
|
|
computedSize.height += outsideBoxSizing;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
computedSize.height += m.top + m.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect r(mRect.x, mRect.y, computedSize.width, computedSize.height);
|
|
|
|
|
|
|
|
SetBounds(state, r);
|
|
|
|
|
|
|
|
// layout our children
|
|
|
|
Layout(state);
|
|
|
|
|
|
|
|
// ok our child could have gotten bigger. So lets get its bounds
|
|
|
|
|
|
|
|
// get the ascent
|
|
|
|
nscoord ascent = mRect.height;
|
|
|
|
|
|
|
|
// getting the ascent could be a lot of work. Don't get it if
|
|
|
|
// we are the root. The viewport doesn't care about it.
|
|
|
|
if (!(mState & NS_STATE_IS_ROOT)) {
|
|
|
|
ascent = GetBoxAscent(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
aDesiredSize.width = mRect.width;
|
|
|
|
aDesiredSize.height = mRect.height;
|
|
|
|
aDesiredSize.ascent = ascent;
|
|
|
|
|
2007-05-22 13:34:00 -07:00
|
|
|
aDesiredSize.mOverflowArea = GetOverflowRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DO_NOISY_REFLOW
|
|
|
|
{
|
|
|
|
printf("%p ** nsBF(done) W:%d H:%d ", this, aDesiredSize.width, aDesiredSize.height);
|
|
|
|
|
|
|
|
if (maxElementSize) {
|
|
|
|
printf("MW:%d\n", *maxElementWidth);
|
|
|
|
} else {
|
|
|
|
printf("MW:?\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsBoxFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
2007-04-29 15:24:59 -07:00
|
|
|
NS_ASSERTION(aBoxLayoutState.GetRenderingContext(),
|
|
|
|
"must have rendering context");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize size(0,0);
|
|
|
|
DISPLAY_PREF_SIZE(this, size);
|
|
|
|
if (!DoesNeedRecalc(mPrefSize)) {
|
2010-03-18 12:58:15 -07:00
|
|
|
return mPrefSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PropagateDebug(aBoxLayoutState);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (IsCollapsed(aBoxLayoutState))
|
|
|
|
return size;
|
|
|
|
|
|
|
|
// if the size was not completely redefined in CSS then ask our children
|
2010-03-18 12:58:15 -07:00
|
|
|
PRBool widthSet, heightSet;
|
|
|
|
if (!nsIBox::AddCSSPrefSize(this, size, widthSet, heightSet))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mLayoutManager) {
|
2010-03-18 12:58:15 -07:00
|
|
|
nsSize layoutSize = mLayoutManager->GetPrefSize(this, aBoxLayoutState);
|
|
|
|
if (!widthSet)
|
|
|
|
size.width = layoutSize.width;
|
|
|
|
if (!heightSet)
|
|
|
|
size.height = layoutSize.height;
|
|
|
|
}
|
|
|
|
else {
|
2007-03-22 10:30:00 -07:00
|
|
|
size = nsBox::GetPrefSize(aBoxLayoutState);
|
2010-03-18 12:58:15 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSize minSize = GetMinSize(aBoxLayoutState);
|
|
|
|
nsSize maxSize = GetMaxSize(aBoxLayoutState);
|
2008-01-04 21:49:44 -08:00
|
|
|
mPrefSize = BoundsCheck(minSize, size, maxSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-04 21:49:44 -08:00
|
|
|
return mPrefSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsBoxFrame::GetBoxAscent(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
if (!DoesNeedRecalc(mAscent))
|
|
|
|
return mAscent;
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PropagateDebug(aBoxLayoutState);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (IsCollapsed(aBoxLayoutState))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (mLayoutManager)
|
2008-01-08 23:28:39 -08:00
|
|
|
mAscent = mLayoutManager->GetAscent(this, aBoxLayoutState);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
mAscent = nsBox::GetBoxAscent(aBoxLayoutState);
|
|
|
|
|
|
|
|
return mAscent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
2007-04-29 15:24:59 -07:00
|
|
|
NS_ASSERTION(aBoxLayoutState.GetRenderingContext(),
|
|
|
|
"must have rendering context");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize size(0,0);
|
|
|
|
DISPLAY_MIN_SIZE(this, size);
|
|
|
|
if (!DoesNeedRecalc(mMinSize)) {
|
2010-03-18 12:58:15 -07:00
|
|
|
return mMinSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PropagateDebug(aBoxLayoutState);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (IsCollapsed(aBoxLayoutState))
|
|
|
|
return size;
|
|
|
|
|
|
|
|
// if the size was not completely redefined in CSS then ask our children
|
2010-03-18 12:58:15 -07:00
|
|
|
PRBool widthSet, heightSet;
|
|
|
|
if (!nsIBox::AddCSSMinSize(aBoxLayoutState, this, size, widthSet, heightSet))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mLayoutManager) {
|
2010-03-18 12:58:15 -07:00
|
|
|
nsSize layoutSize = mLayoutManager->GetMinSize(this, aBoxLayoutState);
|
|
|
|
if (!widthSet)
|
|
|
|
size.width = layoutSize.width;
|
|
|
|
if (!heightSet)
|
|
|
|
size.height = layoutSize.height;
|
|
|
|
}
|
|
|
|
else {
|
2007-03-22 10:30:00 -07:00
|
|
|
size = nsBox::GetMinSize(aBoxLayoutState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mMinSize = size;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsBoxFrame::GetMaxSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
2007-04-29 15:24:59 -07:00
|
|
|
NS_ASSERTION(aBoxLayoutState.GetRenderingContext(),
|
|
|
|
"must have rendering context");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize size(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
|
|
|
DISPLAY_MAX_SIZE(this, size);
|
|
|
|
if (!DoesNeedRecalc(mMaxSize)) {
|
2010-03-18 12:58:15 -07:00
|
|
|
return mMaxSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PropagateDebug(aBoxLayoutState);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (IsCollapsed(aBoxLayoutState))
|
|
|
|
return size;
|
|
|
|
|
|
|
|
// if the size was not completely redefined in CSS then ask our children
|
2010-03-18 12:58:15 -07:00
|
|
|
PRBool widthSet, heightSet;
|
|
|
|
if (!nsIBox::AddCSSMaxSize(this, size, widthSet, heightSet))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mLayoutManager) {
|
2010-03-18 12:58:15 -07:00
|
|
|
nsSize layoutSize = mLayoutManager->GetMaxSize(this, aBoxLayoutState);
|
|
|
|
if (!widthSet)
|
|
|
|
size.width = layoutSize.width;
|
|
|
|
if (!heightSet)
|
|
|
|
size.height = layoutSize.height;
|
|
|
|
}
|
|
|
|
else {
|
2007-03-22 10:30:00 -07:00
|
|
|
size = nsBox::GetMaxSize(aBoxLayoutState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mMaxSize = size;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsBoxFrame::GetFlex(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
if (!DoesNeedRecalc(mFlex))
|
|
|
|
return mFlex;
|
|
|
|
|
|
|
|
mFlex = nsBox::GetFlex(aBoxLayoutState);
|
|
|
|
|
|
|
|
return mFlex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If subclassing please subclass this method not layout.
|
|
|
|
* layout will call this method.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::DoLayout(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
PRUint32 oldFlags = aState.LayoutFlags();
|
|
|
|
aState.SetLayoutFlags(0);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
2009-10-21 17:11:25 -07:00
|
|
|
if (mLayoutManager) {
|
|
|
|
CoordNeedsRecalc(mAscent);
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = mLayoutManager->Layout(this, aState);
|
2009-10-21 17:11:25 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aState.SetLayoutFlags(oldFlags);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// unregister access key
|
|
|
|
RegUnregAccessKey(PR_FALSE);
|
|
|
|
|
|
|
|
// clean up the container box's layout manager and child boxes
|
|
|
|
SetLayoutManager(nsnull);
|
|
|
|
|
2009-12-23 21:21:15 -08:00
|
|
|
nsContainerFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::SetDebug(nsBoxLayoutState& aState, PRBool aDebug)
|
|
|
|
{
|
|
|
|
// see if our state matches the given debug state
|
|
|
|
PRBool debugSet = mState & NS_STATE_CURRENTLY_IN_DEBUG;
|
|
|
|
PRBool debugChanged = (!aDebug && debugSet) || (aDebug && !debugSet);
|
|
|
|
|
|
|
|
// if it doesn't then tell each child below us the new debug state
|
|
|
|
if (debugChanged)
|
|
|
|
{
|
|
|
|
if (aDebug) {
|
|
|
|
mState |= NS_STATE_CURRENTLY_IN_DEBUG;
|
|
|
|
} else {
|
|
|
|
mState &= ~NS_STATE_CURRENTLY_IN_DEBUG;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetDebugOnChildList(aState, mFirstChild, aDebug);
|
|
|
|
|
|
|
|
MarkIntrinsicWidthsDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsBoxFrame::MarkIntrinsicWidthsDirty()
|
|
|
|
{
|
|
|
|
SizeNeedsRecalc(mPrefSize);
|
|
|
|
SizeNeedsRecalc(mMinSize);
|
|
|
|
SizeNeedsRecalc(mMaxSize);
|
|
|
|
CoordNeedsRecalc(mFlex);
|
|
|
|
CoordNeedsRecalc(mAscent);
|
|
|
|
|
|
|
|
if (mLayoutManager) {
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
mLayoutManager->IntrinsicWidthsDirty(this, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't call base class method, since everything it does is within an
|
|
|
|
// IsBoxWrapped check.
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::RemoveFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!aListName, "We don't support out-of-flow kids");
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBoxLayoutState state(presContext);
|
|
|
|
|
|
|
|
// remove the child frame
|
|
|
|
mFrames.RemoveFrame(aOldFrame);
|
|
|
|
|
|
|
|
// notify the layout manager
|
|
|
|
if (mLayoutManager)
|
|
|
|
mLayoutManager->ChildrenRemoved(this, state, aOldFrame);
|
|
|
|
|
|
|
|
// destroy the child frame
|
|
|
|
aOldFrame->Destroy();
|
|
|
|
|
|
|
|
// mark us dirty and generate a reflow command
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 12:16:51 -07:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::InsertFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this,
|
|
|
|
"inserting after sibling frame with different parent");
|
2007-10-19 22:43:38 -07:00
|
|
|
NS_ASSERTION(!aPrevFrame || mFrames.ContainsFrame(aPrevFrame),
|
|
|
|
"inserting after sibling frame not in our child list");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_PRECONDITION(!aListName, "We don't support out-of-flow kids");
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// insert the child frames
|
2009-07-30 10:23:32 -07:00
|
|
|
const nsFrameList::Slice& newFrames =
|
|
|
|
mFrames.InsertFrames(this, aPrevFrame, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// notify the layout manager
|
|
|
|
if (mLayoutManager)
|
2009-07-30 10:23:32 -07:00
|
|
|
mLayoutManager->ChildrenInserted(this, state, aPrevFrame, newFrames);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-28 13:47:58 -07:00
|
|
|
// Make sure to check box order _after_ notifying the layout
|
|
|
|
// manager; otherwise the slice we give the layout manager will
|
|
|
|
// just be bogus. If the layout manager cares about the order, we
|
|
|
|
// just lose.
|
|
|
|
CheckBoxOrder(state);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
// if we are in debug make sure our children are in debug as well.
|
|
|
|
if (mState & NS_STATE_CURRENTLY_IN_DEBUG)
|
|
|
|
SetDebugOnChildList(state, mFrames.FirstChild(), PR_TRUE);
|
|
|
|
#endif
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 12:16:51 -07:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::AppendFrames(nsIAtom* aListName,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!aListName, "We don't support out-of-flow kids");
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// append the new frames
|
2009-07-30 10:23:32 -07:00
|
|
|
const nsFrameList::Slice& newFrames = mFrames.AppendFrames(this, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// notify the layout manager
|
|
|
|
if (mLayoutManager)
|
2009-07-30 10:23:32 -07:00
|
|
|
mLayoutManager->ChildrenAppended(this, state, newFrames);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-28 13:47:58 -07:00
|
|
|
// Make sure to check box order _after_ notifying the layout
|
|
|
|
// manager; otherwise the slice we give the layout manager will
|
|
|
|
// just be bogus. If the layout manager cares about the order, we
|
|
|
|
// just lose.
|
|
|
|
CheckBoxOrder(state);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
// if we are in debug make sure our children are in debug as well.
|
|
|
|
if (mState & NS_STATE_CURRENTLY_IN_DEBUG)
|
|
|
|
SetDebugOnChildList(state, mFrames.FirstChild(), PR_TRUE);
|
|
|
|
#endif
|
|
|
|
|
2007-05-06 12:16:51 -07:00
|
|
|
// XXXbz why is this NS_FRAME_FIRST_REFLOW check here?
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 12:16:51 -07:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-25 16:30:49 -07:00
|
|
|
/* virtual */ nsIFrame*
|
|
|
|
nsBoxFrame::GetContentInsertionFrame()
|
|
|
|
{
|
|
|
|
if (GetStateBits() & NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK)
|
|
|
|
return GetFirstChild(nsnull)->GetContentInsertionFrame();
|
|
|
|
return nsContainerFrame::GetContentInsertionFrame();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
|
|
|
nsresult rv = nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
|
|
|
|
|
|
|
// Ignore 'width', 'height', 'screenX', 'screenY' and 'sizemode' on a
|
|
|
|
// <window>.
|
|
|
|
nsIAtom *tag = mContent->Tag();
|
|
|
|
if ((tag == nsGkAtoms::window ||
|
|
|
|
tag == nsGkAtoms::page ||
|
|
|
|
tag == nsGkAtoms::dialog ||
|
|
|
|
tag == nsGkAtoms::wizard) &&
|
|
|
|
(nsGkAtoms::width == aAttribute ||
|
|
|
|
nsGkAtoms::height == aAttribute ||
|
|
|
|
nsGkAtoms::screenX == aAttribute ||
|
|
|
|
nsGkAtoms::screenY == aAttribute ||
|
|
|
|
nsGkAtoms::sizemode == aAttribute)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height ||
|
|
|
|
aAttribute == nsGkAtoms::align ||
|
|
|
|
aAttribute == nsGkAtoms::valign ||
|
|
|
|
aAttribute == nsGkAtoms::left ||
|
|
|
|
aAttribute == nsGkAtoms::top ||
|
2009-09-13 14:13:54 -07:00
|
|
|
aAttribute == nsGkAtoms::right ||
|
|
|
|
aAttribute == nsGkAtoms::bottom ||
|
2007-03-22 10:30:00 -07:00
|
|
|
aAttribute == nsGkAtoms::minwidth ||
|
|
|
|
aAttribute == nsGkAtoms::maxwidth ||
|
|
|
|
aAttribute == nsGkAtoms::minheight ||
|
|
|
|
aAttribute == nsGkAtoms::maxheight ||
|
|
|
|
aAttribute == nsGkAtoms::flex ||
|
|
|
|
aAttribute == nsGkAtoms::orient ||
|
|
|
|
aAttribute == nsGkAtoms::pack ||
|
|
|
|
aAttribute == nsGkAtoms::dir ||
|
2007-06-18 16:22:46 -07:00
|
|
|
aAttribute == nsGkAtoms::mousethrough ||
|
2007-03-22 10:30:00 -07:00
|
|
|
aAttribute == nsGkAtoms::equalsize) {
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::align ||
|
|
|
|
aAttribute == nsGkAtoms::valign ||
|
|
|
|
aAttribute == nsGkAtoms::orient ||
|
|
|
|
aAttribute == nsGkAtoms::pack ||
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
aAttribute == nsGkAtoms::debug ||
|
|
|
|
#endif
|
|
|
|
aAttribute == nsGkAtoms::dir) {
|
|
|
|
|
|
|
|
mValign = nsBoxFrame::vAlign_Top;
|
|
|
|
mHalign = nsBoxFrame::hAlign_Left;
|
|
|
|
|
|
|
|
PRBool orient = PR_TRUE;
|
|
|
|
GetInitialOrientation(orient);
|
|
|
|
if (orient)
|
|
|
|
mState |= NS_STATE_IS_HORIZONTAL;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_IS_HORIZONTAL;
|
|
|
|
|
|
|
|
PRBool normal = PR_TRUE;
|
|
|
|
GetInitialDirection(normal);
|
|
|
|
if (normal)
|
|
|
|
mState |= NS_STATE_IS_DIRECTION_NORMAL;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_IS_DIRECTION_NORMAL;
|
|
|
|
|
|
|
|
GetInitialVAlignment(mValign);
|
|
|
|
GetInitialHAlignment(mHalign);
|
|
|
|
|
|
|
|
PRBool equalSize = PR_FALSE;
|
|
|
|
GetInitialEqualSize(equalSize);
|
|
|
|
if (equalSize)
|
|
|
|
mState |= NS_STATE_EQUAL_SIZE;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_EQUAL_SIZE;
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PRBool debug = mState & NS_STATE_SET_TO_DEBUG;
|
|
|
|
PRBool debugSet = GetInitialDebug(debug);
|
|
|
|
if (debugSet) {
|
|
|
|
mState |= NS_STATE_DEBUG_WAS_SET;
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
mState |= NS_STATE_SET_TO_DEBUG;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_SET_TO_DEBUG;
|
|
|
|
} else {
|
|
|
|
mState &= ~NS_STATE_DEBUG_WAS_SET;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-10-09 17:00:05 -07:00
|
|
|
PRBool autostretch = !!(mState & NS_STATE_AUTO_STRETCH);
|
2007-03-22 10:30:00 -07:00
|
|
|
GetInitialAutoStretch(autostretch);
|
|
|
|
if (autostretch)
|
|
|
|
mState |= NS_STATE_AUTO_STRETCH;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_AUTO_STRETCH;
|
|
|
|
}
|
|
|
|
else if (aAttribute == nsGkAtoms::left ||
|
2009-09-13 14:13:54 -07:00
|
|
|
aAttribute == nsGkAtoms::top ||
|
|
|
|
aAttribute == nsGkAtoms::right ||
|
|
|
|
aAttribute == nsGkAtoms::bottom) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mState &= ~NS_STATE_STACK_NOT_POSITIONED;
|
|
|
|
}
|
2007-06-18 16:22:46 -07:00
|
|
|
else if (aAttribute == nsGkAtoms::mousethrough) {
|
|
|
|
UpdateMouseThrough();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 12:16:51 -07:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aAttribute == nsGkAtoms::ordinal) {
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext());
|
2007-08-16 08:39:22 -07:00
|
|
|
nsIBox* parent = GetParentBox();
|
2007-03-22 10:30:00 -07:00
|
|
|
// If our parent is not a box, there's not much we can do... but in that
|
|
|
|
// case our ordinal doesn't matter anyway, so that's ok.
|
2007-08-16 08:39:22 -07:00
|
|
|
// Also don't bother with popup frames since they are kept on the
|
|
|
|
// nsGkAtoms::popupList and RelayoutChildAtOrdinal() only handles
|
|
|
|
// principal children.
|
|
|
|
if (parent && !(GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
|
|
|
|
GetStyleDisplay()->mDisplay != NS_STYLE_DISPLAY_POPUP) {
|
|
|
|
parent->RelayoutChildAtOrdinal(state, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXXldb Should this instead be a tree change on the child or parent?
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 12:16:51 -07:00
|
|
|
FrameNeedsReflow(parent, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the accesskey changed, register for the new value
|
|
|
|
// The old value has been unregistered in nsXULElement::SetAttr
|
|
|
|
else if (aAttribute == nsGkAtoms::accesskey) {
|
|
|
|
RegUnregAccessKey(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
void
|
|
|
|
nsBoxFrame::GetDebugPref(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
gDebug = nsContentUtils::GetBoolPref("xul.debug.box");
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsDisplayXULDebug : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayXULDebug(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame) :
|
|
|
|
nsDisplayItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayXULDebug);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayXULDebug() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayXULDebug);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, nsRect aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) {
|
|
|
|
nsPoint rectCenter(aRect.x + aRect.width / 2, aRect.y + aRect.height / 2);
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsBoxFrame*>(mFrame)->
|
2010-08-13 03:01:58 -07:00
|
|
|
DisplayDebugInfoFor(this, rectCenter - ToReferenceFrame());
|
2010-04-07 17:31:26 -07:00
|
|
|
aOutFrames->AppendElement(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder
|
|
|
|
nsIRenderingContext* aCtx);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("XULDebug", TYPE_XUL_DEBUG)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayXULDebug::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-06 17:35:14 -07:00
|
|
|
nsIRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsBoxFrame*>(mFrame)->
|
2010-08-13 03:01:58 -07:00
|
|
|
PaintXULDebugOverlay(*aCtx, ToReferenceFrame());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
PaintXULDebugBackground(nsIFrame* aFrame, nsIRenderingContext* aCtx,
|
|
|
|
const nsRect& aDirtyRect, nsPoint aPt)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsBoxFrame*>(aFrame)->PaintXULDebugBackground(*aCtx, aPt);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
2010-08-27 16:15:08 -07:00
|
|
|
// forcelayer is only supported on XUL elements with box layout
|
|
|
|
PRBool forceLayer =
|
|
|
|
GetContent()->HasAttr(kNameSpaceID_None, nsGkAtoms::layer) &&
|
|
|
|
GetContent()->IsXUL();
|
|
|
|
|
|
|
|
nsDisplayListCollection tempLists;
|
|
|
|
const nsDisplayListSet& destination = forceLayer ? tempLists : aLists;
|
|
|
|
|
|
|
|
nsresult rv = DisplayBorderBackgroundOutline(aBuilder, destination);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
if (mState & NS_STATE_CURRENTLY_IN_DEBUG) {
|
2010-08-27 16:15:08 -07:00
|
|
|
rv = destination.BorderBackground()->AppendNewToTop(new (aBuilder)
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayGeneric(aBuilder, this, PaintXULDebugBackground,
|
|
|
|
"XULDebugBackground"));
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-27 16:15:08 -07:00
|
|
|
rv = destination.Outlines()->AppendNewToTop(new (aBuilder)
|
2010-08-13 03:01:58 -07:00
|
|
|
nsDisplayXULDebug(aBuilder, this));
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-27 16:15:08 -07:00
|
|
|
rv = BuildDisplayListForChildren(aBuilder, aDirtyRect, destination);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// see if we have to draw a selection frame around this container
|
2010-08-27 16:15:08 -07:00
|
|
|
rv = DisplaySelectionOverlay(aBuilder, destination);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (forceLayer) {
|
|
|
|
// This is a bit of a hack. Collect up all descendant display items
|
|
|
|
// and merge them into a single Content() list. This can cause us
|
|
|
|
// to violate CSS stacking order, but forceLayer is a magic
|
|
|
|
// XUL-only extension anyway.
|
|
|
|
nsDisplayList masterList;
|
|
|
|
masterList.AppendToTop(tempLists.BorderBackground());
|
|
|
|
masterList.AppendToTop(tempLists.BlockBorderBackgrounds());
|
|
|
|
masterList.AppendToTop(tempLists.Floats());
|
|
|
|
masterList.AppendToTop(tempLists.Content());
|
|
|
|
masterList.AppendToTop(tempLists.PositionedDescendants());
|
|
|
|
masterList.AppendToTop(tempLists.Outlines());
|
|
|
|
// Wrap the list to make it its own layer
|
|
|
|
rv = aLists.Content()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayOwnLayer(aBuilder, this, &masterList));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
// Put each child's background onto the BlockBorderBackgrounds list
|
|
|
|
// to emulate the existing two-layer XUL painting scheme.
|
|
|
|
nsDisplayListSet set(aLists, aLists.BlockBorderBackgrounds());
|
|
|
|
// The children should be in the right order
|
|
|
|
while (kid) {
|
|
|
|
nsresult rv = BuildDisplayListForChild(aBuilder, kid, aDirtyRect, set);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// REVIEW: PaintChildren did a few things none of which are a big deal
|
|
|
|
// anymore:
|
|
|
|
// * Paint some debugging rects for this frame.
|
|
|
|
// This is done by nsDisplayXULDebugBackground, which goes in the
|
|
|
|
// BorderBackground() layer so it isn't clipped by OVERFLOW_CLIP.
|
|
|
|
// * Apply OVERFLOW_CLIP to the children.
|
|
|
|
// This is now in nsFrame::BuildDisplayListForStackingContext/Child.
|
|
|
|
// * Actually paint the children.
|
|
|
|
// Moved to BuildDisplayList.
|
|
|
|
// * Paint per-kid debug information.
|
|
|
|
// This is done by nsDisplayXULDebug, which is in the Outlines()
|
|
|
|
// layer so it goes on top. This means it is not clipped by OVERFLOW_CLIP,
|
|
|
|
// whereas it did used to respect OVERFLOW_CLIP, but too bad.
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
void
|
|
|
|
nsBoxFrame::PaintXULDebugBackground(nsIRenderingContext& aRenderingContext,
|
|
|
|
nsPoint aPt)
|
|
|
|
{
|
|
|
|
nsMargin border;
|
|
|
|
GetBorder(border);
|
|
|
|
|
|
|
|
nsMargin debugBorder;
|
|
|
|
nsMargin debugMargin;
|
|
|
|
nsMargin debugPadding;
|
|
|
|
|
|
|
|
PRBool isHorizontal = IsHorizontal();
|
|
|
|
|
|
|
|
GetDebugBorder(debugBorder);
|
|
|
|
PixelMarginToTwips(GetPresContext(), debugBorder);
|
|
|
|
|
|
|
|
GetDebugMargin(debugMargin);
|
|
|
|
PixelMarginToTwips(GetPresContext(), debugMargin);
|
|
|
|
|
|
|
|
GetDebugPadding(debugPadding);
|
|
|
|
PixelMarginToTwips(GetPresContext(), debugPadding);
|
|
|
|
|
|
|
|
nsRect inner(mRect);
|
|
|
|
inner.MoveTo(aPt);
|
|
|
|
inner.Deflate(debugMargin);
|
|
|
|
inner.Deflate(border);
|
|
|
|
//nsRect borderRect(inner);
|
|
|
|
|
|
|
|
nscolor color;
|
|
|
|
if (isHorizontal) {
|
|
|
|
color = NS_RGB(0,0,255);
|
|
|
|
} else {
|
|
|
|
color = NS_RGB(255,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
aRenderingContext.SetColor(color);
|
|
|
|
|
|
|
|
//left
|
|
|
|
nsRect r(inner);
|
|
|
|
r.width = debugBorder.left;
|
|
|
|
aRenderingContext.FillRect(r);
|
|
|
|
|
|
|
|
// top
|
|
|
|
r = inner;
|
|
|
|
r.height = debugBorder.top;
|
|
|
|
aRenderingContext.FillRect(r);
|
|
|
|
|
|
|
|
//right
|
|
|
|
r = inner;
|
|
|
|
r.x = r.x + r.width - debugBorder.right;
|
|
|
|
r.width = debugBorder.right;
|
|
|
|
aRenderingContext.FillRect(r);
|
|
|
|
|
|
|
|
//bottom
|
|
|
|
r = inner;
|
|
|
|
r.y = r.y + r.height - debugBorder.bottom;
|
|
|
|
r.height = debugBorder.bottom;
|
|
|
|
aRenderingContext.FillRect(r);
|
|
|
|
|
|
|
|
|
|
|
|
// if we have dirty children or we are dirty
|
|
|
|
// place a green border around us.
|
2007-05-06 12:16:51 -07:00
|
|
|
if (NS_SUBTREE_DIRTY(this)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect dirtyr(inner);
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,255,0));
|
|
|
|
aRenderingContext.DrawRect(dirtyr);
|
|
|
|
aRenderingContext.SetColor(color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::PaintXULDebugOverlay(nsIRenderingContext& aRenderingContext,
|
|
|
|
nsPoint aPt)
|
|
|
|
nsMargin border;
|
|
|
|
GetBorder(border);
|
|
|
|
|
|
|
|
nsMargin debugMargin;
|
|
|
|
GetDebugMargin(debugMargin);
|
|
|
|
PixelMarginToTwips(GetPresContext(), debugMargin);
|
|
|
|
|
|
|
|
nsRect inner(mRect);
|
|
|
|
inner.MoveTo(aPt);
|
|
|
|
inner.Deflate(debugMargin);
|
|
|
|
inner.Deflate(border);
|
|
|
|
|
|
|
|
nscoord onePixel = GetPresContext()->IntScaledPixelsToTwips(1);
|
|
|
|
|
|
|
|
kid = GetChildBox();
|
|
|
|
while (nsnull != kid) {
|
|
|
|
PRBool isHorizontal = IsHorizontal();
|
|
|
|
|
|
|
|
nscoord x, y, borderSize, spacerSize;
|
|
|
|
|
|
|
|
nsRect cr(kid->mRect);
|
|
|
|
nsMargin margin;
|
|
|
|
kid->GetMargin(margin);
|
|
|
|
cr.Inflate(margin);
|
|
|
|
|
|
|
|
if (isHorizontal)
|
|
|
|
{
|
|
|
|
cr.y = inner.y;
|
|
|
|
x = cr.x;
|
|
|
|
y = cr.y + onePixel;
|
|
|
|
spacerSize = debugBorder.top - onePixel*4;
|
|
|
|
} else {
|
|
|
|
cr.x = inner.x;
|
|
|
|
x = cr.y;
|
|
|
|
y = cr.x + onePixel;
|
|
|
|
spacerSize = debugBorder.left - onePixel*4;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBoxLayoutState state(GetPresContext());
|
|
|
|
nscoord flex = kid->GetFlex(state);
|
|
|
|
|
|
|
|
if (!kid->IsCollapsed(state)) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
|
|
|
|
|
|
|
if (isHorizontal)
|
|
|
|
borderSize = cr.width;
|
|
|
|
else
|
|
|
|
borderSize = cr.height;
|
|
|
|
|
|
|
|
DrawSpacer(GetPresContext(), aRenderingContext, isHorizontal, flex, x, y, borderSize, spacerSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
kid = kid->GetNextBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
void
|
|
|
|
nsBoxFrame::GetBoxName(nsAutoString& aName)
|
|
|
|
{
|
|
|
|
GetFrameName(aName);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Box"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsBoxFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::boxFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::GetDebug(PRBool& aDebug)
|
|
|
|
{
|
|
|
|
aDebug = (mState & NS_STATE_CURRENTLY_IN_DEBUG);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// REVIEW: nsBoxFrame::GetFrameForPoint is a problem because of 'mousethrough'
|
|
|
|
// attribute support. Here's how it works:
|
|
|
|
// * For each child frame F, we determine the target frame T(F) by recursively
|
|
|
|
// invoking GetFrameForPoint on the child
|
|
|
|
// * Let F' be the last child frame such that T(F') doesn't have mousethrough.
|
|
|
|
// If F' exists, return T(F')
|
|
|
|
// * Otherwise let F'' be the first child frame such that T(F'') is non-null.
|
|
|
|
// If F'' exists, return T(F'')
|
|
|
|
// * Otherwise return this frame, if this frame contains the point
|
|
|
|
// * Otherwise return null
|
|
|
|
// It's not clear how this should work for more complex z-ordering situations.
|
|
|
|
// The basic principle seems to be that if a frame F has a descendant
|
|
|
|
// 'mousethrough' frame that includes the target position, then F
|
|
|
|
// will not receive events (unless it overrides GetFrameForPoint).
|
|
|
|
// A 'mousethrough' frame will only receive an event if, after applying that rule,
|
|
|
|
// all eligible frames are 'mousethrough'; the bottom-most inner-most 'mousethrough'
|
|
|
|
// frame is then chosen (the first eligible frame reached in a
|
|
|
|
// traversal of the frame tree --- pre/post is irrelevant since ancestors
|
|
|
|
// of the mousethrough frames can't be eligible).
|
|
|
|
// IMHO this is very bogus and adds a great deal of complexity for something
|
|
|
|
// that is very rarely used. So I'm redefining 'mousethrough' to the following:
|
|
|
|
// a frame with mousethrough is transparent to mouse events. This is compatible
|
|
|
|
// with the way 'mousethrough' is used in Seamonkey's navigator.xul and
|
|
|
|
// Firefox's browser.xul. The only other place it's used is in the 'expander'
|
|
|
|
// XBL binding, which in our tree is only used by Thunderbird SMIME Advanced
|
|
|
|
// Preferences, and I can't figure out what that does, so I'll have to test it.
|
|
|
|
// If it's broken I'll probably just change the binding to use it more sensibly.
|
|
|
|
// This new behaviour is implemented in nsDisplayList::HitTest.
|
|
|
|
// REVIEW: This debug-box stuff is annoying. I'm just going to put debug boxes
|
|
|
|
// in the outline layer and avoid GetDebugBoxAt.
|
|
|
|
|
|
|
|
// REVIEW: GetCursor had debug-only event dumping code. I have replaced it
|
|
|
|
// with instrumentation in nsDisplayXULDebug.
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
void
|
|
|
|
nsBoxFrame::DrawLine(nsIRenderingContext& aRenderingContext, PRBool aHorizontal, nscoord x1, nscoord y1, nscoord x2, nscoord y2)
|
|
|
|
{
|
|
|
|
if (aHorizontal)
|
|
|
|
aRenderingContext.DrawLine(x1,y1,x2,y2);
|
|
|
|
else
|
|
|
|
aRenderingContext.DrawLine(y1,x1,y2,x2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::FillRect(nsIRenderingContext& aRenderingContext, PRBool aHorizontal, nscoord x, nscoord y, nscoord width, nscoord height)
|
|
|
|
{
|
|
|
|
if (aHorizontal)
|
|
|
|
aRenderingContext.FillRect(x,y,width,height);
|
|
|
|
else
|
|
|
|
aRenderingContext.FillRect(y,x,height,width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::DrawSpacer(nsPresContext* aPresContext, nsIRenderingContext& aRenderingContext, PRBool aHorizontal, PRInt32 flex, nscoord x, nscoord y, nscoord size, nscoord spacerSize)
|
|
|
|
{
|
|
|
|
nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1);
|
|
|
|
|
|
|
|
// if we do draw the coils
|
|
|
|
int distance = 0;
|
|
|
|
int center = 0;
|
|
|
|
int offset = 0;
|
|
|
|
int coilSize = COIL_SIZE*onePixel;
|
|
|
|
int halfSpacer = spacerSize/2;
|
|
|
|
|
|
|
|
distance = size;
|
|
|
|
center = y + halfSpacer;
|
|
|
|
offset = x;
|
|
|
|
|
|
|
|
int coils = distance/coilSize;
|
|
|
|
|
|
|
|
int halfCoilSize = coilSize/2;
|
|
|
|
|
|
|
|
if (flex == 0) {
|
|
|
|
DrawLine(aRenderingContext, aHorizontal, x,y + spacerSize/2, x + size, y + spacerSize/2);
|
|
|
|
} else {
|
|
|
|
for (int i=0; i < coils; i++)
|
|
|
|
{
|
|
|
|
DrawLine(aRenderingContext, aHorizontal, offset, center+halfSpacer, offset+halfCoilSize, center-halfSpacer);
|
|
|
|
DrawLine(aRenderingContext, aHorizontal, offset+halfCoilSize, center-halfSpacer, offset+coilSize, center+halfSpacer);
|
|
|
|
|
|
|
|
offset += coilSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FillRect(aRenderingContext, aHorizontal, x + size - spacerSize/2, y, spacerSize/2, spacerSize);
|
|
|
|
FillRect(aRenderingContext, aHorizontal, x, y, spacerSize/2, spacerSize);
|
|
|
|
|
|
|
|
//DrawKnob(aPresContext, aRenderingContext, x + size - spacerSize, y, spacerSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::GetDebugBorder(nsMargin& aInset)
|
|
|
|
{
|
|
|
|
aInset.SizeTo(2,2,2,2);
|
|
|
|
|
|
|
|
if (IsHorizontal())
|
|
|
|
aInset.top = 10;
|
|
|
|
else
|
|
|
|
aInset.left = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::GetDebugMargin(nsMargin& aInset)
|
|
|
|
{
|
|
|
|
aInset.SizeTo(2,2,2,2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::GetDebugPadding(nsMargin& aPadding)
|
|
|
|
{
|
|
|
|
aPadding.SizeTo(2,2,2,2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::PixelMarginToTwips(nsPresContext* aPresContext, nsMargin& aMarginPixels)
|
|
|
|
{
|
|
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
aMarginPixels.left *= onePixel;
|
|
|
|
aMarginPixels.right *= onePixel;
|
|
|
|
aMarginPixels.top *= onePixel;
|
|
|
|
aMarginPixels.bottom *= onePixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::GetValue(nsPresContext* aPresContext, const nsSize& a, const nsSize& b, char* ch)
|
|
|
|
{
|
|
|
|
float p2t = aPresContext->ScaledPixelsToTwips();
|
|
|
|
|
|
|
|
char width[100];
|
|
|
|
char height[100];
|
|
|
|
|
|
|
|
if (a.width == NS_INTRINSICSIZE)
|
|
|
|
sprintf(width,"%s","INF");
|
|
|
|
else
|
|
|
|
sprintf(width,"%d", nscoord(a.width/*/p2t*/));
|
|
|
|
|
|
|
|
if (a.height == NS_INTRINSICSIZE)
|
|
|
|
sprintf(height,"%s","INF");
|
|
|
|
else
|
|
|
|
sprintf(height,"%d", nscoord(a.height/*/p2t*/));
|
|
|
|
|
|
|
|
|
|
|
|
sprintf(ch, "(%s%s, %s%s)", width, (b.width != NS_INTRINSICSIZE ? "[SET]" : ""),
|
|
|
|
height, (b.height != NS_INTRINSICSIZE ? "[SET]" : ""));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::GetValue(nsPresContext* aPresContext, PRInt32 a, PRInt32 b, char* ch)
|
|
|
|
{
|
|
|
|
if (a == NS_INTRINSICSIZE)
|
|
|
|
sprintf(ch, "%d[SET]", b);
|
|
|
|
else
|
|
|
|
sprintf(ch, "%d", a);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBoxFrame::DisplayDebugInfoFor(nsIBox* aBox,
|
|
|
|
nsPoint& aPoint)
|
|
|
|
{
|
|
|
|
nsBoxLayoutState state(GetPresContext());
|
|
|
|
|
|
|
|
nscoord x = aPoint.x;
|
|
|
|
nscoord y = aPoint.y;
|
|
|
|
|
|
|
|
// get the area inside our border but not our debug margins.
|
|
|
|
nsRect insideBorder(aBox->mRect);
|
|
|
|
insideBorder.MoveTo(0,0):
|
|
|
|
nsMargin border(0,0,0,0);
|
|
|
|
aBox->GetBorderAndPadding(border);
|
|
|
|
insideBorder.Deflate(border);
|
|
|
|
|
|
|
|
PRBool isHorizontal = IsHorizontal();
|
|
|
|
|
|
|
|
if (!insideBorder.Contains(nsPoint(x,y)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
//printf("%%%%%% inside box %%%%%%%\n");
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
nsIBox* child = aBox->GetChildBox();
|
|
|
|
|
|
|
|
nsMargin m;
|
|
|
|
nsMargin m2;
|
|
|
|
GetDebugBorder(m);
|
|
|
|
PixelMarginToTwips(aPresContext, m);
|
|
|
|
|
|
|
|
GetDebugMargin(m2);
|
|
|
|
PixelMarginToTwips(aPresContext, m2);
|
|
|
|
|
|
|
|
m += m2;
|
|
|
|
|
|
|
|
if ((isHorizontal && y < insideBorder.y + m.top) ||
|
|
|
|
(!isHorizontal && x < insideBorder.x + m.left)) {
|
|
|
|
//printf("**** inside debug border *******\n");
|
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
const nsRect& r = child->mRect;
|
|
|
|
|
|
|
|
// if we are not in the child. But in the spacer above the child.
|
|
|
|
if ((isHorizontal && x >= r.x && x < r.x + r.width) ||
|
|
|
|
(!isHorizontal && y >= r.y && y < r.y + r.height)) {
|
|
|
|
aCursor = NS_STYLE_CURSOR_POINTER;
|
|
|
|
// found it but we already showed it.
|
|
|
|
if (mDebugChild == child)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (aBox->GetContent()) {
|
|
|
|
printf("---------------\n");
|
|
|
|
DumpBox(stdout);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child->GetContent()) {
|
|
|
|
printf("child #%d: ", count);
|
|
|
|
child->DumpBox(stdout);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
mDebugChild = child;
|
|
|
|
|
|
|
|
nsSize prefSizeCSS(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
|
|
|
nsSize minSizeCSS (NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
|
|
|
nsSize maxSizeCSS (NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
|
|
|
nscoord flexCSS = NS_INTRINSICSIZE;
|
|
|
|
|
2010-03-18 12:58:15 -07:00
|
|
|
PRBool widthSet, heightSet;
|
|
|
|
nsIBox::AddCSSPrefSize(child, prefSizeCSS, widthSet, heightSet);
|
|
|
|
nsIBox::AddCSSMinSize (state, child, minSizeCSS, widthSet, heightSet);
|
|
|
|
nsIBox::AddCSSMaxSize (child, maxSizeCSS, widthSet, heightSet);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIBox::AddCSSFlex (state, child, flexCSS);
|
|
|
|
|
|
|
|
nsSize prefSize = child->GetPrefSize(state);
|
|
|
|
nsSize minSize = child->GetMinSize(state);
|
|
|
|
nsSize maxSize = child->GetMaxSize(state);
|
|
|
|
nscoord flexSize = child->GetFlex(state);
|
|
|
|
nscoord ascentSize = child->GetBoxAscent(state);
|
|
|
|
|
|
|
|
char min[100];
|
|
|
|
char pref[100];
|
|
|
|
char max[100];
|
|
|
|
char calc[100];
|
|
|
|
char flex[100];
|
|
|
|
char ascent[100];
|
|
|
|
|
|
|
|
nsSize actualSize;
|
|
|
|
GetFrameSizeWithMargin(child, actualSize);
|
|
|
|
nsSize actualSizeCSS (NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
|
|
|
|
|
|
|
GetValue(aPresContext, minSize, minSizeCSS, min);
|
|
|
|
GetValue(aPresContext, prefSize, prefSizeCSS, pref);
|
|
|
|
GetValue(aPresContext, maxSize, maxSizeCSS, max);
|
|
|
|
GetValue(aPresContext, actualSize, actualSizeCSS, calc);
|
|
|
|
GetValue(aPresContext, flexSize, flexCSS, flex);
|
|
|
|
GetValue(aPresContext, ascentSize, NS_INTRINSICSIZE, ascent);
|
|
|
|
|
|
|
|
|
|
|
|
printf("min%s, pref%s, max%s, actual%s, flex=%s, ascent=%s\n\n",
|
|
|
|
min,
|
|
|
|
pref,
|
|
|
|
max,
|
|
|
|
calc,
|
|
|
|
flex,
|
|
|
|
ascent
|
|
|
|
);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
child = child->GetNextBox();
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
mDebugChild = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::SetDebugOnChildList(nsBoxLayoutState& aState, nsIBox* aChild, PRBool aDebug)
|
|
|
|
{
|
|
|
|
nsIBox* child = GetChildBox();
|
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
child->SetDebug(aState, aDebug);
|
|
|
|
child = child->GetNextBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBoxFrame::GetFrameSizeWithMargin(nsIBox* aBox, nsSize& aSize)
|
|
|
|
{
|
|
|
|
nsRect rect(aBox->GetRect());
|
|
|
|
nsMargin margin(0,0,0,0);
|
|
|
|
aBox->GetMargin(margin);
|
|
|
|
rect.Inflate(margin);
|
|
|
|
aSize.width = rect.width;
|
|
|
|
aSize.height = rect.height;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-22 20:48:43 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Boxed don't support fixed positionioning of their children.
|
2008-01-09 14:45:10 -08:00
|
|
|
* KEEP THIS IN SYNC WITH nsContainerFrame::CreateViewForFrame
|
|
|
|
* as much as possible. Until we get rid of views finally...
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsBoxFrame::CreateViewForFrame(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsStyleContext* aStyleContext,
|
2007-07-04 08:49:38 -07:00
|
|
|
PRBool aForce,
|
|
|
|
PRBool aIsPopup)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aForce, "We only get called to force view creation now");
|
|
|
|
// If we don't yet have a view, see if we need a view
|
|
|
|
if (!aFrame->HasView()) {
|
2007-07-04 08:49:38 -07:00
|
|
|
nsViewVisibility visibility = nsViewVisibility_kShow;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 zIndex = 0;
|
|
|
|
PRBool autoZIndex = PR_FALSE;
|
|
|
|
|
|
|
|
if (aForce) {
|
2007-07-04 08:49:38 -07:00
|
|
|
nsIView* parentView;
|
2009-03-11 08:43:08 -07:00
|
|
|
nsIViewManager* viewManager = aPresContext->GetPresShell()->GetViewManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(nsnull != viewManager, "null view manager");
|
|
|
|
|
|
|
|
// Create a view
|
2007-07-04 08:49:38 -07:00
|
|
|
if (aIsPopup) {
|
|
|
|
viewManager->GetRootView(parentView);
|
|
|
|
visibility = nsViewVisibility_kHide;
|
|
|
|
zIndex = PR_INT32_MAX;
|
|
|
|
}
|
|
|
|
else {
|
2010-01-11 13:45:19 -08:00
|
|
|
parentView = aFrame->GetParent()->GetClosestView();
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(parentView, "no parent view");
|
|
|
|
|
|
|
|
// Create a view
|
|
|
|
nsIView *view = viewManager->CreateView(aFrame->GetRect(), parentView, visibility);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (view) {
|
2010-01-11 13:45:19 -08:00
|
|
|
viewManager->SetViewZIndex(view, autoZIndex, zIndex);
|
|
|
|
// XXX put view last in document order until we can do better
|
|
|
|
viewManager->InsertChild(parentView, view, nsnull, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remember our view
|
|
|
|
aFrame->SetView(view);
|
|
|
|
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsBoxFrame::CreateViewForFrame: frame=%p view=%p",
|
|
|
|
aFrame));
|
|
|
|
if (!view)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If you make changes to this function, check its counterparts
|
2008-12-29 07:07:38 -08:00
|
|
|
// in nsTextBoxFrame and nsXULLabelFrame
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsBoxFrame::RegUnregAccessKey(PRBool aDoReg)
|
|
|
|
{
|
|
|
|
// if we have no content, we can't do anything
|
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// find out what type of element this is
|
|
|
|
nsIAtom *atom = mContent->Tag();
|
|
|
|
|
|
|
|
// only support accesskeys for the following elements
|
|
|
|
if (atom != nsGkAtoms::button &&
|
|
|
|
atom != nsGkAtoms::toolbarbutton &&
|
|
|
|
atom != nsGkAtoms::checkbox &&
|
|
|
|
atom != nsGkAtoms::textbox &&
|
|
|
|
atom != nsGkAtoms::tab &&
|
|
|
|
atom != nsGkAtoms::radio) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString accessKey;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
|
|
|
|
|
|
|
|
if (accessKey.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// With a valid PresContext we can get the ESM
|
|
|
|
// and register the access key
|
2007-03-30 14:11:41 -07:00
|
|
|
nsIEventStateManager *esm = PresContext()->EventStateManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
PRUint32 key = accessKey.First();
|
|
|
|
if (aDoReg)
|
|
|
|
rv = esm->RegisterAccessKey(mContent, key);
|
|
|
|
else
|
|
|
|
rv = esm->UnregisterAccessKey(mContent, key);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:11:30 -08:00
|
|
|
PRBool
|
|
|
|
nsBoxFrame::SupportsOrdinalsInChildren()
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-12-07 10:11:30 -08:00
|
|
|
static nsIFrame*
|
|
|
|
SortedMerge(nsBoxLayoutState& aState, nsIFrame *aLeft, nsIFrame *aRight)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aLeft && aRight, "SortedMerge must have non-empty lists");
|
|
|
|
|
|
|
|
nsIFrame *result;
|
|
|
|
// Unroll first iteration to avoid null-check 'result' inside the loop.
|
|
|
|
if (aLeft->GetOrdinal(aState) <= aRight->GetOrdinal(aState)) {
|
|
|
|
result = aLeft;
|
|
|
|
aLeft = aLeft->GetNextSibling();
|
|
|
|
if (!aLeft) {
|
|
|
|
result->SetNextSibling(aRight);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = aRight;
|
|
|
|
aRight = aRight->GetNextSibling();
|
|
|
|
if (!aRight) {
|
|
|
|
result->SetNextSibling(aLeft);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *last = result;
|
|
|
|
for (;;) {
|
|
|
|
if (aLeft->GetOrdinal(aState) <= aRight->GetOrdinal(aState)) {
|
|
|
|
last->SetNextSibling(aLeft);
|
|
|
|
last = aLeft;
|
|
|
|
aLeft = aLeft->GetNextSibling();
|
|
|
|
if (!aLeft) {
|
|
|
|
last->SetNextSibling(aRight);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
last->SetNextSibling(aRight);
|
|
|
|
last = aRight;
|
|
|
|
aRight = aRight->GetNextSibling();
|
|
|
|
if (!aRight) {
|
|
|
|
last->SetNextSibling(aLeft);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIFrame*
|
|
|
|
MergeSort(nsBoxLayoutState& aState, nsIFrame *aSource)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-07 10:11:30 -08:00
|
|
|
NS_PRECONDITION(aSource, "MergeSort null arg");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-07 10:11:30 -08:00
|
|
|
nsIFrame *sorted[32] = { nsnull };
|
|
|
|
nsIFrame **fill = &sorted[0];
|
|
|
|
nsIFrame **left;
|
|
|
|
nsIFrame *rest = aSource;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-07 10:11:30 -08:00
|
|
|
do {
|
|
|
|
nsIFrame *current = rest;
|
|
|
|
rest = rest->GetNextSibling();
|
|
|
|
current->SetNextSibling(nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-07 10:11:30 -08:00
|
|
|
// Merge it with sorted[0] if present; then merge the result with sorted[1] etc.
|
|
|
|
// sorted[0] is a list of length 1 (or nsnull).
|
|
|
|
// sorted[1] is a list of length 2 (or nsnull).
|
|
|
|
// sorted[2] is a list of length 4 (or nsnull). etc.
|
|
|
|
for (left = &sorted[0]; left != fill && *left; ++left) {
|
|
|
|
current = SortedMerge(aState, *left, current);
|
|
|
|
*left = nsnull;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-07 10:11:30 -08:00
|
|
|
// Fill the empty slot that we couldn't merge with the last result.
|
|
|
|
*left = current;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-07 10:11:30 -08:00
|
|
|
if (left == fill)
|
|
|
|
++fill;
|
|
|
|
} while (rest);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-07 10:11:30 -08:00
|
|
|
// Collect and merge the results.
|
|
|
|
nsIFrame *result = nsnull;
|
|
|
|
for (left = &sorted[0]; left != fill; ++left) {
|
|
|
|
if (*left) {
|
|
|
|
result = result ? SortedMerge(aState, *left, result) : *left;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-07 10:11:30 -08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBoxFrame::CheckBoxOrder(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
nsIFrame *child = mFrames.FirstChild();
|
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
|
2009-01-08 16:11:30 -08:00
|
|
|
if (!SupportsOrdinalsInChildren())
|
|
|
|
return;
|
|
|
|
|
2008-12-07 10:11:30 -08:00
|
|
|
// Run through our list of children and check whether we
|
|
|
|
// need to sort them.
|
|
|
|
PRUint32 maxOrdinal = child->GetOrdinal(aState);
|
|
|
|
child = child->GetNextSibling();
|
|
|
|
for ( ; child; child = child->GetNextSibling()) {
|
|
|
|
PRUint32 ordinal = child->GetOrdinal(aState);
|
|
|
|
if (ordinal < maxOrdinal)
|
|
|
|
break;
|
|
|
|
maxOrdinal = ordinal;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-12-07 10:11:30 -08:00
|
|
|
if (!child)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-18 04:09:36 -07:00
|
|
|
nsIFrame* head = MergeSort(aState, mFrames.FirstChild());
|
|
|
|
mFrames = nsFrameList(head, nsLayoutUtils::GetLastSibling(head));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::SetLayoutManager(nsIBoxLayout* aLayout)
|
|
|
|
{
|
|
|
|
mLayoutManager = aLayout;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::GetLayoutManager(nsIBoxLayout** aLayout)
|
|
|
|
{
|
|
|
|
*aLayout = mLayoutManager;
|
|
|
|
NS_IF_ADDREF(*aLayout);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBoxFrame::LayoutChildAt(nsBoxLayoutState& aState, nsIBox* aBox, const nsRect& aRect)
|
|
|
|
{
|
|
|
|
// get the current rect
|
|
|
|
nsRect oldRect(aBox->GetRect());
|
|
|
|
aBox->SetBounds(aState, aRect);
|
|
|
|
|
2007-05-06 12:16:51 -07:00
|
|
|
PRBool layout = NS_SUBTREE_DIRTY(aBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (layout || (oldRect.width != aRect.width || oldRect.height != aRect.height)) {
|
|
|
|
return aBox->Layout(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxFrame::RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIBox* aChild)
|
|
|
|
{
|
2009-01-08 16:11:30 -08:00
|
|
|
if (!SupportsOrdinalsInChildren())
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 ord = aChild->GetOrdinal(aState);
|
|
|
|
|
2009-10-02 09:27:37 -07:00
|
|
|
nsIFrame* child = mFrames.FirstChild();
|
|
|
|
nsIFrame* newPrevSib = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
while (child) {
|
2009-10-02 09:27:37 -07:00
|
|
|
if (ord < child->GetOrdinal(aState)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child != aChild) {
|
2007-03-22 10:30:00 -07:00
|
|
|
newPrevSib = child;
|
2009-10-02 09:27:37 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
child = child->GetNextBox();
|
|
|
|
}
|
|
|
|
|
2009-10-02 09:27:37 -07:00
|
|
|
if (aChild->GetPrevSibling() == newPrevSib) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// This box is not moving.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-18 04:09:35 -07:00
|
|
|
// Take |aChild| out of its old position in the child list.
|
2009-10-02 09:27:37 -07:00
|
|
|
mFrames.RemoveFrame(aChild);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-18 04:09:35 -07:00
|
|
|
// Insert it after |newPrevSib| or at the start if it's null.
|
|
|
|
mFrames.InsertFrame(nsnull, newPrevSib, aChild);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This wrapper class lets us redirect mouse hits from descendant frames
|
|
|
|
* of a menu to the menu itself, if they didn't specify 'allowevents'.
|
|
|
|
*
|
|
|
|
* The wrapper simply turns a hit on a descendant element
|
|
|
|
* into a hit on the menu itself, unless there is an element between the target
|
|
|
|
* and the menu with the "allowevents" attribute.
|
|
|
|
*
|
|
|
|
* This is used by nsMenuFrame and nsTreeColFrame.
|
|
|
|
*
|
|
|
|
* Note that turning a hit on a descendant element into nsnull, so events
|
|
|
|
* could fall through to the menu background, might be an appealing simplification
|
|
|
|
* but it would mean slightly strange behaviour in some cases, because grabber
|
|
|
|
* wrappers can be created for many individual lists and items, so the exact
|
|
|
|
* fallthrough behaviour would be complex. E.g. an element with "allowevents"
|
|
|
|
* on top of the Content() list could receive the event even if it was covered
|
|
|
|
* by a PositionedDescenants() element without "allowevents". It is best to
|
|
|
|
* never convert a non-null hit into null.
|
|
|
|
*/
|
|
|
|
// REVIEW: This is roughly of what nsMenuFrame::GetFrameForPoint used to do.
|
|
|
|
// I've made 'allowevents' affect child elements because that seems the only
|
|
|
|
// reasonable thing to do.
|
|
|
|
class nsDisplayXULEventRedirector : public nsDisplayWrapList {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayXULEventRedirector(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayItem* aItem,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aTargetFrame)
|
2010-08-13 03:01:13 -07:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aItem), mTargetFrame(aTargetFrame) {}
|
|
|
|
nsDisplayXULEventRedirector(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aTargetFrame)
|
2010-08-13 03:01:13 -07:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList), mTargetFrame(aTargetFrame) {}
|
2010-04-07 17:31:26 -07:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("XULEventRedirector", TYPE_XUL_EVENT_REDIRECTOR)
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsIFrame* mTargetFrame;
|
|
|
|
};
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
void nsDisplayXULEventRedirector::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect, HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-04-07 17:31:26 -07:00
|
|
|
nsTArray<nsIFrame*> outFrames;
|
|
|
|
mList.HitTest(aBuilder, aRect, aState, &outFrames);
|
|
|
|
|
2010-05-01 09:39:00 -07:00
|
|
|
PRBool topMostAdded = PR_FALSE;
|
2010-04-28 12:53:00 -07:00
|
|
|
PRUint32 localLength = outFrames.Length();
|
2010-04-07 17:31:26 -07:00
|
|
|
|
2010-04-10 12:29:12 -07:00
|
|
|
for (PRUint32 i = 0; i < localLength; i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
for (nsIContent* content = outFrames.ElementAt(i)->GetContent();
|
|
|
|
content && content != mTargetFrame->GetContent();
|
|
|
|
content = content->GetParent()) {
|
|
|
|
if (content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::allowevents,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
|
|
|
// Events are allowed on 'frame', so let it go.
|
|
|
|
aOutFrames->AppendElement(outFrames.ElementAt(i));
|
2010-05-01 09:39:00 -07:00
|
|
|
topMostAdded = PR_TRUE;
|
2010-04-07 17:31:26 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-04-07 17:31:26 -07:00
|
|
|
|
2010-05-01 09:39:00 -07:00
|
|
|
// If there was no hit on the topmost frame or its ancestors,
|
|
|
|
// add the target frame itself as the first candidate (see bug 562554).
|
|
|
|
if (!topMostAdded) {
|
|
|
|
topMostAdded = PR_TRUE;
|
|
|
|
aOutFrames->AppendElement(mTargetFrame);
|
|
|
|
}
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
}
|
2010-05-01 09:39:00 -07:00
|
|
|
// If no hits were found, treat it as a hit on the target frame itself.
|
|
|
|
if (localLength == 0) {
|
2010-04-07 17:31:26 -07:00
|
|
|
aOutFrames->AppendElement(mTargetFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsXULEventRedirectorWrapper : public nsDisplayWrapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsXULEventRedirectorWrapper(nsIFrame* aTargetFrame)
|
|
|
|
: mTargetFrame(aTargetFrame) {}
|
|
|
|
virtual nsDisplayItem* WrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList) {
|
|
|
|
return new (aBuilder)
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayXULEventRedirector(aBuilder, aFrame, aList, mTargetFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
virtual nsDisplayItem* WrapItem(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem) {
|
|
|
|
return new (aBuilder)
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayXULEventRedirector(aBuilder, aItem->GetUnderlyingFrame(), aItem,
|
2007-03-22 10:30:00 -07:00
|
|
|
mTargetFrame);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsIFrame* mTargetFrame;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBoxFrame::WrapListsInRedirector(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aIn,
|
|
|
|
const nsDisplayListSet& aOut)
|
|
|
|
{
|
|
|
|
nsXULEventRedirectorWrapper wrapper(this);
|
|
|
|
return wrapper.WrapLists(aBuilder, this, aIn, aOut);
|
|
|
|
}
|