From 04ab2e82c2e8853a3f758d272fc273ff9311523a Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Wed, 7 Sep 2005 18:19:26 +0000 Subject: [PATCH] Supply a scriptable interface for accessing the nsIEditor (and therefore the anonymous div) an HTML input or textarea. Bug 303727, r+sr=jst --- .../html/content/src/nsGenericHTMLElement.cpp | 22 +++++++- .../html/content/src/nsGenericHTMLElement.h | 6 +++ .../html/content/src/nsHTMLInputElement.cpp | 4 ++ .../content/src/nsHTMLTextAreaElement.cpp | 4 ++ dom/public/idl/core/Makefile.in | 1 + .../idl/core/nsIDOMNSEditableElement.idl | 52 +++++++++++++++++++ .../idl/html/nsIDOMNSHTMLInputElement.idl | 6 +-- .../idl/html/nsIDOMNSHTMLTextAreaElement.idl | 6 +-- 8 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 dom/public/idl/core/nsIDOMNSEditableElement.idl diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index d742bfc802a..bfb1268de59 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -109,7 +109,7 @@ #include "nsICSSOMFactory.h" #include "prprf.h" #include "prmem.h" -#include "nsIFormControlFrame.h" +#include "nsITextControlFrame.h" #include "nsIForm.h" #include "nsIFormControl.h" #include "nsIDOMHTMLFormElement.h" @@ -4128,3 +4128,23 @@ nsGenericHTMLElement::InternalGetExistingAttrNameFromQName(const nsAString& aStr return mAttrsAndChildren.GetExistingAttrNameFromQName( NS_ConvertUTF16toUTF8(aStr)); } + +nsresult +nsGenericHTMLElement::GetEditor(nsIEditor** aEditor) +{ + *aEditor = nsnull; + + if (!nsContentUtils::IsCallerChrome()) + return NS_ERROR_DOM_SECURITY_ERR; + + nsIFormControlFrame *fcFrame = GetFormControlFrame(PR_FALSE); + if (fcFrame) { + nsITextControlFrame *textFrame = nsnull; + CallQueryInterface(fcFrame, &textFrame); + if (textFrame) { + return textFrame->GetEditor(aEditor); + } + } + + return NS_OK; +} diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 0afea67a580..c3fc7c506fd 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -62,6 +62,7 @@ class nsIForm; class nsPresState; class nsIScrollableView; class nsILayoutHistoryState; +class nsIEditor; struct nsRect; struct nsSize; struct nsRuleData; @@ -797,6 +798,11 @@ protected: * are any. */ void RecreateFrames(); + + /** + * Locate an nsIEditor rooted at this content node, if there is one. + */ + NS_HIDDEN_(nsresult) GetEditor(nsIEditor** aEditor); }; diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 67da114406b..df2fb645382 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -163,6 +163,9 @@ public: // nsIPhonetic NS_DECL_NSIPHONETIC + // nsIDOMNSEditableElement + NS_FORWARD_NSIDOMNSEDITABLEELEMENT(nsGenericHTMLElement::) + // Overriden nsIFormControl methods NS_IMETHOD_(PRInt32) GetType() const { return mType; } NS_IMETHOD Reset(); @@ -375,6 +378,7 @@ NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLInputElement, NS_INTERFACE_MAP_ENTRY(nsIPhonetic) NS_INTERFACE_MAP_ENTRY(imgIDecoderObserver) NS_INTERFACE_MAP_ENTRY(nsIImageLoadingContent) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSEditableElement) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLInputElement) NS_HTML_CONTENT_INTERFACE_MAP_END diff --git a/content/html/content/src/nsHTMLTextAreaElement.cpp b/content/html/content/src/nsHTMLTextAreaElement.cpp index a71a69005d5..6498e73ab8b 100644 --- a/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -99,6 +99,9 @@ public: // nsIDOMNSHTMLTextAreaElement NS_DECL_NSIDOMNSHTMLTEXTAREAELEMENT + // nsIDOMNSEditableElement + NS_FORWARD_NSIDOMNSEDITABLEELEMENT(nsGenericHTMLElement::) + // nsIFormControl NS_IMETHOD_(PRInt32) GetType() const { return NS_FORM_TEXTAREA; } NS_IMETHOD Reset(); @@ -191,6 +194,7 @@ NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTextAreaElement, NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTextAreaElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLTextAreaElement) NS_INTERFACE_MAP_ENTRY(nsITextControlElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSEditableElement) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTextAreaElement) NS_HTML_CONTENT_INTERFACE_MAP_END diff --git a/dom/public/idl/core/Makefile.in b/dom/public/idl/core/Makefile.in index 8f5235e7125..282bf5a4169 100644 --- a/dom/public/idl/core/Makefile.in +++ b/dom/public/idl/core/Makefile.in @@ -75,6 +75,7 @@ XPIDLSRCS = \ nsIDOMXMLDocument.idl \ nsIDOMUserDataHandler.idl \ nsIDOMDOMConfiguration.idl \ + nsIDOMNSEditableElement.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/dom/public/idl/core/nsIDOMNSEditableElement.idl b/dom/public/idl/core/nsIDOMNSEditableElement.idl new file mode 100644 index 00000000000..20cc2918da6 --- /dev/null +++ b/dom/public/idl/core/nsIDOMNSEditableElement.idl @@ -0,0 +1,52 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Google Inc. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsIEditor; + +/** + * This interface is implemented by elements which have inner editable content, + * such as HTML input and textarea. +*/ + +[scriptable, uuid(c4a71f8e-82ba-49d7-94f9-beb359361072)] +interface nsIDOMNSEditableElement : nsISupports +{ + readonly attribute nsIEditor editor; +}; diff --git a/dom/public/idl/html/nsIDOMNSHTMLInputElement.idl b/dom/public/idl/html/nsIDOMNSHTMLInputElement.idl index 9f123873071..750e80f7b85 100644 --- a/dom/public/idl/html/nsIDOMNSHTMLInputElement.idl +++ b/dom/public/idl/html/nsIDOMNSHTMLInputElement.idl @@ -37,13 +37,13 @@ * * ***** END LICENSE BLOCK ***** */ -#include "domstubs.idl" +#include "nsIDOMNSEditableElement.idl" interface nsIControllers; -[scriptable, uuid(993d2efc-a768-11d3-bccd-0060b0fc76bd)] -interface nsIDOMNSHTMLInputElement : nsISupports +[scriptable, uuid(5e050532-1d12-4b98-ba20-6c883dc0d954)] +interface nsIDOMNSHTMLInputElement : nsIDOMNSEditableElement { readonly attribute nsIControllers controllers; diff --git a/dom/public/idl/html/nsIDOMNSHTMLTextAreaElement.idl b/dom/public/idl/html/nsIDOMNSHTMLTextAreaElement.idl index aee7118ed7b..aac54d70023 100644 --- a/dom/public/idl/html/nsIDOMNSHTMLTextAreaElement.idl +++ b/dom/public/idl/html/nsIDOMNSHTMLTextAreaElement.idl @@ -37,13 +37,13 @@ * * ***** END LICENSE BLOCK ***** */ -#include "domstubs.idl" +#include "nsIDOMNSEditableElement.idl" interface nsIControllers; -[scriptable, uuid(ca066b44-9ddf-11d3-bccc-0060b0fc76bd)] -interface nsIDOMNSHTMLTextAreaElement : nsISupports +[scriptable, uuid(8aa7dadc-73f1-416e-9d1e-15bc63226938)] +interface nsIDOMNSHTMLTextAreaElement : nsIDOMNSEditableElement { readonly attribute nsIControllers controllers;