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
5
* Copyright (c) 2002 Netscape Communications Corporation and
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:
16
* The above copyright notice and this permission notice shall be included
17
* in all copies or substantial portions of the Software.
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.
28
* Chak Nanga <chak@netscape.com>
30
* ***** END LICENSE BLOCK ***** */
33
// This is the class which implements all the interfaces
34
// required(and optional) by the mozilla embeddable browser engine
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
40
// Look at the INTERFACE_MAP_ENTRY's below for the list of
41
// the currently implemented interfaces
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.
49
// nsIWebBrowserChrome - This is a required interface to be implemented
52
// nsIEmbeddingSiteWindow - This is a required interface to be implemented
54
// - SetTitle() gets called after a document
55
// load giving us the chance to update our
58
// Some points to note...
60
// nsIWebBrowserChrome interface's SetStatus() gets called when a user
61
// mouses over the links on a page
63
// nsIWebProgressListener interface's OnStatusChange() gets called
64
// to indicate progress when a page is being loaded
66
// Next suggested file(s) to look at :
67
// Any of the BrowserImpl*.cpp files for other interface
68
// implementation details
75
#include "nsIDOMWindow.h"
76
#include "BrowserImpl.h"
78
CBrowserImpl::CBrowserImpl()
80
m_pBrowserFrameGlue = NULL;
85
CBrowserImpl::~CBrowserImpl()
89
// It's very important that the creator of this CBrowserImpl object
90
// Call on this Init() method with proper values after creation
92
NS_METHOD CBrowserImpl::Init(PBROWSERFRAMEGLUE pBrowserFrameGlue,
93
nsIWebBrowser* aWebBrowser)
95
m_pBrowserFrameGlue = pBrowserFrameGlue;
97
SetWebBrowser(aWebBrowser);
102
//*****************************************************************************
103
// CBrowserImpl::nsISupports
104
//*****************************************************************************
106
NS_IMPL_ADDREF(CBrowserImpl)
107
NS_IMPL_RELEASE(CBrowserImpl)
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)
122
//*****************************************************************************
123
// CBrowserImpl::nsIInterfaceRequestor
124
//*****************************************************************************
126
NS_IMETHODIMP CBrowserImpl::GetInterface(const nsIID &aIID, void** aInstancePtr)
128
if(aIID.Equals(NS_GET_IID(nsIDOMWindow)))
131
return mWebBrowser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
132
return NS_ERROR_NOT_INITIALIZED;
135
return QueryInterface(aIID, aInstancePtr);
138
//*****************************************************************************
139
// CBrowserImpl::nsIWebBrowserChrome
140
//*****************************************************************************
142
//Gets called when you mouseover links etc. in a web page
144
NS_IMETHODIMP CBrowserImpl::SetStatus(PRUint32 aType, const PRUnichar* aStatus)
146
if(! m_pBrowserFrameGlue)
147
return NS_ERROR_FAILURE;
149
m_pBrowserFrameGlue->UpdateStatusBarText(aStatus);
154
NS_IMETHODIMP CBrowserImpl::GetWebBrowser(nsIWebBrowser** aWebBrowser)
156
NS_ENSURE_ARG_POINTER(aWebBrowser);
158
*aWebBrowser = mWebBrowser;
160
NS_IF_ADDREF(*aWebBrowser);
165
// Currently called from Init(). I'm not sure who else
168
NS_IMETHODIMP CBrowserImpl::SetWebBrowser(nsIWebBrowser* aWebBrowser)
170
NS_ENSURE_ARG_POINTER(aWebBrowser);
172
mWebBrowser = aWebBrowser;
177
NS_IMETHODIMP CBrowserImpl::GetChromeFlags(PRUint32* aChromeMask)
179
return NS_ERROR_NOT_IMPLEMENTED;
182
NS_IMETHODIMP CBrowserImpl::SetChromeFlags(PRUint32 aChromeMask)
184
return NS_ERROR_NOT_IMPLEMENTED;
187
// Will get called in response to JavaScript window.close()
189
NS_IMETHODIMP CBrowserImpl::DestroyBrowserWindow()
191
if(! m_pBrowserFrameGlue)
192
return NS_ERROR_FAILURE;
194
m_pBrowserFrameGlue->DestroyBrowserFrame();
199
// Gets called in response to set the size of a window
200
// Ex: In response to a JavaScript Window.Open() call of
203
// window.open("http://www.mozilla.org", "theWin", "width=200, height=400");
205
// First the CreateBrowserWindow() call will be made followed by a
206
// call to this method to resize the window
208
NS_IMETHODIMP CBrowserImpl::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
210
if(! m_pBrowserFrameGlue)
211
return NS_ERROR_FAILURE;
213
HWND w = m_pBrowserFrameGlue->GetBrowserFrameNativeWnd();
215
CRect rcNewFrame(CPoint(0, 0), CSize(aCX, aCY));
219
// Adjust for 3D edge on client area
220
AdjustWindowRectEx(&rcNewFrame, WS_VISIBLE, FALSE, WS_EX_CLIENTEDGE);
222
GetClientRect(w, &rcClient);
223
GetWindowRect(w, &rcFrame);
225
rcNewFrame.right += rcFrame.Width() - rcClient.Width();
226
rcNewFrame.bottom += rcFrame.Height() - rcClient.Height();
228
m_pBrowserFrameGlue->SetBrowserFrameSize(rcNewFrame.Width(), rcNewFrame.Height());
233
NS_IMETHODIMP CBrowserImpl::ShowAsModal(void)
235
return NS_ERROR_NOT_IMPLEMENTED;
238
NS_IMETHODIMP CBrowserImpl::IsWindowModal(PRBool *retval)
246
NS_IMETHODIMP CBrowserImpl::ExitModalEventLoop(nsresult aStatus)
251
//*****************************************************************************
252
// CBrowserImpl::nsIWebBrowserChromeFocus
253
//*****************************************************************************
255
NS_IMETHODIMP CBrowserImpl::FocusNextElement()
257
return NS_ERROR_NOT_IMPLEMENTED;
260
NS_IMETHODIMP CBrowserImpl::FocusPrevElement()
262
return NS_ERROR_NOT_IMPLEMENTED;
265
//*****************************************************************************
266
// CBrowserImpl::nsIEmbeddingSiteWindow
267
//*****************************************************************************
269
NS_IMETHODIMP CBrowserImpl::SetDimensions(PRUint32 aFlags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
271
if(! m_pBrowserFrameGlue)
272
return NS_ERROR_FAILURE;
274
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
275
(aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER ||
276
aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))
278
m_pBrowserFrameGlue->SetBrowserFramePositionAndSize(x, y, cx, cy, PR_TRUE);
282
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
284
m_pBrowserFrameGlue->SetBrowserFramePosition(x, y);
286
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER ||
287
aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
289
m_pBrowserFrameGlue->SetBrowserFrameSize(cx, cy);
296
NS_IMETHODIMP CBrowserImpl::GetDimensions(PRUint32 aFlags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
298
if(! m_pBrowserFrameGlue)
299
return NS_ERROR_FAILURE;
301
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
303
m_pBrowserFrameGlue->GetBrowserFramePosition(x, y);
305
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER ||
306
aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
308
m_pBrowserFrameGlue->GetBrowserFrameSize(cx, cy);
314
NS_IMETHODIMP CBrowserImpl::GetSiteWindow(void** aSiteWindow)
317
return NS_ERROR_NULL_POINTER;
320
if (m_pBrowserFrameGlue) {
321
HWND w = m_pBrowserFrameGlue->GetBrowserFrameNativeWnd();
322
*aSiteWindow = NS_REINTERPRET_CAST(void *, w);
327
NS_IMETHODIMP CBrowserImpl::SetFocus()
329
if(! m_pBrowserFrameGlue)
330
return NS_ERROR_FAILURE;
332
m_pBrowserFrameGlue->SetFocus();
337
NS_IMETHODIMP CBrowserImpl::GetTitle(PRUnichar** aTitle)
339
if(! m_pBrowserFrameGlue)
340
return NS_ERROR_FAILURE;
342
m_pBrowserFrameGlue->GetBrowserFrameTitle(aTitle);
347
NS_IMETHODIMP CBrowserImpl::SetTitle(const PRUnichar* aTitle)
349
if(! m_pBrowserFrameGlue)
350
return NS_ERROR_FAILURE;
352
m_pBrowserFrameGlue->SetBrowserFrameTitle(aTitle);
357
NS_IMETHODIMP CBrowserImpl::GetVisibility(PRBool *aVisibility)
359
if(! m_pBrowserFrameGlue)
360
return NS_ERROR_FAILURE;
362
m_pBrowserFrameGlue->GetBrowserFrameVisibility(aVisibility);
367
NS_IMETHODIMP CBrowserImpl::SetVisibility(PRBool aVisibility)
369
if(! m_pBrowserFrameGlue)
370
return NS_ERROR_FAILURE;
372
m_pBrowserFrameGlue->ShowBrowserFrame(aVisibility);
377
//*****************************************************************************
378
// CBrowserImpl::nsIEmbeddingSiteWindow2
379
//*****************************************************************************
381
NS_IMETHODIMP CBrowserImpl::Blur()
387
//*****************************************************************************
388
// CBrowserImpl::nsITooltipListener
389
//*****************************************************************************
391
/* void onShowTooltip (in long aXCoords, in long aYCoords, in wstring aTipText); */
392
NS_IMETHODIMP CBrowserImpl::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText)
394
if(! m_pBrowserFrameGlue)
395
return NS_ERROR_FAILURE;
397
m_pBrowserFrameGlue->ShowTooltip(aXCoords, aYCoords, aTipText);
402
/* void onHideTooltip (); */
403
NS_IMETHODIMP CBrowserImpl::OnHideTooltip()
405
if(! m_pBrowserFrameGlue)
406
return NS_ERROR_FAILURE;
408
m_pBrowserFrameGlue->HideTooltip();