~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/webshell/tests/viewer/nsBrowserWindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
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/
 
7
 *
 
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.
 
12
 *
 
13
 * The Original Code is Mozilla Communicator client code.
 
14
 *
 
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
 
18
 * Rights Reserved.
 
19
 *
 
20
 * Contributor(s): 
 
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
 
26
 *
 
27
 * Date             Modified by     Description of modification
 
28
 * 04/20/2000       IBM Corp.      OS/2 VisualAge build.
 
29
 */
 
30
 
 
31
#include "nsIPref.h" 
 
32
#include "prmem.h"
 
33
 
 
34
#include "nsBrowserWindow.h"
 
35
#include "nsIAppShell.h"
 
36
#include "nsIWidget.h"
 
37
#include "nsITextWidget.h"
 
38
#include "nsIButton.h"
 
39
#include "nsITimer.h"
 
40
#include "nsIDOMDocument.h"
 
41
#include "nsIURL.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"
 
49
#include "nsCRT.h"
 
50
#include "nsWidgetsCID.h"
 
51
#include "nsViewerApp.h"
 
52
#include "prprf.h"
 
53
#include "nsIComponentManager.h"
 
54
#include "nsParserCIID.h"
 
55
#include "nsCOMPtr.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"
 
79
 
 
80
#include "nsCWebBrowser.h"
 
81
#include "nsUnicharUtils.h"
 
82
 
 
83
#include "nsIParser.h"
 
84
#include "nsEditorMode.h"
 
85
 
 
86
// Needed for "Find" GUI
 
87
#include "nsICheckButton.h"
 
88
#include "nsILabel.h"
 
89
#include "nsWidgetSupport.h"
 
90
 
 
91
#include "nsXPBaseWindow.h"
 
92
 
 
93
#include "resources.h"
 
94
 
 
95
#if defined(WIN32)
 
96
#include <windows.h>
 
97
#endif
 
98
 
 
99
#include <ctype.h> // tolower
 
100
 
 
101
// For Copy
 
102
#include "nsISelection.h"
 
103
#include "nsISelectionController.h"
 
104
 
 
105
// XXX For font setting below
 
106
#include "nsFont.h"
 
107
#include "nsUnitConversion.h"
 
108
#include "nsIDeviceContext.h"
 
109
 
 
110
#if defined(CookieManagement) || defined(SingleSignon) || defined(ClientWallet)
 
111
#include "nsIServiceManager.h"
 
112
#endif
 
113
 
 
114
#ifdef CookieManagement
 
115
 
 
116
#include "nsIURL.h"
 
117
 
 
118
#endif
 
119
#include "nsIIOService.h"
 
120
#include "nsNetCID.h"
 
121
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
 
122
 
 
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);
 
127
#endif
 
128
 
 
129
#ifdef PURIFY
 
130
#include "pure.h"
 
131
#endif
 
132
 
 
133
#define THROBBING_N
 
134
 
 
135
#define CLEANUP_WIDGET(_widget, _txt) \
 
136
  if(_widget) {            \
 
137
  DestroyWidget((_widget)); \
 
138
  refCnt = (_widget)->Release(); \
 
139
  (_widget) = nsnull; \
 
140
  NS_ASSERTION(refCnt == 0, (_txt)); \
 
141
  }
 
142
 
 
143
 
 
144
// XXX greasy constants
 
145
#ifdef THROBBING_N
 
146
#define THROBBER_WIDTH 32
 
147
#define THROBBER_HEIGHT 32
 
148
#define THROBBER_AT "resource:/res/throbber/anims%02d.gif"
 
149
#define THROB_NUM 29
 
150
#else
 
151
#define THROBBER_WIDTH 42
 
152
#define THROBBER_HEIGHT 42
 
153
#define THROBBER_AT "resource:/res/throbber/LargeAnimation%02d.gif"
 
154
#define THROB_NUM 38
 
155
#endif
 
156
#define BUTTON_WIDTH 90
 
157
#define BUTTON_HEIGHT THROBBER_HEIGHT
 
158
#define MAX_TEXT_LENGTH 30000
 
159
 
 
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
 
165
#else
 
166
#define WEBSHELL_LEFT_INSET 0
 
167
#define WEBSHELL_RIGHT_INSET 0
 
168
#define WEBSHELL_TOP_INSET 0
 
169
#define WEBSHELL_BOTTOM_INSET 0
 
170
#endif
 
171
 
 
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);
 
176
 
 
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);
 
186
 
 
187
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
 
188
 
 
189
static NS_DEFINE_IID(kILayoutDebuggerIID, NS_ILAYOUT_DEBUGGER_IID);
 
190
static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID);
 
191
 
 
192
#define FILE_PROTOCOL "file://"
 
193
 
 
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);
 
199
#endif
 
200
 
 
201
//******* Cleanup Above here***********/
 
202
 
 
203
//*****************************************************************************
 
204
// nsBrowserWindow::nsIBaseWindow
 
205
//*****************************************************************************   
 
206
 
 
207
NS_IMETHODIMP nsBrowserWindow::InitWindow(nativeWindow aParentNativeWindow,
 
208
   nsIWidget* parentWidget, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)   
 
209
{
 
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);
 
212
 
 
213
   return NS_OK;
 
214
}
 
215
 
 
216
NS_IMETHODIMP nsBrowserWindow::Create()
 
217
{
 
218
   NS_ASSERTION(PR_FALSE, "You can't call this");
 
219
   return NS_ERROR_UNEXPECTED;
 
220
}
 
221
 
 
222
NS_IMETHODIMP nsBrowserWindow::Destroy()
 
223
{
 
224
  RemoveBrowser(this);
 
225
 
 
226
  nsCOMPtr<nsIBaseWindow> docShellWin(do_QueryInterface(mDocShell));
 
227
  docShellWin->Destroy();
 
228
  mDocShell = nsnull;
 
229
 
 
230
  nsrefcnt refCnt;
 
231
 
 
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.");
 
236
 
 
237
  if (mThrobber) {
 
238
    mThrobber->Destroy();
 
239
    refCnt = mThrobber->Release();
 
240
    mThrobber = nsnull;
 
241
    NS_ASSERTION(refCnt == 0, "nsBrowserWindow::Destroy - mThrobber is being leaked.");
 
242
    mThrobber = nsnull;
 
243
  }
 
244
 
 
245
  // Others are holding refs to this, 
 
246
  // but it gets released OK.
 
247
  DestroyWidget(mWindow);
 
248
  mWindow = nsnull;
 
249
  // NS_RELEASE(mWindow);
 
250
 
 
251
  return NS_OK;
 
252
}
 
253
 
 
254
NS_IMETHODIMP nsBrowserWindow::SetPosition(PRInt32 aX, PRInt32 aY)
 
255
{
 
256
   PRInt32 cx=0;
 
257
   PRInt32 cy=0;
 
258
 
 
259
   NS_ENSURE_SUCCESS(GetSize(&cx, &cy), NS_ERROR_FAILURE);
 
260
   NS_ENSURE_SUCCESS(SetPositionAndSize(aX, aY, cx, cy, PR_FALSE), 
 
261
      NS_ERROR_FAILURE);
 
262
   return NS_OK;
 
263
}
 
264
 
 
265
NS_IMETHODIMP nsBrowserWindow::GetPosition(PRInt32* aX, PRInt32* aY)
 
266
{
 
267
   return GetPositionAndSize(aX, aY, nsnull, nsnull);
 
268
}
 
269
 
 
270
NS_IMETHODIMP nsBrowserWindow::SetSize(PRInt32 aCX, PRInt32 aCY, PRBool aRepaint)
 
271
{
 
272
   PRInt32 x=0;
 
273
   PRInt32 y=0;
 
274
 
 
275
   NS_ENSURE_SUCCESS(GetPosition(&x, &y), NS_ERROR_FAILURE);
 
276
   NS_ENSURE_SUCCESS(SetPositionAndSize(x, y, aCX, aCY, aRepaint), 
 
277
      NS_ERROR_FAILURE);
 
278
 
 
279
   return NS_OK;
 
280
}
 
281
 
 
282
NS_IMETHODIMP nsBrowserWindow::GetSize(PRInt32* aCX, PRInt32* aCY)
 
283
{
 
284
   return GetPositionAndSize(nsnull, nsnull, aCX, aCY);
 
285
}
 
286
 
 
287
NS_IMETHODIMP nsBrowserWindow::SetPositionAndSize(PRInt32 aX, PRInt32 aY, 
 
288
   PRInt32 aCX, PRInt32 aCY, PRBool aRepaint)
 
289
{
 
290
   NS_ENSURE_SUCCESS(mWindow->Resize(aX, aY, aCX, aCY, aRepaint), 
 
291
      NS_ERROR_FAILURE);
 
292
 
 
293
   return NS_OK;
 
294
}
 
295
 
 
296
NS_IMETHODIMP nsBrowserWindow::GetPositionAndSize(PRInt32* aX, PRInt32* aY, 
 
297
   PRInt32* aCX, PRInt32* aCY)
 
298
{
 
299
   nsRect bounds;
 
300
 
 
301
   NS_ENSURE_SUCCESS(mWindow->GetBounds(bounds), NS_ERROR_FAILURE);
 
302
 
 
303
   if(aX)
 
304
      *aX = bounds.x;
 
305
   if(aY)
 
306
      *aY = bounds.y;
 
307
   if(aCX)
 
308
      *aCX = bounds.width;
 
309
   if(aCY)
 
310
      *aCY = bounds.height;
 
311
 
 
312
   return NS_OK;
 
313
}
 
314
 
 
315
NS_IMETHODIMP nsBrowserWindow::Repaint(PRBool aForce)
 
316
{
 
317
   //XXX First Check In
 
318
   NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
 
319
   return NS_OK;
 
320
}
 
321
 
 
322
NS_IMETHODIMP nsBrowserWindow::GetParentWidget(nsIWidget** aParentWidget)
 
323
{
 
324
   NS_ENSURE_ARG_POINTER(aParentWidget);
 
325
   //XXX First Check In
 
326
   NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
 
327
   return NS_OK;
 
328
}
 
329
 
 
330
NS_IMETHODIMP nsBrowserWindow::SetParentWidget(nsIWidget* aParentWidget)
 
331
{
 
332
   NS_ASSERTION(PR_FALSE, "You can't call this");
 
333
   return NS_ERROR_NOT_IMPLEMENTED;
 
334
}
 
335
 
 
336
NS_IMETHODIMP nsBrowserWindow::GetParentNativeWindow(nativeWindow* aParentNativeWindow)
 
337
{
 
338
   NS_ENSURE_ARG_POINTER(aParentNativeWindow);
 
339
 
 
340
   //XXX First Check In
 
341
   NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
 
342
   return NS_OK;
 
343
}
 
344
 
 
345
NS_IMETHODIMP nsBrowserWindow::SetParentNativeWindow(nativeWindow aParentNativeWindow)
 
346
{
 
347
   NS_ASSERTION(PR_FALSE, "You can't call this");
 
348
   return NS_ERROR_NOT_IMPLEMENTED;
 
349
}
 
350
 
 
351
NS_IMETHODIMP nsBrowserWindow::GetVisibility(PRBool* aVisibility)
 
352
{
 
353
   NS_ENSURE_ARG_POINTER(aVisibility);
 
354
 
 
355
   //XXX First Check In
 
356
   NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
 
357
   return NS_OK;
 
358
}
 
359
 
 
360
NS_IMETHODIMP nsBrowserWindow::SetVisibility(PRBool aVisibility)
 
361
{
 
362
   NS_ENSURE_STATE(mWindow);
 
363
 
 
364
   NS_ENSURE_SUCCESS(mWindow->Show(aVisibility), NS_ERROR_FAILURE);
 
365
 
 
366
   return NS_OK;
 
367
}
 
368
 
 
369
NS_IMETHODIMP nsBrowserWindow::GetEnabled(PRBool *aEnabled)
 
370
{
 
371
  NS_ENSURE_ARG_POINTER(aEnabled);
 
372
  *aEnabled = PR_TRUE;
 
373
  if (mWindow)
 
374
    mWindow->IsEnabled(aEnabled);
 
375
  return NS_OK;
 
376
}
 
377
 
 
378
NS_IMETHODIMP nsBrowserWindow::SetEnabled(PRBool aEnabled)
 
379
{
 
380
  if (mWindow)
 
381
    mWindow->Enable(aEnabled);
 
382
  return NS_OK;
 
383
}
 
384
 
 
385
NS_IMETHODIMP nsBrowserWindow::GetBlurSuppression(PRBool *aBlurSuppression)
 
386
{
 
387
  NS_ENSURE_ARG_POINTER(aBlurSuppression);
 
388
  *aBlurSuppression = PR_FALSE;
 
389
  return NS_ERROR_NOT_IMPLEMENTED;
 
390
}
 
391
 
 
392
NS_IMETHODIMP nsBrowserWindow::SetBlurSuppression(PRBool aBlurSuppression)
 
393
{
 
394
  return NS_ERROR_NOT_IMPLEMENTED;
 
395
}
 
