File: BrowserFrameGlue.cpp

package info (click to toggle)
iceweasel 2.0.0.19-0etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 298,784 kB
  • ctags: 317,912
  • sloc: cpp: 1,796,902; ansic: 987,677; xml: 109,036; makefile: 47,777; asm: 35,201; perl: 26,983; sh: 20,879; cs: 6,232; java: 5,513; python: 3,249; pascal: 459; lex: 306; php: 244; csh: 132; objc: 97; yacc: 79; ada: 49; awk: 14; sql: 4; sed: 4
file content (426 lines) | stat: -rw-r--r-- 12,658 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1998
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Chak Nanga <chak@netscape.com>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

// File Overview....
//
// This file has the IBrowserFrameGlueObj implementation
// This frame glue object is nested inside of the BrowserFrame
// object(See BrowserFrm.h for more info)
//
// This is the place where all the platform specific interaction
// with the browser frame window takes place in response to 
// callbacks from Gecko interface methods
// 
// The main purpose of this interface is to separate the cross 
// platform code in BrowserImpl*.cpp from the platform specific
// code(which is in this file)
//
// You'll also notice the use of a macro named "METHOD_PROLOGUE"
// through out this file. This macro essentially makes the pointer
// to a "containing" class available inside of the class which is
// being contained via a var named "pThis". In our case, the 
// BrowserFrameGlue object is contained inside of the BrowserFrame
// object so "pThis" will be a pointer to a BrowserFrame object
// Refer to MFC docs for more info on METHOD_PROLOGUE macro


#include "stdafx.h"
#include "TestEmbed.h"
#include "BrowserFrm.h"
#include "Dialogs.h"
#include "nsReadableUtils.h"

/////////////////////////////////////////////////////////////////////////////
// IBrowserFrameGlue implementation

void CBrowserFrame::BrowserFrameGlueObj::UpdateStatusBarText(const PRUnichar *aMessage)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	nsCString strStatus; 

    if(aMessage)
        strStatus.AssignWithConversion(aMessage);

    pThis->m_wndStatusBar.SetPaneText(0, strStatus.get());
}

void CBrowserFrame::BrowserFrameGlueObj::UpdateProgress(PRInt32 aCurrent, PRInt32 aMax)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

    pThis->m_wndProgressBar.SetRange32(0, aMax);
    pThis->m_wndProgressBar.SetPos(aCurrent);
}

void CBrowserFrame::BrowserFrameGlueObj::UpdateBusyState(PRBool aBusy)
{	
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	// Just notify the view of the busy state
	// There's code in there which will take care of
	// updating the STOP toolbar btn. etc

	pThis->m_wndBrowserView.UpdateBusyState(aBusy);
}

// Called from the OnLocationChange() method in the nsIWebProgressListener 
// interface implementation in CBrowserImpl to update the current URI
// Will get called after a URI is successfully loaded in the browser
// We use this info to update the URL bar's edit box
//
void CBrowserFrame::BrowserFrameGlueObj::UpdateCurrentURI(nsIURI *aLocation)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	if(aLocation)
	{
		nsCAutoString uriString; 
//		nsXPIDLCString uriString;
		aLocation->GetSpec(uriString);

		pThis->m_wndUrlBar.SetCurrentURL(uriString.get());
	}
}

void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameTitle(PRUnichar **aTitle)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	CString title;
	pThis->GetWindowText(title);

	if(!title.IsEmpty())
	{
		nsString nsTitle;
		nsTitle.AssignWithConversion(title.GetBuffer(0));

		*aTitle = ToNewUnicode(nsTitle);
	}
}

void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameTitle(const PRUnichar *aTitle)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	USES_CONVERSION;

	if(W2T(aTitle))
	{
		pThis->SetWindowText(W2T(aTitle));
	}
	else
	{
		// Use the AppName i.e. testembed as the title if we
		// do not get one from GetBrowserWindowTitle()
		//
		CString cs;
		cs.LoadString(AFX_IDS_APP_TITLE);
		pThis->SetWindowText(cs);
	}
}

