11684: remove redundant wrapcol variable from editor

(and fix type in obsolete text editor);
Partial work toward 11390, use style rather than embedded PRE for wrapping
  (unfinished, currently ifdefed out).
This commit is contained in:
akkana%netscape.com 1999-08-19 22:11:58 +00:00
Родитель 3bee9b25b4
Коммит b9ced806e8
5 изменённых файлов: 190 добавлений и 394 удалений

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: C++ tab-width: 2 indent-tabs-mode: nil c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL") you may not use this file except in
@ -153,7 +153,6 @@ nsHTMLEditor::nsHTMLEditor()
, mRules(nsnull)
, mIsComposing(PR_FALSE)
, mMaxTextLength(-1)
, mWrapColumn(0)
{
// Done in nsEditor
// NS_INIT_REFCNT();
@ -894,7 +893,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString)
return res;
}
#if defined(DEBUG_akkana)
#if defined(DEBUG_akkana_verbose)
printf("============ Fragment dump :===========\n");
nsCOMPtr<nsIContent> fragc (do_QueryInterface(docfrag));
@ -2565,6 +2564,22 @@ NS_IMETHODIMP nsHTMLEditor::ApplyStyleSheet(const nsString& aURL)
#pragma mark -
#endif
NS_IMETHODIMP
nsHTMLEditor::GetBodyStyleContext(nsIStyleContext** aStyleContext)
{
nsCOMPtr<nsIDOMElement> body;
nsresult res = GetBodyElement(getter_AddRefs(body));
if (NS_FAILED(res)) return res;
nsCOMPtr<nsIContent> content = do_QueryInterface(body);
nsIFrame *frame;
res = mPresShell->GetPrimaryFrameFor(content, &frame);
if (NS_FAILED(res)) return res;
nsCOMPtr<nsIStyleContext> styleContext;
return mPresShell->GetStyleContextFor(frame, aStyleContext);
}
//
// Get the wrap width for the first PRE tag in the document.
// If no PRE tag, throw an error.
@ -2576,6 +2591,10 @@ NS_IMETHODIMP nsHTMLEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
if (! aWrapColumn)
return NS_ERROR_NULL_POINTER;
*aWrapColumn = -1; // default: no wrap
#define PRE_NODE_IN_BODY 1
#ifdef PRE_NODE_IN_BODY
nsCOMPtr<nsIDOMElement> preElement = FindPreElement();
if (!preElement)
return NS_ERROR_UNEXPECTED;
@ -2607,19 +2626,49 @@ NS_IMETHODIMP nsHTMLEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
*aWrapColumn = -1; // no wrap
return NS_OK;
#else /* PRE_NODE_IN_BODY */
nsCOMPtr<nsIStyleContext> styleContext;
res = GetBodyStyleContext(getter_AddRefs(styleContext));
if (NS_FAILED(res)) return res;
const nsStyleText* styleText =
(const nsStyleText*)styleContext->GetStyleData(eStyleStruct_Text);
if (NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace)
*aWrapColumn = 0; // wrap to window width
else if (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace)
{
const nsStylePosition* stylePosition =
(const nsStylePosition*)styleContext->GetStyleData(eStyleStruct_Position);
if (stylePosition->mWidth.GetUnit() == eStyleUnit_Chars)
*aWrapColumn = stylePosition->mWidth.GetIntValue();
else {
#ifdef DEBUG_akkana
printf("Can't set wrap column: style unit is %d\n",
stylePosition->mWidth.GetUnit());
#endif
*aWrapColumn = -1;
return NS_ERROR_UNEXPECTED;
}
}
else
*aWrapColumn = -1;
return NS_OK;
#endif /* PRE_NODE_IN_BODY */
}
//
// Change the wrap width on the first <PRE> tag in this document.
// (Eventually want to search for more than one in case there are
// interspersed quoted text blocks.)
// Alternately: Change the wrap width on the editor style sheet.
//
NS_IMETHODIMP nsHTMLEditor::SetBodyWrapWidth(PRInt32 aWrapColumn)
{
nsresult res;
mWrapColumn = aWrapColumn;
#ifdef PRE_NODE_IN_BODY
nsCOMPtr<nsIDOMElement> preElement = FindPreElement();
if (!preElement)
return NS_ERROR_UNEXPECTED;
@ -2646,13 +2695,14 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyWrapWidth(PRInt32 aWrapColumn)
nsString numCols;
numCols.Append(aWrapColumn, 10);
res = SetAttribute(preElement, colsStr, numCols);
// Layout doesn't detect that this attribute change requires redraw. Sigh.
//HACKForceRedraw(); // This doesn't do it either!
return res;
}
#else /* PRE_NODE_IN_BODY */
// Need to set a style sheet here ...
// Probably need to keep around an mPlaintextStyleSheet for this purpose.
return NS_ERROR_NOT_IMPLEMENTED;
#endif /* PRE_NODE_IN_BODY */
}
//
@ -2989,7 +3039,7 @@ NS_IMETHODIMP nsHTMLEditor::Paste()
printf("Don't know how to insert an image yet!\n");
//nsIImage* image = (nsIImage *)data;
//NS_RELEASE(image);
rv = NS_ERROR_FAILURE; // for now give error code
rv = NS_ERROR_NOT_IMPLEMENTED; // for now give error code
}
}
@ -3069,15 +3119,19 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
// Set the wrap column. If our wrap column is 0,
// i.e. wrap to body width, then don't set it, let the
// document encoder use its own default.
if (mWrapColumn != 0)
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
PRUint32 wc;
if (mWrapColumn < 0)
wc = 0;
else
wc = (PRUint32)mWrapColumn;
if (mWrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
rv = encoder->EncodeToString(aOutputString);
@ -3147,16 +3201,20 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
// Set the wrap column. If our wrap column is 0,
// i.e. wrap to body width, then don't set it, let the
// document encoder use its own default.
if (mWrapColumn != 0)
{
PRUint32 wc;
if (mWrapColumn < 0)
wc = 0;
else
wc = (PRUint32)mWrapColumn;
if (mWrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
return encoder->EncodeToStream(aOutputStream);
}
@ -3611,7 +3669,9 @@ void nsHTMLEditor::ResetTextSelectionForRange(nsIDOMNode *aParent,
aSelection->Extend(endNode, endOffset);
}
#ifdef XP_MAC
#pragma mark -
#endif
//================================================================
// HTML Editor methods
@ -4471,7 +4531,9 @@ nsHTMLEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtr<nsIDOMNode> &parent
}
#ifdef XP_MAC
#pragma mark -
#endif
nsCOMPtr<nsIDOMElement> nsHTMLEditor::FindPreElement()
{

Просмотреть файл

@ -188,6 +188,10 @@ public:
NS_IMETHOD DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed);
/* ------------ Utility Routines, not part of public API -------------- */
NS_IMETHOD GetBodyStyleContext(nsIStyleContext** aStyleContext);
protected:
virtual void InitRules();
@ -432,7 +436,6 @@ protected:
nsCOMPtr<nsIDOMEventListener> mFocusListenerP;
PRBool mIsComposing;
PRInt32 mMaxTextLength;
PRUint32 mWrapColumn;
// friends
friend class nsHTMLEditRules;

Просмотреть файл

@ -1,334 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsTextEditor_h__
#define nsTextEditor_h__
#include "nsITextEditor.h"
#include "nsCOMPtr.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMElement.h"
#include "nsEditor.h"
#include "nsTextEditRules.h"
#include "TypeInState.h"
#include "nsString.h"
class nsIStyleContext;
class nsIDOMRange;
class nsIDOMNode;
/**
* The text editor implementation.<br>
* Use to edit text represented as a DOM tree.
* This class is used for editing both plain text and rich text (attributed text).
*/
class nsTextEditor : public nsEditor, public nsITextEditor
{
public:
// see nsITextEditor for documentation
//Interfaces for addref and release and queryinterface
//NOTE macro used is for classes that inherit from
// another class. Only the base class should use NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
nsTextEditor();
virtual ~nsTextEditor();
//Initialization
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
NS_IMETHOD GetFlags(PRUint32 *aFlags);
NS_IMETHOD SetFlags(PRUint32 aFlags);
NS_IMETHOD GetDocumentLength(PRInt32 *aCount);
//============================================================================
// Methods that are duplicates of nsEditor -- exposed here for convenience
// Editing Operations
NS_IMETHOD SetTextProperty(nsIAtom *aProperty,
const nsString *aAttribute,
const nsString *aValue);
NS_IMETHOD GetTextProperty(nsIAtom *aProperty,
const nsString *aAttribute,
const nsString *aValue,
PRBool &aFirst, PRBool &aAny, PRBool &aAll);
NS_IMETHOD RemoveTextProperty(nsIAtom *aProperty, const nsString *aAttribute);
NS_IMETHOD DeleteSelection(nsIEditor::ECollapsedSelectionAction aAction);
NS_IMETHOD InsertText(const nsString& aStringToInsert);
NS_IMETHOD SetMaxTextLength(PRInt32 aMaxTextLength);
NS_IMETHOD GetMaxTextLength(PRInt32& aMaxTextLength);
NS_IMETHOD InsertBreak();
NS_IMETHOD CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode);
// This method sets background of the page (the body tag)
NS_IMETHOD SetBackgroundColor(const nsString& aColor);
// Transaction control
NS_IMETHOD EnableUndo(PRBool aEnable);
NS_IMETHOD Undo(PRUint32 aCount);
NS_IMETHOD CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo);
NS_IMETHOD Redo(PRUint32 aCount);
NS_IMETHOD CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo);
NS_IMETHOD BeginTransaction();
NS_IMETHOD EndTransaction();
// Selection and navigation -- exposed here for convenience
NS_IMETHOD MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection);
NS_IMETHOD MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection);
NS_IMETHOD MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection);
NS_IMETHOD MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
NS_IMETHOD SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection);
NS_IMETHOD SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection);
NS_IMETHOD SelectAll();
NS_IMETHOD BeginningOfDocument();
NS_IMETHOD EndOfDocument();
NS_IMETHOD ScrollUp(nsIAtom *aIncrement);
NS_IMETHOD ScrollDown(nsIAtom *aIncrement);
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin);
// file handling
NS_IMETHOD Save();
NS_IMETHOD SaveAs(PRBool aSavingCopy);
// cut, copy & paste
NS_IMETHOD Cut();
NS_IMETHOD Copy();
NS_IMETHOD Paste();
NS_IMETHOD PasteAsQuotation();
NS_IMETHOD InsertAsQuotation(const nsString& aQuotedText);
// Input/Output
NS_IMETHOD BeginComposition(void);
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIPrivateTextRangeList* aRangeList, nsTextEventReply* aReply);
NS_IMETHOD EndComposition(void);
NS_IMETHOD OutputToString(nsString& aOutputString,
const nsString& aFormatType,
PRUint32 aFlags);
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharsetOverride,
PRUint32 aFlags);
// Plain text wrapping control
NS_IMETHOD GetBodyWrapWidth(PRInt32 *aWrapColumn);
NS_IMETHOD SetBodyWrapWidth(PRInt32 aWrapColumn);
// Miscellaneous
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
// Logging methods
NS_IMETHOD StartLogging(nsIFileSpec *aLogFile);
NS_IMETHOD StopLogging();
// End of methods implemented in nsEditor
//=============================================================
protected:
// file handling utils
NS_IMETHOD SaveDocument(PRBool saveAs, PRBool saveCopy);
// rules initialization
virtual void InitRules();
// Utility Methods
/** returns the PRE elements that bounds the content of the text document
* @param domdoc The text document
*/
nsCOMPtr<nsIDOMElement> FindPreElement();
/** content-based query returns PR_TRUE if <aProperty aAttribute=aValue> effects aNode
* If <aProperty aAttribute=aValue> contains aNode,
* but <aProperty aAttribute=SomeOtherValue> also contains aNode and the second is
* more deeply nested than the first, then the first does not effect aNode.
*
* @param aNode The target of the query
* @param aProperty The property that we are querying for
* @param aAttribute The attribute of aProperty, example: color in <FONT color="blue">
* May be null.
* @param aValue The value of aAttribute, example: blue in <FONT color="blue">
* May be null. Ignored if aAttribute is null.
* @param aIsSet [OUT] PR_TRUE if <aProperty aAttribute=aValue> effects aNode.
* @param aStyleNode [OUT] set to the node representing <aProperty aAttribute=aValue>, if found.
* null if aIsSet is returned as PR_FALSE;
*/
virtual void IsTextPropertySetByContent(nsIDOMNode *aNode,
nsIAtom *aProperty,
const nsString *aAttribute,
const nsString *aValue,
PRBool &aIsSet,
nsIDOMNode **aStyleNode) const;
/** style-based query returns PR_TRUE if (aProperty, aAttribute) is set in aSC.
* WARNING: not well tested yet since we don't do style-based queries anywhere.
*/
virtual void IsTextStyleSet(nsIStyleContext *aSC,
nsIAtom *aProperty,
const nsString *aAttributes,
PRBool &aIsSet) const;
/** Moves the content between (aNode, aStartOffset) and (aNode, aEndOffset)
* into aNewParentNode, splitting aNode as necessary to maintain the relative
* position of all leaf content.
* @param aNode The node whose content we're repositioning.
* aNode can be either a text node or a container node.
* @param aNewParentNode The node that will be the repositioned contents' parent.
* The caller is responsible for allocating aNewParentNode
* @param aStartOffset The start offset of the content of aNode
* @param aEndOffset The end offset of the content of aNode.
*/
NS_IMETHOD MoveContentOfNodeIntoNewParent(nsIDOMNode *aNode,
nsIDOMNode *aNewParentNode,
PRInt32 aStartOffset,
PRInt32 aEndOffset);
/** Moves the content between (aStartNode, aStartOffset) and (aEndNode, aEndOffset)
* into aNewParentNode, splitting aStartNode and aEndNode as necessary to maintain
* the relative position of all leaf content.
* The content between the two endpoints MUST be "contiguous" in the sense that
* it is all in the same block. Another way of saying this is all content nodes
* between aStartNode and aEndNode must be inline.
* @see IntermediateNodesAreInline
*
* @param aStartNode The left node, can be either a text node or a container node.
* @param aStartOffset The start offset in the content of aStartNode
* @param aEndNode The right node, can be either a text node or a container node.
* @param aEndOffset The end offset in the content of aEndNode.
* @param aGrandParentNode The common ancestor of aStartNode and aEndNode.
* aGrandParentNode will be the parent of aNewParentNode.
* @param aNewParentNode The node that will be the repositioned contents' parent.
* The caller is responsible for allocating aNewParentNode
*/
NS_IMETHOD MoveContiguousContentIntoNewParent(nsIDOMNode *aStartNode,
PRInt32 aStartOffset,
nsIDOMNode *aEndNode,
PRInt32 aEndOffset,
nsIDOMNode *aGrandParentNode,
nsIDOMNode *aNewParentNode);
NS_IMETHOD SetTextPropertiesForNode(nsIDOMNode *aNode,
nsIDOMNode *aParent,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsIAtom *aPropName,
const nsString *aAttribute,
const nsString *aValue);
NS_IMETHOD SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
PRInt32 aStartOffset,
nsIDOMNode *aEndNode,
PRInt32 aEndOffset,
nsIDOMNode *aParent,
nsIAtom *aPropName,
const nsString *aAttribute,
const nsString *aValue);
NS_IMETHOD SetTextPropertiesForNodeWithDifferentParents(nsIDOMRange *aRange,
nsIDOMNode *aStartNode,
PRInt32 aStartOffset,
nsIDOMNode *aEndNode,
PRInt32 aEndOffset,
nsIDOMNode *aParent,
nsIAtom *aPropName,
const nsString *aAttribute,
const nsString *aValue);
NS_IMETHOD RemoveTextPropertiesForNode(nsIDOMNode *aNode,
nsIDOMNode *aParent,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsIAtom *aPropName,
const nsString *aAttribute);
NS_IMETHOD RemoveTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
PRInt32 aStartOffset,
nsIDOMNode *aEndNode,
PRInt32 aEndOffset,
nsIDOMNode *aParent,
nsIAtom *aPropName,
const nsString *aAttribute);
NS_IMETHOD RemoveTextPropertiesForNodeWithDifferentParents(nsIDOMNode *aStartNode,
PRInt32 aStartOffset,
nsIDOMNode *aEndNode,
PRInt32 aEndOffset,
nsIDOMNode *aParent,
nsIAtom *aPropName,
const nsString *aAttribute);
NS_IMETHOD SetTypeInStateForProperty(TypeInState &aTypeInState,
nsIAtom *aPropName,
const nsString *aAttribute,
const nsString *aValue);
void GetTextSelectionOffsetsForRange(nsIDOMSelection *aSelection,
nsIDOMNode **aParent,
PRInt32 &aStartOffset,
PRInt32 &aEndOffset);
void ResetTextSelectionForRange(nsIDOMNode *aParent,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsIDOMSelection *aSelection);
/** returns the absolute position of the end points of aSelection
* in the document as a text stream.
*/
nsresult GetTextSelectionOffsets(nsIDOMSelection *aSelection,
PRInt32 &aStartOffset,
PRInt32 &aEndOffset);
TypeInState *GetTypeInState();
/** simple utility to handle any error with event listener allocation or registration */
void HandleEventListenerError();
// this overrides the base class implementation. It is not exported in nsITextEditor.
NS_IMETHOD DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed);
// Data members
protected:
TypeInState *mTypeInState;
nsTextEditRules *mRules;
nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
nsCOMPtr<nsIDOMEventListener> mTextListenerP;
nsCOMPtr<nsIDOMEventListener> mCompositionListenerP;
nsCOMPtr<nsIDOMEventListener> mDragListenerP;
nsCOMPtr<nsIDOMEventListener> mFocusListenerP;
PRBool mIsComposing;
PRInt32 mMaxTextLength;
PRUint32 mWrapColumn;
// friends
friend class nsTextEditRules;
};
#endif //nsTextEditor_h__

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: C++ tab-width: 2 indent-tabs-mode: nil c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL") you may not use this file except in
@ -153,7 +153,6 @@ nsHTMLEditor::nsHTMLEditor()
, mRules(nsnull)
, mIsComposing(PR_FALSE)
, mMaxTextLength(-1)
, mWrapColumn(0)
{
// Done in nsEditor
// NS_INIT_REFCNT();
@ -894,7 +893,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString)
return res;
}
#if defined(DEBUG_akkana)
#if defined(DEBUG_akkana_verbose)
printf("============ Fragment dump :===========\n");
nsCOMPtr<nsIContent> fragc (do_QueryInterface(docfrag));
@ -2565,6 +2564,22 @@ NS_IMETHODIMP nsHTMLEditor::ApplyStyleSheet(const nsString& aURL)
#pragma mark -
#endif
NS_IMETHODIMP
nsHTMLEditor::GetBodyStyleContext(nsIStyleContext** aStyleContext)
{
nsCOMPtr<nsIDOMElement> body;
nsresult res = GetBodyElement(getter_AddRefs(body));
if (NS_FAILED(res)) return res;
nsCOMPtr<nsIContent> content = do_QueryInterface(body);
nsIFrame *frame;
res = mPresShell->GetPrimaryFrameFor(content, &frame);
if (NS_FAILED(res)) return res;
nsCOMPtr<nsIStyleContext> styleContext;
return mPresShell->GetStyleContextFor(frame, aStyleContext);
}
//
// Get the wrap width for the first PRE tag in the document.
// If no PRE tag, throw an error.
@ -2576,6 +2591,10 @@ NS_IMETHODIMP nsHTMLEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
if (! aWrapColumn)
return NS_ERROR_NULL_POINTER;
*aWrapColumn = -1; // default: no wrap
#define PRE_NODE_IN_BODY 1
#ifdef PRE_NODE_IN_BODY
nsCOMPtr<nsIDOMElement> preElement = FindPreElement();
if (!preElement)
return NS_ERROR_UNEXPECTED;
@ -2607,19 +2626,49 @@ NS_IMETHODIMP nsHTMLEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
*aWrapColumn = -1; // no wrap
return NS_OK;
#else /* PRE_NODE_IN_BODY */
nsCOMPtr<nsIStyleContext> styleContext;
res = GetBodyStyleContext(getter_AddRefs(styleContext));
if (NS_FAILED(res)) return res;
const nsStyleText* styleText =
(const nsStyleText*)styleContext->GetStyleData(eStyleStruct_Text);
if (NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace)
*aWrapColumn = 0; // wrap to window width
else if (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace)
{
const nsStylePosition* stylePosition =
(const nsStylePosition*)styleContext->GetStyleData(eStyleStruct_Position);
if (stylePosition->mWidth.GetUnit() == eStyleUnit_Chars)
*aWrapColumn = stylePosition->mWidth.GetIntValue();
else {
#ifdef DEBUG_akkana
printf("Can't set wrap column: style unit is %d\n",
stylePosition->mWidth.GetUnit());
#endif
*aWrapColumn = -1;
return NS_ERROR_UNEXPECTED;
}
}
else
*aWrapColumn = -1;
return NS_OK;
#endif /* PRE_NODE_IN_BODY */
}
//
// Change the wrap width on the first <PRE> tag in this document.
// (Eventually want to search for more than one in case there are
// interspersed quoted text blocks.)
// Alternately: Change the wrap width on the editor style sheet.
//
NS_IMETHODIMP nsHTMLEditor::SetBodyWrapWidth(PRInt32 aWrapColumn)
{
nsresult res;
mWrapColumn = aWrapColumn;
#ifdef PRE_NODE_IN_BODY
nsCOMPtr<nsIDOMElement> preElement = FindPreElement();
if (!preElement)
return NS_ERROR_UNEXPECTED;
@ -2646,13 +2695,14 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyWrapWidth(PRInt32 aWrapColumn)
nsString numCols;
numCols.Append(aWrapColumn, 10);
res = SetAttribute(preElement, colsStr, numCols);
// Layout doesn't detect that this attribute change requires redraw. Sigh.
//HACKForceRedraw(); // This doesn't do it either!
return res;
}
#else /* PRE_NODE_IN_BODY */
// Need to set a style sheet here ...
// Probably need to keep around an mPlaintextStyleSheet for this purpose.
return NS_ERROR_NOT_IMPLEMENTED;
#endif /* PRE_NODE_IN_BODY */
}
//
@ -2989,7 +3039,7 @@ NS_IMETHODIMP nsHTMLEditor::Paste()
printf("Don't know how to insert an image yet!\n");
//nsIImage* image = (nsIImage *)data;
//NS_RELEASE(image);
rv = NS_ERROR_FAILURE; // for now give error code
rv = NS_ERROR_NOT_IMPLEMENTED; // for now give error code
}
}
@ -3069,15 +3119,19 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
// Set the wrap column. If our wrap column is 0,
// i.e. wrap to body width, then don't set it, let the
// document encoder use its own default.
if (mWrapColumn != 0)
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
PRUint32 wc;
if (mWrapColumn < 0)
wc = 0;
else
wc = (PRUint32)mWrapColumn;
if (mWrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
rv = encoder->EncodeToString(aOutputString);
@ -3147,16 +3201,20 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
// Set the wrap column. If our wrap column is 0,
// i.e. wrap to body width, then don't set it, let the
// document encoder use its own default.
if (mWrapColumn != 0)
{
PRUint32 wc;
if (mWrapColumn < 0)
wc = 0;
else
wc = (PRUint32)mWrapColumn;
if (mWrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
return encoder->EncodeToStream(aOutputStream);
}
@ -3611,7 +3669,9 @@ void nsHTMLEditor::ResetTextSelectionForRange(nsIDOMNode *aParent,
aSelection->Extend(endNode, endOffset);
}
#ifdef XP_MAC
#pragma mark -
#endif
//================================================================
// HTML Editor methods
@ -4471,7 +4531,9 @@ nsHTMLEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtr<nsIDOMNode> &parent
}
#ifdef XP_MAC
#pragma mark -
#endif
nsCOMPtr<nsIDOMElement> nsHTMLEditor::FindPreElement()
{

Просмотреть файл

@ -188,6 +188,10 @@ public:
NS_IMETHOD DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed);
/* ------------ Utility Routines, not part of public API -------------- */
NS_IMETHOD GetBodyStyleContext(nsIStyleContext** aStyleContext);
protected:
virtual void InitRules();
@ -432,7 +436,6 @@ protected:
nsCOMPtr<nsIDOMEventListener> mFocusListenerP;
PRBool mIsComposing;
PRInt32 mMaxTextLength;
PRUint32 mWrapColumn;
// friends
friend class nsHTMLEditRules;