396
 
 
397
NS_IMETHODIMP nsBrowserWindow::GetMainWidget(nsIWidget** aMainWidget)
 
398
{
 
399
   NS_ENSURE_ARG_POINTER(aMainWidget);
 
400
 
 
401
   //XXX First Check In
 
402
   NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
 
403
   return NS_OK;
 
404
}
 
405
 
 
406
NS_IMETHODIMP nsBrowserWindow::SetFocus()
 
407
{
 
408
   //XXX First Check In
 
409
   //NS_WARNING("Not Yet Implemented");
 
410
   return NS_OK;
 
411
}
 
412
 
 
413
NS_IMETHODIMP nsBrowserWindow::GetTitle(PRUnichar** aTitle)
 
414
{
 
415
   NS_ENSURE_ARG_POINTER(aTitle);
 
416
 
 
417
   *aTitle = ToNewUnicode(mTitle);
 
418
 
 
419
   return NS_OK;
 
420
}
 
421
 
 
422
NS_IMETHODIMP nsBrowserWindow::SetTitle(const PRUnichar* aTitle)
 
423
{
 
424
   NS_ENSURE_STATE(mWindow);
 
425
 
 
426
   mTitle = aTitle;
 
427
 
 
428
   NS_ENSURE_SUCCESS(mWindow->SetTitle(nsAutoString(aTitle)), NS_ERROR_FAILURE);
 
429
 
 
430
   return NS_OK;
 
431
}
 
432
 
 
433
//*****************************************************************************
 
434
// nsBrowserWindow: Helper Function
 
435
//*****************************************************************************   
 
436
 
 
437
void nsBrowserWindow::DestroyWidget(nsISupports* aWidget)
 
438
{
 
439
  if(aWidget) {
 
440
    nsCOMPtr<nsIWidget> w(do_QueryInterface(aWidget));
 
441
    if (w) {
 
442
      w->Destroy();
 
443
    }
 
444
  }
 
445
}
 
446
 
 
447
//******* Cleanup below here *************/
 
448
 
 
449
 
 
450
 
 
451
 
 
452
//----------------------------------------------------------------------
 
453
 
 
454
static
 
455
nsIPresShell*
 
456
GetPresShellFor(nsIDocShell* aDocShell)
 
457
{
 
458
  nsIPresShell* shell = nsnull;
 
459
  if (nsnull != aDocShell) {
 
460
    nsIContentViewer* cv = nsnull;
 
461
    aDocShell->GetContentViewer(&cv);
 
462
    if (nsnull != 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));
 
468
        if (nsnull != cx) {
 
469
          NS_IF_ADDREF(shell = cx->GetPresShell());
 
470
        }
 
471
        NS_RELEASE(docv);
 
472
      }
 
473
      NS_RELEASE(cv);
 
474
    }
 
475
  }
 
476
  return shell;
 
477
}
 
478
 
 
479
nsVoidArray* nsBrowserWindow::gBrowsers = nsnull;
 
480
 
 
481
nsBrowserWindow*
 
482
nsBrowserWindow::FindBrowserFor(nsIWidget* aWidget, PRIntn aWhich)
 
483
{
 
484
  nsIWidget*        widget;
 
485
  nsBrowserWindow*  result = nsnull;
 
486
 
 
487
  if (!gBrowsers)
 
488
    return nsnull;
 
489
 
 
490
  PRInt32 i, n = gBrowsers->Count();
 
491
  for (i = 0; i < n; i++) {
 
492
    nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers->ElementAt(i);
 
493
    if (nsnull != bw) {
 
494
      switch (aWhich) {
 
495
      case FIND_WINDOW:
 
496
        if (bw->mWindow) {
 
497
          bw->mWindow->QueryInterface(kIWidgetIID, (void**) &widget);
 
498
          if (widget == aWidget) {
 
499
            result = bw;
 
500
          }
 
501
          NS_IF_RELEASE(widget);
 
502
        }
 
503
        break;
 
504
      case FIND_BACK:
 
505
        if (bw->mBack) {
 
506
          bw->mBack->QueryInterface(kIWidgetIID, (void**) &widget);
 
507
          if (widget == aWidget) {
 
508
            result = bw;
 
509
          }
 
510
          NS_IF_RELEASE(widget);
 
511
        }
 
512
        break;
 
513
      case FIND_FORWARD:
 
514
        if (bw->mForward) {
 
515
          bw->mForward->QueryInterface(kIWidgetIID, (void**) &widget);
 
516
          if (widget == aWidget) {
 
517
            result = bw;
 
518
          }
 
519
          NS_IF_RELEASE(widget);
 
520
        }
 
521
        break;
 
522
      case FIND_LOCATION:
 
523
        if (bw->mLocation) {
 
524
          bw->mLocation->QueryInterface(kIWidgetIID, (void**) &widget);
 
525
          if (widget == aWidget) {
 
526
            result = bw;
 
527
          }
 
528
          NS_IF_RELEASE(widget);
 
529
        }
 
530
        break;
 
531
      }
 
532
    }
 
533
  }
 
534
  if (nsnull != result) {
 
535
    NS_ADDREF(result);
 
536
  }
 
537
  return result;
 
538
}
 
539
 
 
540
void
 
541
nsBrowserWindow::AddBrowser(nsBrowserWindow* aBrowser)
 
542
{
 
543
  if (!gBrowsers) {
 
544
    gBrowsers = new nsVoidArray();
 
545
    if (!gBrowsers)
 
546
      return;
 
547
  }
 
548
  gBrowsers->AppendElement(aBrowser);
 
549
  NS_ADDREF(aBrowser);
 
550
}
 
551
 
 
552
void
 
553
nsBrowserWindow::RemoveBrowser(nsBrowserWindow* aBrowser)
 
554
{
 
555
  //nsViewerApp* app = aBrowser->mApp;
 
556
  if (!gBrowsers)
 
557
    return;
 
558
  gBrowsers->RemoveElement(aBrowser);
 
559
  if (!gBrowsers->Count()) {
 
560
    delete gBrowsers;
 
561
    gBrowsers = nsnull;
 
562
  }
 
563
  NS_RELEASE(aBrowser);
 
564
}
 
565
 
 
566
void
 
567
nsBrowserWindow::CloseAllWindows()
 
568
{
 
569
  while (gBrowsers && gBrowsers->Count()) {
 
570
    nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers->ElementAt(0);
 
571
    NS_ADDREF(bw);
 
572
    bw->Destroy();
 
573
    NS_RELEASE(bw);
 
574
  }
 
575
  if (gBrowsers) {
 
576
    delete gBrowsers;
 
577
    gBrowsers = nsnull;
 
578
  }
 
579
}
 
580
 
 
581
static nsEventStatus PR_CALLBACK
 
582
HandleBrowserEvent(nsGUIEvent *aEvent)
 
583
 
584
  nsEventStatus result = nsEventStatus_eIgnore;
 
585
  nsBrowserWindow* bw =
 
586
    nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_WINDOW);
 
587
  if (nsnull != bw) {
 
588
    nsSizeEvent* sizeEvent;
 
589
    switch(aEvent->message) {
 
590
    case NS_SIZE:
 
591
      sizeEvent = (nsSizeEvent*)aEvent;  
 
592
      bw->Layout(sizeEvent->windowSize->width,
 
593
                 sizeEvent->windowSize->height);
 
594
      result = nsEventStatus_eConsumeNoDefault;
 
595
      break;
 
596
 
 
597
    case NS_XUL_CLOSE:
 
598
    case NS_DESTROY:
 
599
    {
 
600
      nsViewerApp* app = bw->mApp;
 
601
      app->CloseWindow(bw);
 
602
      result = nsEventStatus_eConsumeDoDefault;
 
603
 
 
604
#ifndef XP_MAC
 
605
      // XXX Really shouldn't just exit, we should just notify somebody...
 
606
      if (!nsBrowserWindow::gBrowsers || !nsBrowserWindow::gBrowsers->Count()) {
 
607
        app->Exit();
 
608
      }
 
609
#endif
 
610
    }
 
611
    return result;
 
612
 
 
613
    case NS_MENU_SELECTED:
 
614
      result = bw->DispatchMenuItem(((nsMenuEvent*)aEvent)->mCommand);
 
615
      break;
 
616
 
 
617
    case NS_ACTIVATE:
 
618
      {
 
619
        nsCOMPtr<nsIWebBrowserFocus> focus = do_GetInterface(bw->mWebBrowser);
 
620
        if (focus)
 
621
          focus->Activate();
 
622
      }
 
623
      break;
 
624
 
 
625
    case NS_DEACTIVATE:
 
626
      {
 
627
        nsCOMPtr<nsIWebBrowserFocus> focus = do_GetInterface(bw->mWebBrowser);
 
628
        if (focus)
 
629
          focus->Deactivate();
 
630
      }
 
631
      break;
 
632
 
 
633
    default:
 
634
      break;
 
635
    }
 
636
    NS_RELEASE(bw);
 
637
  }
 
638
  return result;
 
639
}
 
640
 
 
641
static nsEventStatus PR_CALLBACK
 
642
HandleBackEvent(nsGUIEvent *aEvent)
 
643
{
 
644
  nsEventStatus result = nsEventStatus_eIgnore;
 
645
  nsBrowserWindow* bw =
 
646
    nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_BACK);
 
647
  if (nsnull != bw) {
 
648
    switch(aEvent->message) {
 
649
    case NS_MOUSE_LEFT_BUTTON_UP:
 
650
      bw->Back();
 
651
      break;
 
652
    }
 
653
    NS_RELEASE(bw);
 
654
  }
 
655
  return result;
 
656
}
 
657
 
 
658
static nsEventStatus PR_CALLBACK
 
659
HandleForwardEvent(nsGUIEvent *aEvent)
 
660
{
 
661
  nsEventStatus result = nsEventStatus_eIgnore;
 
662
  nsBrowserWindow* bw =
 
663
    nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_FORWARD);
 
664
  if (nsnull != bw) {
 
665
    switch(aEvent->message) {
 
666
    case NS_MOUSE_LEFT_BUTTON_UP:
 
667
      bw->Forward();
 
668
      break;
 
669
    }
 
670
    NS_RELEASE(bw);
 
671
  }
 
672
  return result;
 
673
}
 
674
 
 
675
static nsEventStatus PR_CALLBACK
 
676
HandleLocationEvent(nsGUIEvent *aEvent)
 
677
{
 
678
  nsEventStatus result = nsEventStatus_eIgnore;
 
679
  nsBrowserWindow* bw =
 
680
    nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_LOCATION);
 
681
  if (nsnull != bw) {
 
682
    switch (aEvent->message) {
 
683
    case NS_KEY_UP:
 
684
      if (NS_VK_RETURN == ((nsKeyEvent*)aEvent)->keyCode) {
 
685
        nsAutoString text;
 
686
        PRUint32 size;
 
687
        bw->mLocation->GetText(text, 1000, size);
 
688
        bw->GoTo(text.get());
 
689
      }
 
690
      break;
 
691
 
 
692
    default:
 
693
      break;
 
694
    }
 
695
    NS_RELEASE(bw);
 
696
  }
 
697
  return result;
 
698
}
 
699
 
 
700
#ifdef PURIFY
 
701
static void
 
702
DispatchPurifyEvent(PRInt32 aID)
 
703
{
 
704
  if (!PurifyIsRunning()) {
 
705
      printf("!!! Re-run viewer under Purify to use this menu item.\n");
 
706
      fflush(stdout);
 
707
      return;
 
708
  }
 
709
 
 
710
  switch (aID) {
 
711
  case VIEWER_PURIFY_SHOW_NEW_LEAKS:
 
712
    PurifyPrintf("viewer: new leaks");
 
713
    PurifyNewLeaks();
 
714
    break;
 
715
  case VIEWER_PURIFY_SHOW_ALL_LEAKS:
 
716
    PurifyPrintf("viewer: all leaks");
 
717
    PurifyAllLeaks();
 
718
    break;
 
719
  case VIEWER_PURIFY_CLEAR_ALL_LEAKS:
 
720
    PurifyPrintf("viewer: clear leaks");
 
721
    PurifyClearLeaks();
 
722
    break;
 
723
  case VIEWER_PURIFY_SHOW_ALL_HANDLES_IN_USE:
 
724
    PurifyPrintf("viewer: all handles");
 
725
    PurifyAllHandlesInuse();
 
726
    break;
 
727
  case VIEWER_PURIFY_SHOW_NEW_IN_USE:
 
728
    PurifyPrintf("viewer: new in-use");
 
729
    PurifyNewInuse();
 
730
    break;
 
731
  case VIEWER_PURIFY_SHOW_ALL_IN_USE:
 
732
    PurifyPrintf("viewer: all in-use");
 
733
    PurifyAllInuse();
 
734
    break;
 
735
  case VIEWER_PURIFY_CLEAR_ALL_IN_USE:
 
736
    PurifyPrintf("viewer: clear in-use");
 
737
    PurifyClearInuse();
 
738
    break;
 
739
  case VIEWER_PURIFY_HEAP_VALIDATE:
 
740
    PurifyPrintf("viewer: heap validate");
 
741
    PurifyHeapValidate(PURIFY_HEAP_ALL, PURIFY_HEAP_BLOCKS_ALL, NULL);
 
742
    break;
 
743
  }
 
744
}
 
