1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
37
#include "nsHTMLParts.h"
38
#include "nsContainerFrame.h"
39
#include "nsCSSRendering.h"
40
#include "nsIDocument.h"
41
#include "nsIPresContext.h"
42
#include "nsViewsCID.h"
44
#include "nsIViewManager.h"
45
#include "nsIWidget.h"
46
#include "nsPageFrame.h"
47
#include "nsIRenderingContext.h"
48
#include "nsGUIEvent.h"
49
#include "nsIDOMEvent.h"
50
#include "nsStyleConsts.h"
51
#include "nsIViewManager.h"
52
#include "nsHTMLAtoms.h"
53
#include "nsIEventStateManager.h"
54
#include "nsIDeviceContext.h"
55
#include "nsIScrollableView.h"
56
#include "nsLayoutAtoms.h"
57
#include "nsIPresShell.h"
58
#include "nsBoxFrame.h"
59
#include "nsStackLayout.h"
60
#include "nsIRootBox.h"
61
#include "nsIContent.h"
62
#include "nsXULTooltipListener.h"
66
//#define DEBUG_REFLOW
68
class nsRootBoxFrame : public nsBoxFrame, public nsIRootBox {
71
friend nsresult NS_NewBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
73
nsRootBoxFrame(nsIPresShell* aShell);
75
NS_DECL_ISUPPORTS_INHERITED
77
NS_IMETHOD GetPopupSetFrame(nsIFrame** aResult);
78
NS_IMETHOD SetPopupSetFrame(nsIFrame* aPopupSet);
79
NS_IMETHOD GetDefaultTooltip(nsIContent** aResult);
80
NS_IMETHOD SetDefaultTooltip(nsIContent* aTooltip);
81
NS_IMETHOD AddTooltipSupport(nsIContent* aNode);
82
NS_IMETHOD RemoveTooltipSupport(nsIContent* aNode);
84
NS_IMETHOD AppendFrames(nsIPresContext* aPresContext,
85
nsIPresShell& aPresShell,
87
nsIFrame* aFrameList);
88
NS_IMETHOD InsertFrames(nsIPresContext* aPresContext,
89
nsIPresShell& aPresShell,
92
nsIFrame* aFrameList);
93
NS_IMETHOD RemoveFrame(nsIPresContext* aPresContext,
94
nsIPresShell& aPresShell,
98
NS_IMETHOD Reflow(nsIPresContext* aPresContext,
99
nsHTMLReflowMetrics& aDesiredSize,
100
const nsHTMLReflowState& aReflowState,
101
nsReflowStatus& aStatus);
102
NS_IMETHOD HandleEvent(nsIPresContext* aPresContext,
104
nsEventStatus* aEventStatus);
105
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
106
const nsPoint& aPoint,
107
nsFramePaintLayer aWhichLayer,
111
* Get the "type" of the frame
113
* @see nsLayoutAtoms::rootFrame
115
virtual nsIAtom* GetType() const;
118
NS_IMETHOD GetFrameName(nsString& aResult) const;
121
nsIFrame* mPopupSetFrame;
124
nsIContent* mDefaultTooltip;
127
//----------------------------------------------------------------------
130
NS_NewRootBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
132
NS_PRECONDITION(aNewFrame, "null OUT ptr");
133
if (nsnull == aNewFrame) {
134
return NS_ERROR_NULL_POINTER;
136
nsRootBoxFrame* it = new (aPresShell) nsRootBoxFrame (aPresShell);
138
return NS_ERROR_OUT_OF_MEMORY;
146
nsRootBoxFrame::nsRootBoxFrame(nsIPresShell* aShell):nsBoxFrame(aShell, PR_TRUE)
148
mPopupSetFrame = nsnull;
150
nsCOMPtr<nsIBoxLayout> layout;
151
NS_NewStackLayout(aShell, layout);
152
SetLayoutManager(layout);
156
nsRootBoxFrame::AppendFrames(nsIPresContext* aPresContext,
157
nsIPresShell& aPresShell,
159
nsIFrame* aFrameList)
163
NS_ASSERTION(!aListName, "unexpected child list name");
164
NS_PRECONDITION(mFrames.IsEmpty(), "already have a child frame");
166
// We only support unnamed principal child list
167
rv = NS_ERROR_INVALID_ARG;
169
} else if (!mFrames.IsEmpty()) {
170
// We only allow a single child frame
171
rv = NS_ERROR_FAILURE;
174
rv = nsBoxFrame::AppendFrames(aPresContext, aPresShell, aListName, aFrameList);
181
nsRootBoxFrame::InsertFrames(nsIPresContext* aPresContext,
182
nsIPresShell& aPresShell,
184
nsIFrame* aPrevFrame,
185
nsIFrame* aFrameList)
189
// Because we only support a single child frame inserting is the same
191
NS_PRECONDITION(!aPrevFrame, "unexpected previous sibling frame");
193
rv = NS_ERROR_UNEXPECTED;
195
rv = AppendFrames(aPresContext, aPresShell, aListName, aFrameList);
202
nsRootBoxFrame::RemoveFrame(nsIPresContext* aPresContext,
203
nsIPresShell& aPresShell,
209
NS_ASSERTION(!aListName, "unexpected child list name");
211
// We only support the unnamed principal child list
212
rv = NS_ERROR_INVALID_ARG;
214
} else if (aOldFrame == mFrames.FirstChild()) {
215
rv = nsBoxFrame::RemoveFrame(aPresContext, aPresShell, aListName, aOldFrame);
217
rv = NS_ERROR_FAILURE;
224
PRInt32 gReflows = 0;
228
nsRootBoxFrame::Reflow(nsIPresContext* aPresContext,
229
nsHTMLReflowMetrics& aDesiredSize,
230
const nsHTMLReflowState& aReflowState,
231
nsReflowStatus& aStatus)
233
DO_GLOBAL_REFLOW_COUNT("nsRootBoxFrame", aReflowState.reason);
237
printf("----Reflow %d----\n", gReflows);
239
return nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
243
nsRootBoxFrame::HandleEvent(nsIPresContext* aPresContext,
245
nsEventStatus* aEventStatus)
247
NS_ENSURE_ARG_POINTER(aEventStatus);
248
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
252
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP ||
253
aEvent->message == NS_MOUSE_MIDDLE_BUTTON_UP ||
254
aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP) {
255
nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
262
nsRootBoxFrame::GetFrameForPoint(nsIPresContext* aPresContext,
263
const nsPoint& aPoint,
264
nsFramePaintLayer aWhichLayer,
267
// this should act like a block, so we need to override
268
return nsBoxFrame::GetFrameForPoint(aPresContext, aPoint, aWhichLayer, aFrame);
272
nsRootBoxFrame::GetType() const
274
return nsLayoutAtoms::rootFrame;
278
nsRootBoxFrame::GetPopupSetFrame(nsIFrame** aResult)
280
*aResult = mPopupSetFrame;
285
nsRootBoxFrame::SetPopupSetFrame(nsIFrame* aPopupSet)
287
// Under normal conditions this should only be called once. However,
288
// if something triggers ReconstructDocElementHierarchy, we will
289
// destroy this frame's child (the nsDocElementBoxFrame), but not this
290
// frame. This will cause the popupset to remove itself by calling
291
// |SetPopupSetFrame(nsnull)|, and then we'll be able to accept a new
292
// popupset. Since the anonymous content is associated with the
293
// nsDocElementBoxFrame, we'll get a new popupset when the new doc
294
// element box frame is created.
295
if (!mPopupSetFrame || !aPopupSet) {
296
mPopupSetFrame = aPopupSet;
298
NS_NOTREACHED("Popup set is already defined! Only 1 allowed.");
304
nsRootBoxFrame::GetDefaultTooltip(nsIContent** aTooltip)
306
*aTooltip = mDefaultTooltip;
311
nsRootBoxFrame::SetDefaultTooltip(nsIContent* aTooltip)
313
mDefaultTooltip = aTooltip;
318
nsRootBoxFrame::AddTooltipSupport(nsIContent* aNode)
320
// listener will be refcounted by dom event targets that
321
// it will add itself to, and destroyed when those targets
323
nsXULTooltipListener* listener = new nsXULTooltipListener();
325
return NS_ERROR_OUT_OF_MEMORY;
327
listener->Init(aNode, this);
332
nsRootBoxFrame::RemoveTooltipSupport(nsIContent* aNode)
334
// XXjh yuck, I'll have to implement a way to get at
335
// the tooltip listener for a given node to make
336
// this work. Not crucial, we aren't removing
337
// tooltips from any nodes in the app just yet.
338
return NS_ERROR_NOT_IMPLEMENTED;
341
NS_IMETHODIMP_(nsrefcnt)
342
nsRootBoxFrame::AddRef(void)
347
NS_IMETHODIMP_(nsrefcnt)
348
nsRootBoxFrame::Release(void)
353
NS_INTERFACE_MAP_BEGIN(nsRootBoxFrame)
354
NS_INTERFACE_MAP_ENTRY(nsIRootBox)
355
NS_INTERFACE_MAP_END_INHERITING(nsBoxFrame)
359
nsRootBoxFrame::GetFrameName(nsString& aResult) const
361
return MakeFrameName(NS_LITERAL_STRING("RootBox"), aResult);