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