745
#endif
 
746
 
 
747
nsEventStatus
 
748
nsBrowserWindow::DispatchMenuItem(PRInt32 aID)
 
749
{
 
750
#if defined(CookieManagement) || defined(SingleSignon) || defined(ClientWallet)
 
751
  nsresult res;
 
752
#if defined(ClientWallet) || defined(SingleSignon)
 
753
  nsIWalletService *walletservice;
 
754
#endif
 
755
#ifdef ClientWallet
 
756
#define WALLET_EDITOR_URL "file:///y|/walleted.html"
 
757
  nsAutoString urlString; urlString.AssignWithConversion(WALLET_EDITOR_URL);
 
758
#endif
 
759
#endif
 
760
 
 
761
  nsEventStatus result;
 
762
#ifdef NS_DEBUG
 
763
  result = DispatchDebugMenu(aID);
 
764
  if (nsEventStatus_eIgnore != result) {
 
765
    return result;
 
766
  }
 
767
#endif
 
768
  result = DispatchStyleMenu(aID);
 
769
  if (nsEventStatus_eIgnore != result) {
 
770
    return result;
 
771
  }
 
772
 
 
773
  switch (aID) {
 
774
  case VIEWER_EXIT:
 
775
    mApp->Exit();
 
776
    return nsEventStatus_eConsumeNoDefault;
 
777
 
 
778
  case VIEWER_WINDOW_OPEN:
 
779
    mApp->OpenWindow();
 
780
    break;
 
781
  
 
782
  case VIEWER_FILE_OPEN:
 
783
    DoFileOpen();
 
784
    break;
 
785
 
 
786
  case VIEW_SOURCE:
 
787
    {
 
788
//      PRInt32 theIndex;
 
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...
 
796
    }
 
797
    break;
 
798
  
 
799
  case VIEWER_EDIT_COPY:
 
800
    DoCopy();
 
801
    break;
 
802
 
 
803
  case VIEWER_EDIT_PASTE:
 
804
    DoPaste();
 
805
    break;
 
806
 
 
807
  case VIEWER_EDIT_FINDINPAGE:
 
808
    DoFind();
 
809
    break;
 
810
 
 
811
  case VIEWER_DEMO0:
 
812
  case VIEWER_DEMO1:
 
813
  case VIEWER_DEMO2:
 
814
  case VIEWER_DEMO3:
 
815
  case VIEWER_DEMO4:
 
816
  case VIEWER_DEMO5:
 
817
  case VIEWER_DEMO6:
 
818
  case VIEWER_DEMO7:
 
819
  case VIEWER_DEMO8: 
 
820
  case VIEWER_DEMO9: 
 
821
  case VIEWER_DEMO10: 
 
822
  case VIEWER_DEMO11: 
 
823
  case VIEWER_DEMO12: 
 
824
  case VIEWER_DEMO13:
 
825
  case VIEWER_DEMO14:
 
826
  case VIEWER_DEMO15:
 
827
  case VIEWER_DEMO16:
 
828
  case VIEWER_DEMO17:
 
829
    {
 
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);
 
837
    }
 
838
    break;
 
839
 
 
840
  case VIEWER_XPTOOLKITTOOLBAR1:
 
841
    {
 
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);
 
846
      break;
 
847
    }
 
848
  case VIEWER_XPTOOLKITTREE1:
 
849
    {
 
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);
 
854
      break;
 
855
    }
 
856
  
 
857
  case JS_CONSOLE:
 
858
    DoJSConsole();
 
859
    break;
 
860
 
 
861
  case VIEWER_PREFS:
 
862
    DoPrefs();
 
863
    break;
 
864
 
 
865
  case EDITOR_MODE:
 
866
    DoEditorMode(mDocShell);
 
867
    break;
 
868
 
 
869
  case VIEWER_ONE_COLUMN:
 
870
  case VIEWER_TWO_COLUMN:
 
871
  case VIEWER_THREE_COLUMN:
 
872
    ShowPrintPreview(aID);
 
873
    break;
 
874
 
 
875
  case VIEWER_PRINT:
 
876
    DoPrint();
 
877
    break;
 
878
 
 
879
  case VIEWER_TABLE_INSPECTOR:
 
880
    DoTableInspector();
 
881
    break;
 
882
 
 
883
  case VIEWER_IMAGE_INSPECTOR:
 
884
    DoImageInspector();
 
885
    break;
 
886
 
 
887
  case VIEWER_GFX_SCROLLBARS_ON: {
 
888
    SetBoolPref("nglayout.widget.gfxscrollbars", PR_TRUE);
 
889
    nsAutoString text;
 
890
    PRUint32 size;
 
891
    mLocation->GetText(text, 1000, size);
 
892
    GoTo(text.get());
 
893
    }
 
894
    break;
 
895
 
 
896
  case VIEWER_GFX_SCROLLBARS_OFF: {
 
897
    SetBoolPref("nglayout.widget.gfxscrollbars", PR_FALSE);
 
898
    nsAutoString text;
 
899
    PRUint32 size;
 
900
    mLocation->GetText(text, 1000, size);
 
901
    GoTo(text.get());
 
902
    }
 
903
    break;
 
904
 
 
905
  case VIEWER_GOTO_TEST_URL1: 
 
906
  case VIEWER_GOTO_TEST_URL2: {
 
907
    nsAutoString urlStr;
 
908
    const char * pref = (aID == VIEWER_GOTO_TEST_URL1) ? "nglayout.widget.testurl1" : "nglayout.widget.testurl2";
 
909
    GetStringPref(pref, urlStr);
 
910
    PRUint32 size;
 
911
    mLocation->SetText(urlStr, size);
 
912
    GoTo(urlStr.get());
 
913
 
 
914
    }
 
915
    break;
 
916
 
 
917
  case VIEWER_SAVE_TEST_URL1: 
 
918
  case VIEWER_SAVE_TEST_URL2: {
 
919
    nsAutoString text;
 
920
    PRUint32 size;
 
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);
 
924
    }
 
925
    break;
 
926
 
 
927
#ifdef PURIFY
 
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);
 
937
    break;
 
938
#endif
 
939
 
 
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);
 
949
    break;
 
950
 
 
951
#ifdef ClientWallet
 
952
  case PRVCY_PREFILL:
 
953
  case PRVCY_QPREFILL:
 
954
  nsIPresShell* shell;
 
955
  shell = nsnull;
 
956
  shell = GetPresShell();
 
957
  res = nsServiceManager::GetService(kWalletServiceCID,
 
958
                                     kIWalletServiceIID,
 
959
                                     (nsISupports **)&walletservice);
 
960
  if ((NS_OK == res) && (nsnull != walletservice)) {
 
961
    nsString urlString2;
 
962
//    res = walletservice->WALLET_Prefill(shell, (PRVCY_QPREFILL == aID));
 
963
    NS_RELEASE(walletservice);
 
964
  }
 
965
 
 
966
#ifndef HTMLDialogs 
 
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);
 
972
    bw->GoTo(url.get());
 
973
    NS_RELEASE(bw);
 
974
  }
 
975
#endif
 
976
  break;
 
977
 
 
978
  case PRVCY_DISPLAY_WALLET:
 
979
  {
 
980
 
 
981
 
 
982
  /* set a cookie for the javascript wallet editor */
 
983
  res = nsServiceManager::GetService(kWalletServiceCID,
 
984
                                     kIWalletServiceIID,
 
985
                                     (nsISupports **)&walletservice);
 
986
  if ((NS_OK == res) && (nsnull != walletservice)) {
 
987
    nsIURI * url;
 
988
    nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &res));
 
989
    if (NS_FAILED(res)) return nsEventStatus_eIgnore;
 
990
 
 
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;
 
994
 
 
995
    res = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&url);
 
996
    NS_RELEASE(uri);
 
997
    if (NS_SUCCEEDED(res)) {
 
998
//      res = walletservice->WALLET_PreEdit(url);
 
999
      NS_RELEASE(walletservice);
 
1000
    }
 
1001
  }
 
1002
 
 
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);
 
1006
  }
 
1007
  break;
 
1008
#endif
 
1009
 
 
1010
#if defined(CookieManagement)
 
1011
  case PRVCY_DISPLAY_COOKIES:
 
1012
  {
 
1013
      break;
 
1014
  }
 
1015
#endif
 
1016
 
 
1017
#if defined(SingleSignon)
 
1018
  case PRVCY_DISPLAY_SIGNONS:
 
1019
  res = nsServiceManager::GetService(kWalletServiceCID,
 
1020
                                     kIWalletServiceIID,
 
1021
                                     (nsISupports **)&walletservice);
 
1022
  if ((NS_OK == res) && (nsnull != walletservice)) {
 
1023
//    res = walletservice->SI_DisplaySignonInfoAsHTML();
 
1024
    NS_RELEASE(walletservice);
 
1025
  }
 
1026
  break;
 
1027
#endif
 
1028
 
 
1029
  }
 
1030
 
 
1031
  // Any menu IDs that the editor uses will be processed here
 
1032
  DoEditorTest(mDocShell, aID);
 
1033
 
 
1034
  return nsEventStatus_eIgnore;
 
1035
}
 
1036
 
 
1037
void
 
1038
nsBrowserWindow::Back()
 
1039
{
 
1040
  nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
 
1041
  webNav->GoBack();
 
1042
}
 
1043
 
 
1044
void
 
1045
nsBrowserWindow::Forward()
 
1046
{
 
1047
  nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
 
1048
  webNav->GoForward();
 
1049
}
 
1050
 
 
1051
void
 
1052
nsBrowserWindow::GoTo(const PRUnichar* aURL)
 
1053
{
 
1054
   nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
 
1055
   webNav->LoadURI(aURL, nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
 
1056
}
 
1057
 
 
1058
 
 
1059
static PRBool GetFileFromFileSelector(nsIDOMWindowInternal* aParentWindow,
 
1060
                                      nsILocalFile **aFile,
 
1061
                                      nsILocalFile **aDisplayDirectory)
 
1062
{
 
1063
  nsresult rv;
 
1064
  nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1");
 
1065
 
 
1066
  if (filePicker) {
 
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);
 
1074
      
 
1075
      PRInt16 dialogResult;
 
1076
      rv = filePicker->Show(&dialogResult);
 
1077
      if (NS_FAILED(rv) || dialogResult == nsIFilePicker::returnCancel)
 
1078
        return PR_FALSE;
 
1079
 
 
1080
      filePicker->GetFile(aFile);
 
1081
      if (*aFile) {
 
1082
        NS_IF_RELEASE(*aDisplayDirectory);
 
1083
        filePicker->GetDisplayDirectory(aDisplayDirectory);
 
1084
        return PR_TRUE;
 
1085
      }
 
1086
    }
 
1087
  }
 
1088
 
 
1089
  return PR_FALSE;
 
1090
}
 
1091
 
 
1092
void
 
1093
nsBrowserWindow::DoFileOpen()
 
1094
{
 
1095
  nsCOMPtr<nsILocalFile> file;
 
1096
  nsCOMPtr<nsIDOMWindow> domWindow;
 
1097
  nsCOMPtr<nsIDOMWindowInternal> parentWindow;
 
1098
  nsresult rv;
 
1099
 
 
1100
  // get nsIDOMWindowInternal interface for nsIFilePicker
 
1101
  rv = mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
 
1102
  if (NS_SUCCEEDED(rv))
 
1103
    parentWindow = do_QueryInterface(domWindow);
 
1104
 
 
1105
  if (GetFileFromFileSelector(parentWindow, getter_AddRefs(file),
 
1106
                              getter_AddRefs(mOpenFileDirectory))) {
 
1107
    nsCOMPtr<nsIURI> uri;
 
1108
    NS_NewFileURI(getter_AddRefs(uri), file);
 
1109
    if (uri) {
 
1110
      nsCAutoString spec;
 
1111
      uri->GetSpec(spec);
 
1112
      
 
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,
 
1117
                      nsnull,
 
1118
                      nsnull,
 
1119
                      nsnull);
 
1120
      SetVisibility(PR_TRUE);
 
1121
    }
 
1122
  }
 
1123
}
 
1124
 
 
1125
#define DIALOG_FONT      "Helvetica"
 
1126
#define DIALOG_FONT_SIZE 10
 
1127
 
 
1128
//---------------------------------------------------------------
 
1129
NS_IMETHODIMP nsBrowserWindow::FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound)
 
1130
{
 
1131
  // Insert find code here.
 
1132
 
 
1133
  return NS_OK;
 
1134
}
 
1135
 
 
1136
//---------------------------------------------------------------
 
1137
NS_IMETHODIMP nsBrowserWindow::ForceRefresh()
 
1138
{
 
1139
  nsIPresShell* shell = GetPresShell();
 
1140
  if (nsnull != shell) {
 
1141
    nsCOMPtr<nsIViewManager> vm;
 
1142
    shell->GetViewManager(getter_AddRefs(vm));
 
1143
    if (vm) {
 
1144
      nsIView* root;
 
1145
      vm->GetRootView(root);
 
1146
      if (nsnull != root) {
 
1147
        vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE);
 
1148
      }
 
1149
    }
 
1150
    NS_RELEASE(shell);
 
1151
  }
 
