2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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-21 22:46:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsDeckFrame.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1999-04-21 22:46:15 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1999-05-19 22:14:11 +00:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2013-01-05 03:12:24 +00:00
|
|
|
#include "nsViewManager.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsStackLayout.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
2011-12-27 20:18:48 +00:00
|
|
|
#include "nsContainerFrame.h"
|
2014-08-02 12:22:06 +00:00
|
|
|
#include "nsContentUtils.h"
|
1999-05-09 21:46:24 +00:00
|
|
|
|
2012-12-28 08:15:02 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame*
|
2009-01-19 18:31:33 +00:00
|
|
|
NS_NewDeckFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-04-21 22:46:15 +00:00
|
|
|
{
|
2015-01-06 09:27:56 +00:00
|
|
|
return new (aPresShell) nsDeckFrame(aContext);
|
2009-09-12 16:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsDeckFrame)
|
1999-04-21 22:46:15 +00:00
|
|
|
|
2011-10-26 23:57:55 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsDeckFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsDeckFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
|
|
|
|
2000-03-02 03:01:30 +00:00
|
|
|
|
2015-01-06 09:27:56 +00:00
|
|
|
nsDeckFrame::nsDeckFrame(nsStyleContext* aContext)
|
|
|
|
: nsBoxFrame(aContext), mIndex(0)
|
1999-04-21 22:46:15 +00:00
|
|
|
{
|
2011-07-11 14:05:10 +00:00
|
|
|
nsCOMPtr<nsBoxLayout> layout;
|
2015-12-07 23:27:01 +00:00
|
|
|
NS_NewStackLayout(layout);
|
2016-04-21 04:28:33 +00:00
|
|
|
SetXULLayoutManager(layout);
|
1999-04-21 22:46:15 +00:00
|
|
|
}
|
|
|
|
|
2007-05-15 09:46:06 +00:00
|
|
|
nsIAtom*
|
|
|
|
nsDeckFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::deckFrame;
|
|
|
|
}
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsDeckFrame::AttributeChanged(int32_t aNameSpaceID,
|
2003-05-24 02:35:08 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
1999-04-21 22:46:15 +00:00
|
|
|
{
|
2005-09-07 16:49:21 +00:00
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
1999-04-21 22:46:15 +00:00
|
|
|
|
1999-04-25 20:07:45 +00:00
|
|
|
|
2006-12-10 18:13:48 +00:00
|
|
|
// if the index changed hide the old element and make the new element visible
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::selectedIndex) {
|
2011-10-26 23:57:55 +00:00
|
|
|
IndexChanged();
|
1999-04-21 22:46:15 +00:00
|
|
|
}
|
|
|
|
|
2000-04-25 07:10:48 +00:00
|
|
|
return rv;
|
1999-04-21 22:46:15 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 01:47:48 +00:00
|
|
|
void
|
2014-05-24 22:20:40 +00:00
|
|
|
nsDeckFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-04-21 22:46:15 +00:00
|
|
|
{
|
2013-03-20 01:47:48 +00:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2000-06-22 00:48:49 +00:00
|
|
|
|
|
|
|
mIndex = GetSelectedIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-06 03:00:57 +00:00
|
|
|
nsDeckFrame::HideBox(nsIFrame* aBox)
|
2000-06-22 00:48:49 +00:00
|
|
|
{
|
2011-10-26 23:57:55 +00:00
|
|
|
nsIPresShell::ClearMouseCapture(aBox);
|
2000-06-22 00:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-26 23:57:55 +00:00
|
|
|
nsDeckFrame::IndexChanged()
|
2000-06-22 00:48:49 +00:00
|
|
|
{
|
|
|
|
//did the index change?
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index = GetSelectedIndex();
|
2000-06-22 00:48:49 +00:00
|
|
|
if (index == mIndex)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// redraw
|
2012-08-29 05:39:31 +00:00
|
|
|
InvalidateFrame();
|
2000-06-22 00:48:49 +00:00
|
|
|
|
|
|
|
// hide the currently showing box
|
2012-08-06 03:00:57 +00:00
|
|
|
nsIFrame* currentBox = GetSelectedBox();
|
2001-01-11 01:56:27 +00:00
|
|
|
if (currentBox) // only hide if it exists
|
2011-10-26 23:57:55 +00:00
|
|
|
HideBox(currentBox);
|
2000-06-22 00:48:49 +00:00
|
|
|
|
2006-12-10 18:13:48 +00:00
|
|
|
mIndex = index;
|
2012-12-28 08:15:02 +00:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
nsAccessibilityService* accService = GetAccService();
|
|
|
|
if (accService) {
|
|
|
|
accService->DeckPanelSwitched(PresContext()->GetPresShell(), mContent,
|
|
|
|
currentBox, GetSelectedBox());
|
|
|
|
}
|
|
|
|
#endif
|
2000-06-22 00:48:49 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2000-06-22 00:48:49 +00:00
|
|
|
nsDeckFrame::GetSelectedIndex()
|
|
|
|
{
|
2003-05-24 02:35:08 +00:00
|
|
|
// default index is 0
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index = 0;
|
1999-04-21 22:46:15 +00:00
|
|
|
|
|
|
|
// get the index attribute
|
|
|
|
nsAutoString value;
|
2006-12-26 17:47:52 +00:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::selectedIndex, value))
|
1999-04-21 22:46:15 +00:00
|
|
|
{
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult error;
|
1999-04-21 22:46:15 +00:00
|
|
|
|
|
|
|
// convert it to an integer
|
|
|
|
index = value.ToInteger(&error);
|
|
|
|
}
|
|
|
|
|
2000-06-22 00:48:49 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2011-10-26 23:57:55 +00:00
|
|
|
nsIFrame*
|
2000-06-22 00:48:49 +00:00
|
|
|
nsDeckFrame::GetSelectedBox()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return (mIndex >= 0) ? mFrames.FrameAt(mIndex) : nullptr;
|
1999-04-21 22:46:15 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2006-01-26 02:29:17 +00:00
|
|
|
nsDeckFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
1999-04-21 22:46:15 +00:00
|
|
|
{
|
1999-05-19 22:14:11 +00:00
|
|
|
// if a tab is hidden all its children are too.
|
2013-02-16 21:51:02 +00:00
|
|
|
if (!StyleVisibility()->mVisible)
|
2013-02-14 11:12:27 +00:00
|
|
|
return;
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
nsBoxFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
1999-04-21 22:46:15 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 12:22:06 +00: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);
|
|
|
|
}
|
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2006-01-26 02:29:17 +00:00
|
|
|
nsDeckFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
1999-04-21 22:46:15 +00:00
|
|
|
{
|
2006-01-26 02:29:17 +00:00
|
|
|
// only paint the selected box
|
2012-08-06 03:00:57 +00:00
|
|
|
nsIFrame* box = GetSelectedBox();
|
2006-01-26 02:29:17 +00:00
|
|
|
if (!box)
|
2013-02-14 11:12:27 +00:00
|
|
|
return;
|
2003-11-15 00:47:43 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
// 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());
|
2013-02-14 11:08:08 +00:00
|
|
|
BuildDisplayListForChild(aBuilder, box, aDirtyRect, set);
|
1999-04-21 22:46:15 +00:00
|
|
|
}
|
|
|
|
|
1999-10-29 22:13:57 +00:00
|
|
|
NS_IMETHODIMP
|
2016-04-21 04:28:35 +00:00
|
|
|
nsDeckFrame::DoXULLayout(nsBoxLayoutState& aState)
|
1999-05-09 21:46:24 +00:00
|
|
|
{
|
2004-06-22 02:55:04 +00:00
|
|
|
// Make sure we tweak the state so it does not resize our children.
|
2003-05-24 02:35:08 +00:00
|
|
|
// We will do that.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t oldFlags = aState.LayoutFlags();
|
2000-06-22 00:48:49 +00:00
|
|
|
aState.SetLayoutFlags(NS_FRAME_NO_SIZE_VIEW | NS_FRAME_NO_VISIBILITY);
|
1999-05-09 21:46:24 +00:00
|
|
|
|
2000-06-22 00:48:49 +00:00
|
|
|
// do a normal layout
|
2016-04-21 04:28:35 +00:00
|
|
|
nsresult rv = nsBoxFrame::DoXULLayout(aState);
|
1999-05-19 22:14:11 +00:00
|
|
|
|
2000-06-22 00:48:49 +00:00
|
|
|
// run though each child. Hide all but the selected one
|
2016-04-21 04:28:32 +00:00
|
|
|
nsIFrame* box = nsBox::GetChildXULBox(this);
|
1999-10-29 22:13:57 +00:00
|
|
|
|
1999-07-23 00:11:21 +00:00
|
|
|
nscoord count = 0;
|
2000-06-22 00:48:49 +00:00
|
|
|
while (box)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
|
|
|
// make collapsed children not show up
|
2011-10-26 23:57:55 +00:00
|
|
|
if (count != mIndex)
|
|
|
|
HideBox(box);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
box = GetNextXULBox(box);
|
2000-03-31 07:02:06 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2000-06-22 00:48:49 +00:00
|
|
|
aState.SetLayoutFlags(oldFlags);
|
1999-07-23 00:11:21 +00:00
|
|
|
|
1999-10-29 22:13:57 +00:00
|
|
|
return rv;
|
1999-07-23 00:11:21 +00:00
|
|
|
}
|
|
|
|
|