nsIHTMLEditor.idl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. #include "nsISupports.idl"
  6. #include "domstubs.idl"
  7. interface nsIAtom;
  8. interface nsIContent;
  9. interface nsIArray;
  10. interface nsISelection;
  11. interface nsIContentFilter;
  12. %{C++
  13. namespace mozilla {
  14. namespace dom {
  15. class Element;
  16. }
  17. }
  18. %}
  19. [ptr] native Element (mozilla::dom::Element);
  20. [scriptable, uuid(87ee993e-985f-4a43-a974-0d9512da2fb0)]
  21. interface nsIHTMLEditor : nsISupports
  22. {
  23. %{C++
  24. typedef short EAlignment;
  25. %}
  26. // used by GetAlignment()
  27. const short eLeft = 0;
  28. const short eCenter = 1;
  29. const short eRight = 2;
  30. const short eJustify = 3;
  31. /* ------------ Inline property methods -------------- */
  32. /**
  33. * AddDefaultProperty() registers a default style property with the editor
  34. *
  35. * @param aProperty the property to set by default
  36. * @param aAttribute the attribute of the property, if applicable.
  37. * May be null.
  38. * Example: aProperty="font", aAttribute="color"
  39. * @param aValue if aAttribute is not null, the value of the attribute.
  40. * Example: aProperty="font", aAttribute="color",
  41. * aValue="0x00FFFF"
  42. */
  43. void addDefaultProperty(in nsIAtom aProperty,
  44. in AString aAttribute,
  45. in AString aValue);
  46. /**
  47. * RemoveDefaultProperty() unregisters a default style property with the editor
  48. *
  49. * @param aProperty the property to remove from defaults
  50. * @param aAttribute the attribute of the property, if applicable.
  51. * May be null.
  52. * Example: aProperty="font", aAttribute="color"
  53. * @param aValue if aAttribute is not null, the value of the attribute.
  54. * Example: aProperty="font", aAttribute="color",
  55. * aValue="0x00FFFF"
  56. */
  57. void removeDefaultProperty(in nsIAtom aProperty,
  58. in AString aAttribute,
  59. in AString aValue);
  60. /**
  61. * RemoveAllDefaultProperties() unregisters all default style properties with the editor
  62. *
  63. */
  64. void removeAllDefaultProperties();
  65. /**
  66. * SetInlineProperty() sets the aggregate properties on the current selection
  67. *
  68. * @param aProperty the property to set on the selection
  69. * @param aAttribute the attribute of the property, if applicable.
  70. * May be null.
  71. * Example: aProperty="font", aAttribute="color"
  72. * @param aValue if aAttribute is not null, the value of the attribute.
  73. * May be null.
  74. * Example: aProperty="font", aAttribute="color",
  75. * aValue="0x00FFFF"
  76. */
  77. void setInlineProperty(in nsIAtom aProperty,
  78. in AString aAttribute,
  79. in AString aValue);
  80. /**
  81. * getInlineProperty() gets aggregate properties of the current selection.
  82. * All object in the current selection are scanned and their attributes are
  83. * represented in a list of Property object.
  84. *
  85. * @param aProperty the property to get on the selection
  86. * @param aAttribute the attribute of the property, if applicable.
  87. * May be null.
  88. * Example: aProperty="font", aAttribute="color"
  89. * @param aValue if aAttribute is not null, the value of the attribute.
  90. * May be null.
  91. * Example: aProperty="font", aAttribute="color",
  92. * aValue="0x00FFFF"
  93. * @param aFirst [OUT] PR_TRUE if the first text node in the
  94. * selection has the property
  95. * @param aAny [OUT] PR_TRUE if any of the text nodes in the
  96. * selection have the property
  97. * @param aAll [OUT] PR_TRUE if all of the text nodes in the
  98. * selection have the property
  99. */
  100. void getInlineProperty(in nsIAtom aProperty,
  101. in AString aAttribute,
  102. in AString aValue,
  103. out boolean aFirst,
  104. out boolean aAny,
  105. out boolean aAll);
  106. AString getInlinePropertyWithAttrValue(in nsIAtom aProperty,
  107. in AString aAttribute,
  108. in AString aValue,
  109. out boolean aFirst,
  110. out boolean aAny,
  111. out boolean aAll);
  112. /**
  113. * removeAllInlineProperties() deletes all the inline properties from all
  114. * text in the current selection.
  115. */
  116. void removeAllInlineProperties();
  117. /**
  118. * removeInlineProperty() deletes the properties from all text in the current
  119. * selection. If aProperty is not set on the selection, nothing is done.
  120. *
  121. * @param aProperty the property to remove from the selection
  122. * All atoms are for normal HTML tags (e.g.:
  123. * nsIEditorProperty::font) except when you want to
  124. * remove just links and not named anchors.
  125. * For that, use nsIEditorProperty::href
  126. * @param aAttribute the attribute of the property, if applicable.
  127. * May be null.
  128. * Example: aProperty=nsIEditorProptery::font,
  129. * aAttribute="color"
  130. * nsIEditProperty::allAttributes is special.
  131. * It indicates that all content-based text properties
  132. * are to be removed from the selection.
  133. */
  134. void removeInlineProperty(in nsIAtom aProperty, in AString aAttribute);
  135. /**
  136. * Increase font size for text in selection by 1 HTML unit
  137. * All existing text is scanned for existing <FONT SIZE> attributes
  138. * so they will be incremented instead of inserting new <FONT> tag
  139. */
  140. void increaseFontSize();
  141. /**
  142. * Decrease font size for text in selection by 1 HTML unit
  143. * All existing text is scanned for existing <FONT SIZE> attributes
  144. * so they will be decreased instead of inserting new <FONT> tag
  145. */
  146. void decreaseFontSize();
  147. /* ------------ HTML content methods -------------- */
  148. /**
  149. * Tests if a node is a BLOCK element according the the HTML 4.0 DTD.
  150. * This does NOT consider CSS effect on display type
  151. *
  152. * @param aNode the node to test
  153. */
  154. boolean nodeIsBlock(in nsIDOMNode node);
  155. /**
  156. * Insert some HTML source at the current location
  157. *
  158. * @param aInputString the string to be inserted
  159. */
  160. void insertHTML(in AString aInputString);
  161. /**
  162. * Paste the text in the OS clipboard at the cursor position, replacing
  163. * the selected text (if any), but strip out any HTML styles and formatting
  164. */
  165. void pasteNoFormatting(in long aSelectionType);
  166. /**
  167. * Rebuild the entire document from source HTML
  168. * Needed to be able to edit HEAD and other outside-of-BODY content
  169. *
  170. * @param aSourceString HTML source string of the entire new document
  171. */
  172. void rebuildDocumentFromSource(in AString aSourceString);
  173. /**
  174. * Insert some HTML source, interpreting
  175. * the string argument according to the given context.
  176. *
  177. * @param aInputString the string to be inserted
  178. * @param aContextStr Context of insertion
  179. * @param aInfoStr Related info to aInputString
  180. * @param aFlavor Transferable flavor, can be ""
  181. * @param aSourceDoc document where input was dragged from (may be null)
  182. * @param aDestinationNode location for insertion (such as when dropped)
  183. * @param aDestinationOffset used with aDestNode to determine insert location
  184. * @param aDeleteSelection used with aDestNode during drag&drop
  185. * @param aCollapseSelection used with aDestNode during drag&drop
  186. */
  187. void insertHTMLWithContext(in AString aInputString,
  188. in AString aContextStr,
  189. in AString aInfoStr,
  190. in AString aFlavor,
  191. in nsIDOMDocument aSourceDoc,
  192. in nsIDOMNode aDestinationNode,
  193. in long aDestinationOffset,
  194. in boolean aDeleteSelection);
  195. /**
  196. * Insert an element, which may have child nodes, at the selection
  197. * Used primarily to insert a new element for various insert element dialogs,
  198. * but it enforces the HTML 4.0 DTD "CanContain" rules, so it should
  199. * be useful for other elements.
  200. *
  201. * @param aElement The element to insert
  202. * @param aDeleteSelection Delete the selection before inserting
  203. * If aDeleteSelection is PR_FALSE, then the element is inserted
  204. * after the end of the selection for all element except
  205. * Named Anchors, which insert before the selection
  206. */
  207. void insertElementAtSelection(in nsIDOMElement aElement,
  208. in boolean aDeleteSelection);
  209. /**
  210. * Set the documents title.
  211. */
  212. void setDocumentTitle(in AString aTitle);
  213. /**
  214. * Set the BaseURL for the document to the current URL
  215. * but only if the page doesn't have a <base> tag
  216. * This should be done after the document URL has changed,
  217. * such as after saving a file
  218. * This is used as base for relativizing link and image urls
  219. */
  220. void updateBaseURL();
  221. /* ------------ Selection manipulation -------------- */
  222. /* Should these be moved to nsISelection? */
  223. /**
  224. * Set the selection at the suppled element
  225. *
  226. * @param aElement An element in the document
  227. */
  228. void selectElement(in nsIDOMElement aElement);
  229. /**
  230. * Create a collapsed selection just after aElement
  231. *
  232. * XXX could we parameterize SelectElement(before/select/after>?
  233. *
  234. * The selection is set to parent-of-aElement with an
  235. * offset 1 greater than aElement's offset
  236. * but it enforces the HTML 4.0 DTD "CanContain" rules, so it should
  237. * be useful for other elements.
  238. *
  239. * @param aElement An element in the document
  240. */
  241. void setCaretAfterElement(in nsIDOMElement aElement);
  242. /**
  243. * SetParagraphFormat Insert a block paragraph tag around selection
  244. * @param aParagraphFormat "p", "h1" to "h6", "address", "pre", or "blockquote"
  245. */
  246. void setParagraphFormat(in AString aParagraphFormat);
  247. /**
  248. * getParagraphState returns what block tag paragraph format is in
  249. * the selection.
  250. * @param aMixed True if there is more than one format
  251. * @return Name of block tag. "" is returned for none.
  252. */
  253. AString getParagraphState(out boolean aMixed);
  254. /**
  255. * getFontFaceState returns what font face is in the selection.
  256. * @param aMixed True if there is more than one font face
  257. * @return Name of face. Note: "tt" is returned for
  258. * tt tag. "" is returned for none.
  259. */
  260. AString getFontFaceState(out boolean aMixed);
  261. /**
  262. * getFontColorState returns what font face is in the selection.
  263. * @param aMixed True if there is more than one font color
  264. * @return Color string. "" is returned for none.
  265. */
  266. AString getFontColorState(out boolean aMixed);
  267. /**
  268. * getFontColorState returns what font face is in the selection.
  269. * @param aMixed True if there is more than one font color
  270. * @return Color string. "" is returned for none.
  271. */
  272. AString getBackgroundColorState(out boolean aMixed);
  273. /**
  274. * getHighlightColorState returns what the highlight color of the selection.
  275. * @param aMixed True if there is more than one font color
  276. * @return Color string. "" is returned for none.
  277. */
  278. AString getHighlightColorState(out boolean aMixed);
  279. /**
  280. * getListState returns what list type is in the selection.
  281. * @param aMixed True if there is more than one type of list, or
  282. * if there is some list and non-list
  283. * @param aOL The company that employs me. No, really, it's
  284. * true if an "ol" list is selected.
  285. * @param aUL true if an "ul" list is selected.
  286. * @param aDL true if a "dl" list is selected.
  287. */
  288. void getListState(out boolean aMixed, out boolean aOL, out boolean aUL,
  289. out boolean aDL);
  290. /**
  291. * getListItemState returns what list item type is in the selection.
  292. * @param aMixed True if there is more than one type of list item, or
  293. * if there is some list and non-list
  294. * @param aLI true if "li" list items are selected.
  295. * @param aDT true if "dt" list items are selected.
  296. * @param aDD true if "dd" list items are selected.
  297. */
  298. void getListItemState(out boolean aMixed, out boolean aLI,
  299. out boolean aDT, out boolean aDD);
  300. /**
  301. * getAlignment returns what alignment is in the selection.
  302. * @param aMixed True if there is more than one type of list item, or
  303. * if there is some list and non-list
  304. * @param aAlign enum value for first encountered alignment
  305. * (left/center/right)
  306. */
  307. void getAlignment(out boolean aMixed, out short aAlign);
  308. /**
  309. * Document me!
  310. *
  311. */
  312. void getIndentState(out boolean aCanIndent, out boolean aCanOutdent);
  313. /**
  314. * Document me!
  315. *
  316. */
  317. void makeOrChangeList(in AString aListType, in boolean entireList,
  318. in AString aBulletType);
  319. /**
  320. * Document me!
  321. *
  322. */
  323. void removeList(in AString aListType);
  324. /**
  325. * Document me!
  326. *
  327. */
  328. void indent(in AString aIndent);
  329. /**
  330. * Document me!
  331. *
  332. */
  333. void align(in AString aAlign);
  334. /**
  335. * Return the input node or a parent matching the given aTagName,
  336. * starting the search at the supplied node.
  337. * An example of use is for testing if a node is in a table cell
  338. * given a selection anchor node.
  339. *
  340. * @param aTagName The HTML tagname
  341. * Special input values:
  342. * Use "href" to get a link node
  343. * (an "A" tag with the "href" attribute set)
  344. * Use "anchor" or "namedanchor" to get a named anchor node
  345. * (an "A" tag with the "name" attribute set)
  346. * Use "list" to get an OL, UL, or DL list node
  347. * Use "td" to get either a TD or TH cell node
  348. *
  349. * @param aNode The node in the document to start the search.
  350. * If it is null, the anchor node of the current selection is used.
  351. * @return NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
  352. * (passes NS_SUCCEEDED macro)
  353. */
  354. nsIDOMElement getElementOrParentByTagName(in AString aTagName,
  355. in nsIDOMNode aNode);
  356. /**
  357. * Return an element only if it is the only node selected,
  358. * such as an image, horizontal rule, etc.
  359. * The exception is a link, which is more like a text attribute:
  360. * The Anchor tag is returned if the selection is within the textnode(s)
  361. * that are children of the "A" node.
  362. * This could be a collapsed selection, i.e., a caret
  363. * within the link text.
  364. *
  365. * @param aTagName The HTML tagname or and empty string
  366. * to get any element (but only if it is the only element selected)
  367. * Special input values for Links and Named anchors:
  368. * Use "href" to get a link node
  369. * (an "A" tag with the "href" attribute set)
  370. * Use "anchor" or "namedanchor" to get a named anchor node
  371. * (an "A" tag with the "name" attribute set)
  372. * @return NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
  373. * (passes NS_SUCCEEDED macro)
  374. */
  375. nsIDOMElement getSelectedElement(in AString aTagName);
  376. /**
  377. * Output the contents of the <HEAD> section as text/HTML format
  378. */
  379. AString getHeadContentsAsHTML();
  380. /**
  381. * Replace all children of <HEAD> with string of HTML source
  382. */
  383. void replaceHeadContentsWithHTML(in AString aSourceToInsert);
  384. /**
  385. * Return a new element with default attribute values
  386. *
  387. * This does not rely on the selection, and is not sensitive to context.
  388. *
  389. * Used primarily to supply new element for various insert element dialogs
  390. * (Image, Link, NamedAnchor, Table, and HorizontalRule
  391. * are the only returned elements as of 7/25/99)
  392. *
  393. * @param aTagName The HTML tagname
  394. * Special input values for Links and Named anchors:
  395. * Use "href" to get a link node
  396. * (an "A" tag with the "href" attribute set)
  397. * Use "anchor" or "namedanchor" to get a named anchor node
  398. * (an "A" tag with the "name" attribute set)
  399. * @return The new element created.
  400. */
  401. nsIDOMElement createElementWithDefaults(in AString aTagName);
  402. /**
  403. * Insert an link element as the parent of the current selection
  404. *
  405. * @param aElement An "A" element with a non-empty "href" attribute
  406. */
  407. void insertLinkAroundSelection(in nsIDOMElement aAnchorElement);
  408. /**
  409. * Set the value of the "bgcolor" attribute on the document's <body> element
  410. *
  411. * @param aColor The HTML color string, such as "#ffccff" or "yellow"
  412. */
  413. void setBackgroundColor(in AString aColor);
  414. /**
  415. * Set an attribute on the document's <body> element
  416. * such as text, link, background colors
  417. *
  418. * 8/31/00 THIS ISN'T BEING USED? SHOULD WE DROP IT?
  419. *
  420. * @param aAttr The attribute to be set
  421. * @param aValue The value of the attribute
  422. */
  423. void setBodyAttribute(in AString aAttr, in AString aValue);
  424. /**
  425. * Find all the nodes in the document which contain references
  426. * to outside URIs (e.g. a href, img src, script src, etc.)
  427. * The objects in the array will be type nsIURIRefObject.
  428. *
  429. * @return aNodeList the linked nodes found
  430. */
  431. nsIArray getLinkedObjects();
  432. /**
  433. * A boolean which is true is the HTMLEditor has been instantiated
  434. * with CSS knowledge and if the CSS pref is currently checked
  435. *
  436. * @return true if CSS handled and enabled
  437. */
  438. attribute boolean isCSSEnabled;
  439. /**
  440. * Add listener for insertion override
  441. * @param inFilter function which callers want called during insertion
  442. */
  443. void addInsertionListener(in nsIContentFilter inFilter);
  444. /**
  445. * Remove listener for insertion override
  446. * @param inFilter function which callers do not want called during insertion
  447. */
  448. void removeInsertionListener(in nsIContentFilter inFilter);
  449. /**
  450. * Returns an anonymous nsDOMElement of type aTag,
  451. * child of aParentNode. If aIsCreatedHidden is true, the class
  452. * "hidden" is added to the created element. If aAnonClass is not
  453. * the empty string, it becomes the value of the attribute "_moz_anonclass"
  454. * @return a DOM Element
  455. * @param aTag [IN] a string representing the desired type of
  456. * the element to create
  457. * @param aParentNode [IN] the parent node of the created anonymous
  458. * element
  459. * @param aAnonClass [IN] contents of the _moz_anonclass attribute
  460. * @param aIsCreatedHidden [IN] a boolean specifying if the class "hidden"
  461. * is to be added to the created anonymous
  462. * element
  463. */
  464. nsIDOMElement createAnonymousElement(in AString aTag, in nsIDOMNode aParentNode,
  465. in AString aAnonClass, in boolean aIsCreatedHidden);
  466. /**
  467. * returns the deepest container of the selection
  468. * @return a DOM Element
  469. */
  470. nsIDOMElement getSelectionContainer();
  471. /**
  472. * Checks if the anonymous nodes created by the HTML editor have to be
  473. * refreshed or hidden depending on a possible new state of the selection
  474. * @param aSelection [IN] a selection
  475. */
  476. void checkSelectionStateForAnonymousButtons(in nsISelection aSelection);
  477. boolean isAnonymousElement(in nsIDOMElement aElement);
  478. /**
  479. * A boolean indicating if a return key pressed in a paragraph creates
  480. * another paragraph or just inserts a <br> at the caret
  481. *
  482. * @return true if CR in a paragraph creates a new paragraph
  483. */
  484. attribute boolean returnInParagraphCreatesNewParagraph;
  485. /**
  486. * Get an active editor's editing host in DOM window. If this editor isn't
  487. * active in the DOM window, this returns NULL.
  488. */
  489. [noscript, notxpcom] Element GetActiveEditingHost();
  490. };