1152
  return NS_OK;
 
1153
}
 
1154
 
 
1155
 
 
1156
/**--------------------------------------------------------------------------------
 
1157
 * Main Handler
 
1158
 *--------------------------------------------------------------------------------
 
1159
 */
 
1160
 
 
1161
 
 
1162
 
 
1163
nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent)
 
1164
 
1165
  nsEventStatus result = nsEventStatus_eIgnore;
 
1166
 
 
1167
  //printf("aEvent->message %d\n", aEvent->message);
 
1168
  switch(aEvent->message) {
 
1169
 
 
1170
    case NS_KEY_DOWN: {
 
1171
    } break;
 
1172
 
 
1173
    case NS_MOUSE_LEFT_BUTTON_UP: {
 
1174
    } break;
 
1175
 
 
1176
    case NS_PAINT: 
 
1177
      break;
 
1178
    default:
 
1179
      result = nsEventStatus_eIgnore;
 
1180
  }
 
1181
    //printf("result: %d = %d\n", result, PR_FALSE);
 
1182
 
 
1183
    return result;
 
1184
}
 
1185
 
 
1186
void
 
1187
nsBrowserWindow::DoFind()
 
1188
{
 
1189
}
 
1190
 
 
1191
 
 
1192
//----------------------------------------------------------------------
 
1193
 
 
1194
#define VIEWER_BUNDLE_URL NS_LITERAL_CSTRING("resource:/res/viewer.properties")
 
1195
 
 
1196
static nsString* gTitleSuffix = nsnull;
 
1197
 
 
1198
#if XXX
 
1199
static nsString*
 
1200
GetTitleSuffix(void)
 
1201
{
 
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)) {
 
1207
    return suffix;
 
1208
  }
 
1209
  nsIURI* url = nsnull;
 
1210
    nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &ret));
 
1211
    if (NS_FAILED(ret)) return ret;
 
1212
 
 
1213
    nsIURI *uri = nsnull;
 
1214
    ret = service->NewURI(VIEWER_BUNDLE_URL, nsnull, nsnull, &uri);
 
1215
    if (NS_FAILED(ret)) return ret;
 
1216
 
 
1217
    ret = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&url);
 
1218
    NS_RELEASE(uri);
 
1219
  if (NS_FAILED(ret)) {
 
1220
    NS_RELEASE(service);
 
1221
    return suffix;
 
1222
  }
 
1223
  nsIStringBundle* bundle = nsnull;
 
1224
  ret = service->CreateBundle(url, &bundle);
 
1225
  NS_RELEASE(url);
 
1226
  if (NS_FAILED(ret)) {
 
1227
    NS_RELEASE(service);
 
1228
    return suffix;
 
1229
  }
 
1230
  ret = bundle->GetStringFromID(1, *suffix);
 
1231
  NS_RELEASE(bundle);
 
1232
  NS_RELEASE(service);
 
1233
 
 
1234
  return suffix;
 
1235
}
 
1236
#endif
 
1237
 
 
1238
// Note: operator new zeros our memory
 
1239
nsBrowserWindow::nsBrowserWindow()
 
1240
{
 
1241
  if (!gTitleSuffix) {
 
1242
#if XXX
 
1243
    gTitleSuffix = GetTitleSuffix();
 
1244
#endif
 
1245
    if ( (gTitleSuffix = new nsString) != 0 )
 
1246
      gTitleSuffix->Assign(NS_LITERAL_STRING(" - Raptor"));
 
1247
  }
 
1248
  AddBrowser(this);
 
1249
}
 
1250
 
 
1251
nsBrowserWindow::~nsBrowserWindow()
 
1252
{
 
1253
  NS_IF_RELEASE(mAppShell);
 
1254
  NS_IF_RELEASE(mTableInspectorDialog);
 
1255
  NS_IF_RELEASE(mImageInspectorDialog);
 
1256
  NS_IF_RELEASE(mWebCrawler);
 
1257
 
 
1258
  if (nsnull != mTableInspector) {
 
1259
    delete mTableInspector;
 
1260
  }
 
1261
  if (nsnull != mImageInspector) {
 
1262
    delete mImageInspector;
 
1263
  }
 
1264
  if (mWebBrowserChrome) {
 
1265
    mWebBrowserChrome->BrowserWindow(nsnull);
 
1266
    NS_RELEASE(mWebBrowserChrome);
 
1267
  }
 
1268
  if (nsnull != gTitleSuffix) {
 
1269
    delete gTitleSuffix;
 
1270
    gTitleSuffix = nsnull;
 
1271
  }
 
1272
}
 
1273
 
 
1274
NS_IMPL_ISUPPORTS4(nsBrowserWindow, nsIBaseWindow, nsIInterfaceRequestor, nsIProgressEventSink, nsIWebShellContainer)
 
1275
 
 
1276
nsresult
 
1277
nsBrowserWindow::GetInterface(const nsIID& aIID,
 
1278
                              void** aInstancePtrResult)
 
1279
{
 
1280
  nsresult rv;
 
1281
 
 
1282
  NS_PRECONDITION(aInstancePtrResult, "null pointer");
 
1283
  if (!aInstancePtrResult)
 
1284
    return NS_ERROR_NULL_POINTER;
 
1285
 
 
1286
  *aInstancePtrResult = NULL;
 
1287
 
 
1288
  if (aIID.Equals(NS_GET_IID(nsIWebBrowserChrome))) {
 
1289
    rv = EnsureWebBrowserChrome();
 
1290
    if (NS_SUCCEEDED(rv))
 
1291
      return mWebBrowserChrome->QueryInterface(aIID, aInstancePtrResult);
 
1292
  }
 
1293
 
 
1294
  return QueryInterface(aIID, aInstancePtrResult);
 
1295
}
 
1296
 
 
1297
nsresult
 
1298
nsBrowserWindow::Init(nsIAppShell* aAppShell,
 
1299
                      const nsRect& aBounds,
 
1300
                      PRUint32 aChromeMask,
 
1301
                      PRBool aAllowPlugins)
 
1302
{
 
1303
  mChromeMask = aChromeMask;
 
1304
  mAppShell = aAppShell;
 
1305
  NS_IF_ADDREF(mAppShell);
 
1306
  mAllowPlugins = aAllowPlugins;
 
1307
 
 
1308
  // Create top level window
 
1309
  nsresult rv = nsComponentManager::CreateInstance(kWindowCID, nsnull,
 
1310
                                                   kIWidgetIID,
 
1311
                                                   getter_AddRefs(mWindow));
 
1312
  if (NS_OK != rv) {
 
1313
    return rv;
 
1314
  }
 
1315
  nsWidgetInitData initData;
 
1316
  initData.mWindowType = eWindowType_toplevel;
 
1317
  initData.mBorderStyle = eBorderStyle_default;
 
1318
 
 
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);
 
1323
 
 
1324
  // Create web shell
 
1325
  mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
 
1326
  NS_ENSURE_TRUE(mWebBrowser, NS_ERROR_FAILURE);
 
1327
 
 
1328
  r.x = r.y = 0;
 
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);
 
1333
  nsWeakPtr weakling(
 
1334
      do_GetWeakReference((nsIWebProgressListener*)mWebBrowserChrome));
 
1335
  mWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsIWebProgressListener));
 
1336
 
 
1337
  webBrowserWin->Create();
 
1338
 
 
1339
  // Give the embedding app a chance to do platforms-specific window setup
 
1340
  InitNativeWindow();
 
1341
 
 
1342
  // Disable global history because we don't have profile-relative file locations
 
1343
  nsCOMPtr<nsIWebBrowserSetup> setup(do_QueryInterface(mWebBrowser));
 
1344
  if (setup)
 
1345
    setup->SetProperty(nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY, PR_FALSE);
 
1346
 
 
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);
 
1352
 
 
1353
  if (nsIWebBrowserChrome::CHROME_MENUBAR & aChromeMask) {
 
1354
    rv = CreateMenuBar(r.width);
 
1355
    if (NS_OK != rv) {
 
1356
      return rv;
 
1357
    }
 
1358
    mHaveMenuBar = PR_TRUE;
 
1359
    mWindow->GetClientBounds(r);
 
1360
    r.x = r.y = 0;
 
1361
  }
 
1362
 
 
1363
  if (nsIWebBrowserChrome::CHROME_TOOLBAR & aChromeMask) {
 
1364
    rv = CreateToolBar(r.width);
 
1365
    if (NS_OK != rv) {
 
1366
      return rv;
 
1367
    }
 
1368
  }
 
1369
 
 
1370
  if (nsIWebBrowserChrome::CHROME_STATUSBAR & aChromeMask) {
 
1371
    rv = CreateStatusBar(r.width);
 
1372
    if (NS_OK != rv) {
 
1373
      return rv;
 
1374
    }
 
1375
  }
 
1376
 
 
1377
  // Now lay it all out
 
1378
  Layout(r.width, r.height);
 
1379
 
 
1380
  return NS_OK;
 
1381
}
 
1382
 
 
1383
nsresult
 
1384
nsBrowserWindow::Init(nsIAppShell* aAppShell,
 
1385
                      const nsRect& aBounds,
 
1386
                      PRUint32 aChromeMask,
 
1387
                      PRBool aAllowPlugins,
 
1388
                      nsIDocumentViewer* aDocumentViewer,
 
1389
                      nsIPresContext* aPresContext)
 
1390
{
 
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,
 
1397
nsnull,
 
1398
                                                  
 
1399
kIWidgetIID,
 
1400
                                                  
 
1401
getter_AddRefs(mWindow));
 
1402
  if (NS_OK != rv) {
 
1403
    return rv;
 
1404
  }
 
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,
 
1410
                 
 
1411
nsnull, aAppShell, nsnull, &initData);
 
1412
  mWindow->GetClientBounds(r);
 
1413
  // Create web shell
 
1414
  mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
 
1415
  NS_ENSURE_TRUE(mWebBrowser, NS_ERROR_FAILURE);
 
1416
  r.x = r.y = 0;
 
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);
 
1430
    if (NS_OK != rv) {
 
1431
      return rv;
 
1432
    }
 
1433
    mWindow->GetClientBounds(r);
 
1434
    r.x = r.y = 0;
 
1435
  }
 
1436
  if (nsIWebBrowserChrome::CHROME_TOOLBAR & aChromeMask) {
 
1437
    rv = CreateToolBar(r.width);
 
1438
    if (NS_OK != rv) {
 
1439
      return rv;
 
1440
    }
 
1441
  }
 
1442
  if (nsIWebBrowserChrome::CHROME_STATUSBAR & aChromeMask)
 
1443
{
 
1444
    rv = CreateStatusBar(r.width);
 
1445
    if (NS_OK != rv) {
 
1446
      return rv;
 
1447
    }
 
1448
  }
 
1449
  // Give the embedding app a chance to do platforms-specific window setup
 
1450
  InitNativeWindow();
 
1451
 
 
1452
  // Now lay it all out
 
1453
  Layout(r.width, r.height);
 
1454
 
 
1455
 
 
1456
 
 
1457
 
 
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);
 
1465
 
 
1466
  webBrowserWin->SetVisibility(PR_TRUE);
 
1467
 
 
1468
  return NS_OK;
 
1469
}
 
1470
 
 
1471
void
 
1472
nsBrowserWindow::SetWebCrawler(nsWebCrawler* aCrawler)
 
1473
{
 
1474
  if (mWebCrawler) {
 
1475
    if (mDocShell) {
 
1476
      nsCOMPtr<nsIWebProgress> progress(do_GetInterface(mDocShell));
 
1477
      NS_ASSERTION(progress, "no web progress avail");
 
1478
 
 
1479
      (void) progress->RemoveProgressListener(
 
1480
                                (nsIWebProgressListener*)mWebCrawler);
 
1481
    }
 
1482
    NS_RELEASE(mWebCrawler);
 
1483
  }
 
1484
  if (aCrawler) {
 
1485
    mWebCrawler = aCrawler;
 
1486
    NS_ADDREF(aCrawler);
 
1487
  }
 
1488
}
 
1489
 
 
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
 
1495
 
 
1496
nsresult
 
1497
nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
 
1498
{
 
1499
  nsresult rv;
 
1500
 
 
1501
  nsIDeviceContext* dc = mWindow->GetDeviceContext();
 
1502
  float t2d;
 
1503
  t2d = dc->TwipsToDevUnits();
 
1504
  float d2a;
 
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));
 
1509
  NS_RELEASE(dc);
 
1510
 
 
1511
#ifdef USE_LOCAL_WIDGETS
 
1512
  rv = NS_NewButton(&mBack);
 
1513
#else
 
1514
  // Create and place back button
 
1515
  rv = nsComponentManager::CreateInstance(kButtonCID, nsnull, kIButtonIID,
 
1516
                                          (void**)&mBack);
 
1517
#endif
 
1518
 
 
1519
  if (NS_OK != rv) {
 
1520
    return rv;
 
1521
  }
 
