HTMLEditor.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_HTMLEditor_h
  6. #define mozilla_HTMLEditor_h
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/CSSEditUtils.h"
  9. #include "mozilla/StyleSheet.h"
  10. #include "mozilla/TextEditor.h"
  11. #include "mozilla/UniquePtr.h"
  12. #include "mozilla/dom/Element.h"
  13. #include "mozilla/dom/File.h"
  14. #include "nsAttrName.h"
  15. #include "nsCOMPtr.h"
  16. #include "nsIContentFilter.h"
  17. #include "nsICSSLoaderObserver.h"
  18. #include "nsIDocumentObserver.h"
  19. #include "nsIDOMElement.h"
  20. #include "nsIDOMEventListener.h"
  21. #include "nsIEditor.h"
  22. #include "nsIEditorMailSupport.h"
  23. #include "nsIEditorStyleSheets.h"
  24. #include "nsIEditorUtils.h"
  25. #include "nsIEditRules.h"
  26. #include "nsIHTMLAbsPosEditor.h"
  27. #include "nsIHTMLEditor.h"
  28. #include "nsIHTMLInlineTableEditor.h"
  29. #include "nsIHTMLObjectResizeListener.h"
  30. #include "nsIHTMLObjectResizer.h"
  31. #include "nsISelectionListener.h"
  32. #include "nsITableEditor.h"
  33. #include "nsPoint.h"
  34. #include "nsStubMutationObserver.h"
  35. #include "nsTArray.h"
  36. class nsDocumentFragment;
  37. class nsIDOMKeyEvent;
  38. class nsITransferable;
  39. class nsIClipboard;
  40. class nsILinkHandler;
  41. class nsTableWrapperFrame;
  42. class nsIDOMRange;
  43. class nsRange;
  44. namespace mozilla {
  45. class HTMLEditorEventListener;
  46. class HTMLEditRules;
  47. class TextEditRules;
  48. class TypeInState;
  49. class WSRunObject;
  50. struct PropItem;
  51. template<class T> class OwningNonNull;
  52. namespace dom {
  53. class DocumentFragment;
  54. } // namespace dom
  55. namespace widget {
  56. struct IMEState;
  57. } // namespace widget
  58. /**
  59. * The HTML editor implementation.<br>
  60. * Use to edit HTML document represented as a DOM tree.
  61. */
  62. class HTMLEditor final : public TextEditor
  63. , public nsIHTMLEditor
  64. , public nsIHTMLObjectResizer
  65. , public nsIHTMLAbsPosEditor
  66. , public nsITableEditor
  67. , public nsIHTMLInlineTableEditor
  68. , public nsIEditorStyleSheets
  69. , public nsICSSLoaderObserver
  70. , public nsStubMutationObserver
  71. {
  72. private:
  73. enum BlockTransformationType
  74. {
  75. eNoOp,
  76. eReplaceParent = 1,
  77. eInsertParent = 2
  78. };
  79. const char16_t kNBSP = 160;
  80. public:
  81. enum ResizingRequestID
  82. {
  83. kX = 0,
  84. kY = 1,
  85. kWidth = 2,
  86. kHeight = 3
  87. };
  88. NS_DECL_ISUPPORTS_INHERITED
  89. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLEditor, TextEditor)
  90. HTMLEditor();
  91. bool GetReturnInParagraphCreatesNewParagraph();
  92. Element* GetSelectionContainer();
  93. // TextEditor overrides
  94. NS_IMETHOD GetIsDocumentEditable(bool* aIsDocumentEditable) override;
  95. NS_IMETHOD BeginningOfDocument() override;
  96. virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent) override;
  97. virtual already_AddRefed<nsIContent> GetFocusedContent() override;
  98. virtual already_AddRefed<nsIContent> GetFocusedContentForIME() override;
  99. virtual bool IsActiveInDOMWindow() override;
  100. virtual already_AddRefed<dom::EventTarget> GetDOMEventTarget() override;
  101. virtual Element* GetEditorRoot() override;
  102. virtual already_AddRefed<nsIContent> FindSelectionRoot(
  103. nsINode *aNode) override;
  104. virtual bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent) override;
  105. virtual already_AddRefed<nsIContent> GetInputEventTargetContent() override;
  106. virtual bool IsEditable(nsINode* aNode) override;
  107. using EditorBase::IsEditable;
  108. virtual nsresult RemoveAttributeOrEquivalent(
  109. Element* aElement,
  110. nsIAtom* aAttribute,
  111. bool aSuppressTransaction) override;
  112. virtual nsresult SetAttributeOrEquivalent(Element* aElement,
  113. nsIAtom* aAttribute,
  114. const nsAString& aValue,
  115. bool aSuppressTransaction) override;
  116. using EditorBase::RemoveAttributeOrEquivalent;
  117. using EditorBase::SetAttributeOrEquivalent;
  118. // nsStubMutationObserver overrides
  119. NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
  120. NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
  121. NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
  122. // nsIEditorIMESupport overrides
  123. NS_IMETHOD GetPreferredIMEState(widget::IMEState* aState) override;
  124. // nsIHTMLEditor methods
  125. NS_DECL_NSIHTMLEDITOR
  126. // nsIHTMLObjectResizer methods (implemented in HTMLObjectResizer.cpp)
  127. NS_DECL_NSIHTMLOBJECTRESIZER
  128. // nsIHTMLAbsPosEditor methods (implemented in HTMLAbsPositionEditor.cpp)
  129. NS_DECL_NSIHTMLABSPOSEDITOR
  130. // nsIHTMLInlineTableEditor methods (implemented in HTMLInlineTableEditor.cpp)
  131. NS_DECL_NSIHTMLINLINETABLEEDITOR
  132. // XXX Following methods are not overriding but defined here...
  133. nsresult CopyLastEditableChildStyles(nsIDOMNode* aPreviousBlock,
  134. nsIDOMNode* aNewBlock,
  135. Element** aOutBrNode);
  136. nsresult LoadHTML(const nsAString& aInputString);
  137. nsresult GetCSSBackgroundColorState(bool* aMixed, nsAString& aOutColor,
  138. bool aBlockLevel);
  139. NS_IMETHOD GetHTMLBackgroundColorState(bool* aMixed, nsAString& outColor);
  140. // nsIEditorStyleSheets methods
  141. NS_IMETHOD AddStyleSheet(const nsAString& aURL) override;
  142. NS_IMETHOD ReplaceStyleSheet(const nsAString& aURL) override;
  143. NS_IMETHOD RemoveStyleSheet(const nsAString &aURL) override;
  144. NS_IMETHOD AddOverrideStyleSheet(const nsAString& aURL) override;
  145. NS_IMETHOD ReplaceOverrideStyleSheet(const nsAString& aURL) override;
  146. NS_IMETHOD RemoveOverrideStyleSheet(const nsAString &aURL) override;
  147. NS_IMETHOD EnableStyleSheet(const nsAString& aURL, bool aEnable) override;
  148. // nsIEditorMailSupport methods
  149. NS_DECL_NSIEDITORMAILSUPPORT
  150. // nsITableEditor methods
  151. NS_IMETHOD InsertTableCell(int32_t aNumber, bool aAfter) override;
  152. NS_IMETHOD InsertTableColumn(int32_t aNumber, bool aAfter) override;
  153. NS_IMETHOD InsertTableRow(int32_t aNumber, bool aAfter) override;
  154. NS_IMETHOD DeleteTable() override;
  155. NS_IMETHOD DeleteTableCell(int32_t aNumber) override;
  156. NS_IMETHOD DeleteTableCellContents() override;
  157. NS_IMETHOD DeleteTableColumn(int32_t aNumber) override;
  158. NS_IMETHOD DeleteTableRow(int32_t aNumber) override;
  159. NS_IMETHOD SelectTableCell() override;
  160. NS_IMETHOD SelectBlockOfCells(nsIDOMElement* aStartCell,
  161. nsIDOMElement* aEndCell) override;
  162. NS_IMETHOD SelectTableRow() override;
  163. NS_IMETHOD SelectTableColumn() override;
  164. NS_IMETHOD SelectTable() override;
  165. NS_IMETHOD SelectAllTableCells() override;
  166. NS_IMETHOD SwitchTableCellHeaderType(nsIDOMElement* aSourceCell,
  167. nsIDOMElement** aNewCell) override;
  168. NS_IMETHOD JoinTableCells(bool aMergeNonContiguousContents) override;
  169. NS_IMETHOD SplitTableCell() override;
  170. NS_IMETHOD NormalizeTable(nsIDOMElement* aTable) override;
  171. NS_IMETHOD GetCellIndexes(nsIDOMElement* aCell,
  172. int32_t* aRowIndex, int32_t* aColIndex) override;
  173. NS_IMETHOD GetTableSize(nsIDOMElement* aTable,
  174. int32_t* aRowCount, int32_t* aColCount) override;
  175. NS_IMETHOD GetCellAt(nsIDOMElement* aTable, int32_t aRowIndex,
  176. int32_t aColIndex, nsIDOMElement **aCell) override;
  177. NS_IMETHOD GetCellDataAt(nsIDOMElement* aTable,
  178. int32_t aRowIndex, int32_t aColIndex,
  179. nsIDOMElement** aCell,
  180. int32_t* aStartRowIndex, int32_t* aStartColIndex,
  181. int32_t* aRowSpan, int32_t* aColSpan,
  182. int32_t* aActualRowSpan, int32_t* aActualColSpan,
  183. bool* aIsSelected) override;
  184. NS_IMETHOD GetFirstRow(nsIDOMElement* aTableElement,
  185. nsIDOMNode** aRowNode) override;
  186. NS_IMETHOD GetNextRow(nsIDOMNode* aCurrentRowNode,
  187. nsIDOMNode** aRowNode) override;
  188. nsresult GetLastCellInRow(nsIDOMNode* aRowNode,
  189. nsIDOMNode** aCellNode);
  190. NS_IMETHOD SetSelectionAfterTableEdit(nsIDOMElement* aTable, int32_t aRow,
  191. int32_t aCol, int32_t aDirection,
  192. bool aSelected) override;
  193. NS_IMETHOD GetSelectedOrParentTableElement(
  194. nsAString& aTagName, int32_t* aSelectedCount,
  195. nsIDOMElement** aTableElement) override;
  196. NS_IMETHOD GetSelectedCellsType(nsIDOMElement* aElement,
  197. uint32_t* aSelectionType) override;
  198. nsresult GetCellFromRange(nsRange* aRange, nsIDOMElement** aCell);
  199. /**
  200. * Finds the first selected cell in first range of selection
  201. * This is in the *order of selection*, not order in the table
  202. * (i.e., each cell added to selection is added in another range
  203. * in the selection's rangelist, independent of location in table)
  204. * aRange is optional: returns the range around the cell.
  205. */
  206. NS_IMETHOD GetFirstSelectedCell(nsIDOMRange** aRange,
  207. nsIDOMElement** aCell) override;
  208. /**
  209. * Get next cell until no more are found. Always use GetFirstSelected cell
  210. * first aRange is optional: returns the range around the cell.
  211. */
  212. NS_IMETHOD GetNextSelectedCell(nsIDOMRange** aRange,
  213. nsIDOMElement** aCell) override;
  214. /**
  215. * Upper-left-most selected cell in table.
  216. */
  217. NS_IMETHOD GetFirstSelectedCellInTable(int32_t* aRowIndex, int32_t* aColIndex,
  218. nsIDOMElement** aCell) override;
  219. // Miscellaneous
  220. /**
  221. * This sets background on the appropriate container element (table, cell,)
  222. * or calls into nsTextEditor to set the page background.
  223. */
  224. nsresult SetCSSBackgroundColor(const nsAString& aColor);
  225. nsresult SetHTMLBackgroundColor(const nsAString& aColor);
  226. // Block methods moved from EditorBase
  227. static Element* GetBlockNodeParent(nsINode* aNode);
  228. static nsIDOMNode* GetBlockNodeParent(nsIDOMNode* aNode);
  229. static Element* GetBlock(nsINode& aNode);
  230. void IsNextCharInNodeWhitespace(nsIContent* aContent,
  231. int32_t aOffset,
  232. bool* outIsSpace,
  233. bool* outIsNBSP,
  234. nsIContent** outNode = nullptr,
  235. int32_t* outOffset = 0);
  236. void IsPrevCharInNodeWhitespace(nsIContent* aContent,
  237. int32_t aOffset,
  238. bool* outIsSpace,
  239. bool* outIsNBSP,
  240. nsIContent** outNode = nullptr,
  241. int32_t* outOffset = 0);
  242. // Overrides of EditorBase interface methods
  243. nsresult EndUpdateViewBatch() override;
  244. NS_IMETHOD Init(nsIDOMDocument* aDoc, nsIContent* aRoot,
  245. nsISelectionController* aSelCon, uint32_t aFlags,
  246. const nsAString& aValue) override;
  247. NS_IMETHOD PreDestroy(bool aDestroyingFrames) override;
  248. /**
  249. * @param aElement Must not be null.
  250. */
  251. static bool NodeIsBlockStatic(const nsINode* aElement);
  252. static nsresult NodeIsBlockStatic(nsIDOMNode *aNode, bool *aIsBlock);
  253. protected:
  254. virtual ~HTMLEditor();
  255. using EditorBase::IsBlockNode;
  256. virtual bool IsBlockNode(nsINode *aNode) override;
  257. public:
  258. // XXX Why don't we move following methods above for grouping by the origins?
  259. NS_IMETHOD SetFlags(uint32_t aFlags) override;
  260. NS_IMETHOD Paste(int32_t aSelectionType) override;
  261. NS_IMETHOD CanPaste(int32_t aSelectionType, bool* aCanPaste) override;
  262. NS_IMETHOD PasteTransferable(nsITransferable* aTransferable) override;
  263. NS_IMETHOD CanPasteTransferable(nsITransferable* aTransferable,
  264. bool* aCanPaste) override;
  265. NS_IMETHOD DebugUnitTests(int32_t* outNumTests,
  266. int32_t* outNumTestsFailed) override;
  267. /**
  268. * All editor operations which alter the doc should be prefaced
  269. * with a call to StartOperation, naming the action and direction.
  270. */
  271. NS_IMETHOD StartOperation(EditAction opID,
  272. nsIEditor::EDirection aDirection) override;
  273. /**
  274. * All editor operations which alter the doc should be followed
  275. * with a call to EndOperation.
  276. */
  277. NS_IMETHOD EndOperation() override;
  278. /**
  279. * returns true if aParentTag can contain a child of type aChildTag.
  280. */
  281. virtual bool TagCanContainTag(nsIAtom& aParentTag,
  282. nsIAtom& aChildTag) override;
  283. /**
  284. * Returns true if aNode is a container.
  285. */
  286. virtual bool IsContainer(nsINode* aNode) override;
  287. virtual bool IsContainer(nsIDOMNode* aNode) override;
  288. /**
  289. * Make the given selection span the entire document.
  290. */
  291. virtual nsresult SelectEntireDocument(Selection* aSelection) override;
  292. /**
  293. * Join together any adjacent editable text nodes in the range.
  294. */
  295. nsresult CollapseAdjacentTextNodes(nsRange* aRange);
  296. virtual bool AreNodesSameType(nsIContent* aNode1,
  297. nsIContent* aNode2) override;
  298. NS_IMETHOD DeleteSelectionImpl(EDirection aAction,
  299. EStripWrappers aStripWrappers) override;
  300. nsresult DeleteNode(nsINode* aNode);
  301. NS_IMETHOD DeleteNode(nsIDOMNode* aNode) override;
  302. nsresult DeleteText(nsGenericDOMDataNode& aTextNode, uint32_t aOffset,
  303. uint32_t aLength);
  304. virtual nsresult InsertTextImpl(const nsAString& aStringToInsert,
  305. nsCOMPtr<nsINode>* aInOutNode,
  306. int32_t* aInOutOffset,
  307. nsIDocument* aDoc) override;
  308. NS_IMETHOD_(bool) IsModifiableNode(nsIDOMNode* aNode) override;
  309. virtual bool IsModifiableNode(nsINode* aNode) override;
  310. NS_IMETHOD GetIsSelectionEditable(bool* aIsSelectionEditable) override;
  311. NS_IMETHOD SelectAll() override;
  312. // nsICSSLoaderObserver
  313. NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet,
  314. bool aWasAlternate, nsresult aStatus) override;
  315. // Utility Routines, not part of public API
  316. NS_IMETHOD TypedText(const nsAString& aString,
  317. ETypingAction aAction) override;
  318. nsresult InsertNodeAtPoint(nsIDOMNode* aNode,
  319. nsCOMPtr<nsIDOMNode>* ioParent,
  320. int32_t* ioOffset,
  321. bool aNoEmptyNodes);
  322. /**
  323. * Use this to assure that selection is set after attribute nodes when
  324. * trying to collapse selection at begining of a block node
  325. * e.g., when setting at beginning of a table cell
  326. * This will stop at a table, however, since we don't want to
  327. * "drill down" into nested tables.
  328. * @param aSelection Optional. If null, we get current selection.
  329. */
  330. void CollapseSelectionToDeepestNonTableFirstChild(Selection* aSelection,
  331. nsINode* aNode);
  332. /**
  333. * aNode must be a non-null text node.
  334. * outIsEmptyNode must be non-null.
  335. */
  336. nsresult IsVisTextNode(nsIContent* aNode,
  337. bool* outIsEmptyNode,
  338. bool aSafeToAskFrames);
  339. nsresult IsEmptyNode(nsIDOMNode* aNode, bool* outIsEmptyBlock,
  340. bool aMozBRDoesntCount = false,
  341. bool aListOrCellNotEmpty = false,
  342. bool aSafeToAskFrames = false);
  343. nsresult IsEmptyNode(nsINode* aNode, bool* outIsEmptyBlock,
  344. bool aMozBRDoesntCount = false,
  345. bool aListOrCellNotEmpty = false,
  346. bool aSafeToAskFrames = false);
  347. nsresult IsEmptyNodeImpl(nsINode* aNode,
  348. bool* outIsEmptyBlock,
  349. bool aMozBRDoesntCount,
  350. bool aListOrCellNotEmpty,
  351. bool aSafeToAskFrames,
  352. bool* aSeenBR);
  353. /**
  354. * Returns TRUE if sheet was loaded, false if it wasn't.
  355. */
  356. bool EnableExistingStyleSheet(const nsAString& aURL);
  357. /**
  358. * Dealing with the internal style sheet lists.
  359. */
  360. StyleSheet* GetStyleSheetForURL(const nsAString& aURL);
  361. void GetURLForStyleSheet(StyleSheet* aStyleSheet,
  362. nsAString& aURL);
  363. /**
  364. * Add a url + known style sheet to the internal lists.
  365. */
  366. nsresult AddNewStyleSheetToList(const nsAString &aURL,
  367. StyleSheet* aStyleSheet);
  368. nsresult RemoveStyleSheetFromList(const nsAString &aURL);
  369. bool IsCSSEnabled()
  370. {
  371. // TODO: removal of mCSSAware and use only the presence of mCSSEditUtils
  372. return mCSSAware && mCSSEditUtils && mCSSEditUtils->IsCSSPrefChecked();
  373. }
  374. static bool HasAttributes(Element* aElement)
  375. {
  376. MOZ_ASSERT(aElement);
  377. uint32_t attrCount = aElement->GetAttrCount();
  378. return attrCount > 1 ||
  379. (1 == attrCount &&
  380. !aElement->GetAttrNameAt(0)->Equals(nsGkAtoms::mozdirty));
  381. }
  382. protected:
  383. class BlobReader final : public nsIEditorBlobListener
  384. {
  385. public:
  386. BlobReader(dom::BlobImpl* aBlob, HTMLEditor* aHTMLEditor,
  387. bool aIsSafe, nsIDOMDocument* aSourceDoc,
  388. nsIDOMNode* aDestinationNode, int32_t aDestOffset,
  389. bool aDoDeleteSelection);
  390. NS_DECL_ISUPPORTS
  391. NS_DECL_NSIEDITORBLOBLISTENER
  392. private:
  393. ~BlobReader()
  394. {
  395. }
  396. RefPtr<dom::BlobImpl> mBlob;
  397. RefPtr<HTMLEditor> mHTMLEditor;
  398. bool mIsSafe;
  399. nsCOMPtr<nsIDOMDocument> mSourceDoc;
  400. nsCOMPtr<nsIDOMNode> mDestinationNode;
  401. int32_t mDestOffset;
  402. bool mDoDeleteSelection;
  403. };
  404. NS_IMETHOD InitRules() override;
  405. virtual void CreateEventListeners() override;
  406. virtual nsresult InstallEventListeners() override;
  407. virtual void RemoveEventListeners() override;
  408. bool ShouldReplaceRootElement();
  409. void NotifyRootChanged();
  410. nsresult GetBodyElement(nsIDOMHTMLElement** aBody);
  411. /**
  412. * Get the focused node of this editor.
  413. * @return If the editor has focus, this returns the focused node.
  414. * Otherwise, returns null.
  415. */
  416. already_AddRefed<nsINode> GetFocusedNode();
  417. /**
  418. * Return TRUE if aElement is a table-related elemet and caret was set.
  419. */
  420. bool SetCaretInTableCell(nsIDOMElement* aElement);
  421. NS_IMETHOD TabInTable(bool inIsShift, bool* outHandled);
  422. already_AddRefed<Element> CreateBR(nsINode* aNode, int32_t aOffset,
  423. EDirection aSelect = eNone);
  424. NS_IMETHOD CreateBR(
  425. nsIDOMNode* aNode, int32_t aOffset,
  426. nsCOMPtr<nsIDOMNode>* outBRNode,
  427. nsIEditor::EDirection aSelect = nsIEditor::eNone) override;
  428. // Table Editing (implemented in nsTableEditor.cpp)
  429. /**
  430. * Insert a new cell after or before supplied aCell.
  431. * Optional: If aNewCell supplied, returns the newly-created cell (addref'd,
  432. * of course)
  433. * This doesn't change or use the current selection.
  434. */
  435. NS_IMETHOD InsertCell(nsIDOMElement* aCell, int32_t aRowSpan,
  436. int32_t aColSpan, bool aAfter, bool aIsHeader,
  437. nsIDOMElement** aNewCell);
  438. /**
  439. * Helpers that don't touch the selection or do batch transactions.
  440. */
  441. NS_IMETHOD DeleteRow(nsIDOMElement* aTable, int32_t aRowIndex);
  442. NS_IMETHOD DeleteColumn(nsIDOMElement* aTable, int32_t aColIndex);
  443. NS_IMETHOD DeleteCellContents(nsIDOMElement* aCell);
  444. /**
  445. * Move all contents from aCellToMerge into aTargetCell (append at end).
  446. */
  447. NS_IMETHOD MergeCells(nsCOMPtr<nsIDOMElement> aTargetCell,
  448. nsCOMPtr<nsIDOMElement> aCellToMerge,
  449. bool aDeleteCellToMerge);
  450. nsresult DeleteTable2(nsIDOMElement* aTable, Selection* aSelection);
  451. NS_IMETHOD SetColSpan(nsIDOMElement* aCell, int32_t aColSpan);
  452. NS_IMETHOD SetRowSpan(nsIDOMElement* aCell, int32_t aRowSpan);
  453. /**
  454. * Helper used to get nsTableWrapperFrame for a table.
  455. */
  456. nsTableWrapperFrame* GetTableFrame(nsIDOMElement* aTable);
  457. /**
  458. * Needed to do appropriate deleting when last cell or row is about to be
  459. * deleted. This doesn't count cells that don't start in the given row (are
  460. * spanning from row above).
  461. */
  462. int32_t GetNumberOfCellsInRow(nsIDOMElement* aTable, int32_t rowIndex);
  463. /**
  464. * Test if all cells in row or column at given index are selected.
  465. */
  466. bool AllCellsInRowSelected(nsIDOMElement* aTable, int32_t aRowIndex,
  467. int32_t aNumberOfColumns);
  468. bool AllCellsInColumnSelected(nsIDOMElement* aTable, int32_t aColIndex,
  469. int32_t aNumberOfRows);
  470. bool IsEmptyCell(Element* aCell);
  471. /**
  472. * Most insert methods need to get the same basic context data.
  473. * Any of the pointers may be null if you don't need that datum (for more
  474. * efficiency).
  475. * Input: *aCell is a known cell,
  476. * if null, cell is obtained from the anchor node of the selection.
  477. * Returns NS_EDITOR_ELEMENT_NOT_FOUND if cell is not found even if aCell is
  478. * null.
  479. */
  480. nsresult GetCellContext(Selection** aSelection, nsIDOMElement** aTable,
  481. nsIDOMElement** aCell, nsIDOMNode** aCellParent,
  482. int32_t* aCellOffset, int32_t* aRowIndex,
  483. int32_t* aColIndex);
  484. NS_IMETHOD GetCellSpansAt(nsIDOMElement* aTable, int32_t aRowIndex,
  485. int32_t aColIndex, int32_t& aActualRowSpan,
  486. int32_t& aActualColSpan);
  487. NS_IMETHOD SplitCellIntoColumns(nsIDOMElement* aTable, int32_t aRowIndex,
  488. int32_t aColIndex, int32_t aColSpanLeft,
  489. int32_t aColSpanRight,
  490. nsIDOMElement** aNewCell);
  491. NS_IMETHOD SplitCellIntoRows(nsIDOMElement* aTable, int32_t aRowIndex,
  492. int32_t aColIndex, int32_t aRowSpanAbove,
  493. int32_t aRowSpanBelow, nsIDOMElement** aNewCell);
  494. nsresult CopyCellBackgroundColor(nsIDOMElement* destCell,
  495. nsIDOMElement* sourceCell);
  496. /**
  497. * Reduce rowspan/colspan when cells span into nonexistent rows/columns.
  498. */
  499. NS_IMETHOD FixBadRowSpan(nsIDOMElement* aTable, int32_t aRowIndex,
  500. int32_t& aNewRowCount);
  501. NS_IMETHOD FixBadColSpan(nsIDOMElement* aTable, int32_t aColIndex,
  502. int32_t& aNewColCount);
  503. /**
  504. * Fallback method: Call this after using ClearSelection() and you
  505. * failed to set selection to some other content in the document.
  506. */
  507. nsresult SetSelectionAtDocumentStart(Selection* aSelection);
  508. // End of Table Editing utilities
  509. static Element* GetEnclosingTable(nsINode* aNode);
  510. static nsIDOMNode* GetEnclosingTable(nsIDOMNode* aNode);
  511. /**
  512. * Content-based query returns true if <aProperty aAttribute=aValue> effects
  513. * aNode. If <aProperty aAttribute=aValue> contains aNode, but
  514. * <aProperty aAttribute=SomeOtherValue> also contains aNode and the second is
  515. * more deeply nested than the first, then the first does not effect aNode.
  516. *
  517. * @param aNode The target of the query
  518. * @param aProperty The property that we are querying for
  519. * @param aAttribute The attribute of aProperty, example: color in
  520. * <FONT color="blue"> May be null.
  521. * @param aValue The value of aAttribute, example: blue in
  522. * <FONT color="blue"> May be null. Ignored if aAttribute
  523. * is null.
  524. * @param aIsSet [OUT] true if <aProperty aAttribute=aValue> effects
  525. * aNode.
  526. * @param outValue [OUT] the value of the attribute, if aIsSet is true
  527. *
  528. * The nsIContent variant returns aIsSet instead of using an out parameter.
  529. */
  530. bool IsTextPropertySetByContent(nsINode* aNode,
  531. nsIAtom* aProperty,
  532. const nsAString* aAttribute,
  533. const nsAString* aValue,
  534. nsAString* outValue = nullptr);
  535. void IsTextPropertySetByContent(nsIDOMNode* aNode,
  536. nsIAtom* aProperty,
  537. const nsAString* aAttribute,
  538. const nsAString* aValue,
  539. bool& aIsSet,
  540. nsAString* outValue = nullptr);
  541. // Methods for handling plaintext quotations
  542. NS_IMETHOD PasteAsPlaintextQuotation(int32_t aSelectionType);
  543. /**
  544. * Insert a string as quoted text, replacing the selected text (if any).
  545. * @param aQuotedText The string to insert.
  546. * @param aAddCites Whether to prepend extra ">" to each line
  547. * (usually true, unless those characters
  548. * have already been added.)
  549. * @return aNodeInserted The node spanning the insertion, if applicable.
  550. * If aAddCites is false, this will be null.
  551. */
  552. NS_IMETHOD InsertAsPlaintextQuotation(const nsAString& aQuotedText,
  553. bool aAddCites,
  554. nsIDOMNode** aNodeInserted);
  555. nsresult InsertObject(const nsACString& aType, nsISupports* aObject,
  556. bool aIsSafe,
  557. nsIDOMDocument* aSourceDoc,
  558. nsIDOMNode* aDestinationNode,
  559. int32_t aDestOffset,
  560. bool aDoDeleteSelection);
  561. // factored methods for handling insertion of data from transferables
  562. // (drag&drop or clipboard)
  563. NS_IMETHOD PrepareTransferable(nsITransferable** transferable) override;
  564. nsresult PrepareHTMLTransferable(nsITransferable** transferable);
  565. nsresult InsertFromTransferable(nsITransferable* transferable,
  566. nsIDOMDocument* aSourceDoc,
  567. const nsAString& aContextStr,
  568. const nsAString& aInfoStr,
  569. bool havePrivateHTMLFlavor,
  570. nsIDOMNode *aDestinationNode,
  571. int32_t aDestinationOffset,
  572. bool aDoDeleteSelection);
  573. nsresult InsertFromDataTransfer(dom::DataTransfer* aDataTransfer,
  574. int32_t aIndex,
  575. nsIDOMDocument* aSourceDoc,
  576. nsIDOMNode* aDestinationNode,
  577. int32_t aDestOffset,
  578. bool aDoDeleteSelection) override;
  579. bool HavePrivateHTMLFlavor(nsIClipboard* clipboard );
  580. nsresult ParseCFHTML(nsCString& aCfhtml, char16_t** aStuffToPaste,
  581. char16_t** aCfcontext);
  582. nsresult DoContentFilterCallback(const nsAString& aFlavor,
  583. nsIDOMDocument* aSourceDoc,
  584. bool aWillDeleteSelection,
  585. nsIDOMNode** aFragmentAsNode,
  586. nsIDOMNode** aFragStartNode,
  587. int32_t* aFragStartOffset,
  588. nsIDOMNode** aFragEndNode,
  589. int32_t* aFragEndOffset,
  590. nsIDOMNode** aTargetNode,
  591. int32_t* aTargetOffset,
  592. bool* aDoContinue);
  593. bool IsInLink(nsIDOMNode* aNode, nsCOMPtr<nsIDOMNode>* outLink = nullptr);
  594. nsresult StripFormattingNodes(nsIContent& aNode, bool aOnlyList = false);
  595. nsresult CreateDOMFragmentFromPaste(const nsAString& aInputString,
  596. const nsAString& aContextStr,
  597. const nsAString& aInfoStr,
  598. nsCOMPtr<nsIDOMNode>* outFragNode,
  599. nsCOMPtr<nsIDOMNode>* outStartNode,
  600. nsCOMPtr<nsIDOMNode>* outEndNode,
  601. int32_t* outStartOffset,
  602. int32_t* outEndOffset,
  603. bool aTrustedInput);
  604. nsresult ParseFragment(const nsAString& aStr, nsIAtom* aContextLocalName,
  605. nsIDocument* aTargetDoc,
  606. dom::DocumentFragment** aFragment, bool aTrustedInput);
  607. void CreateListOfNodesToPaste(dom::DocumentFragment& aFragment,
  608. nsTArray<OwningNonNull<nsINode>>& outNodeList,
  609. nsINode* aStartNode,
  610. int32_t aStartOffset,
  611. nsINode* aEndNode,
  612. int32_t aEndOffset);
  613. nsresult CreateTagStack(nsTArray<nsString>& aTagStack,
  614. nsIDOMNode* aNode);
  615. enum class StartOrEnd { start, end };
  616. void GetListAndTableParents(StartOrEnd aStartOrEnd,
  617. nsTArray<OwningNonNull<nsINode>>& aNodeList,
  618. nsTArray<OwningNonNull<Element>>& outArray);
  619. int32_t DiscoverPartialListsAndTables(
  620. nsTArray<OwningNonNull<nsINode>>& aPasteNodes,
  621. nsTArray<OwningNonNull<Element>>& aListsAndTables);
  622. nsINode* ScanForListAndTableStructure(
  623. StartOrEnd aStartOrEnd,
  624. nsTArray<OwningNonNull<nsINode>>& aNodes,
  625. Element& aListOrTable);
  626. void ReplaceOrphanedStructure(
  627. StartOrEnd aStartOrEnd,
  628. nsTArray<OwningNonNull<nsINode>>& aNodeArray,
  629. nsTArray<OwningNonNull<Element>>& aListAndTableArray,
  630. int32_t aHighWaterMark);
  631. /**
  632. * Small utility routine to test if a break node is visible to user.
  633. */
  634. bool IsVisBreak(nsINode* aNode);
  635. /**
  636. * Utility routine to possibly adjust the insertion position when
  637. * inserting a block level element.
  638. */
  639. void NormalizeEOLInsertPosition(nsINode* firstNodeToInsert,
  640. nsCOMPtr<nsIDOMNode>* insertParentNode,
  641. int32_t* insertOffset);
  642. /**
  643. * Small utility routine to test the eEditorReadonly bit.
  644. */
  645. bool IsModifiable();
  646. /**
  647. * Helpers for block transformations.
  648. */
  649. nsresult MakeDefinitionItem(const nsAString& aItemType);
  650. nsresult InsertBasicBlock(const nsAString& aBlockType);
  651. /**
  652. * Increase/decrease the font size of selection.
  653. */
  654. enum class FontSize { incr, decr };
  655. nsresult RelativeFontChange(FontSize aDir);
  656. /**
  657. * Helper routines for font size changing.
  658. */
  659. nsresult RelativeFontChangeOnTextNode(FontSize aDir,
  660. Text& aTextNode,
  661. int32_t aStartOffset,
  662. int32_t aEndOffset);
  663. nsresult RelativeFontChangeOnNode(int32_t aSizeChange, nsIContent* aNode);
  664. nsresult RelativeFontChangeHelper(int32_t aSizeChange, nsINode* aNode);
  665. /**
  666. * Helper routines for inline style.
  667. */
  668. nsresult SetInlinePropertyOnTextNode(Text& aData,
  669. int32_t aStartOffset,
  670. int32_t aEndOffset,
  671. nsIAtom& aProperty,
  672. const nsAString* aAttribute,
  673. const nsAString& aValue);
  674. nsresult SetInlinePropertyOnNode(nsIContent& aNode,
  675. nsIAtom& aProperty,
  676. const nsAString* aAttribute,
  677. const nsAString& aValue);
  678. nsresult PromoteInlineRange(nsRange& aRange);
  679. nsresult PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange);
  680. nsresult SplitStyleAboveRange(nsRange* aRange,
  681. nsIAtom* aProperty,
  682. const nsAString* aAttribute);
  683. nsresult SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
  684. nsIAtom* aProperty,
  685. const nsAString* aAttribute,
  686. nsIContent** aOutLeftNode = nullptr,
  687. nsIContent** aOutRightNode = nullptr);
  688. nsresult ApplyDefaultProperties();
  689. nsresult RemoveStyleInside(nsIContent& aNode,
  690. nsIAtom* aProperty,
  691. const nsAString* aAttribute,
  692. const bool aChildrenOnly = false);
  693. nsresult RemoveInlinePropertyImpl(nsIAtom* aProperty,
  694. const nsAString* aAttribute);
  695. bool NodeIsProperty(nsINode& aNode);
  696. bool IsAtFrontOfNode(nsINode& aNode, int32_t aOffset);
  697. bool IsAtEndOfNode(nsINode& aNode, int32_t aOffset);
  698. bool IsOnlyAttribute(const nsIContent* aElement, const nsAString& aAttribute);
  699. nsresult RemoveBlockContainer(nsIContent& aNode);
  700. nsIContent* GetPriorHTMLSibling(nsINode* aNode);
  701. nsresult GetPriorHTMLSibling(nsIDOMNode*inNode,
  702. nsCOMPtr<nsIDOMNode>* outNode);
  703. nsIContent* GetPriorHTMLSibling(nsINode* aParent, int32_t aOffset);
  704. nsresult GetPriorHTMLSibling(nsIDOMNode* inParent, int32_t inOffset,
  705. nsCOMPtr<nsIDOMNode>* outNode);
  706. nsIContent* GetNextHTMLSibling(nsINode* aNode);
  707. nsresult GetNextHTMLSibling(nsIDOMNode* inNode,
  708. nsCOMPtr<nsIDOMNode>* outNode);
  709. nsIContent* GetNextHTMLSibling(nsINode* aParent, int32_t aOffset);
  710. nsresult GetNextHTMLSibling(nsIDOMNode* inParent, int32_t inOffset,
  711. nsCOMPtr<nsIDOMNode>* outNode);
  712. nsIContent* GetPriorHTMLNode(nsINode* aNode, bool aNoBlockCrossing = false);
  713. nsresult GetPriorHTMLNode(nsIDOMNode* inNode, nsCOMPtr<nsIDOMNode>* outNode,
  714. bool bNoBlockCrossing = false);
  715. nsIContent* GetPriorHTMLNode(nsINode* aParent, int32_t aOffset,
  716. bool aNoBlockCrossing = false);
  717. nsresult GetPriorHTMLNode(nsIDOMNode* inParent, int32_t inOffset,
  718. nsCOMPtr<nsIDOMNode>* outNode,
  719. bool bNoBlockCrossing = false);
  720. nsIContent* GetNextHTMLNode(nsINode* aNode, bool aNoBlockCrossing = false);
  721. nsresult GetNextHTMLNode(nsIDOMNode* inNode, nsCOMPtr<nsIDOMNode>* outNode,
  722. bool bNoBlockCrossing = false);
  723. nsIContent* GetNextHTMLNode(nsINode* aParent, int32_t aOffset,
  724. bool aNoBlockCrossing = false);
  725. nsresult GetNextHTMLNode(nsIDOMNode* inParent, int32_t inOffset,
  726. nsCOMPtr<nsIDOMNode>* outNode,
  727. bool bNoBlockCrossing = false);
  728. nsresult IsFirstEditableChild(nsIDOMNode* aNode, bool* aOutIsFirst);
  729. nsresult IsLastEditableChild(nsIDOMNode* aNode, bool* aOutIsLast);
  730. nsIContent* GetFirstEditableChild(nsINode& aNode);
  731. nsIContent* GetLastEditableChild(nsINode& aNode);
  732. nsIContent* GetFirstEditableLeaf(nsINode& aNode);
  733. nsIContent* GetLastEditableLeaf(nsINode& aNode);
  734. nsresult GetInlinePropertyBase(nsIAtom& aProperty,
  735. const nsAString* aAttribute,
  736. const nsAString* aValue,
  737. bool* aFirst,
  738. bool* aAny,
  739. bool* aAll,
  740. nsAString* outValue,
  741. bool aCheckDefaults = true);
  742. bool HasStyleOrIdOrClass(Element* aElement);
  743. nsresult RemoveElementIfNoStyleOrIdOrClass(Element& aElement);
  744. /**
  745. * Whether the outer window of the DOM event target has focus or not.
  746. */
  747. bool OurWindowHasFocus();
  748. /**
  749. * This function is used to insert a string of HTML input optionally with some
  750. * context information into the editable field. The HTML input either comes
  751. * from a transferable object created as part of a drop/paste operation, or
  752. * from the InsertHTML method. We may want the HTML input to be sanitized
  753. * (for example, if it's coming from a transferable object), in which case
  754. * aTrustedInput should be set to false, otherwise, the caller should set it
  755. * to true, which means that the HTML will be inserted in the DOM verbatim.
  756. *
  757. * aClearStyle should be set to false if you want the paste to be affected by
  758. * local style (e.g., for the insertHTML command).
  759. */
  760. nsresult DoInsertHTMLWithContext(const nsAString& aInputString,
  761. const nsAString& aContextStr,
  762. const nsAString& aInfoStr,
  763. const nsAString& aFlavor,
  764. nsIDOMDocument* aSourceDoc,
  765. nsIDOMNode* aDestNode,
  766. int32_t aDestOffset,
  767. bool aDeleteSelection,
  768. bool aTrustedInput,
  769. bool aClearStyle = true);
  770. nsresult ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
  771. nsIAtom* aProperty, const nsAString* aAttribute);
  772. void SetElementPosition(Element& aElement, int32_t aX, int32_t aY);
  773. protected:
  774. nsTArray<OwningNonNull<nsIContentFilter>> mContentFilters;
  775. RefPtr<TypeInState> mTypeInState;
  776. bool mCRInParagraphCreatesParagraph;
  777. bool mCSSAware;
  778. UniquePtr<CSSEditUtils> mCSSEditUtils;
  779. // Used by GetFirstSelectedCell and GetNextSelectedCell
  780. int32_t mSelectedCellIndex;
  781. nsString mLastStyleSheetURL;
  782. nsString mLastOverrideStyleSheetURL;
  783. // Maintain a list of associated style sheets and their urls.
  784. nsTArray<nsString> mStyleSheetURLs;
  785. nsTArray<RefPtr<StyleSheet>> mStyleSheets;
  786. // an array for holding default style settings
  787. nsTArray<PropItem*> mDefaultStyles;
  788. protected:
  789. // ANONYMOUS UTILS
  790. void RemoveListenerAndDeleteRef(const nsAString& aEvent,
  791. nsIDOMEventListener* aListener,
  792. bool aUseCapture,
  793. Element* aElement,
  794. nsIContent* aParentContent,
  795. nsIPresShell* aShell);
  796. void DeleteRefToAnonymousNode(nsIDOMElement* aElement,
  797. nsIContent* aParentContent,
  798. nsIPresShell* aShell);
  799. nsresult ShowResizersInner(nsIDOMElement *aResizedElement);
  800. /**
  801. * Returns the offset of an element's frame to its absolute containing block.
  802. */
  803. nsresult GetElementOrigin(nsIDOMElement* aElement,
  804. int32_t& aX, int32_t& aY);
  805. nsresult GetPositionAndDimensions(nsIDOMElement* aElement,
  806. int32_t& aX, int32_t& aY,
  807. int32_t& aW, int32_t& aH,
  808. int32_t& aBorderLeft,
  809. int32_t& aBorderTop,
  810. int32_t& aMarginLeft,
  811. int32_t& aMarginTop);
  812. bool IsInObservedSubtree(nsIDocument* aDocument,
  813. nsIContent* aContainer,
  814. nsIContent* aChild);
  815. void UpdateRootElement();
  816. // resizing
  817. bool mIsObjectResizingEnabled;
  818. bool mIsResizing;
  819. bool mPreserveRatio;
  820. bool mResizedObjectIsAnImage;
  821. // absolute positioning
  822. bool mIsAbsolutelyPositioningEnabled;
  823. bool mResizedObjectIsAbsolutelyPositioned;
  824. bool mGrabberClicked;
  825. bool mIsMoving;
  826. bool mSnapToGridEnabled;
  827. // inline table editing
  828. bool mIsInlineTableEditingEnabled;
  829. // resizing
  830. nsCOMPtr<Element> mTopLeftHandle;
  831. nsCOMPtr<Element> mTopHandle;
  832. nsCOMPtr<Element> mTopRightHandle;
  833. nsCOMPtr<Element> mLeftHandle;
  834. nsCOMPtr<Element> mRightHandle;
  835. nsCOMPtr<Element> mBottomLeftHandle;
  836. nsCOMPtr<Element> mBottomHandle;
  837. nsCOMPtr<Element> mBottomRightHandle;
  838. nsCOMPtr<Element> mActivatedHandle;
  839. nsCOMPtr<Element> mResizingShadow;
  840. nsCOMPtr<Element> mResizingInfo;
  841. nsCOMPtr<Element> mResizedObject;
  842. nsCOMPtr<nsIDOMEventListener> mMouseMotionListenerP;
  843. nsCOMPtr<nsISelectionListener> mSelectionListenerP;
  844. nsCOMPtr<nsIDOMEventListener> mResizeEventListenerP;
  845. nsTArray<OwningNonNull<nsIHTMLObjectResizeListener>> mObjectResizeEventListeners;
  846. int32_t mOriginalX;
  847. int32_t mOriginalY;
  848. int32_t mResizedObjectX;
  849. int32_t mResizedObjectY;
  850. int32_t mResizedObjectWidth;
  851. int32_t mResizedObjectHeight;
  852. int32_t mResizedObjectMarginLeft;
  853. int32_t mResizedObjectMarginTop;
  854. int32_t mResizedObjectBorderLeft;
  855. int32_t mResizedObjectBorderTop;
  856. int32_t mXIncrementFactor;
  857. int32_t mYIncrementFactor;
  858. int32_t mWidthIncrementFactor;
  859. int32_t mHeightIncrementFactor;
  860. int8_t mInfoXIncrement;
  861. int8_t mInfoYIncrement;
  862. nsresult SetAllResizersPosition();
  863. already_AddRefed<Element> CreateResizer(int16_t aLocation,
  864. nsIDOMNode* aParentNode);
  865. void SetAnonymousElementPosition(int32_t aX, int32_t aY,
  866. nsIDOMElement* aResizer);
  867. already_AddRefed<Element> CreateShadow(nsIDOMNode* aParentNode,
  868. nsIDOMElement* aOriginalObject);
  869. nsresult SetShadowPosition(Element* aShadow, Element* aOriginalObject,
  870. int32_t aOriginalObjectX,
  871. int32_t aOriginalObjectY);
  872. already_AddRefed<Element> CreateResizingInfo(nsIDOMNode* aParentNode);
  873. nsresult SetResizingInfoPosition(int32_t aX, int32_t aY,
  874. int32_t aW, int32_t aH);
  875. int32_t GetNewResizingIncrement(int32_t aX, int32_t aY, int32_t aID);
  876. nsresult StartResizing(nsIDOMElement* aHandle);
  877. int32_t GetNewResizingX(int32_t aX, int32_t aY);
  878. int32_t GetNewResizingY(int32_t aX, int32_t aY);
  879. int32_t GetNewResizingWidth(int32_t aX, int32_t aY);
  880. int32_t GetNewResizingHeight(int32_t aX, int32_t aY);
  881. void HideShadowAndInfo();
  882. void SetFinalSize(int32_t aX, int32_t aY);
  883. void DeleteRefToAnonymousNode(nsIDOMNode* aNode);
  884. void SetResizeIncrements(int32_t aX, int32_t aY, int32_t aW, int32_t aH,
  885. bool aPreserveRatio);
  886. void HideAnonymousEditingUIs();
  887. // absolute positioning
  888. int32_t mPositionedObjectX;
  889. int32_t mPositionedObjectY;
  890. int32_t mPositionedObjectWidth;
  891. int32_t mPositionedObjectHeight;
  892. int32_t mPositionedObjectMarginLeft;
  893. int32_t mPositionedObjectMarginTop;
  894. int32_t mPositionedObjectBorderLeft;
  895. int32_t mPositionedObjectBorderTop;
  896. nsCOMPtr<Element> mAbsolutelyPositionedObject;
  897. nsCOMPtr<Element> mGrabber;
  898. nsCOMPtr<Element> mPositioningShadow;
  899. int32_t mGridSize;
  900. already_AddRefed<Element> CreateGrabber(nsINode* aParentNode);
  901. nsresult StartMoving(nsIDOMElement* aHandle);
  902. nsresult SetFinalPosition(int32_t aX, int32_t aY);
  903. void AddPositioningOffset(int32_t& aX, int32_t& aY);
  904. void SnapToGrid(int32_t& newX, int32_t& newY);
  905. nsresult GrabberClicked();
  906. nsresult EndMoving();
  907. nsresult CheckPositionedElementBGandFG(nsIDOMElement* aElement,
  908. nsAString& aReturn);
  909. // inline table editing
  910. nsCOMPtr<nsIDOMElement> mInlineEditedCell;
  911. nsCOMPtr<nsIDOMElement> mAddColumnBeforeButton;
  912. nsCOMPtr<nsIDOMElement> mRemoveColumnButton;
  913. nsCOMPtr<nsIDOMElement> mAddColumnAfterButton;
  914. nsCOMPtr<nsIDOMElement> mAddRowBeforeButton;
  915. nsCOMPtr<nsIDOMElement> mRemoveRowButton;
  916. nsCOMPtr<nsIDOMElement> mAddRowAfterButton;
  917. void AddMouseClickListener(nsIDOMElement* aElement);
  918. void RemoveMouseClickListener(nsIDOMElement* aElement);
  919. nsCOMPtr<nsILinkHandler> mLinkHandler;
  920. public:
  921. friend class HTMLEditorEventListener;
  922. friend class HTMLEditRules;
  923. friend class TextEditRules;
  924. friend class WSRunObject;
  925. private:
  926. bool IsSimpleModifiableNode(nsIContent* aContent,
  927. nsIAtom* aProperty,
  928. const nsAString* aAttribute,
  929. const nsAString* aValue);
  930. nsresult SetInlinePropertyOnNodeImpl(nsIContent& aNode,
  931. nsIAtom& aProperty,
  932. const nsAString* aAttribute,
  933. const nsAString& aValue);
  934. typedef enum { eInserted, eAppended } InsertedOrAppended;
  935. void DoContentInserted(nsIDocument* aDocument, nsIContent* aContainer,
  936. nsIContent* aChild, int32_t aIndexInContainer,
  937. InsertedOrAppended aInsertedOrAppended);
  938. already_AddRefed<Element> GetElementOrParentByTagName(
  939. const nsAString& aTagName, nsINode* aNode);
  940. already_AddRefed<Element> CreateElementWithDefaults(
  941. const nsAString& aTagName);
  942. };
  943. } // namespace mozilla
  944. #endif // #ifndef mozilla_HTMLEditor_h