void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameSize(PRInt32 aCX, PRInt32 aCY)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
	
	pThis->SetWindowPos(NULL, 0, 0, aCX, aCY, 
				SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER
			);
}

void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameSize(PRInt32 *aCX, PRInt32 *aCY)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	RECT wndRect;
	pThis->GetWindowRect(&wndRect);

	if (aCX)
		*aCX = wndRect.right - wndRect.left;

	if (aCY)
		*aCY = wndRect.bottom - wndRect.top;
}

void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePosition(PRInt32 aX, PRInt32 aY)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)	

	pThis->SetWindowPos(NULL, aX, aY, 0, 0, 
				SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
}

void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePosition(PRInt32 *aX, PRInt32 *aY)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	RECT wndRect;
	pThis->GetWindowRect(&wndRect);

	if (aX)
		*aX = wndRect.left;

	if (aY)
		*aY = wndRect.top;
}

void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePositionAndSize(PRInt32 *aX, PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	RECT wndRect;
	pThis->GetWindowRect(&wndRect);

	if (aX)
		*aX = wndRect.left;

	if (aY)
		*aY = wndRect.top;

	if (aCX)
		*aCX = wndRect.right - wndRect.left;

	if (aCY)
		*aCY = wndRect.bottom - wndRect.top;
}

void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePositionAndSize(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, PRBool fRepaint)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	pThis->SetWindowPos(NULL, aX, aY, aCX, aCY, 
				SWP_NOACTIVATE | SWP_NOZORDER);
}

void CBrowserFrame::BrowserFrameGlueObj::SetFocus()
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	pThis->SetFocus();
}

void CBrowserFrame::BrowserFrameGlueObj::FocusAvailable(PRBool *aFocusAvail)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	HWND focusWnd = GetFocus()->m_hWnd;

	if ((focusWnd == pThis->m_hWnd) || ::IsChild(pThis->m_hWnd, focusWnd))
		*aFocusAvail = PR_TRUE;
	else
		*aFocusAvail = PR_FALSE;
}

void CBrowserFrame::BrowserFrameGlueObj::ShowBrowserFrame(PRBool aShow)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	if(aShow)
	{
		pThis->ShowWindow(SW_SHOW);
		pThis->SetActiveWindow();
		pThis->UpdateWindow();
	}
	else
	{
		pThis->ShowWindow(SW_HIDE);
	}
}

void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameVisibility(PRBool *aVisible)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	// Is the current BrowserFrame the active one?
	if (GetActiveWindow()->m_hWnd != pThis->m_hWnd)
	{
		*aVisible = PR_FALSE;
		return;
	}

	// We're the active one
	//Return FALSE if we're minimized
	WINDOWPLACEMENT wpl;
	pThis->GetWindowPlacement(&wpl);

	if ((wpl.showCmd == SW_RESTORE) || (wpl.showCmd == SW_MAXIMIZE))
		*aVisible = PR_TRUE;
	else
		*aVisible = PR_FALSE;
}

PRBool CBrowserFrame::BrowserFrameGlueObj::CreateNewBrowserFrame(PRUint32 chromeMask, 
							PRInt32 x, PRInt32 y, 
							PRInt32 cx, PRInt32 cy,
							nsIWebBrowser** aWebBrowser)
{
   NS_ENSURE_ARG_POINTER(aWebBrowser);

   *aWebBrowser = nsnull;

	CTestEmbedApp *pApp = (CTestEmbedApp *)AfxGetApp();
	if(!pApp)
		return PR_FALSE;

	// Note that we're calling with the last param set to "false" i.e.
	// this instructs not to show the frame window
	// This is mainly needed when the window size is specified in the window.open()
	// JS call. In those cases Gecko calls us to create the browser with a default
	// size (all are -1) and then it calls the SizeBrowserTo() method to set
	// the proper window size. If this window were to be visible then you'll see
	// the window size changes on the screen causing an unappealing flicker
	//

	CBrowserFrame* pFrm = pApp->CreateNewBrowserFrame(chromeMask, x, y, cx, cy, PR_FALSE);
    if(!pFrm)
		return PR_FALSE;

	// At this stage we have a new CBrowserFrame and a new CBrowserView
	// objects. The CBrowserView also would have an embedded browser
	// object created. Get the mWebBrowser member from the CBrowserView
	// and return it. (See CBrowserView's CreateBrowser() on how the
	// embedded browser gets created and how it's mWebBrowser member
	// gets initialized)

	NS_IF_ADDREF(*aWebBrowser = pFrm->m_wndBrowserView.mWebBrowser);

	return PR_TRUE;
}