1522
  nsRect r(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
 
1523
 
 
1524
  nsIWidget* widget = nsnull;
 
1525
  NS_CreateButton(mWindow,mBack,r,HandleBackEvent,&font);
 
1526
  if (NS_OK == mBack->QueryInterface(kIWidgetIID,(void**)&widget))
 
1527
  {
 
1528
    nsAutoString back(NS_LITERAL_STRING("Back"));
 
1529
    mBack->SetLabel(back);
 
1530
    NS_RELEASE(widget);
 
1531
  }
 
1532
 
 
1533
 
 
1534
  // Create and place forward button
 
1535
  r.SetRect(BUTTON_WIDTH, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
 
1536
  
 
1537
#ifdef USE_LOCAL_WIDGETS
 
1538
  rv = NS_NewButton(&mForward);
 
1539
#else
 
1540
  rv = nsComponentManager::CreateInstance(kButtonCID, nsnull, kIButtonIID,
 
1541
                                          (void**)&mForward);
 
1542
#endif
 
1543
  if (NS_OK != rv) {
 
1544
    return rv;
 
1545
  }
 
1546
  if (NS_OK == mForward->QueryInterface(kIWidgetIID,(void**)&widget))
 
1547
  {
 
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);
 
1553
    NS_RELEASE(widget);
 
1554
  }
 
1555
 
 
1556
 
 
1557
  // Create and place location bar
 
1558
  r.SetRect(2*BUTTON_WIDTH, 0,
 
1559
            aWidth - 2*BUTTON_WIDTH - THROBBER_WIDTH,
 
1560
            BUTTON_HEIGHT);
 
1561
 
 
1562
#ifdef USE_LOCAL_WIDGETS
 
1563
  rv = NS_NewTextWidget(&mLocation);
 
1564
#else
 
1565
  rv = nsComponentManager::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID,
 
1566
                                          (void**)&mLocation);
 
1567
#endif
 
1568
 
 
1569
  if (NS_OK != rv) {
 
1570
    return rv;
 
1571
  }
 
1572
 
 
1573
  NS_CreateTextWidget(mWindow,mLocation,r,HandleLocationEvent,&font);
 
1574
  if (NS_OK == mLocation->QueryInterface(kIWidgetIID,(void**)&widget))
 
1575
  { 
 
1576
    widget->SetForegroundColor(NS_RGB(0, 0, 0));
 
1577
    widget->SetBackgroundColor(NS_RGB(255, 255, 255));
 
1578
    PRUint32 size;
 
1579
    nsAutoString empty;
 
1580
    mLocation->SetText(empty, size);
 
1581
    mLocation->SetMaxTextLength(MAX_TEXT_LENGTH);
 
1582
    NS_RELEASE(widget);
 
1583
  }
 
1584
 
 
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);
 
1591
  mThrobber->Show();
 
1592
  return NS_OK;
 
1593
}
 
1594
 
 
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.
 
1598
nsresult
 
1599
nsBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
 
1600
{
 
1601
  NS_ASSERTION(nsnull != aHeightOut,"null out param.");
 
1602
 
 
1603
  *aHeightOut = 0;
 
1604
 
 
1605
  return NS_OK;
 
1606
}
 
1607
 
 
1608
nsresult
 
1609
nsBrowserWindow::CreateStatusBar(PRInt32 aWidth)
 
1610
{
 
1611
  nsresult rv;
 
1612
 
 
1613
  nsIDeviceContext* dc = mWindow->GetDeviceContext();
 
1614
  float t2d;
 
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)));
 
1619
  NS_RELEASE(dc);
 
1620
 
 
1621
  nsRect r(0, 0, aWidth, THROBBER_HEIGHT);
 
1622
 
 
1623
#ifdef USE_LOCAL_WIDGETS
 
1624
  rv = NS_NewTextWidget(&mStatus);
 
1625
#else
 
1626
  rv = nsComponentManager::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID,
 
1627
                                          (void**)&mStatus);
 
1628
#endif
 
1629
 
 
1630
  if (NS_OK != rv) {
 
1631
    return rv;
 
1632
  }
 
1633
 
 
1634
  nsIWidget* widget = nsnull;
 
1635
  NS_CreateTextWidget(mWindow,mStatus,r,HandleLocationEvent,&font);
 
1636
  if (NS_OK == mStatus->QueryInterface(kIWidgetIID,(void**)&widget))
 
1637
  {
 
1638
    widget->SetForegroundColor(NS_RGB(0, 0, 0));
 
1639
    PRUint32 size;
 
1640
    mStatus->SetText(nsAutoString(),size);
 
1641
    mStatus->SetMaxTextLength(MAX_TEXT_LENGTH);
 
1642
 
 
1643
    nsITextWidget* textWidget = nsnull;
 
1644
    if (NS_OK == mStatus->QueryInterface(kITextWidgetIID,(void**)&textWidget))
 
1645
    {
 
1646
      PRBool  wasReadOnly;
 
1647
      textWidget->SetReadOnly(PR_TRUE, wasReadOnly);
 
1648
      NS_RELEASE(textWidget);
 
1649
    }
 
1650
 
 
1651
    NS_RELEASE(widget);
 
1652
  }
 
1653
 
 
1654
  return NS_OK;
 
1655
}
 
1656
 
 
1657
void
 
1658
nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
 
1659
{
 
1660
  nscoord txtHeight;
 
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);
 
1666
  } else {
 
1667
    txtHeight = 24;
 
1668
  }
 
1669
 
 
1670
  // Find out the menubar height
 
1671
  GetMenuBarHeight(&menuBarHeight);
 
1672
 
 
1673
  nsRect rr(0, 0, aWidth, aHeight);
 
1674
 
 
1675
  // position location bar (it's stretchy)
 
1676
  if (nsIWebBrowserChrome::CHROME_TOOLBAR & mChromeMask) {
 
1677
    nsIWidget* locationWidget = nsnull;
 
1678
    if (mLocation &&
 
1679
        NS_SUCCEEDED(mLocation->QueryInterface(kIWidgetIID,
 
1680
                                               (void**)&locationWidget))) {
 
1681
      if (mThrobber) {
 
1682
        PRInt32 width = PR_MAX(aWidth - (2*BUTTON_WIDTH + THROBBER_WIDTH), 0);
 
1683
      
 
1684
        locationWidget->Resize(2*BUTTON_WIDTH, menuBarHeight,
 
1685
                               width,
 
1686
                               BUTTON_HEIGHT,
 
1687
                               PR_TRUE);
 
1688
        mThrobber->MoveTo(aWidth - THROBBER_WIDTH, menuBarHeight);
 
1689
      }
 
1690
      else {
 
1691
        PRInt32 width = PR_MAX(aWidth - 2*BUTTON_WIDTH, 0);
 
1692
        locationWidget->Resize(2*BUTTON_WIDTH, menuBarHeight,
 
1693
                               width,
 
1694
                               BUTTON_HEIGHT,
 
1695
                               PR_TRUE);
 
1696
      }
 
1697
 
 
1698
      locationWidget->Show(PR_TRUE);
 
1699
      NS_RELEASE(locationWidget);
 
1700
 
 
1701
      nsIWidget* w = nsnull;
 
1702
      if (mBack &&
 
1703
          NS_SUCCEEDED(mBack->QueryInterface(kIWidgetIID, (void**)&w))) {
 
1704
        w->Move(0, menuBarHeight);
 
1705
        w->Show(PR_TRUE);
 
1706
        NS_RELEASE(w);
 
1707
      }
 
1708
      if (mForward &&
 
1709
          NS_SUCCEEDED(mForward->QueryInterface(kIWidgetIID, (void**)&w))) {
 
1710
        w->Move(BUTTON_WIDTH, menuBarHeight);
 
1711
        w->Show(PR_TRUE);
 
1712
        NS_RELEASE(w);
 
1713
      }
 
1714
    }
 
1715
  }
 
1716
  else {
 
1717
    nsIWidget* w = nsnull;
 
1718
    if (mLocation &&
 
1719
        NS_SUCCEEDED(mLocation->QueryInterface(kIWidgetIID, (void**)&w))) {
 
1720
      w->Show(PR_FALSE);
 
1721
      NS_RELEASE(w);
 
1722
    }
 
1723
    if (mBack &&
 
1724
        NS_SUCCEEDED(mBack->QueryInterface(kIWidgetIID, (void**)&w))) {
 
1725
      w->Move(0, menuBarHeight);
 
1726
      w->Show(PR_FALSE);
 
1727
      NS_RELEASE(w);
 
1728
    }
 
1729
    if (mForward &&
 
1730
        NS_SUCCEEDED(mForward->QueryInterface(kIWidgetIID, (void**)&w))) {
 
1731
      w->Move(BUTTON_WIDTH, menuBarHeight);
 
1732
      w->Show(PR_FALSE);
 
1733
      NS_RELEASE(w);
 
1734
    }
 
1735
    if (mThrobber) {
 
1736
      mThrobber->Hide();
 
1737
    }
 
1738
  }
 
1739
  
 
1740
  nsIWidget* statusWidget = nsnull;
 
1741
 
 
1742
  if (mStatus && NS_OK == mStatus->QueryInterface(kIWidgetIID,(void**)&statusWidget)) {
 
1743
    if (mChromeMask & nsIWebBrowserChrome::CHROME_STATUSBAR) {
 
1744
      statusWidget->Resize(0, aHeight - txtHeight,
 
1745
                           aWidth, txtHeight,
 
1746
                           PR_TRUE);
 
1747
 
 
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);
 
1751
    }
 
1752
    else {
 
1753
      statusWidget->Show(PR_FALSE);
 
1754
    }
 
1755
    NS_RELEASE(statusWidget);
 
1756
  }
 
1757
 
 
1758
  // inset the web widget
 
1759
 
 
1760
  if (nsIWebBrowserChrome::CHROME_TOOLBAR & mChromeMask) {
 
1761
    rr.height -= BUTTON_HEIGHT;
 
1762
    rr.y += BUTTON_HEIGHT;
 
1763
  }
 
1764
 
 
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;
 
1769
 
 
1770
  //Since allowing a negative height is a bad idea, let's condition this...
 
1771
  if(rr.height<0)
 
1772
    rr.height=0;
 
1773
 
 
1774
  nsCOMPtr<nsIBaseWindow> webBrowserWin(do_QueryInterface(mWebBrowser));
 
1775
  if (webBrowserWin) {
 
1776
    webBrowserWin->SetPositionAndSize(rr.x, rr.y, rr.width, rr.height, PR_FALSE);
 
1777
  }
 
1778
}
 
1779
 
 
1780
NS_IMETHODIMP
 
1781
nsBrowserWindow::MoveTo(PRInt32 aX, PRInt32 aY)
 
1782
{
 
1783
  NS_PRECONDITION(nsnull != mWindow, "null window");
 
1784
  mWindow->Move(aX, aY);
 
1785
  return NS_OK;
 
1786
}
 
1787
 
 
1788
NS_IMETHODIMP
 
1789
nsBrowserWindow::SizeContentTo(PRInt32 aWidth, PRInt32 aHeight)
 
1790
{
 
1791
  NS_PRECONDITION(nsnull != mWindow, "null window");
 
1792
 
 
1793
  // XXX We want to do this in one shot
 
1794
  mWindow->Resize(aWidth, aHeight, PR_FALSE);
 
1795
  Layout(aWidth, aHeight);
 
1796
 
 
1797
  return NS_OK;
 
1798
}
 
1799
 
 
1800
NS_IMETHODIMP
 
1801
nsBrowserWindow::SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight,
 
1802
                              PRBool /*aWidthTransient*/,
 
1803
                              PRBool /*aHeightTransient*/)
 
1804
{
 
1805
  return SizeContentTo(aWidth, aHeight);
 
1806
}
 
1807
 
 
1808
NS_IMETHODIMP
 
1809
nsBrowserWindow::GetContentBounds(nsRect& aBounds)
 
1810
{
 
1811
  mWindow->GetClientBounds(aBounds);
 
1812
  return NS_OK;
 
1813
}
 
1814
 
 
1815
NS_IMETHODIMP
 
1816
nsBrowserWindow::GetWindowBounds(nsRect& aBounds)
 
1817
{
 
1818
  mWindow->GetBounds(aBounds);
 
1819
  return NS_OK;
 
1820
}
 
1821
 
 
1822
NS_IMETHODIMP
 
1823
nsBrowserWindow::SetChrome(PRUint32 aChromeMask)
 
1824
{
 
1825
  mChromeMask = aChromeMask;
 
1826
  nsRect r;
 
1827
  mWindow->GetClientBounds(r);
 
1828
  Layout(r.width, r.height);
 
1829
 
 
1830
  return NS_OK;
 
1831
}
 
1832
 
 
1833
NS_IMETHODIMP
 
1834
nsBrowserWindow::GetChrome(PRUint32& aChromeMaskResult)
 
1835
{
 
1836
  aChromeMaskResult = mChromeMask;
 
1837
  return NS_OK;
 
1838
}
 
1839
 
 
1840
NS_IMETHODIMP
 
1841
nsBrowserWindow::GetWebShell(nsIWebShell*& aResult)
 
