2002-07-26 21:17:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-07-26 21:17:00 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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/
|
2002-07-26 21:17:00 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-07-26 21:17:00 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Blake Ross <blakeross@telocity.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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"),
|
2002-07-26 21:17:00 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-07-26 21:17:00 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-07-26 21:17:00 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2002-07-27 00:57:24 +04:00
|
|
|
#include "nsTextControlFrame.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMNSHTMLTextAreaElement.h"
|
|
|
|
#include "nsIDOMNSHTMLInputElement.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2006-04-26 06:01:07 +04:00
|
|
|
#include "nsFrameSelection.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsIPlaintextEditor.h"
|
|
|
|
#include "nsEditorCID.h"
|
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsIDocumentEncoder.h"
|
2008-07-16 14:52:01 +04:00
|
|
|
#include "nsCaret.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsISelectionListener.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
|
|
|
#include "nsIController.h"
|
|
|
|
#include "nsIControllers.h"
|
2002-11-13 02:03:27 +03:00
|
|
|
#include "nsIControllerContext.h"
|
2005-01-12 22:45:38 +03:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsIEditorIMESupport.h"
|
2002-12-18 02:38:04 +03:00
|
|
|
#include "nsIPhonetic.h"
|
|
|
|
#include "nsIEditorObserver.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsIDOMHTMLTextAreaElement.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsINodeInfo.h"
|
|
|
|
#include "nsIScrollableFrame.h" //to turn off scroll bars
|
|
|
|
#include "nsFormControlFrame.h" //for registering accesskeys
|
|
|
|
#include "nsIDeviceContext.h" // to measure fonts
|
|
|
|
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIAtom.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2006-07-06 14:43:51 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIView.h"
|
2007-02-12 22:31:59 +03:00
|
|
|
#include "nsIViewManager.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
//for keylistener for "return" check
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2007-05-14 13:11:38 +04:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsIDocument.h" //observe documents to send onchangenotifications
|
|
|
|
#include "nsIStyleSheet.h"//observe documents to send onchangenotifications
|
|
|
|
#include "nsIStyleRule.h"//observe documents to send onchangenotifications
|
|
|
|
#include "nsIDOMEventListener.h"//observe documents to send onchangenotifications
|
|
|
|
#include "nsGUIEvent.h"
|
2002-11-09 03:25:25 +03:00
|
|
|
#include "nsIDOMEventGroup.h"
|
|
|
|
#include "nsIDOM3EventTarget.h"
|
2004-09-30 20:29:54 +04:00
|
|
|
#include "nsIDOMNSEvent.h"
|
2002-11-09 03:25:25 +03:00
|
|
|
#include "nsIDOMNSUIEvent.h"
|
2004-05-06 02:48:51 +04:00
|
|
|
#include "nsIEventStateManager.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
#include "nsIDOMFocusListener.h" //onchange events
|
|
|
|
#include "nsIDOMCharacterData.h" //for selection setting helper func
|
|
|
|
#include "nsIDOMNodeList.h" //for selection setting helper func
|
|
|
|
#include "nsIDOMRange.h" //for selection setting helper func
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h" //needed for notify selection changed to update the menus ect.
|
2002-07-26 21:17:00 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsITextControlElement.h"
|
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
#include "nsIEditorObserver.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
#include "nsITransactionManager.h"
|
|
|
|
#include "nsIDOMText.h" //for multiline getselection
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2004-09-08 01:21:48 +04:00
|
|
|
#include "nsIDOMKeyListener.h"
|
|
|
|
#include "nsIDOMEventGroup.h"
|
|
|
|
#include "nsIDOM3EventTarget.h"
|
|
|
|
#include "nsINativeKeyBindings.h"
|
2005-04-26 07:31:29 +04:00
|
|
|
#include "nsIJSContextStack.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
#define DEFAULT_COLUMN_WIDTH 20
|
|
|
|
|
|
|
|
#include "nsContentCID.h"
|
|
|
|
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
|
|
|
|
static NS_DEFINE_CID(kFrameSelectionCID, NS_FRAMESELECTION_CID);
|
|
|
|
|
2002-09-16 10:23:52 +04:00
|
|
|
static const PRInt32 DEFAULT_COLS = 20;
|
|
|
|
static const PRInt32 DEFAULT_ROWS = 1;
|
|
|
|
static const PRInt32 DEFAULT_ROWS_TEXTAREA = 2;
|
2005-10-20 06:10:31 +04:00
|
|
|
static const PRInt32 DEFAULT_UNDO_CAP = 1000;
|
2002-09-16 10:23:52 +04:00
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
static nsINativeKeyBindings *sNativeInputBindings = nsnull;
|
|
|
|
static nsINativeKeyBindings *sNativeTextAreaBindings = nsnull;
|
|
|
|
|
2006-07-06 14:43:51 +04:00
|
|
|
static void
|
|
|
|
PlatformToDOMLineBreaks(nsString &aString)
|
|
|
|
{
|
|
|
|
// Windows linebreaks: Map CRLF to LF:
|
|
|
|
aString.ReplaceSubstring(NS_LITERAL_STRING("\r\n").get(),
|
|
|
|
NS_LITERAL_STRING("\n").get());
|
|
|
|
|
|
|
|
// Mac linebreaks: Map any remaining CR to LF:
|
|
|
|
aString.ReplaceSubstring(NS_LITERAL_STRING("\r").get(),
|
|
|
|
NS_LITERAL_STRING("\n").get());
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrap can be one of these three values.
|
|
|
|
typedef enum {
|
|
|
|
eHTMLTextWrap_Off = 1, // "off"
|
|
|
|
eHTMLTextWrap_Hard = 2, // "hard"
|
|
|
|
eHTMLTextWrap_Soft = 3 // the default
|
|
|
|
} nsHTMLTextWrap;
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
GetWrapPropertyEnum(nsIContent* aContent, nsHTMLTextWrap& aWrapProp)
|
|
|
|
{
|
|
|
|
// soft is the default; "physical" defaults to soft as well because all other
|
|
|
|
// browsers treat it that way and there is no real reason to maintain physical
|
|
|
|
// and virtual as separate entities if no one else does. Only hard and off
|
|
|
|
// do anything different.
|
|
|
|
aWrapProp = eHTMLTextWrap_Soft; // the default
|
|
|
|
|
|
|
|
nsAutoString wrap;
|
2009-08-25 00:02:07 +04:00
|
|
|
if (aContent->IsHTML()) {
|
2006-07-06 14:43:51 +04:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2006-12-26 20:47:52 +03:00
|
|
|
{&nsGkAtoms::HARD, &nsGkAtoms::OFF, nsnull};
|
2006-07-06 14:43:51 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
switch (aContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::wrap,
|
2006-07-06 14:43:51 +04:00
|
|
|
strings, eIgnoreCase)) {
|
|
|
|
case 0: aWrapProp = eHTMLTextWrap_Hard; break;
|
|
|
|
case 1: aWrapProp = eHTMLTextWrap_Off; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
class nsTextInputListener : public nsISelectionListener,
|
2004-09-08 01:21:48 +04:00
|
|
|
public nsIDOMKeyListener,
|
2002-07-26 21:17:00 +04:00
|
|
|
public nsIEditorObserver,
|
|
|
|
public nsSupportsWeakReference
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** the default constructor
|
|
|
|
*/
|
|
|
|
nsTextInputListener();
|
|
|
|
/** the default destructor. virtual due to the possibility of derivation.
|
|
|
|
*/
|
|
|
|
virtual ~nsTextInputListener();
|
|
|
|
|
|
|
|
/** SetEditor gives an address to the editor that will be accessed
|
|
|
|
* @param aEditor the editor this listener calls for editing operations
|
|
|
|
*/
|
2002-07-27 00:57:24 +04:00
|
|
|
void SetFrame(nsTextControlFrame *aFrame){mFrame = aFrame;}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
NS_DECL_NSISELECTIONLISTENER
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
// nsIDOMKeyListener
|
|
|
|
NS_IMETHOD KeyDown(nsIDOMEvent *aKeyEvent);
|
|
|
|
NS_IMETHOD KeyPress(nsIDOMEvent *aKeyEvent);
|
|
|
|
NS_IMETHOD KeyUp(nsIDOMEvent *aKeyEvent);
|
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
NS_DECL_NSIEDITOROBSERVER
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
nsresult UpdateTextInputCommands(const nsAString& commandsToUpdate);
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
NS_HIDDEN_(nsINativeKeyBindings*) GetKeyBindings();
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
protected:
|
|
|
|
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame* mFrame; // weak reference
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
PRPackedBool mSelectionWasCollapsed;
|
2002-11-21 02:19:45 +03:00
|
|
|
/**
|
|
|
|
* Whether we had undo items or not the last time we got EditAction()
|
|
|
|
* notification (when this state changes we update undo and redo menus)
|
|
|
|
*/
|
|
|
|
PRPackedBool mHadUndoItems;
|
|
|
|
/**
|
|
|
|
* Whether we had redo items or not the last time we got EditAction()
|
|
|
|
* notification (when this state changes we update undo and redo menus)
|
|
|
|
*/
|
|
|
|
PRPackedBool mHadRedoItems;
|
2002-07-26 21:17:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsTextEditorListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsTextInputListener::nsTextInputListener()
|
|
|
|
: mFrame(nsnull)
|
|
|
|
, mSelectionWasCollapsed(PR_TRUE)
|
2002-11-21 02:19:45 +03:00
|
|
|
, mHadUndoItems(PR_FALSE)
|
|
|
|
, mHadRedoItems(PR_FALSE)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextInputListener::~nsTextInputListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
NS_IMPL_ADDREF(nsTextInputListener)
|
|
|
|
NS_IMPL_RELEASE(nsTextInputListener)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsTextInputListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISelectionListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIEditorObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMKeyListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMKeyListener)
|
2004-09-08 01:21:48 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// BEGIN nsIDOMSelectionListener
|
2002-07-26 21:17:00 +04:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
static PRBool
|
|
|
|
IsFocusedContent(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (!fm)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
|
|
|
fm->GetFocusedElement(getter_AddRefs(focusedElement));
|
|
|
|
nsCOMPtr<nsIContent> focusedContent = do_QueryInterface(focusedElement);
|
|
|
|
return (focusedContent == aContent);
|
|
|
|
}
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputListener::NotifySelectionChanged(nsIDOMDocument* aDoc, nsISelection* aSel, PRInt16 aReason)
|
|
|
|
{
|
|
|
|
PRBool collapsed;
|
|
|
|
if (!mFrame || !aDoc || !aSel || NS_FAILED(aSel->GetIsCollapsed(&collapsed)))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Fire the select event
|
|
|
|
// The specs don't exactly say when we should fire the select event.
|
|
|
|
// IE: Whenever you add/remove a character to/from the selection. Also
|
|
|
|
// each time for select all. Also if you get to the end of the text
|
|
|
|
// field you will get new event for each keypress or a continuous
|
|
|
|
// stream of events if you use the mouse. IE will fire select event
|
|
|
|
// when the selection collapses to nothing if you are holding down
|
|
|
|
// the shift or mouse button.
|
|
|
|
// Mozilla: If we have non-empty selection we will fire a new event for each
|
|
|
|
// keypress (or mouseup) if the selection changed. Mozilla will also
|
|
|
|
// create the event each time select all is called, even if everything
|
|
|
|
// was previously selected, becase technically select all will first collapse
|
|
|
|
// and then extend. Mozilla will never create an event if the selection
|
|
|
|
// collapses to nothing.
|
|
|
|
if (!collapsed && (aReason & (nsISelectionListener::MOUSEUP_REASON |
|
|
|
|
nsISelectionListener::KEYPRESS_REASON |
|
|
|
|
nsISelectionListener::SELECTALL_REASON)))
|
|
|
|
{
|
2005-12-13 02:53:06 +03:00
|
|
|
nsIContent* content = mFrame->GetContent();
|
2002-07-26 21:17:00 +04:00
|
|
|
if (content)
|
|
|
|
{
|
2003-07-29 01:25:13 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = content->GetDocument();
|
|
|
|
if (doc)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2007-05-02 02:24:20 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
|
2003-07-29 01:25:13 +04:00
|
|
|
if (presShell)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2003-07-29 01:25:13 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-04-29 03:48:28 +04:00
|
|
|
nsEvent event(PR_TRUE, NS_FORM_SELECTED);
|
2003-07-29 01:25:13 +04:00
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
presShell->HandleEventWithTarget(&event, mFrame, content, &status);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the collapsed state did not change, don't fire notifications
|
2006-09-14 04:54:44 +04:00
|
|
|
if (collapsed == mSelectionWasCollapsed)
|
2002-07-26 21:17:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mSelectionWasCollapsed = collapsed;
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (!mFrame || !IsFocusedContent(mFrame->GetContent()))
|
2007-09-15 02:33:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
return UpdateTextInputCommands(NS_LITERAL_STRING("select"));
|
|
|
|
}
|
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// END nsIDOMSelectionListener
|
2002-07-26 21:17:00 +04:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
// BEGIN nsIDOMKeyListener
|
2002-11-21 02:19:45 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputListener::HandleEvent(nsIDOMEvent* aEvent)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2002-11-21 02:19:45 +03:00
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
static void
|
|
|
|
DoCommandCallback(const char *aCommand, void *aData)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsTextControlFrame *frame = static_cast<nsTextControlFrame*>(aData);
|
2004-09-08 01:21:48 +04:00
|
|
|
nsIContent *content = frame->GetContent();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLInputElement> input = do_QueryInterface(content);
|
|
|
|
if (input) {
|
|
|
|
input->GetControllers(getter_AddRefs(controllers));
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLTextAreaElement> textArea =
|
|
|
|
do_QueryInterface(content);
|
|
|
|
|
|
|
|
if (textArea) {
|
|
|
|
textArea->GetControllers(getter_AddRefs(controllers));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!controllers) {
|
|
|
|
NS_WARNING("Could not get controllers");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
controllers->GetControllerForCommand(aCommand, getter_AddRefs(controller));
|
|
|
|
if (controller) {
|
|
|
|
controller->DoCommand(aCommand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-10-15 14:50:42 +04:00
|
|
|
nsTextInputListener::KeyDown(nsIDOMEvent *aDOMEvent)
|
2004-09-08 01:21:48 +04:00
|
|
|
{
|
2008-10-15 14:50:42 +04:00
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aDOMEvent));
|
|
|
|
NS_ENSURE_TRUE(keyEvent, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
nsNativeKeyEvent nativeEvent;
|
|
|
|
nsINativeKeyBindings *bindings = GetKeyBindings();
|
2006-04-29 04:39:03 +04:00
|
|
|
if (bindings &&
|
2008-10-15 14:50:42 +04:00
|
|
|
nsContentUtils::DOMEventToNativeKeyEvent(keyEvent, &nativeEvent, PR_FALSE)) {
|
2004-09-08 01:21:48 +04:00
|
|
|
if (bindings->KeyDown(nativeEvent, DoCommandCallback, mFrame)) {
|
2008-10-15 14:50:42 +04:00
|
|
|
aDOMEvent->PreventDefault();
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-10-15 14:50:42 +04:00
|
|
|
nsTextInputListener::KeyPress(nsIDOMEvent *aDOMEvent)
|
2004-09-08 01:21:48 +04:00
|
|
|
{
|
2008-10-15 14:50:42 +04:00
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aDOMEvent));
|
|
|
|
NS_ENSURE_TRUE(keyEvent, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
nsNativeKeyEvent nativeEvent;
|
|
|
|
nsINativeKeyBindings *bindings = GetKeyBindings();
|
2006-04-29 04:39:03 +04:00
|
|
|
if (bindings &&
|
2008-10-15 14:50:42 +04:00
|
|
|
nsContentUtils::DOMEventToNativeKeyEvent(keyEvent, &nativeEvent, PR_TRUE)) {
|
2004-09-08 01:21:48 +04:00
|
|
|
if (bindings->KeyPress(nativeEvent, DoCommandCallback, mFrame)) {
|
2008-10-15 14:50:42 +04:00
|
|
|
aDOMEvent->PreventDefault();
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-10-15 14:50:42 +04:00
|
|
|
nsTextInputListener::KeyUp(nsIDOMEvent *aDOMEvent)
|
2004-09-08 01:21:48 +04:00
|
|
|
{
|
2008-10-15 14:50:42 +04:00
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aDOMEvent));
|
|
|
|
NS_ENSURE_TRUE(keyEvent, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
nsNativeKeyEvent nativeEvent;
|
|
|
|
nsINativeKeyBindings *bindings = GetKeyBindings();
|
2006-04-29 04:39:03 +04:00
|
|
|
if (bindings &&
|
2008-10-15 14:50:42 +04:00
|
|
|
nsContentUtils::DOMEventToNativeKeyEvent(keyEvent, &nativeEvent, PR_FALSE)) {
|
2004-09-08 01:21:48 +04:00
|
|
|
if (bindings->KeyUp(nativeEvent, DoCommandCallback, mFrame)) {
|
2008-10-15 14:50:42 +04:00
|
|
|
aDOMEvent->PreventDefault();
|
2004-09-08 01:21:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// END nsIDOMKeyListener
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// BEGIN nsIEditorObserver
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputListener::EditAction()
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2002-11-21 02:19:45 +03:00
|
|
|
//
|
|
|
|
// Update the undo / redo menus
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIEditor> editor;
|
|
|
|
mFrame->GetEditor(getter_AddRefs(editor));
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
nsCOMPtr<nsITransactionManager> manager;
|
|
|
|
editor->GetTransactionManager(getter_AddRefs(manager));
|
|
|
|
NS_ENSURE_TRUE(manager, NS_ERROR_FAILURE);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// Get the number of undo / redo items
|
|
|
|
PRInt32 numUndoItems = 0;
|
|
|
|
PRInt32 numRedoItems = 0;
|
|
|
|
manager->GetNumberOfUndoItems(&numUndoItems);
|
|
|
|
manager->GetNumberOfRedoItems(&numRedoItems);
|
2008-09-15 19:40:25 +04:00
|
|
|
if ((numUndoItems && !mHadUndoItems) || (!numUndoItems && mHadUndoItems) ||
|
|
|
|
(numRedoItems && !mHadRedoItems) || (!numRedoItems && mHadRedoItems)) {
|
2002-11-21 02:19:45 +03:00
|
|
|
// Modify the menu if undo or redo items are different
|
|
|
|
UpdateTextInputCommands(NS_LITERAL_STRING("undo"));
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
mHadUndoItems = numUndoItems != 0;
|
|
|
|
mHadRedoItems = numRedoItems != 0;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// Make sure we know we were changed (do NOT set this to false if there are
|
|
|
|
// no undo items; JS could change the value and we'd still need to save it)
|
|
|
|
mFrame->SetValueChanged(PR_TRUE);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// Fire input event
|
|
|
|
mFrame->FireOnInput();
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// END nsIEditorObserver
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
nsresult
|
|
|
|
nsTextInputListener::UpdateTextInputCommands(const nsAString& commandsToUpdate)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-07-26 11:58:18 +04:00
|
|
|
NS_ENSURE_STATE(mFrame);
|
|
|
|
|
2003-07-04 16:50:32 +04:00
|
|
|
nsIContent* content = mFrame->GetContent();
|
2002-11-21 02:19:45 +03:00
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-07-29 01:25:13 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = content->GetDocument();
|
2002-11-21 02:19:45 +03:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
nsPIDOMWindow *domWindow = doc->GetWindow();
|
2002-11-21 02:19:45 +03:00
|
|
|
NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
return domWindow->UpdateCommands(commandsToUpdate);
|
|
|
|
}
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
nsINativeKeyBindings*
|
|
|
|
nsTextInputListener::GetKeyBindings()
|
|
|
|
{
|
|
|
|
if (mFrame->IsTextArea()) {
|
|
|
|
static PRBool sNoTextAreaBindings = PR_FALSE;
|
|
|
|
|
|
|
|
if (!sNativeTextAreaBindings && !sNoTextAreaBindings) {
|
|
|
|
CallGetService(NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "textarea",
|
|
|
|
&sNativeTextAreaBindings);
|
|
|
|
|
|
|
|
if (!sNativeTextAreaBindings) {
|
|
|
|
sNoTextAreaBindings = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sNativeTextAreaBindings;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool sNoInputBindings = PR_FALSE;
|
|
|
|
if (!sNativeInputBindings && !sNoInputBindings) {
|
|
|
|
CallGetService(NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "input",
|
|
|
|
&sNativeInputBindings);
|
|
|
|
|
|
|
|
if (!sNativeInputBindings) {
|
|
|
|
sNoInputBindings = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sNativeInputBindings;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// END nsTextInputListener
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2006-02-21 03:49:04 +03:00
|
|
|
class nsTextInputSelectionImpl : public nsSupportsWeakReference
|
|
|
|
, public nsISelectionController
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
nsTextInputSelectionImpl(nsFrameSelection *aSel, nsIPresShell *aShell,
|
|
|
|
nsIContent *aLimiter);
|
2002-07-26 21:17:00 +04:00
|
|
|
~nsTextInputSelectionImpl(){}
|
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
void SetScrollableFrame(nsIScrollableFrame *aScrollableFrame)
|
|
|
|
{ mScrollFrame = aScrollableFrame; }
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
//NSISELECTIONCONTROLLER INTERFACES
|
|
|
|
NS_IMETHOD SetDisplaySelection(PRInt16 toggle);
|
|
|
|
NS_IMETHOD GetDisplaySelection(PRInt16 *_retval);
|
|
|
|
NS_IMETHOD SetSelectionFlags(PRInt16 aInEnable);
|
|
|
|
NS_IMETHOD GetSelectionFlags(PRInt16 *aOutEnable);
|
|
|
|
NS_IMETHOD GetSelection(PRInt16 type, nsISelection **_retval);
|
|
|
|
NS_IMETHOD ScrollSelectionIntoView(PRInt16 aType, PRInt16 aRegion, PRBool aIsSynchronous);
|
|
|
|
NS_IMETHOD RepaintSelection(PRInt16 type);
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD RepaintSelection(nsPresContext* aPresContext, SelectionType aSelectionType);
|
2002-07-26 21:17:00 +04:00
|
|
|
NS_IMETHOD SetCaretEnabled(PRBool enabled);
|
|
|
|
NS_IMETHOD SetCaretReadOnly(PRBool aReadOnly);
|
|
|
|
NS_IMETHOD GetCaretEnabled(PRBool *_retval);
|
2008-04-08 22:52:48 +04:00
|
|
|
NS_IMETHOD GetCaretVisible(PRBool *_retval);
|
2003-06-25 05:14:25 +04:00
|
|
|
NS_IMETHOD SetCaretVisibilityDuringSelection(PRBool aVisibility);
|
2002-07-26 21:17:00 +04:00
|
|
|
NS_IMETHOD CharacterMove(PRBool aForward, PRBool aExtend);
|
2008-10-16 11:44:32 +04:00
|
|
|
NS_IMETHOD CharacterExtendForDelete();
|
2002-07-26 21:17:00 +04:00
|
|
|
NS_IMETHOD WordMove(PRBool aForward, PRBool aExtend);
|
2006-07-18 11:28:38 +04:00
|
|
|
NS_IMETHOD WordExtendForDelete(PRBool aForward);
|
2002-07-26 21:17:00 +04:00
|
|
|
NS_IMETHOD LineMove(PRBool aForward, PRBool aExtend);
|
|
|
|
NS_IMETHOD IntraLineMove(PRBool aForward, PRBool aExtend);
|
|
|
|
NS_IMETHOD PageMove(PRBool aForward, PRBool aExtend);
|
|
|
|
NS_IMETHOD CompleteScroll(PRBool aForward);
|
|
|
|
NS_IMETHOD CompleteMove(PRBool aForward, PRBool aExtend);
|
|
|
|
NS_IMETHOD ScrollPage(PRBool aForward);
|
|
|
|
NS_IMETHOD ScrollLine(PRBool aForward);
|
|
|
|
NS_IMETHOD ScrollHorizontal(PRBool aLeft);
|
|
|
|
NS_IMETHOD SelectAll(void);
|
|
|
|
NS_IMETHOD CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOffset, PRBool *_retval);
|
|
|
|
|
|
|
|
private:
|
2006-04-26 06:01:07 +04:00
|
|
|
nsCOMPtr<nsFrameSelection> mFrameSelection;
|
2009-09-03 09:23:47 +04:00
|
|
|
nsCOMPtr<nsIContent> mLimiter;
|
|
|
|
nsIScrollableFrame *mScrollFrame;
|
2002-07-26 21:17:00 +04:00
|
|
|
nsWeakPtr mPresShellWeak;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implement our nsISupports methods
|
2008-04-06 16:28:34 +04:00
|
|
|
NS_IMPL_ISUPPORTS3(nsTextInputSelectionImpl,
|
|
|
|
nsISelectionController,
|
|
|
|
nsISelectionDisplay,
|
|
|
|
nsISupportsWeakReference)
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
// BEGIN nsTextInputSelectionImpl
|
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
nsTextInputSelectionImpl::nsTextInputSelectionImpl(nsFrameSelection *aSel,
|
|
|
|
nsIPresShell *aShell,
|
|
|
|
nsIContent *aLimiter)
|
|
|
|
: mScrollFrame(nsnull)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
if (aSel && aShell)
|
|
|
|
{
|
|
|
|
mFrameSelection = aSel;//we are the owner now!
|
|
|
|
mLimiter = aLimiter;
|
2004-09-01 09:16:00 +04:00
|
|
|
mFrameSelection->Init(aShell, mLimiter);
|
2003-07-25 23:06:59 +04:00
|
|
|
mPresShellWeak = do_GetWeakReference(aShell);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::SetDisplaySelection(PRInt16 aToggle)
|
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
mFrameSelection->SetDisplaySelection(aToggle);
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::GetDisplaySelection(PRInt16 *aToggle)
|
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aToggle = mFrameSelection->GetDisplaySelection();
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::SetSelectionFlags(PRInt16 aToggle)
|
|
|
|
{
|
|
|
|
return NS_OK;//stub this out. not used in input
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::GetSelectionFlags(PRInt16 *aOutEnable)
|
|
|
|
{
|
|
|
|
*aOutEnable = nsISelectionDisplay::DISPLAY_TEXT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::GetSelection(PRInt16 type, nsISelection **_retval)
|
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*_retval = mFrameSelection->GetSelection(type);
|
|
|
|
|
|
|
|
if (!(*_retval))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::ScrollSelectionIntoView(PRInt16 aType, PRInt16 aRegion, PRBool aIsSynchronous)
|
|
|
|
{
|
2009-09-03 09:23:47 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-02-05 00:56:07 +03:00
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
return mFrameSelection->ScrollSelectionIntoView(aType, aRegion, aIsSynchronous);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::RepaintSelection(PRInt16 type)
|
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return mFrameSelection->RepaintSelection(type);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTextInputSelectionImpl::RepaintSelection(nsPresContext* aPresContext, SelectionType aSelectionType)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return mFrameSelection->RepaintSelection(aSelectionType);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::SetCaretEnabled(PRBool enabled)
|
|
|
|
{
|
|
|
|
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShellWeak);
|
|
|
|
if (!shell) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// tell the pres shell to enable the caret, rather than settings its visibility directly.
|
|
|
|
// this way the presShell's idea of caret visibility is maintained.
|
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryInterface(shell);
|
|
|
|
if (!selCon) return NS_ERROR_NO_INTERFACE;
|
|
|
|
selCon->SetCaretEnabled(enabled);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::SetCaretReadOnly(PRBool aReadOnly)
|
|
|
|
{
|
|
|
|
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShellWeak, &result);
|
|
|
|
if (shell)
|
|
|
|
{
|
2008-07-16 14:52:01 +04:00
|
|
|
nsRefPtr<nsCaret> caret;
|
2006-04-26 06:01:07 +04:00
|
|
|
if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret))))
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
nsISelection* domSel = mFrameSelection->
|
|
|
|
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
if (domSel)
|
2008-07-16 14:52:01 +04:00
|
|
|
caret->SetCaretReadOnly(aReadOnly);
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::GetCaretEnabled(PRBool *_retval)
|
2008-04-08 22:52:48 +04:00
|
|
|
{
|
|
|
|
return GetCaretVisible(_retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::GetCaretVisible(PRBool *_retval)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShellWeak, &result);
|
|
|
|
if (shell)
|
|
|
|
{
|
2008-07-16 14:52:01 +04:00
|
|
|
nsRefPtr<nsCaret> caret;
|
2006-04-26 06:01:07 +04:00
|
|
|
if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret))))
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
nsISelection* domSel = mFrameSelection->
|
|
|
|
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
if (domSel)
|
2002-07-26 21:17:00 +04:00
|
|
|
return caret->GetCaretVisible(_retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-06-25 05:14:25 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::SetCaretVisibilityDuringSelection(PRBool aVisibility)
|
|
|
|
{
|
|
|
|
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShellWeak, &result);
|
|
|
|
if (shell)
|
|
|
|
{
|
2008-07-16 14:52:01 +04:00
|
|
|
nsRefPtr<nsCaret> caret;
|
2006-04-26 06:01:07 +04:00
|
|
|
if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret))))
|
2003-06-25 05:14:25 +04:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
nsISelection* domSel = mFrameSelection->
|
|
|
|
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
if (domSel)
|
2008-07-16 14:52:01 +04:00
|
|
|
caret->SetVisibilityDuringSelection(aVisibility);
|
|
|
|
return NS_OK;
|
2003-06-25 05:14:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::CharacterMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
|
|
|
if (mFrameSelection)
|
|
|
|
return mFrameSelection->CharacterMove(aForward, aExtend);
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2008-10-16 11:44:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::CharacterExtendForDelete()
|
|
|
|
{
|
|
|
|
if (mFrameSelection)
|
|
|
|
return mFrameSelection->CharacterExtendForDelete();
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::WordMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
|
|
|
if (mFrameSelection)
|
|
|
|
return mFrameSelection->WordMove(aForward, aExtend);
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2006-07-18 11:28:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::WordExtendForDelete(PRBool aForward)
|
|
|
|
{
|
|
|
|
if (mFrameSelection)
|
|
|
|
return mFrameSelection->WordExtendForDelete(aForward);
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::LineMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
|
|
|
if (mFrameSelection)
|
|
|
|
{
|
|
|
|
nsresult result = mFrameSelection->LineMove(aForward, aExtend);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
result = CompleteMove(aForward,aExtend);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::IntraLineMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
|
|
|
if (mFrameSelection)
|
|
|
|
return mFrameSelection->IntraLineMove(aForward, aExtend);
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::PageMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
2002-08-27 00:55:30 +04:00
|
|
|
// expected behavior for PageMove is to scroll AND move the caret
|
|
|
|
// and to remain relative position of the caret in view. see Bug 4302.
|
2009-09-03 09:23:47 +04:00
|
|
|
if (mScrollFrame)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2009-09-03 09:23:47 +04:00
|
|
|
mFrameSelection->CommonPageMove(aForward, aExtend, mScrollFrame);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2008-02-28 18:28:37 +03:00
|
|
|
// After ScrollSelectionIntoView(), the pending notifications might be
|
|
|
|
// flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
|
2002-08-27 11:34:41 +04:00
|
|
|
return ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION, PR_TRUE);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::CompleteScroll(PRBool aForward)
|
|
|
|
{
|
2009-09-03 09:23:47 +04:00
|
|
|
if (!mScrollFrame)
|
2002-07-26 21:17:00 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
mScrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
|
|
|
|
nsIScrollableFrame::WHOLE,
|
|
|
|
nsIScrollableFrame::INSTANT);
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::CompleteMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
|
|
|
// grab the parent / root DIV for this text widget
|
2006-04-26 06:01:07 +04:00
|
|
|
nsIContent* parentDIV = mFrameSelection->GetLimiter();
|
2002-07-26 21:17:00 +04:00
|
|
|
if (!parentDIV)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// make the caret be either at the very beginning (0) or the very end
|
|
|
|
PRInt32 offset = 0;
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::HINT hint = nsFrameSelection::HINTLEFT;
|
2002-07-26 21:17:00 +04:00
|
|
|
if (aForward)
|
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
offset = parentDIV->GetChildCount();
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
// Prevent the caret from being placed after the last
|
|
|
|
// BR node in the content tree!
|
|
|
|
|
|
|
|
if (offset > 0)
|
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
nsIContent *child = parentDIV->GetChildAt(offset - 1);
|
2003-11-19 04:20:56 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (child->Tag() == nsGkAtoms::br)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
--offset;
|
2006-04-26 06:01:07 +04:00
|
|
|
hint = nsFrameSelection::HINTRIGHT; // for Bug 106855
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-21 03:49:04 +03:00
|
|
|
mFrameSelection->HandleClick(parentDIV, offset, offset, aExtend,
|
|
|
|
PR_FALSE, hint);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
// if we got this far, attempt to scroll no matter what the above result is
|
|
|
|
return CompleteScroll(aForward);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::ScrollPage(PRBool aForward)
|
|
|
|
{
|
2009-09-03 09:23:47 +04:00
|
|
|
if (!mScrollFrame)
|
2002-07-26 21:17:00 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
mScrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
|
|
|
|
nsIScrollableFrame::PAGES,
|
|
|
|
nsIScrollableFrame::SMOOTH);
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::ScrollLine(PRBool aForward)
|
|
|
|
{
|
2009-09-03 09:23:47 +04:00
|
|
|
if (!mScrollFrame)
|
2002-07-26 21:17:00 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
mScrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
|
|
|
|
nsIScrollableFrame::LINES,
|
|
|
|
nsIScrollableFrame::SMOOTH);
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::ScrollHorizontal(PRBool aLeft)
|
|
|
|
{
|
2009-09-03 09:23:47 +04:00
|
|
|
if (!mScrollFrame)
|
2002-07-26 21:17:00 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
// will we have bug #7354 because we aren't forcing an update here?
|
2009-09-03 09:23:47 +04:00
|
|
|
mScrollFrame->ScrollBy(nsIntPoint(aLeft ? -1 : 1, 0),
|
|
|
|
nsIScrollableFrame::LINES,
|
|
|
|
nsIScrollableFrame::SMOOTH);
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::SelectAll()
|
|
|
|
{
|
|
|
|
if (mFrameSelection)
|
|
|
|
return mFrameSelection->SelectAll();
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextInputSelectionImpl::CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOffset, PRBool *_retval)
|
|
|
|
{
|
|
|
|
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsISelectionController> shell = do_QueryReferent(mPresShellWeak, &result);
|
|
|
|
if (shell)
|
|
|
|
{
|
|
|
|
return shell->CheckVisibility(node,startOffset,EndOffset, _retval);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-11-01 23:40:54 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewTextControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsTextControlFrame(aPresShell, aContext);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsTextControlFrame)
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsTextControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsITextControlFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2002-07-27 00:57:24 +04:00
|
|
|
NS_IMETHODIMP nsTextControlFrame::GetAccessible(nsIAccessible** aAccessible)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return accService->CreateHTMLTextFieldAccessible(static_cast<nsIFrame*>(this), aAccessible);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsTextControlFrame::nsTextControlFrame(nsIPresShell* aShell, nsStyleContext* aContext)
|
|
|
|
: nsStackFrame(aShell, aContext)
|
2007-01-05 19:31:07 +03:00
|
|
|
, mUseEditor(PR_FALSE)
|
|
|
|
, mIsProcessing(PR_FALSE)
|
|
|
|
, mNotifyOnInput(PR_TRUE)
|
|
|
|
, mDidPreDestroy(PR_FALSE)
|
|
|
|
, mFireChangeEventState(PR_FALSE)
|
2007-09-27 20:01:32 +04:00
|
|
|
, mInSecureKeyboardInputMode(PR_FALSE)
|
2007-01-05 19:31:07 +03:00
|
|
|
, mTextListener(nsnull)
|
|
|
|
{
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::~nsTextControlFrame()
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-02-21 03:49:04 +03:00
|
|
|
NS_IF_RELEASE(mTextListener);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
SuppressEventHandlers(nsPresContext* aPresContext)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
PRBool suppressHandlers = PR_FALSE;
|
|
|
|
|
|
|
|
if (aPresContext)
|
|
|
|
{
|
|
|
|
// Right now we only suppress event handlers and controller manipulation
|
|
|
|
// when in a print preview or print context!
|
|
|
|
|
|
|
|
// In the current implementation, we only paginate when
|
|
|
|
// printing or in print preview.
|
|
|
|
|
2004-03-03 21:24:20 +03:00
|
|
|
suppressHandlers = aPresContext->IsPaginated();
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return suppressHandlers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-04-10 04:16:29 +04:00
|
|
|
nsTextControlFrame::PreDestroy()
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
// notify the editor that we are going away
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
// If we were in charge of state before, relinquish it back
|
|
|
|
// to the control.
|
|
|
|
if (mUseEditor)
|
|
|
|
{
|
|
|
|
// First get the frame state from the editor
|
|
|
|
nsAutoString value;
|
|
|
|
GetValue(value, PR_TRUE);
|
|
|
|
|
|
|
|
mUseEditor = PR_FALSE;
|
|
|
|
|
|
|
|
// Next store the frame state in the control
|
|
|
|
// (now that mUseEditor is false values get stored
|
|
|
|
// in content).
|
|
|
|
SetValue(value);
|
|
|
|
}
|
2008-12-12 11:34:43 +03:00
|
|
|
mEditor->PreDestroy(PR_TRUE);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up the controller
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
if (!SuppressEventHandlers(PresContext()))
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLInputElement> inputElement = do_QueryInterface(mContent);
|
|
|
|
if (inputElement)
|
|
|
|
inputElement->GetControllers(getter_AddRefs(controllers));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLTextAreaElement> textAreaElement = do_QueryInterface(mContent);
|
2004-10-02 20:14:56 +04:00
|
|
|
if (textAreaElement) {
|
|
|
|
textAreaElement->GetControllers(getter_AddRefs(controllers));
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (controllers)
|
|
|
|
{
|
|
|
|
PRUint32 numControllers;
|
|
|
|
nsresult rv = controllers->GetControllerCount(&numControllers);
|
|
|
|
NS_ASSERTION((NS_SUCCEEDED(rv)), "bad result in gfx text control destructor");
|
|
|
|
for (PRUint32 i = 0; i < numControllers; i ++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
rv = controllers->GetControllerAt(i, getter_AddRefs(controller));
|
|
|
|
if (NS_SUCCEEDED(rv) && controller)
|
|
|
|
{
|
2002-11-13 02:03:27 +03:00
|
|
|
nsCOMPtr<nsIControllerContext> editController = do_QueryInterface(controller);
|
2002-07-26 21:17:00 +04:00
|
|
|
if (editController)
|
|
|
|
{
|
2003-04-10 22:44:03 +04:00
|
|
|
editController->SetCommandContext(nsnull);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-21 03:49:04 +03:00
|
|
|
mEditor = nsnull;
|
2009-09-03 09:23:47 +04:00
|
|
|
if (mSelCon) {
|
|
|
|
mSelCon->SetScrollableFrame(nsnull);
|
|
|
|
mSelCon = nsnull;
|
|
|
|
}
|
2007-03-19 13:23:29 +03:00
|
|
|
if (mFrameSel) {
|
2008-04-03 06:42:20 +04:00
|
|
|
mFrameSel->DisconnectFromPresShell();
|
2007-03-19 13:23:29 +03:00
|
|
|
mFrameSel = nsnull;
|
|
|
|
}
|
2006-02-21 03:49:04 +03:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), PR_FALSE);
|
2002-07-26 21:17:00 +04:00
|
|
|
if (mTextListener)
|
|
|
|
{
|
2008-07-12 13:26:40 +04:00
|
|
|
mTextListener->SetFrame(nsnull);
|
2004-09-08 01:21:48 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventGroup> systemGroup;
|
2007-05-14 13:11:38 +04:00
|
|
|
mContent->GetSystemEventGroup(getter_AddRefs(systemGroup));
|
2004-09-08 01:21:48 +04:00
|
|
|
nsCOMPtr<nsIDOM3EventTarget> dom3Targ = do_QueryInterface(mContent);
|
|
|
|
if (dom3Targ) {
|
|
|
|
// cast because of ambiguous base
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIDOMEventListener *listener = static_cast<nsIDOMKeyListener*>
|
|
|
|
(mTextListener);
|
2004-09-08 01:21:48 +04:00
|
|
|
|
|
|
|
dom3Targ->RemoveGroupedEventListener(NS_LITERAL_STRING("keydown"),
|
|
|
|
listener, PR_FALSE, systemGroup);
|
|
|
|
dom3Targ->RemoveGroupedEventListener(NS_LITERAL_STRING("keypress"),
|
|
|
|
listener, PR_FALSE, systemGroup);
|
|
|
|
dom3Targ->RemoveGroupedEventListener(NS_LITERAL_STRING("keyup"),
|
|
|
|
listener, PR_FALSE, systemGroup);
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mDidPreDestroy = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2009-12-24 08:21:15 +03:00
|
|
|
nsTextControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2007-09-27 20:01:32 +04:00
|
|
|
if (mInSecureKeyboardInputMode) {
|
|
|
|
MaybeEndSecureKeyboardInput();
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
if (!mDidPreDestroy) {
|
2006-04-10 04:16:29 +04:00
|
|
|
PreDestroy();
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2010-02-07 22:44:32 +03:00
|
|
|
if (mAnonymousDiv && mMutationObserver) {
|
|
|
|
mAnonymousDiv->RemoveMutationObserver(mMutationObserver);
|
|
|
|
}
|
2007-02-18 20:34:09 +03:00
|
|
|
nsContentUtils::DestroyAnonymousContent(&mAnonymousDiv);
|
2009-12-24 08:21:15 +03:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
|
|
|
nsTextControlFrame::GetType() const
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::textInputFrame;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: wouldn't it be nice to get this from the style context!
|
2002-07-27 00:57:24 +04:00
|
|
|
PRBool nsTextControlFrame::IsSingleLineTextControl() const
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2005-12-13 02:53:06 +03:00
|
|
|
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(mContent);
|
|
|
|
if (formControl) {
|
|
|
|
PRInt32 type = formControl->GetType();
|
|
|
|
return (type == NS_FORM_INPUT_TEXT) || (type == NS_FORM_INPUT_PASSWORD);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2002-07-27 00:57:24 +04:00
|
|
|
PRBool nsTextControlFrame::IsTextArea() const
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return mContent && mContent->Tag() == nsGkAtoms::textarea;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: wouldn't it be nice to get this from the style context!
|
2002-07-27 00:57:24 +04:00
|
|
|
PRBool nsTextControlFrame::IsPlainTextControl() const
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
// need to check HTML attribute of mContent and/or CSS.
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-09-27 20:01:32 +04:00
|
|
|
nsresult nsTextControlFrame::MaybeBeginSecureKeyboardInput()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (IsPasswordTextControl() && !mInSecureKeyboardInputMode) {
|
|
|
|
nsIWidget* window = GetWindow();
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
|
|
|
rv = window->BeginSecureKeyboardInput();
|
|
|
|
mInSecureKeyboardInputMode = NS_SUCCEEDED(rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsTextControlFrame::MaybeEndSecureKeyboardInput()
|
|
|
|
{
|
|
|
|
if (mInSecureKeyboardInputMode) {
|
|
|
|
nsIWidget* window = GetWindow();
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
window->EndSecureKeyboardInput();
|
|
|
|
mInSecureKeyboardInputMode = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-27 00:57:24 +04:00
|
|
|
PRBool nsTextControlFrame::IsPasswordTextControl() const
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2005-12-13 02:53:06 +03:00
|
|
|
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(mContent);
|
|
|
|
return formControl && formControl->GetType() == NS_FORM_INPUT_PASSWORD;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-16 10:23:52 +04:00
|
|
|
PRInt32
|
|
|
|
nsTextControlFrame::GetCols()
|
|
|
|
{
|
2005-01-12 22:45:38 +03:00
|
|
|
nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(mContent);
|
2002-09-16 10:23:52 +04:00
|
|
|
NS_ASSERTION(content, "Content is not HTML content!");
|
|
|
|
|
|
|
|
if (IsTextArea()) {
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::cols);
|
2005-01-25 03:02:58 +03:00
|
|
|
if (attr) {
|
|
|
|
PRInt32 cols = attr->Type() == nsAttrValue::eInteger ?
|
|
|
|
attr->GetIntegerValue() : 0;
|
2002-09-16 10:23:52 +04:00
|
|
|
// XXX why a default of 1 char, why hide it
|
|
|
|
return (cols <= 0) ? 1 : cols;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Else we know (assume) it is an input with size attr
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::size);
|
2005-01-25 03:02:58 +03:00
|
|
|
if (attr && attr->Type() == nsAttrValue::eInteger) {
|
|
|
|
PRInt32 cols = attr->GetIntegerValue();
|
2002-09-16 10:23:52 +04:00
|
|
|
if (cols > 0) {
|
|
|
|
return cols;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-09-16 10:23:52 +04:00
|
|
|
return DEFAULT_COLS;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
|
2002-09-16 10:23:52 +04:00
|
|
|
PRInt32
|
|
|
|
nsTextControlFrame::GetRows()
|
|
|
|
{
|
|
|
|
if (IsTextArea()) {
|
2005-01-12 22:45:38 +03:00
|
|
|
nsGenericHTMLElement *content =
|
|
|
|
nsGenericHTMLElement::FromContent(mContent);
|
2002-09-16 10:23:52 +04:00
|
|
|
NS_ASSERTION(content, "Content is not HTML content!");
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::rows);
|
2005-01-25 03:02:58 +03:00
|
|
|
if (attr && attr->Type() == nsAttrValue::eInteger) {
|
|
|
|
PRInt32 rows = attr->GetIntegerValue();
|
2002-09-16 10:23:52 +04:00
|
|
|
return (rows <= 0) ? DEFAULT_ROWS_TEXTAREA : rows;
|
|
|
|
}
|
|
|
|
return DEFAULT_ROWS_TEXTAREA;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2002-09-16 10:23:52 +04:00
|
|
|
return DEFAULT_ROWS;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-23 23:43:48 +04:00
|
|
|
nsresult
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsTextControlFrame::CalcIntrinsicSize(nsIRenderingContext* aRenderingContext,
|
|
|
|
nsSize& aIntrinsicSize)
|
2002-09-16 10:23:52 +04:00
|
|
|
{
|
2002-09-23 23:43:48 +04:00
|
|
|
// Get leading and the Average/MaxAdvance char width
|
2004-10-10 22:30:28 +04:00
|
|
|
nscoord lineHeight = 0;
|
2002-09-23 23:43:48 +04:00
|
|
|
nscoord charWidth = 0;
|
|
|
|
nscoord charMaxAdvance = 0;
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> fontMet;
|
2006-07-06 14:43:51 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
2002-09-23 23:43:48 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
aRenderingContext->SetFont(fontMet);
|
|
|
|
|
2009-05-19 02:13:12 +04:00
|
|
|
lineHeight =
|
|
|
|
nsHTMLReflowState::CalcLineHeight(GetStyleContext(), NS_AUTOHEIGHT);
|
2002-09-23 23:43:48 +04:00
|
|
|
fontMet->GetAveCharWidth(charWidth);
|
|
|
|
fontMet->GetMaxAdvance(charMaxAdvance);
|
2002-09-16 10:23:52 +04:00
|
|
|
|
|
|
|
// Set the width equal to the width in characters
|
2004-08-08 02:04:27 +04:00
|
|
|
PRInt32 cols = GetCols();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
aIntrinsicSize.width = cols * charWidth;
|
2003-11-11 02:42:43 +03:00
|
|
|
|
|
|
|
// To better match IE, take the maximum character width(in twips) and remove
|
|
|
|
// 4 pixels add this on as additional padding(internalPadding). But only do
|
|
|
|
// this if charMaxAdvance != charWidth; if they are equal, this is almost
|
|
|
|
// certainly a fixed-width font.
|
|
|
|
if (charWidth != charMaxAdvance) {
|
2009-09-16 19:01:36 +04:00
|
|
|
nscoord internalPadding = NS_MAX(0, charMaxAdvance -
|
2007-02-07 10:46:44 +03:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(4));
|
|
|
|
nscoord t = nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
// Round to a multiple of t
|
2003-11-11 02:42:43 +03:00
|
|
|
nscoord rest = internalPadding % t;
|
|
|
|
if (rest < t - rest) {
|
|
|
|
internalPadding -= rest;
|
|
|
|
} else {
|
|
|
|
internalPadding += t - rest;
|
|
|
|
}
|
|
|
|
// Now add the extra padding on (so that small input sizes work well)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
aIntrinsicSize.width += internalPadding;
|
2003-12-18 09:06:00 +03:00
|
|
|
} else {
|
|
|
|
// This is to account for the anonymous <br> having a 1 twip width
|
|
|
|
// in Full Standards mode, see BRFrame::Reflow and bug 228752.
|
2007-05-05 09:30:10 +04:00
|
|
|
if (PresContext()->CompatibilityMode() == eCompatibility_FullStandards) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
aIntrinsicSize.width += 1;
|
2003-12-18 09:06:00 +03:00
|
|
|
}
|
2007-08-03 02:06:00 +04:00
|
|
|
|
|
|
|
// Also add in the padding of our anonymous div child. Note that it hasn't
|
|
|
|
// been reflowed yet, so we can't get its used padding, but it shouldn't be
|
|
|
|
// using percentage padding anyway.
|
|
|
|
nsMargin childPadding;
|
|
|
|
if (GetFirstChild(nsnull)->GetStylePadding()->GetPadding(childPadding)) {
|
|
|
|
aIntrinsicSize.width += childPadding.LeftRight();
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Percentage padding on anonymous div?");
|
|
|
|
}
|
2003-11-11 02:42:43 +03:00
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2004-08-08 02:04:27 +04:00
|
|
|
// Increment width with cols * letter-spacing.
|
|
|
|
{
|
|
|
|
const nsStyleCoord& lsCoord = GetStyleText()->mLetterSpacing;
|
|
|
|
if (eStyleUnit_Coord == lsCoord.GetUnit()) {
|
|
|
|
nscoord letterSpacing = lsCoord.GetCoordValue();
|
|
|
|
if (letterSpacing != 0) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
aIntrinsicSize.width += cols * letterSpacing;
|
2004-08-08 02:04:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-16 10:23:52 +04:00
|
|
|
// Set the height equal to total number of rows (times the height of each
|
|
|
|
// line, of course)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
aIntrinsicSize.height = lineHeight * GetRows();
|
|
|
|
|
|
|
|
// Add in the size of the scrollbars for textarea
|
|
|
|
if (IsTextArea()) {
|
2006-12-19 18:08:34 +03:00
|
|
|
nsIFrame* first = GetFirstChild(nsnull);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIScrollableFrame *scrollableFrame = do_QueryFrame(first);
|
2006-12-19 18:08:34 +03:00
|
|
|
NS_ASSERTION(scrollableFrame, "Child must be scrollable");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2008-04-10 08:39:41 +04:00
|
|
|
nsMargin scrollbarSizes =
|
|
|
|
scrollableFrame->GetDesiredScrollbarSizes(PresContext(), aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2006-12-19 18:08:34 +03:00
|
|
|
aIntrinsicSize.width += scrollbarSizes.LeftRight();
|
|
|
|
|
|
|
|
aIntrinsicSize.height += scrollbarSizes.TopBottom();;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-09-23 23:43:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
void
|
|
|
|
nsTextControlFrame::DelayedEditorInit()
|
|
|
|
{
|
|
|
|
nsIDocument* doc = mContent->GetCurrentDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
|
|
|
|
// Flush out content on our document. Have to do this, because script
|
|
|
|
// blockers don't prevent the sink flushing out content and notifying in the
|
|
|
|
// process, which can destroy frames.
|
|
|
|
doc->FlushPendingNotifications(Flush_ContentAndNotify);
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that editor init doesn't do things that would kill us off
|
|
|
|
// (especially off the script blockers it'll create for its DOM mutations).
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
|
|
|
// Time to mess with our security context... See comments in GetValue()
|
|
|
|
// for why this is needed.
|
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
|
|
|
|
|
|
|
InitEditor();
|
|
|
|
if (IsFocusedContent(GetContent()))
|
|
|
|
SetFocus(PR_TRUE, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2009-06-13 13:16:27 +04:00
|
|
|
PRInt32
|
|
|
|
nsTextControlFrame::GetWrapCols()
|
|
|
|
{
|
|
|
|
if (IsTextArea()) {
|
|
|
|
// wrap=off means -1 for wrap width no matter what cols is
|
|
|
|
nsHTMLTextWrap wrapProp;
|
|
|
|
::GetWrapPropertyEnum(mContent, wrapProp);
|
|
|
|
if (wrapProp == eHTMLTextWrap_Off) {
|
|
|
|
// do not wrap when wrap=off
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise we just wrap at the given number of columns
|
|
|
|
return GetCols();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Never wrap non-textareas
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
nsresult
|
2010-02-19 03:03:28 +03:00
|
|
|
nsTextControlFrame::InitEditor()
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2009-01-29 22:46:17 +03:00
|
|
|
// This method initializes our editor, if needed.
|
2010-02-19 03:03:28 +03:00
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
// This code used to be called from CreateAnonymousContent(), but
|
|
|
|
// when the editor set the initial string, it would trigger a
|
|
|
|
// PresShell listener which called FlushPendingNotifications()
|
|
|
|
// during frame construction. This was causing other form controls
|
2010-02-19 03:03:28 +03:00
|
|
|
// to display wrong values. So we call this from a script runner
|
|
|
|
// now.
|
2006-05-15 23:35:12 +04:00
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
// Check if this method has been called already.
|
|
|
|
// If so, just return early.
|
2010-02-19 03:03:28 +03:00
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
if (mUseEditor)
|
|
|
|
return NS_OK;
|
2006-05-15 23:35:12 +04:00
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
// Create an editor
|
2006-05-15 23:35:12 +04:00
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
nsresult rv;
|
|
|
|
mEditor = do_CreateInstance(kTextEditorCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-05-15 23:35:12 +04:00
|
|
|
// Setup the editor flags
|
|
|
|
|
|
|
|
PRUint32 editorFlags = 0;
|
|
|
|
if (IsPlainTextControl())
|
|
|
|
editorFlags |= nsIPlaintextEditor::eEditorPlaintextMask;
|
|
|
|
if (IsSingleLineTextControl())
|
|
|
|
editorFlags |= nsIPlaintextEditor::eEditorSingleLineMask;
|
|
|
|
if (IsPasswordTextControl())
|
|
|
|
editorFlags |= nsIPlaintextEditor::eEditorPasswordMask;
|
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
// All nsTextControlFrames are widgets
|
2006-05-15 23:35:12 +04:00
|
|
|
editorFlags |= nsIPlaintextEditor::eEditorWidgetMask;
|
|
|
|
|
|
|
|
// Use async reflow and painting for text widgets to improve
|
|
|
|
// performance.
|
|
|
|
|
2007-07-10 03:05:44 +04:00
|
|
|
// XXX: Using editor async updates exposes bugs 158782, 151882,
|
|
|
|
// and 165130, so we're disabling it for now, until they
|
|
|
|
// can be addressed.
|
|
|
|
// editorFlags |= nsIPlaintextEditor::eEditorUseAsyncUpdatesMask;
|
2006-05-15 23:35:12 +04:00
|
|
|
|
|
|
|
// Now initialize the editor.
|
|
|
|
//
|
|
|
|
// NOTE: Conversion of '\n' to <BR> happens inside the
|
|
|
|
// editor's Init() call.
|
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
nsPresContext *presContext = PresContext();
|
|
|
|
nsIPresShell *shell = presContext->GetPresShell();
|
2006-05-15 23:35:12 +04:00
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
// Get the DOM document
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc = do_QueryInterface(shell->GetDocument());
|
|
|
|
if (!domdoc)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = mEditor->Init(domdoc, shell, mAnonymousDiv, mSelCon, editorFlags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-05-15 23:35:12 +04:00
|
|
|
|
|
|
|
// Initialize the controller for the editor
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
if (!SuppressEventHandlers(presContext)) {
|
2006-05-15 23:35:12 +04:00
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLInputElement> inputElement =
|
|
|
|
do_QueryInterface(mContent);
|
|
|
|
if (inputElement) {
|
|
|
|
rv = inputElement->GetControllers(getter_AddRefs(controllers));
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLTextAreaElement> textAreaElement =
|
|
|
|
do_QueryInterface(mContent);
|
|
|
|
|
|
|
|
if (!textAreaElement)
|
2009-01-29 22:46:17 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2006-05-15 23:35:12 +04:00
|
|
|
|
|
|
|
rv = textAreaElement->GetControllers(getter_AddRefs(controllers));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2009-01-29 22:46:17 +03:00
|
|
|
return rv;
|
2006-05-15 23:35:12 +04:00
|
|
|
|
|
|
|
if (controllers) {
|
|
|
|
PRUint32 numControllers;
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
rv = controllers->GetControllerCount(&numControllers);
|
|
|
|
for (PRUint32 i = 0; i < numControllers; i ++) {
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
rv = controllers->GetControllerAt(i, getter_AddRefs(controller));
|
|
|
|
if (NS_SUCCEEDED(rv) && controller) {
|
|
|
|
nsCOMPtr<nsIControllerContext> editController =
|
|
|
|
do_QueryInterface(controller);
|
|
|
|
if (editController) {
|
|
|
|
editController->SetCommandContext(mEditor);
|
|
|
|
found = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the plaintext editor
|
|
|
|
nsCOMPtr<nsIPlaintextEditor> textEditor(do_QueryInterface(mEditor));
|
|
|
|
if (textEditor) {
|
|
|
|
// Set up wrapping
|
2009-06-13 13:16:27 +04:00
|
|
|
textEditor->SetWrapColumn(GetWrapCols());
|
2006-05-15 23:35:12 +04:00
|
|
|
|
|
|
|
// Set max text field length
|
|
|
|
PRInt32 maxLength;
|
|
|
|
if (GetMaxLength(&maxLength)) {
|
|
|
|
textEditor->SetMaxTextLength(maxLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mContent) {
|
|
|
|
rv = mEditor->GetFlags(&editorFlags);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2007-02-18 20:34:09 +03:00
|
|
|
return nsnull;
|
2006-05-15 23:35:12 +04:00
|
|
|
|
|
|
|
// Check if the readonly attribute is set.
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::readonly))
|
2006-05-15 23:35:12 +04:00
|
|
|
editorFlags |= nsIPlaintextEditor::eEditorReadonlyMask;
|
|
|
|
|
|
|
|
// Check if the disabled attribute is set.
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled))
|
2006-05-15 23:35:12 +04:00
|
|
|
editorFlags |= nsIPlaintextEditor::eEditorDisabledMask;
|
|
|
|
|
|
|
|
// Disable the selection if necessary.
|
|
|
|
|
|
|
|
if (editorFlags & nsIPlaintextEditor::eEditorDisabledMask)
|
|
|
|
mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF);
|
|
|
|
|
|
|
|
mEditor->SetFlags(editorFlags);
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
// Get the current value of the textfield from the content.
|
|
|
|
nsAutoString defaultValue;
|
|
|
|
GetValue(defaultValue, PR_TRUE);
|
|
|
|
|
|
|
|
// Turn on mUseEditor so that subsequent calls will use the
|
|
|
|
// editor.
|
|
|
|
mUseEditor = PR_TRUE;
|
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
// If we have a default value, insert it under the div we created
|
|
|
|
// above, but be sure to use the editor so that '*' characters get
|
|
|
|
// displayed for password fields, etc. SetValue() will call the
|
|
|
|
// editor for us.
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
if (!defaultValue.IsEmpty()) {
|
|
|
|
// Avoid causing reentrant painting and reflowing by telling the editor
|
|
|
|
// that we don't want it to force immediate view refreshes or force
|
|
|
|
// immediate reflows during any editor calls.
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
rv = mEditor->SetFlags(editorFlags |
|
|
|
|
nsIPlaintextEditor::eEditorUseAsyncUpdatesMask);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
// Now call SetValue() which will make the necessary editor calls to set
|
|
|
|
// the default value. Make sure to turn off undo before setting the default
|
|
|
|
// value, and turn it back on afterwards. This will make sure we can't undo
|
|
|
|
// past the default value.
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
rv = mEditor->EnableUndo(PR_FALSE);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
SetValue(defaultValue);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
rv = mEditor->EnableUndo(PR_TRUE);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),"Transaction Manager must have failed");
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
// Now restore the original editor flags.
|
|
|
|
rv = mEditor->SetFlags(editorFlags);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2005-10-20 06:10:31 +04:00
|
|
|
nsCOMPtr<nsITransactionManager> transMgr;
|
|
|
|
mEditor->GetTransactionManager(getter_AddRefs(transMgr));
|
|
|
|
NS_ENSURE_TRUE(transMgr, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
transMgr->SetMaxTransactionCount(DEFAULT_UNDO_CAP);
|
|
|
|
|
2004-12-05 21:26:13 +03:00
|
|
|
if (IsPasswordTextControl()) {
|
|
|
|
// Disable undo for password textfields. Note that we want to do this at
|
|
|
|
// the very end of InitEditor, so the calls to EnableUndo when setting the
|
|
|
|
// default value don't screw us up.
|
|
|
|
// Since changing the control type does a reframe, we don't have to worry
|
|
|
|
// about dynamic type changes here.
|
|
|
|
mEditor->EnableUndo(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
mEditor->PostCreate();
|
|
|
|
|
2009-11-19 02:38:11 +03:00
|
|
|
if (mTextListener)
|
|
|
|
mEditor->AddEditorObserver(mTextListener);
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
nsresult
|
|
|
|
nsTextControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
mState |= NS_FRAME_INDEPENDENT_SELECTION;
|
|
|
|
|
2010-02-19 03:03:28 +03:00
|
|
|
nsIPresShell* shell = PresContext()->GetPresShell();
|
2002-07-26 21:17:00 +04:00
|
|
|
if (!shell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = shell->GetDocument();
|
2002-07-26 21:17:00 +04:00
|
|
|
if (!doc)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Now create a DIV and add it to the anonymous content child list.
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2008-09-13 02:32:18 +04:00
|
|
|
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::div, nsnull,
|
|
|
|
kNameSpaceID_XHTML);
|
2008-09-26 02:46:52 +04:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2008-09-13 02:32:18 +04:00
|
|
|
nsresult rv = NS_NewHTMLElement(getter_AddRefs(mAnonymousDiv), nodeInfo, PR_FALSE);
|
2007-02-18 20:34:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2009-09-23 15:02:27 +04:00
|
|
|
// Set the necessary classes on the text control. We use class values
|
|
|
|
// instead of a 'style' attribute so that the style comes from a user-agent
|
|
|
|
// style sheet and is still applied even if author styles are disabled.
|
|
|
|
nsAutoString classValue;
|
|
|
|
classValue.AppendLiteral("anonymous-div");
|
2009-06-13 13:16:27 +04:00
|
|
|
PRInt32 wrapCols = GetWrapCols();
|
|
|
|
if (wrapCols >= 0) {
|
2009-09-23 15:02:27 +04:00
|
|
|
classValue.AppendLiteral(" wrap");
|
2009-06-13 13:16:27 +04:00
|
|
|
}
|
2004-05-15 09:09:37 +04:00
|
|
|
if (!IsSingleLineTextControl()) {
|
|
|
|
// We can't just inherit the overflow because setting visible overflow will
|
|
|
|
// crash when the number of lines exceeds the height of the textarea and
|
2004-08-10 05:32:10 +04:00
|
|
|
// setting -moz-hidden-unscrollable overflow (NS_STYLE_OVERFLOW_CLIP)
|
2004-05-15 09:09:37 +04:00
|
|
|
// doesn't paint the caret for some reason.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* disp = GetStyleDisplay();
|
2004-09-05 04:04:04 +04:00
|
|
|
if (disp->mOverflowX != NS_STYLE_OVERFLOW_VISIBLE &&
|
|
|
|
disp->mOverflowX != NS_STYLE_OVERFLOW_CLIP) {
|
2009-09-23 15:02:27 +04:00
|
|
|
classValue.AppendLiteral(" inherit-overflow");
|
2004-05-15 09:09:37 +04:00
|
|
|
}
|
2010-02-07 22:44:32 +03:00
|
|
|
|
|
|
|
mMutationObserver = new nsAnonDivObserver(this);
|
|
|
|
NS_ENSURE_TRUE(mMutationObserver, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
mAnonymousDiv->AddMutationObserver(mMutationObserver);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2009-09-23 15:02:27 +04:00
|
|
|
rv = mAnonymousDiv->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
|
|
|
|
classValue, PR_FALSE);
|
2009-06-13 13:16:27 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
if (!aElements.AppendElement(mAnonymousDiv))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2009-01-29 22:46:17 +03:00
|
|
|
// Create selection
|
|
|
|
|
|
|
|
mFrameSel = do_CreateInstance(kFrameSelectionCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// Create a SelectionController
|
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
mSelCon = new nsTextInputSelectionImpl(mFrameSel, shell,
|
|
|
|
mAnonymousDiv);
|
2009-01-29 22:46:17 +03:00
|
|
|
if (!mSelCon)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
mTextListener = new nsTextInputListener();
|
|
|
|
if (!mTextListener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mTextListener);
|
|
|
|
|
|
|
|
mTextListener->SetFrame(this);
|
|
|
|
mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
|
|
|
|
|
|
|
// Get the caret and make it a selection listener.
|
|
|
|
|
|
|
|
nsRefPtr<nsISelection> domSelection;
|
|
|
|
if (NS_SUCCEEDED(mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(domSelection))) &&
|
|
|
|
domSelection) {
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(domSelection));
|
|
|
|
nsRefPtr<nsCaret> caret;
|
|
|
|
nsCOMPtr<nsISelectionListener> listener;
|
|
|
|
if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret))) && caret) {
|
|
|
|
listener = do_QueryInterface(caret);
|
|
|
|
if (listener) {
|
|
|
|
selPriv->AddSelectionListener(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selPriv->AddSelectionListener(static_cast<nsISelectionListener*>
|
|
|
|
(mTextListener));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Someone forgot a script blocker?");
|
|
|
|
|
|
|
|
if (!nsContentUtils::AddScriptRunner(new EditorInitializer(this))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2010-02-11 20:34:01 +03:00
|
|
|
void
|
|
|
|
nsTextControlFrame::GetAnonymousContent(nsBaseContentList& aElements)
|
|
|
|
{
|
|
|
|
aElements.MaybeAppendElement(mAnonymousDiv);
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord
|
|
|
|
nsTextControlFrame::GetMinWidth(nsIRenderingContext* aRenderingContext)
|
|
|
|
{
|
2007-01-30 08:52:27 +03:00
|
|
|
// Our min width is just our preferred width if we have auto width.
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
2007-01-30 08:52:27 +03:00
|
|
|
result = GetPrefWidth(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-08-22 07:07:25 +04:00
|
|
|
nsSize
|
|
|
|
nsTextControlFrame::ComputeAutoSize(nsIRenderingContext *aRenderingContext,
|
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder,
|
|
|
|
nsSize aPadding, PRBool aShrinkWrap)
|
|
|
|
{
|
|
|
|
nsSize autoSize;
|
|
|
|
nsresult rv = CalcIntrinsicSize(aRenderingContext, autoSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// What now?
|
|
|
|
autoSize.SizeTo(0, 0);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Note: Ancestor ComputeAutoSize only computes a width if we're auto-width
|
|
|
|
else if (GetStylePosition()->mWidth.GetUnit() == eStyleUnit_Auto) {
|
|
|
|
nsSize ancestorAutoSize =
|
|
|
|
nsStackFrame::ComputeAutoSize(aRenderingContext,
|
|
|
|
aCBSize, aAvailableWidth,
|
|
|
|
aMargin, aBorder,
|
|
|
|
aPadding, aShrinkWrap);
|
|
|
|
NS_ASSERTION(ancestorAutoSize.width == autoSize.width,
|
|
|
|
"Incorrect size computed by ComputeAutoSize?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return autoSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// We inherit our GetPrefWidth from nsBoxFrame
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTextControlFrame::Reflow(nsPresContext* aPresContext,
|
2007-01-22 07:27:31 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsTextControlFrame");
|
2002-07-26 21:17:00 +04:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
|
|
|
// make sure the the form registers itself on the initial/first reflow
|
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
2006-04-10 04:16:29 +04:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, PR_TRUE);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
return nsStackFrame::Reflow(aPresContext, aDesiredSize, aReflowState,
|
|
|
|
aStatus);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
|
|
|
nsTextControlFrame::GetPrefSize(nsBoxLayoutState& aState)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2007-01-08 05:57:59 +03:00
|
|
|
if (!DoesNeedRecalc(mPrefSize))
|
|
|
|
return mPrefSize;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2004-06-19 13:07:47 +04:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2002-07-26 21:17:00 +04:00
|
|
|
PropagateDebug(aState);
|
2004-06-19 13:07:47 +04:00
|
|
|
#endif
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize pref(0,0);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsresult rv = CalcIntrinsicSize(aState.GetRenderingContext(), pref);
|
|
|
|
NS_ENSURE_SUCCESS(rv, pref);
|
|
|
|
AddBorderAndPadding(pref);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
mPrefSize = pref;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_rods
|
|
|
|
{
|
|
|
|
nsMargin borderPadding(0,0,0,0);
|
|
|
|
GetBorderAndPadding(borderPadding);
|
|
|
|
nsSize size(169, 24);
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize actual(pref.width/15,
|
|
|
|
pref.height/15);
|
2002-07-26 21:17:00 +04:00
|
|
|
printf("nsGfxText(field) %d,%d %d,%d %d,%d\n",
|
|
|
|
size.width, size.height, actual.width, actual.height, actual.width-size.width, actual.height-size.height); // text field
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
return pref;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
|
|
|
nsTextControlFrame::GetMinSize(nsBoxLayoutState& aState)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXbz why? Why not the nsBoxFrame sizes?
|
2007-01-08 05:57:59 +03:00
|
|
|
return nsBox::GetMinSize(aState);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
|
|
|
nsTextControlFrame::GetMaxSize(nsBoxLayoutState& aState)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXbz why? Why not the nsBoxFrame sizes?
|
2007-01-08 05:57:59 +03:00
|
|
|
return nsBox::GetMaxSize(aState);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2007-01-31 19:02:42 +03:00
|
|
|
nscoord
|
|
|
|
nsTextControlFrame::GetBoxAscent(nsBoxLayoutState& aState)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2009-05-19 02:13:12 +04:00
|
|
|
// Return the baseline of the first (nominal) row, with centering for
|
|
|
|
// single-line controls.
|
|
|
|
|
|
|
|
// First calculate the ascent wrt the client rect
|
|
|
|
nsRect clientRect;
|
|
|
|
GetClientRect(clientRect);
|
|
|
|
nscoord lineHeight =
|
|
|
|
IsSingleLineTextControl() ? clientRect.height :
|
|
|
|
nsHTMLReflowState::CalcLineHeight(GetStyleContext(), NS_AUTOHEIGHT);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFontMetrics> fontMet;
|
|
|
|
nsresult rv =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
|
|
|
|
NS_ENSURE_SUCCESS(rv, 0);
|
|
|
|
|
|
|
|
nscoord ascent = nsLayoutUtils::GetCenteredFontBaseline(fontMet, lineHeight);
|
|
|
|
|
|
|
|
// Now adjust for our borders and padding
|
|
|
|
ascent += clientRect.y;
|
|
|
|
|
2007-01-31 19:02:42 +03:00
|
|
|
return ascent;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2007-01-31 19:02:42 +03:00
|
|
|
PRBool
|
|
|
|
nsTextControlFrame::IsCollapsed(nsBoxLayoutState& aBoxLayoutState)
|
2007-01-22 07:27:31 +03:00
|
|
|
{
|
|
|
|
// We're never collapsed in the box sense.
|
2007-01-31 19:02:42 +03:00
|
|
|
return PR_FALSE;
|
2007-01-22 07:27:31 +03:00
|
|
|
}
|
|
|
|
|
2005-08-17 02:52:48 +04:00
|
|
|
PRBool
|
|
|
|
nsTextControlFrame::IsLeaf() const
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-12-13 02:53:06 +03:00
|
|
|
//IMPLEMENTING NS_IFORMCONTROLFRAME
|
|
|
|
void nsTextControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
2004-04-15 23:45:46 +04:00
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (!aOn) {
|
|
|
|
MaybeEndSecureKeyboardInput();
|
2004-04-15 23:45:46 +04:00
|
|
|
return;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
}
|
2004-05-06 02:48:51 +04:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (!mSelCon)
|
2004-05-06 02:48:51 +04:00
|
|
|
return;
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (NS_SUCCEEDED(InitFocusedValue()))
|
|
|
|
MaybeBeginSecureKeyboardInput();
|
|
|
|
|
2004-04-15 23:45:46 +04:00
|
|
|
// tell the caret to use our selection
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> ourSel;
|
|
|
|
mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(ourSel));
|
|
|
|
if (!ourSel) return;
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsIPresShell* presShell = PresContext()->GetPresShell();
|
2008-07-16 14:52:01 +04:00
|
|
|
nsRefPtr<nsCaret> caret;
|
2004-04-15 23:45:46 +04:00
|
|
|
presShell->GetCaret(getter_AddRefs(caret));
|
|
|
|
if (!caret) return;
|
|
|
|
caret->SetCaretDOMSelection(ourSel);
|
|
|
|
|
|
|
|
// mutual-exclusion: the selection is either controlled by the
|
|
|
|
// document or by the text input/area. Clear any selection in the
|
|
|
|
// document since the focus is now on our independent selection.
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionController> selCon(do_QueryInterface(presShell));
|
|
|
|
nsCOMPtr<nsISelection> docSel;
|
|
|
|
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(docSel));
|
|
|
|
if (!docSel) return;
|
|
|
|
|
|
|
|
PRBool isCollapsed = PR_FALSE;
|
|
|
|
docSel->GetIsCollapsed(&isCollapsed);
|
|
|
|
if (!isCollapsed)
|
|
|
|
docSel->RemoveAllRanges();
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2005-12-13 02:53:06 +03:00
|
|
|
nsresult nsTextControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
if (!mIsProcessing)//some kind of lock.
|
|
|
|
{
|
|
|
|
mIsProcessing = PR_TRUE;
|
2007-10-02 20:56:07 +04:00
|
|
|
PRBool isUserInput = (nsGkAtoms::userInput == aName);
|
|
|
|
if (nsGkAtoms::value == aName || isUserInput)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2007-10-02 20:56:07 +04:00
|
|
|
PRBool fireChangeEvent = GetFireChangeEventState();
|
|
|
|
if (isUserInput) {
|
|
|
|
SetFireChangeEventState(PR_TRUE);
|
|
|
|
}
|
2009-01-29 22:46:17 +03:00
|
|
|
SetValueChanged(PR_TRUE);
|
2007-03-19 13:23:29 +03:00
|
|
|
nsresult rv = SetValue(aValue); // set new text value
|
2007-10-02 20:56:07 +04:00
|
|
|
if (isUserInput) {
|
|
|
|
SetFireChangeEventState(fireChangeEvent);
|
|
|
|
}
|
2007-03-19 13:23:29 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (nsGkAtoms::select == aName)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2003-01-21 18:17:32 +03:00
|
|
|
// Select all the text.
|
|
|
|
//
|
|
|
|
// XXX: This is lame, we can't call mEditor->SelectAll()
|
|
|
|
// because that triggers AutoCopies in unix builds.
|
|
|
|
// Instead, we have to call our own homegrown version
|
|
|
|
// of select all which merely builds a range that selects
|
|
|
|
// all of the content and adds that to the selection.
|
|
|
|
|
2010-02-07 22:44:32 +03:00
|
|
|
SelectAllOrCollapseToEndOfText(PR_TRUE);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
mIsProcessing = PR_FALSE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-12-13 02:53:06 +03:00
|
|
|
nsresult
|
|
|
|
nsTextControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
// Return the value of the property from the widget it is not null.
|
|
|
|
// If widget is null, assume the widget is GFX-rendered and return a member variable instead.
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::value == aName) {
|
2002-07-26 21:17:00 +04:00
|
|
|
GetValue(aValue, PR_FALSE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::GetEditor(nsIEditor **aEditor)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEditor);
|
|
|
|
*aEditor = mEditor;
|
|
|
|
NS_IF_ADDREF(*aEditor);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::OwnsValue(PRBool* aOwnsValue)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aOwnsValue, "aOwnsValue must be non-null");
|
|
|
|
*aOwnsValue = mUseEditor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::GetTextLength(PRInt32* aTextLength)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTextLength);
|
|
|
|
|
|
|
|
nsAutoString textContents;
|
|
|
|
GetValue(textContents, PR_FALSE); // this is expensive!
|
|
|
|
*aTextLength = textContents.Length();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-21 18:17:32 +03:00
|
|
|
nsresult
|
|
|
|
nsTextControlFrame::SetSelectionInternal(nsIDOMNode *aStartNode,
|
|
|
|
PRInt32 aStartOffset,
|
|
|
|
nsIDOMNode *aEndNode,
|
|
|
|
PRInt32 aEndOffset)
|
|
|
|
{
|
|
|
|
// Create a new range to represent the new selection.
|
|
|
|
// Note that we use a new range to avoid having to do
|
|
|
|
// isIncreasing checks to avoid possible errors.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> range = do_CreateInstance(kRangeCID);
|
|
|
|
NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsresult rv = range->SetStart(aStartNode, aStartOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = range->SetEnd(aEndNode, aEndOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Get the selection, clear it and add the new range to it!
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
2006-02-21 03:49:04 +03:00
|
|
|
mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
|
2003-01-21 18:17:32 +03:00
|
|
|
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = selection->RemoveAllRanges();
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return selection->AddRange(range);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-02-07 22:44:32 +03:00
|
|
|
nsTextControlFrame::SelectAllOrCollapseToEndOfText(PRBool aSelect)
|
2003-01-21 18:17:32 +03:00
|
|
|
{
|
|
|
|
if (!mEditor)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> rootElement;
|
|
|
|
nsresult rv = mEditor->GetRootElement(getter_AddRefs(rootElement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> rootContent = do_QueryInterface(rootElement);
|
2010-02-07 22:44:32 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
|
2003-09-27 08:18:26 +04:00
|
|
|
PRInt32 numChildren = rootContent->GetChildCount();
|
2003-01-21 18:17:32 +03:00
|
|
|
|
|
|
|
if (numChildren > 0) {
|
|
|
|
// We never want to place the selection after the last
|
|
|
|
// br under the root node!
|
2003-09-27 08:18:26 +04:00
|
|
|
nsIContent *child = rootContent->GetChildAt(numChildren - 1);
|
|
|
|
if (child) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (child->Tag() == nsGkAtoms::br)
|
2003-01-21 18:17:32 +03:00
|
|
|
--numChildren;
|
|
|
|
}
|
2010-02-07 22:44:32 +03:00
|
|
|
if (!aSelect && numChildren) {
|
|
|
|
child = rootContent->GetChildAt(numChildren - 1);
|
|
|
|
if (child && child->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
rootNode = do_QueryInterface(child);
|
|
|
|
const nsTextFragment* fragment = child->GetText();
|
|
|
|
numChildren = fragment ? fragment->GetLength() : 0;
|
|
|
|
}
|
|
|
|
}
|
2003-01-21 18:17:32 +03:00
|
|
|
}
|
|
|
|
|
2010-02-07 22:44:32 +03:00
|
|
|
return SetSelectionInternal(rootNode, aSelect ? 0 : numChildren,
|
|
|
|
rootNode, numChildren);
|
2003-01-21 18:17:32 +03:00
|
|
|
}
|
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
nsresult
|
|
|
|
nsTextControlFrame::SetSelectionEndPoints(PRInt32 aSelStart, PRInt32 aSelEnd)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2003-01-09 09:06:17 +03:00
|
|
|
NS_ASSERTION(aSelStart <= aSelEnd, "Invalid selection offsets!");
|
|
|
|
|
|
|
|
if (aSelStart > aSelEnd)
|
2002-07-26 21:17:00 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> startNode, endNode;
|
|
|
|
PRInt32 startOffset, endOffset;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
// Calculate the selection start point.
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
nsresult rv = OffsetToDOMPoint(aSelStart, getter_AddRefs(startNode), &startOffset);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
if (aSelStart == aSelEnd) {
|
|
|
|
// Collapsed selection, so start and end are the same!
|
|
|
|
endNode = startNode;
|
|
|
|
endOffset = startOffset;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2003-01-09 09:06:17 +03:00
|
|
|
else {
|
|
|
|
// Selection isn't collapsed so we have to calculate
|
|
|
|
// the end point too.
|
|
|
|
|
|
|
|
rv = OffsetToDOMPoint(aSelEnd, getter_AddRefs(endNode), &endOffset);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2003-01-21 18:17:32 +03:00
|
|
|
return SetSelectionInternal(startNode, startOffset, endNode, endOffset);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::SetSelectionRange(PRInt32 aSelStart, PRInt32 aSelEnd)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2003-01-09 09:06:17 +03:00
|
|
|
NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_INITIALIZED);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
if (aSelStart > aSelEnd) {
|
|
|
|
// Simulate what we'd see SetSelectionStart() was called, followed
|
|
|
|
// by a SetSelectionEnd().
|
|
|
|
|
|
|
|
aSelStart = aSelEnd;
|
|
|
|
}
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
return SetSelectionEndPoints(aSelStart, aSelEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::SetSelectionStart(PRInt32 aSelectionStart)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2003-01-09 09:06:17 +03:00
|
|
|
NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_INITIALIZED);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
PRInt32 selStart = 0, selEnd = 0;
|
|
|
|
|
|
|
|
nsresult rv = GetSelectionRange(&selStart, &selEnd);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aSelectionStart > selEnd) {
|
|
|
|
// Collapse to the new start point.
|
|
|
|
selEnd = aSelectionStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
selStart = aSelectionStart;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
return SetSelectionEndPoints(selStart, selEnd);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::SetSelectionEnd(PRInt32 aSelectionEnd)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2003-01-09 09:06:17 +03:00
|
|
|
NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
PRInt32 selStart = 0, selEnd = 0;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
nsresult rv = GetSelectionRange(&selStart, &selEnd);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aSelectionEnd < selStart) {
|
|
|
|
// Collapse to the new end point.
|
|
|
|
selStart = aSelectionEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
selEnd = aSelectionEnd;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
return SetSelectionEndPoints(selStart, selEnd);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
nsresult
|
|
|
|
nsTextControlFrame::DOMPointToOffset(nsIDOMNode* aNode,
|
|
|
|
PRInt32 aNodeOffset,
|
|
|
|
PRInt32* aResult)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2003-01-09 09:06:17 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aNode && aResult);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
*aResult = 0;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
nsCOMPtr<nsIDOMElement> rootElement;
|
|
|
|
mEditor->GetRootElement(getter_AddRefs(rootElement));
|
|
|
|
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
|
|
|
|
|
|
|
nsresult rv = rootNode->GetChildNodes(getter_AddRefs(nodeList));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRUint32 length = 0;
|
|
|
|
rv = nodeList->GetLength(&length);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!length || aNodeOffset < 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRInt32 i, textOffset = 0;
|
2003-01-27 18:25:38 +03:00
|
|
|
PRInt32 lastIndex = (PRInt32)length - 1;
|
2003-01-09 09:06:17 +03:00
|
|
|
|
2003-01-27 18:25:38 +03:00
|
|
|
for (i = 0; i < (PRInt32)length; i++) {
|
2003-01-09 09:06:17 +03:00
|
|
|
if (rootNode == aNode && i == aNodeOffset) {
|
|
|
|
*aResult = textOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> item;
|
|
|
|
rv = nodeList->Item(i, getter_AddRefs(item));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMText> domText(do_QueryInterface(item));
|
|
|
|
|
|
|
|
if (domText) {
|
|
|
|
PRUint32 textLength = 0;
|
|
|
|
|
|
|
|
rv = domText->GetLength(&textLength);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (item == aNode) {
|
2003-01-27 18:25:38 +03:00
|
|
|
NS_ASSERTION((aNodeOffset >= 0 && aNodeOffset <= (PRInt32)textLength),
|
2003-01-09 09:06:17 +03:00
|
|
|
"Invalid aNodeOffset!");
|
|
|
|
*aResult = textOffset + aNodeOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
textOffset += textLength;
|
|
|
|
}
|
|
|
|
else {
|
2003-01-27 18:25:38 +03:00
|
|
|
// Must be a BR node. If it's not the last BR node
|
|
|
|
// under the root, count it as a newline.
|
2003-01-09 09:06:17 +03:00
|
|
|
|
2003-01-27 18:25:38 +03:00
|
|
|
if (i != lastIndex)
|
|
|
|
++textOffset;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2003-01-09 09:06:17 +03:00
|
|
|
}
|
|
|
|
|
2003-01-27 18:25:38 +03:00
|
|
|
NS_ASSERTION((aNode == rootNode && aNodeOffset == (PRInt32)length),
|
2006-08-29 00:12:37 +04:00
|
|
|
"Invalid node offset!");
|
2003-01-09 09:06:17 +03:00
|
|
|
|
|
|
|
*aResult = textOffset;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2003-01-09 09:06:17 +03:00
|
|
|
nsresult
|
|
|
|
nsTextControlFrame::OffsetToDOMPoint(PRInt32 aOffset,
|
|
|
|
nsIDOMNode** aResult,
|
|
|
|
PRInt32* aPosition)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult && aPosition);
|
|
|
|
|
|
|
|
*aResult = nsnull;
|
|
|
|
*aPosition = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> rootElement;
|
|
|
|
mEditor->GetRootElement(getter_AddRefs(rootElement));
|
|
|
|
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
|
|
|
|
|
|
|
nsresult rv = rootNode->GetChildNodes(getter_AddRefs(nodeList));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRUint32 length = 0;
|
|
|
|
|
|
|
|
rv = nodeList->GetLength(&length);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!length || aOffset < 0) {
|
|
|
|
*aPosition = 0;
|
|
|
|
*aResult = rootNode;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 textOffset = 0;
|
|
|
|
PRUint32 lastIndex = length - 1;
|
|
|
|
|
|
|
|
for (PRUint32 i=0; i<length; i++) {
|
|
|
|
nsCOMPtr<nsIDOMNode> item;
|
|
|
|
rv = nodeList->Item(i, getter_AddRefs(item));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMText> domText(do_QueryInterface(item));
|
|
|
|
|
|
|
|
if (domText) {
|
|
|
|
PRUint32 textLength = 0;
|
|
|
|
|
|
|
|
rv = domText->GetLength(&textLength);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Check if aOffset falls within this range.
|
|
|
|
if (aOffset >= textOffset && aOffset <= textOffset+(PRInt32)textLength) {
|
|
|
|
*aPosition = aOffset - textOffset;
|
|
|
|
*aResult = item;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2003-01-09 09:06:17 +03:00
|
|
|
|
|
|
|
textOffset += textLength;
|
|
|
|
|
|
|
|
// If there aren't any more siblings after this text node,
|
|
|
|
// return the point at the end of this text node!
|
|
|
|
|
|
|
|
if (i == lastIndex) {
|
|
|
|
*aPosition = textLength;
|
|
|
|
*aResult = item;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Must be a BR node, count it as a newline.
|
|
|
|
|
|
|
|
if (aOffset == textOffset || i == lastIndex) {
|
|
|
|
// We've found the correct position, or aOffset takes us
|
|
|
|
// beyond the last child under rootNode, just return the point
|
|
|
|
// under rootNode that is in front of this br.
|
|
|
|
|
|
|
|
*aPosition = i;
|
|
|
|
*aResult = rootNode;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2003-01-09 09:06:17 +03:00
|
|
|
|
|
|
|
++textOffset;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2003-01-09 09:06:17 +03:00
|
|
|
}
|
|
|
|
|
2009-08-14 18:09:00 +04:00
|
|
|
NS_ERROR("We should never get here!");
|
2003-01-09 09:06:17 +03:00
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextControlFrame::GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd)
|
|
|
|
{
|
|
|
|
// make sure we have an editor
|
|
|
|
NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
*aSelectionStart = 0;
|
|
|
|
*aSelectionEnd = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
2006-02-21 03:49:04 +03:00
|
|
|
nsresult rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
|
2003-01-09 09:06:17 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRInt32 numRanges = 0;
|
|
|
|
selection->GetRangeCount(&numRanges);
|
|
|
|
|
|
|
|
if (numRanges < 1)
|
2002-07-26 21:17:00 +04:00
|
|
|
return NS_OK;
|
2003-01-09 09:06:17 +03:00
|
|
|
|
|
|
|
// We only operate on the first range in the selection!
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> firstRange;
|
|
|
|
rv = selection->GetRangeAt(0, getter_AddRefs(firstRange));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(firstRange, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode, endNode;
|
|
|
|
PRInt32 startOffset = 0, endOffset = 0;
|
|
|
|
|
|
|
|
// Get the start point of the range.
|
|
|
|
|
|
|
|
rv = firstRange->GetStartContainer(getter_AddRefs(startNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = firstRange->GetStartOffset(&startOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Get the end point of the range.
|
|
|
|
|
|
|
|
rv = firstRange->GetEndContainer(getter_AddRefs(endNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(endNode, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = firstRange->GetEndOffset(&endOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Convert the start point to a selection offset.
|
|
|
|
|
|
|
|
rv = DOMPointToOffset(startNode, startOffset, aSelectionStart);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Convert the end point to a selection offset.
|
|
|
|
|
|
|
|
return DOMPointToOffset(endNode, endOffset, aSelectionEnd);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
nsISelectionController*
|
|
|
|
nsTextControlFrame::GetOwnedSelectionController()
|
|
|
|
{
|
|
|
|
return mSelCon;
|
|
|
|
}
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
/////END INTERFACE IMPLEMENTATIONS
|
|
|
|
|
|
|
|
////NSIFRAME
|
|
|
|
NS_IMETHODIMP
|
2005-09-07 20:49:21 +04:00
|
|
|
nsTextControlFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
2004-12-31 04:13:27 +03:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-02-21 03:49:04 +03:00
|
|
|
if (!mEditor || !mSelCon)
|
2009-01-29 22:46:17 +03:00
|
|
|
return nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);;
|
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::maxlength == aAttribute)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
PRInt32 maxLength;
|
2005-10-28 15:25:24 +04:00
|
|
|
PRBool maxDefined = GetMaxLength(&maxLength);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
|
|
|
|
if (textEditor)
|
|
|
|
{
|
2005-10-28 15:25:24 +04:00
|
|
|
if (maxDefined)
|
2002-07-26 21:17:00 +04:00
|
|
|
{ // set the maxLength attribute
|
|
|
|
textEditor->SetMaxTextLength(maxLength);
|
|
|
|
// if maxLength>docLength, we need to truncate the doc content
|
|
|
|
}
|
|
|
|
else { // unset the maxLength attribute
|
|
|
|
textEditor->SetMaxTextLength(-1);
|
|
|
|
}
|
|
|
|
}
|
2005-03-24 21:41:39 +03:00
|
|
|
rv = NS_OK; // don't propagate the error
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (nsGkAtoms::readonly == aAttribute)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
PRUint32 flags;
|
|
|
|
mEditor->GetFlags(&flags);
|
2006-12-26 20:47:52 +03:00
|
|
|
if (AttributeExists(nsGkAtoms::readonly))
|
2002-07-26 21:17:00 +04:00
|
|
|
{ // set readonly
|
|
|
|
flags |= nsIPlaintextEditor::eEditorReadonlyMask;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (IsFocusedContent(mContent))
|
2002-07-26 21:17:00 +04:00
|
|
|
mSelCon->SetCaretEnabled(PR_FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // unset readonly
|
|
|
|
flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
|
2006-02-21 03:49:04 +03:00
|
|
|
if (!(flags & nsIPlaintextEditor::eEditorDisabledMask) &&
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
IsFocusedContent(mContent))
|
2002-07-26 21:17:00 +04:00
|
|
|
mSelCon->SetCaretEnabled(PR_TRUE);
|
2010-02-19 03:03:28 +03:00
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
mEditor->SetFlags(flags);
|
|
|
|
}
|
2009-01-29 22:46:17 +03:00
|
|
|
else if (nsGkAtoms::disabled == aAttribute)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
PRUint32 flags;
|
|
|
|
mEditor->GetFlags(&flags);
|
2006-12-26 20:47:52 +03:00
|
|
|
if (AttributeExists(nsGkAtoms::disabled))
|
2002-07-26 21:17:00 +04:00
|
|
|
{ // set disabled
|
|
|
|
flags |= nsIPlaintextEditor::eEditorDisabledMask;
|
2006-02-21 03:49:04 +03:00
|
|
|
mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (IsFocusedContent(mContent))
|
2006-02-21 03:49:04 +03:00
|
|
|
mSelCon->SetCaretEnabled(PR_FALSE);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // unset disabled
|
|
|
|
flags &= ~(nsIPlaintextEditor::eEditorDisabledMask);
|
2006-02-21 03:49:04 +03:00
|
|
|
mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_HIDDEN);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
mEditor->SetFlags(flags);
|
|
|
|
}
|
|
|
|
// Allow the base class to handle common attributes supported
|
|
|
|
// by all form elements...
|
|
|
|
else {
|
2005-09-07 20:49:21 +04:00
|
|
|
rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-07 22:44:32 +03:00
|
|
|
nsresult
|
|
|
|
nsTextControlFrame::GetText(nsString& aText)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2005-10-28 15:25:24 +04:00
|
|
|
nsresult rv = NS_OK;
|
2002-09-16 10:23:52 +04:00
|
|
|
if (IsSingleLineTextControl()) {
|
2002-07-26 21:17:00 +04:00
|
|
|
// If we're going to remove newlines anyway, ignore the wrap property
|
2010-02-07 22:44:32 +03:00
|
|
|
GetValue(aText, PR_TRUE);
|
|
|
|
RemoveNewlines(aText);
|
2002-07-26 21:17:00 +04:00
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea = do_QueryInterface(mContent);
|
|
|
|
if (textArea) {
|
2010-02-07 22:44:32 +03:00
|
|
|
rv = textArea->GetValue(aText);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-28 03:27:55 +03:00
|
|
|
nsresult
|
2002-12-18 02:38:04 +03:00
|
|
|
nsTextControlFrame::GetPhonetic(nsAString& aPhonetic)
|
|
|
|
{
|
|
|
|
aPhonetic.Truncate(0);
|
|
|
|
if (!mEditor)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIEditorIMESupport> imeSupport = do_QueryInterface(mEditor);
|
|
|
|
if (imeSupport) {
|
|
|
|
nsCOMPtr<nsIPhonetic> phonetic = do_QueryInterface(imeSupport);
|
|
|
|
if (phonetic)
|
|
|
|
phonetic->GetPhonetic(aPhonetic);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
///END NSIFRAME OVERLOADS
|
|
|
|
/////BEGIN PROTECTED METHODS
|
|
|
|
|
2002-07-27 00:57:24 +04:00
|
|
|
void nsTextControlFrame::RemoveNewlines(nsString &aString)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
// strip CR/LF and null
|
|
|
|
static const char badChars[] = {10, 13, 0};
|
|
|
|
aString.StripChars(badChars);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-28 15:25:24 +04:00
|
|
|
PRBool
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::GetMaxLength(PRInt32* aSize)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
*aSize = -1;
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(mContent);
|
2002-07-26 21:17:00 +04:00
|
|
|
if (content) {
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::maxlength);
|
2005-01-25 03:02:58 +03:00
|
|
|
if (attr && attr->Type() == nsAttrValue::eInteger) {
|
|
|
|
*aSize = attr->GetIntegerValue();
|
|
|
|
|
2005-10-28 15:25:24 +04:00
|
|
|
return PR_TRUE;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
2005-10-28 15:25:24 +04:00
|
|
|
return PR_FALSE;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// this is where we propagate a content changed event
|
2002-11-21 02:19:45 +03:00
|
|
|
void
|
|
|
|
nsTextControlFrame::FireOnInput()
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-02-21 03:49:04 +03:00
|
|
|
if (!mNotifyOnInput)
|
2002-11-21 02:19:45 +03:00
|
|
|
return; // if notification is turned off, do nothing
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// Dispatch the "input" event
|
2002-07-26 21:17:00 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-08-22 22:34:21 +04:00
|
|
|
nsUIEvent event(PR_TRUE, NS_FORM_INPUT, 0);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2002-11-21 02:19:45 +03:00
|
|
|
// Have the content handle the event, propagating it according to normal
|
|
|
|
// DOM rules.
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell = PresContext()->PresShell();
|
2007-03-26 09:38:22 +04:00
|
|
|
shell->HandleEventWithTarget(&event, nsnull, mContent, &status);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::InitFocusedValue()
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2010-02-07 22:44:32 +03:00
|
|
|
return GetText(mFocusedValue);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::CheckFireOnChange()
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
nsString value;
|
2010-02-07 22:44:32 +03:00
|
|
|
GetText(value);
|
2006-02-21 03:49:04 +03:00
|
|
|
if (!mFocusedValue.Equals(value))
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
mFocusedValue = value;
|
2006-02-21 03:49:04 +03:00
|
|
|
// Dispatch the change event
|
2002-07-26 21:17:00 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-04-29 03:48:28 +04:00
|
|
|
nsInputEvent event(PR_TRUE, NS_FORM_CHANGE, nsnull);
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell = PresContext()->PresShell();
|
2007-03-26 09:38:22 +04:00
|
|
|
shell->HandleEventWithTarget(&event, nsnull, mContent, &status);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//======
|
|
|
|
//privates
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-12-13 02:53:06 +03:00
|
|
|
nsTextControlFrame::GetValue(nsAString& aValue, PRBool aIgnoreWrap) const
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
aValue.Truncate(); // initialize out param
|
2005-04-26 07:31:29 +04:00
|
|
|
nsresult rv = NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
if (mEditor && mUseEditor)
|
|
|
|
{
|
2010-02-07 22:44:32 +03:00
|
|
|
PRBool canCache = aIgnoreWrap && !IsSingleLineTextControl();
|
|
|
|
if (canCache && !mCachedValue.IsEmpty()) {
|
|
|
|
aValue = mCachedValue;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-07 07:27:49 +04:00
|
|
|
PRUint32 flags = (nsIDocumentEncoder::OutputLFLineBreak |
|
|
|
|
nsIDocumentEncoder::OutputPreformatted |
|
|
|
|
nsIDocumentEncoder::OutputPersistNBSP);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
if (PR_TRUE==IsPlainTextControl())
|
|
|
|
{
|
|
|
|
flags |= nsIDocumentEncoder::OutputBodyOnly;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aIgnoreWrap) {
|
2006-07-06 14:43:51 +04:00
|
|
|
nsHTMLTextWrap wrapProp;
|
|
|
|
if (::GetWrapPropertyEnum(mContent, wrapProp) &&
|
|
|
|
wrapProp == eHTMLTextWrap_Hard) {
|
2005-10-28 15:25:24 +04:00
|
|
|
flags |= nsIDocumentEncoder::OutputWrap;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-26 07:31:29 +04:00
|
|
|
// What follows is a bit of a hack. The problem is that we could be in
|
|
|
|
// this method because we're being destroyed for whatever reason while
|
|
|
|
// script is executing. If that happens, editor will run with the
|
|
|
|
// privileges of the executing script, which means it may not be able to
|
|
|
|
// access its own DOM nodes! Let's try to deal with that by pushing a null
|
|
|
|
// JSContext on the JSContext stack to make it clear that we're native
|
|
|
|
// code. Note that any script that's directly trying to access our value
|
|
|
|
// has to be going through some scriptable object to do that and that
|
|
|
|
// already does the relevant security checks.
|
|
|
|
// XXXbz if we could just get the textContent of our anonymous content (eg
|
|
|
|
// if plaintext editor didn't create <br> nodes all over), we wouldn't need
|
|
|
|
// this.
|
2009-02-16 17:11:41 +03:00
|
|
|
{ /* Scope for context pusher */
|
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
2005-04-26 07:31:29 +04:00
|
|
|
|
2009-02-16 17:11:41 +03:00
|
|
|
rv = mEditor->OutputToString(NS_LITERAL_STRING("text/plain"), flags,
|
|
|
|
aValue);
|
2005-04-26 07:31:29 +04:00
|
|
|
}
|
2010-02-07 22:44:32 +03:00
|
|
|
if (canCache) {
|
|
|
|
const_cast<nsTextControlFrame*>(this)->mCachedValue = aValue;
|
|
|
|
} else {
|
|
|
|
const_cast<nsTextControlFrame*>(this)->mCachedValue.Truncate();
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Otherwise get the value from content.
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputControl = do_QueryInterface(mContent);
|
|
|
|
if (inputControl)
|
|
|
|
{
|
2005-04-26 07:31:29 +04:00
|
|
|
rv = inputControl->GetValue(aValue);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLTextAreaElement> textareaControl
|
|
|
|
= do_QueryInterface(mContent);
|
|
|
|
if (textareaControl)
|
|
|
|
{
|
2005-04-26 07:31:29 +04:00
|
|
|
rv = textareaControl->GetValue(aValue);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-26 07:31:29 +04:00
|
|
|
return rv;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// END IMPLEMENTING NS_IFORMCONTROLFRAME
|
|
|
|
|
2007-03-19 13:23:29 +03:00
|
|
|
nsresult
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::SetValue(const nsAString& aValue)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2005-04-26 07:31:29 +04:00
|
|
|
// XXX this method should actually propagate errors! It'd make debugging it
|
|
|
|
// so much easier...
|
2002-07-26 21:17:00 +04:00
|
|
|
if (mEditor && mUseEditor)
|
|
|
|
{
|
2007-07-21 03:19:19 +04:00
|
|
|
// This method isn't used for user-generated changes, except for calls
|
|
|
|
// from nsFileControlFrame which sets mFireChangeEventState==true and
|
|
|
|
// restores it afterwards (ie. we want 'change' events for those changes).
|
|
|
|
// Focused value must be updated to prevent incorrect 'change' events,
|
|
|
|
// but only if user hasn't changed the value.
|
2010-02-07 22:44:32 +03:00
|
|
|
|
|
|
|
// GetText removes newlines from single line control.
|
|
|
|
nsString currentValue;
|
|
|
|
GetText(currentValue);
|
2007-07-21 03:19:19 +04:00
|
|
|
PRBool focusValueInit = !mFireChangeEventState &&
|
2010-02-07 22:44:32 +03:00
|
|
|
mFocusedValue.Equals(currentValue);
|
2007-07-21 03:19:19 +04:00
|
|
|
|
2007-03-19 13:23:29 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = mEditor;
|
|
|
|
nsWeakFrame weakFrame(this);
|
2010-02-07 22:44:32 +03:00
|
|
|
|
2002-07-26 21:17:00 +04:00
|
|
|
// this is necessary to avoid infinite recursion
|
|
|
|
if (!currentValue.Equals(aValue))
|
|
|
|
{
|
|
|
|
// \r is an illegal character in the dom, but people use them,
|
|
|
|
// so convert windows and mac platform linebreaks to \n:
|
|
|
|
// Unfortunately aValue is declared const, so we have to copy
|
|
|
|
// in order to do this substitution.
|
2010-02-07 22:44:32 +03:00
|
|
|
nsString newValue(aValue);
|
|
|
|
if (aValue.FindChar(PRUnichar('\r')) != -1) {
|
|
|
|
::PlatformToDOMLineBreaks(newValue);
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
|
2010-02-07 22:44:32 +03:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
editor->GetDocument(getter_AddRefs(domDoc));
|
2007-03-19 13:23:29 +03:00
|
|
|
NS_ENSURE_STATE(domDoc);
|
2005-04-26 07:31:29 +04:00
|
|
|
|
2009-02-16 17:11:41 +03:00
|
|
|
PRBool outerTransaction;
|
2005-04-26 07:31:29 +04:00
|
|
|
// Time to mess with our security context... See comments in GetValue()
|
|
|
|
// for why this is needed. Note that we have to do this up here, because
|
|
|
|
// otherwise SelectAll() will fail.
|
2009-02-16 17:11:41 +03:00
|
|
|
{ /* Scope for context pusher */
|
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> domSel;
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPriv;
|
|
|
|
mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(domSel));
|
|
|
|
if (domSel)
|
|
|
|
{
|
|
|
|
selPriv = do_QueryInterface(domSel);
|
|
|
|
if (selPriv)
|
|
|
|
selPriv->StartBatchChanges();
|
2006-01-07 02:32:21 +03:00
|
|
|
}
|
2005-03-02 04:19:19 +03:00
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
nsCOMPtr<nsISelectionController> kungFuDeathGrip = mSelCon.get();
|
2010-02-07 22:44:32 +03:00
|
|
|
PRUint32 currentLength = currentValue.Length();
|
|
|
|
PRUint32 newlength = newValue.Length();
|
|
|
|
if (!currentLength ||
|
|
|
|
!StringBeginsWith(newValue, currentValue)) {
|
|
|
|
// Replace the whole text.
|
|
|
|
currentLength = 0;
|
|
|
|
mSelCon->SelectAll();
|
|
|
|
} else {
|
|
|
|
// Collapse selection to the end so that we can append data.
|
|
|
|
SelectAllOrCollapseToEndOfText(PR_FALSE);
|
|
|
|
}
|
|
|
|
const nsAString& insertValue =
|
|
|
|
StringTail(newValue, newlength - currentLength);
|
2009-02-16 17:11:41 +03:00
|
|
|
nsCOMPtr<nsIPlaintextEditor> plaintextEditor = do_QueryInterface(editor);
|
|
|
|
if (!plaintextEditor || !weakFrame.IsAlive()) {
|
|
|
|
NS_WARNING("Somehow not a plaintext editor?");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2005-04-26 07:31:29 +04:00
|
|
|
|
2009-02-16 17:11:41 +03:00
|
|
|
// Since this code does not handle user-generated changes to the text,
|
|
|
|
// make sure we don't fire oninput when the editor notifies us.
|
|
|
|
// (mNotifyOnInput must be reset before we return).
|
|
|
|
|
|
|
|
// To protect against a reentrant call to SetValue, we check whether
|
|
|
|
// another SetValue is already happening for this frame. If it is,
|
|
|
|
// we must wait until we unwind to re-enable oninput events.
|
|
|
|
outerTransaction = mNotifyOnInput;
|
|
|
|
if (outerTransaction)
|
|
|
|
mNotifyOnInput = PR_FALSE;
|
|
|
|
|
|
|
|
// get the flags, remove readonly and disabled, set the value,
|
|
|
|
// restore flags
|
|
|
|
PRUint32 flags, savedFlags;
|
|
|
|
editor->GetFlags(&savedFlags);
|
|
|
|
flags = savedFlags;
|
|
|
|
flags &= ~(nsIPlaintextEditor::eEditorDisabledMask);
|
|
|
|
flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
|
2009-11-12 02:28:16 +03:00
|
|
|
flags |= nsIPlaintextEditor::eEditorUseAsyncUpdatesMask;
|
2009-11-25 20:41:23 +03:00
|
|
|
flags |= nsIPlaintextEditor::eEditorDontEchoPassword;
|
2009-02-16 17:11:41 +03:00
|
|
|
editor->SetFlags(flags);
|
|
|
|
|
|
|
|
// Also don't enforce max-length here
|
|
|
|
PRInt32 savedMaxLength;
|
|
|
|
plaintextEditor->GetMaxTextLength(&savedMaxLength);
|
|
|
|
plaintextEditor->SetMaxTextLength(-1);
|
|
|
|
|
2010-02-07 22:44:32 +03:00
|
|
|
if (insertValue.IsEmpty()) {
|
2009-02-16 17:11:41 +03:00
|
|
|
editor->DeleteSelection(nsIEditor::eNone);
|
2010-02-07 22:44:32 +03:00
|
|
|
} else {
|
|
|
|
plaintextEditor->InsertText(insertValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsSingleLineTextControl()) {
|
|
|
|
mCachedValue = newValue;
|
2009-02-16 17:11:41 +03:00
|
|
|
}
|
2005-02-16 02:14:42 +03:00
|
|
|
|
2009-02-16 17:11:41 +03:00
|
|
|
plaintextEditor->SetMaxTextLength(savedMaxLength);
|
|
|
|
editor->SetFlags(savedFlags);
|
|
|
|
if (selPriv)
|
|
|
|
selPriv->EndBatchChanges();
|
2005-04-26 07:31:29 +04:00
|
|
|
}
|
|
|
|
|
2007-03-19 13:23:29 +03:00
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
2005-03-02 04:19:19 +03:00
|
|
|
if (outerTransaction)
|
|
|
|
mNotifyOnInput = PR_TRUE;
|
2006-07-06 02:15:01 +04:00
|
|
|
|
2007-07-21 03:19:19 +04:00
|
|
|
if (focusValueInit) {
|
2007-01-05 19:31:07 +03:00
|
|
|
// Reset mFocusedValue so the onchange event doesn't fire incorrectly.
|
2006-07-06 02:15:01 +04:00
|
|
|
InitFocusedValue();
|
|
|
|
}
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
2007-03-19 13:23:29 +03:00
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
2009-09-03 09:23:47 +04:00
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(GetFirstChild(nsnull));
|
|
|
|
if (scrollableFrame)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
// Scroll the upper left corner of the text control's
|
|
|
|
// content area back into view.
|
2009-09-03 09:23:47 +04:00
|
|
|
scrollableFrame->ScrollTo(nsPoint(0, 0), nsIScrollableFrame::INSTANT);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Otherwise set the value in content.
|
|
|
|
nsCOMPtr<nsITextControlElement> textControl = do_QueryInterface(mContent);
|
|
|
|
if (textControl)
|
|
|
|
{
|
2002-12-17 02:49:16 +03:00
|
|
|
textControl->TakeTextFrameValue(aValue);
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
2007-03-19 13:23:29 +03:00
|
|
|
return NS_OK;
|
2002-07-26 21:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-04-10 04:16:29 +04:00
|
|
|
nsTextControlFrame::SetInitialChildList(nsIAtom* aListName,
|
2009-07-28 16:53:20 +04:00
|
|
|
nsFrameList& aChildList)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
2006-04-10 04:16:29 +04:00
|
|
|
nsresult rv = nsBoxFrame::SetInitialChildList(aListName, aChildList);
|
2009-01-29 22:46:17 +03:00
|
|
|
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* first = GetFirstChild(nsnull);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
|
|
|
// Mark the scroll frame as being a reflow root. This will allow
|
|
|
|
// incremental reflows to be initiated at the scroll frame, rather
|
|
|
|
// than descending from the root frame of the frame hierarchy.
|
2003-07-04 16:50:32 +04:00
|
|
|
first->AddStateBits(NS_FRAME_REFLOW_ROOT);
|
2002-07-26 21:17:00 +04:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
//register key listeners
|
2004-09-08 01:21:48 +04:00
|
|
|
nsCOMPtr<nsIDOMEventGroup> systemGroup;
|
2007-05-14 13:11:38 +04:00
|
|
|
mContent->GetSystemEventGroup(getter_AddRefs(systemGroup));
|
2004-09-08 01:21:48 +04:00
|
|
|
nsCOMPtr<nsIDOM3EventTarget> dom3Targ = do_QueryInterface(mContent);
|
|
|
|
if (dom3Targ) {
|
|
|
|
// cast because of ambiguous base
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIDOMEventListener *listener = static_cast<nsIDOMKeyListener*>
|
|
|
|
(mTextListener);
|
2004-09-08 01:21:48 +04:00
|
|
|
|
|
|
|
dom3Targ->AddGroupedEventListener(NS_LITERAL_STRING("keydown"),
|
|
|
|
listener, PR_FALSE, systemGroup);
|
|
|
|
dom3Targ->AddGroupedEventListener(NS_LITERAL_STRING("keypress"),
|
|
|
|
listener, PR_FALSE, systemGroup);
|
|
|
|
dom3Targ->AddGroupedEventListener(NS_LITERAL_STRING("keyup"),
|
|
|
|
listener, PR_FALSE, systemGroup);
|
|
|
|
}
|
|
|
|
|
2009-09-03 09:23:47 +04:00
|
|
|
mSelCon->SetScrollableFrame(do_QueryFrame(first));
|
2002-07-26 21:17:00 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::IsScrollable() const
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
return !IsSingleLineTextControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-27 00:57:24 +04:00
|
|
|
nsTextControlFrame::SetValueChanged(PRBool aValueChanged)
|
2002-07-26 21:17:00 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsITextControlElement> elem = do_QueryInterface(mContent);
|
|
|
|
if (elem) {
|
|
|
|
elem->SetValueChanged(aValueChanged);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-08 01:21:48 +04:00
|
|
|
/* static */ void
|
|
|
|
nsTextControlFrame::ShutDown()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(sNativeTextAreaBindings);
|
|
|
|
NS_IF_RELEASE(sNativeInputBindings);
|
|
|
|
}
|
2010-02-07 22:44:32 +03:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsAnonDivObserver, nsIMutationObserver)
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAnonDivObserver::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
mTextControl->ClearValueCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAnonDivObserver::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
mTextControl->ClearValueCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAnonDivObserver::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
mTextControl->ClearValueCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAnonDivObserver::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
mTextControl->ClearValueCache();
|
|
|
|
}
|
|
|
|
|