void CBrowserFrame::BrowserFrameGlueObj::DestroyBrowserFrame()
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	pThis->PostMessage(WM_CLOSE);
}

#define GOTO_BUILD_CTX_MENU { bContentHasFrames = FALSE; goto BUILD_CTX_MENU; }

void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode)
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)

	UINT nIDResource = IDR_CTXMENU_DOCUMENT;

	if(aContextFlags & nsIContextMenuListener::CONTEXT_DOCUMENT)
		nIDResource = IDR_CTXMENU_DOCUMENT;
	else if(aContextFlags & nsIContextMenuListener::CONTEXT_TEXT)		
		nIDResource = IDR_CTXMENU_TEXT;
	else if(aContextFlags & nsIContextMenuListener::CONTEXT_LINK)
	{
		nIDResource = IDR_CTXMENU_LINK;

		// Since we handle all the browser menu/toolbar commands
		// in the View, we basically setup the Link's URL in the
		// BrowserView object. When a menu selection in the context
		// menu is made, the appropriate command handler in the
		// BrowserView will be invoked and the value of the URL
		// will be accesible in the view
		
		// Reset the value from the last invocation
		// (A new value will be set after we determine it below)
		//
		nsAutoString strUrlUcs2;
		pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2);

		// Get the URL from the link. This is two step process
		// 1. We first get the nsIDOMHTMLAnchorElement
		// 2. We then get the URL associated with the link
		nsresult rv = NS_OK;
		nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement(do_QueryInterface(aNode, &rv));
		if(NS_FAILED(rv))
			return;

		rv = linkElement->GetHref(strUrlUcs2);
		if(NS_FAILED(rv))
			return;

		// Update the view with the new LinkUrl
		// Note that this string is in UCS2 format
		pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2);
	}
	else if(aContextFlags & nsIContextMenuListener::CONTEXT_IMAGE)
	{
		nIDResource = IDR_CTXMENU_IMAGE;

		nsAutoString strImgSrcUcs2;
		pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Clear it

		// Get the IMG SRC
		nsresult rv = NS_OK;
		nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(aNode, &rv));
		if(NS_FAILED(rv))
			return;

		rv = imgElement->GetSrc(strImgSrcUcs2);
		if(NS_FAILED(rv))
			return;

		pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Set the new Img Src
	}

	CMenu ctxMenu;
	if(ctxMenu.LoadMenu(nIDResource))
	{
		POINT cursorPos;
		GetCursorPos(&cursorPos);

		(ctxMenu.GetSubMenu(0))->TrackPopupMenu(TPM_LEFTALIGN, cursorPos.x, cursorPos.y, pThis);
	}
}

HWND CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameNativeWnd()
{
	METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
	return pThis->m_hWnd;
}

void CBrowserFrame::BrowserFrameGlueObj::ShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText)
{
    METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
    pThis->m_wndTooltip.SetTipText(CString(aTipText));
    pThis->m_wndTooltip.Show(&pThis->m_wndBrowserView, aXCoords, aYCoords);
}

void CBrowserFrame::BrowserFrameGlueObj::HideTooltip()
{
    METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
    pThis->m_wndTooltip.Hide();
}