diff --git a/mozilla/editor/base/EditTable.cpp b/mozilla/editor/base/EditTable.cpp index ffff91bb5d3..8d3075a571a 100644 --- a/mozilla/editor/base/EditTable.cpp +++ b/mozilla/editor/base/EditTable.cpp @@ -120,10 +120,11 @@ NS_IMETHODIMP nsHTMLEditor::JoinTableCells(PRBool aCellToRight) return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsHTMLEditor::GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex) +NS_IMETHODIMP nsHTMLEditor::GetCellIndexes(nsIDOMNode *aCellNode, PRInt32 &aColIndex, PRInt32 &aRowIndex) { nsresult result=NS_ERROR_NOT_INITIALIZED; - aCellIndex=0; // initialize out param + aColIndex=0; // initialize out params + aRowIndex=0; result = NS_ERROR_FAILURE; // we return an error unless we get the index nsISupports *layoutObject=nsnull; // frames are not ref counted, so don't use an nsCOMPtr @@ -135,17 +136,14 @@ NS_IMETHODIMP nsHTMLEditor::GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &a result = layoutObject->QueryInterface(nsITableCellLayout::GetIID(), (void**)(&cellLayoutObject)); if ((NS_SUCCEEDED(result)) && (nsnull!=cellLayoutObject)) { // get the index - result = cellLayoutObject->GetColIndex(aCellIndex); + result = cellLayoutObject->GetColIndex(aColIndex); + if (NS_SUCCEEDED(result)) + result = cellLayoutObject->GetRowIndex(aRowIndex); } } return result; } -NS_IMETHODIMP nsHTMLEditor::GetRowIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsHTMLEditor::GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode) { diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index d0cf1ed7995..0112ff1c460 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -2112,7 +2112,7 @@ NS_IMETHODIMP nsEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtrGetNodeName(tag); - printf("Parent of selected node's NodeName = "); + printf("DeleteSelectionAndPrepareToCreateNode: Parent of selected node: "); wprintf(tag.GetUnicode()); printf("\n"); #endif @@ -2886,6 +2886,14 @@ nsEditor::IsNodeBlock(nsIDOMNode *aNode, PRBool &aIsBlock) } result = NS_OK; } + } else { + // We don't have an element -- probably a text node + nsCOMPtrnodeAsText = do_QueryInterface(aNode); + if (nodeAsText) + { + aIsBlock = PR_FALSE; + result = NS_OK; + } } return result; } diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 759a59e0775..233dced3e6a 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -721,6 +721,8 @@ nsEditorShell::PrepareDocumentForEditing() domSelection->AddSelectionListener(mStateMaintainer); #endif + // Force initial focus to the content window -- HOW? +// mWebShellWin->SetFocus(); return NS_OK; } diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 4b2b80a812a..06a7cc3c627 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -2139,10 +2139,6 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* // Set default values for new elements if (TagName.Equals("hr")) - { - // TODO: Get the text of the selection and build a suggested Name - // Replace spaces with "_" - } else if (TagName.Equals("hr")) { // Hard coded defaults in case there's no prefs nsAutoString align("center"); @@ -2262,9 +2258,6 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) // For most elements, set caret after inserting PRBool setCaretAfterElement = PR_TRUE; - nsCOMPtr parentSelectedNode; - PRInt32 splitPointOffset; - nsCOMPtrselection; res = nsEditor::GetSelection(getter_AddRefs(selection)); if (!NS_SUCCEEDED(res) || !selection) @@ -2314,103 +2307,65 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) } } - res = DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, splitPointOffset); - if (NS_SUCCEEDED(res)) + nsCOMPtr parentSelectedNode; + PRInt32 splitPointOffset; + PRInt32 offsetOfSelectedNode; + res = selection->GetAnchorNode(getter_AddRefs(parentSelectedNode)); + if (NS_SUCCEEDED(res) && NS_SUCCEEDED(selection->GetAnchorOffset(&splitPointOffset)) && parentSelectedNode) { - nsCOMPtr newNode = do_QueryInterface(aElement); - PRBool isInline; - res = IsNodeInline(newNode, isInline); - if( NS_SUCCEEDED(res) && isInline) - { - // The simple case of an inline node - // This will split any inline nodes at the caret - // and insert between them - res = InsertNode(aElement, parentSelectedNode, splitPointOffset); - } else { - // Inserting a BLOCK element - // Get the first block parent of the paragraph/container - // which we can split to create insert location - // (Current parent may already be a suitable block to split) - nsCOMPtr parentNodeOfInsert = parentSelectedNode; - nsCOMPtr topNodeToSplit = parentSelectedNode; - nsCOMPtr bodyElement; - // We need to find the offset at each level we will split - // to use when we insert the new element - PRInt32 offsetToInsertAt = splitPointOffset; - - res = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); - - if (NS_SUCCEEDED(res) && bodyElement && - // If text node is direct child of body, we can't insert a block node - (parentSelectedNode != bodyElement)) - { - nsCOMPtr bodyNode = do_QueryInterface(bodyElement); - isInline = PR_TRUE; - while (isInline) - { - // Get parent of the top node to split - res = topNodeToSplit->GetParentNode(getter_AddRefs(parentNodeOfInsert)); - // If Inline, we loop around to get the next parent level - if (NS_SUCCEEDED(res) && parentNodeOfInsert && - NS_SUCCEEDED(IsNodeInline(topNodeToSplit, isInline)) && - NS_SUCCEEDED(GetChildOffset(topNodeToSplit, parentNodeOfInsert, offsetToInsertAt))) - { #ifdef DEBUG_cmanske - nsAutoString nodeName; - topNodeToSplit->GetNodeName(nodeName); - printf("Top Node to split: "); - wprintf(nodeName.GetUnicode()); - - parentNodeOfInsert->GetNodeName(nodeName); - printf(" Parent of this node: "); - wprintf(nodeName.GetUnicode()); - printf("\n"); -#endif - - // The new offset to insert at is just after the topmost node we will split - offsetToInsertAt++; - } else { - // Major failure if we get here - return NS_ERROR_FAILURE; - } - } - if (bodyNode != topNodeToSplit) - { - // We have the node to split and its parent. - // TODO: Implement "CanContainElement" to be sure - // we are allowed to insert aElement under parentNodeOfInsert - // If we can't we should call special methods for various combintations -// if (!CanContain(aElement, parentNodeOfInsert) -// return NS_ERROR_FAILURE; - - // Split nodes from the selection parent ("bottom node") and all intervening parents - // up to the topmost node, which may be = to bottom node) - // (This redistribute children as each level is split.) - res = SplitNodeDeep(topNodeToSplit, parentSelectedNode, splitPointOffset); - if (NS_SUCCEEDED(res)) - { - //Insert the block element between the 2 "topmost" containers - res = InsertNode(aElement, parentNodeOfInsert, offsetToInsertAt); - - // Check for special case of inserting a table - PRBool caretIsSet; - res = SetCaretInTableCell(aElement, &caretIsSet); - if (NS_SUCCEEDED(res) && caretIsSet) - setCaretAfterElement = PR_FALSE; - } - } else { - // If here, we must have an inline node directly under the body - // so we can't insert a block tag - // TODO: Take each inline node resulting from DeleteSelectionAndPrepareToCreateNode - // and insert them each into a default paragraph. - // Then insert new block node between them. - return NS_ERROR_FAILURE; - } - } + { + nsAutoString name; + parentSelectedNode->GetNodeName(name); + printf("parentSelectedNode: "); + wprintf(name.GetUnicode()); + printf("\n"); } +#endif + nsAutoString tagName; + aElement->GetNodeName(tagName); + tagName.ToLowerCase(); + nsCOMPtr parent = parentSelectedNode; + nsCOMPtr topChild = parentSelectedNode; + nsCOMPtr tmp; + PRInt32 offset = offsetOfSelectedNode; + + while (!CanContainTag(parent, tagName)) + { + // If the current parent is a root (body or table cell) + // then go no further - we can't insert + nsAutoString parentTagName; + parent->GetNodeName(parentTagName); + PRBool isRoot; + res = IsRootTag(parentTagName, isRoot); + if (!NS_SUCCEEDED(res) || isRoot) + return NS_ERROR_FAILURE; + // Get the next parent + parent->GetParentNode(getter_AddRefs(tmp)); + if (!tmp) + return NS_ERROR_FAILURE; + topChild = parent; + parent = tmp; + } + + // we need to split up to the child of parent + res = SplitNodeDeep(topChild, parentSelectedNode, splitPointOffset); + if (NS_FAILED(res)) + return res; + // topChild already went to the right on the split + // so we don't need to add one to offset when figuring + // out where to plop list + offset = GetIndexOf(parent,topChild); + + // Now we can finally insert the new node + res = InsertNode(aElement, parent, offset); + + // Set caret after element, but check for special case + // of inserting table-related elements: set in first cell instead + if (!SetCaretInTableCell(aElement)) + res = SetCaretAfterElement(aElement); + } - if (setCaretAfterElement && NS_SUCCEEDED(res)) - SetCaretAfterElement(aElement); return res; } @@ -2579,21 +2534,21 @@ nsHTMLEditor::SelectElement(nsIDOMElement* aElement) return res; } -NS_IMETHODIMP -nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement, PRBool* caretIsSet) +PRBool +nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement) { - nsresult res = NS_ERROR_NULL_POINTER; - if (caretIsSet) - *caretIsSet = PR_FALSE; + PRBool caretIsSet = PR_FALSE; + if (aElement && IsElementInBody(aElement)) { - res = NS_OK; + nsresult res = NS_OK; nsAutoString tagName; aElement->GetNodeName(tagName); tagName.ToLowerCase(); - if (tagName == "td" || tagName == "tr" || - tagName == "th" || tagName == "td" || - tagName == "caption") + if (tagName == "table" || tagName == "tr" || + tagName == "td" || tagName == "th" || + tagName == "thead" || tagName == "tfoot" || + tagName == "tbody" || tagName == "caption") { nsCOMPtr node = do_QueryInterface(aElement); nsCOMPtr parent; @@ -2642,12 +2597,12 @@ nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement, PRBool* caretIsSet) if (NS_SUCCEEDED(res) && selection) { res = selection->Collapse(parent, offset); - if (NS_SUCCEEDED(res) && caretIsSet) - *caretIsSet = PR_TRUE; + if (NS_SUCCEEDED(res)) + caretIsSet = PR_TRUE; } } } - return res; + return caretIsSet; } NS_IMETHODIMP @@ -2675,8 +2630,6 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) { PRInt32 offsetInParent; res = GetChildOffset(aElement, parent, offsetInParent); - // New collapsed selection will be just after the new element - offsetInParent++; if (NS_SUCCEEDED(res)) { // Collapse selection to just after desired element, diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h index be1f8792231..da7d34e3012 100644 --- a/mozilla/editor/base/nsHTMLEditor.h +++ b/mozilla/editor/base/nsHTMLEditor.h @@ -158,18 +158,18 @@ public: NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection); NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement); NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); - PRBool IsElementInBody(nsIDOMElement* aElement); NS_IMETHOD SelectElement(nsIDOMElement* aElement); - NS_IMETHOD SetCaretInTableCell(nsIDOMElement* aElement, PRBool* caretIsSet); NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement); + // Return TRUE if aElement is a table-related elemet and caret was set + PRBool SetCaretInTableCell(nsIDOMElement* aElement); + PRBool IsElementInBody(nsIDOMElement* aElement); // MHTML helper methods NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); // Table Editing (implemented in EditTable.cpp) NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn); - NS_IMETHOD GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex); - NS_IMETHOD GetRowIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex); + NS_IMETHOD GetCellIndexes(nsIDOMNode *aCellNode, PRInt32 &aColIndex, PRInt32 &aRowIndex); NS_IMETHOD GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode); NS_IMETHOD GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode); NS_IMETHOD GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode); diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 759a59e0775..233dced3e6a 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -721,6 +721,8 @@ nsEditorShell::PrepareDocumentForEditing() domSelection->AddSelectionListener(mStateMaintainer); #endif + // Force initial focus to the content window -- HOW? +// mWebShellWin->SetFocus(); return NS_OK; } diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index d0cf1ed7995..0112ff1c460 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -2112,7 +2112,7 @@ NS_IMETHODIMP nsEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtrGetNodeName(tag); - printf("Parent of selected node's NodeName = "); + printf("DeleteSelectionAndPrepareToCreateNode: Parent of selected node: "); wprintf(tag.GetUnicode()); printf("\n"); #endif @@ -2886,6 +2886,14 @@ nsEditor::IsNodeBlock(nsIDOMNode *aNode, PRBool &aIsBlock) } result = NS_OK; } + } else { + // We don't have an element -- probably a text node + nsCOMPtrnodeAsText = do_QueryInterface(aNode); + if (nodeAsText) + { + aIsBlock = PR_FALSE; + result = NS_OK; + } } return result; } diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 4b2b80a812a..06a7cc3c627 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -2139,10 +2139,6 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* // Set default values for new elements if (TagName.Equals("hr")) - { - // TODO: Get the text of the selection and build a suggested Name - // Replace spaces with "_" - } else if (TagName.Equals("hr")) { // Hard coded defaults in case there's no prefs nsAutoString align("center"); @@ -2262,9 +2258,6 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) // For most elements, set caret after inserting PRBool setCaretAfterElement = PR_TRUE; - nsCOMPtr parentSelectedNode; - PRInt32 splitPointOffset; - nsCOMPtrselection; res = nsEditor::GetSelection(getter_AddRefs(selection)); if (!NS_SUCCEEDED(res) || !selection) @@ -2314,103 +2307,65 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) } } - res = DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, splitPointOffset); - if (NS_SUCCEEDED(res)) + nsCOMPtr parentSelectedNode; + PRInt32 splitPointOffset; + PRInt32 offsetOfSelectedNode; + res = selection->GetAnchorNode(getter_AddRefs(parentSelectedNode)); + if (NS_SUCCEEDED(res) && NS_SUCCEEDED(selection->GetAnchorOffset(&splitPointOffset)) && parentSelectedNode) { - nsCOMPtr newNode = do_QueryInterface(aElement); - PRBool isInline; - res = IsNodeInline(newNode, isInline); - if( NS_SUCCEEDED(res) && isInline) - { - // The simple case of an inline node - // This will split any inline nodes at the caret - // and insert between them - res = InsertNode(aElement, parentSelectedNode, splitPointOffset); - } else { - // Inserting a BLOCK element - // Get the first block parent of the paragraph/container - // which we can split to create insert location - // (Current parent may already be a suitable block to split) - nsCOMPtr parentNodeOfInsert = parentSelectedNode; - nsCOMPtr topNodeToSplit = parentSelectedNode; - nsCOMPtr bodyElement; - // We need to find the offset at each level we will split - // to use when we insert the new element - PRInt32 offsetToInsertAt = splitPointOffset; - - res = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); - - if (NS_SUCCEEDED(res) && bodyElement && - // If text node is direct child of body, we can't insert a block node - (parentSelectedNode != bodyElement)) - { - nsCOMPtr bodyNode = do_QueryInterface(bodyElement); - isInline = PR_TRUE; - while (isInline) - { - // Get parent of the top node to split - res = topNodeToSplit->GetParentNode(getter_AddRefs(parentNodeOfInsert)); - // If Inline, we loop around to get the next parent level - if (NS_SUCCEEDED(res) && parentNodeOfInsert && - NS_SUCCEEDED(IsNodeInline(topNodeToSplit, isInline)) && - NS_SUCCEEDED(GetChildOffset(topNodeToSplit, parentNodeOfInsert, offsetToInsertAt))) - { #ifdef DEBUG_cmanske - nsAutoString nodeName; - topNodeToSplit->GetNodeName(nodeName); - printf("Top Node to split: "); - wprintf(nodeName.GetUnicode()); - - parentNodeOfInsert->GetNodeName(nodeName); - printf(" Parent of this node: "); - wprintf(nodeName.GetUnicode()); - printf("\n"); -#endif - - // The new offset to insert at is just after the topmost node we will split - offsetToInsertAt++; - } else { - // Major failure if we get here - return NS_ERROR_FAILURE; - } - } - if (bodyNode != topNodeToSplit) - { - // We have the node to split and its parent. - // TODO: Implement "CanContainElement" to be sure - // we are allowed to insert aElement under parentNodeOfInsert - // If we can't we should call special methods for various combintations -// if (!CanContain(aElement, parentNodeOfInsert) -// return NS_ERROR_FAILURE; - - // Split nodes from the selection parent ("bottom node") and all intervening parents - // up to the topmost node, which may be = to bottom node) - // (This redistribute children as each level is split.) - res = SplitNodeDeep(topNodeToSplit, parentSelectedNode, splitPointOffset); - if (NS_SUCCEEDED(res)) - { - //Insert the block element between the 2 "topmost" containers - res = InsertNode(aElement, parentNodeOfInsert, offsetToInsertAt); - - // Check for special case of inserting a table - PRBool caretIsSet; - res = SetCaretInTableCell(aElement, &caretIsSet); - if (NS_SUCCEEDED(res) && caretIsSet) - setCaretAfterElement = PR_FALSE; - } - } else { - // If here, we must have an inline node directly under the body - // so we can't insert a block tag - // TODO: Take each inline node resulting from DeleteSelectionAndPrepareToCreateNode - // and insert them each into a default paragraph. - // Then insert new block node between them. - return NS_ERROR_FAILURE; - } - } + { + nsAutoString name; + parentSelectedNode->GetNodeName(name); + printf("parentSelectedNode: "); + wprintf(name.GetUnicode()); + printf("\n"); } +#endif + nsAutoString tagName; + aElement->GetNodeName(tagName); + tagName.ToLowerCase(); + nsCOMPtr parent = parentSelectedNode; + nsCOMPtr topChild = parentSelectedNode; + nsCOMPtr tmp; + PRInt32 offset = offsetOfSelectedNode; + + while (!CanContainTag(parent, tagName)) + { + // If the current parent is a root (body or table cell) + // then go no further - we can't insert + nsAutoString parentTagName; + parent->GetNodeName(parentTagName); + PRBool isRoot; + res = IsRootTag(parentTagName, isRoot); + if (!NS_SUCCEEDED(res) || isRoot) + return NS_ERROR_FAILURE; + // Get the next parent + parent->GetParentNode(getter_AddRefs(tmp)); + if (!tmp) + return NS_ERROR_FAILURE; + topChild = parent; + parent = tmp; + } + + // we need to split up to the child of parent + res = SplitNodeDeep(topChild, parentSelectedNode, splitPointOffset); + if (NS_FAILED(res)) + return res; + // topChild already went to the right on the split + // so we don't need to add one to offset when figuring + // out where to plop list + offset = GetIndexOf(parent,topChild); + + // Now we can finally insert the new node + res = InsertNode(aElement, parent, offset); + + // Set caret after element, but check for special case + // of inserting table-related elements: set in first cell instead + if (!SetCaretInTableCell(aElement)) + res = SetCaretAfterElement(aElement); + } - if (setCaretAfterElement && NS_SUCCEEDED(res)) - SetCaretAfterElement(aElement); return res; } @@ -2579,21 +2534,21 @@ nsHTMLEditor::SelectElement(nsIDOMElement* aElement) return res; } -NS_IMETHODIMP -nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement, PRBool* caretIsSet) +PRBool +nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement) { - nsresult res = NS_ERROR_NULL_POINTER; - if (caretIsSet) - *caretIsSet = PR_FALSE; + PRBool caretIsSet = PR_FALSE; + if (aElement && IsElementInBody(aElement)) { - res = NS_OK; + nsresult res = NS_OK; nsAutoString tagName; aElement->GetNodeName(tagName); tagName.ToLowerCase(); - if (tagName == "td" || tagName == "tr" || - tagName == "th" || tagName == "td" || - tagName == "caption") + if (tagName == "table" || tagName == "tr" || + tagName == "td" || tagName == "th" || + tagName == "thead" || tagName == "tfoot" || + tagName == "tbody" || tagName == "caption") { nsCOMPtr node = do_QueryInterface(aElement); nsCOMPtr parent; @@ -2642,12 +2597,12 @@ nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement, PRBool* caretIsSet) if (NS_SUCCEEDED(res) && selection) { res = selection->Collapse(parent, offset); - if (NS_SUCCEEDED(res) && caretIsSet) - *caretIsSet = PR_TRUE; + if (NS_SUCCEEDED(res)) + caretIsSet = PR_TRUE; } } } - return res; + return caretIsSet; } NS_IMETHODIMP @@ -2675,8 +2630,6 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) { PRInt32 offsetInParent; res = GetChildOffset(aElement, parent, offsetInParent); - // New collapsed selection will be just after the new element - offsetInParent++; if (NS_SUCCEEDED(res)) { // Collapse selection to just after desired element, diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index be1f8792231..da7d34e3012 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -158,18 +158,18 @@ public: NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection); NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement); NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); - PRBool IsElementInBody(nsIDOMElement* aElement); NS_IMETHOD SelectElement(nsIDOMElement* aElement); - NS_IMETHOD SetCaretInTableCell(nsIDOMElement* aElement, PRBool* caretIsSet); NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement); + // Return TRUE if aElement is a table-related elemet and caret was set + PRBool SetCaretInTableCell(nsIDOMElement* aElement); + PRBool IsElementInBody(nsIDOMElement* aElement); // MHTML helper methods NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList); // Table Editing (implemented in EditTable.cpp) NS_IMETHOD CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn); - NS_IMETHOD GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex); - NS_IMETHOD GetRowIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex); + NS_IMETHOD GetCellIndexes(nsIDOMNode *aCellNode, PRInt32 &aColIndex, PRInt32 &aRowIndex); NS_IMETHOD GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode); NS_IMETHOD GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode); NS_IMETHOD GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode); diff --git a/mozilla/editor/ui/composer/content/EditorAppShell.xul b/mozilla/editor/ui/composer/content/EditorAppShell.xul index 94794710583..1b143c9d526 100644 --- a/mozilla/editor/ui/composer/content/EditorAppShell.xul +++ b/mozilla/editor/ui/composer/content/EditorAppShell.xul @@ -148,7 +148,7 @@ - + diff --git a/mozilla/editor/ui/composer/content/EditorCommands.js b/mozilla/editor/ui/composer/content/EditorCommands.js index 28da06561db..c7179cf9ba3 100644 --- a/mozilla/editor/ui/composer/content/EditorCommands.js +++ b/mozilla/editor/ui/composer/content/EditorCommands.js @@ -314,13 +314,14 @@ function EditorRemoveStyle(styleName) function EditorRemoveLinks() { - dump("NOT IMPLEMENTED YET\n"); + editorShell.RemoveTextProperty("a", ""); contentWindow.focus(); } function EditorApplyStyleSheet(styleSheetURL) { editorShell.ApplyStyleSheet(styleSheetURL); + contentWindow.focus(); } diff --git a/mozilla/editor/ui/composer/content/EditorContent.css b/mozilla/editor/ui/composer/content/EditorContent.css index f164edbc95e..998fe389a16 100644 --- a/mozilla/editor/ui/composer/content/EditorContent.css +++ b/mozilla/editor/ui/composer/content/EditorContent.css @@ -1,13 +1,19 @@ /* Styles to alter look of things in the Editor content window */ +/* new feature, not implemented yet */ a[name] { - display: inline; /*-block;*/ /* the new feature */ + display: inline-block; min-width: 10px; width: 10px; height: 10px; - background-image: url(chrome://editor/skin/images/ED_Left.gif); + background-image: border: 1px solid blue; } +*/ + +a[name]:before { + content: url(chrome://editor/skin/images/ED_Left.gif); +} table { empty-cells: show; diff --git a/mozilla/editor/ui/dialogs/content/EdLinkProps.js b/mozilla/editor/ui/dialogs/content/EdLinkProps.js index c6e4e9f16d6..66fb12807f8 100644 --- a/mozilla/editor/ui/dialogs/content/EdLinkProps.js +++ b/mozilla/editor/ui/dialogs/content/EdLinkProps.js @@ -157,23 +157,31 @@ function onOK() // Append the link text as the last child node // of the anchor node dump("Creating text node\n"); - textNode = editorShell.editorDocument.createTextNode(dialog.linkTextInput.value); + newText = TrimString(dialog.linkTextInput.value); + if (newText.length == 0) { + ShowInputErrorMessage("You must enter some text for this link."); + dialog.linkTextInput.focus(); + return; + } + textNode = editorShell.editorDocument.createTextNode(newText); if (textNode) { anchorElement.appendChild(textNode); } dump("Inserting\n"); editorShell.InsertElement(anchorElement, false); } else if (insertLinkAroundSelection) { + // Text was supplied by the selection, + // so insert a link node as parent of this text dump("Setting link around selected text\n"); editorShell.InsertLinkAroundSelection(anchorElement); } editorShell.EndBatchChanges(); } else if (!insertNew) { // We already had a link, but empty HREF means remove it - // TODO: IMPLEMENT REMOVE LINK - + editorShell.RemoveTextProperty("a", ""); } - + // Note: if HREF is empty and we were inserting a new link, do nothing + window.close(); }