diff --git a/mozilla/content/base/public/nsIContent.h b/mozilla/content/base/public/nsIContent.h index 2cfdc644e00..6368dccf5cb 100644 --- a/mozilla/content/base/public/nsIContent.h +++ b/mozilla/content/base/public/nsIContent.h @@ -262,6 +262,13 @@ public: NS_IMETHOD GetContentID(PRUint32* aID) = 0; NS_IMETHOD SetContentID(PRUint32 aID) = 0; + /** + * All content elements are potentially focusable (according to CSS3). + * These methods are used to set and remove the focus on the content + * element. + */ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) = 0; + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) = 0; }; // nsresult codes for GetAttribute diff --git a/mozilla/content/base/src/nsCommentNode.cpp b/mozilla/content/base/src/nsCommentNode.cpp index f4e592e8704..cb7f253795f 100644 --- a/mozilla/content/base/src/nsCommentNode.cpp +++ b/mozilla/content/base/src/nsCommentNode.cpp @@ -167,7 +167,14 @@ public: } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); - } + } + NS_IMETHOD SetFocus(nsIPresContext* aContext) { + return mInner.SetFocus(aContext); + } + NS_IMETHOD RemoveFocus(nsIPresContext* aContext) { + return mInner.RemoveFocus(aContext); + } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { if (!aResult) { return NS_ERROR_NULL_POINTER; diff --git a/mozilla/content/base/src/nsDocumentFragment.cpp b/mozilla/content/base/src/nsDocumentFragment.cpp index 6686413f36c..003e2b88da6 100644 --- a/mozilla/content/base/src/nsDocumentFragment.cpp +++ b/mozilla/content/base/src/nsDocumentFragment.cpp @@ -213,7 +213,13 @@ public: NS_IMETHOD RangeRemove(nsIDOMRange& aRange) { return mInner.RangeRemove(aRange); } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const - { return mInner.GetRangeList(aResult); } + { return mInner.GetRangeList(aResult); } + NS_IMETHOD SetFocus(nsIPresContext* aContext) { + return mInner.SetFocus(aContext); + } + NS_IMETHOD RemoveFocus(nsIPresContext* aContext) { + return mInner.RemoveFocus(aContext); + } NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { if (!aResult) { return NS_ERROR_NULL_POINTER; diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index aefec04ae56..9e3adf8cd04 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -855,6 +855,18 @@ nsGenericDOMDataNode::GetRangeList(nsVoidArray*& aResult) const return NS_OK; } +nsresult +nsGenericDOMDataNode::SetFocus(nsIPresContext* aPresContext) +{ + return NS_OK; +} + +nsresult +nsGenericDOMDataNode::RemoveFocus(nsIPresContext* aPresContext) +{ + return NS_OK; +} + nsresult nsGenericDOMDataNode::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, size_t aInstanceSize) const diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.h b/mozilla/content/base/src/nsGenericDOMDataNode.h index 79f6f9285ec..e8cf56e28c1 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.h +++ b/mozilla/content/base/src/nsGenericDOMDataNode.h @@ -197,6 +197,9 @@ struct nsGenericDOMDataNode { nsresult RangeAdd(nsIDOMRange& aRange); nsresult RangeRemove(nsIDOMRange& aRange); nsresult GetRangeList(nsVoidArray*& aResult) const; + nsresult SetFocus(nsIPresContext *aPresContext); + nsresult RemoveFocus(nsIPresContext *aPresContext); + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, size_t aInstanceSize) const; @@ -424,7 +427,7 @@ struct nsGenericDOMDataNode { return _g.SetScriptObject(aScriptObject); \ } -#define NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(_g) \ +#define NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ return _g.GetDocument(aResult); \ } \ @@ -524,7 +527,13 @@ struct nsGenericDOMDataNode { } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } /** * Implement the nsIDOMText API by forwarding the methods to a diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 1b8229d4787..f0058a23065 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -1133,6 +1133,18 @@ nsGenericElement::GetRangeList(nsVoidArray*& aResult) const return NS_OK; } +nsresult +nsGenericElement::SetFocus(nsIPresContext* aPresContext) +{ + return NS_OK; +} + +nsresult +nsGenericElement::RemoveFocus(nsIPresContext* aPresContext) +{ + return NS_OK; +} + nsresult nsGenericElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, size_t aInstanceSize) const diff --git a/mozilla/content/base/src/nsGenericElement.h b/mozilla/content/base/src/nsGenericElement.h index 3fd8c2e2cc5..1e9a1f7d9fa 100644 --- a/mozilla/content/base/src/nsGenericElement.h +++ b/mozilla/content/base/src/nsGenericElement.h @@ -184,6 +184,8 @@ public: nsresult RangeAdd(nsIDOMRange& aRange); nsresult RangeRemove(nsIDOMRange& aRange); nsresult GetRangeList(nsVoidArray*& aResult) const; + nsresult SetFocus(nsIPresContext* aContext); + nsresult RemoveFocus(nsIPresContext* aContext); nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, size_t aInstanceSize) const; @@ -599,7 +601,13 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ } \ - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } #define NS_IMPL_ICONTENT_NO_SETPARENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -708,7 +716,13 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ } \ - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } #define NS_IMPL_ICONTENT_NO_SETDOCUMENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -817,7 +831,13 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ } \ - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } #define NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -924,8 +944,236 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ } \ - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } +#define NS_IMPL_ICONTENT_NO_FOCUS_USING_GENERIC(_g) \ + NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ + return _g.GetDocument(aResult); \ + } \ + NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep) { \ + return _g.SetDocument(aDocument, aDeep); \ + } \ + NS_IMETHOD GetParent(nsIContent*& aResult) const { \ + return _g.GetParent(aResult); \ + } \ + NS_IMETHOD SetParent(nsIContent* aParent) { \ + return _g.SetParent(aParent); \ + } \ + NS_IMETHOD CanContainChildren(PRBool& aResult) const { \ + return _g.CanContainChildren(aResult); \ + } \ + NS_IMETHOD ChildCount(PRInt32& aResult) const { \ + return _g.ChildCount(aResult); \ + } \ + NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { \ + return _g.ChildAt(aIndex, aResult); \ + } \ + NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { \ + return _g.IndexOf(aPossibleChild, aResult); \ + } \ + NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, \ + PRBool aNotify) { \ + return _g.InsertChildAt(aKid, aIndex, aNotify); \ + } \ + NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, \ + PRBool aNotify) { \ + return _g.ReplaceChildAt(aKid, aIndex, aNotify); \ + } \ + NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { \ + return _g.AppendChildTo(aKid, aNotify); \ + } \ + NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { \ + return _g.RemoveChildAt(aIndex, aNotify); \ + } \ + NS_IMETHOD IsSynthetic(PRBool& aResult) { \ + return _g.IsSynthetic(aResult); \ + } \ + NS_IMETHOD GetNameSpaceID(PRInt32& aResult) const { \ + return _g.GetNameSpaceID(aResult); \ + } \ + NS_IMETHOD GetTag(nsIAtom*& aResult) const { \ + return _g.GetTag(aResult); \ + } \ + NS_IMETHOD ParseAttributeString(const nsString& aStr, \ + nsIAtom*& aName, \ + PRInt32& aNameSpaceID) { \ + return _g.ParseAttributeString(aStr, aName, aNameSpaceID); \ + } \ + NS_IMETHOD GetNameSpacePrefixFromId(PRInt32 aNameSpaceID, \ + nsIAtom*& aPrefix) { \ + return _g.GetNameSpacePrefixFromId(aNameSpaceID, aPrefix); \ + } \ + NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, \ + const nsString& aValue, PRBool aNotify) { \ + return _g.SetAttribute(aNameSpaceID, aName, aValue, aNotify); \ + } \ + NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, \ + nsString& aResult) const { \ + return _g.GetAttribute(aNameSpaceID, aName, aResult); \ + } \ + NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, \ + PRBool aNotify) { \ + return _g.UnsetAttribute(aNameSpaceID, aAttribute, aNotify); \ + } \ + NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, \ + PRInt32& aNameSpaceID, \ + nsIAtom*& aName) const { \ + return _g.GetAttributeNameAt(aIndex, aNameSpaceID, aName); \ + } \ + NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { \ + return _g.GetAttributeCount(aResult); \ + } \ + NS_IMETHOD List(FILE* out, PRInt32 aIndent) const { \ + return _g.List(out, aIndent); \ + } \ + NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const { \ + return _g.BeginConvertToXIF(aConverter); \ + } \ + NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const { \ + return _g.ConvertContentToXIF(aConverter); \ + } \ + NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const { \ + return _g.FinishConvertToXIF(aConverter); \ + } \ + NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, \ + nsEvent* aEvent, \ + nsIDOMEvent** aDOMEvent, \ + PRUint32 aFlags, \ + nsEventStatus* aEventStatus); \ + NS_IMETHOD GetContentID(PRUint32* aID) { \ + return _g.GetContentID(aID); \ + } \ + NS_IMETHOD SetContentID(PRUint32 aID) { \ + return _g.SetContentID(aID); \ + } \ + NS_IMETHOD RangeAdd(nsIDOMRange& aRange) { \ + return _g.RangeAdd(aRange); \ + } \ + NS_IMETHOD RangeRemove(nsIDOMRange& aRange) { \ + return _g.RangeRemove(aRange); \ + } \ + NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ + return _g.GetRangeList(aResult); \ + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext); \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); + +#define NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(_g) \ + NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ + return _g.GetDocument(aResult); \ + } \ + NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep); \ + NS_IMETHOD GetParent(nsIContent*& aResult) const { \ + return _g.GetParent(aResult); \ + } \ + NS_IMETHOD SetParent(nsIContent* aParent); \ + NS_IMETHOD CanContainChildren(PRBool& aResult) const { \ + return _g.CanContainChildren(aResult); \ + } \ + NS_IMETHOD ChildCount(PRInt32& aResult) const { \ + return _g.ChildCount(aResult); \ + } \ + NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { \ + return _g.ChildAt(aIndex, aResult); \ + } \ + NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { \ + return _g.IndexOf(aPossibleChild, aResult); \ + } \ + NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, \ + PRBool aNotify) { \ + return _g.InsertChildAt(aKid, aIndex, aNotify); \ + } \ + NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, \ + PRBool aNotify) { \ + return _g.ReplaceChildAt(aKid, aIndex, aNotify); \ + } \ + NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { \ + return _g.AppendChildTo(aKid, aNotify); \ + } \ + NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { \ + return _g.RemoveChildAt(aIndex, aNotify); \ + } \ + NS_IMETHOD IsSynthetic(PRBool& aResult) { \ + return _g.IsSynthetic(aResult); \ + } \ + NS_IMETHOD GetNameSpaceID(PRInt32& aResult) const { \ + return _g.GetNameSpaceID(aResult); \ + } \ + NS_IMETHOD GetTag(nsIAtom*& aResult) const { \ + return _g.GetTag(aResult); \ + } \ + NS_IMETHOD ParseAttributeString(const nsString& aStr, \ + nsIAtom*& aName, \ + PRInt32& aNameSpaceID) { \ + return _g.ParseAttributeString(aStr, aName, aNameSpaceID); \ + } \ + NS_IMETHOD GetNameSpacePrefixFromId(PRInt32 aNameSpaceID, \ + nsIAtom*& aPrefix) { \ + return _g.GetNameSpacePrefixFromId(aNameSpaceID, aPrefix); \ + } \ + NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, \ + const nsString& aValue, PRBool aNotify) { \ + return _g.SetAttribute(aNameSpaceID, aName, aValue, aNotify); \ + } \ + NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, \ + nsString& aResult) const { \ + return _g.GetAttribute(aNameSpaceID, aName, aResult); \ + } \ + NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, \ + PRBool aNotify) { \ + return _g.UnsetAttribute(aNameSpaceID, aAttribute, aNotify); \ + } \ + NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, \ + PRInt32& aNameSpaceID, \ + nsIAtom*& aName) const { \ + return _g.GetAttributeNameAt(aIndex, aNameSpaceID, aName); \ + } \ + NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { \ + return _g.GetAttributeCount(aResult); \ + } \ + NS_IMETHOD List(FILE* out, PRInt32 aIndent) const { \ + return _g.List(out, aIndent); \ + } \ + NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const { \ + return _g.BeginConvertToXIF(aConverter); \ + } \ + NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const { \ + return _g.ConvertContentToXIF(aConverter); \ + } \ + NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const { \ + return _g.FinishConvertToXIF(aConverter); \ + } \ + NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, \ + nsEvent* aEvent, \ + nsIDOMEvent** aDOMEvent, \ + PRUint32 aFlags, \ + nsEventStatus* aEventStatus); \ + NS_IMETHOD GetContentID(PRUint32* aID) { \ + return _g.GetContentID(aID); \ + } \ + NS_IMETHOD SetContentID(PRUint32 aID) { \ + return _g.SetContentID(aID); \ + } \ + NS_IMETHOD RangeAdd(nsIDOMRange& aRange) { \ + return _g.RangeAdd(aRange); \ + } \ + NS_IMETHOD RangeRemove(nsIDOMRange& aRange) { \ + return _g.RangeRemove(aRange); \ + } \ + NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ + return _g.GetRangeList(aResult); \ + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext); \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); + /** * Implement the nsIScriptObjectOwner API by forwarding the methods to a * generic content object diff --git a/mozilla/content/events/public/nsIEventStateManager.h b/mozilla/content/events/public/nsIEventStateManager.h index 72bb503b34f..b0badce6fc0 100644 --- a/mozilla/content/events/public/nsIEventStateManager.h +++ b/mozilla/content/events/public/nsIEventStateManager.h @@ -73,9 +73,6 @@ public: NS_IMETHOD GetFocusedContent(nsIContent **aContent) = 0; NS_IMETHOD SetFocusedContent(nsIContent* aContent) = 0; - // Cross ESM methods, doesn't matter what instance you call it from - NS_IMETHOD GetFocusedEventTarget(nsIFrame **aFrame) = 0; - // This is an experiement and may be temporary NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) = 0; diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 8ee9a434c7c..f2c09ef9b74 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -43,7 +43,6 @@ #include "nsINameSpaceManager.h" // for kNameSpaceID_HTML #include "nsIWebShell.h" #include "nsIBaseWindow.h" -#include "nsIFocusableContent.h" #include "nsIScrollableView.h" #include "nsIDOMSelection.h" #include "nsIFrameSelection.h" @@ -54,6 +53,8 @@ #include "nsIGfxTextControlFrame.h" #include "nsIDOMWindow.h" #include "nsPIDOMWindow.h" +#include "nsIEnumerator.h" +#include "nsFrameTraversal.h" #include "nsIServiceManager.h" #include "nsIPref.h" @@ -70,9 +71,6 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); -nsIFrame * gCurrentlyFocusedTargetFrame = 0; -nsIContent * gCurrentlyFocusedContent = 0; // Weak because it mirrors the strong mCurrentFocus - nsIContent * gLastFocusedContent = 0; // Strong reference nsIDocument * gLastFocusedDocument = 0; // Strong reference nsIPresContext* gLastFocusedPresContext = 0; // Weak reference @@ -376,43 +374,42 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, } } - if (!focusedWindow) { - nsCOMPtr globalObject; - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - focusedWindow = do_QueryInterface(globalObject); + if (!focusedWindow) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + focusedWindow = do_QueryInterface(globalObject); } - // Sill no focused XULDocument, that is bad - if(!xulDoc && focusedWindow) - { - nsCOMPtr privateWindow = do_QueryInterface(focusedWindow); + // Sill no focused XULDocument, that is bad + if(!xulDoc && focusedWindow) + { + nsCOMPtr privateWindow = do_QueryInterface(focusedWindow); if(privateWindow){ - nsCOMPtr privateRootWindow; - privateWindow->GetPrivateRoot(getter_AddRefs(privateRootWindow)); - if(privateRootWindow){ - nsCOMPtr privateParentDoc; - privateRootWindow->GetDocument(getter_AddRefs(privateParentDoc)); + nsCOMPtr privateRootWindow; + privateWindow->GetPrivateRoot(getter_AddRefs(privateRootWindow)); + if(privateRootWindow) { + nsCOMPtr privateParentDoc; + privateRootWindow->GetDocument(getter_AddRefs(privateParentDoc)); xulDoc = do_QueryInterface(privateParentDoc); - } - } - - if (xulDoc) { + } + } + + if (xulDoc) { // See if we have a command dispatcher attached. xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher)); if (commandDispatcher) { // Obtain focus info from the command dispatcher. commandDispatcher->GetFocusedWindow(getter_AddRefs(focusedWindow)); commandDispatcher->GetFocusedElement(getter_AddRefs(focusedElement)); - } - } - } + } + } + } // Focus the DOM window. focusedWindow->Focus(); if (focusedElement) { - // Focus the content node. - nsCOMPtr focusContent = do_QueryInterface(focusedElement); + nsCOMPtr focusContent = do_QueryInterface(focusedElement); nsCOMPtr domDoc; nsCOMPtr document; focusedWindow->GetDocument(getter_AddRefs(domDoc)); @@ -429,7 +426,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, commandDispatcher->SetSuppressFocus(PR_FALSE); // Unsuppress and let the command dispatcher listen again. } } - break; + break; case NS_DEACTIVATE: { @@ -678,74 +675,32 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, if (nsEventStatus_eConsumeNoDefault != *aStatus) { nsCOMPtr newFocus; - mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(newFocus)); - nsCOMPtr focusable; - - if (newFocus) { - // Look for the nearest enclosing focusable content. - nsCOMPtr current = newFocus; - while (current) { - focusable = do_QueryInterface(current); - if (focusable) - break; - - nsCOMPtr parent; - current->GetParent(*getter_AddRefs(parent)); - current = parent; - } - - // if a focusable piece of content is an anonymous node - // weed to find the parent and have the parent be the - // new focusable node - // - // We fist to check here to see if the focused content - // is anonymous content - if (focusable) { - nsCOMPtr parent; - current->GetParent(*getter_AddRefs(parent)); - NS_ASSERTION(parent.get(), "parent is null. this should not happen."); - PRInt32 numChilds; - parent->ChildCount(numChilds); - PRInt32 i; - PRBool isChild = PR_FALSE; - for (i=0;i child; - parent->ChildAt(i, *getter_AddRefs(child)); - if (child.get() == current.get()) { - isChild = PR_TRUE; - break; - } - } - // if it isn't a child of the parent, then it is anonynous content - // Now, go up the parent list to find a focusable content node - if (!isChild) { - current = parent; - while (current) { - focusable = do_QueryInterface(current); - if (focusable) - break; - - nsCOMPtr tempParent; - current->GetParent(*getter_AddRefs(tempParent)); - current = tempParent; - } - } - // now we ned to get the content node's frame and reset - // the mCurrentTarget target - nsCOMPtr shell; - if (mPresContext) { - nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv) && shell){ - shell->GetPrimaryFrameFor(current, &mCurrentTarget); - } - } - // now adjust the value for the "newFocus" - newFocus = current; - } - - nsCOMPtr content = do_QueryInterface(focusable); - ChangeFocus(content, mCurrentTarget, PR_TRUE); + PRBool suppressBlur = PR_FALSE; + if (mCurrentTarget) { + mCurrentTarget->GetContentForEvent(mPresContext, aEvent, getter_AddRefs(newFocus)); + const nsStyleUserInterface* ui; + mCurrentTarget->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));; + suppressBlur = (ui->mUserFocus == NS_STYLE_USER_FOCUS_IGNORE); } + + nsIFrame* currFrame = mCurrentTarget; + // Look for the nearest enclosing focusable frame. + while (currFrame) { + const nsStyleUserInterface* ui; + currFrame->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));; + if ((ui->mUserFocus != NS_STYLE_USER_FOCUS_IGNORE) && + (ui->mUserFocus != NS_STYLE_USER_FOCUS_NONE)) { + currFrame->GetContent(getter_AddRefs(newFocus)); + break; + } + currFrame->GetParent(&currFrame); + } + + if (newFocus && currFrame) + ChangeFocus(newFocus, currFrame, PR_TRUE); + else if (!suppressBlur) + SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + SetContentState(newFocus, NS_EVENT_STATE_ACTIVE); } } @@ -1607,34 +1562,7 @@ nsEventStateManager::CheckForAndDispatchClick(nsIPresContext* aPresContext, PRBool nsEventStateManager::ChangeFocus(nsIContent* aFocusContent, nsIFrame* aTargetFrame, PRBool aSetFocus) { - nsCOMPtr focusChange = do_QueryInterface(aFocusContent); - - if (aTargetFrame) { - - PRBool suppressBlurAndFocus = PR_FALSE; - nsCOMPtr context; - aTargetFrame->GetStyleContext(getter_AddRefs(context)); - - const nsStyleUserInterface* styleStruct = (const nsStyleUserInterface*)context->GetStyleData(eStyleStruct_UserInterface); - if (NS_STYLE_USER_FOCUS_IGNORE == styleStruct->mUserFocus) { - // we want to surpress the blur and the following focus - suppressBlurAndFocus = PR_TRUE; - } - - if(!suppressBlurAndFocus) { - - if (focusChange) { - focusChange->SetFocus(mPresContext); - } - else { - SendFocusBlur(mPresContext, nsnull); - } - } - } - else { - printf("OH MY GOD!\n"); - } - + aFocusContent->SetFocus(mPresContext); return PR_FALSE; } @@ -1666,9 +1594,21 @@ nsEventStateManager::ShiftFocus(PRBool forward) topOfDoc = PR_TRUE; } - nsIContent* next = GetNextTabbableContent(mCurrentFocus, nsnull, mCurrentFocus, forward); + nsIFrame* primaryFrame; + nsCOMPtr shell; + if (mPresContext) { + nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv) && shell){ + shell->GetPrimaryFrameFor(mCurrentFocus, &primaryFrame); + } + } - if (nsnull == next) { + nsCOMPtr rootContent = getter_AddRefs(mDocument->GetRootContent()); + + nsCOMPtr next; + GetNextTabbableContent(rootContent, primaryFrame, forward, getter_AddRefs(next)); + + if (!next) { PRBool focusTaken = PR_FALSE; SetContentState(nsnull, NS_EVENT_STATE_FOCUS); @@ -1689,193 +1629,174 @@ nsEventStateManager::ShiftFocus(PRBool forward) // Now we need to get the content node's frame and reset // the mCurrentTarget target. Otherwise the focus // code will be slightly out of sync (with regards to - // focusing widgets within the current target). - nsCOMPtr shell; - if (mPresContext) { - nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv) && shell){ - shell->GetPrimaryFrameFor(next, &mCurrentTarget); - } - } + // focusing widgets within the current target) + if (shell) + shell->GetPrimaryFrameFor(next, &mCurrentTarget); + ChangeFocus(next, mCurrentTarget, PR_TRUE); NS_IF_RELEASE(mCurrentFocus); mCurrentFocus = next; + NS_IF_ADDREF(mCurrentFocus); } /* * At some point this will need to be linked into HTML 4.0 tabindex */ -nsIContent* -nsEventStateManager::GetNextTabbableContent(nsIContent* aParent, nsIContent* aChild, nsIContent* aTop, PRBool forward) + +NS_IMETHODIMP +nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* aFrame, PRBool forward, + nsIContent** aResult) { - PRInt32 count, index; - aParent->ChildCount(count); + *aResult = nsnull; - if (nsnull != aChild) { - aParent->IndexOf(aChild, index); - index += forward ? 1 : -1; - } - else { - index = forward ? 0 : count-1; - } + nsCOMPtr frameTraversal; + nsresult result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal), EXTENSIVE, + mPresContext, aFrame); - for (;index < count && index >= 0;index += forward ? 1 : -1) { - nsIContent* child; + if (NS_FAILED(result)) + return NS_OK; - aParent->ChildAt(index, child); - nsIContent* content = GetNextTabbableContent(child, nsnull, aTop, forward); - if (content != nsnull) { - NS_IF_RELEASE(child); - return content; - } - if (nsnull != child) { + if (forward) + frameTraversal->Next(); + else frameTraversal->Prev(); + + nsISupports* currentItem; + frameTraversal->CurrentItem(¤tItem); + nsIFrame* currentFrame = (nsIFrame*)currentItem; + + while (currentFrame) { + nsCOMPtr child; + currentFrame->GetContent(getter_AddRefs(child)); + + const nsStyleDisplay* disp; + currentFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)disp)); + + const nsStyleUserInterface* ui; + currentFrame->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));; + + nsCOMPtr element(do_QueryInterface(child)); + + // if collapsed or hidden, we don't get tabbed into. + if ((disp->mVisible != NS_STYLE_VISIBILITY_COLLAPSE) && + (disp->mVisible != NS_STYLE_VISIBILITY_HIDDEN) && + (ui->mUserFocus != NS_STYLE_USER_FOCUS_IGNORE) && + (ui->mUserFocus != NS_STYLE_USER_FOCUS_NONE) && element) { nsCOMPtr tag; PRInt32 tabIndex = -1; PRBool disabled = PR_TRUE; PRBool hidden = PR_FALSE; child->GetTag(*getter_AddRefs(tag)); - if (nsHTMLAtoms::input==tag.get()) { - nsIDOMHTMLInputElement *nextInput; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLInputElement), - (void **)&nextInput)) { - nextInput->GetDisabled(&disabled); - nextInput->GetTabIndex(&tabIndex); + nsCOMPtr htmlElement(do_QueryInterface(child)); + if (htmlElement) { + if (nsHTMLAtoms::input==tag.get()) { + nsCOMPtr nextInput(do_QueryInterface(child)); + if (nextInput) { + nextInput->GetDisabled(&disabled); + nextInput->GetTabIndex(&tabIndex); - nsAutoString type; - nextInput->GetType(type); - if (type.EqualsIgnoreCase("hidden")) { - hidden = PR_TRUE; + nsAutoString type; + nextInput->GetType(type); + if (type.EqualsIgnoreCase("hidden")) { + hidden = PR_TRUE; + } } - NS_RELEASE(nextInput); } - } - else if (nsHTMLAtoms::select==tag.get()) { - nsIDOMHTMLSelectElement *nextSelect; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement), - (void **)&nextSelect)) { - nextSelect->GetDisabled(&disabled); - nextSelect->GetTabIndex(&tabIndex); - NS_RELEASE(nextSelect); + else if (nsHTMLAtoms::select==tag.get()) { + nsCOMPtr nextSelect(do_QueryInterface(child)); + if (nextSelect) { + nextSelect->GetDisabled(&disabled); + nextSelect->GetTabIndex(&tabIndex); + } } - } - else if (nsHTMLAtoms::textarea==tag.get()) { - nsIDOMHTMLTextAreaElement *nextTextArea; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLTextAreaElement),(void **)&nextTextArea)) { - nextTextArea->GetDisabled(&disabled); - nextTextArea->GetTabIndex(&tabIndex); - NS_RELEASE(nextTextArea); + else if (nsHTMLAtoms::textarea==tag.get()) { + nsCOMPtr nextTextArea(do_QueryInterface(child)); + if (nextTextArea) { + nextTextArea->GetDisabled(&disabled); + nextTextArea->GetTabIndex(&tabIndex); + } } - - } - else if(nsHTMLAtoms::a==tag.get()) { - nsIDOMHTMLAnchorElement *nextAnchor; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLAnchorElement), - (void **)&nextAnchor)) { - nextAnchor->GetTabIndex(&tabIndex); - NS_RELEASE(nextAnchor); + else if(nsHTMLAtoms::a==tag.get()) { + nsCOMPtr nextAnchor(do_QueryInterface(child)); + if (nextAnchor) + nextAnchor->GetTabIndex(&tabIndex); + disabled = PR_FALSE; } - disabled = PR_FALSE; - } - else if(nsHTMLAtoms::button==tag.get()) { - nsIDOMHTMLButtonElement *nextButton; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLButtonElement), - (void **)&nextButton)) { - nextButton->GetTabIndex(&tabIndex); - nextButton->GetDisabled(&disabled); - NS_RELEASE(nextButton); + else if(nsHTMLAtoms::button==tag.get()) { + nsCOMPtr nextButton(do_QueryInterface(child)); + if (nextButton) { + nextButton->GetTabIndex(&tabIndex); + nextButton->GetDisabled(&disabled); + } } - } - else if(nsHTMLAtoms::area==tag.get()) { - nsIDOMHTMLAreaElement *nextArea; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLAreaElement), - (void **)&nextArea)) { - nextArea->GetTabIndex(&tabIndex); - NS_RELEASE(nextArea); + else if(nsHTMLAtoms::area==tag.get()) { + nsCOMPtr nextArea(do_QueryInterface(child)); + if (nextArea) + nextArea->GetTabIndex(&tabIndex); + disabled = PR_FALSE; } - disabled = PR_FALSE; - } - else if(nsHTMLAtoms::object==tag.get()) { - nsIDOMHTMLObjectElement *nextObject; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLObjectElement), - (void **)&nextObject)) { - nextObject->GetTabIndex(&tabIndex); - NS_RELEASE(nextObject); + else if(nsHTMLAtoms::object==tag.get()) { + nsCOMPtr nextObject(do_QueryInterface(child)); + if (nextObject) + nextObject->GetTabIndex(&tabIndex); + disabled = PR_FALSE; } - disabled = PR_FALSE; } else { - // QI to nsIFocusableContent - nsCOMPtr focusable(do_QueryInterface(child)); - if (focusable) { - nsAutoString value; - child->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, value); - if (!value.EqualsWithConversion("true")) - disabled = PR_FALSE; + nsAutoString value; + child->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, value); + nsAutoString tabStr; + child->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::tabindex, tabStr); + if (tabStr != "") { + PRInt32 errorCode; + tabIndex = tabStr.ToInteger(&errorCode); } + if (!value.EqualsWithConversion("true")) + disabled = PR_FALSE; } - // Get the primary frame for the widget. We don't tab into anything - // that doesn't have a frame. - nsCOMPtr shell; - if (mPresContext) { - nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv) && shell){ - nsIFrame* potentialFrame; - shell->GetPrimaryFrameFor(child, &potentialFrame); - if (!potentialFrame) - hidden = PR_TRUE; - } - } - //TabIndex not set (-1) treated at same level as set to 0 tabIndex = tabIndex < 0 ? 0 : tabIndex; if (!disabled && !hidden && mCurrentTabIndex == tabIndex) { - return child; + *aResult = child; + NS_IF_ADDREF(*aResult); + return NS_OK; } - NS_RELEASE(child); } + + if (forward) + frameTraversal->Next(); + else frameTraversal->Prev(); + + frameTraversal->CurrentItem(¤tItem); + currentFrame = (nsIFrame*)currentItem; } - if (aParent == aTop) { - nsIContent* nextParent; - aParent->GetParent(nextParent); - if (nsnull != nextParent) { - nsIContent* content = GetNextTabbableContent(nextParent, aParent, nextParent, forward); - NS_RELEASE(nextParent); - return content; - } - //Reached end of document - else { - //If already at lowest priority tab (0), end - if (((forward) && (0 == mCurrentTabIndex)) || - ((!forward) && (1 == mCurrentTabIndex))) { - return nsnull; - } - //else continue looking for next highest priority tab - mCurrentTabIndex = GetNextTabIndex(aParent, forward); - nsIContent* content = GetNextTabbableContent(aParent, nsnull, aParent, forward); - return content; - } + // Reached end or beginning of document + //If already at lowest priority tab (0), end + if (((forward) && (0 == mCurrentTabIndex)) || + ((!forward) && (1 == mCurrentTabIndex))) { + return NS_OK; } - - return nsnull; + //else continue looking for next highest priority tab + mCurrentTabIndex = GetNextTabIndex(aRootContent, forward); + return GetNextTabbableContent(aRootContent, nsnull, forward, aResult); } PRInt32 nsEventStateManager::GetNextTabIndex(nsIContent* aParent, PRBool forward) { PRInt32 count, tabIndex, childTabIndex; - nsIContent* child; + nsCOMPtr child; aParent->ChildCount(count); if (forward) { tabIndex = 0; for (PRInt32 index = 0; index < count; index++) { - aParent->ChildAt(index, child); + aParent->ChildAt(index, *getter_AddRefs(child)); childTabIndex = GetNextTabIndex(child, forward); if (childTabIndex > mCurrentTabIndex && childTabIndex != tabIndex) { tabIndex = (tabIndex == 0 || childTabIndex < tabIndex) ? childTabIndex : tabIndex; @@ -1887,13 +1808,12 @@ nsEventStateManager::GetNextTabIndex(nsIContent* aParent, PRBool forward) if (NS_OK == ec && val > mCurrentTabIndex && val != tabIndex) { tabIndex = (tabIndex == 0 || val < tabIndex) ? val : tabIndex; } - NS_RELEASE(child); } } else { /* !forward */ tabIndex = 1; for (PRInt32 index = 0; index < count; index++) { - aParent->ChildAt(index, child); + aParent->ChildAt(index, *getter_AddRefs(child)); childTabIndex = GetNextTabIndex(child, forward); if ((mCurrentTabIndex==0 && childTabIndex > tabIndex) || (childTabIndex < mCurrentTabIndex && childTabIndex > tabIndex)) { @@ -1909,7 +1829,6 @@ nsEventStateManager::GetNextTabIndex(nsIContent* aParent, PRBool forward) tabIndex = val; } } - NS_RELEASE(child); } } return tabIndex; @@ -1933,26 +1852,6 @@ nsEventStateManager::GetEventTarget(nsIFrame **aFrame) return NS_OK; } -// This API crosses ESM instances to give the currently focused frame, no matter what ESM instace -// you call it from. -NS_IMETHODIMP -nsEventStateManager::GetFocusedEventTarget(nsIFrame **aFrame) -{ - if (!gCurrentlyFocusedTargetFrame && gCurrentlyFocusedContent && gLastFocusedPresContext) { - nsCOMPtr shell; - if (gLastFocusedPresContext) { - nsresult rv = gLastFocusedPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv) && shell){ - shell->GetPrimaryFrameFor(gCurrentlyFocusedContent, &gCurrentlyFocusedTargetFrame); - } - } - } - - *aFrame = gCurrentlyFocusedTargetFrame; - return NS_OK; -} - - NS_IMETHODIMP nsEventStateManager::GetEventTargetContent(nsEvent* aEvent, nsIContent** aContent) { @@ -2040,21 +1939,16 @@ nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState) } if ((aState & NS_EVENT_STATE_FOCUS)) { - if (aContent == mCurrentFocus) { + if (aContent && (aContent == mCurrentFocus)) { // gLastFocusedDocument appears to always be correct, that is why // I'm not setting it here. This is to catch an edge case. NS_IF_RELEASE(gLastFocusedContent); gLastFocusedContent = mCurrentFocus; NS_IF_ADDREF(gLastFocusedContent); } else { - SendFocusBlur(mPresContext, aContent); - - //transferring ref to notifyContent from mCurrentFocus notifyContent[3] = mCurrentFocus; - mCurrentFocus = aContent; NS_IF_ADDREF(mCurrentFocus); - - gCurrentlyFocusedContent = mCurrentFocus; + SendFocusBlur(mPresContext, aContent); } } @@ -2144,24 +2038,9 @@ nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState) NS_IMETHODIMP nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aContent) { - //PRBool suppressBlurAndFocus = PR_FALSE; - - if(mCurrentTarget) { - nsCOMPtr context; - mCurrentTarget->GetStyleContext(getter_AddRefs(context)); - if(!context) return NS_OK; - - - const nsStyleUserInterface* styleStruct = (const nsStyleUserInterface*)context->GetStyleData(eStyleStruct_UserInterface); - if (NS_STYLE_USER_FOCUS_IGNORE == styleStruct->mUserFocus) { - // we want to suppress the blur and the following focus - return NS_OK; - } - } - nsCOMPtr presShell; aPresContext->GetShell(getter_AddRefs(presShell)); - + if (nsnull != gLastFocusedPresContext) { if (gLastFocusedContent && gLastFocusedContent != mFirstBlurEvent) { @@ -2258,10 +2137,6 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo event.eventStructType = NS_EVENT; event.message = NS_FOCUS_CONTENT; - NS_IF_RELEASE(mCurrentFocus); - mCurrentFocus = aContent; - NS_IF_ADDREF(mCurrentFocus); - if (nsnull != mPresContext) { aContent->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } @@ -2278,9 +2153,11 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo } } - // XXx The following line could be bad in the case where a - // parent element is really the one with the focus. - nsIFrame * currentFocusFrame = mCurrentTarget; + nsIFrame * currentFocusFrame = nsnull; + if (mCurrentFocus) + presShell->GetPrimaryFrameFor(mCurrentFocus, ¤tFocusFrame); + if (!currentFocusFrame) + currentFocusFrame = mCurrentTarget; // Find the window that this frame is in and // make sure it has focus diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index 4409e27b73c..af93e6eb5c9 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -90,9 +90,6 @@ public: NS_IMETHOD GetFocusedContent(nsIContent **aContent); NS_IMETHOD SetFocusedContent(nsIContent* aContent); - // Cross ESM methods - NS_IMETHOD GetFocusedEventTarget(nsIFrame **aFrame); - // This is an experiement and may be temporary NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) { mConsumeFocusEvents = aDoConsume; return NS_OK; } @@ -108,7 +105,7 @@ protected: NS_IMETHOD CheckForAndDispatchClick(nsIPresContext* aPresContext, nsMouseEvent *aEvent, nsEventStatus* aStatus); PRBool ChangeFocus(nsIContent* aFocus, nsIFrame* aFocusFrame, PRBool aSetFocus); void ShiftFocus(PRBool foward); - nsIContent* GetNextTabbableContent(nsIContent* aParent, nsIContent* aChild, nsIContent* aTop, PRBool foward); + NS_IMETHOD GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* aFrame, PRBool foward, nsIContent** aResult); PRInt32 GetNextTabIndex(nsIContent* aParent, PRBool foward); NS_IMETHOD SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aContent); PRBool CheckDisabled(nsIContent* aContent); diff --git a/mozilla/content/html/content/public/MANIFEST b/mozilla/content/html/content/public/MANIFEST index bff7f373fd2..3948b65ce20 100644 --- a/mozilla/content/html/content/public/MANIFEST +++ b/mozilla/content/html/content/public/MANIFEST @@ -1,4 +1,3 @@ -nsIFocusableContent.h nsIForm.h nsIFormControl.h nsISelectElement.h diff --git a/mozilla/content/html/content/public/Makefile.in b/mozilla/content/html/content/public/Makefile.in index 395432ce998..7342f9a83e0 100644 --- a/mozilla/content/html/content/public/Makefile.in +++ b/mozilla/content/html/content/public/Makefile.in @@ -31,7 +31,6 @@ MODULE = layout EXPORTS = \ nsIFormControl.h \ nsIForm.h \ - nsIFocusableContent.h \ nsISelectElement.h \ $(NULL) diff --git a/mozilla/content/html/content/public/makefile.win b/mozilla/content/html/content/public/makefile.win index 002a8a0ff3f..72f2297df0a 100644 --- a/mozilla/content/html/content/public/makefile.win +++ b/mozilla/content/html/content/public/makefile.win @@ -21,7 +21,7 @@ DEPTH=..\..\..\.. -EXPORTS=nsIFormControl.h nsIForm.h nsIFocusableContent.h nsISelectElement.h +EXPORTS=nsIFormControl.h nsIForm.h nsISelectElement.h MODULE=raptor diff --git a/mozilla/content/html/content/src/nsAttributeContent.cpp b/mozilla/content/html/content/src/nsAttributeContent.cpp index 6fbdaea5a6e..6dde6287b29 100644 --- a/mozilla/content/html/content/src/nsAttributeContent.cpp +++ b/mozilla/content/html/content/src/nsAttributeContent.cpp @@ -122,6 +122,9 @@ public: return NS_OK; } + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { return NS_OK; } + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { return NS_OK; } + NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, const nsString& aValue, PRBool aNotify) { return NS_OK; } NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRBool aNotify) { return NS_OK; } @@ -168,7 +171,7 @@ public: NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { return NS_OK; } NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { return NS_OK; } NS_IMETHOD SplitText(PRUint32 aOffset, nsIDOMText** aReturn){ return NS_OK; } - + /////////////////// // Implementation for nsITextContent NS_IMETHOD GetText(const nsTextFragment** aFragmentsResult); diff --git a/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp b/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp index 05f31cd7ce9..03d4b122683 100644 --- a/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp @@ -33,7 +33,6 @@ #include "nsIPresContext.h" #include "nsIEventStateManager.h" #include "nsIURL.h" -#include "nsIFocusableContent.h" #include "nsIEventStateManager.h" #include "nsDOMEvent.h" @@ -50,13 +49,11 @@ // custom frame static NS_DEFINE_IID(kIDOMHTMLAnchorElementIID, NS_IDOMHTMLANCHORELEMENT_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); class nsHTMLAnchorElement : public nsIDOMHTMLAnchorElement, public nsIDOMNSHTMLAnchorElement, public nsIJSScriptObject, - public nsIHTMLContent, - public nsIFocusableContent + public nsIHTMLContent { public: nsHTMLAnchorElement(nsIAtom* aTag); @@ -116,15 +113,11 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_USING_GENERIC(mInner) + NS_IMPL_ICONTENT_NO_FOCUS_USING_GENERIC(mInner) // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - protected: nsGenericHTMLContainerElement mInner; }; @@ -168,11 +161,6 @@ nsHTMLAnchorElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIDOMNSHTMLAnchorElement))) { *aInstancePtr = (void*)(nsIDOMNSHTMLAnchorElement*) this; NS_ADDREF_THIS(); diff --git a/mozilla/content/html/content/src/nsHTMLAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLAreaElement.cpp index f9de7e5f146..8167edc596f 100644 --- a/mozilla/content/html/content/src/nsHTMLAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLAreaElement.cpp @@ -31,18 +31,15 @@ #include "nsIMutableStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIFocusableContent.h" #include "nsIEventStateManager.h" #include "nsIURL.h" #include "nsNetUtil.h" static NS_DEFINE_IID(kIDOMHTMLAreaElementIID, NS_IDOMHTMLAREAELEMENT_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); class nsHTMLAreaElement : public nsIDOMHTMLAreaElement, public nsIJSScriptObject, - public nsIHTMLContent, - public nsIFocusableContent + public nsIHTMLContent { public: nsHTMLAreaElement(nsIAtom* aTag); @@ -91,15 +88,11 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_USING_GENERIC(mInner) - + NS_IMPL_ICONTENT_NO_FOCUS_USING_GENERIC(mInner) + // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - protected: nsGenericHTMLLeafElement mInner; }; @@ -143,11 +136,6 @@ nsHTMLAreaElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIDOMNSHTMLAreaElement))) { *aInstancePtr = (void*)(nsIDOMNSHTMLAreaElement*) this; NS_ADDREF_THIS(); diff --git a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp index 39dfc0686df..333f2bc9a8a 100644 --- a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp @@ -35,7 +35,6 @@ #include "nsIFormControl.h" #include "nsIForm.h" #include "nsIURL.h" -#include "nsIFocusableContent.h" #include "nsIFormControlFrame.h" #include "nsIEventStateManager.h" @@ -43,13 +42,11 @@ #include "nsISizeOfHandler.h" static NS_DEFINE_IID(kIDOMHTMLButtonElementIID, NS_IDOMHTMLBUTTONELEMENT_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); class nsHTMLButtonElement : public nsIDOMHTMLButtonElement, public nsIJSScriptObject, public nsIHTMLContent, - public nsIFormControl, - public nsIFocusableContent + public nsIFormControl { public: nsHTMLButtonElement(nsIAtom* aTag); @@ -89,8 +86,8 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(mInner) - + NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(mInner) + // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) @@ -99,10 +96,6 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init() { return NS_OK; } - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - protected: nsGenericHTMLContainerElement mInner; nsIForm* mForm; @@ -165,11 +158,6 @@ nsHTMLButtonElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } return NS_NOINTERFACE; } diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index c43a9b3b6ff..b85b82250f1 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -46,7 +46,6 @@ #include "nsIPresShell.h" #include "nsIFormControlFrame.h" #include "nsIFrame.h" -#include "nsIFocusableContent.h" #include "nsIBindableContent.h" #include "nsIXBLBinding.h" #include "nsIEventStateManager.h" @@ -66,7 +65,6 @@ static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID); static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); class nsHTMLInputElement : public nsIDOMHTMLInputElement, @@ -74,7 +72,6 @@ class nsHTMLInputElement : public nsIDOMHTMLInputElement, public nsIJSScriptObject, public nsIHTMLContent, public nsIFormControl, - public nsIFocusableContent, public nsIBindableContent { public: @@ -123,7 +120,6 @@ public: return mInner.GetElementsByTagName(aTagname, aReturn); } - // nsIDOMHTMLElement NS_IMPL_IDOMHTMLELEMENT_USING_GENERIC(mInner) @@ -178,7 +174,7 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(mInner) + NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(mInner) // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) @@ -188,10 +184,6 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init() { return NS_OK; } - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - // nsIBindableContent NS_IMETHOD SetBinding(nsIXBLBinding* aBinding); NS_IMETHOD GetBinding(nsIXBLBinding** aResult); @@ -277,11 +269,6 @@ nsHTMLInputElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIBindableContent))) { *aInstancePtr = (void*)(nsIBindableContent*) this; NS_ADDREF_THIS(); @@ -700,18 +687,17 @@ nsHTMLInputElement::Focus() NS_IMETHODIMP nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext) { - nsIEventStateManager* esm; - if (NS_OK == aPresContext->GetEventStateManager(&esm)) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); - NS_RELEASE(esm); - } - // first see if we are disabled or not. If disabled then do nothing. nsAutoString disabled; if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled)) { return NS_OK; } - + + nsCOMPtr esm; + if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) { + esm->SetContentState(this, NS_EVENT_STATE_FOCUS); + } + nsIFormControlFrame* formControlFrame = nsnull; nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/content/html/content/src/nsHTMLMapElement.cpp b/mozilla/content/html/content/src/nsHTMLMapElement.cpp index 94e4cee8d42..8b6060c18e3 100644 --- a/mozilla/content/html/content/src/nsHTMLMapElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLMapElement.cpp @@ -174,7 +174,16 @@ public: } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); - } + } + + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { + return mInner.SetFocus(aPresContext); + } + + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { + return mInner.RemoveFocus(aPresContext); + } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; // nsIHTMLContent diff --git a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp index 943048fb758..383fd60586e 100644 --- a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp @@ -39,7 +39,6 @@ #include "nsIForm.h" #include "nsIDOMHTMLCollection.h" #include "nsIDOMHTMLOptionElement.h" -#include "nsIFocusableContent.h" #include "nsIEventStateManager.h" #include "nsGenericDOMHTMLCollection.h" #include "nsIJSScriptObject.h" @@ -69,7 +68,6 @@ static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID); static NS_DEFINE_IID(kISelectElementIID, NS_ISELECTELEMENT_IID); static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); class nsHTMLSelectElement; @@ -128,7 +126,6 @@ class nsHTMLSelectElement : public nsIDOMHTMLSelectElement, public nsIJSScriptObject, public nsIHTMLContent, public nsIFormControl, - public nsIFocusableContent, public nsISelectElement { public: @@ -177,7 +174,7 @@ public: NS_IMETHOD NamedItem(const nsString& aName, nsIDOMNode** aReturn); // nsIContent - NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(mInner) + NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(mInner) // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) @@ -187,9 +184,6 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init(); - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - // nsISelectElement NS_IMETHOD AddOption(nsIContent* aContent); NS_IMETHOD RemoveOption(nsIContent* aContent); @@ -297,11 +291,6 @@ nsHTMLSelectElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(kISelectElementIID)) { *aInstancePtr = (void*)(nsISelectElement*) this; NS_ADDREF_THIS(); diff --git a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp index 935d1d75854..3b8dc68f2d5 100644 --- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -42,7 +42,6 @@ #include "nsIPresContext.h" #include "nsIHTMLAttributes.h" #include "nsIFormControlFrame.h" -#include "nsIFocusableContent.h" #include "nsIBindableContent.h" #include "nsIXBLBinding.h" #include "nsIEventStateManager.h" @@ -53,7 +52,6 @@ static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); class nsHTMLTextAreaElement : public nsIDOMHTMLTextAreaElement, @@ -61,7 +59,6 @@ class nsHTMLTextAreaElement : public nsIDOMHTMLTextAreaElement, public nsIJSScriptObject, public nsIHTMLContent, public nsIFormControl, - public nsIFocusableContent, public nsIBindableContent { public: @@ -112,7 +109,7 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(mInner) + NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(mInner) // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) @@ -122,10 +119,6 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init() { return NS_OK; } - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - // nsIBindableContent NS_IMETHOD SetBinding(nsIXBLBinding* aBinding); NS_IMETHOD GetBinding(nsIXBLBinding** aResult); @@ -190,11 +183,6 @@ nsHTMLTextAreaElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIBindableContent))) { *aInstancePtr = (void*)(nsIBindableContent*) this; NS_ADDREF_THIS(); diff --git a/mozilla/content/xml/content/src/nsXMLElement.h b/mozilla/content/xml/content/src/nsXMLElement.h index af408704acf..ca712cc29c7 100644 --- a/mozilla/content/xml/content/src/nsXMLElement.h +++ b/mozilla/content/xml/content/src/nsXMLElement.h @@ -168,7 +168,15 @@ public: } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); - } + } + + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { + return mInner.SetFocus(aPresContext); + } + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { + return mInner.RemoveFocus(aPresContext); + } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { if (!aResult) { return NS_ERROR_NULL_POINTER; diff --git a/mozilla/layout/base/nsFrameTraversal.cpp b/mozilla/layout/base/nsFrameTraversal.cpp index 882b3c87e40..8180657954d 100644 --- a/mozilla/layout/base/nsFrameTraversal.cpp +++ b/mozilla/layout/base/nsFrameTraversal.cpp @@ -80,6 +80,8 @@ class nsLeafIterator: public nsFrameIterator { public: nsLeafIterator(nsIPresContext* aPresContext, nsIFrame *start); + void SetExtensive(PRBool aExtensive) {mExtensive = aExtensive;} + PRBool GetExtensive(){return mExtensive;} private : NS_IMETHOD Next(); @@ -87,6 +89,7 @@ private : NS_IMETHOD Prev(); nsIPresContext* mPresContext; + PRBool mExtensive; }; /************IMPLEMENTATIONS**************/ @@ -107,17 +110,19 @@ NS_NewFrameTraversal(nsIBidirectionalEnumerator **aEnumerator, return NS_ERROR_OUT_OF_MEMORY; *aEnumerator = NS_STATIC_CAST(nsIBidirectionalEnumerator*, trav); NS_ADDREF(trav); + trav->SetExtensive(PR_FALSE); + } + break; + case EXTENSIVE:{ + nsLeafIterator *trav = new nsLeafIterator(aPresContext, aStart); + if (!trav) + return NS_ERROR_OUT_OF_MEMORY; + *aEnumerator = NS_STATIC_CAST(nsIBidirectionalEnumerator*, trav); + NS_ADDREF(trav); + trav->SetExtensive(PR_TRUE); } break; #if 0 - case EXTENSIVE:{ - nsExtensiveTraversal *trav = new nsExtensiveTraversal(aStart); - if (!trav) - return NS_ERROR_NOMEMORY; - *aEnumerator = NS_STATIC_CAST(nsIBidirectionalEnumerator*, trav); - NS_ADDREF(trav); - } - break; case FASTEST:{ nsFastestTraversal *trav = new nsFastestTraversal(aStart); if (!trav) @@ -210,9 +215,12 @@ nsLeafIterator::Next() nsIFrame *parent = getCurrent(); if (!parent) parent = getLast(); - while(NS_SUCCEEDED(parent->FirstChild(mPresContext, nsnull,&result)) && result) + if (!mExtensive) { - parent = result; + while(NS_SUCCEEDED(parent->FirstChild(mPresContext, nsnull,&result)) && result) + { + parent = result; + } } if (parent != getCurrent()) { @@ -235,7 +243,11 @@ nsLeafIterator::Next() break; } else + { parent = result; + if (mExtensive) + break; + } } } setCurrent(result); @@ -277,7 +289,11 @@ nsLeafIterator::Prev() break; } else + { parent = result; + if (mExtensive) + break; + } } else{ setLast(parent); @@ -286,35 +302,6 @@ nsLeafIterator::Prev() } } - -/* while(parent){ - nsIFrame *grandParent; - if (NS_SUCCEEDED(parent->GetParent(&grandParent)) && grandParent){ - nsIFrame * grandFchild; - if (NS_SUCCEEDED(grandParent->FirstChild(nsnull,&grandFchild)) && grandFchild){ - nsFrameList list(grandFchild); - if (nsnull != (result = list.GetPrevSiblingFor(parent)) ){ - parent = result; - while(NS_SUCCEEDED(parent->FirstChild(nsnull,&result)) && result){ - parent = result; - while(NS_SUCCEEDED(parent->GetNextSibling(&result)) && result){ - parent = result; - } - } - result = parent; - break; - } - else - if (NS_FAILED(parent->GetParent(&result)) || !result){ - result = nsnull; - break; - } - else - parent = result; - } - } - } - */ setCurrent(result); if (!result) setOffEdge(-1); diff --git a/mozilla/layout/base/public/nsIContent.h b/mozilla/layout/base/public/nsIContent.h index 2cfdc644e00..6368dccf5cb 100644 --- a/mozilla/layout/base/public/nsIContent.h +++ b/mozilla/layout/base/public/nsIContent.h @@ -262,6 +262,13 @@ public: NS_IMETHOD GetContentID(PRUint32* aID) = 0; NS_IMETHOD SetContentID(PRUint32 aID) = 0; + /** + * All content elements are potentially focusable (according to CSS3). + * These methods are used to set and remove the focus on the content + * element. + */ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) = 0; + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) = 0; }; // nsresult codes for GetAttribute diff --git a/mozilla/layout/base/src/nsCommentNode.cpp b/mozilla/layout/base/src/nsCommentNode.cpp index f4e592e8704..cb7f253795f 100644 --- a/mozilla/layout/base/src/nsCommentNode.cpp +++ b/mozilla/layout/base/src/nsCommentNode.cpp @@ -167,7 +167,14 @@ public: } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); - } + } + NS_IMETHOD SetFocus(nsIPresContext* aContext) { + return mInner.SetFocus(aContext); + } + NS_IMETHOD RemoveFocus(nsIPresContext* aContext) { + return mInner.RemoveFocus(aContext); + } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { if (!aResult) { return NS_ERROR_NULL_POINTER; diff --git a/mozilla/layout/base/src/nsDocumentFragment.cpp b/mozilla/layout/base/src/nsDocumentFragment.cpp index 6686413f36c..003e2b88da6 100644 --- a/mozilla/layout/base/src/nsDocumentFragment.cpp +++ b/mozilla/layout/base/src/nsDocumentFragment.cpp @@ -213,7 +213,13 @@ public: NS_IMETHOD RangeRemove(nsIDOMRange& aRange) { return mInner.RangeRemove(aRange); } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const - { return mInner.GetRangeList(aResult); } + { return mInner.GetRangeList(aResult); } + NS_IMETHOD SetFocus(nsIPresContext* aContext) { + return mInner.SetFocus(aContext); + } + NS_IMETHOD RemoveFocus(nsIPresContext* aContext) { + return mInner.RemoveFocus(aContext); + } NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { if (!aResult) { return NS_ERROR_NULL_POINTER; diff --git a/mozilla/layout/base/src/nsFrameTraversal.cpp b/mozilla/layout/base/src/nsFrameTraversal.cpp index 882b3c87e40..8180657954d 100644 --- a/mozilla/layout/base/src/nsFrameTraversal.cpp +++ b/mozilla/layout/base/src/nsFrameTraversal.cpp @@ -80,6 +80,8 @@ class nsLeafIterator: public nsFrameIterator { public: nsLeafIterator(nsIPresContext* aPresContext, nsIFrame *start); + void SetExtensive(PRBool aExtensive) {mExtensive = aExtensive;} + PRBool GetExtensive(){return mExtensive;} private : NS_IMETHOD Next(); @@ -87,6 +89,7 @@ private : NS_IMETHOD Prev(); nsIPresContext* mPresContext; + PRBool mExtensive; }; /************IMPLEMENTATIONS**************/ @@ -107,17 +110,19 @@ NS_NewFrameTraversal(nsIBidirectionalEnumerator **aEnumerator, return NS_ERROR_OUT_OF_MEMORY; *aEnumerator = NS_STATIC_CAST(nsIBidirectionalEnumerator*, trav); NS_ADDREF(trav); + trav->SetExtensive(PR_FALSE); + } + break; + case EXTENSIVE:{ + nsLeafIterator *trav = new nsLeafIterator(aPresContext, aStart); + if (!trav) + return NS_ERROR_OUT_OF_MEMORY; + *aEnumerator = NS_STATIC_CAST(nsIBidirectionalEnumerator*, trav); + NS_ADDREF(trav); + trav->SetExtensive(PR_TRUE); } break; #if 0 - case EXTENSIVE:{ - nsExtensiveTraversal *trav = new nsExtensiveTraversal(aStart); - if (!trav) - return NS_ERROR_NOMEMORY; - *aEnumerator = NS_STATIC_CAST(nsIBidirectionalEnumerator*, trav); - NS_ADDREF(trav); - } - break; case FASTEST:{ nsFastestTraversal *trav = new nsFastestTraversal(aStart); if (!trav) @@ -210,9 +215,12 @@ nsLeafIterator::Next() nsIFrame *parent = getCurrent(); if (!parent) parent = getLast(); - while(NS_SUCCEEDED(parent->FirstChild(mPresContext, nsnull,&result)) && result) + if (!mExtensive) { - parent = result; + while(NS_SUCCEEDED(parent->FirstChild(mPresContext, nsnull,&result)) && result) + { + parent = result; + } } if (parent != getCurrent()) { @@ -235,7 +243,11 @@ nsLeafIterator::Next() break; } else + { parent = result; + if (mExtensive) + break; + } } } setCurrent(result); @@ -277,7 +289,11 @@ nsLeafIterator::Prev() break; } else + { parent = result; + if (mExtensive) + break; + } } else{ setLast(parent); @@ -286,35 +302,6 @@ nsLeafIterator::Prev() } } - -/* while(parent){ - nsIFrame *grandParent; - if (NS_SUCCEEDED(parent->GetParent(&grandParent)) && grandParent){ - nsIFrame * grandFchild; - if (NS_SUCCEEDED(grandParent->FirstChild(nsnull,&grandFchild)) && grandFchild){ - nsFrameList list(grandFchild); - if (nsnull != (result = list.GetPrevSiblingFor(parent)) ){ - parent = result; - while(NS_SUCCEEDED(parent->FirstChild(nsnull,&result)) && result){ - parent = result; - while(NS_SUCCEEDED(parent->GetNextSibling(&result)) && result){ - parent = result; - } - } - result = parent; - break; - } - else - if (NS_FAILED(parent->GetParent(&result)) || !result){ - result = nsnull; - break; - } - else - parent = result; - } - } - } - */ setCurrent(result); if (!result) setOffEdge(-1); diff --git a/mozilla/layout/base/src/nsGenericDOMDataNode.cpp b/mozilla/layout/base/src/nsGenericDOMDataNode.cpp index aefec04ae56..9e3adf8cd04 100644 --- a/mozilla/layout/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/layout/base/src/nsGenericDOMDataNode.cpp @@ -855,6 +855,18 @@ nsGenericDOMDataNode::GetRangeList(nsVoidArray*& aResult) const return NS_OK; } +nsresult +nsGenericDOMDataNode::SetFocus(nsIPresContext* aPresContext) +{ + return NS_OK; +} + +nsresult +nsGenericDOMDataNode::RemoveFocus(nsIPresContext* aPresContext) +{ + return NS_OK; +} + nsresult nsGenericDOMDataNode::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, size_t aInstanceSize) const diff --git a/mozilla/layout/base/src/nsGenericDOMDataNode.h b/mozilla/layout/base/src/nsGenericDOMDataNode.h index 79f6f9285ec..e8cf56e28c1 100644 --- a/mozilla/layout/base/src/nsGenericDOMDataNode.h +++ b/mozilla/layout/base/src/nsGenericDOMDataNode.h @@ -197,6 +197,9 @@ struct nsGenericDOMDataNode { nsresult RangeAdd(nsIDOMRange& aRange); nsresult RangeRemove(nsIDOMRange& aRange); nsresult GetRangeList(nsVoidArray*& aResult) const; + nsresult SetFocus(nsIPresContext *aPresContext); + nsresult RemoveFocus(nsIPresContext *aPresContext); + nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, size_t aInstanceSize) const; @@ -424,7 +427,7 @@ struct nsGenericDOMDataNode { return _g.SetScriptObject(aScriptObject); \ } -#define NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(_g) \ +#define NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ return _g.GetDocument(aResult); \ } \ @@ -524,7 +527,13 @@ struct nsGenericDOMDataNode { } \ NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ - } + } \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } /** * Implement the nsIDOMText API by forwarding the methods to a diff --git a/mozilla/layout/base/src/nsGenericElement.cpp b/mozilla/layout/base/src/nsGenericElement.cpp index 1b8229d4787..f0058a23065 100644 --- a/mozilla/layout/base/src/nsGenericElement.cpp +++ b/mozilla/layout/base/src/nsGenericElement.cpp @@ -1133,6 +1133,18 @@ nsGenericElement::GetRangeList(nsVoidArray*& aResult) const return NS_OK; } +nsresult +nsGenericElement::SetFocus(nsIPresContext* aPresContext) +{ + return NS_OK; +} + +nsresult +nsGenericElement::RemoveFocus(nsIPresContext* aPresContext) +{ + return NS_OK; +} + nsresult nsGenericElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, size_t aInstanceSize) const diff --git a/mozilla/layout/base/src/nsGenericElement.h b/mozilla/layout/base/src/nsGenericElement.h index 3fd8c2e2cc5..1e9a1f7d9fa 100644 --- a/mozilla/layout/base/src/nsGenericElement.h +++ b/mozilla/layout/base/src/nsGenericElement.h @@ -184,6 +184,8 @@ public: nsresult RangeAdd(nsIDOMRange& aRange); nsresult RangeRemove(nsIDOMRange& aRange); nsresult GetRangeList(nsVoidArray*& aResult) const; + nsresult SetFocus(nsIPresContext* aContext); + nsresult RemoveFocus(nsIPresContext* aContext); nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, size_t aInstanceSize) const; @@ -599,7 +601,13 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ } \ - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } #define NS_IMPL_ICONTENT_NO_SETPARENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -708,7 +716,13 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ } \ - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } #define NS_IMPL_ICONTENT_NO_SETDOCUMENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -817,7 +831,13 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ } \ - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } #define NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ @@ -924,8 +944,236 @@ public: NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ return _g.GetRangeList(aResult); \ } \ - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ + return _g.SetFocus(aPresContext); \ + } \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ + return _g.RemoveFocus(aPresContext); \ + } +#define NS_IMPL_ICONTENT_NO_FOCUS_USING_GENERIC(_g) \ + NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ + return _g.GetDocument(aResult); \ + } \ + NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep) { \ + return _g.SetDocument(aDocument, aDeep); \ + } \ + NS_IMETHOD GetParent(nsIContent*& aResult) const { \ + return _g.GetParent(aResult); \ + } \ + NS_IMETHOD SetParent(nsIContent* aParent) { \ + return _g.SetParent(aParent); \ + } \ + NS_IMETHOD CanContainChildren(PRBool& aResult) const { \ + return _g.CanContainChildren(aResult); \ + } \ + NS_IMETHOD ChildCount(PRInt32& aResult) const { \ + return _g.ChildCount(aResult); \ + } \ + NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { \ + return _g.ChildAt(aIndex, aResult); \ + } \ + NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { \ + return _g.IndexOf(aPossibleChild, aResult); \ + } \ + NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, \ + PRBool aNotify) { \ + return _g.InsertChildAt(aKid, aIndex, aNotify); \ + } \ + NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, \ + PRBool aNotify) { \ + return _g.ReplaceChildAt(aKid, aIndex, aNotify); \ + } \ + NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { \ + return _g.AppendChildTo(aKid, aNotify); \ + } \ + NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { \ + return _g.RemoveChildAt(aIndex, aNotify); \ + } \ + NS_IMETHOD IsSynthetic(PRBool& aResult) { \ + return _g.IsSynthetic(aResult); \ + } \ + NS_IMETHOD GetNameSpaceID(PRInt32& aResult) const { \ + return _g.GetNameSpaceID(aResult); \ + } \ + NS_IMETHOD GetTag(nsIAtom*& aResult) const { \ + return _g.GetTag(aResult); \ + } \ + NS_IMETHOD ParseAttributeString(const nsString& aStr, \ + nsIAtom*& aName, \ + PRInt32& aNameSpaceID) { \ + return _g.ParseAttributeString(aStr, aName, aNameSpaceID); \ + } \ + NS_IMETHOD GetNameSpacePrefixFromId(PRInt32 aNameSpaceID, \ + nsIAtom*& aPrefix) { \ + return _g.GetNameSpacePrefixFromId(aNameSpaceID, aPrefix); \ + } \ + NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, \ + const nsString& aValue, PRBool aNotify) { \ + return _g.SetAttribute(aNameSpaceID, aName, aValue, aNotify); \ + } \ + NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, \ + nsString& aResult) const { \ + return _g.GetAttribute(aNameSpaceID, aName, aResult); \ + } \ + NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, \ + PRBool aNotify) { \ + return _g.UnsetAttribute(aNameSpaceID, aAttribute, aNotify); \ + } \ + NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, \ + PRInt32& aNameSpaceID, \ + nsIAtom*& aName) const { \ + return _g.GetAttributeNameAt(aIndex, aNameSpaceID, aName); \ + } \ + NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { \ + return _g.GetAttributeCount(aResult); \ + } \ + NS_IMETHOD List(FILE* out, PRInt32 aIndent) const { \ + return _g.List(out, aIndent); \ + } \ + NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const { \ + return _g.BeginConvertToXIF(aConverter); \ + } \ + NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const { \ + return _g.ConvertContentToXIF(aConverter); \ + } \ + NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const { \ + return _g.FinishConvertToXIF(aConverter); \ + } \ + NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, \ + nsEvent* aEvent, \ + nsIDOMEvent** aDOMEvent, \ + PRUint32 aFlags, \ + nsEventStatus* aEventStatus); \ + NS_IMETHOD GetContentID(PRUint32* aID) { \ + return _g.GetContentID(aID); \ + } \ + NS_IMETHOD SetContentID(PRUint32 aID) { \ + return _g.SetContentID(aID); \ + } \ + NS_IMETHOD RangeAdd(nsIDOMRange& aRange) { \ + return _g.RangeAdd(aRange); \ + } \ + NS_IMETHOD RangeRemove(nsIDOMRange& aRange) { \ + return _g.RangeRemove(aRange); \ + } \ + NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ + return _g.GetRangeList(aResult); \ + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext); \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); + +#define NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(_g) \ + NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ + return _g.GetDocument(aResult); \ + } \ + NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep); \ + NS_IMETHOD GetParent(nsIContent*& aResult) const { \ + return _g.GetParent(aResult); \ + } \ + NS_IMETHOD SetParent(nsIContent* aParent); \ + NS_IMETHOD CanContainChildren(PRBool& aResult) const { \ + return _g.CanContainChildren(aResult); \ + } \ + NS_IMETHOD ChildCount(PRInt32& aResult) const { \ + return _g.ChildCount(aResult); \ + } \ + NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { \ + return _g.ChildAt(aIndex, aResult); \ + } \ + NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { \ + return _g.IndexOf(aPossibleChild, aResult); \ + } \ + NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, \ + PRBool aNotify) { \ + return _g.InsertChildAt(aKid, aIndex, aNotify); \ + } \ + NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, \ + PRBool aNotify) { \ + return _g.ReplaceChildAt(aKid, aIndex, aNotify); \ + } \ + NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { \ + return _g.AppendChildTo(aKid, aNotify); \ + } \ + NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { \ + return _g.RemoveChildAt(aIndex, aNotify); \ + } \ + NS_IMETHOD IsSynthetic(PRBool& aResult) { \ + return _g.IsSynthetic(aResult); \ + } \ + NS_IMETHOD GetNameSpaceID(PRInt32& aResult) const { \ + return _g.GetNameSpaceID(aResult); \ + } \ + NS_IMETHOD GetTag(nsIAtom*& aResult) const { \ + return _g.GetTag(aResult); \ + } \ + NS_IMETHOD ParseAttributeString(const nsString& aStr, \ + nsIAtom*& aName, \ + PRInt32& aNameSpaceID) { \ + return _g.ParseAttributeString(aStr, aName, aNameSpaceID); \ + } \ + NS_IMETHOD GetNameSpacePrefixFromId(PRInt32 aNameSpaceID, \ + nsIAtom*& aPrefix) { \ + return _g.GetNameSpacePrefixFromId(aNameSpaceID, aPrefix); \ + } \ + NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, \ + const nsString& aValue, PRBool aNotify) { \ + return _g.SetAttribute(aNameSpaceID, aName, aValue, aNotify); \ + } \ + NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, \ + nsString& aResult) const { \ + return _g.GetAttribute(aNameSpaceID, aName, aResult); \ + } \ + NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, \ + PRBool aNotify) { \ + return _g.UnsetAttribute(aNameSpaceID, aAttribute, aNotify); \ + } \ + NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, \ + PRInt32& aNameSpaceID, \ + nsIAtom*& aName) const { \ + return _g.GetAttributeNameAt(aIndex, aNameSpaceID, aName); \ + } \ + NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { \ + return _g.GetAttributeCount(aResult); \ + } \ + NS_IMETHOD List(FILE* out, PRInt32 aIndent) const { \ + return _g.List(out, aIndent); \ + } \ + NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const { \ + return _g.BeginConvertToXIF(aConverter); \ + } \ + NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const { \ + return _g.ConvertContentToXIF(aConverter); \ + } \ + NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const { \ + return _g.FinishConvertToXIF(aConverter); \ + } \ + NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, \ + nsEvent* aEvent, \ + nsIDOMEvent** aDOMEvent, \ + PRUint32 aFlags, \ + nsEventStatus* aEventStatus); \ + NS_IMETHOD GetContentID(PRUint32* aID) { \ + return _g.GetContentID(aID); \ + } \ + NS_IMETHOD SetContentID(PRUint32 aID) { \ + return _g.SetContentID(aID); \ + } \ + NS_IMETHOD RangeAdd(nsIDOMRange& aRange) { \ + return _g.RangeAdd(aRange); \ + } \ + NS_IMETHOD RangeRemove(nsIDOMRange& aRange) { \ + return _g.RangeRemove(aRange); \ + } \ + NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ + return _g.GetRangeList(aResult); \ + } \ + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; \ + NS_IMETHOD SetFocus(nsIPresContext* aPresContext); \ + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); + /** * Implement the nsIScriptObjectOwner API by forwarding the methods to a * generic content object diff --git a/mozilla/layout/events/public/nsIEventStateManager.h b/mozilla/layout/events/public/nsIEventStateManager.h index 72bb503b34f..b0badce6fc0 100644 --- a/mozilla/layout/events/public/nsIEventStateManager.h +++ b/mozilla/layout/events/public/nsIEventStateManager.h @@ -73,9 +73,6 @@ public: NS_IMETHOD GetFocusedContent(nsIContent **aContent) = 0; NS_IMETHOD SetFocusedContent(nsIContent* aContent) = 0; - // Cross ESM methods, doesn't matter what instance you call it from - NS_IMETHOD GetFocusedEventTarget(nsIFrame **aFrame) = 0; - // This is an experiement and may be temporary NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) = 0; diff --git a/mozilla/layout/events/src/nsEventStateManager.cpp b/mozilla/layout/events/src/nsEventStateManager.cpp index 8ee9a434c7c..f2c09ef9b74 100644 --- a/mozilla/layout/events/src/nsEventStateManager.cpp +++ b/mozilla/layout/events/src/nsEventStateManager.cpp @@ -43,7 +43,6 @@ #include "nsINameSpaceManager.h" // for kNameSpaceID_HTML #include "nsIWebShell.h" #include "nsIBaseWindow.h" -#include "nsIFocusableContent.h" #include "nsIScrollableView.h" #include "nsIDOMSelection.h" #include "nsIFrameSelection.h" @@ -54,6 +53,8 @@ #include "nsIGfxTextControlFrame.h" #include "nsIDOMWindow.h" #include "nsPIDOMWindow.h" +#include "nsIEnumerator.h" +#include "nsFrameTraversal.h" #include "nsIServiceManager.h" #include "nsIPref.h" @@ -70,9 +71,6 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); -nsIFrame * gCurrentlyFocusedTargetFrame = 0; -nsIContent * gCurrentlyFocusedContent = 0; // Weak because it mirrors the strong mCurrentFocus - nsIContent * gLastFocusedContent = 0; // Strong reference nsIDocument * gLastFocusedDocument = 0; // Strong reference nsIPresContext* gLastFocusedPresContext = 0; // Weak reference @@ -376,43 +374,42 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, } } - if (!focusedWindow) { - nsCOMPtr globalObject; - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - focusedWindow = do_QueryInterface(globalObject); + if (!focusedWindow) { + nsCOMPtr globalObject; + mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); + focusedWindow = do_QueryInterface(globalObject); } - // Sill no focused XULDocument, that is bad - if(!xulDoc && focusedWindow) - { - nsCOMPtr privateWindow = do_QueryInterface(focusedWindow); + // Sill no focused XULDocument, that is bad + if(!xulDoc && focusedWindow) + { + nsCOMPtr privateWindow = do_QueryInterface(focusedWindow); if(privateWindow){ - nsCOMPtr privateRootWindow; - privateWindow->GetPrivateRoot(getter_AddRefs(privateRootWindow)); - if(privateRootWindow){ - nsCOMPtr privateParentDoc; - privateRootWindow->GetDocument(getter_AddRefs(privateParentDoc)); + nsCOMPtr privateRootWindow; + privateWindow->GetPrivateRoot(getter_AddRefs(privateRootWindow)); + if(privateRootWindow) { + nsCOMPtr privateParentDoc; + privateRootWindow->GetDocument(getter_AddRefs(privateParentDoc)); xulDoc = do_QueryInterface(privateParentDoc); - } - } - - if (xulDoc) { + } + } + + if (xulDoc) { // See if we have a command dispatcher attached. xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher)); if (commandDispatcher) { // Obtain focus info from the command dispatcher. commandDispatcher->GetFocusedWindow(getter_AddRefs(focusedWindow)); commandDispatcher->GetFocusedElement(getter_AddRefs(focusedElement)); - } - } - } + } + } + } // Focus the DOM window. focusedWindow->Focus(); if (focusedElement) { - // Focus the content node. - nsCOMPtr focusContent = do_QueryInterface(focusedElement); + nsCOMPtr focusContent = do_QueryInterface(focusedElement); nsCOMPtr domDoc; nsCOMPtr document; focusedWindow->GetDocument(getter_AddRefs(domDoc)); @@ -429,7 +426,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, commandDispatcher->SetSuppressFocus(PR_FALSE); // Unsuppress and let the command dispatcher listen again. } } - break; + break; case NS_DEACTIVATE: { @@ -678,74 +675,32 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, if (nsEventStatus_eConsumeNoDefault != *aStatus) { nsCOMPtr newFocus; - mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(newFocus)); - nsCOMPtr focusable; - - if (newFocus) { - // Look for the nearest enclosing focusable content. - nsCOMPtr current = newFocus; - while (current) { - focusable = do_QueryInterface(current); - if (focusable) - break; - - nsCOMPtr parent; - current->GetParent(*getter_AddRefs(parent)); - current = parent; - } - - // if a focusable piece of content is an anonymous node - // weed to find the parent and have the parent be the - // new focusable node - // - // We fist to check here to see if the focused content - // is anonymous content - if (focusable) { - nsCOMPtr parent; - current->GetParent(*getter_AddRefs(parent)); - NS_ASSERTION(parent.get(), "parent is null. this should not happen."); - PRInt32 numChilds; - parent->ChildCount(numChilds); - PRInt32 i; - PRBool isChild = PR_FALSE; - for (i=0;i child; - parent->ChildAt(i, *getter_AddRefs(child)); - if (child.get() == current.get()) { - isChild = PR_TRUE; - break; - } - } - // if it isn't a child of the parent, then it is anonynous content - // Now, go up the parent list to find a focusable content node - if (!isChild) { - current = parent; - while (current) { - focusable = do_QueryInterface(current); - if (focusable) - break; - - nsCOMPtr tempParent; - current->GetParent(*getter_AddRefs(tempParent)); - current = tempParent; - } - } - // now we ned to get the content node's frame and reset - // the mCurrentTarget target - nsCOMPtr shell; - if (mPresContext) { - nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv) && shell){ - shell->GetPrimaryFrameFor(current, &mCurrentTarget); - } - } - // now adjust the value for the "newFocus" - newFocus = current; - } - - nsCOMPtr content = do_QueryInterface(focusable); - ChangeFocus(content, mCurrentTarget, PR_TRUE); + PRBool suppressBlur = PR_FALSE; + if (mCurrentTarget) { + mCurrentTarget->GetContentForEvent(mPresContext, aEvent, getter_AddRefs(newFocus)); + const nsStyleUserInterface* ui; + mCurrentTarget->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));; + suppressBlur = (ui->mUserFocus == NS_STYLE_USER_FOCUS_IGNORE); } + + nsIFrame* currFrame = mCurrentTarget; + // Look for the nearest enclosing focusable frame. + while (currFrame) { + const nsStyleUserInterface* ui; + currFrame->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));; + if ((ui->mUserFocus != NS_STYLE_USER_FOCUS_IGNORE) && + (ui->mUserFocus != NS_STYLE_USER_FOCUS_NONE)) { + currFrame->GetContent(getter_AddRefs(newFocus)); + break; + } + currFrame->GetParent(&currFrame); + } + + if (newFocus && currFrame) + ChangeFocus(newFocus, currFrame, PR_TRUE); + else if (!suppressBlur) + SetContentState(nsnull, NS_EVENT_STATE_FOCUS); + SetContentState(newFocus, NS_EVENT_STATE_ACTIVE); } } @@ -1607,34 +1562,7 @@ nsEventStateManager::CheckForAndDispatchClick(nsIPresContext* aPresContext, PRBool nsEventStateManager::ChangeFocus(nsIContent* aFocusContent, nsIFrame* aTargetFrame, PRBool aSetFocus) { - nsCOMPtr focusChange = do_QueryInterface(aFocusContent); - - if (aTargetFrame) { - - PRBool suppressBlurAndFocus = PR_FALSE; - nsCOMPtr context; - aTargetFrame->GetStyleContext(getter_AddRefs(context)); - - const nsStyleUserInterface* styleStruct = (const nsStyleUserInterface*)context->GetStyleData(eStyleStruct_UserInterface); - if (NS_STYLE_USER_FOCUS_IGNORE == styleStruct->mUserFocus) { - // we want to surpress the blur and the following focus - suppressBlurAndFocus = PR_TRUE; - } - - if(!suppressBlurAndFocus) { - - if (focusChange) { - focusChange->SetFocus(mPresContext); - } - else { - SendFocusBlur(mPresContext, nsnull); - } - } - } - else { - printf("OH MY GOD!\n"); - } - + aFocusContent->SetFocus(mPresContext); return PR_FALSE; } @@ -1666,9 +1594,21 @@ nsEventStateManager::ShiftFocus(PRBool forward) topOfDoc = PR_TRUE; } - nsIContent* next = GetNextTabbableContent(mCurrentFocus, nsnull, mCurrentFocus, forward); + nsIFrame* primaryFrame; + nsCOMPtr shell; + if (mPresContext) { + nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv) && shell){ + shell->GetPrimaryFrameFor(mCurrentFocus, &primaryFrame); + } + } - if (nsnull == next) { + nsCOMPtr rootContent = getter_AddRefs(mDocument->GetRootContent()); + + nsCOMPtr next; + GetNextTabbableContent(rootContent, primaryFrame, forward, getter_AddRefs(next)); + + if (!next) { PRBool focusTaken = PR_FALSE; SetContentState(nsnull, NS_EVENT_STATE_FOCUS); @@ -1689,193 +1629,174 @@ nsEventStateManager::ShiftFocus(PRBool forward) // Now we need to get the content node's frame and reset // the mCurrentTarget target. Otherwise the focus // code will be slightly out of sync (with regards to - // focusing widgets within the current target). - nsCOMPtr shell; - if (mPresContext) { - nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv) && shell){ - shell->GetPrimaryFrameFor(next, &mCurrentTarget); - } - } + // focusing widgets within the current target) + if (shell) + shell->GetPrimaryFrameFor(next, &mCurrentTarget); + ChangeFocus(next, mCurrentTarget, PR_TRUE); NS_IF_RELEASE(mCurrentFocus); mCurrentFocus = next; + NS_IF_ADDREF(mCurrentFocus); } /* * At some point this will need to be linked into HTML 4.0 tabindex */ -nsIContent* -nsEventStateManager::GetNextTabbableContent(nsIContent* aParent, nsIContent* aChild, nsIContent* aTop, PRBool forward) + +NS_IMETHODIMP +nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* aFrame, PRBool forward, + nsIContent** aResult) { - PRInt32 count, index; - aParent->ChildCount(count); + *aResult = nsnull; - if (nsnull != aChild) { - aParent->IndexOf(aChild, index); - index += forward ? 1 : -1; - } - else { - index = forward ? 0 : count-1; - } + nsCOMPtr frameTraversal; + nsresult result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal), EXTENSIVE, + mPresContext, aFrame); - for (;index < count && index >= 0;index += forward ? 1 : -1) { - nsIContent* child; + if (NS_FAILED(result)) + return NS_OK; - aParent->ChildAt(index, child); - nsIContent* content = GetNextTabbableContent(child, nsnull, aTop, forward); - if (content != nsnull) { - NS_IF_RELEASE(child); - return content; - } - if (nsnull != child) { + if (forward) + frameTraversal->Next(); + else frameTraversal->Prev(); + + nsISupports* currentItem; + frameTraversal->CurrentItem(¤tItem); + nsIFrame* currentFrame = (nsIFrame*)currentItem; + + while (currentFrame) { + nsCOMPtr child; + currentFrame->GetContent(getter_AddRefs(child)); + + const nsStyleDisplay* disp; + currentFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)disp)); + + const nsStyleUserInterface* ui; + currentFrame->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));; + + nsCOMPtr element(do_QueryInterface(child)); + + // if collapsed or hidden, we don't get tabbed into. + if ((disp->mVisible != NS_STYLE_VISIBILITY_COLLAPSE) && + (disp->mVisible != NS_STYLE_VISIBILITY_HIDDEN) && + (ui->mUserFocus != NS_STYLE_USER_FOCUS_IGNORE) && + (ui->mUserFocus != NS_STYLE_USER_FOCUS_NONE) && element) { nsCOMPtr tag; PRInt32 tabIndex = -1; PRBool disabled = PR_TRUE; PRBool hidden = PR_FALSE; child->GetTag(*getter_AddRefs(tag)); - if (nsHTMLAtoms::input==tag.get()) { - nsIDOMHTMLInputElement *nextInput; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLInputElement), - (void **)&nextInput)) { - nextInput->GetDisabled(&disabled); - nextInput->GetTabIndex(&tabIndex); + nsCOMPtr htmlElement(do_QueryInterface(child)); + if (htmlElement) { + if (nsHTMLAtoms::input==tag.get()) { + nsCOMPtr nextInput(do_QueryInterface(child)); + if (nextInput) { + nextInput->GetDisabled(&disabled); + nextInput->GetTabIndex(&tabIndex); - nsAutoString type; - nextInput->GetType(type); - if (type.EqualsIgnoreCase("hidden")) { - hidden = PR_TRUE; + nsAutoString type; + nextInput->GetType(type); + if (type.EqualsIgnoreCase("hidden")) { + hidden = PR_TRUE; + } } - NS_RELEASE(nextInput); } - } - else if (nsHTMLAtoms::select==tag.get()) { - nsIDOMHTMLSelectElement *nextSelect; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement), - (void **)&nextSelect)) { - nextSelect->GetDisabled(&disabled); - nextSelect->GetTabIndex(&tabIndex); - NS_RELEASE(nextSelect); + else if (nsHTMLAtoms::select==tag.get()) { + nsCOMPtr nextSelect(do_QueryInterface(child)); + if (nextSelect) { + nextSelect->GetDisabled(&disabled); + nextSelect->GetTabIndex(&tabIndex); + } } - } - else if (nsHTMLAtoms::textarea==tag.get()) { - nsIDOMHTMLTextAreaElement *nextTextArea; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLTextAreaElement),(void **)&nextTextArea)) { - nextTextArea->GetDisabled(&disabled); - nextTextArea->GetTabIndex(&tabIndex); - NS_RELEASE(nextTextArea); + else if (nsHTMLAtoms::textarea==tag.get()) { + nsCOMPtr nextTextArea(do_QueryInterface(child)); + if (nextTextArea) { + nextTextArea->GetDisabled(&disabled); + nextTextArea->GetTabIndex(&tabIndex); + } } - - } - else if(nsHTMLAtoms::a==tag.get()) { - nsIDOMHTMLAnchorElement *nextAnchor; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLAnchorElement), - (void **)&nextAnchor)) { - nextAnchor->GetTabIndex(&tabIndex); - NS_RELEASE(nextAnchor); + else if(nsHTMLAtoms::a==tag.get()) { + nsCOMPtr nextAnchor(do_QueryInterface(child)); + if (nextAnchor) + nextAnchor->GetTabIndex(&tabIndex); + disabled = PR_FALSE; } - disabled = PR_FALSE; - } - else if(nsHTMLAtoms::button==tag.get()) { - nsIDOMHTMLButtonElement *nextButton; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLButtonElement), - (void **)&nextButton)) { - nextButton->GetTabIndex(&tabIndex); - nextButton->GetDisabled(&disabled); - NS_RELEASE(nextButton); + else if(nsHTMLAtoms::button==tag.get()) { + nsCOMPtr nextButton(do_QueryInterface(child)); + if (nextButton) { + nextButton->GetTabIndex(&tabIndex); + nextButton->GetDisabled(&disabled); + } } - } - else if(nsHTMLAtoms::area==tag.get()) { - nsIDOMHTMLAreaElement *nextArea; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLAreaElement), - (void **)&nextArea)) { - nextArea->GetTabIndex(&tabIndex); - NS_RELEASE(nextArea); + else if(nsHTMLAtoms::area==tag.get()) { + nsCOMPtr nextArea(do_QueryInterface(child)); + if (nextArea) + nextArea->GetTabIndex(&tabIndex); + disabled = PR_FALSE; } - disabled = PR_FALSE; - } - else if(nsHTMLAtoms::object==tag.get()) { - nsIDOMHTMLObjectElement *nextObject; - if (NS_OK == child->QueryInterface(NS_GET_IID(nsIDOMHTMLObjectElement), - (void **)&nextObject)) { - nextObject->GetTabIndex(&tabIndex); - NS_RELEASE(nextObject); + else if(nsHTMLAtoms::object==tag.get()) { + nsCOMPtr nextObject(do_QueryInterface(child)); + if (nextObject) + nextObject->GetTabIndex(&tabIndex); + disabled = PR_FALSE; } - disabled = PR_FALSE; } else { - // QI to nsIFocusableContent - nsCOMPtr focusable(do_QueryInterface(child)); - if (focusable) { - nsAutoString value; - child->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, value); - if (!value.EqualsWithConversion("true")) - disabled = PR_FALSE; + nsAutoString value; + child->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, value); + nsAutoString tabStr; + child->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::tabindex, tabStr); + if (tabStr != "") { + PRInt32 errorCode; + tabIndex = tabStr.ToInteger(&errorCode); } + if (!value.EqualsWithConversion("true")) + disabled = PR_FALSE; } - // Get the primary frame for the widget. We don't tab into anything - // that doesn't have a frame. - nsCOMPtr shell; - if (mPresContext) { - nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv) && shell){ - nsIFrame* potentialFrame; - shell->GetPrimaryFrameFor(child, &potentialFrame); - if (!potentialFrame) - hidden = PR_TRUE; - } - } - //TabIndex not set (-1) treated at same level as set to 0 tabIndex = tabIndex < 0 ? 0 : tabIndex; if (!disabled && !hidden && mCurrentTabIndex == tabIndex) { - return child; + *aResult = child; + NS_IF_ADDREF(*aResult); + return NS_OK; } - NS_RELEASE(child); } + + if (forward) + frameTraversal->Next(); + else frameTraversal->Prev(); + + frameTraversal->CurrentItem(¤tItem); + currentFrame = (nsIFrame*)currentItem; } - if (aParent == aTop) { - nsIContent* nextParent; - aParent->GetParent(nextParent); - if (nsnull != nextParent) { - nsIContent* content = GetNextTabbableContent(nextParent, aParent, nextParent, forward); - NS_RELEASE(nextParent); - return content; - } - //Reached end of document - else { - //If already at lowest priority tab (0), end - if (((forward) && (0 == mCurrentTabIndex)) || - ((!forward) && (1 == mCurrentTabIndex))) { - return nsnull; - } - //else continue looking for next highest priority tab - mCurrentTabIndex = GetNextTabIndex(aParent, forward); - nsIContent* content = GetNextTabbableContent(aParent, nsnull, aParent, forward); - return content; - } + // Reached end or beginning of document + //If already at lowest priority tab (0), end + if (((forward) && (0 == mCurrentTabIndex)) || + ((!forward) && (1 == mCurrentTabIndex))) { + return NS_OK; } - - return nsnull; + //else continue looking for next highest priority tab + mCurrentTabIndex = GetNextTabIndex(aRootContent, forward); + return GetNextTabbableContent(aRootContent, nsnull, forward, aResult); } PRInt32 nsEventStateManager::GetNextTabIndex(nsIContent* aParent, PRBool forward) { PRInt32 count, tabIndex, childTabIndex; - nsIContent* child; + nsCOMPtr child; aParent->ChildCount(count); if (forward) { tabIndex = 0; for (PRInt32 index = 0; index < count; index++) { - aParent->ChildAt(index, child); + aParent->ChildAt(index, *getter_AddRefs(child)); childTabIndex = GetNextTabIndex(child, forward); if (childTabIndex > mCurrentTabIndex && childTabIndex != tabIndex) { tabIndex = (tabIndex == 0 || childTabIndex < tabIndex) ? childTabIndex : tabIndex; @@ -1887,13 +1808,12 @@ nsEventStateManager::GetNextTabIndex(nsIContent* aParent, PRBool forward) if (NS_OK == ec && val > mCurrentTabIndex && val != tabIndex) { tabIndex = (tabIndex == 0 || val < tabIndex) ? val : tabIndex; } - NS_RELEASE(child); } } else { /* !forward */ tabIndex = 1; for (PRInt32 index = 0; index < count; index++) { - aParent->ChildAt(index, child); + aParent->ChildAt(index, *getter_AddRefs(child)); childTabIndex = GetNextTabIndex(child, forward); if ((mCurrentTabIndex==0 && childTabIndex > tabIndex) || (childTabIndex < mCurrentTabIndex && childTabIndex > tabIndex)) { @@ -1909,7 +1829,6 @@ nsEventStateManager::GetNextTabIndex(nsIContent* aParent, PRBool forward) tabIndex = val; } } - NS_RELEASE(child); } } return tabIndex; @@ -1933,26 +1852,6 @@ nsEventStateManager::GetEventTarget(nsIFrame **aFrame) return NS_OK; } -// This API crosses ESM instances to give the currently focused frame, no matter what ESM instace -// you call it from. -NS_IMETHODIMP -nsEventStateManager::GetFocusedEventTarget(nsIFrame **aFrame) -{ - if (!gCurrentlyFocusedTargetFrame && gCurrentlyFocusedContent && gLastFocusedPresContext) { - nsCOMPtr shell; - if (gLastFocusedPresContext) { - nsresult rv = gLastFocusedPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv) && shell){ - shell->GetPrimaryFrameFor(gCurrentlyFocusedContent, &gCurrentlyFocusedTargetFrame); - } - } - } - - *aFrame = gCurrentlyFocusedTargetFrame; - return NS_OK; -} - - NS_IMETHODIMP nsEventStateManager::GetEventTargetContent(nsEvent* aEvent, nsIContent** aContent) { @@ -2040,21 +1939,16 @@ nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState) } if ((aState & NS_EVENT_STATE_FOCUS)) { - if (aContent == mCurrentFocus) { + if (aContent && (aContent == mCurrentFocus)) { // gLastFocusedDocument appears to always be correct, that is why // I'm not setting it here. This is to catch an edge case. NS_IF_RELEASE(gLastFocusedContent); gLastFocusedContent = mCurrentFocus; NS_IF_ADDREF(gLastFocusedContent); } else { - SendFocusBlur(mPresContext, aContent); - - //transferring ref to notifyContent from mCurrentFocus notifyContent[3] = mCurrentFocus; - mCurrentFocus = aContent; NS_IF_ADDREF(mCurrentFocus); - - gCurrentlyFocusedContent = mCurrentFocus; + SendFocusBlur(mPresContext, aContent); } } @@ -2144,24 +2038,9 @@ nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState) NS_IMETHODIMP nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aContent) { - //PRBool suppressBlurAndFocus = PR_FALSE; - - if(mCurrentTarget) { - nsCOMPtr context; - mCurrentTarget->GetStyleContext(getter_AddRefs(context)); - if(!context) return NS_OK; - - - const nsStyleUserInterface* styleStruct = (const nsStyleUserInterface*)context->GetStyleData(eStyleStruct_UserInterface); - if (NS_STYLE_USER_FOCUS_IGNORE == styleStruct->mUserFocus) { - // we want to suppress the blur and the following focus - return NS_OK; - } - } - nsCOMPtr presShell; aPresContext->GetShell(getter_AddRefs(presShell)); - + if (nsnull != gLastFocusedPresContext) { if (gLastFocusedContent && gLastFocusedContent != mFirstBlurEvent) { @@ -2258,10 +2137,6 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo event.eventStructType = NS_EVENT; event.message = NS_FOCUS_CONTENT; - NS_IF_RELEASE(mCurrentFocus); - mCurrentFocus = aContent; - NS_IF_ADDREF(mCurrentFocus); - if (nsnull != mPresContext) { aContent->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } @@ -2278,9 +2153,11 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo } } - // XXx The following line could be bad in the case where a - // parent element is really the one with the focus. - nsIFrame * currentFocusFrame = mCurrentTarget; + nsIFrame * currentFocusFrame = nsnull; + if (mCurrentFocus) + presShell->GetPrimaryFrameFor(mCurrentFocus, ¤tFocusFrame); + if (!currentFocusFrame) + currentFocusFrame = mCurrentTarget; // Find the window that this frame is in and // make sure it has focus diff --git a/mozilla/layout/events/src/nsEventStateManager.h b/mozilla/layout/events/src/nsEventStateManager.h index 4409e27b73c..af93e6eb5c9 100644 --- a/mozilla/layout/events/src/nsEventStateManager.h +++ b/mozilla/layout/events/src/nsEventStateManager.h @@ -90,9 +90,6 @@ public: NS_IMETHOD GetFocusedContent(nsIContent **aContent); NS_IMETHOD SetFocusedContent(nsIContent* aContent); - // Cross ESM methods - NS_IMETHOD GetFocusedEventTarget(nsIFrame **aFrame); - // This is an experiement and may be temporary NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) { mConsumeFocusEvents = aDoConsume; return NS_OK; } @@ -108,7 +105,7 @@ protected: NS_IMETHOD CheckForAndDispatchClick(nsIPresContext* aPresContext, nsMouseEvent *aEvent, nsEventStatus* aStatus); PRBool ChangeFocus(nsIContent* aFocus, nsIFrame* aFocusFrame, PRBool aSetFocus); void ShiftFocus(PRBool foward); - nsIContent* GetNextTabbableContent(nsIContent* aParent, nsIContent* aChild, nsIContent* aTop, PRBool foward); + NS_IMETHOD GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* aFrame, PRBool foward, nsIContent** aResult); PRInt32 GetNextTabIndex(nsIContent* aParent, PRBool foward); NS_IMETHOD SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aContent); PRBool CheckDisabled(nsIContent* aContent); diff --git a/mozilla/layout/forms/nsFormControlFrame.h b/mozilla/layout/forms/nsFormControlFrame.h index 5bdb8453b4f..e4dc50bc152 100644 --- a/mozilla/layout/forms/nsFormControlFrame.h +++ b/mozilla/layout/forms/nsFormControlFrame.h @@ -38,7 +38,6 @@ class nsIView; class nsIPresContext; class nsStyleCoord; class nsFormFrame; -class nsIFocusableContent; #define CSS_NOTSET -1 #define ATTR_NOTSET -1 diff --git a/mozilla/layout/html/content/public/MANIFEST b/mozilla/layout/html/content/public/MANIFEST index bff7f373fd2..3948b65ce20 100644 --- a/mozilla/layout/html/content/public/MANIFEST +++ b/mozilla/layout/html/content/public/MANIFEST @@ -1,4 +1,3 @@ -nsIFocusableContent.h nsIForm.h nsIFormControl.h nsISelectElement.h diff --git a/mozilla/layout/html/content/public/Makefile.in b/mozilla/layout/html/content/public/Makefile.in index 395432ce998..7342f9a83e0 100644 --- a/mozilla/layout/html/content/public/Makefile.in +++ b/mozilla/layout/html/content/public/Makefile.in @@ -31,7 +31,6 @@ MODULE = layout EXPORTS = \ nsIFormControl.h \ nsIForm.h \ - nsIFocusableContent.h \ nsISelectElement.h \ $(NULL) diff --git a/mozilla/layout/html/content/public/makefile.win b/mozilla/layout/html/content/public/makefile.win index 002a8a0ff3f..72f2297df0a 100644 --- a/mozilla/layout/html/content/public/makefile.win +++ b/mozilla/layout/html/content/public/makefile.win @@ -21,7 +21,7 @@ DEPTH=..\..\..\.. -EXPORTS=nsIFormControl.h nsIForm.h nsIFocusableContent.h nsISelectElement.h +EXPORTS=nsIFormControl.h nsIForm.h nsISelectElement.h MODULE=raptor diff --git a/mozilla/layout/html/content/public/nsIFocusableContent.h b/mozilla/layout/html/content/public/nsIFocusableContent.h deleted file mode 100644 index c67788a917b..00000000000 --- a/mozilla/layout/html/content/public/nsIFocusableContent.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIFocusableContent_h___ -#define nsIFocusableContent_h___ - -#include "nsISupports.h" -class nsIPresContext; - -#define NS_IFOCUSABLECONTENT_IID \ -{ 0xc5df3c30, 0xc79a, 0x11d2, \ - {0xbd, 0x94, 0x00, 0x00, 0x80, 0x5f, 0x8a, 0x81} } - -/** - * Interface which all focusable content (e.g. form elements, links - * , etc) implements in addition to their dom specific interface. - **/ -class nsIFocusableContent : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_IFOCUSABLECONTENT_IID; return iid; } - - /** - * Give focus to the content - * @param aPresContext the PesContext - * @return NS_OK - */ - NS_IMETHOD SetFocus(nsIPresContext* aPresContext) = 0; - - /** - * Remove focus to the content - * @param aPresContext the PesContext - * @return NS_OK - */ - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) = 0; - -}; - -#endif /* nsIFocusableContent_h___ */ diff --git a/mozilla/layout/html/content/src/nsAttributeContent.cpp b/mozilla/layout/html/content/src/nsAttributeContent.cpp index 6fbdaea5a6e..6dde6287b29 100644 --- a/mozilla/layout/html/content/src/nsAttributeContent.cpp +++ b/mozilla/layout/html/content/src/nsAttributeContent.cpp @@ -122,6 +122,9 @@ public: return NS_OK; } + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { return NS_OK; } + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { return NS_OK; } + NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, const nsString& aValue, PRBool aNotify) { return NS_OK; } NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRBool aNotify) { return NS_OK; } @@ -168,7 +171,7 @@ public: NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { return NS_OK; } NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { return NS_OK; } NS_IMETHOD SplitText(PRUint32 aOffset, nsIDOMText** aReturn){ return NS_OK; } - + /////////////////// // Implementation for nsITextContent NS_IMETHOD GetText(const nsTextFragment** aFragmentsResult); diff --git a/mozilla/layout/html/content/src/nsHTMLAnchorElement.cpp b/mozilla/layout/html/content/src/nsHTMLAnchorElement.cpp index 05f31cd7ce9..03d4b122683 100644 --- a/mozilla/layout/html/content/src/nsHTMLAnchorElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLAnchorElement.cpp @@ -33,7 +33,6 @@ #include "nsIPresContext.h" #include "nsIEventStateManager.h" #include "nsIURL.h" -#include "nsIFocusableContent.h" #include "nsIEventStateManager.h" #include "nsDOMEvent.h" @@ -50,13 +49,11 @@ // custom frame static NS_DEFINE_IID(kIDOMHTMLAnchorElementIID, NS_IDOMHTMLANCHORELEMENT_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); class nsHTMLAnchorElement : public nsIDOMHTMLAnchorElement, public nsIDOMNSHTMLAnchorElement, public nsIJSScriptObject, - public nsIHTMLContent, - public nsIFocusableContent + public nsIHTMLContent { public: nsHTMLAnchorElement(nsIAtom* aTag); @@ -116,15 +113,11 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_USING_GENERIC(mInner) + NS_IMPL_ICONTENT_NO_FOCUS_USING_GENERIC(mInner) // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - protected: nsGenericHTMLContainerElement mInner; }; @@ -168,11 +161,6 @@ nsHTMLAnchorElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIDOMNSHTMLAnchorElement))) { *aInstancePtr = (void*)(nsIDOMNSHTMLAnchorElement*) this; NS_ADDREF_THIS(); diff --git a/mozilla/layout/html/content/src/nsHTMLAreaElement.cpp b/mozilla/layout/html/content/src/nsHTMLAreaElement.cpp index f9de7e5f146..8167edc596f 100644 --- a/mozilla/layout/html/content/src/nsHTMLAreaElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLAreaElement.cpp @@ -31,18 +31,15 @@ #include "nsIMutableStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIFocusableContent.h" #include "nsIEventStateManager.h" #include "nsIURL.h" #include "nsNetUtil.h" static NS_DEFINE_IID(kIDOMHTMLAreaElementIID, NS_IDOMHTMLAREAELEMENT_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); class nsHTMLAreaElement : public nsIDOMHTMLAreaElement, public nsIJSScriptObject, - public nsIHTMLContent, - public nsIFocusableContent + public nsIHTMLContent { public: nsHTMLAreaElement(nsIAtom* aTag); @@ -91,15 +88,11 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_USING_GENERIC(mInner) - + NS_IMPL_ICONTENT_NO_FOCUS_USING_GENERIC(mInner) + // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - protected: nsGenericHTMLLeafElement mInner; }; @@ -143,11 +136,6 @@ nsHTMLAreaElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIDOMNSHTMLAreaElement))) { *aInstancePtr = (void*)(nsIDOMNSHTMLAreaElement*) this; NS_ADDREF_THIS(); diff --git a/mozilla/layout/html/content/src/nsHTMLButtonElement.cpp b/mozilla/layout/html/content/src/nsHTMLButtonElement.cpp index 39dfc0686df..333f2bc9a8a 100644 --- a/mozilla/layout/html/content/src/nsHTMLButtonElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLButtonElement.cpp @@ -35,7 +35,6 @@ #include "nsIFormControl.h" #include "nsIForm.h" #include "nsIURL.h" -#include "nsIFocusableContent.h" #include "nsIFormControlFrame.h" #include "nsIEventStateManager.h" @@ -43,13 +42,11 @@ #include "nsISizeOfHandler.h" static NS_DEFINE_IID(kIDOMHTMLButtonElementIID, NS_IDOMHTMLBUTTONELEMENT_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); class nsHTMLButtonElement : public nsIDOMHTMLButtonElement, public nsIJSScriptObject, public nsIHTMLContent, - public nsIFormControl, - public nsIFocusableContent + public nsIFormControl { public: nsHTMLButtonElement(nsIAtom* aTag); @@ -89,8 +86,8 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(mInner) - + NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(mInner) + // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) @@ -99,10 +96,6 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init() { return NS_OK; } - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - protected: nsGenericHTMLContainerElement mInner; nsIForm* mForm; @@ -165,11 +158,6 @@ nsHTMLButtonElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } return NS_NOINTERFACE; } diff --git a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp index c43a9b3b6ff..b85b82250f1 100644 --- a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp @@ -46,7 +46,6 @@ #include "nsIPresShell.h" #include "nsIFormControlFrame.h" #include "nsIFrame.h" -#include "nsIFocusableContent.h" #include "nsIBindableContent.h" #include "nsIXBLBinding.h" #include "nsIEventStateManager.h" @@ -66,7 +65,6 @@ static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID); static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); class nsHTMLInputElement : public nsIDOMHTMLInputElement, @@ -74,7 +72,6 @@ class nsHTMLInputElement : public nsIDOMHTMLInputElement, public nsIJSScriptObject, public nsIHTMLContent, public nsIFormControl, - public nsIFocusableContent, public nsIBindableContent { public: @@ -123,7 +120,6 @@ public: return mInner.GetElementsByTagName(aTagname, aReturn); } - // nsIDOMHTMLElement NS_IMPL_IDOMHTMLELEMENT_USING_GENERIC(mInner) @@ -178,7 +174,7 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(mInner) + NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(mInner) // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) @@ -188,10 +184,6 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init() { return NS_OK; } - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - // nsIBindableContent NS_IMETHOD SetBinding(nsIXBLBinding* aBinding); NS_IMETHOD GetBinding(nsIXBLBinding** aResult); @@ -277,11 +269,6 @@ nsHTMLInputElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIBindableContent))) { *aInstancePtr = (void*)(nsIBindableContent*) this; NS_ADDREF_THIS(); @@ -700,18 +687,17 @@ nsHTMLInputElement::Focus() NS_IMETHODIMP nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext) { - nsIEventStateManager* esm; - if (NS_OK == aPresContext->GetEventStateManager(&esm)) { - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); - NS_RELEASE(esm); - } - // first see if we are disabled or not. If disabled then do nothing. nsAutoString disabled; if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled)) { return NS_OK; } - + + nsCOMPtr esm; + if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) { + esm->SetContentState(this, NS_EVENT_STATE_FOCUS); + } + nsIFormControlFrame* formControlFrame = nsnull; nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/layout/html/content/src/nsHTMLMapElement.cpp b/mozilla/layout/html/content/src/nsHTMLMapElement.cpp index 94e4cee8d42..8b6060c18e3 100644 --- a/mozilla/layout/html/content/src/nsHTMLMapElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLMapElement.cpp @@ -174,7 +174,16 @@ public: } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); - } + } + + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { + return mInner.SetFocus(aPresContext); + } + + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { + return mInner.RemoveFocus(aPresContext); + } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; // nsIHTMLContent diff --git a/mozilla/layout/html/content/src/nsHTMLSelectElement.cpp b/mozilla/layout/html/content/src/nsHTMLSelectElement.cpp index 943048fb758..383fd60586e 100644 --- a/mozilla/layout/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLSelectElement.cpp @@ -39,7 +39,6 @@ #include "nsIForm.h" #include "nsIDOMHTMLCollection.h" #include "nsIDOMHTMLOptionElement.h" -#include "nsIFocusableContent.h" #include "nsIEventStateManager.h" #include "nsGenericDOMHTMLCollection.h" #include "nsIJSScriptObject.h" @@ -69,7 +68,6 @@ static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID); static NS_DEFINE_IID(kISelectElementIID, NS_ISELECTELEMENT_IID); static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); class nsHTMLSelectElement; @@ -128,7 +126,6 @@ class nsHTMLSelectElement : public nsIDOMHTMLSelectElement, public nsIJSScriptObject, public nsIHTMLContent, public nsIFormControl, - public nsIFocusableContent, public nsISelectElement { public: @@ -177,7 +174,7 @@ public: NS_IMETHOD NamedItem(const nsString& aName, nsIDOMNode** aReturn); // nsIContent - NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(mInner) + NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(mInner) // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) @@ -187,9 +184,6 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init(); - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - // nsISelectElement NS_IMETHOD AddOption(nsIContent* aContent); NS_IMETHOD RemoveOption(nsIContent* aContent); @@ -297,11 +291,6 @@ nsHTMLSelectElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(kISelectElementIID)) { *aInstancePtr = (void*)(nsISelectElement*) this; NS_ADDREF_THIS(); diff --git a/mozilla/layout/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/layout/html/content/src/nsHTMLTextAreaElement.cpp index 935d1d75854..3b8dc68f2d5 100644 --- a/mozilla/layout/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLTextAreaElement.cpp @@ -42,7 +42,6 @@ #include "nsIPresContext.h" #include "nsIHTMLAttributes.h" #include "nsIFormControlFrame.h" -#include "nsIFocusableContent.h" #include "nsIBindableContent.h" #include "nsIXBLBinding.h" #include "nsIEventStateManager.h" @@ -53,7 +52,6 @@ static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID); -static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); class nsHTMLTextAreaElement : public nsIDOMHTMLTextAreaElement, @@ -61,7 +59,6 @@ class nsHTMLTextAreaElement : public nsIDOMHTMLTextAreaElement, public nsIJSScriptObject, public nsIHTMLContent, public nsIFormControl, - public nsIFocusableContent, public nsIBindableContent { public: @@ -112,7 +109,7 @@ public: NS_IMPL_IJSSCRIPTOBJECT_USING_GENERIC(mInner) // nsIContent - NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_USING_GENERIC(mInner) + NS_IMPL_ICONTENT_NO_SETPARENT_NO_SETDOCUMENT_NO_FOCUS_USING_GENERIC(mInner) // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) @@ -122,10 +119,6 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init() { return NS_OK; } - // nsIFocusableContent - NS_IMETHOD SetFocus(nsIPresContext* aPresContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext); - // nsIBindableContent NS_IMETHOD SetBinding(nsIXBLBinding* aBinding); NS_IMETHOD GetBinding(nsIXBLBinding** aResult); @@ -190,11 +183,6 @@ nsHTMLTextAreaElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - else if (aIID.Equals(kIFocusableContentIID)) { - *aInstancePtr = (void*)(nsIFocusableContent*) this; - NS_ADDREF_THIS(); - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIBindableContent))) { *aInstancePtr = (void*)(nsIBindableContent*) this; NS_ADDREF_THIS(); diff --git a/mozilla/layout/html/document/src/html.css b/mozilla/layout/html/document/src/html.css index 2519ab834d9..86420b84813 100644 --- a/mozilla/layout/html/document/src/html.css +++ b/mozilla/layout/html/document/src/html.css @@ -49,6 +49,11 @@ iframe { background-color: white; } +/* focusable content */ +a, area, button, input, select, textarea { + user-focus: normal; +} + /* blocks */ p { @@ -980,6 +985,7 @@ select[disabled] { /* combobox button */ select > input[type="button"] { + user-focus: none; position: static !important; white-space:nowrap; border: outset 2px rgb(204, 204, 204); diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.h b/mozilla/layout/html/forms/src/nsFormControlFrame.h index 5bdb8453b4f..e4dc50bc152 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.h +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.h @@ -38,7 +38,6 @@ class nsIView; class nsIPresContext; class nsStyleCoord; class nsFormFrame; -class nsIFocusableContent; #define CSS_NOTSET -1 #define ATTR_NOTSET -1 diff --git a/mozilla/layout/html/forms/src/nsLabelFrame.cpp b/mozilla/layout/html/forms/src/nsLabelFrame.cpp index 9f2ffd66356..019ffad36d1 100644 --- a/mozilla/layout/html/forms/src/nsLabelFrame.cpp +++ b/mozilla/layout/html/forms/src/nsLabelFrame.cpp @@ -56,8 +56,6 @@ #include "nsIDOMHTMLAnchorElement.h" #include "nsFormControlFrame.h" -#include "nsIFocusableContent.h" - static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID); static NS_DEFINE_IID(kViewCID, NS_VIEW_CID); @@ -216,10 +214,7 @@ nsLabelFrame::HandleEvent(nsIPresContext* aPresContext, nsIContent * content; mControlFrame->GetFormContent(content); if (nsnull != content) { - nsCOMPtr focusable(do_QueryInterface(content)); - if (focusable) { - focusable->SetFocus(aPresContext); - } + content->SetFocus(aPresContext); NS_RELEASE(content); } mLastMouseState = eMouseDown; diff --git a/mozilla/layout/style/html.css b/mozilla/layout/style/html.css index 2519ab834d9..86420b84813 100644 --- a/mozilla/layout/style/html.css +++ b/mozilla/layout/style/html.css @@ -49,6 +49,11 @@ iframe { background-color: white; } +/* focusable content */ +a, area, button, input, select, textarea { + user-focus: normal; +} + /* blocks */ p { @@ -980,6 +985,7 @@ select[disabled] { /* combobox button */ select > input[type="button"] { + user-focus: none; position: static !important; white-space:nowrap; border: outset 2px rgb(204, 204, 204); diff --git a/mozilla/layout/xml/content/src/nsXMLElement.h b/mozilla/layout/xml/content/src/nsXMLElement.h index af408704acf..ca712cc29c7 100644 --- a/mozilla/layout/xml/content/src/nsXMLElement.h +++ b/mozilla/layout/xml/content/src/nsXMLElement.h @@ -168,7 +168,15 @@ public: } NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { return mInner.GetRangeList(aResult); - } + } + + NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { + return mInner.SetFocus(aPresContext); + } + NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { + return mInner.RemoveFocus(aPresContext); + } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { if (!aResult) { return NS_ERROR_NULL_POINTER;