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

« back to all changes in this revision

Viewing changes to mozilla/embedding/tests/mfcembed/BrowserImpl.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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: Mozilla-sample-code 1.0
 
4
 *
 
5
 * Copyright (c) 2002 Netscape Communications Corporation and
 
6
 * other contributors
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person obtaining a
 
9
 * copy of this Mozilla sample software and associated documentation files
 
10
 * (the "Software"), to deal in the Software without restriction, including
 
11
 * without limitation the rights to use, copy, modify, merge, publish,
 
12
 * distribute, sublicense, and/or sell copies of the Software, and to permit
 
13
 * persons to whom the Software is furnished to do so, subject to the
 
14
 * following conditions:
 
15
 *
 
16
 * The above copyright notice and this permission notice shall be included
 
17
 * in all copies or substantial portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
20
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
22
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
25
 * DEALINGS IN THE SOFTWARE.
 
26
 *
 
27
 * Contributor(s):
 
28
 *   Chak Nanga <chak@netscape.com> 
 
29
 *
 
30
 * ***** END LICENSE BLOCK ***** */
 
31
 
 
32
// File Overview....
 
33
// This is the class which implements all the interfaces
 
34
// required(and optional) by the mozilla embeddable browser engine
 
35
//
 
36
// Note that this obj gets passed in the IBrowserFrameGlue* using the 
 
37
// Init() method. Many of the interface implementations use this
 
38
// to get the actual task done. Ex: to update the status bar
 
39
//
 
40
// Look at the INTERFACE_MAP_ENTRY's below for the list of 
 
41
// the currently implemented interfaces
 
42
//
 
43
// This file currently has the implementation for all the interfaces
 
44
// which are required of an app embedding Gecko
 
45
// Implementation of other optional interfaces are in separate files
 
46
// to avoid cluttering this one and to demonstrate other embedding
 
47
// principles. For example, nsIPrompt is implemented in a separate DLL.
 
48
// 
 
49
//    nsIWebBrowserChrome    - This is a required interface to be implemented
 
50
//                          by embeddors
 
51
//
 
52
//    nsIEmbeddingSiteWindow - This is a required interface to be implemented
 
53
//                         by embedders            
 
54
//                       - SetTitle() gets called after a document
 
55
//                         load giving us the chance to update our
 
56
//                         titlebar
 
57
//
 
58
// Some points to note...
 
59
//
 
60
// nsIWebBrowserChrome interface's SetStatus() gets called when a user 
 
61
// mouses over the links on a page
 
62
//
 
63
// nsIWebProgressListener interface's OnStatusChange() gets called
 
64
// to indicate progress when a page is being loaded
 
65
//
 
66
// Next suggested file(s) to look at : 
 
67
//            Any of the BrowserImpl*.cpp files for other interface
 
68
//            implementation details
 
69
//
 
70
 
 
71
#ifdef _WINDOWS
 
72
  #include "stdafx.h"
 
73
#endif
 
74
 
 
75
#include "nsIDOMWindow.h"
 
76
#include "BrowserImpl.h"
 
77
 
 
78
CBrowserImpl::CBrowserImpl()
 
79
{
 
80
  m_pBrowserFrameGlue = NULL;
 
81
  mWebBrowser = nsnull;
 
82
}
 
83
 
 
84
 
 
85
CBrowserImpl::~CBrowserImpl()
 
86
{
 
87
}
 
88
 
 
89
// It's very important that the creator of this CBrowserImpl object
 
90
// Call on this Init() method with proper values after creation
 
91
//
 
92
NS_METHOD CBrowserImpl::Init(PBROWSERFRAMEGLUE pBrowserFrameGlue, 
 
93
                             nsIWebBrowser* aWebBrowser)
 
94
{
 
95
      m_pBrowserFrameGlue = pBrowserFrameGlue;
 
96
      
 
97
      SetWebBrowser(aWebBrowser);
 
98
 
 
99
      return NS_OK;
 
100
}
 
101
 
 
102
//*****************************************************************************
 
103
// CBrowserImpl::nsISupports
 
104
//*****************************************************************************   
 
105
 
 
106
NS_IMPL_ADDREF(CBrowserImpl)
 
