gecko-dev/layout/xul/nsDeckFrame.cpp

233 строки
6.0 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2012-05-21 15:12:37 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
1999-04-22 02:46:15 +04:00
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsDeckFrame.h"
#include "nsStyleContext.h"
#include "nsPresContext.h"
1999-04-22 02:46:15 +04:00
#include "nsIContent.h"
#include "nsCOMPtr.h"
#include "nsNameSpaceManager.h"
#include "nsGkAtoms.h"
#include "nsHTMLParts.h"
#include "nsIPresShell.h"
#include "nsCSSRendering.h"
#include "nsViewManager.h"
2000-03-31 11:02:06 +04:00
#include "nsBoxLayoutState.h"
#include "nsStackLayout.h"
#include "nsDisplayList.h"
#include "nsContainerFrame.h"
#include "nsContentUtils.h"
#ifdef ACCESSIBILITY
#include "nsAccessibilityService.h"
#endif
nsIFrame*
NS_NewDeckFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
1999-04-22 02:46:15 +04:00
{
return new (aPresShell) nsDeckFrame(aContext);
}
NS_IMPL_FRAMEARENA_HELPERS(nsDeckFrame)
1999-04-22 02:46:15 +04:00
NS_QUERYFRAME_HEAD(nsDeckFrame)
NS_QUERYFRAME_ENTRY(nsDeckFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
nsDeckFrame::nsDeckFrame(nsStyleContext* aContext)
: nsBoxFrame(aContext, kClassID)
, mIndex(0)
1999-04-22 02:46:15 +04:00
{
2011-07-11 18:05:10 +04:00
nsCOMPtr<nsBoxLayout> layout;
NS_NewStackLayout(layout);
SetXULLayoutManager(layout);
1999-04-22 02:46:15 +04:00
}
nsresult
nsDeckFrame::AttributeChanged(int32_t aNameSpaceID,
nsIAtom* aAttribute,
int32_t aModType)
1999-04-22 02:46:15 +04:00
{
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
aModType);
1999-04-22 02:46:15 +04:00
// if the index changed hide the old element and make the new element visible
if (aAttribute == nsGkAtoms::selectedIndex) {
IndexChanged();
1999-04-22 02:46:15 +04:00
}
return rv;
1999-04-22 02:46:15 +04:00
}
void
nsDeckFrame::Init(nsIContent* aContent,
nsContainerFrame* aParent,
nsIFrame* aPrevInFlow)
1999-04-22 02:46:15 +04:00
{
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
2000-06-22 04:48:49 +04:00
mIndex = GetSelectedIndex();
}
void
nsDeckFrame::HideBox(nsIFrame* aBox)
2000-06-22 04:48:49 +04:00
{
nsIPresShell::ClearMouseCapture(aBox);
2000-06-22 04:48:49 +04:00
}
void
nsDeckFrame::IndexChanged()
2000-06-22 04:48:49 +04:00
{
//did the index change?
int32_t index = GetSelectedIndex();
2000-06-22 04:48:49 +04:00
if (index == mIndex)
return;
// redraw
InvalidateFrame();
2000-06-22 04:48:49 +04:00
// hide the currently showing box
nsIFrame* currentBox = GetSelectedBox();
if (currentBox) // only hide if it exists
HideBox(currentBox);
2000-06-22 04:48:49 +04:00
mIndex = index;
#ifdef ACCESSIBILITY
nsAccessibilityService* accService = GetAccService();
if (accService) {
accService->DeckPanelSwitched(PresContext()->GetPresShell(), mContent,
currentBox, GetSelectedBox());
}
#endif
// Force any popups that might be anchored on elements within hidden
// box to update.
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm && currentBox) {
pm->UpdatePopupPositions(currentBox->PresContext()->RefreshDriver());
}
2000-06-22 04:48:49 +04:00
}
int32_t
2000-06-22 04:48:49 +04:00
nsDeckFrame::GetSelectedIndex()
{
// default index is 0
int32_t index = 0;
1999-04-22 02:46:15 +04:00
// get the index attribute
nsAutoString value;
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::selectedIndex, value))
1999-04-22 02:46:15 +04:00
{
nsresult error;
1999-04-22 02:46:15 +04:00
// convert it to an integer
index = value.ToInteger(&error);
}
2000-06-22 04:48:49 +04:00
return index;
}
nsIFrame*
2000-06-22 04:48:49 +04:00
nsDeckFrame::GetSelectedBox()
{
return (mIndex >= 0) ? mFrames.FrameAt(mIndex) : nullptr;
1999-04-22 02:46:15 +04:00
}
void
nsDeckFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists)
1999-04-22 02:46:15 +04:00
{
// if a tab is hidden all its children are too.
if (!StyleVisibility()->mVisible)
return;
nsBoxFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
1999-04-22 02:46:15 +04:00
}
void
nsDeckFrame::RemoveFrame(ChildListID aListID,
nsIFrame* aOldFrame)
{
nsIFrame* currentFrame = GetSelectedBox();
if (currentFrame &&
aOldFrame &&
currentFrame != aOldFrame) {
// If the frame we're removing is at an index that's less
// than mIndex, that means we're going to be shifting indexes
// by 1.
//
// We attempt to keep the same child displayed by automatically
// updating our internal notion of the current index.
int32_t removedIndex = mFrames.IndexOf(aOldFrame);
MOZ_ASSERT(removedIndex >= 0,
"A deck child was removed that was not in mFrames.");
if (removedIndex < mIndex) {
mIndex--;
// This is going to cause us to handle the index change in IndexedChanged,
// but since the new index will match mIndex, it's essentially a noop.
nsContentUtils::AddScriptRunner(new nsSetAttrRunnable(
mContent, nsGkAtoms::selectedIndex, mIndex));
}
}
nsBoxFrame::RemoveFrame(aListID, aOldFrame);
}
void
nsDeckFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists)
1999-04-22 02:46:15 +04:00
{
// only paint the selected box
nsIFrame* box = GetSelectedBox();
if (!box)
return;
// Putting the child in the background list. This is a little weird but
// it matches what we were doing before.
nsDisplayListSet set(aLists, aLists.BlockBorderBackgrounds());
BuildDisplayListForChild(aBuilder, box, aDirtyRect, set);
1999-04-22 02:46:15 +04:00
}
NS_IMETHODIMP
nsDeckFrame::DoXULLayout(nsBoxLayoutState& aState)
{
// Make sure we tweak the state so it does not resize our children.
// We will do that.
uint32_t oldFlags = aState.LayoutFlags();
2000-06-22 04:48:49 +04:00
aState.SetLayoutFlags(NS_FRAME_NO_SIZE_VIEW | NS_FRAME_NO_VISIBILITY);
2000-06-22 04:48:49 +04:00
// do a normal layout
nsresult rv = nsBoxFrame::DoXULLayout(aState);
2000-06-22 04:48:49 +04:00
// run though each child. Hide all but the selected one
nsIFrame* box = nsBox::GetChildXULBox(this);
nscoord count = 0;
while (box)
2000-03-31 11:02:06 +04:00
{
// make collapsed children not show up
if (count != mIndex)
HideBox(box);
2000-03-31 11:02:06 +04:00
box = GetNextXULBox(box);
2000-03-31 11:02:06 +04:00
count++;
}
2000-06-22 04:48:49 +04:00
aState.SetLayoutFlags(oldFlags);
return rv;
}