1842
{
 
1843
  nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
 
1844
  aResult = webShell;
 
1845
  NS_IF_ADDREF(aResult);
 
1846
  return NS_OK;
 
1847
}
 
1848
 
 
1849
NS_IMETHODIMP
 
1850
nsBrowserWindow::GetContentWebShell(nsIWebShell **aResult)
 
1851
{
 
1852
  nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
 
1853
  *aResult = webShell;
 
1854
  NS_IF_ADDREF(*aResult);
 
1855
  return NS_OK;
 
1856
}
 
1857
 
 
1858
//----------------------------------------
 
1859
NS_IMETHODIMP
 
1860
nsBrowserWindow::SetProgress(PRInt32 aProgress, PRInt32 aProgressMax)
 
1861
{
 
1862
  return NS_OK;
 
1863
}
 
1864
 
 
1865
NS_IMETHODIMP
 
1866
nsBrowserWindow::ShowMenuBar(PRBool aShow)
 
1867
{
 
1868
  return NS_OK;
 
1869
}
 
1870
 
 
1871
NS_IMETHODIMP
 
1872
nsBrowserWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL,
 
1873
                             nsLoadType aReason)
 
1874
{
 
1875
  return NS_OK;
 
1876
}
 
1877
 
 
1878
NS_IMETHODIMP
 
1879
nsBrowserWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
 
1880
{
 
1881
  return NS_OK;
 
1882
}
 
1883
 
 
1884
NS_IMETHODIMP
 
1885
nsBrowserWindow::ProgressLoadURL(nsIWebShell* aShell,
 
1886
                                 const PRUnichar* aURL,
 
1887
                                 PRInt32 aProgress,
 
1888
                                 PRInt32 aProgressMax)
 
1889
{
 
1890
  return NS_OK;
 
1891
}
 
1892
 
 
1893
NS_IMETHODIMP
 
1894
nsBrowserWindow::EndLoadURL(nsIWebShell* aShell,
 
1895
                            const PRUnichar* aURL,
 
1896
                            nsresult aStatus)
 
1897
{  
 
1898
   return NS_OK;
 
1899
}
 
1900
 
 
1901
 
 
1902
NS_IMETHODIMP
 
1903
nsBrowserWindow::NewWebShell(PRUint32 aChromeMask,
 
1904
                             PRBool aVisible,
 
1905
                             nsIWebShell*& aNewWebShell)
 
1906
{
 
1907
  nsresult rv = NS_OK;
 
1908
 
 
1909
  if (mWebCrawler) {
 
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;
 
1914
    }
 
1915
  }
 
1916
 
 
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);
 
1921
 
 
1922
  if (nsnull != browser)
 
1923
  {
 
1924
    nsRect  bounds;
 
1925
    GetContentBounds(bounds);
 
1926
 
 
1927
    browser->SetApp(mApp);
 
1928
 
 
1929
    // Assume no controls for now
 
1930
    rv = browser->Init(mAppShell, bounds, aChromeMask, mAllowPlugins);
 
1931
    if (NS_OK == rv)
 
1932
    {
 
1933
      // Default is to startup hidden
 
1934
      if (aVisible) {
 
1935
        browser->SetVisibility(PR_TRUE);
 
1936
      }
 
1937
      nsIWebShell *shell;
 
1938
      rv = browser->GetWebShell(shell);
 
1939
      aNewWebShell = shell;
 
1940
    }
 
1941
    else
 
1942
    {
 
1943
      browser->Destroy();
 
1944
    }
 
1945
  }
 
1946
  else
 
1947
    rv = NS_ERROR_OUT_OF_MEMORY;
 
1948
 
 
1949
  return rv;
 
1950
}
 
1951
 
 
1952
 
 
1953
NS_IMETHODIMP
 
1954
nsBrowserWindow::ContentShellAdded(nsIWebShell* aChildShell, nsIContent* frameNode)
 
1955
{
 
1956
  return NS_OK;
 
1957
}
 
1958
 
 
1959
NS_IMETHODIMP
 
1960
nsBrowserWindow::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult)
 
1961
{
 
1962
  PRInt32 i, n = gBrowsers ? gBrowsers->Count() : 0;
 
1963
 
 
1964
  aResult = nsnull;
 
1965
  nsString aNameStr(aName);
 
1966
 
 
1967
  for (i = 0; i < n; i++) {
 
1968
    nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers->ElementAt(i);
 
1969
    nsCOMPtr<nsIWebShell> webShell;
 
1970
    
 
1971
    if (NS_OK == bw->GetWebShell(*getter_AddRefs(webShell))) {
 
1972
      nsXPIDLString name;
 
1973
      nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
 
1974
      if (NS_OK == docShellAsItem->GetName(getter_Copies(name))) {
 
1975
        if (aNameStr.Equals(name)) {
 
1976
          aResult = webShell;
 
1977
          NS_ADDREF(aResult);
 
1978
          return NS_OK;
 
1979
        }
 
1980
      }      
 
1981
 
 
1982
      nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(mDocShell));
 
1983
 
 
1984
      nsCOMPtr<nsIDocShellTreeItem> result;
 
1985
      if (NS_OK == docShellAsNode->FindChildWithName(aName, PR_TRUE, PR_FALSE, nsnull,
 
1986
         getter_AddRefs(result))) {
 
1987
        if (result) {
 
1988
          CallQueryInterface(result, &aResult);
 
1989
          return NS_OK;
 
1990
        }
 
1991
      }
 
1992
    }
 
1993
  }
 
1994
  return NS_OK;
 
1995
}
 
1996
 
 
1997
 
 
1998
//----------------------------------------
 
1999
 
 
2000
NS_IMETHODIMP
 
2001
nsBrowserWindow::OnProgress(nsIRequest* request, nsISupports *ctxt,
 
2002
                            PRUint32 aProgress, PRUint32 aProgressMax)
 
2003
{
 
2004
  nsresult rv;
 
2005
 
 
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;
 
2010
  
 
2011
  if (mStatus) {
 
2012
    nsAutoString url;
 
2013
    if (nsnull != aURL) {
 
2014
      nsCAutoString str;
 
2015
      aURL->GetSpec(str);
 
2016
      AppendUTF8toUTF16(str, url);
 
2017
    }
 
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(")"));
 
2024
    }
 
2025
    PRUint32 size;
 
2026
    mStatus->SetText(url,size);
 
2027
  }
 
2028
  return NS_OK;
 
2029
}
 
2030
 
 
2031
NS_IMETHODIMP
 
2032
nsBrowserWindow::OnStatus(nsIRequest* request, nsISupports *ctxt,
 
2033
                          nsresult aStatus, const PRUnichar *aStatusArg)
 
2034
{
 
2035
  if (mStatus) {
 
2036
    nsresult rv;
 
2037
    nsCOMPtr<nsIStringBundleService> sbs = do_GetService(kStringBundleServiceCID, &rv);
 
2038
    if (NS_FAILED(rv)) return rv;
 
2039
    nsXPIDLString msg;
 
2040
    rv = sbs->FormatStatusMessage(aStatus, aStatusArg, getter_Copies(msg));
 
2041
    if (NS_FAILED(rv)) return rv;
 
2042
    PRUint32 size;
 
2043
    nsAutoString msg2( NS_STATIC_CAST(const PRUnichar*, msg));
 
2044
    mStatus->SetText(msg2, size);
 
2045
  }
 
2046
  return NS_OK;
 
2047
}
 
2048
 
 
2049
//----------------------------------------
 
2050
 
 
2051
// Toolbar support
 
2052
 
 
2053
void
 
2054
nsBrowserWindow::StartThrobber()
 
2055
{
 
2056
}
 
2057
 
 
2058
void
 
2059
nsBrowserWindow::StopThrobber()
 
2060
{
 
2061
}
 
2062
 
 
2063
void
 
2064
nsBrowserWindow::LoadThrobberImages()
 
2065
{
 
2066
}
 
2067
 
 
2068
void
 
2069
nsBrowserWindow::DestroyThrobberImages()
 
2070
{
 
2071
}
 
2072
 
 
2073
nsIPresShell*
 
2074
nsBrowserWindow::GetPresShell()
 
2075
{
 
2076
  return GetPresShellFor(mDocShell);
 
2077
}
 
2078
 
 
2079
 
 
2080
void
 
2081
nsBrowserWindow::DoCopy()
 
2082
{
 
2083
  nsIPresShell* shell = GetPresShell();
 
2084
  if (nsnull != shell) {
 
2085
    shell->DoCopy();
 
2086
    NS_RELEASE(shell);
 
2087
  }
 
2088
}
 
2089
 
 
2090
void
 
2091
nsBrowserWindow::DoPaste()
 
2092
{
 
2093
  nsIPresShell* shell = GetPresShell();
 
2094
  if (nsnull != shell) {
 
2095
 
 
2096
    printf("nsBrowserWindow::DoPaste()\n");
 
2097
 
 
2098
    NS_RELEASE(shell);
 
2099
  }
 
2100
}
 
2101
 
 
2102
//----------------------------------------------------------------------
 
2103
 
 
2104
void
 
2105
nsBrowserWindow::ShowPrintPreview(PRInt32 aID)
 
2106
{
 
2107
  nsCOMPtr <nsIContentViewer> viewer;
 
2108
 
 
2109
  mDocShell->GetContentViewer(getter_AddRefs(viewer));
 
2110
 
 
2111
  if (viewer)
 
2112
  {
 
2113
    nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
 
2114
    if (viewerFile) {
 
2115
      //viewerFile->PrintPreview(nsnull);
 
2116
    }
 
2117
  }
 
2118
}
 
2119
 
 
2120
void nsBrowserWindow::DoPrint(void)
 
2121
{
 
2122
  nsCOMPtr <nsIContentViewer> viewer;
 
2123
 
 
2124
  mDocShell->GetContentViewer(getter_AddRefs(viewer));
 
2125
 
 
2126
  if (viewer) {
 
2127
    nsCOMPtr<nsIWebBrowserPrint> webBrowserPrint = do_QueryInterface(viewer);
 
2128
    if (webBrowserPrint) {
 
2129
      if (!mPrintSettings) {
 
2130
        webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(mPrintSettings));
 
2131
      }
 
2132
      webBrowserPrint->Print(mPrintSettings, (nsIWebProgressListener*)nsnull);
 
2133
    }
 
2134
  }
 
2135
}
 
2136
 
 
2137
//---------------------------------------------------------------
 
2138
nsIDOMDocument* nsBrowserWindow::GetDOMDocument(nsIDocShell *aDocShell)
 
2139
{
 
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);
 
2151
        }
 
2152
        NS_RELEASE(mDViewer);
 
2153
      }
 
2154
      NS_RELEASE(mCViewer);
 
2155
    }
 
2156
  }
 
2157
  return domDoc;
 
2158
}
 
2159
 
 
2160
//---------------------------------------------------------------
 
2161
 
 
2162
void nsBrowserWindow::DoTableInspector()
 
2163
{
 
2164
  if (mTableInspectorDialog) {
 
2165
    mTableInspectorDialog->SetVisible(PR_TRUE);
 
2166
    return;
 
2167
  }
 
2168
  nsIDOMDocument* domDoc = GetDOMDocument(mDocShell);
 
2169
 
 
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"));
 
2174
 
 
2175
    nsXPBaseWindow * xpWin = nsnull;
 
2176
    nsresult rv = nsComponentManager::CreateInstance(kXPBaseWindowCID, nsnull,
 
2177
                                                     kIXPBaseWindowIID,
 
2178
                                                     (void**) &xpWin);
 
2179
    if (rv == NS_OK) {
 
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); 
 
2186
        }
 
2187
      }
 
2188
      NS_RELEASE(xpWin);
 
2189
    }
 
2190
    NS_RELEASE(domDoc);
 
2191
  }
 
2192
 
 
2193
}
 
2194
void nsBrowserWindow::DoImageInspector()
 
2195
{
 
2196
  if (mImageInspectorDialog) {
 
2197
    mImageInspectorDialog->SetVisible(PR_TRUE);
 
2198
    return;
 
2199
  }
 
2200
 
 
2201
  nsIDOMDocument* domDoc = GetDOMDocument(mDocShell);
 
2202
 
 
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"));
 
2207
 
 
2208
    nsXPBaseWindow * xpWin = nsnull;
 
2209
    nsresult rv = nsComponentManager::CreateInstance(kXPBaseWindowCID, nsnull, kIXPBaseWindowIID, (void**) &xpWin);
 
2210
    if (rv == NS_OK) {
 
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); 
 
2217
        }
 
2218
      }
 
2219
      NS_RELEASE(xpWin);
 
2220
    }
 
2221
    NS_RELEASE(domDoc);
 
2222
  }
 
2223
 
 
2224
}
 
2225
 
 
2226
//----------------------------------------------------------------------
 
2227
 
 
2228
void
 
2229
nsBrowserWindow::DoJSConsole()
 
2230
{
 
2231
  mApp->CreateJSConsole(this);
 
2232
}
 
2233
 
 
2234
void
 
2235
nsBrowserWindow::DoPrefs()
 
