1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
3 :
4 : /* This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
6 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 :
8 : #include "nsGenericHTMLElement.h"
9 : #include "nsIDOMHTMLFrameElement.h"
10 : #include "nsIMozBrowserFrame.h"
11 : #include "nsIDOMEventListener.h"
12 : #include "nsIWebProgressListener.h"
13 :
14 : /**
15 : * A helper class for frame elements
16 : */
17 : class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
18 : public nsIFrameLoaderOwner,
19 : public nsIMozBrowserFrame,
20 : public nsIWebProgressListener
21 : {
22 : public:
23 0 : nsGenericHTMLFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
24 : mozilla::dom::FromParser aFromParser)
25 : : nsGenericHTMLElement(aNodeInfo)
26 : , mNetworkCreated(aFromParser == mozilla::dom::FROM_PARSER_NETWORK)
27 0 : , mBrowserFrameListenersRegistered(false)
28 : {
29 0 : }
30 :
31 : virtual ~nsGenericHTMLFrameElement();
32 :
33 : NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
34 : NS_DECL_NSIFRAMELOADEROWNER
35 : NS_DECL_NSIDOMMOZBROWSERFRAME
36 : NS_DECL_NSIMOZBROWSERFRAME
37 : NS_DECL_NSIWEBPROGRESSLISTENER
38 :
39 : // nsIContent
40 : virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, PRInt32 *aTabIndex);
41 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
42 : nsIContent* aBindingParent,
43 : bool aCompileEventHandlers);
44 : virtual void UnbindFromTree(bool aDeep = true,
45 : bool aNullParent = true);
46 : nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
47 : const nsAString& aValue, bool aNotify)
48 : {
49 : return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
50 : }
51 : virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
52 : nsIAtom* aPrefix, const nsAString& aValue,
53 : bool aNotify);
54 : virtual void DestroyContent();
55 :
56 : nsresult CopyInnerTo(nsGenericElement* aDest) const;
57 :
58 : // nsIDOMHTMLElement
59 : NS_IMETHOD GetTabIndex(PRInt32 *aTabIndex);
60 : NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
61 :
62 1464 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsGenericHTMLFrameElement,
63 : nsGenericHTMLElement)
64 :
65 : // Non-COM version of nsIMozBrowserFrame::GetReallyIsBrowser.
66 : bool GetReallyIsBrowser();
67 :
68 : protected:
69 : /**
70 : * Listens to titlechanged events from the document inside the iframe and
71 : * forwards them along to the iframe so it can fire a mozbrowsertitlechange
72 : * event if appropriate.
73 : */
74 : class TitleChangedListener MOZ_FINAL : public nsIDOMEventListener
75 0 : {
76 : public:
77 : TitleChangedListener(nsGenericHTMLFrameElement *aElement,
78 : nsIDOMEventTarget *aChromeHandler);
79 :
80 : /* Unregister this listener. */
81 : void Unregister();
82 :
83 : NS_DECL_ISUPPORTS
84 : NS_DECL_NSIDOMEVENTLISTENER
85 :
86 : private:
87 : nsWeakPtr mElement; /* nsGenericHTMLFrameElement */
88 : nsWeakPtr mChromeHandler; /* nsIDOMEventTarget */
89 : };
90 :
91 : // This doesn't really ensure a frame loade in all cases, only when
92 : // it makes sense.
93 : nsresult EnsureFrameLoader();
94 : nsresult LoadSrc();
95 : nsresult GetContentDocument(nsIDOMDocument** aContentDocument);
96 : nsresult GetContentWindow(nsIDOMWindow** aContentWindow);
97 :
98 : void MaybeEnsureBrowserFrameListenersRegistered();
99 : nsresult MaybeFireBrowserEvent(const nsAString &aEventName,
100 : const nsAString &aEventType,
101 0 : const nsAString &aValue = EmptyString());
102 :
103 : nsRefPtr<nsFrameLoader> mFrameLoader;
104 : nsRefPtr<TitleChangedListener> mTitleChangedListener;
105 :
106 : // True when the element is created by the parser
107 : // using NS_FROM_PARSER_NETWORK flag.
108 : // If the element is modified, it may lose the flag.
109 : bool mNetworkCreated;
110 :
111 : bool mBrowserFrameListenersRegistered;
112 : };
|