107
NS_IMPL_RELEASE(CBrowserImpl)
 
108
 
 
109
NS_INTERFACE_MAP_BEGIN(CBrowserImpl)
 
110
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
 
111
   NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
 
112
   NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
 
113
   NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus)
 
114
   NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
 
115
   NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow2)
 
116
   NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
 
117
   NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener2)
 
118
   NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
 
119
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 
120
NS_INTERFACE_MAP_END
 
121
 
 
122
//*****************************************************************************
 
123
// CBrowserImpl::nsIInterfaceRequestor
 
124
//*****************************************************************************   
 
125
 
 
126
NS_IMETHODIMP CBrowserImpl::GetInterface(const nsIID &aIID, void** aInstancePtr)
 
127
{
 
128
    if(aIID.Equals(NS_GET_IID(nsIDOMWindow)))
 
129
    {
 
130
        if (mWebBrowser)
 
131
            return mWebBrowser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
 
132
        return NS_ERROR_NOT_INITIALIZED;
 
133
    }
 
134
 
 
135
    return QueryInterface(aIID, aInstancePtr);
 
136
}
 
137
 
 
138
//*****************************************************************************
 
139
// CBrowserImpl::nsIWebBrowserChrome
 
140
//*****************************************************************************   
 
141
 
 
142
//Gets called when you mouseover links etc. in a web page
 
143
//
 
144
NS_IMETHODIMP CBrowserImpl::SetStatus(PRUint32 aType, const PRUnichar* aStatus)
 
145
{
 
146
    if(! m_pBrowserFrameGlue)
 
147
        return NS_ERROR_FAILURE;
 
148
 
 
149
    m_pBrowserFrameGlue->UpdateStatusBarText(aStatus);
 
150
 
 
151
    return NS_OK;
 
152
}
 
153
 
 
154
NS_IMETHODIMP CBrowserImpl::GetWebBrowser(nsIWebBrowser** aWebBrowser)
 
155
{
 
156
   NS_ENSURE_ARG_POINTER(aWebBrowser);
 
157
 
 
158
   *aWebBrowser = mWebBrowser;
 
159
 
 
160
   NS_IF_ADDREF(*aWebBrowser);
 
161
 
 
162
   return NS_OK;
 
163
}
 
164
 
 
165
// Currently called from Init(). I'm not sure who else
 
166
// calls this
 
167
//
 
168
NS_IMETHODIMP CBrowserImpl::SetWebBrowser(nsIWebBrowser* aWebBrowser)
 
169
{
 
170
   NS_ENSURE_ARG_POINTER(aWebBrowser);
 
171
 
 
172
   mWebBrowser = aWebBrowser;
 
173
 
 
174
   return NS_OK;
 
175
}
 
176
 
 
177
NS_IMETHODIMP CBrowserImpl::GetChromeFlags(PRUint32* aChromeMask)
 
178
{
 
179
   return NS_ERROR_NOT_IMPLEMENTED;
 
180
}
 
181
 
 
182
NS_IMETHODIMP CBrowserImpl::SetChromeFlags(PRUint32 aChromeMask)
 
183
{
 
184
   return NS_ERROR_NOT_IMPLEMENTED;
 
185
}
 
186
 
 
187
// Will get called in response to JavaScript window.close()
 
188
//
 
189
NS_IMETHODIMP CBrowserImpl::DestroyBrowserWindow()
 
190
{
 
191
    if(! m_pBrowserFrameGlue)
 
192
        return NS_ERROR_FAILURE;
 
193
 
 
194
    m_pBrowserFrameGlue->DestroyBrowserFrame();
 
195
 
 
196
    return NS_OK;
 
197
}
 
198
 
 
199
// Gets called in response to set the size of a window
 
200
// Ex: In response to a JavaScript Window.Open() call of
 
201
// the form 
 
202
//
 
203
//        window.open("http://www.mozilla.org", "theWin", "width=200, height=400");
 
204
//
 
205
// First the CreateBrowserWindow() call will be made followed by a 
 
206
// call to this method to resize the window
 
207
//
 
208
NS_IMETHODIMP CBrowserImpl::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
 
