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