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
|
|
|
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsStackLayout.h"
|
|
|
|
#include "nsIRootBox.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsXULTooltipListener.h"
|
|
|
|
#include "nsFrameManager.h"
|
2013-09-25 04:21:22 -07:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-01 20:46:03 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Interface IDs
|
|
|
|
|
|
|
|
//#define DEBUG_REFLOW
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIRootBox*
|
|
|
|
nsIRootBox::GetRootBox(nsIPresShell* aShell)
|
|
|
|
{
|
|
|
|
if (!aShell) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = aShell->FrameManager()->GetRootFrame();
|
|
|
|
if (!rootFrame) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rootFrame) {
|
2011-08-24 13:54:30 -07:00
|
|
|
rootFrame = rootFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIRootBox* rootBox = do_QueryFrame(rootFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rootBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsRootBoxFrame : public nsBoxFrame, public nsIRootBox {
|
|
|
|
public:
|
|
|
|
|
|
|
|
friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|
|
|
|
|
|
|
nsRootBoxFrame(nsIPresShell* aShell, nsStyleContext *aContext);
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsPopupSetFrame* GetPopupSetFrame() MOZ_OVERRIDE;
|
|
|
|
virtual void SetPopupSetFrame(nsPopupSetFrame* aPopupSet) MOZ_OVERRIDE;
|
|
|
|
virtual nsIContent* GetDefaultTooltip() MOZ_OVERRIDE;
|
|
|
|
virtual void SetDefaultTooltip(nsIContent* aTooltip) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult AddTooltipSupport(nsIContent* aNode) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult RemoveTooltipSupport(nsIContent* aNode) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult AppendFrames(ChildListID aListID,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult InsertFrames(ChildListID aListID,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsIFrame* aPrevFrame,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult RemoveFrame(ChildListID aListID,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsIFrame* aOldFrame) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-12 15:47:41 -07:00
|
|
|
virtual nsresult Reflow(nsPresContext* aPresContext,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsReflowStatus& aStatus) MOZ_OVERRIDE;
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2014-02-18 00:36:33 -08:00
|
|
|
WidgetGUIEvent* aEvent,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsEventStatus* aEventStatus) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsGkAtoms::rootFrame
|
|
|
|
*/
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Override bogus IsFrameOfType in nsBoxFrame.
|
|
|
|
if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsBoxFrame::IsFrameOfType(aFlags);
|
|
|
|
}
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsPopupSetFrame* mPopupSetFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIContent* mDefaultTooltip;
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewRootBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsRootBoxFrame (aPresShell, aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRootBoxFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRootBoxFrame::nsRootBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
2011-10-17 07:59:28 -07:00
|
|
|
nsBoxFrame(aShell, aContext, true)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mPopupSetFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-11 07:05:10 -07:00
|
|
|
nsCOMPtr<nsBoxLayout> layout;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_NewStackLayout(aShell, layout);
|
|
|
|
SetLayoutManager(layout);
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsRootBoxFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list ID");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_PRECONDITION(mFrames.IsEmpty(), "already have a child frame");
|
2011-08-24 13:54:30 -07:00
|
|
|
if (aListID != kPrincipalList) {
|
|
|
|
// We only support the principal child list.
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
} else if (!mFrames.IsEmpty()) {
|
2011-08-24 13:54:30 -07:00
|
|
|
// We only allow a single child frame.
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
2011-08-24 13:54:30 -07:00
|
|
|
rv = nsBoxFrame::AppendFrames(aListID, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsRootBoxFrame::InsertFrames(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Because we only support a single child frame inserting is the same
|
2011-08-24 13:54:30 -07:00
|
|
|
// as appending.
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_PRECONDITION(!aPrevFrame, "unexpected previous sibling frame");
|
|
|
|
if (aPrevFrame) {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
} else {
|
2011-08-24 13:54:30 -07:00
|
|
|
rv = AppendFrames(aListID, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsRootBoxFrame::RemoveFrame(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list ID");
|
|
|
|
if (aListID != kPrincipalList) {
|
|
|
|
// We only support the principal child list.
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
} else if (aOldFrame == mFrames.FirstChild()) {
|
2011-08-24 13:54:30 -07:00
|
|
|
rv = nsBoxFrame::RemoveFrame(aListID, aOldFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_REFLOW
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t gReflows = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2014-05-12 15:47:41 -07:00
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsRootBoxFrame::Reflow(nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsRootBoxFrame");
|
|
|
|
|
|
|
|
#ifdef DEBUG_REFLOW
|
|
|
|
gReflows++;
|
|
|
|
printf("----Reflow %d----\n", gReflows);
|
|
|
|
#endif
|
|
|
|
return nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRootBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// root boxes don't need a debug border/outline or a selection overlay...
|
|
|
|
// They *may* have a background propagated to them, so force creation
|
|
|
|
// of a background display list element.
|
2013-02-14 03:08:08 -08:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2013-10-01 20:46:03 -07:00
|
|
|
nsRootBoxFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
|
|
|
nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// REVIEW: The override here was doing nothing since nsBoxFrame is our
|
|
|
|
// parent class
|
|
|
|
nsIAtom*
|
|
|
|
nsRootBoxFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::rootFrame;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsPopupSetFrame*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRootBoxFrame::GetPopupSetFrame()
|
|
|
|
{
|
|
|
|
return mPopupSetFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-07-04 08:49:38 -07:00
|
|
|
nsRootBoxFrame::SetPopupSetFrame(nsPopupSetFrame* aPopupSet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Under normal conditions this should only be called once. However,
|
|
|
|
// if something triggers ReconstructDocElementHierarchy, we will
|
|
|
|
// destroy this frame's child (the nsDocElementBoxFrame), but not this
|
|
|
|
// frame. This will cause the popupset to remove itself by calling
|
2012-07-30 07:20:58 -07:00
|
|
|
// |SetPopupSetFrame(nullptr)|, and then we'll be able to accept a new
|
2007-03-22 10:30:00 -07:00
|
|
|
// popupset. Since the anonymous content is associated with the
|
|
|
|
// nsDocElementBoxFrame, we'll get a new popupset when the new doc
|
|
|
|
// element box frame is created.
|
|
|
|
if (!mPopupSetFrame || !aPopupSet) {
|
|
|
|
mPopupSetFrame = aPopupSet;
|
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("Popup set is already defined! Only 1 allowed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsRootBoxFrame::GetDefaultTooltip()
|
|
|
|
{
|
|
|
|
return mDefaultTooltip;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRootBoxFrame::SetDefaultTooltip(nsIContent* aTooltip)
|
|
|
|
{
|
|
|
|
mDefaultTooltip = aTooltip;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsRootBoxFrame::AddTooltipSupport(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
|
|
|
|
2007-04-12 13:59:01 -07:00
|
|
|
nsXULTooltipListener *listener = nsXULTooltipListener::GetInstance();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!listener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-04-12 13:59:01 -07:00
|
|
|
return listener->AddTooltipSupport(aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsRootBoxFrame::RemoveTooltipSupport(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
// XXjh yuck, I'll have to implement a way to get at
|
|
|
|
// the tooltip listener for a given node to make
|
|
|
|
// this work. Not crucial, we aren't removing
|
|
|
|
// tooltips from any nodes in the app just yet.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsRootBoxFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIRootBox)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRootBoxFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("RootBox"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|