209
{
 
210
    if(! m_pBrowserFrameGlue)
 
211
        return NS_ERROR_FAILURE;
 
212
 
 
213
    HWND w = m_pBrowserFrameGlue->GetBrowserFrameNativeWnd();
 
214
 
 
215
    CRect rcNewFrame(CPoint(0, 0), CSize(aCX, aCY));
 
216
    CRect rcFrame;
 
217
    CRect rcClient;
 
218
 
 
219
    // Adjust for 3D edge on client area
 
220
    AdjustWindowRectEx(&rcNewFrame, WS_VISIBLE, FALSE, WS_EX_CLIENTEDGE);
 
221
 
 
222
    GetClientRect(w, &rcClient);
 
223
    GetWindowRect(w, &rcFrame);
 
224
 
 
225
    rcNewFrame.right += rcFrame.Width() - rcClient.Width();
 
226
    rcNewFrame.bottom += rcFrame.Height() - rcClient.Height();
 
227
 
 
228
    m_pBrowserFrameGlue->SetBrowserFrameSize(rcNewFrame.Width(), rcNewFrame.Height());
 
229
 
 
230
    return NS_OK;
 
231
}
 
232
 
 
233
NS_IMETHODIMP CBrowserImpl::ShowAsModal(void)
 
234
{
 
235
   return NS_ERROR_NOT_IMPLEMENTED;
 
236
}
 
237
 
 
238
NS_IMETHODIMP CBrowserImpl::IsWindowModal(PRBool *retval)
 
239
{
 
240
  // We're not modal
 
241
  *retval = PR_FALSE;
 
242
 
 
243
  return NS_OK;
 
244
}
 
245
 
 
246
NS_IMETHODIMP CBrowserImpl::ExitModalEventLoop(nsresult aStatus)
 
247
{
 
248
  return NS_OK;
 
249
}
 
250
 
 
251
//*****************************************************************************
 
252
// CBrowserImpl::nsIWebBrowserChromeFocus
 
253
//*****************************************************************************
 
254
 
 
255
NS_IMETHODIMP CBrowserImpl::FocusNextElement()
 
256
{
 
257
    return NS_ERROR_NOT_IMPLEMENTED;
 
258
}
 
259
 
 
260
NS_IMETHODIMP CBrowserImpl::FocusPrevElement()
 
261
{
 
262
    return NS_ERROR_NOT_IMPLEMENTED;
 
263
}
 
264
 
 
265
//*****************************************************************************
 
266
// CBrowserImpl::nsIEmbeddingSiteWindow
 
267
//*****************************************************************************   
 
268
 
 
269
NS_IMETHODIMP CBrowserImpl::SetDimensions(PRUint32 aFlags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
 
270
{
 
271
    if(! m_pBrowserFrameGlue)
 
272
        return NS_ERROR_FAILURE;
 
273
 
 
274
    if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
 
275
        (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER || 
 
276
         aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))
 
277
    {
 
278
        m_pBrowserFrameGlue->SetBrowserFramePositionAndSize(x, y, cx, cy, PR_TRUE);
 
279
    }
 
280
    else
 
281
    {
 
282
        if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
 
283
        {
 
284
            m_pBrowserFrameGlue->SetBrowserFramePosition(x, y);
 
285
        }
 
286
        if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER || 
 
287
            aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
 
288
        {
 
289
            m_pBrowserFrameGlue->SetBrowserFrameSize(cx, cy);
 
290
        }
 
291
    }
 
292
 
 
293
    return NS_OK;
 
294
}
 
