1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3
* The contents of this file are subject to the Netscape Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/NPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is Mozilla Communicator client code.
15
* The Initial Developer of the Original Code is Netscape Communications
16
* Corporation. Portions created by Netscape are
17
* Copyright (C) 1998 Netscape Communications Corporation. All
21
* Pierre Phaneuf <pp@ludusdesign.com>
22
* Brian Ryner <bryner@brianryner.com>
23
* This Original Code has been modified by IBM Corporation. Modifications made by IBM
24
* described herein are Copyright (c) International Business Machines Corporation, 2000.
25
* Modifications to Mozilla code or documentation identified per MPL Section 3.3
27
* Date Modified by Description of modification
28
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
34
#include "nsBrowserWindow.h"
35
#include "nsIAppShell.h"
36
#include "nsIWidget.h"
37
#include "nsITextWidget.h"
38
#include "nsIButton.h"
40
#include "nsIDOMDocument.h"
42
#include "nsIChannel.h"
43
#include "nsNetUtil.h"
44
#include "nsIDOMWindowInternal.h"
45
#include "nsIFilePicker.h"
46
#include "nsILookAndFeel.h"
47
#include "nsIComponentManager.h"
48
#include "nsIFactory.h"
50
#include "nsWidgetsCID.h"
51
#include "nsViewerApp.h"
53
#include "nsIComponentManager.h"
54
#include "nsParserCIID.h"
56
#include "nsIServiceManager.h"
57
#include "nsIStringBundle.h"
58
#include "nsLayoutCID.h"
59
#include "nsIDocumentViewer.h"
60
#include "nsIContentViewer.h"
61
#include "nsIContentViewerFile.h"
62
#include "nsIPresShell.h"
63
#include "nsIPresContext.h"
64
#include "nsIDocument.h"
65
#include "nsILayoutDebugger.h"
66
#include "nsThrobber.h"
67
#include "nsIDocShellTreeItem.h"
68
#include "nsIDocShellTreeNode.h"
69
#include "nsIWebNavigation.h"
70
#include "nsIWebBrowserFocus.h"
71
#include "nsIBaseWindow.h"
72
#include "nsXPIDLString.h"
73
#include "nsReadableUtils.h"
74
#include "nsIViewManager.h"
75
#include "nsGUIEvent.h"
76
#include "nsIWebProgress.h"
77
#include "nsIWebBrowserSetup.h"
78
#include "nsIWebBrowserPrint.h"
80
#include "nsCWebBrowser.h"
81
#include "nsUnicharUtils.h"
83
#include "nsIParser.h"
84
#include "nsEditorMode.h"
86
// Needed for "Find" GUI
87
#include "nsICheckButton.h"
89
#include "nsWidgetSupport.h"
91
#include "nsXPBaseWindow.h"
93
#include "resources.h"
99
#include <ctype.h> // tolower
102
#include "nsISelection.h"
103
#include "nsISelectionController.h"
105
// XXX For font setting below
107
#include "nsUnitConversion.h"
108
#include "nsIDeviceContext.h"
110
#if defined(CookieManagement) || defined(SingleSignon) || defined(ClientWallet)
111
#include "nsIServiceManager.h"
114
#ifdef CookieManagement
119
#include "nsIIOService.h"
120
#include "nsNetCID.h"
121
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
123
#if defined(ClientWallet) || defined(SingleSignon)
124
#include "nsIWalletService.h"
125
static NS_DEFINE_IID(kIWalletServiceIID, NS_IWALLETSERVICE_IID);
126
static NS_DEFINE_CID(kWalletServiceCID, NS_WALLETSERVICE_CID);
135
#define CLEANUP_WIDGET(_widget, _txt) \
137
DestroyWidget((_widget)); \
138
refCnt = (_widget)->Release(); \
139
(_widget) = nsnull; \
140
NS_ASSERTION(refCnt == 0, (_txt)); \
144
// XXX greasy constants
146
#define THROBBER_WIDTH 32
147
#define THROBBER_HEIGHT 32
148
#define THROBBER_AT "resource:/res/throbber/anims%02d.gif"
151
#define THROBBER_WIDTH 42
152
#define THROBBER_HEIGHT 42
153
#define THROBBER_AT "resource:/res/throbber/LargeAnimation%02d.gif"
156
#define BUTTON_WIDTH 90
157
#define BUTTON_HEIGHT THROBBER_HEIGHT
158
#define MAX_TEXT_LENGTH 30000
160
#ifdef INSET_WEBSHELL
161
#define WEBSHELL_LEFT_INSET 5
162
#define WEBSHELL_RIGHT_INSET 5
163
#define WEBSHELL_TOP_INSET 5
164
#define WEBSHELL_BOTTOM_INSET 5
166
#define WEBSHELL_LEFT_INSET 0
167
#define WEBSHELL_RIGHT_INSET 0
168
#define WEBSHELL_TOP_INSET 0
169
#define WEBSHELL_BOTTOM_INSET 0
172
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
173
static NS_DEFINE_CID(kButtonCID, NS_BUTTON_CID);
174
static NS_DEFINE_CID(kTextFieldCID, NS_TEXTFIELD_CID);
175
static NS_DEFINE_CID(kWindowCID, NS_WINDOW_CID);
177
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
178
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
179
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
180
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
181
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
182
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
183
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
184
static NS_DEFINE_CID(kXPBaseWindowCID, NS_XPBASE_WINDOW_CID);
185
static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID);
187
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
189
static NS_DEFINE_IID(kILayoutDebuggerIID, NS_ILAYOUT_DEBUGGER_IID);
190
static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID);
192
#define FILE_PROTOCOL "file://"
194
#ifdef USE_LOCAL_WIDGETS
195
extern nsresult NS_NewButton(nsIButton** aControl);
196
extern nsresult NS_NewLabel(nsILabel** aControl);
197
extern nsresult NS_NewTextWidget(nsITextWidget** aControl);
198
extern nsresult NS_NewCheckButton(nsICheckButton** aControl);
201
//******* Cleanup Above here***********/
203
//*****************************************************************************
204
// nsBrowserWindow::nsIBaseWindow
205
//*****************************************************************************
207
NS_IMETHODIMP nsBrowserWindow::InitWindow(nativeWindow aParentNativeWindow,
208
nsIWidget* parentWidget, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
210
// Ignore wigdet parents for now. Don't think those are a vaild thing to call.
211
NS_ENSURE_SUCCESS(SetPositionAndSize(x, y, cx, cy, PR_FALSE), NS_ERROR_FAILURE);
216
NS_IMETHODIMP nsBrowserWindow::Create()
218
NS_ASSERTION(PR_FALSE, "You can't call this");
219
return NS_ERROR_UNEXPECTED;
222
NS_IMETHODIMP nsBrowserWindow::Destroy()
226
nsCOMPtr<nsIBaseWindow> docShellWin(do_QueryInterface(mDocShell));
227
docShellWin->Destroy();
232
CLEANUP_WIDGET(mBack, "nsBrowserWindow::Destroy - mBack is being leaked.");
233
CLEANUP_WIDGET(mForward, "nsBrowserWindow::Destroy - mForward is being leaked.");
234
CLEANUP_WIDGET(mLocation, "nsBrowserWindow::Destroy - mLocation is being leaked.");
235
CLEANUP_WIDGET(mStatus, "nsBrowserWindow::Destroy - mStatus is being leaked.");
238
mThrobber->Destroy();
239
refCnt = mThrobber->Release();
241
NS_ASSERTION(refCnt == 0, "nsBrowserWindow::Destroy - mThrobber is being leaked.");
245
// Others are holding refs to this,
246
// but it gets released OK.
247
DestroyWidget(mWindow);
249
// NS_RELEASE(mWindow);
254
NS_IMETHODIMP nsBrowserWindow::SetPosition(PRInt32 aX, PRInt32 aY)
259
NS_ENSURE_SUCCESS(GetSize(&cx, &cy), NS_ERROR_FAILURE);
260
NS_ENSURE_SUCCESS(SetPositionAndSize(aX, aY, cx, cy, PR_FALSE),
265
NS_IMETHODIMP nsBrowserWindow::GetPosition(PRInt32* aX, PRInt32* aY)
267
return GetPositionAndSize(aX, aY, nsnull, nsnull);
270
NS_IMETHODIMP nsBrowserWindow::SetSize(PRInt32 aCX, PRInt32 aCY, PRBool aRepaint)
275
NS_ENSURE_SUCCESS(GetPosition(&x, &y), NS_ERROR_FAILURE);
276
NS_ENSURE_SUCCESS(SetPositionAndSize(x, y, aCX, aCY, aRepaint),
282
NS_IMETHODIMP nsBrowserWindow::GetSize(PRInt32* aCX, PRInt32* aCY)
284
return GetPositionAndSize(nsnull, nsnull, aCX, aCY);
287
NS_IMETHODIMP nsBrowserWindow::SetPositionAndSize(PRInt32 aX, PRInt32 aY,
288
PRInt32 aCX, PRInt32 aCY, PRBool aRepaint)
290
NS_ENSURE_SUCCESS(mWindow->Resize(aX, aY, aCX, aCY, aRepaint),
296
NS_IMETHODIMP nsBrowserWindow::GetPositionAndSize(PRInt32* aX, PRInt32* aY,
297
PRInt32* aCX, PRInt32* aCY)
301
NS_ENSURE_SUCCESS(mWindow->GetBounds(bounds), NS_ERROR_FAILURE);
310
*aCY = bounds.height;
315
NS_IMETHODIMP nsBrowserWindow::Repaint(PRBool aForce)
318
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
322
NS_IMETHODIMP nsBrowserWindow::GetParentWidget(nsIWidget** aParentWidget)
324
NS_ENSURE_ARG_POINTER(aParentWidget);
326
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
330
NS_IMETHODIMP nsBrowserWindow::SetParentWidget(nsIWidget* aParentWidget)
332
NS_ASSERTION(PR_FALSE, "You can't call this");
333
return NS_ERROR_NOT_IMPLEMENTED;
336
NS_IMETHODIMP nsBrowserWindow::GetParentNativeWindow(nativeWindow* aParentNativeWindow)
338
NS_ENSURE_ARG_POINTER(aParentNativeWindow);
341
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
345
NS_IMETHODIMP nsBrowserWindow::SetParentNativeWindow(nativeWindow aParentNativeWindow)
347
NS_ASSERTION(PR_FALSE, "You can't call this");
348
return NS_ERROR_NOT_IMPLEMENTED;
351
NS_IMETHODIMP nsBrowserWindow::GetVisibility(PRBool* aVisibility)
353
NS_ENSURE_ARG_POINTER(aVisibility);
356
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
360
NS_IMETHODIMP nsBrowserWindow::SetVisibility(PRBool aVisibility)
362
NS_ENSURE_STATE(mWindow);
364
NS_ENSURE_SUCCESS(mWindow->Show(aVisibility), NS_ERROR_FAILURE);
369
NS_IMETHODIMP nsBrowserWindow::GetEnabled(PRBool *aEnabled)
371
NS_ENSURE_ARG_POINTER(aEnabled);
374
mWindow->IsEnabled(aEnabled);
378
NS_IMETHODIMP nsBrowserWindow::SetEnabled(PRBool aEnabled)
381
mWindow->Enable(aEnabled);
385
NS_IMETHODIMP nsBrowserWindow::GetBlurSuppression(PRBool *aBlurSuppression)
387
NS_ENSURE_ARG_POINTER(aBlurSuppression);
388
*aBlurSuppression = PR_FALSE;
389
return NS_ERROR_NOT_IMPLEMENTED;
392
NS_IMETHODIMP nsBrowserWindow::SetBlurSuppression(PRBool aBlurSuppression)
394
return NS_ERROR_NOT_IMPLEMENTED;
397
NS_IMETHODIMP nsBrowserWindow::GetMainWidget(nsIWidget** aMainWidget)
399
NS_ENSURE_ARG_POINTER(aMainWidget);
402
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
406
NS_IMETHODIMP nsBrowserWindow::SetFocus()
409
//NS_WARNING("Not Yet Implemented");
413
NS_IMETHODIMP nsBrowserWindow::GetTitle(PRUnichar** aTitle)
415
NS_ENSURE_ARG_POINTER(aTitle);
417
*aTitle = ToNewUnicode(mTitle);
422
NS_IMETHODIMP nsBrowserWindow::SetTitle(const PRUnichar* aTitle)
424
NS_ENSURE_STATE(mWindow);
428
NS_ENSURE_SUCCESS(mWindow->SetTitle(nsAutoString(aTitle)), NS_ERROR_FAILURE);
433
//*****************************************************************************
434
// nsBrowserWindow: Helper Function
435
//*****************************************************************************
437
void nsBrowserWindow::DestroyWidget(nsISupports* aWidget)
440
nsCOMPtr<nsIWidget> w(do_QueryInterface(aWidget));
447
//******* Cleanup below here *************/
452
//----------------------------------------------------------------------
456
GetPresShellFor(nsIDocShell* aDocShell)
458
nsIPresShell* shell = nsnull;
459
if (nsnull != aDocShell) {
460
nsIContentViewer* cv = nsnull;
461
aDocShell->GetContentViewer(&cv);
463
nsIDocumentViewer* docv = nsnull;
464
cv->QueryInterface(kIDocumentViewerIID, (void**) &docv);
465
if (nsnull != docv) {
466
nsCOMPtr<nsIPresContext> cx;
467
docv->GetPresContext(getter_AddRefs(cx));
469
NS_IF_ADDREF(shell = cx->GetPresShell());
479
nsVoidArray* nsBrowserWindow::gBrowsers = nsnull;
482
nsBrowserWindow::FindBrowserFor(nsIWidget* aWidget, PRIntn aWhich)
485
nsBrowserWindow* result = nsnull;
490
PRInt32 i, n = gBrowsers->Count();
491
for (i = 0; i < n; i++) {
492
nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers->ElementAt(i);
497
bw->mWindow->QueryInterface(kIWidgetIID, (void**) &widget);
498
if (widget == aWidget) {
501
NS_IF_RELEASE(widget);
506
bw->mBack->QueryInterface(kIWidgetIID, (void**) &widget);
507
if (widget == aWidget) {
510
NS_IF_RELEASE(widget);
515
bw->mForward->QueryInterface(kIWidgetIID, (void**) &widget);
516
if (widget == aWidget) {
519
NS_IF_RELEASE(widget);
524
bw->mLocation->QueryInterface(kIWidgetIID, (void**) &widget);
525
if (widget == aWidget) {
528
NS_IF_RELEASE(widget);
534
if (nsnull != result) {
541
nsBrowserWindow::AddBrowser(nsBrowserWindow* aBrowser)
544
gBrowsers = new nsVoidArray();
548
gBrowsers->AppendElement(aBrowser);
553
nsBrowserWindow::RemoveBrowser(nsBrowserWindow* aBrowser)
555
//nsViewerApp* app = aBrowser->mApp;
558
gBrowsers->RemoveElement(aBrowser);
559
if (!gBrowsers->Count()) {
563
NS_RELEASE(aBrowser);
567
nsBrowserWindow::CloseAllWindows()
569
while (gBrowsers && gBrowsers->Count()) {
570
nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers->ElementAt(0);
581
static nsEventStatus PR_CALLBACK
582
HandleBrowserEvent(nsGUIEvent *aEvent)
584
nsEventStatus result = nsEventStatus_eIgnore;
585
nsBrowserWindow* bw =
586
nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_WINDOW);
588
nsSizeEvent* sizeEvent;
589
switch(aEvent->message) {
591
sizeEvent = (nsSizeEvent*)aEvent;
592
bw->Layout(sizeEvent->windowSize->width,
593
sizeEvent->windowSize->height);
594
result = nsEventStatus_eConsumeNoDefault;
600
nsViewerApp* app = bw->mApp;
601
app->CloseWindow(bw);
602
result = nsEventStatus_eConsumeDoDefault;
605
// XXX Really shouldn't just exit, we should just notify somebody...
606
if (!nsBrowserWindow::gBrowsers || !nsBrowserWindow::gBrowsers->Count()) {
613
case NS_MENU_SELECTED:
614
result = bw->DispatchMenuItem(((nsMenuEvent*)aEvent)->mCommand);
619
nsCOMPtr<nsIWebBrowserFocus> focus = do_GetInterface(bw->mWebBrowser);
627
nsCOMPtr<nsIWebBrowserFocus> focus = do_GetInterface(bw->mWebBrowser);
641
static nsEventStatus PR_CALLBACK
642
HandleBackEvent(nsGUIEvent *aEvent)
644
nsEventStatus result = nsEventStatus_eIgnore;
645
nsBrowserWindow* bw =
646
nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_BACK);
648
switch(aEvent->message) {
649
case NS_MOUSE_LEFT_BUTTON_UP:
658
static nsEventStatus PR_CALLBACK
659
HandleForwardEvent(nsGUIEvent *aEvent)
661
nsEventStatus result = nsEventStatus_eIgnore;
662
nsBrowserWindow* bw =
663
nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_FORWARD);
665
switch(aEvent->message) {
666
case NS_MOUSE_LEFT_BUTTON_UP:
675
static nsEventStatus PR_CALLBACK
676
HandleLocationEvent(nsGUIEvent *aEvent)
678
nsEventStatus result = nsEventStatus_eIgnore;
679
nsBrowserWindow* bw =
680
nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_LOCATION);
682
switch (aEvent->message) {
684
if (NS_VK_RETURN == ((nsKeyEvent*)aEvent)->keyCode) {
687
bw->mLocation->GetText(text, 1000, size);
688
bw->GoTo(text.get());
702
DispatchPurifyEvent(PRInt32 aID)
704
if (!PurifyIsRunning()) {
705
printf("!!! Re-run viewer under Purify to use this menu item.\n");
711
case VIEWER_PURIFY_SHOW_NEW_LEAKS:
712
PurifyPrintf("viewer: new leaks");
715
case VIEWER_PURIFY_SHOW_ALL_LEAKS:
716
PurifyPrintf("viewer: all leaks");
719
case VIEWER_PURIFY_CLEAR_ALL_LEAKS:
720
PurifyPrintf("viewer: clear leaks");
723
case VIEWER_PURIFY_SHOW_ALL_HANDLES_IN_USE:
724
PurifyPrintf("viewer: all handles");
725
PurifyAllHandlesInuse();
727
case VIEWER_PURIFY_SHOW_NEW_IN_USE:
728
PurifyPrintf("viewer: new in-use");
731
case VIEWER_PURIFY_SHOW_ALL_IN_USE:
732
PurifyPrintf("viewer: all in-use");
735
case VIEWER_PURIFY_CLEAR_ALL_IN_USE:
736
PurifyPrintf("viewer: clear in-use");
739
case VIEWER_PURIFY_HEAP_VALIDATE:
740
PurifyPrintf("viewer: heap validate");
741
PurifyHeapValidate(PURIFY_HEAP_ALL, PURIFY_HEAP_BLOCKS_ALL, NULL);
748
nsBrowserWindow::DispatchMenuItem(PRInt32 aID)
750
#if defined(CookieManagement) || defined(SingleSignon) || defined(ClientWallet)
752
#if defined(ClientWallet) || defined(SingleSignon)
753
nsIWalletService *walletservice;
756
#define WALLET_EDITOR_URL "file:///y|/walleted.html"
757
nsAutoString urlString; urlString.AssignWithConversion(WALLET_EDITOR_URL);
761
nsEventStatus result;
763
result = DispatchDebugMenu(aID);
764
if (nsEventStatus_eIgnore != result) {
768
result = DispatchStyleMenu(aID);
769
if (nsEventStatus_eIgnore != result) {
776
return nsEventStatus_eConsumeNoDefault;
778
case VIEWER_WINDOW_OPEN:
782
case VIEWER_FILE_OPEN:
789
// nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
790
// webShell->GetHistoryIndex(theIndex);
791
// nsXPIDLString theURL;
792
// webShell->GetURL(theIndex, getter_Copies(theURL));
793
// nsAutoString theString(theURL);
794
// mApp->ViewSource(theString);
795
//XXX Find out how the string is allocated, and perhaps delete it...
799
case VIEWER_EDIT_COPY:
803
case VIEWER_EDIT_PASTE:
807
case VIEWER_EDIT_FINDINPAGE:
830
PRIntn ix = aID - VIEWER_DEMO0;
831
nsAutoString url; url.AssignWithConversion(SAMPLES_BASE_URL);
832
url.Append(NS_LITERAL_STRING("/test"));
833
url.AppendInt(ix, 10);
834
url.Append(NS_LITERAL_STRING(".html"));
835
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
836
webNav->LoadURI(url.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
840
case VIEWER_XPTOOLKITTOOLBAR1:
842
nsAutoString url; url.AssignWithConversion(SAMPLES_BASE_URL);
843
url.Append(NS_LITERAL_STRING("/toolbarTest1.xul"));
844
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
845
webNav->LoadURI(url.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
848
case VIEWER_XPTOOLKITTREE1:
850
nsAutoString url; url.AssignWithConversion(SAMPLES_BASE_URL);
851
url.Append(NS_LITERAL_STRING("/treeTest1.xul"));
852
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
853
webNav->LoadURI(url.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
866
DoEditorMode(mDocShell);
869
case VIEWER_ONE_COLUMN:
870
case VIEWER_TWO_COLUMN:
871
case VIEWER_THREE_COLUMN:
872
ShowPrintPreview(aID);
879
case VIEWER_TABLE_INSPECTOR:
883
case VIEWER_IMAGE_INSPECTOR:
887
case VIEWER_GFX_SCROLLBARS_ON: {
888
SetBoolPref("nglayout.widget.gfxscrollbars", PR_TRUE);
891
mLocation->GetText(text, 1000, size);
896
case VIEWER_GFX_SCROLLBARS_OFF: {
897
SetBoolPref("nglayout.widget.gfxscrollbars", PR_FALSE);
900
mLocation->GetText(text, 1000, size);
905
case VIEWER_GOTO_TEST_URL1:
906
case VIEWER_GOTO_TEST_URL2: {
908
const char * pref = (aID == VIEWER_GOTO_TEST_URL1) ? "nglayout.widget.testurl1" : "nglayout.widget.testurl2";
909
GetStringPref(pref, urlStr);
911
mLocation->SetText(urlStr, size);
917
case VIEWER_SAVE_TEST_URL1:
918
case VIEWER_SAVE_TEST_URL2: {
921
mLocation->GetText(text, 1000, size);
922
const char * pref = (aID == VIEWER_SAVE_TEST_URL1) ? "nglayout.widget.testurl1" : "nglayout.widget.testurl2";
923
SetStringPref(pref, text);
928
case VIEWER_PURIFY_SHOW_NEW_LEAKS:
929
case VIEWER_PURIFY_SHOW_ALL_LEAKS:
930
case VIEWER_PURIFY_CLEAR_ALL_LEAKS:
931
case VIEWER_PURIFY_SHOW_ALL_HANDLES_IN_USE:
932
case VIEWER_PURIFY_SHOW_NEW_IN_USE:
933
case VIEWER_PURIFY_SHOW_ALL_IN_USE:
934
case VIEWER_PURIFY_CLEAR_ALL_IN_USE:
935
case VIEWER_PURIFY_HEAP_VALIDATE:
936
DispatchPurifyEvent(aID);
940
case VIEWER_ZOOM_500:
941
case VIEWER_ZOOM_300:
942
case VIEWER_ZOOM_200:
943
case VIEWER_ZOOM_100:
944
case VIEWER_ZOOM_070:
945
case VIEWER_ZOOM_050:
946
case VIEWER_ZOOM_030:
947
case VIEWER_ZOOM_020:
948
mDocShell->SetZoom((aID - VIEWER_ZOOM_BASE) / 10.0f);
956
shell = GetPresShell();
957
res = nsServiceManager::GetService(kWalletServiceCID,
959
(nsISupports **)&walletservice);
960
if ((NS_OK == res) && (nsnull != walletservice)) {
962
// res = walletservice->WALLET_Prefill(shell, (PRVCY_QPREFILL == aID));
963
NS_RELEASE(walletservice);
967
if (aID == PRVCY_PREFILL) {
968
nsAutoString url(NS_LITERAL_STRING("file:///y|/htmldlgs.htm"));
969
nsBrowserWindow* bw = nsnull;
970
mApp->OpenWindow(PRUint32(~0), bw);
971
bw->SetVisibility(PR_TRUE);
978
case PRVCY_DISPLAY_WALLET:
982
/* set a cookie for the javascript wallet editor */
983
res = nsServiceManager::GetService(kWalletServiceCID,
985
(nsISupports **)&walletservice);
986
if ((NS_OK == res) && (nsnull != walletservice)) {
988
nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &res));
989
if (NS_FAILED(res)) return nsEventStatus_eIgnore;
991
nsIURI *uri = nsnull;
992
res = service->NewURI(NS_LITERAL_CSTRING(WALLET_EDITOR_URL), nsnull, nsnull, &uri);
993
if (NS_FAILED(res)) return nsEventStatus_eIgnore;
995
res = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&url);
997
if (NS_SUCCEEDED(res)) {
998
// res = walletservice->WALLET_PreEdit(url);
999
NS_RELEASE(walletservice);
1003
/* invoke the javascript wallet editor */
1004
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
1005
webNav->LoadURI(urlString.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
1010
#if defined(CookieManagement)
1011
case PRVCY_DISPLAY_COOKIES:
1017
#if defined(SingleSignon)
1018
case PRVCY_DISPLAY_SIGNONS:
1019
res = nsServiceManager::GetService(kWalletServiceCID,
1021
(nsISupports **)&walletservice);
1022
if ((NS_OK == res) && (nsnull != walletservice)) {
1023
// res = walletservice->SI_DisplaySignonInfoAsHTML();
1024
NS_RELEASE(walletservice);
1031
// Any menu IDs that the editor uses will be processed here
1032
DoEditorTest(mDocShell, aID);
1034
return nsEventStatus_eIgnore;
1038
nsBrowserWindow::Back()
1040
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
1045
nsBrowserWindow::Forward()
1047
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
1048
webNav->GoForward();
1052
nsBrowserWindow::GoTo(const PRUnichar* aURL)
1054
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
1055
webNav->LoadURI(aURL, nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
1059
static PRBool GetFileFromFileSelector(nsIDOMWindowInternal* aParentWindow,
1060
nsILocalFile **aFile,
1061
nsILocalFile **aDisplayDirectory)
1064
nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1");
1067
rv = filePicker->Init(aParentWindow, NS_LITERAL_STRING("Open HTML"),
1068
nsIFilePicker::modeOpen);
1069
if (NS_SUCCEEDED(rv)) {
1070
filePicker->AppendFilters(nsIFilePicker::filterAll | nsIFilePicker::filterHTML |
1071
nsIFilePicker::filterXML | nsIFilePicker::filterImages);
1072
if (*aDisplayDirectory)
1073
filePicker->SetDisplayDirectory(*aDisplayDirectory);
1075
PRInt16 dialogResult;
1076
rv = filePicker->Show(&dialogResult);
1077
if (NS_FAILED(rv) || dialogResult == nsIFilePicker::returnCancel)
1080
filePicker->GetFile(aFile);
1082
NS_IF_RELEASE(*aDisplayDirectory);
1083
filePicker->GetDisplayDirectory(aDisplayDirectory);
1093
nsBrowserWindow::DoFileOpen()
1095
nsCOMPtr<nsILocalFile> file;
1096
nsCOMPtr<nsIDOMWindow> domWindow;
1097
nsCOMPtr<nsIDOMWindowInternal> parentWindow;
1100
// get nsIDOMWindowInternal interface for nsIFilePicker
1101
rv = mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
1102
if (NS_SUCCEEDED(rv))
1103
parentWindow = do_QueryInterface(domWindow);
1105
if (GetFileFromFileSelector(parentWindow, getter_AddRefs(file),
1106
getter_AddRefs(mOpenFileDirectory))) {
1107
nsCOMPtr<nsIURI> uri;
1108
NS_NewFileURI(getter_AddRefs(uri), file);
1113
// Ask the Web widget to load the file URL
1114
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
1115
webNav->LoadURI(NS_ConvertUTF8toUCS2(spec).get(),
1116
nsIWebNavigation::LOAD_FLAGS_NONE,
1120
SetVisibility(PR_TRUE);
1125
#define DIALOG_FONT "Helvetica"
1126
#define DIALOG_FONT_SIZE 10
1128
//---------------------------------------------------------------
1129
NS_IMETHODIMP nsBrowserWindow::FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound)
1131
// Insert find code here.
1136
//---------------------------------------------------------------
1137
NS_IMETHODIMP nsBrowserWindow::ForceRefresh()
1139
nsIPresShell* shell = GetPresShell();
1140
if (nsnull != shell) {
1141
nsCOMPtr<nsIViewManager> vm;
1142
shell->GetViewManager(getter_AddRefs(vm));
1145
vm->GetRootView(root);
1146
if (nsnull != root) {
1147
vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE);
1156
/**--------------------------------------------------------------------------------
1158
*--------------------------------------------------------------------------------
1163
nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent)
1165
nsEventStatus result = nsEventStatus_eIgnore;
1167
//printf("aEvent->message %d\n", aEvent->message);
1168
switch(aEvent->message) {
1173
case NS_MOUSE_LEFT_BUTTON_UP: {
1179
result = nsEventStatus_eIgnore;
1181
//printf("result: %d = %d\n", result, PR_FALSE);
1187
nsBrowserWindow::DoFind()
1192
//----------------------------------------------------------------------
1194
#define VIEWER_BUNDLE_URL NS_LITERAL_CSTRING("resource:/res/viewer.properties")
1196
static nsString* gTitleSuffix = nsnull;
1200
GetTitleSuffix(void)
1202
nsString* suffix = new nsString(" - Failed");
1203
nsIStringBundleService* service = nsnull;
1204
nsresult ret = nsServiceManager::GetService(kStringBundleServiceCID,
1205
kIStringBundleServiceIID, (nsISupports**) &service);
1206
if (NS_FAILED(ret)) {
1209
nsIURI* url = nsnull;
1210
nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &ret));
1211
if (NS_FAILED(ret)) return ret;
1213
nsIURI *uri = nsnull;
1214
ret = service->NewURI(VIEWER_BUNDLE_URL, nsnull, nsnull, &uri);
1215
if (NS_FAILED(ret)) return ret;
1217
ret = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&url);
1219
if (NS_FAILED(ret)) {
1220
NS_RELEASE(service);
1223
nsIStringBundle* bundle = nsnull;
1224
ret = service->CreateBundle(url, &bundle);
1226
if (NS_FAILED(ret)) {
1227
NS_RELEASE(service);
1230
ret = bundle->GetStringFromID(1, *suffix);
1232
NS_RELEASE(service);
1238
// Note: operator new zeros our memory
1239
nsBrowserWindow::nsBrowserWindow()
1241
if (!gTitleSuffix) {
1243
gTitleSuffix = GetTitleSuffix();
1245
if ( (gTitleSuffix = new nsString) != 0 )
1246
gTitleSuffix->Assign(NS_LITERAL_STRING(" - Raptor"));
1251
nsBrowserWindow::~nsBrowserWindow()
1253
NS_IF_RELEASE(mAppShell);
1254
NS_IF_RELEASE(mTableInspectorDialog);
1255
NS_IF_RELEASE(mImageInspectorDialog);
1256
NS_IF_RELEASE(mWebCrawler);
1258
if (nsnull != mTableInspector) {
1259
delete mTableInspector;
1261
if (nsnull != mImageInspector) {
1262
delete mImageInspector;
1264
if (mWebBrowserChrome) {
1265
mWebBrowserChrome->BrowserWindow(nsnull);
1266
NS_RELEASE(mWebBrowserChrome);
1268
if (nsnull != gTitleSuffix) {
1269
delete gTitleSuffix;
1270
gTitleSuffix = nsnull;
1274
NS_IMPL_ISUPPORTS4(nsBrowserWindow, nsIBaseWindow, nsIInterfaceRequestor, nsIProgressEventSink, nsIWebShellContainer)
1277
nsBrowserWindow::GetInterface(const nsIID& aIID,
1278
void** aInstancePtrResult)
1282
NS_PRECONDITION(aInstancePtrResult, "null pointer");
1283
if (!aInstancePtrResult)
1284
return NS_ERROR_NULL_POINTER;
1286
*aInstancePtrResult = NULL;
1288
if (aIID.Equals(NS_GET_IID(nsIWebBrowserChrome))) {
1289
rv = EnsureWebBrowserChrome();
1290
if (NS_SUCCEEDED(rv))
1291
return mWebBrowserChrome->QueryInterface(aIID, aInstancePtrResult);
1294
return QueryInterface(aIID, aInstancePtrResult);
1298
nsBrowserWindow::Init(nsIAppShell* aAppShell,
1299
const nsRect& aBounds,
1300
PRUint32 aChromeMask,
1301
PRBool aAllowPlugins)
1303
mChromeMask = aChromeMask;
1304
mAppShell = aAppShell;
1305
NS_IF_ADDREF(mAppShell);
1306
mAllowPlugins = aAllowPlugins;
1308
// Create top level window
1309
nsresult rv = nsComponentManager::CreateInstance(kWindowCID, nsnull,
1311
getter_AddRefs(mWindow));
1315
nsWidgetInitData initData;
1316
initData.mWindowType = eWindowType_toplevel;
1317
initData.mBorderStyle = eBorderStyle_default;
1319
nsRect r(0, 0, aBounds.width, aBounds.height);
1320
mWindow->Create((nsIWidget*)NULL, r, HandleBrowserEvent,
1321
nsnull, aAppShell, nsnull, &initData);
1322
mWindow->GetClientBounds(r);
1325
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
1326
NS_ENSURE_TRUE(mWebBrowser, NS_ERROR_FAILURE);
1329
nsCOMPtr<nsIBaseWindow> webBrowserWin(do_QueryInterface(mWebBrowser));
1330
rv = webBrowserWin->InitWindow(mWindow->GetNativeData(NS_NATIVE_WIDGET), nsnull, r.x, r.y, r.width, r.height);
1331
NS_ENSURE_SUCCESS(EnsureWebBrowserChrome(), NS_ERROR_FAILURE);
1332
mWebBrowser->SetContainerWindow(mWebBrowserChrome);
1334
do_GetWeakReference((nsIWebProgressListener*)mWebBrowserChrome));
1335
mWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsIWebProgressListener));
1337
webBrowserWin->Create();
1339
// Give the embedding app a chance to do platforms-specific window setup
1342
// Disable global history because we don't have profile-relative file locations
1343
nsCOMPtr<nsIWebBrowserSetup> setup(do_QueryInterface(mWebBrowser));
1345
setup->SetProperty(nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY, PR_FALSE);
1347
mDocShell = do_GetInterface(mWebBrowser);
1348
mDocShell->SetAllowPlugins(aAllowPlugins);
1349
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
1350
webShell->SetContainer((nsIWebShellContainer*) this);
1351
webBrowserWin->SetVisibility(PR_TRUE);
1353
if (nsIWebBrowserChrome::CHROME_MENUBAR & aChromeMask) {
1354
rv = CreateMenuBar(r.width);
1358
mHaveMenuBar = PR_TRUE;
1359
mWindow->GetClientBounds(r);
1363
if (nsIWebBrowserChrome::CHROME_TOOLBAR & aChromeMask) {
1364
rv = CreateToolBar(r.width);
1370
if (nsIWebBrowserChrome::CHROME_STATUSBAR & aChromeMask) {
1371
rv = CreateStatusBar(r.width);
1377
// Now lay it all out
1378
Layout(r.width, r.height);
1384
nsBrowserWindow::Init(nsIAppShell* aAppShell,
1385
const nsRect& aBounds,
1386
PRUint32 aChromeMask,
1387
PRBool aAllowPlugins,
1388
nsIDocumentViewer* aDocumentViewer,
1389
nsIPresContext* aPresContext)
1391
mChromeMask = aChromeMask;
1392
mAppShell = aAppShell;
1393
NS_IF_ADDREF(mAppShell);
1394
mAllowPlugins = aAllowPlugins;
1395
// Create top level window
1396
nsresult rv = nsComponentManager::CreateInstance(kWindowCID,
1401
getter_AddRefs(mWindow));
1405
nsWidgetInitData initData;
1406
initData.mWindowType = eWindowType_toplevel;
1407
initData.mBorderStyle = eBorderStyle_default;
1408
nsRect r(0, 0, aBounds.width, aBounds.height);
1409
mWindow->Create((nsIWidget*)NULL, r, HandleBrowserEvent,
1411
nsnull, aAppShell, nsnull, &initData);
1412
mWindow->GetClientBounds(r);
1414
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
1415
NS_ENSURE_TRUE(mWebBrowser, NS_ERROR_FAILURE);
1417
nsCOMPtr<nsIBaseWindow> webBrowserWin(do_QueryInterface(mWebBrowser));
1418
rv = webBrowserWin->InitWindow(mWindow->GetNativeData(NS_NATIVE_WIDGET),
1419
nsnull, r.x, r.y, r.width, r.height);
1420
NS_ENSURE_SUCCESS(EnsureWebBrowserChrome(), NS_ERROR_FAILURE);
1421
mWebBrowser->SetContainerWindow(mWebBrowserChrome);
1422
webBrowserWin->Create();
1423
mDocShell = do_GetInterface(mWebBrowser);
1424
mDocShell->SetAllowPlugins(aAllowPlugins);
1425
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
1426
webShell->SetContainer((nsIWebShellContainer*) this);
1427
webBrowserWin->SetVisibility(PR_TRUE);
1428
if (nsIWebBrowserChrome::CHROME_MENUBAR & aChromeMask) {
1429
rv = CreateMenuBar(r.width);
1433
mWindow->GetClientBounds(r);
1436
if (nsIWebBrowserChrome::CHROME_TOOLBAR & aChromeMask) {
1437
rv = CreateToolBar(r.width);
1442
if (nsIWebBrowserChrome::CHROME_STATUSBAR & aChromeMask)
1444
rv = CreateStatusBar(r.width);
1449
// Give the embedding app a chance to do platforms-specific window setup
1452
// Now lay it all out
1453
Layout(r.width, r.height);
1458
// Create a document viewer and bind it to the webshell
1459
nsCOMPtr<nsIDocumentViewer> docv;
1460
aDocumentViewer->CreateDocumentViewerUsing(aPresContext,
1461
getter_AddRefs(docv));
1462
docv->SetContainer(mWebBrowser);
1463
nsCOMPtr<nsIContentViewerContainer> cvContainer = do_QueryInterface(mDocShell);
1464
cvContainer->Embed(docv, "duh", nsnull);
1466
webBrowserWin->SetVisibility(PR_TRUE);
1472
nsBrowserWindow::SetWebCrawler(nsWebCrawler* aCrawler)
1476
nsCOMPtr<nsIWebProgress> progress(do_GetInterface(mDocShell));
1477
NS_ASSERTION(progress, "no web progress avail");
1479
(void) progress->RemoveProgressListener(
1480
(nsIWebProgressListener*)mWebCrawler);
1482
NS_RELEASE(mWebCrawler);
1485
mWebCrawler = aCrawler;
1486
NS_ADDREF(aCrawler);
1490
// XXX This sort of thing should be in a resource
1491
#define TOOL_BAR_FONT "Helvetica"
1492
#define TOOL_BAR_FONT_SIZE 12
1493
#define STATUS_BAR_FONT "Helvetica"
1494
#define STATUS_BAR_FONT_SIZE 10
1497
nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
1501
nsIDeviceContext* dc = mWindow->GetDeviceContext();
1503
t2d = dc->TwipsToDevUnits();
1505
d2a = dc->DevUnitsToAppUnits();
1506
nsFont font(TOOL_BAR_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
1507
NS_FONT_WEIGHT_NORMAL, 0,
1508
nscoord(NSIntPointsToTwips(TOOL_BAR_FONT_SIZE) * t2d * d2a));
1511
#ifdef USE_LOCAL_WIDGETS
1512
rv = NS_NewButton(&mBack);
1514
// Create and place back button
1515
rv = nsComponentManager::CreateInstance(kButtonCID, nsnull, kIButtonIID,
1522
nsRect r(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
1524
nsIWidget* widget = nsnull;
1525
NS_CreateButton(mWindow,mBack,r,HandleBackEvent,&font);
1526
if (NS_OK == mBack->QueryInterface(kIWidgetIID,(void**)&widget))
1528
nsAutoString back(NS_LITERAL_STRING("Back"));
1529
mBack->SetLabel(back);
1534
// Create and place forward button
1535
r.SetRect(BUTTON_WIDTH, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
1537
#ifdef USE_LOCAL_WIDGETS
1538
rv = NS_NewButton(&mForward);
1540
rv = nsComponentManager::CreateInstance(kButtonCID, nsnull, kIButtonIID,
1546
if (NS_OK == mForward->QueryInterface(kIWidgetIID,(void**)&widget))
1548
widget->Create(mWindow.get(), r, HandleForwardEvent, NULL);
1549
widget->SetFont(font);
1550
widget->Show(PR_TRUE);
1551
nsAutoString forward(NS_LITERAL_STRING("Forward"));
1552
mForward->SetLabel(forward);
1557
// Create and place location bar
1558
r.SetRect(2*BUTTON_WIDTH, 0,
1559
aWidth - 2*BUTTON_WIDTH - THROBBER_WIDTH,
1562
#ifdef USE_LOCAL_WIDGETS
1563
rv = NS_NewTextWidget(&mLocation);
1565
rv = nsComponentManager::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID,
1566
(void**)&mLocation);
1573
NS_CreateTextWidget(mWindow,mLocation,r,HandleLocationEvent,&font);
1574
if (NS_OK == mLocation->QueryInterface(kIWidgetIID,(void**)&widget))
1576
widget->SetForegroundColor(NS_RGB(0, 0, 0));
1577
widget->SetBackgroundColor(NS_RGB(255, 255, 255));
1580
mLocation->SetText(empty, size);
1581
mLocation->SetMaxTextLength(MAX_TEXT_LENGTH);
1585
// Create and place throbber
1586
r.SetRect(aWidth - THROBBER_WIDTH, 0,
1587
THROBBER_WIDTH, THROBBER_HEIGHT);
1588
mThrobber = nsThrobber::NewThrobber();
1589
nsString throbberURL; throbberURL.AssignWithConversion(THROBBER_AT);
1590
mThrobber->Init(mWindow, r, throbberURL, THROB_NUM);
1595
// Overload this method in your nsNativeBrowserWindow if you need to
1596
// have the logic in nsBrowserWindow::Layout() offset the menu within
1597
// the parent window.
1599
nsBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
1601
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
1609
nsBrowserWindow::CreateStatusBar(PRInt32 aWidth)
1613
nsIDeviceContext* dc = mWindow->GetDeviceContext();
1615
t2d = dc->TwipsToDevUnits();
1616
nsFont font(STATUS_BAR_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
1617
NS_FONT_WEIGHT_NORMAL, 0,
1618
nscoord(t2d * NSIntPointsToTwips(STATUS_BAR_FONT_SIZE)));
1621
nsRect r(0, 0, aWidth, THROBBER_HEIGHT);
1623
#ifdef USE_LOCAL_WIDGETS
1624
rv = NS_NewTextWidget(&mStatus);
1626
rv = nsComponentManager::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID,
1634
nsIWidget* widget = nsnull;
1635
NS_CreateTextWidget(mWindow,mStatus,r,HandleLocationEvent,&font);
1636
if (NS_OK == mStatus->QueryInterface(kIWidgetIID,(void**)&widget))
1638
widget->SetForegroundColor(NS_RGB(0, 0, 0));
1640
mStatus->SetText(nsAutoString(),size);
1641
mStatus->SetMaxTextLength(MAX_TEXT_LENGTH);
1643
nsITextWidget* textWidget = nsnull;
1644
if (NS_OK == mStatus->QueryInterface(kITextWidgetIID,(void**)&textWidget))
1647
textWidget->SetReadOnly(PR_TRUE, wasReadOnly);
1648
NS_RELEASE(textWidget);
1658
nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
1661
nscoord menuBarHeight;
1662
nsILookAndFeel * lookAndFeel;
1663
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
1664
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight);
1665
NS_RELEASE(lookAndFeel);
1670
// Find out the menubar height
1671
GetMenuBarHeight(&menuBarHeight);
1673
nsRect rr(0, 0, aWidth, aHeight);
1675
// position location bar (it's stretchy)
1676
if (nsIWebBrowserChrome::CHROME_TOOLBAR & mChromeMask) {
1677
nsIWidget* locationWidget = nsnull;
1679
NS_SUCCEEDED(mLocation->QueryInterface(kIWidgetIID,
1680
(void**)&locationWidget))) {
1682
PRInt32 width = PR_MAX(aWidth - (2*BUTTON_WIDTH + THROBBER_WIDTH), 0);
1684
locationWidget->Resize(2*BUTTON_WIDTH, menuBarHeight,
1688
mThrobber->MoveTo(aWidth - THROBBER_WIDTH, menuBarHeight);
1691
PRInt32 width = PR_MAX(aWidth - 2*BUTTON_WIDTH, 0);
1692
locationWidget->Resize(2*BUTTON_WIDTH, menuBarHeight,
1698
locationWidget->Show(PR_TRUE);
1699
NS_RELEASE(locationWidget);
1701
nsIWidget* w = nsnull;
1703
NS_SUCCEEDED(mBack->QueryInterface(kIWidgetIID, (void**)&w))) {
1704
w->Move(0, menuBarHeight);
1709
NS_SUCCEEDED(mForward->QueryInterface(kIWidgetIID, (void**)&w))) {
1710
w->Move(BUTTON_WIDTH, menuBarHeight);
1717
nsIWidget* w = nsnull;
1719
NS_SUCCEEDED(mLocation->QueryInterface(kIWidgetIID, (void**)&w))) {
1724
NS_SUCCEEDED(mBack->QueryInterface(kIWidgetIID, (void**)&w))) {
1725
w->Move(0, menuBarHeight);
1730
NS_SUCCEEDED(mForward->QueryInterface(kIWidgetIID, (void**)&w))) {
1731
w->Move(BUTTON_WIDTH, menuBarHeight);
1740
nsIWidget* statusWidget = nsnull;
1742
if (mStatus && NS_OK == mStatus->QueryInterface(kIWidgetIID,(void**)&statusWidget)) {
1743
if (mChromeMask & nsIWebBrowserChrome::CHROME_STATUSBAR) {
1744
statusWidget->Resize(0, aHeight - txtHeight,
1748
//Since allowing a negative height is a bad idea, let's condition this...
1749
rr.height = PR_MAX(0,rr.height-txtHeight);
1750
statusWidget->Show(PR_TRUE);
1753
statusWidget->Show(PR_FALSE);
1755
NS_RELEASE(statusWidget);
1758
// inset the web widget
1760
if (nsIWebBrowserChrome::CHROME_TOOLBAR & mChromeMask) {
1761
rr.height -= BUTTON_HEIGHT;
1762
rr.y += BUTTON_HEIGHT;
1765
rr.x += WEBSHELL_LEFT_INSET;
1766
rr.y += WEBSHELL_TOP_INSET + menuBarHeight;
1767
rr.width -= WEBSHELL_LEFT_INSET + WEBSHELL_RIGHT_INSET;
1768
rr.height -= WEBSHELL_TOP_INSET + WEBSHELL_BOTTOM_INSET + menuBarHeight;
1770
//Since allowing a negative height is a bad idea, let's condition this...
1774
nsCOMPtr<nsIBaseWindow> webBrowserWin(do_QueryInterface(mWebBrowser));
1775
if (webBrowserWin) {
1776
webBrowserWin->SetPositionAndSize(rr.x, rr.y, rr.width, rr.height, PR_FALSE);
1781
nsBrowserWindow::MoveTo(PRInt32 aX, PRInt32 aY)
1783
NS_PRECONDITION(nsnull != mWindow, "null window");
1784
mWindow->Move(aX, aY);
1789
nsBrowserWindow::SizeContentTo(PRInt32 aWidth, PRInt32 aHeight)
1791
NS_PRECONDITION(nsnull != mWindow, "null window");
1793
// XXX We want to do this in one shot
1794
mWindow->Resize(aWidth, aHeight, PR_FALSE);
1795
Layout(aWidth, aHeight);
1801
nsBrowserWindow::SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight,
1802
PRBool /*aWidthTransient*/,
1803
PRBool /*aHeightTransient*/)
1805
return SizeContentTo(aWidth, aHeight);
1809
nsBrowserWindow::GetContentBounds(nsRect& aBounds)
1811
mWindow->GetClientBounds(aBounds);
1816
nsBrowserWindow::GetWindowBounds(nsRect& aBounds)
1818
mWindow->GetBounds(aBounds);
1823
nsBrowserWindow::SetChrome(PRUint32 aChromeMask)
1825
mChromeMask = aChromeMask;
1827
mWindow->GetClientBounds(r);
1828
Layout(r.width, r.height);
1834
nsBrowserWindow::GetChrome(PRUint32& aChromeMaskResult)
1836
aChromeMaskResult = mChromeMask;
1841
nsBrowserWindow::GetWebShell(nsIWebShell*& aResult)
1843
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
1845
NS_IF_ADDREF(aResult);
1850
nsBrowserWindow::GetContentWebShell(nsIWebShell **aResult)
1852
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
1853
*aResult = webShell;
1854
NS_IF_ADDREF(*aResult);
1858
//----------------------------------------
1860
nsBrowserWindow::SetProgress(PRInt32 aProgress, PRInt32 aProgressMax)
1866
nsBrowserWindow::ShowMenuBar(PRBool aShow)
1872
nsBrowserWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL,
1879
nsBrowserWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
1885
nsBrowserWindow::ProgressLoadURL(nsIWebShell* aShell,
1886
const PRUnichar* aURL,
1888
PRInt32 aProgressMax)
1894
nsBrowserWindow::EndLoadURL(nsIWebShell* aShell,
1895
const PRUnichar* aURL,
1903
nsBrowserWindow::NewWebShell(PRUint32 aChromeMask,
1905
nsIWebShell*& aNewWebShell)
1907
nsresult rv = NS_OK;
1910
if (mWebCrawler->Crawling() || mWebCrawler->LoadingURLList()) {
1911
// Do not fly javascript popups when we are crawling
1912
aNewWebShell = nsnull;
1913
return NS_ERROR_NOT_IMPLEMENTED;
1917
// Create new window. By default, the refcnt will be 1 because of
1918
// the registration of the browser window in gBrowsers.
1919
nsNativeBrowserWindow* browser;
1920
NS_NEWXPCOM(browser, nsNativeBrowserWindow);
1922
if (nsnull != browser)
1925
GetContentBounds(bounds);
1927
browser->SetApp(mApp);
1929
// Assume no controls for now
1930
rv = browser->Init(mAppShell, bounds, aChromeMask, mAllowPlugins);
1933
// Default is to startup hidden
1935
browser->SetVisibility(PR_TRUE);
1938
rv = browser->GetWebShell(shell);
1939
aNewWebShell = shell;
1947
rv = NS_ERROR_OUT_OF_MEMORY;
1954
nsBrowserWindow::ContentShellAdded(nsIWebShell* aChildShell, nsIContent* frameNode)
1960
nsBrowserWindow::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult)
1962
PRInt32 i, n = gBrowsers ? gBrowsers->Count() : 0;
1965
nsString aNameStr(aName);
1967
for (i = 0; i < n; i++) {
1968
nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers->ElementAt(i);
1969
nsCOMPtr<nsIWebShell> webShell;
1971
if (NS_OK == bw->GetWebShell(*getter_AddRefs(webShell))) {
1973
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
1974
if (NS_OK == docShellAsItem->GetName(getter_Copies(name))) {
1975
if (aNameStr.Equals(name)) {
1982
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(mDocShell));
1984
nsCOMPtr<nsIDocShellTreeItem> result;
1985
if (NS_OK == docShellAsNode->FindChildWithName(aName, PR_TRUE, PR_FALSE, nsnull,
1986
getter_AddRefs(result))) {
1988
CallQueryInterface(result, &aResult);
1998
//----------------------------------------
2001
nsBrowserWindow::OnProgress(nsIRequest* request, nsISupports *ctxt,
2002
PRUint32 aProgress, PRUint32 aProgressMax)
2006
nsCOMPtr<nsIURI> aURL;
2007
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
2008
rv = channel->GetURI(getter_AddRefs(aURL));
2009
if (NS_FAILED(rv)) return rv;
2013
if (nsnull != aURL) {
2016
AppendUTF8toUTF16(str, url);
2018
url.Append(NS_LITERAL_STRING(": progress "));
2019
url.AppendInt(aProgress, 10);
2020
if (0 != aProgressMax) {
2021
url.Append(NS_LITERAL_STRING(" (out of "));
2022
url.AppendInt(aProgressMax, 10);
2023
url.Append(NS_LITERAL_STRING(")"));
2026
mStatus->SetText(url,size);
2032
nsBrowserWindow::OnStatus(nsIRequest* request, nsISupports *ctxt,
2033
nsresult aStatus, const PRUnichar *aStatusArg)
2037
nsCOMPtr<nsIStringBundleService> sbs = do_GetService(kStringBundleServiceCID, &rv);
2038
if (NS_FAILED(rv)) return rv;
2040
rv = sbs->FormatStatusMessage(aStatus, aStatusArg, getter_Copies(msg));
2041
if (NS_FAILED(rv)) return rv;
2043
nsAutoString msg2( NS_STATIC_CAST(const PRUnichar*, msg));
2044
mStatus->SetText(msg2, size);
2049
//----------------------------------------
2054
nsBrowserWindow::StartThrobber()
2059
nsBrowserWindow::StopThrobber()
2064
nsBrowserWindow::LoadThrobberImages()
2069
nsBrowserWindow::DestroyThrobberImages()
2074
nsBrowserWindow::GetPresShell()
2076
return GetPresShellFor(mDocShell);
2081
nsBrowserWindow::DoCopy()
2083
nsIPresShell* shell = GetPresShell();
2084
if (nsnull != shell) {
2091
nsBrowserWindow::DoPaste()
2093
nsIPresShell* shell = GetPresShell();
2094
if (nsnull != shell) {
2096
printf("nsBrowserWindow::DoPaste()\n");
2102
//----------------------------------------------------------------------
2105
nsBrowserWindow::ShowPrintPreview(PRInt32 aID)
2107
nsCOMPtr <nsIContentViewer> viewer;
2109
mDocShell->GetContentViewer(getter_AddRefs(viewer));
2113
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
2115
//viewerFile->PrintPreview(nsnull);
2120
void nsBrowserWindow::DoPrint(void)
2122
nsCOMPtr <nsIContentViewer> viewer;
2124
mDocShell->GetContentViewer(getter_AddRefs(viewer));
2127
nsCOMPtr<nsIWebBrowserPrint> webBrowserPrint = do_QueryInterface(viewer);
2128
if (webBrowserPrint) {
2129
if (!mPrintSettings) {
2130
webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(mPrintSettings));
2132
webBrowserPrint->Print(mPrintSettings, (nsIWebProgressListener*)nsnull);
2137
//---------------------------------------------------------------
2138
nsIDOMDocument* nsBrowserWindow::GetDOMDocument(nsIDocShell *aDocShell)
2140
nsIDOMDocument* domDoc = nsnull;
2141
if (nsnull != aDocShell) {
2142
nsIContentViewer* mCViewer;
2143
aDocShell->GetContentViewer(&mCViewer);
2144
if (nsnull != mCViewer) {
2145
nsIDocumentViewer* mDViewer;
2146
if (NS_OK == mCViewer->QueryInterface(kIDocumentViewerIID, (void**) &mDViewer)) {
2147
nsCOMPtr<nsIDocument> mDoc;
2148
mDViewer->GetDocument(getter_AddRefs(mDoc));
2149
if (nsnull != mDoc) {
2150
mDoc->QueryInterface(kIDOMDocumentIID, (void**) &domDoc);
2152
NS_RELEASE(mDViewer);
2154
NS_RELEASE(mCViewer);
2160
//---------------------------------------------------------------
2162
void nsBrowserWindow::DoTableInspector()
2164
if (mTableInspectorDialog) {
2165
mTableInspectorDialog->SetVisible(PR_TRUE);
2168
nsIDOMDocument* domDoc = GetDOMDocument(mDocShell);
2170
if (nsnull != domDoc) {
2171
nsString printHTML(NS_LITERAL_STRING("resource:/res/samples/printsetup.html"));
2172
nsRect rect(0, 0, 375, 510);
2173
nsString title(NS_LITERAL_STRING("Table Inspector"));
2175
nsXPBaseWindow * xpWin = nsnull;
2176
nsresult rv = nsComponentManager::CreateInstance(kXPBaseWindowCID, nsnull,
2180
xpWin->Init(eXPBaseWindowType_dialog, mAppShell, printHTML, title, rect, PRUint32(~0), PR_FALSE);
2181
xpWin->SetVisible(PR_TRUE);
2182
if (NS_OK == xpWin->QueryInterface(kIXPBaseWindowIID, (void**) &mTableInspectorDialog)) {
2183
mTableInspector = new nsTableInspectorDialog(this, domDoc); // ref counts domDoc
2184
if (nsnull != mTableInspector) {
2185
xpWin->AddWindowListener(mTableInspector);
2194
void nsBrowserWindow::DoImageInspector()
2196
if (mImageInspectorDialog) {
2197
mImageInspectorDialog->SetVisible(PR_TRUE);
2201
nsIDOMDocument* domDoc = GetDOMDocument(mDocShell);
2203
if (nsnull != domDoc) {
2204
nsString printHTML(NS_LITERAL_STRING("resource:/res/samples/image_props.html"));
2205
nsRect rect(0, 0, 485, 124);
2206
nsString title(NS_LITERAL_STRING("Image Inspector"));
2208
nsXPBaseWindow * xpWin = nsnull;
2209
nsresult rv = nsComponentManager::CreateInstance(kXPBaseWindowCID, nsnull, kIXPBaseWindowIID, (void**) &xpWin);
2211
xpWin->Init(eXPBaseWindowType_dialog, mAppShell, printHTML, title, rect, PRUint32(~0), PR_FALSE);
2212
xpWin->SetVisible(PR_TRUE);
2213
if (NS_OK == xpWin->QueryInterface(kIXPBaseWindowIID, (void**) &mImageInspectorDialog)) {
2214
mImageInspector = new nsImageInspectorDialog(this, domDoc); // ref counts domDoc
2215
if (nsnull != mImageInspector) {
2216
xpWin->AddWindowListener(mImageInspector);
2226
//----------------------------------------------------------------------
2229
nsBrowserWindow::DoJSConsole()
2231
mApp->CreateJSConsole(this);
2235
nsBrowserWindow::DoPrefs()
2237
mApp->DoPrefs(this);
2241
nsBrowserWindow::DoEditorMode(nsIDocShell *aDocShell)
2244
if (nsnull != aDocShell) {
2245
nsIContentViewer* mCViewer;
2246
aDocShell->GetContentViewer(&mCViewer);
2247
if (nsnull != mCViewer) {
2248
nsIDocumentViewer* mDViewer;
2249
if (NS_OK == mCViewer->QueryInterface(kIDocumentViewerIID, (void**) &mDViewer))
2251
nsCOMPtr<nsIDocument> mDoc;
2252
mDViewer->GetDocument(getter_AddRefs(mDoc));
2253
if (nsnull != mDoc) {
2254
nsIDOMDocument* mDOMDoc;
2255
if (NS_OK == mDoc->QueryInterface(kIDOMDocumentIID, (void**) &mDOMDoc))
2257
nsIPresShell* shell = GetPresShellFor(aDocShell);
2258
NS_InitEditorMode(mDOMDoc, shell);
2259
NS_RELEASE(mDOMDoc);
2260
NS_IF_RELEASE(shell);
2263
NS_RELEASE(mDViewer);
2265
NS_RELEASE(mCViewer);
2268
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(aDocShell));
2269
docShellAsNode->GetChildCount(&n);
2270
for (i = 0; i < n; i++) {
2271
nsCOMPtr<nsIDocShellTreeItem> child;
2272
docShellAsNode->GetChildAt(i, getter_AddRefs(child));
2273
nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child));
2274
DoEditorMode(childAsShell);
2279
// Same as above, but calls NS_DoEditorTest instead of starting an editor
2281
nsBrowserWindow::DoEditorTest(nsIDocShell *aDocShell, PRInt32 aCommandID)
2283
if (nsnull != aDocShell) {
2284
nsIContentViewer* mCViewer;
2285
aDocShell->GetContentViewer(&mCViewer);
2286
if (nsnull != mCViewer) {
2287
nsIDocumentViewer* mDViewer;
2288
if (NS_OK == mCViewer->QueryInterface(kIDocumentViewerIID, (void**) &mDViewer))
2290
nsCOMPtr<nsIDocument> mDoc;
2291
mDViewer->GetDocument(getter_AddRefs(mDoc));
2292
if (nsnull != mDoc) {
2293
nsIDOMDocument* mDOMDoc;
2294
if (NS_OK == mDoc->QueryInterface(kIDOMDocumentIID, (void**) &mDOMDoc))
2296
NS_DoEditorTest(aCommandID);
2297
NS_RELEASE(mDOMDoc);
2300
NS_RELEASE(mDViewer);
2302
NS_RELEASE(mCViewer);
2304
// Do we need to do all the children as in DoEditorMode?
2305
// Its seems to work if we don't do that
2313
#include "nsIContent.h"
2314
#include "nsIFrame.h"
2315
#include "nsIFrameDebug.h"
2318
static void DumpAWebShell(nsIDocShellTreeItem* aShellItem, FILE* out, PRInt32 aIndent)
2322
nsCOMPtr<nsIDocShellTreeItem> parent;
2325
for (i = aIndent; --i >= 0; ) fprintf(out, " ");
2327
fprintf(out, "%p '", aShellItem);
2328
aShellItem->GetName(getter_Copies(name));
2329
aShellItem->GetSameTypeParent(getter_AddRefs(parent));
2331
fputs(NS_LossyConvertUCS2toASCII(str).get(), out);
2332
fprintf(out, "' parent=%p <\n", parent.get());
2335
nsCOMPtr<nsIDocShellTreeNode> shellAsNode(do_QueryInterface(aShellItem));
2336
shellAsNode->GetChildCount(&n);
2337
for (i = 0; i < n; i++) {
2338
nsCOMPtr<nsIDocShellTreeItem> child;
2339
shellAsNode->GetChildAt(i, getter_AddRefs(child));
2341
DumpAWebShell(child, out, aIndent);
2345
for (i = aIndent; --i >= 0; ) fprintf(out, " ");
2350
nsBrowserWindow::DumpWebShells(FILE* out)
2352
nsCOMPtr<nsIDocShellTreeItem> shellAsItem(do_QueryInterface(mDocShell));
2353
DumpAWebShell(shellAsItem, out, 0);
2358
DumpMultipleWebShells(nsBrowserWindow& aBrowserWindow, nsIDocShell* aDocShell, FILE* aOut)
2361
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(aDocShell));
2362
if (docShellAsNode) {
2363
docShellAsNode->GetChildCount(&count);
2365
fprintf(aOut, "webshells= \n");
2366
aBrowserWindow.DumpWebShells(aOut);
2373
DumpContentRecurse(nsIDocShell* aDocShell, FILE* out)
2375
if (nsnull != aDocShell) {
2376
fprintf(out, "docshell=%p \n", aDocShell);
2377
nsIPresShell* shell = GetPresShellFor(aDocShell);
2378
if (nsnull != shell) {
2379
nsCOMPtr<nsIDocument> doc;
2380
shell->GetDocument(getter_AddRefs(doc));
2382
nsIContent *root = doc->GetRootContent();
2383
if (nsnull != root) {
2390
fputs("null pres shell\n", out);
2392
// dump the frames of the sub documents
2394
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(aDocShell));
2395
docShellAsNode->GetChildCount(&n);
2396
for (i = 0; i < n; i++) {
2397
nsCOMPtr<nsIDocShellTreeItem> child;
2398
docShellAsNode->GetChildAt(i, getter_AddRefs(child));
2399
nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child));
2400
if (nsnull != child) {
2401
DumpContentRecurse(childAsShell, out);
2408
nsBrowserWindow::DumpContent(FILE* out)
2410
DumpContentRecurse(mDocShell, out);
2411
DumpMultipleWebShells(*this, mDocShell, out);
2415
DumpFramesRecurse(nsIDocShell* aDocShell, FILE* out, nsString *aFilterName)
2417
if (nsnull != aDocShell) {
2418
fprintf(out, "webshell=%p \n", aDocShell);
2419
nsIPresShell* shell = GetPresShellFor(aDocShell);
2420
if (nsnull != shell) {
2422
shell->GetRootFrame(&root);
2423
if (nsnull != root) {
2424
nsIPresContext* presContext;
2425
shell->GetPresContext(&presContext);
2427
nsIFrameDebug* fdbg;
2428
if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) {
2429
fdbg->List(presContext, out, 0);
2431
NS_IF_RELEASE(presContext);
2436
fputs("null pres shell\n", out);
2439
// dump the frames of the sub documents
2441
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(aDocShell));
2442
docShellAsNode->GetChildCount(&n);
2443
for (i = 0; i < n; i++) {
2444
nsCOMPtr<nsIDocShellTreeItem> child;
2445
docShellAsNode->GetChildAt(i, getter_AddRefs(child));
2446
nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child));
2448
DumpFramesRecurse(childAsShell, out, aFilterName);
2455
nsBrowserWindow::DumpFrames(FILE* out, nsString *aFilterName)
2457
DumpFramesRecurse(mDocShell, out, aFilterName);
2458
DumpMultipleWebShells(*this, mDocShell, out);
2461
//----------------------------------------------------------------------
2465
DumpViewsRecurse(nsIDocShell* aDocShell, FILE* out)
2467
if (nsnull != aDocShell) {
2468
fprintf(out, "docshell=%p \n", aDocShell);
2469
nsIPresShell* shell = GetPresShellFor(aDocShell);
2470
if (nsnull != shell) {
2471
nsCOMPtr<nsIViewManager> vm;
2472
shell->GetViewManager(getter_AddRefs(vm));
2475
vm->GetRootView(root);
2476
if (nsnull != root) {
2483
fputs("null pres shell\n", out);
2486
// dump the views of the sub documents
2488
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(aDocShell));
2489
docShellAsNode->GetChildCount(&n);
2490
for (i = 0; i < n; i++) {
2491
nsCOMPtr<nsIDocShellTreeItem> child;
2492
docShellAsNode->GetChildAt(i, getter_AddRefs(child));
2493
nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child));
2495
DumpViewsRecurse(childAsShell, out);
2502
nsBrowserWindow::DumpViews(FILE* out)
2504
DumpViewsRecurse(mDocShell, out);
2505
DumpMultipleWebShells(*this, mDocShell, out);
2509
nsBrowserWindow::DumpStyleSheets(FILE* out)
2511
nsCOMPtr<nsIPresShell> shell = dont_AddRef(GetPresShell());
2513
shell->ListStyleSheets(out);
2515
fputs("null pres shell\n", out);
2520
nsBrowserWindow::DumpStyleContexts(FILE* out)
2522
nsCOMPtr<nsIPresShell> shell = dont_AddRef(GetPresShell());
2525
shell->GetRootFrame(&root);
2526
shell->ListStyleContexts(root, out);
2528
fputs("null pres shell\n", out);
2533
nsBrowserWindow::DumpReflowStats(FILE* out)
2535
nsIPresShell* shell = GetPresShell();
2536
if (nsnull != shell) {
2537
#ifdef MOZ_REFLOW_PERF
2538
shell->DumpReflows();
2540
fprintf(out,"***********************************\n");
2541
fprintf(out, "Sorry, you have built with MOZ_REFLOW_PERF=1\n");
2542
fprintf(out,"***********************************\n");
2546
fputs("null pres shell\n", out);
2551
nsBrowserWindow::DisplayReflowStats(PRBool aIsOn)
2553
nsIPresShell* shell = GetPresShell();
2554
if (nsnull != shell) {
2555
#ifdef MOZ_REFLOW_PERF
2556
shell->SetPaintFrameCount(aIsOn);
2557
SetBoolPref("layout.reflow.showframecounts",aIsOn);
2560
printf("***********************************\n");
2561
printf("Sorry, you have built with MOZ_REFLOW_PERF=1\n");
2562
printf("***********************************\n");
2569
nsBrowserWindow::ToggleFrameBorders()
2571
nsILayoutDebugger* ld;
2572
nsresult rv = nsComponentManager::CreateInstance(kLayoutDebuggerCID,
2574
kILayoutDebuggerIID,
2576
if (NS_SUCCEEDED(rv)) {
2578
ld->GetShowFrameBorders(&showing);
2579
ld->SetShowFrameBorders(!showing);
2586
nsBrowserWindow::ToggleVisualEventDebugging()
2588
nsILayoutDebugger* ld;
2589
nsresult rv = nsComponentManager::CreateInstance(kLayoutDebuggerCID,
2591
kILayoutDebuggerIID,
2593
if (NS_SUCCEEDED(rv)) {
2595
ld->GetShowEventTargetFrameBorder(&showing);
2596
ld->SetShowEventTargetFrameBorder(!showing);
2603
nsBrowserWindow::ToggleBoolPrefAndRefresh(const char * aPrefName)
2605
NS_ASSERTION(nsnull != aPrefName,"null pref name");
2607
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
2608
if (prefs && nsnull != aPrefName)
2611
prefs->GetBoolPref(aPrefName,&value);
2612
prefs->SetBoolPref(aPrefName,!value);
2613
prefs->SavePrefFile(nsnull);
2622
nsBrowserWindow::SetBoolPref(const char * aPrefName, PRBool aValue)
2624
NS_ASSERTION(nsnull != aPrefName,"null pref name");
2626
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
2627
if (prefs && nsnull != aPrefName)
2629
prefs->SetBoolPref(aPrefName, aValue);
2630
prefs->SavePrefFile(nsnull);
2635
nsBrowserWindow::SetStringPref(const char * aPrefName, const nsString& aValue)
2637
NS_ASSERTION(nsnull != aPrefName, "null pref name");
2639
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
2640
if (nsnull != prefs && nsnull != aPrefName)
2642
char * prefStr = ToNewCString(aValue);
2643
prefs->SetCharPref(aPrefName, prefStr);
2644
prefs->SavePrefFile(nsnull);
2651
nsBrowserWindow::GetStringPref(const char * aPrefName, nsString& aValue)
2653
NS_ASSERTION(nsnull != aPrefName, "null pref name");
2655
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
2656
if (nsnull != prefs && nsnull != aPrefName)
2659
nsresult result = prefs->CopyCharPref(aPrefName, &prefCharVal);
2660
if (NS_SUCCEEDED(result)) {
2661
aValue.AssignWithConversion(prefCharVal);
2662
PL_strfree(prefCharVal);
2669
nsBrowserWindow::DoDebugSave()
2671
/* Removed 04/01/99 -- gpk */
2675
nsBrowserWindow::DoToggleSelection()
2677
nsIPresShell* shell = GetPresShell();
2678
if (nsnull != shell) {
2679
nsCOMPtr<nsISelectionController> selCon;
2680
selCon = do_QueryInterface(shell);
2683
selCon->GetDisplaySelection(¤t);
2684
selCon->SetDisplaySelection(!current);
2692
nsBrowserWindow::DoDebugRobot()
2694
mApp->CreateRobot(this);
2698
nsBrowserWindow::DoSiteWalker()
2700
mApp->CreateSiteWalker(this);
2704
nsBrowserWindow::DispatchDebugMenu(PRInt32 aID)
2706
nsEventStatus result = nsEventStatus_eIgnore;
2709
case VIEWER_VISUAL_DEBUGGING:
2710
ToggleFrameBorders();
2711
result = nsEventStatus_eConsumeNoDefault;
2714
case VIEWER_VISUAL_EVENT_DEBUGGING:
2715
ToggleVisualEventDebugging();
2716
result = nsEventStatus_eConsumeNoDefault;
2719
case VIEWER_TOGGLE_PAINT_FLASHING:
2720
ToggleBoolPrefAndRefresh("nglayout.debug.paint_flashing");
2721
result = nsEventStatus_eConsumeNoDefault;
2724
case VIEWER_TOGGLE_PAINT_DUMPING:
2725
ToggleBoolPrefAndRefresh("nglayout.debug.paint_dumping");
2726
result = nsEventStatus_eConsumeNoDefault;
2729
case VIEWER_TOGGLE_INVALIDATE_DUMPING:
2730
ToggleBoolPrefAndRefresh("nglayout.debug.invalidate_dumping");
2731
result = nsEventStatus_eConsumeNoDefault;
2734
case VIEWER_TOGGLE_EVENT_DUMPING:
2735
ToggleBoolPrefAndRefresh("nglayout.debug.event_dumping");
2736
result = nsEventStatus_eConsumeNoDefault;
2739
case VIEWER_TOGGLE_MOTION_EVENT_DUMPING:
2740
ToggleBoolPrefAndRefresh("nglayout.debug.motion_event_dumping");
2741
result = nsEventStatus_eConsumeNoDefault;
2744
case VIEWER_TOGGLE_CROSSING_EVENT_DUMPING:
2745
ToggleBoolPrefAndRefresh("nglayout.debug.crossing_event_dumping");
2746
result = nsEventStatus_eConsumeNoDefault;
2749
case VIEWER_DUMP_CONTENT:
2751
result = nsEventStatus_eConsumeNoDefault;
2754
case VIEWER_DUMP_FRAMES:
2756
result = nsEventStatus_eConsumeNoDefault;
2759
case VIEWER_DUMP_VIEWS:
2761
result = nsEventStatus_eConsumeNoDefault;
2764
case VIEWER_DUMP_STYLE_SHEETS:
2766
result = nsEventStatus_eConsumeNoDefault;
2769
case VIEWER_DUMP_STYLE_CONTEXTS:
2770
DumpStyleContexts();
2771
result = nsEventStatus_eConsumeNoDefault;
2774
case VIEWER_DEBUG_DUMP_REFLOW_TOTS:
2776
result = nsEventStatus_eConsumeNoDefault;
2779
case VIEWER_DSP_REFLOW_CNTS_ON:
2780
DisplayReflowStats(PR_TRUE);
2781
result = nsEventStatus_eConsumeNoDefault;
2784
case VIEWER_DSP_REFLOW_CNTS_OFF:
2785
DisplayReflowStats(PR_FALSE);
2786
result = nsEventStatus_eConsumeNoDefault;
2789
case VIEWER_DEBUGSAVE:
2793
case VIEWER_TOGGLE_SELECTION:
2794
DoToggleSelection();
2798
case VIEWER_DEBUGROBOT:
2815
nsBrowserWindow::SetCompatibilityMode(PRUint32 aMode)
2817
nsCOMPtr<nsIPref> pref(do_GetService(NS_PREF_CONTRACTID));
2819
int32 prefInt = USE_DTD;
2820
if (STANDARD == aMode) {
2821
prefInt = eCompatibility_FullStandards;
2823
else if (QUIRKS == aMode) {
2824
prefInt = eCompatibility_NavQuirks;
2826
pref->SetIntPref("nglayout.compatibility.mode", prefInt);
2827
pref->SavePrefFile(nsnull);
2832
nsBrowserWindow::DispatchStyleMenu(PRInt32 aID)
2834
nsEventStatus result = nsEventStatus_eIgnore;
2837
case VIEWER_SELECT_STYLE_LIST:
2839
nsIPresShell* shell = GetPresShell();
2840
if (nsnull != shell) {
2841
nsAutoString defaultStyle;
2842
nsCOMPtr<nsIDocument> doc;
2843
shell->GetDocument(getter_AddRefs(doc));
2845
nsIAtom* defStyleAtom = NS_NewAtom("default-style");
2846
doc->GetHeaderData(defStyleAtom, defaultStyle);
2847
NS_RELEASE(defStyleAtom);
2850
nsStringArray titles;
2851
shell->ListAlternateStyleSheets(titles);
2852
nsAutoString current;
2853
shell->GetActiveAlternateStyleSheet(current);
2855
PRInt32 count = titles.Count();
2856
fprintf(stdout, "There %s %d alternate style sheet%s\n",
2857
((1 == count) ? "is" : "are"),
2859
((1 == count) ? "" : "s"));
2861
for (index = 0; index < count; index++) {
2862
fprintf(stdout, "%d: \"", index + 1);
2864
titles.StringAt(index, title);
2865
fputs(NS_LossyConvertUCS2toASCII(title).get(), stdout);
2866
fprintf(stdout, "\" %s%s\n",
2867
((title.Equals(current, nsCaseInsensitiveStringComparator())) ? "<< current " : ""),
2868
((title.Equals(defaultStyle, nsCaseInsensitiveStringComparator())) ? "** default" : ""));
2873
result = nsEventStatus_eConsumeNoDefault;
2876
case VIEWER_SELECT_STYLE_DEFAULT:
2878
nsIPresShell* shell = GetPresShell();
2879
if (nsnull != shell) {
2880
nsCOMPtr<nsIDocument> doc;
2881
shell->GetDocument(getter_AddRefs(doc));
2883
nsAutoString defaultStyle;
2884
nsIAtom* defStyleAtom = NS_NewAtom("default-style");
2885
doc->GetHeaderData(defStyleAtom, defaultStyle);
2886
NS_RELEASE(defStyleAtom);
2887
fputs("Selecting default style sheet \"", stdout);
2888
fputs(NS_LossyConvertUCS2toASCII(defaultStyle).get(), stdout);
2889
fputs("\"\n", stdout);
2890
shell->SelectAlternateStyleSheet(defaultStyle);
2895
result = nsEventStatus_eConsumeNoDefault;
2898
case VIEWER_SELECT_STYLE_ONE:
2899
case VIEWER_SELECT_STYLE_TWO:
2900
case VIEWER_SELECT_STYLE_THREE:
2901
case VIEWER_SELECT_STYLE_FOUR:
2903
nsIPresShell* shell = GetPresShell();
2904
if (nsnull != shell) {
2905
nsStringArray titles;
2906
shell->ListAlternateStyleSheets(titles);
2908
titles.StringAt(aID - VIEWER_SELECT_STYLE_ONE, title);
2909
fputs("Selecting alternate style sheet \"", stdout);
2910
fputs(NS_LossyConvertUCS2toASCII(title).get(), stdout);
2911
fputs("\"\n", stdout);
2912
shell->SelectAlternateStyleSheet(title);
2916
result = nsEventStatus_eConsumeNoDefault;
2919
case VIEWER_USE_DTD_MODE:
2920
case VIEWER_NAV_QUIRKS_MODE:
2921
case VIEWER_STANDARD_MODE:
2922
SetCompatibilityMode(aID - VIEWER_USE_DTD_MODE);
2923
result = nsEventStatus_eConsumeNoDefault;
2929
NS_IMETHODIMP nsBrowserWindow::EnsureWebBrowserChrome()
2931
if(mWebBrowserChrome)
2934
mWebBrowserChrome = new nsWebBrowserChrome();
2935
NS_ENSURE_TRUE(mWebBrowserChrome, NS_ERROR_OUT_OF_MEMORY);
2937
NS_ADDREF(mWebBrowserChrome);
2938
mWebBrowserChrome->BrowserWindow(this);
2943
nsresult nsBrowserWindow::GetWindow(nsIWidget** aWindow)
2945
if (aWindow && mWindow) {
2946
*aWindow = mWindow.get();
2947
NS_IF_ADDREF(*aWindow);
2950
return NS_ERROR_FAILURE;