2236
{
 
2237
  mApp->DoPrefs(this);
 
2238
}
 
2239
 
 
2240
void
 
2241
nsBrowserWindow::DoEditorMode(nsIDocShell *aDocShell)
 
2242
{
 
2243
  PRInt32 i, n;
 
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)) 
 
2250
      {
 
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)) 
 
2256
          {
 
2257
            nsIPresShell* shell = GetPresShellFor(aDocShell);
 
2258
            NS_InitEditorMode(mDOMDoc, shell);
 
2259
            NS_RELEASE(mDOMDoc);
 
2260
            NS_IF_RELEASE(shell);
 
2261
          }
 
2262
        }
 
2263
        NS_RELEASE(mDViewer);
 
2264
      }
 
2265
      NS_RELEASE(mCViewer);
 
2266
    }
 
2267
    
 
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);
 
2275
    }
 
2276
  }
 
2277
}
 
2278
 
 
2279
// Same as above, but calls NS_DoEditorTest instead of starting an editor
 
2280
void
 
2281
nsBrowserWindow::DoEditorTest(nsIDocShell *aDocShell, PRInt32 aCommandID)
 
2282
{
 
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)) 
 
2289
      {
 
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)) 
 
2295
          {
 
2296
            NS_DoEditorTest(aCommandID);
 
2297
            NS_RELEASE(mDOMDoc);
 
2298
          }
 
2299
        }
 
2300
        NS_RELEASE(mDViewer);
 
2301
      }
 
2302
      NS_RELEASE(mCViewer);
 
2303
    }
 
2304
    // Do we need to do all the children as in DoEditorMode?
 
2305
    // Its seems to work if we don't do that
 
2306
  }
 
2307
}
 
2308
 
 
2309
 
 
2310
 
 
2311
 
 
2312
#ifdef NS_DEBUG
 
2313
#include "nsIContent.h"
 
2314
#include "nsIFrame.h"
 
2315
#include "nsIFrameDebug.h"
 
2316
 
 
2317
 
 
2318
static void DumpAWebShell(nsIDocShellTreeItem* aShellItem, FILE* out, PRInt32 aIndent)
 
2319
{
 
2320
  nsXPIDLString name;
 
2321
  nsAutoString str;
 
2322
  nsCOMPtr<nsIDocShellTreeItem> parent;
 
2323
  PRInt32 i, n;
 
2324
 
 
2325
  for (i = aIndent; --i >= 0; ) fprintf(out, "  ");
 
2326
 
 
2327
  fprintf(out, "%p '", aShellItem);
 
2328
  aShellItem->GetName(getter_Copies(name));
 
2329
  aShellItem->GetSameTypeParent(getter_AddRefs(parent));
 
2330
  str.Assign(name);
 
2331
  fputs(NS_LossyConvertUCS2toASCII(str).get(), out);
 
2332
  fprintf(out, "' parent=%p <\n", parent.get());
 
2333
 
 
2334
  aIndent++;
 
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));
 
2340
    if (child) {
 
2341
      DumpAWebShell(child, out, aIndent);
 
2342
    }
 
2343
  }
 
2344
  aIndent--;
 
2345
  for (i = aIndent; --i >= 0; ) fprintf(out, "  ");
 
2346
  fputs(">\n", out);
 
2347
}
 
2348
 
 
2349
void
 
2350
nsBrowserWindow::DumpWebShells(FILE* out)
 
2351
{
 
2352
  nsCOMPtr<nsIDocShellTreeItem> shellAsItem(do_QueryInterface(mDocShell));
 
2353
  DumpAWebShell(shellAsItem, out, 0);
 
2354
}
 
2355
 
 
2356
static
 
2357
void 
 
2358
DumpMultipleWebShells(nsBrowserWindow& aBrowserWindow, nsIDocShell* aDocShell, FILE* aOut)
 
2359
 
2360
  PRInt32 count;
 
2361
  nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(aDocShell));
 
2362
  if (docShellAsNode) {
 
2363
    docShellAsNode->GetChildCount(&count);
 
2364
    if (count > 0) {
 
2365
      fprintf(aOut, "webshells= \n");
 
2366
      aBrowserWindow.DumpWebShells(aOut);
 
2367
    }
 
2368
  }
 
2369
}
 
2370
 
 
2371
static
 
2372
void
 
2373
DumpContentRecurse(nsIDocShell* aDocShell, FILE* out)
 
2374
{
 
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));
 
2381
      if (doc) {
 
2382
        nsIContent *root = doc->GetRootContent();
 
2383
        if (nsnull != root) {
 
2384
          root->List(out);
 
2385
        }
 
2386
      }
 
2387
      NS_RELEASE(shell);
 
2388
    }
 
2389
    else {
 
2390
      fputs("null pres shell\n", out);
 
2391
    }
 
2392
    // dump the frames of the sub documents
 
2393
    PRInt32 i, n;
 
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);
 
2402
      }
 
2403
    }
 
2404
  }
 
2405
}
 
2406
 
 
2407
void
 
2408
nsBrowserWindow::DumpContent(FILE* out)
 
2409
{
 
2410
  DumpContentRecurse(mDocShell, out);
 
2411
  DumpMultipleWebShells(*this, mDocShell, out);
 
2412
}
 
2413
 
 
2414
static void
 
2415
DumpFramesRecurse(nsIDocShell* aDocShell, FILE* out, nsString *aFilterName)
 
2416
{
 
2417
  if (nsnull != aDocShell) {
 
2418
    fprintf(out, "webshell=%p \n", aDocShell);
 
2419
    nsIPresShell* shell = GetPresShellFor(aDocShell);
 
2420
    if (nsnull != shell) {
 
2421
      nsIFrame* root;
 
2422
      shell->GetRootFrame(&root);
 
2423
      if (nsnull != root) {
 
2424
        nsIPresContext* presContext;
 
2425
        shell->GetPresContext(&presContext);
 
2426
 
 
2427
        nsIFrameDebug* fdbg;
 
2428
        if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) {
 
2429
          fdbg->List(presContext, out, 0);
 
2430
        }
 
2431
        NS_IF_RELEASE(presContext);
 
2432
      }
 
2433
      NS_RELEASE(shell);
 
2434
    }
 
2435
    else {
 
2436
      fputs("null pres shell\n", out);
 
2437
    }
 
2438
 
 
2439
    // dump the frames of the sub documents
 
2440
    PRInt32 i, n;
 
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));
 
2447
      if (childAsShell) {
 
2448
        DumpFramesRecurse(childAsShell, out, aFilterName);
 
2449
      }
 
2450
    }
 
2451
  }
 
2452
}
 
2453
 
 
2454
void
 
2455
nsBrowserWindow::DumpFrames(FILE* out, nsString *aFilterName)
 
2456
{
 
2457
  DumpFramesRecurse(mDocShell, out, aFilterName);
 
2458
  DumpMultipleWebShells(*this, mDocShell, out);
 
2459
}
 
2460
 
 
2461
//----------------------------------------------------------------------
 
2462
 
 
2463
static
 
2464
void
 
2465
DumpViewsRecurse(nsIDocShell* aDocShell, FILE* out)
 
2466
{
 
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));
 
2473
      if (vm) {
 
2474
        nsIView* root;
 
2475
        vm->GetRootView(root);
 
2476
        if (nsnull != root) {
 
2477
          root->List(out);
 
2478
        }
 
2479
      }
 
2480
      NS_RELEASE(shell);
 
2481
    }
 
2482
    else {
 
2483
      fputs("null pres shell\n", out);
 
2484
    }
 
2485
 
 
2486
    // dump the views of the sub documents
 
2487
    PRInt32 i, n;
 
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));
 
2494
      if (childAsShell) {
 
2495
        DumpViewsRecurse(childAsShell, out);
 
2496
      }
 
2497
    }
 
2498
  }
 
2499
}
 
2500
 
 
2501
void
 
2502
nsBrowserWindow::DumpViews(FILE* out)
 
2503
{
 
2504
  DumpViewsRecurse(mDocShell, out);
 
2505
  DumpMultipleWebShells(*this, mDocShell, out);
 
2506
}
 
2507
 
 
2508
void
 
2509
nsBrowserWindow::DumpStyleSheets(FILE* out)
 
2510
{
 
2511
  nsCOMPtr<nsIPresShell> shell = dont_AddRef(GetPresShell());
 
2512
  if (shell) {
 
2513
    shell->ListStyleSheets(out);
 
2514
  } else {
 
2515
    fputs("null pres shell\n", out);
 
2516
  }
 
2517
}
 
2518
 
 
2519
void
 
2520
nsBrowserWindow::DumpStyleContexts(FILE* out)
 
2521
{
 
2522
  nsCOMPtr<nsIPresShell> shell = dont_AddRef(GetPresShell());
 
2523
  if (shell) {
 
2524
    nsIFrame* root;
 
2525
    shell->GetRootFrame(&root);
 
2526
    shell->ListStyleContexts(root, out);
 
2527
  } else {
 
2528
    fputs("null pres shell\n", out);
 
2529
  }
 
2530
}
 
2531
 
 
2532
void
 
2533
nsBrowserWindow::DumpReflowStats(FILE* out)
 
2534
{
 
2535
  nsIPresShell* shell = GetPresShell();
 
2536
  if (nsnull != shell) {
 
2537
#ifdef MOZ_REFLOW_PERF
 
2538
    shell->DumpReflows();
 
2539
#else
 
2540
    fprintf(out,"***********************************\n");
 
2541
    fprintf(out, "Sorry, you have built with MOZ_REFLOW_PERF=1\n");
 
2542
    fprintf(out,"***********************************\n");
 
2543
#endif
 
2544
    NS_RELEASE(shell);
 
2545
  } else {
 
2546
    fputs("null pres shell\n", out);
 
2547
  }
 
2548
}
 
2549
 
 
2550
void
 
2551
nsBrowserWindow::DisplayReflowStats(PRBool aIsOn)
 
2552
{
 
2553
  nsIPresShell* shell = GetPresShell();
 
2554
  if (nsnull != shell) {
 
2555
#ifdef MOZ_REFLOW_PERF
 
2556
    shell->SetPaintFrameCount(aIsOn);
 
2557
    SetBoolPref("layout.reflow.showframecounts",aIsOn);
 
2558
    ForceRefresh();
 
2559
#else
 
2560
    printf("***********************************\n");
 
2561
    printf("Sorry, you have built with MOZ_REFLOW_PERF=1\n");
 
2562
    printf("***********************************\n");
 
2563
#endif
 
2564
    NS_RELEASE(shell);
 
2565
  }
 
2566
}
 
2567
 
 
2568
void
 
2569
nsBrowserWindow::ToggleFrameBorders()
 
2570
{
 
2571
  nsILayoutDebugger* ld;
 
2572
  nsresult rv = nsComponentManager::CreateInstance(kLayoutDebuggerCID,
 
2573
                                                   nsnull,
 
2574
                                                   kILayoutDebuggerIID,
 
2575
                                                   (void **)&ld);
 
2576
  if (NS_SUCCEEDED(rv)) {
 
2577
    PRBool showing;
 
2578
    ld->GetShowFrameBorders(&showing);
 
2579
    ld->SetShowFrameBorders(!showing);
 
2580
    ForceRefresh();
 
2581
    NS_RELEASE(ld);
 
2582
  }
 
2583
}
 
2584
 
 
2585
void
 
2586
nsBrowserWindow::ToggleVisualEventDebugging()
 
2587
{
 
2588
  nsILayoutDebugger* ld;
 
2589
  nsresult rv = nsComponentManager::CreateInstance(kLayoutDebuggerCID,
 
2590
                                                   nsnull,
 
2591
                                                   kILayoutDebuggerIID,
 
2592
                                                   (void **)&ld);
 
2593
  if (NS_SUCCEEDED(rv)) {
 
2594
    PRBool showing;
 
2595
    ld->GetShowEventTargetFrameBorder(&showing);
 
2596
    ld->SetShowEventTargetFrameBorder(!showing);
 
2597
    ForceRefresh();
 
2598
    NS_RELEASE(ld);
 
2599
  }
 
2600
}
 
2601
 
 
2602
void
 
2603
nsBrowserWindow::ToggleBoolPrefAndRefresh(const char * aPrefName)
 
2604
{
 
2605
  NS_ASSERTION(nsnull != aPrefName,"null pref name");
 
2606
 
 
2607
  nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
 
2608
  if (prefs && nsnull != aPrefName)
 
2609
  {
 
2610
    PRBool value;
 
2611
    prefs->GetBoolPref(aPrefName,&value);
 
2612
    prefs->SetBoolPref(aPrefName,!value);
 
2613
    prefs->SavePrefFile(nsnull);
 
2614
    
 
2615
    ForceRefresh();
 
2616
  }
 
2617
}
 
2618
 
 
2619
#endif
 
2620
 
 
2621
void
 
2622
nsBrowserWindow::SetBoolPref(const char * aPrefName, PRBool aValue)
 
2623
{
 
2624
  NS_ASSERTION(nsnull != aPrefName,"null pref name");
 
2625
 
 
2626
  nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
 
2627
  if (prefs && nsnull != aPrefName)
 
2628
  {
 
2629
    prefs->SetBoolPref(aPrefName, aValue);
 
2630
    prefs->SavePrefFile(nsnull);
 
2631
  }
 
2632
}
 