295
 
 
296
NS_IMETHODIMP CBrowserImpl::GetDimensions(PRUint32 aFlags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
 
297
{
 
298
    if(! m_pBrowserFrameGlue)
 
299
        return NS_ERROR_FAILURE;
 
300
    
 
301
    if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
 
302
    {
 
303
        m_pBrowserFrameGlue->GetBrowserFramePosition(x, y);
 
304
    }
 
305
    if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER || 
 
306
        aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
 
307
    {
 
308
        m_pBrowserFrameGlue->GetBrowserFrameSize(cx, cy);
 
309
    }
 
310
 
 
311
    return NS_OK;
 
312
}
 
313
 
 
314
NS_IMETHODIMP CBrowserImpl::GetSiteWindow(void** aSiteWindow)
 
315
{
 
316
  if (!aSiteWindow)
 
317
    return NS_ERROR_NULL_POINTER;
 
318
 
 
319
  *aSiteWindow = 0;
 
320
  if (m_pBrowserFrameGlue) {
 
321
    HWND w = m_pBrowserFrameGlue->GetBrowserFrameNativeWnd();
 
322
    *aSiteWindow = NS_REINTERPRET_CAST(void *, w);
 
323
  }
 
324
  return NS_OK;
 
325
}
 
326
 
 
327
NS_IMETHODIMP CBrowserImpl::SetFocus()
 
328
{
 
329
    if(! m_pBrowserFrameGlue)
 
330
        return NS_ERROR_FAILURE;
 
331
 
 
332
    m_pBrowserFrameGlue->SetFocus();
 
333
 
 
334
    return NS_OK;
 
335
}
 
336
 
 
337
NS_IMETHODIMP CBrowserImpl::GetTitle(PRUnichar** aTitle)
 
338
{
 
339
    if(! m_pBrowserFrameGlue)
 
340
        return NS_ERROR_FAILURE;
 
341
 
 
342
    m_pBrowserFrameGlue->GetBrowserFrameTitle(aTitle);
 
343
    
 
344
    return NS_OK;
 
345
}
 
346
 
 
347
NS_IMETHODIMP CBrowserImpl::SetTitle(const PRUnichar* aTitle)
 
348
{
 
349
    if(! m_pBrowserFrameGlue)
 
350
        return NS_ERROR_FAILURE;
 
351
 
 
352
    m_pBrowserFrameGlue->SetBrowserFrameTitle(aTitle);
 
353
    
 
354
    return NS_OK;
 
355
}
 
356
 
 
357
NS_IMETHODIMP CBrowserImpl::GetVisibility(PRBool *aVisibility)
 
358
{
 
359
    if(! m_pBrowserFrameGlue)
 
360
        return NS_ERROR_FAILURE;
 
361
 
 
362
    m_pBrowserFrameGlue->GetBrowserFrameVisibility(aVisibility);
 
363
 
 
364
    return NS_OK;
 
365
}
 
366
 
 
367
NS_IMETHODIMP CBrowserImpl::SetVisibility(PRBool aVisibility)
 
368
{
 
369
    if(! m_pBrowserFrameGlue)
 
370
        return NS_ERROR_FAILURE;
 
371
 
 
372
    m_pBrowserFrameGlue->ShowBrowserFrame(aVisibility);
 
373
 
 
374
    return NS_OK;
 
375
}
 
376
 
 
377
//*****************************************************************************
 
378
// CBrowserImpl::nsIEmbeddingSiteWindow2
 
379
//*****************************************************************************   
 
380
 
 
381
NS_IMETHODIMP CBrowserImpl::Blur()
 
382
{
 
383
    return NS_OK;
 
384
}
 
385
 
 
386
 
 
387
//*****************************************************************************
 
388
// CBrowserImpl::nsITooltipListener
 
389
//*****************************************************************************   
 
390
 
 
391
/* void onShowTooltip (in long aXCoords, in long aYCoords, in wstring aTipText); */
 
392
NS_IMETHODIMP CBrowserImpl::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText)
 
393
{
 
394
    if(! m_pBrowserFrameGlue)
 
395
        return NS_ERROR_FAILURE;
 
396
 
 
397
    m_pBrowserFrameGlue->ShowTooltip(aXCoords, aYCoords, aTipText);
 
398
 
 
399
    return NS_OK;
 
400
}
 
401
 
 
402
/* void onHideTooltip (); */
 
403
NS_IMETHODIMP CBrowserImpl::OnHideTooltip()
 
404
{
 
405
    if(! m_pBrowserFrameGlue)
 
406
        return NS_ERROR_FAILURE;
 
407
 
 
408
    m_pBrowserFrameGlue->HideTooltip();
 
409
 
 
410
    return NS_OK;
 
411
}