source: pkg/viola/main/xulrunner/branches/upstream/current/embedding/browser/gtk/src/EmbedContextMenuInfo.cpp @ 4022

Revision 4022, 19.7 KB checked in by alanbach-guest, 6 years ago (diff)

[svn-inject] Installing original source of xulrunner

Line 
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
3/*
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 *
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
16 *
17 * The Original Code is mozilla.org code.
18 *
19 * The Initial Developer of the Original Code is
20 * Oleg Romashin.
21 * Portions created by the Initial Developer are Copyright (C) 2006
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s):
25 *   Oleg Romashin <romaxa@gmail.com>
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40#include "EmbedContextMenuInfo.h"
41#include "nsIImageLoadingContent.h"
42#include "imgILoader.h"
43#include "nsIDOMDocument.h"
44#include "nsIDOMHTMLDocument.h"
45#include "nsIDOMHTMLElement.h"
46#include "nsIDOMHTMLHtmlElement.h"
47#include "nsIDOMHTMLAnchorElement.h"
48#include "nsIDOMHTMLImageElement.h"
49#include "nsIDOMHTMLAreaElement.h"
50#include "nsIDOMHTMLLinkElement.h"
51#include "nsIDOMDocumentView.h"
52#include "nsIDOMAbstractView.h"
53#include "nsIDOMViewCSS.h"
54#include "nsIDOMCSSStyleDeclaration.h"
55#include "nsIDOMCSSValue.h"
56#include "nsIDOMCSSPrimitiveValue.h"
57#include "nsNetUtil.h"
58#include "nsUnicharUtils.h"
59#include "nsIDOMMouseEvent.h"
60#include "nsIDOMNSEvent.h"
61#include "nsIDOMWindow.h"
62#include "nsIDOMWindowCollection.h"
63#include "nsIWebBrowser.h"
64#include "nsIDOM3Document.h"
65#include "nsIContent.h"
66#include "nsIPresShell.h"
67#include "nsIFormControl.h"
68#include "nsIDOMNSHTMLInputElement.h"
69#include "nsIDOMNSHTMLTextAreaElement.h"
70#include "nsIDOMHTMLInputElement.h"
71#include "nsIDOMHTMLTextAreaElement.h"
72#include "nsIDOMNSHTMLDocument.h"
73#include "nsIDOMNodeList.h"
74#include "nsISelection.h"
75#include "nsIDocument.h"
76#include "EmbedPrivate.h"
77#include <stdio.h>
78#include <stdarg.h>
79#include <stdlib.h>
80#include <glib.h>
81#if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
82#include "nsIFrame.h"
83#endif
84
85//*****************************************************************************
86// class EmbedContextMenuInfo
87//*****************************************************************************
88EmbedContextMenuInfo::EmbedContextMenuInfo(EmbedPrivate *aOwner) : mCtxFrameNum(-1), mEmbedCtxType(0)
89{
90  mOwner = aOwner;
91  mEventNode = nsnull;
92  mCtxDocument = nsnull;
93  mNSHHTMLElement = nsnull;
94  mNSHHTMLElementSc = nsnull;
95  mCtxEvent = nsnull;
96  mEventNode = nsnull;
97  mFormRect = nsRect(0,0,0,0);
98}
99
100EmbedContextMenuInfo::~EmbedContextMenuInfo(void)
101{
102  mEventNode = nsnull;
103  mCtxDocument = nsnull;
104  mNSHHTMLElement = nsnull;
105  mNSHHTMLElementSc = nsnull;
106  mCtxEvent = nsnull;
107  mEventNode = nsnull;
108}
109
110NS_IMPL_ADDREF(EmbedContextMenuInfo)
111NS_IMPL_RELEASE(EmbedContextMenuInfo)
112NS_INTERFACE_MAP_BEGIN(EmbedContextMenuInfo)
113NS_INTERFACE_MAP_ENTRY(nsISupports)
114NS_INTERFACE_MAP_END
115
116nsresult
117EmbedContextMenuInfo::SetFrameIndex()
118{
119  nsCOMPtr<nsIDOMWindowCollection> frames;
120  mCtxDomWindow->GetFrames(getter_AddRefs(frames));
121  nsCOMPtr<nsIDOMWindow> currentWindow;
122  PRUint32 frameCount = 0;
123  frames->GetLength(&frameCount);
124  for (unsigned int i= 0; i < frameCount; i++) {
125    frames->Item(i, getter_AddRefs(currentWindow));
126    nsCOMPtr<nsIDOMDocument> currentDoc;
127    currentWindow->GetDocument(getter_AddRefs(currentDoc));
128    if (currentDoc == mCtxDocument) {
129      mCtxFrameNum = i;
130      mCtxDomWindow = currentWindow;
131      nsCOMPtr<nsIDocument> doc = do_QueryInterface(currentDoc);
132      if (doc)
133        mCtxDocTitle = doc->GetDocumentTitle();
134      return NS_OK;
135    }
136  }
137  return NS_ERROR_FAILURE;
138}
139
140nsresult
141EmbedContextMenuInfo::GetFormControlType(nsIDOMEvent* aEvent)
142{
143  if (!aEvent)
144    return NS_OK;
145  nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
146  nsCOMPtr<nsIDOMEventTarget> target;
147  nsevent->GetOriginalTarget(getter_AddRefs(target));
148  //    mOrigTarget  = target;
149  if (SetFormControlType(target)) {
150    nsCOMPtr<nsIDOMNode> eventNode = do_QueryInterface(target);
151    if (!eventNode)
152      return NS_OK;
153    //Frame Stuff
154    nsCOMPtr<nsIDOMDocument> domDoc;
155    nsresult rv = eventNode->GetOwnerDocument(getter_AddRefs(domDoc));
156    if (!NS_SUCCEEDED(rv) || !domDoc) {
157      return NS_OK;
158    }
159    mEventNode = eventNode;
160    mCtxDocument = domDoc;
161    nsCOMPtr<nsIDocument> doc = do_QueryInterface(mCtxDocument);
162    if (!doc)
163      return NS_OK;
164    nsIPresShell *presShell = doc->GetPrimaryShell();
165    if (!presShell)
166      return NS_OK;
167    nsCOMPtr<nsIContent> tgContent = do_QueryInterface(mEventTarget);
168        nsIFrame* frame = nsnull;
169#if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
170#ifdef MOZILLA_1_8_BRANCH
171    presShell->GetPrimaryFrameFor(tgContent, &frame);
172#else
173    frame = presShell->GetPrimaryFrameFor(tgContent);
174#endif
175    if (frame)
176      mFormRect = frame->GetScreenRectExternal();
177#endif
178    return NS_OK;
179  }
180  return NS_ERROR_FAILURE;
181}
182
183nsresult
184EmbedContextMenuInfo::SetFormControlType(nsIDOMEventTarget *originalTarget)
185{
186  nsresult rv = NS_ERROR_FAILURE;
187  nsCOMPtr<nsIContent> targetContent = do_QueryInterface(originalTarget);
188  mCtxFormType = 0;
189#ifdef MOZILLA_1_8_BRANCH
190  if (targetContent && targetContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) {
191#else
192  if (targetContent && targetContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL)) {
193#endif
194    nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(targetContent));
195    if (formControl) {
196      mCtxFormType = formControl->GetType();
197      rv = NS_OK;
198      //#ifdef MOZ_LOGGING
199      switch (mCtxFormType) {
200      case NS_FORM_BUTTON_BUTTON:
201        break;
202      case NS_FORM_BUTTON_RESET:
203        break;
204      case NS_FORM_BUTTON_SUBMIT:
205        break;
206      case NS_FORM_INPUT_BUTTON:
207        break;
208      case NS_FORM_INPUT_CHECKBOX:
209        break;
210      case NS_FORM_INPUT_FILE:
211        mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
212        break;
213      case NS_FORM_INPUT_HIDDEN:
214        break;
215      case NS_FORM_INPUT_RESET:
216        break;
217      case NS_FORM_INPUT_IMAGE:
218        break;
219      case NS_FORM_INPUT_PASSWORD:
220        mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
221        mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IPASSWORD;
222        break;
223      case NS_FORM_INPUT_RADIO:
224        break;
225      case NS_FORM_INPUT_SUBMIT:
226        break;
227      case NS_FORM_INPUT_TEXT:
228        mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
229        break;
230      case NS_FORM_LABEL:
231        break;
232      case NS_FORM_OPTION:
233        break;
234      case NS_FORM_OPTGROUP:
235        break;
236      case NS_FORM_LEGEND:
237        break;
238      case NS_FORM_SELECT:
239        break;
240      case NS_FORM_TEXTAREA:
241        mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
242        break;
243      case NS_FORM_OBJECT:
244        break;
245      default:
246        break;
247      }
248      if (mEmbedCtxType & GTK_MOZ_EMBED_CTX_INPUT) {
249        PRBool rdonly = PR_FALSE;
250        if (mCtxFormType == NS_FORM_TEXTAREA) {
251          nsCOMPtr<nsIDOMHTMLTextAreaElement> input;
252          input = do_QueryInterface(mEventNode, &rv);
253          if (!NS_FAILED(rv) && input)
254            rv = input->GetReadOnly(&rdonly);
255          if (!NS_FAILED(rv) && rdonly) {
256            mEmbedCtxType |= GTK_MOZ_EMBED_CTX_ROINPUT;
257          }
258        } else {
259          nsCOMPtr<nsIDOMHTMLInputElement> input;
260          input = do_QueryInterface(mEventNode, &rv);
261          if (!NS_FAILED(rv) && input)
262            rv = input->GetReadOnly(&rdonly);
263          if (!NS_FAILED(rv) && rdonly) {
264            mEmbedCtxType |= GTK_MOZ_EMBED_CTX_ROINPUT;
265          }
266        }
267      }
268      //#endif
269    }
270  }
271  return rv;
272}
273
274const char*
275EmbedContextMenuInfo::GetSelectedText()
276{
277  nsString cString;
278  nsresult rv = NS_ERROR_FAILURE;
279  if (mCtxFormType != 0 && mEventNode) {
280    PRInt32 TextLength = 0, selStart = 0, selEnd = 0;
281    if (mCtxFormType == NS_FORM_INPUT_TEXT || mCtxFormType == NS_FORM_INPUT_FILE) {
282      nsCOMPtr<nsIDOMNSHTMLInputElement> nsinput = do_QueryInterface(mEventNode, &rv);
283      if (NS_SUCCEEDED(rv) && nsinput)
284        nsinput->GetTextLength(&TextLength);
285      if (TextLength > 0) {
286        nsinput->GetSelectionEnd(&selEnd);
287        nsinput->GetSelectionStart(&selStart);
288        if (selStart < selEnd || mCtxFormType == NS_FORM_INPUT_FILE) {
289          nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(mEventNode, &rv);
290          rv = input->GetValue(cString);
291        }
292      }
293    } else if (mCtxFormType == NS_FORM_TEXTAREA) {
294      nsCOMPtr<nsIDOMNSHTMLTextAreaElement> nsinput = do_QueryInterface(mEventNode, &rv);
295      if (NS_SUCCEEDED(rv) && nsinput)
296        nsinput->GetTextLength(&TextLength);
297      if (TextLength > 0) {
298        nsinput->GetSelectionStart(&selStart);
299        nsinput->GetSelectionEnd(&selEnd);
300        if (selStart < selEnd) {
301          nsCOMPtr<nsIDOMHTMLTextAreaElement> input = do_QueryInterface(mEventNode, &rv);
302          rv = input->GetValue(cString);
303        }
304      }
305    }
306    if (NS_SUCCEEDED(rv) && !cString.IsEmpty()) {
307      if (selStart < selEnd) {
308        cString.Cut(0, selStart);
309        cString.Cut(selEnd-selStart, TextLength);
310      }
311      rv = NS_OK;
312    }
313  } else if (mCtxDocument) {
314    nsCOMPtr<nsIDOMNSHTMLDocument> htmlDoc = do_QueryInterface(mCtxDocument, &rv);
315    if (NS_FAILED(rv) || !htmlDoc)
316      return nsnull;
317    rv = htmlDoc->GetSelection(cString);
318    if (NS_FAILED(rv) || cString.IsEmpty())
319      return nsnull;
320    rv = NS_OK;
321  }
322  if (rv == NS_OK) {
323    return NS_ConvertUTF16toUTF8(cString).get();
324  }
325  return nsnull;
326}
327
328nsresult
329EmbedContextMenuInfo::CheckDomImageElement(nsIDOMNode *node, nsString& aHref,
330                                           PRInt32 *aWidth, PRInt32 *aHeight)
331{
332  nsresult rv = NS_ERROR_FAILURE;
333  nsCOMPtr<nsIDOMHTMLImageElement> image =
334    do_QueryInterface(node, &rv);
335  if (image) {
336    rv = image->GetSrc(aHref);
337    if (NS_FAILED(rv)) {
338      return rv;
339    }
340    rv = image->GetWidth(aWidth);
341    rv = image->GetHeight(aHeight);
342    rv = NS_OK;
343  }
344  return rv;
345}
346
347nsresult
348EmbedContextMenuInfo::GetImageRequest(imgIRequest **aRequest, nsIDOMNode *aDOMNode)
349{
350  NS_ENSURE_ARG(aDOMNode);
351  NS_ENSURE_ARG_POINTER(aRequest);
352
353  // Get content
354  nsCOMPtr<nsIImageLoadingContent> content(do_QueryInterface(aDOMNode));
355  NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
356
357  return content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
358                             aRequest);
359}
360
361nsresult
362EmbedContextMenuInfo::CheckDomHtmlNode(nsIDOMNode *aNode)
363{
364  nsresult rv = NS_ERROR_FAILURE;
365  nsString uTag;
366  PRUint16 dnode_type;
367
368  nsCOMPtr<nsIDOMNode> node;
369  if (!aNode && mEventNode)
370    node = mEventNode;
371  nsCOMPtr<nsIDOMHTMLElement> element  = do_QueryInterface(node, &rv);
372  if (!element) {
373    element = do_QueryInterface(mOrigNode, &rv);
374    if (element) {
375      node = mOrigNode;
376      element  = do_QueryInterface(node, &rv);
377    }
378  }
379
380  rv = node->GetNodeType(&dnode_type);
381  if (NS_FAILED(rv)) {
382    return rv;
383  }
384
385  if (!((nsIDOMNode::ELEMENT_NODE == dnode_type) && element)) {
386    return rv;
387  }
388  nsCOMPtr<nsIDOMNSHTMLElement> nodeElement = do_QueryInterface(node, &rv);
389  if (NS_SUCCEEDED(rv) && nodeElement) {
390    mNSHHTMLElement = nodeElement;
391  } else {
392    mNSHHTMLElement = nsnull;
393  }
394  rv = element->GetLocalName(uTag);
395  if (NS_FAILED(rv)) {
396    return rv;
397  }
398  if (uTag.LowerCaseEqualsLiteral("object")) {
399  }
400  else if (uTag.LowerCaseEqualsLiteral("html")) {
401  }
402  else if (uTag.LowerCaseEqualsLiteral("a")) {
403    nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(node);
404    anchor->GetHref(mCtxHref);
405    mEmbedCtxType |= GTK_MOZ_EMBED_CTX_LINK;
406    if (anchor && !mCtxHref.IsEmpty()) {
407      if (mCtxHref.LowerCaseEqualsLiteral("text/smartbookmark")) {
408        nsCOMPtr<nsIDOMNode> childNode;
409        node->GetFirstChild(getter_AddRefs(childNode));
410        if (childNode) {
411          PRInt32 width, height;
412          rv = CheckDomImageElement(node, mCtxImgHref, &width, &height);
413          if (NS_SUCCEEDED(rv))
414            mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IMAGE;
415        }
416      } else if (StringBeginsWith(mCtxHref, NS_LITERAL_STRING("mailto:"))) {
417        mEmbedCtxType |= GTK_MOZ_EMBED_CTX_EMAIL;
418      }
419    }
420  }
421  else if (uTag.LowerCaseEqualsLiteral("area")) {
422    nsCOMPtr<nsIDOMHTMLAreaElement> area = do_QueryInterface(node, &rv);
423    if (NS_SUCCEEDED(rv) && area) {
424      PRBool aNoHref = PR_FALSE;
425      rv = area->GetNoHref(&aNoHref);
426      if (aNoHref == PR_FALSE)
427        rv = area->GetHref(mCtxHref);
428      else
429        rv = area->GetTarget(mCtxHref);
430      mEmbedCtxType |= GTK_MOZ_EMBED_CTX_LINK;
431      rv = NS_OK;
432    }
433  }
434  else if (uTag.LowerCaseEqualsLiteral("img")) {
435    PRInt32 width, height;
436    rv = CheckDomImageElement(node, mCtxImgHref, &width, &height);
437    if (NS_SUCCEEDED(rv))
438      mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IMAGE;
439  } else {
440    rv = NS_ERROR_FAILURE;
441  }
442  return rv;
443}
444
445nsresult
446EmbedContextMenuInfo::UpdateContextData(void *aEvent)
447{
448  NS_ENSURE_ARG_POINTER(aEvent);
449  nsresult rv;
450  nsCOMPtr<nsIDOMEvent> event = do_QueryInterface((nsISupports*)aEvent, &rv);
451  if (NS_FAILED(rv) || !event)
452    return NS_ERROR_FAILURE;
453  return UpdateContextData(event);
454}
455
456nsresult
457EmbedContextMenuInfo::GetElementForScroll(nsIDOMEvent *aEvent)
458{
459  if (!aEvent) return NS_ERROR_UNEXPECTED;
460  nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
461  nsCOMPtr<nsIDOMEventTarget> target;
462  nsevent->GetOriginalTarget(getter_AddRefs(target));
463  if (!target) return NS_ERROR_UNEXPECTED;
464  nsCOMPtr<nsIDOMNode> targetDOMNode(do_QueryInterface(target));
465  if (!targetDOMNode) return NS_ERROR_UNEXPECTED;
466  nsCOMPtr<nsIDOMDocument> targetDOMDocument;
467  targetDOMNode->GetOwnerDocument(getter_AddRefs(targetDOMDocument));
468  if (!targetDOMDocument) return NS_ERROR_UNEXPECTED;
469  return GetElementForScroll(targetDOMDocument);
470}
471
472nsresult
473EmbedContextMenuInfo::GetElementForScroll(nsIDOMDocument *targetDOMDocument)
474{
475  nsCOMPtr<nsIDOMElement> targetDOMElement;
476  targetDOMDocument->GetDocumentElement(getter_AddRefs(targetDOMElement));
477  if (!targetDOMElement) return NS_ERROR_UNEXPECTED;
478  nsString bodyName(NS_LITERAL_STRING("body"));
479  nsCOMPtr<nsIDOMNodeList> bodyList;
480  targetDOMElement->GetElementsByTagName(bodyName, getter_AddRefs(bodyList));
481  PRUint32 i = 0;
482  bodyList->GetLength(&i);
483  if (i) {
484    nsCOMPtr<nsIDOMNode> domBodyNode;
485    bodyList->Item(0, getter_AddRefs(domBodyNode));
486    if (!domBodyNode) return NS_ERROR_UNEXPECTED;
487    mNSHHTMLElementSc = do_QueryInterface(domBodyNode);
488    if (!mNSHHTMLElementSc) return NS_ERROR_UNEXPECTED;
489  }
490  return NS_OK;
491}
492
493nsresult
494EmbedContextMenuInfo::UpdateContextData(nsIDOMEvent *aDOMEvent)
495{
496  if (mCtxEvent == aDOMEvent)
497    return NS_OK;
498
499  nsresult rv = nsnull;
500  mCtxEvent = aDOMEvent;
501  NS_ENSURE_ARG_POINTER(mCtxEvent);
502
503  PRUint16 eventphase;
504  mCtxEvent->GetEventPhase(&eventphase);
505  if (!eventphase) {
506    mCtxEvent = nsnull;
507    return NS_ERROR_FAILURE;
508  }
509
510  nsCOMPtr<nsIDOMEventTarget> originalTarget = nsnull;
511  nsCOMPtr<nsIDOMNode> originalNode = nsnull;
512
513  nsCOMPtr<nsIDOMNSEvent> aEvent = do_QueryInterface(mCtxEvent, &rv);
514  if (NS_FAILED(rv) || !aEvent)
515    return NS_OK;
516
517  nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(mCtxEvent, &rv));
518  if (mouseEvent) {
519    ((nsIDOMMouseEvent*)mouseEvent)->GetClientX(&mX);
520    ((nsIDOMMouseEvent*)mouseEvent)->GetClientY(&mY);
521  }
522
523  if (aEvent)
524    rv = aEvent->GetOriginalTarget(getter_AddRefs(originalTarget));
525  originalNode = do_QueryInterface(originalTarget);
526  if (NS_FAILED(rv) || !originalNode)
527    return NS_ERROR_NULL_POINTER;
528
529  //    nsresult SelText = mOwner->ClipBoardAction(GTK_MOZ_EMBED_CAN_COPY);
530  if (originalNode == mOrigNode)
531    return NS_OK;
532
533  mEmbedCtxType = GTK_MOZ_EMBED_CTX_NONE;
534  mOrigNode = originalNode;
535  if (mOrigNode) {
536    nsString SOrigNode;
537    mOrigNode->GetNodeName(SOrigNode);
538    if (SOrigNode.EqualsLiteral("#document"))
539      return NS_OK;
540    if (SOrigNode.EqualsLiteral("xul:thumb")
541        || SOrigNode.EqualsLiteral("xul:slider")
542        || SOrigNode.EqualsLiteral("xul:scrollbarbutton")
543        || SOrigNode.EqualsLiteral("xul:vbox")
544        || SOrigNode.EqualsLiteral("xul:spacer")) {
545      mEmbedCtxType |= GTK_MOZ_EMBED_CTX_XUL;
546      return NS_OK;
547    }
548  }
549  if (mCtxEvent)
550    rv = mCtxEvent->GetTarget(getter_AddRefs(mEventTarget));
551  if (NS_FAILED(rv) || !mEventTarget) {
552    return NS_OK;
553  }
554  nsCOMPtr<nsIDOMNode> eventNode = do_QueryInterface(mEventTarget, &rv);
555  mEventNode = eventNode;
556  //Frame Stuff
557  nsCOMPtr<nsIDOMDocument> domDoc;
558  if (mEventNode)
559    rv = mEventNode->GetOwnerDocument(getter_AddRefs(domDoc));
560  if (!NS_SUCCEEDED(rv) || !domDoc) {
561    //  return NS_OK;
562  }
563  if (NS_SUCCEEDED(rv) && domDoc && mCtxDocument != domDoc) {
564    mCtxDocument = domDoc;
565    mNSHHTMLElementSc = nsnull;
566    nsCOMPtr<nsIDOM3Document> docuri = do_QueryInterface(mCtxDocument);
567    docuri->GetDocumentURI(mCtxURI);
568    NS_ENSURE_ARG_POINTER(mOwner);
569    nsCOMPtr<nsIWebBrowser> webBrowser;
570    mOwner->mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
571    webBrowser->GetContentDOMWindow(getter_AddRefs(mCtxDomWindow));
572    nsCOMPtr<nsIDOMDocument> mainDocument;
573    mCtxDomWindow->GetDocument(getter_AddRefs(mainDocument));
574    if (!mainDocument) {
575      return NS_OK;
576    }
577    mCtxFrameNum = -1;
578    if (mainDocument != domDoc) {
579      mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IFRAME;
580      SetFrameIndex();
581    }
582  }
583  nsCOMPtr<nsIDOMElement> targetDOMElement;
584  mCtxDocument->GetDocumentElement(getter_AddRefs(targetDOMElement));
585  if (!targetDOMElement) return NS_ERROR_UNEXPECTED;
586  nsCOMPtr<nsIDOMNSHTMLDocument> htmlDoc = do_QueryInterface(mCtxDocument);
587  if (htmlDoc) {
588    nsString DMode;
589    htmlDoc->GetDesignMode(DMode);
590    if (DMode.EqualsLiteral("on")) {
591      mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
592      mEmbedCtxType |= GTK_MOZ_EMBED_CTX_RICHEDIT;
593    }
594  }
595  nsCOMPtr<nsIDocument> doc = do_QueryInterface(mCtxDocument);
596  if (!doc)
597    return NS_OK;
598  nsIPresShell *presShell = doc->GetPrimaryShell();
599  if (!presShell)
600    return NS_OK;
601  nsCOMPtr<nsIContent> tgContent = do_QueryInterface(mEventTarget);
602  nsIFrame* frame = nsnull;
603#if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
604  if (mEmbedCtxType & GTK_MOZ_EMBED_CTX_RICHEDIT)
605    frame = presShell->GetRootFrame();
606  else {
607#ifdef MOZILLA_1_8_BRANCH
608    frame = nsnull;
609    presShell->GetPrimaryFrameFor(tgContent, &frame);
610#else
611    frame = presShell->GetPrimaryFrameFor(tgContent);
612#endif
613  }
614  if (frame) {
615    mFormRect = frame->GetScreenRectExternal();
616  }
617#endif
618  if (NS_SUCCEEDED(SetFormControlType(mEventTarget))) {
619    return NS_OK;
620  }
621  CheckDomHtmlNode();
622  nsCOMPtr<nsIDOMNode> node = mEventNode;
623  nsCOMPtr<nsIDOMNode> parentNode;
624  node->GetParentNode(getter_AddRefs(parentNode));
625  node = parentNode;
626  while (node) {
627    if (NS_FAILED(CheckDomHtmlNode()))
628      break;
629    node->GetParentNode(getter_AddRefs(parentNode));
630    node = parentNode;
631  }
632  mEmbedCtxType |= GTK_MOZ_EMBED_CTX_DOCUMENT;
633  return NS_OK;
634}
Note: See TracBrowser for help on using the repository browser.