2633
 
 
2634
void
 
2635
nsBrowserWindow::SetStringPref(const char * aPrefName, const nsString& aValue)
 
2636
{
 
2637
  NS_ASSERTION(nsnull != aPrefName, "null pref name");
 
2638
 
 
2639
  nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
 
2640
  if (nsnull != prefs && nsnull != aPrefName)
 
2641
  {
 
2642
    char * prefStr = ToNewCString(aValue);
 
2643
    prefs->SetCharPref(aPrefName, prefStr);
 
2644
    prefs->SavePrefFile(nsnull);
 
2645
    delete [] prefStr;
 
2646
  }
 
2647
 
 
2648
}
 
2649
 
 
2650
void
 
2651
nsBrowserWindow::GetStringPref(const char * aPrefName, nsString& aValue)
 
2652
{
 
2653
  NS_ASSERTION(nsnull != aPrefName, "null pref name");
 
2654
 
 
2655
  nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
 
2656
  if (nsnull != prefs && nsnull != aPrefName)
 
2657
  {
 
2658
    char* prefCharVal;
 
2659
    nsresult result = prefs->CopyCharPref(aPrefName, &prefCharVal);
 
2660
    if (NS_SUCCEEDED(result)) {
 
2661
      aValue.AssignWithConversion(prefCharVal);
 
2662
      PL_strfree(prefCharVal);
 
2663
    }
 
2664
  }
 
2665
}
 
2666
 
 
2667
#ifdef NS_DEBUG
 
2668
void
 
2669
nsBrowserWindow::DoDebugSave()
 
2670
{
 
2671
  /* Removed 04/01/99 -- gpk */
 
2672
}
 
2673
 
 
2674
void 
 
2675
nsBrowserWindow::DoToggleSelection()
 
2676
{
 
2677
  nsIPresShell* shell = GetPresShell();
 
2678
  if (nsnull != shell) {
 
2679
    nsCOMPtr<nsISelectionController> selCon;
 
2680
    selCon = do_QueryInterface(shell);
 
2681
    if (selCon) {
 
2682
      PRInt16  current;
 
2683
      selCon->GetDisplaySelection(&current);
 
2684
      selCon->SetDisplaySelection(!current);
 
2685
      ForceRefresh();
 
2686
    }
 
2687
    NS_RELEASE(shell);
 
2688
  }
 
2689
}
 
2690
 
 
2691
void
 
2692
nsBrowserWindow::DoDebugRobot()
 
2693
{
 
2694
  mApp->CreateRobot(this);
 
2695
}
 
2696
 
 
2697
void
 
2698
nsBrowserWindow::DoSiteWalker()
 
2699
{
 
2700
  mApp->CreateSiteWalker(this);
 
2701
}
 
2702
 
 
2703
nsEventStatus
 
2704
nsBrowserWindow::DispatchDebugMenu(PRInt32 aID)
 
2705
{
 
2706
  nsEventStatus result = nsEventStatus_eIgnore;
 
2707
 
 
2708
  switch(aID) {
 
2709
    case VIEWER_VISUAL_DEBUGGING:
 
2710
      ToggleFrameBorders();
 
2711
      result = nsEventStatus_eConsumeNoDefault;
 
2712
      break;
 
2713
 
 
2714
    case VIEWER_VISUAL_EVENT_DEBUGGING:
 
2715
      ToggleVisualEventDebugging();
 
2716
      result = nsEventStatus_eConsumeNoDefault;
 
2717
      break;
 
2718
 
 
2719
    case VIEWER_TOGGLE_PAINT_FLASHING:
 
2720
      ToggleBoolPrefAndRefresh("nglayout.debug.paint_flashing");
 
2721
      result = nsEventStatus_eConsumeNoDefault;
 
2722
      break;
 
2723
 
 
2724
    case VIEWER_TOGGLE_PAINT_DUMPING:
 
2725
      ToggleBoolPrefAndRefresh("nglayout.debug.paint_dumping");
 
2726
      result = nsEventStatus_eConsumeNoDefault;
 
2727
      break;
 
2728
 
 
2729
    case VIEWER_TOGGLE_INVALIDATE_DUMPING:
 
2730
      ToggleBoolPrefAndRefresh("nglayout.debug.invalidate_dumping");
 
2731
      result = nsEventStatus_eConsumeNoDefault;
 
2732
      break;
 
2733
 
 
2734
    case VIEWER_TOGGLE_EVENT_DUMPING:
 
2735
      ToggleBoolPrefAndRefresh("nglayout.debug.event_dumping");
 
2736
      result = nsEventStatus_eConsumeNoDefault;
 
2737
      break;
 
2738
 
 
2739
    case VIEWER_TOGGLE_MOTION_EVENT_DUMPING:
 
2740
      ToggleBoolPrefAndRefresh("nglayout.debug.motion_event_dumping");
 
2741
      result = nsEventStatus_eConsumeNoDefault;
 
2742
      break;
 
2743
 
 
2744
    case VIEWER_TOGGLE_CROSSING_EVENT_DUMPING:
 
2745
      ToggleBoolPrefAndRefresh("nglayout.debug.crossing_event_dumping");
 
2746
      result = nsEventStatus_eConsumeNoDefault;
 
2747
      break;
 
2748
 
 
2749
    case VIEWER_DUMP_CONTENT:
 
2750
      DumpContent();
 
2751
      result = nsEventStatus_eConsumeNoDefault;
 
2752
      break;
 
2753
 
 
2754
    case VIEWER_DUMP_FRAMES:
 
2755
      DumpFrames();
 
2756
      result = nsEventStatus_eConsumeNoDefault;
 
2757
      break;
 
2758
 
 
2759
    case VIEWER_DUMP_VIEWS:
 
2760
      DumpViews();
 
2761
      result = nsEventStatus_eConsumeNoDefault;
 
2762
      break;
 
2763
 
 
2764
    case VIEWER_DUMP_STYLE_SHEETS:
 
2765
      DumpStyleSheets();
 
2766
      result = nsEventStatus_eConsumeNoDefault;
 
2767
      break;
 
2768
 
 
2769
    case VIEWER_DUMP_STYLE_CONTEXTS:
 
2770
      DumpStyleContexts();
 
2771
      result = nsEventStatus_eConsumeNoDefault;
 
2772
      break;
 
2773
 
 
2774
    case VIEWER_DEBUG_DUMP_REFLOW_TOTS:
 
2775
      DumpReflowStats();
 
2776
      result = nsEventStatus_eConsumeNoDefault;
 
2777
      break;
 
2778
 
 
2779
    case VIEWER_DSP_REFLOW_CNTS_ON:
 
2780
      DisplayReflowStats(PR_TRUE);
 
2781
      result = nsEventStatus_eConsumeNoDefault;
 
2782
      break;
 
2783
 
 
2784
    case VIEWER_DSP_REFLOW_CNTS_OFF:
 
2785
      DisplayReflowStats(PR_FALSE);
 
2786
      result = nsEventStatus_eConsumeNoDefault;
 
2787
      break;
 
2788
 
 
2789
    case VIEWER_DEBUGSAVE:
 
2790
      DoDebugSave();
 
2791
      break;
 
2792
 
 
2793
    case VIEWER_TOGGLE_SELECTION:
 
2794
      DoToggleSelection();
 
2795
      break;
 
2796
 
 
2797
 
 
2798
    case VIEWER_DEBUGROBOT:
 
2799
      DoDebugRobot();
 
2800
      break;
 
2801
 
 
2802
    case VIEWER_TOP100:
 
2803
      DoSiteWalker();
 
2804
      break;
 
2805
  }
 
2806
  return(result);
 
2807
}
 
2808
 
 
2809
#endif // NS_DEBUG
 
2810
 
 
2811
#define USE_DTD  0
 
2812
#define STANDARD 1 
 
2813
#define QUIRKS   2 
 
2814
void 
 
2815
nsBrowserWindow::SetCompatibilityMode(PRUint32 aMode)
 
2816
{
 
2817
  nsCOMPtr<nsIPref> pref(do_GetService(NS_PREF_CONTRACTID));
 
2818
  if (pref) { 
 
2819
    int32 prefInt = USE_DTD;
 
2820
    if (STANDARD == aMode) {
 
2821
      prefInt = eCompatibility_FullStandards;
 
2822
    }
 
2823
    else if (QUIRKS == aMode) {
 
2824
      prefInt = eCompatibility_NavQuirks;
 
2825
    }
 
2826
    pref->SetIntPref("nglayout.compatibility.mode", prefInt);
 
2827
    pref->SavePrefFile(nsnull);
 
2828
  }
 
2829
}
 
2830
 
 
2831
nsEventStatus
 
2832
nsBrowserWindow::DispatchStyleMenu(PRInt32 aID)
 
2833
{
 
2834
  nsEventStatus result = nsEventStatus_eIgnore;
 
2835
 
 
2836
  switch(aID) {
 
2837
  case VIEWER_SELECT_STYLE_LIST:
 
2838
    {
 
2839
      nsIPresShell* shell = GetPresShell();
 
2840
      if (nsnull != shell) {
 
2841
        nsAutoString  defaultStyle;
 
2842
        nsCOMPtr<nsIDocument> doc;
 
2843
        shell->GetDocument(getter_AddRefs(doc));
 
2844
        if (doc) {
 
2845
          nsIAtom* defStyleAtom = NS_NewAtom("default-style");
 
2846
          doc->GetHeaderData(defStyleAtom, defaultStyle);
 
2847
          NS_RELEASE(defStyleAtom);
 
2848
        }
 
2849
 
 
2850
        nsStringArray titles;
 
2851
        shell->ListAlternateStyleSheets(titles);
 
2852
        nsAutoString  current;
 
2853
        shell->GetActiveAlternateStyleSheet(current);
 
2854
 
 
2855
        PRInt32 count = titles.Count();
 
2856
        fprintf(stdout, "There %s %d alternate style sheet%s\n",  
 
2857
                ((1 == count) ? "is" : "are"),
 
2858
                count,
 
2859
                ((1 == count) ? "" : "s"));
 
2860
        PRInt32 index;
 
2861
        for (index = 0; index < count; index++) {
 
2862
          fprintf(stdout, "%d: \"", index + 1);
 
2863
          nsAutoString title;
 
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" : ""));
 
2869
        }
 
2870
        NS_RELEASE(shell);
 
2871
      }
 
2872
    }
 
2873
    result = nsEventStatus_eConsumeNoDefault;
 
2874
    break;
 
2875
 
 
2876
  case VIEWER_SELECT_STYLE_DEFAULT:
 
2877
    {
 
2878
      nsIPresShell* shell = GetPresShell();
 
2879
      if (nsnull != shell) {
 
2880
        nsCOMPtr<nsIDocument> doc;
 
2881
        shell->GetDocument(getter_AddRefs(doc));
 
2882
        if (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);
 
2891
        }
 
2892
        NS_RELEASE(shell);
 
2893
      }
 
2894
    }
 
2895
    result = nsEventStatus_eConsumeNoDefault;
 
2896
    break;
 
2897
 
 
2898
  case VIEWER_SELECT_STYLE_ONE:
 
2899
  case VIEWER_SELECT_STYLE_TWO:
 
2900
  case VIEWER_SELECT_STYLE_THREE:
 
2901
  case VIEWER_SELECT_STYLE_FOUR:
 
2902
    {
 
2903
      nsIPresShell* shell = GetPresShell();
 
2904
      if (nsnull != shell) {
 
2905
        nsStringArray titles;
 
2906
        shell->ListAlternateStyleSheets(titles);
 
2907
        nsAutoString  title;
 
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);
 
2913
        NS_RELEASE(shell);
 
2914
      }
 
2915
    }
 
2916
    result = nsEventStatus_eConsumeNoDefault;
 
2917
    break;
 
2918
 
 
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;
 
2924
    break;
 
2925
  }
 
2926
  return result;
 
2927
}
 
2928
 
 
2929
NS_IMETHODIMP nsBrowserWindow::EnsureWebBrowserChrome()
 
2930
{
 
2931
   if(mWebBrowserChrome)
 
2932
      return NS_OK;
 
2933
 
 
2934
   mWebBrowserChrome = new nsWebBrowserChrome();
 
2935
   NS_ENSURE_TRUE(mWebBrowserChrome, NS_ERROR_OUT_OF_MEMORY);
 
2936
 
 
2937
   NS_ADDREF(mWebBrowserChrome);
 
2938
   mWebBrowserChrome->BrowserWindow(this);
 
2939
 
 
2940
   return NS_OK;
 
2941
}
 
2942
 
 
2943
nsresult nsBrowserWindow::GetWindow(nsIWidget** aWindow)
 
2944
{
 
2945
  if (aWindow && mWindow) {
 
2946
    *aWindow = mWindow.get();
 
2947
    NS_IF_ADDREF(*aWindow);
 
2948
    return NS_OK;
 
2949
  }
 
2950
  return NS_ERROR_FAILURE;
 
2951
}
 
2952