Skip to content

Commit ef514b5

Browse files
committed
Bug 1313986 - Part 4. Use Element instead of nsIDOMElement for resizer. r=masayuki
Resizer and etc attributes on table editor still use nsIDOMElement. Converting to Element makes both implementation and the callers simpler. MozReview-Commit-ID: TTFSvqn5GE --HG-- extra : rebase_source : 705576c4eb0fe5f8f566f3415a8a72842c919edd
1 parent 3d6d028 commit ef514b5

5 files changed

+87
-97
lines changed

editor/libeditor/HTMLAbsPositionEditor.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ HTMLEditor::RefreshGrabber()
270270

271271
SetAnonymousElementPosition(mPositionedObjectX+12,
272272
mPositionedObjectY-14,
273-
static_cast<nsIDOMElement*>(GetAsDOMNode(mGrabber)));
273+
mGrabber);
274274
return NS_OK;
275275
}
276276

@@ -294,9 +294,9 @@ HTMLEditor::HideGrabber()
294294
nsCOMPtr<nsIContent> parentContent = mGrabber->GetParent();
295295
NS_ENSURE_TRUE(parentContent, NS_ERROR_NULL_POINTER);
296296

297-
DeleteRefToAnonymousNode(static_cast<nsIDOMElement*>(GetAsDOMNode(mGrabber)), parentContent, ps);
297+
DeleteRefToAnonymousNode(mGrabber, parentContent, ps);
298298
mGrabber = nullptr;
299-
DeleteRefToAnonymousNode(static_cast<nsIDOMElement*>(GetAsDOMNode(mPositioningShadow)), parentContent, ps);
299+
DeleteRefToAnonymousNode(mPositioningShadow, parentContent, ps);
300300
mPositioningShadow = nullptr;
301301

302302
return NS_OK;
@@ -399,8 +399,7 @@ HTMLEditor::EndMoving()
399399
nsCOMPtr<nsIContent> parentContent = mGrabber->GetParent();
400400
NS_ENSURE_TRUE(parentContent, NS_ERROR_FAILURE);
401401

402-
DeleteRefToAnonymousNode(static_cast<nsIDOMElement*>(GetAsDOMNode(mPositioningShadow)),
403-
parentContent, ps);
402+
DeleteRefToAnonymousNode(mPositioningShadow, parentContent, ps);
404403

405404
mPositioningShadow = nullptr;
406405
}

editor/libeditor/HTMLAnonymousNodeEditor.cpp

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -286,51 +286,50 @@ HTMLEditor::RemoveListenerAndDeleteRef(const nsAString& aEvent,
286286
if (evtTarget) {
287287
evtTarget->RemoveEventListener(aEvent, aListener, aUseCapture);
288288
}
289-
DeleteRefToAnonymousNode(static_cast<nsIDOMElement*>(GetAsDOMNode(aElement)), aParentContent, aShell);
289+
DeleteRefToAnonymousNode(aElement, aParentContent, aShell);
290290
}
291291

292292
// Deletes all references to an anonymous element
293293
void
294-
HTMLEditor::DeleteRefToAnonymousNode(nsIDOMElement* aElement,
294+
HTMLEditor::DeleteRefToAnonymousNode(nsIContent* aContent,
295295
nsIContent* aParentContent,
296296
nsIPresShell* aShell)
297297
{
298298
// call ContentRemoved() for the anonymous content
299299
// node so its references get removed from the frame manager's
300300
// undisplay map, and its layout frames get destroyed!
301301

302-
if (aElement) {
303-
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
304-
if (content) {
305-
nsAutoScriptBlocker scriptBlocker;
306-
// Need to check whether aShell has been destroyed (but not yet deleted).
307-
// In that case presContext->GetPresShell() returns nullptr.
308-
// See bug 338129.
309-
if (content->IsInComposedDoc() && aShell && aShell->GetPresContext() &&
310-
aShell->GetPresContext()->GetPresShell() == aShell) {
311-
nsCOMPtr<nsIDocumentObserver> docObserver = do_QueryInterface(aShell);
312-
if (docObserver) {
313-
// Call BeginUpdate() so that the nsCSSFrameConstructor/PresShell
314-
// knows we're messing with the frame tree.
315-
nsCOMPtr<nsIDocument> document = GetDocument();
316-
if (document) {
317-
docObserver->BeginUpdate(document, UPDATE_CONTENT_MODEL);
318-
}
319-
320-
// XXX This is wrong (bug 439258). Once it's fixed, the NS_WARNING
321-
// in RestyleManager::RestyleForRemove should be changed back
322-
// to an assertion.
323-
docObserver->ContentRemoved(content->GetComposedDoc(),
324-
aParentContent, content, -1,
325-
content->GetPreviousSibling());
326-
if (document) {
327-
docObserver->EndUpdate(document, UPDATE_CONTENT_MODEL);
328-
}
329-
}
302+
if (NS_WARN_IF(!aContent)) {
303+
return;
304+
}
305+
306+
nsAutoScriptBlocker scriptBlocker;
307+
// Need to check whether aShell has been destroyed (but not yet deleted).
308+
// In that case presContext->GetPresShell() returns nullptr.
309+
// See bug 338129.
310+
if (aContent->IsInComposedDoc() && aShell && aShell->GetPresContext() &&
311+
aShell->GetPresContext()->GetPresShell() == aShell) {
312+
nsCOMPtr<nsIDocumentObserver> docObserver = do_QueryInterface(aShell);
313+
if (docObserver) {
314+
// Call BeginUpdate() so that the nsCSSFrameConstructor/PresShell
315+
// knows we're messing with the frame tree.
316+
nsCOMPtr<nsIDocument> document = GetDocument();
317+
if (document) {
318+
docObserver->BeginUpdate(document, UPDATE_CONTENT_MODEL);
319+
}
320+
321+
// XXX This is wrong (bug 439258). Once it's fixed, the NS_WARNING
322+
// in RestyleManager::RestyleForRemove should be changed back
323+
// to an assertion.
324+
docObserver->ContentRemoved(aContent->GetComposedDoc(),
325+
aParentContent, aContent, -1,
326+
aContent->GetPreviousSibling());
327+
if (document) {
328+
docObserver->EndUpdate(document, UPDATE_CONTENT_MODEL);
330329
}
331-
content->UnbindFromTree();
332330
}
333331
}
332+
aContent->UnbindFromTree();
334333
}
335334

336335
// The following method is mostly called by a selection listener. When a
@@ -569,10 +568,10 @@ HTMLEditor::GetPositionAndDimensions(nsIDOMElement* aElement,
569568
void
570569
HTMLEditor::SetAnonymousElementPosition(int32_t aX,
571570
int32_t aY,
572-
nsIDOMElement* aElement)
571+
Element* aElement)
573572
{
574-
mCSSEditUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("left"), aX);
575-
mCSSEditUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("top"), aY);
573+
mCSSEditUtils->SetCSSPropertyPixels(*aElement, *nsGkAtoms::left, aX);
574+
mCSSEditUtils->SetCSSPropertyPixels(*aElement, *nsGkAtoms::top, aY);
576575
}
577576

578577
} // namespace mozilla

editor/libeditor/HTMLEditor.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ class HTMLEditor final : public TextEditor
921921
Element* aElement,
922922
nsIContent* aParentContent,
923923
nsIPresShell* aShell);
924-
void DeleteRefToAnonymousNode(nsIDOMElement* aElement,
924+
void DeleteRefToAnonymousNode(nsIContent* aContent,
925925
nsIContent* aParentContent,
926926
nsIPresShell* aShell);
927927

@@ -1007,7 +1007,7 @@ class HTMLEditor final : public TextEditor
10071007
already_AddRefed<Element> CreateResizer(int16_t aLocation,
10081008
nsIDOMNode* aParentNode);
10091009
void SetAnonymousElementPosition(int32_t aX, int32_t aY,
1010-
nsIDOMElement* aResizer);
1010+
Element* aResizer);
10111011

10121012
already_AddRefed<Element> CreateShadow(nsIDOMNode* aParentNode,
10131013
nsIDOMElement* aOriginalObject);
@@ -1062,16 +1062,16 @@ class HTMLEditor final : public TextEditor
10621062
// inline table editing
10631063
nsCOMPtr<nsIDOMElement> mInlineEditedCell;
10641064

1065-
nsCOMPtr<nsIDOMElement> mAddColumnBeforeButton;
1066-
nsCOMPtr<nsIDOMElement> mRemoveColumnButton;
1067-
nsCOMPtr<nsIDOMElement> mAddColumnAfterButton;
1065+
RefPtr<Element> mAddColumnBeforeButton;
1066+
RefPtr<Element> mRemoveColumnButton;
1067+
RefPtr<Element> mAddColumnAfterButton;
10681068

1069-
nsCOMPtr<nsIDOMElement> mAddRowBeforeButton;
1070-
nsCOMPtr<nsIDOMElement> mRemoveRowButton;
1071-
nsCOMPtr<nsIDOMElement> mAddRowAfterButton;
1069+
RefPtr<Element> mAddRowBeforeButton;
1070+
RefPtr<Element> mRemoveRowButton;
1071+
RefPtr<Element> mAddRowAfterButton;
10721072

1073-
void AddMouseClickListener(nsIDOMElement* aElement);
1074-
void RemoveMouseClickListener(nsIDOMElement* aElement);
1073+
void AddMouseClickListener(Element* aElement);
1074+
void RemoveMouseClickListener(Element* aElement);
10751075

10761076
nsCOMPtr<nsILinkHandler> mLinkHandler;
10771077

editor/libeditor/HTMLEditorObjectResizer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,16 @@ HTMLEditor::SetAllResizersPosition()
241241
int32_t rw = (int32_t)((resizerWidth + 1) / 2);
242242
int32_t rh = (int32_t)((resizerHeight+ 1) / 2);
243243

244-
SetAnonymousElementPosition(x-rw, y-rh, static_cast<nsIDOMElement*>(GetAsDOMNode(mTopLeftHandle)));
245-
SetAnonymousElementPosition(x+w/2-rw, y-rh, static_cast<nsIDOMElement*>(GetAsDOMNode(mTopHandle)));
246-
SetAnonymousElementPosition(x+w-rw-1, y-rh, static_cast<nsIDOMElement*>(GetAsDOMNode(mTopRightHandle)));
244+
SetAnonymousElementPosition(x-rw, y-rh, mTopLeftHandle);
245+
SetAnonymousElementPosition(x+w/2-rw, y-rh, mTopHandle);
246+
SetAnonymousElementPosition(x+w-rw-1, y-rh, mTopRightHandle);
247247

248-
SetAnonymousElementPosition(x-rw, y+h/2-rh, static_cast<nsIDOMElement*>(GetAsDOMNode(mLeftHandle)));
249-
SetAnonymousElementPosition(x+w-rw-1, y+h/2-rh, static_cast<nsIDOMElement*>(GetAsDOMNode(mRightHandle)));
248+
SetAnonymousElementPosition(x-rw, y+h/2-rh, mLeftHandle);
249+
SetAnonymousElementPosition(x+w-rw-1, y+h/2-rh, mRightHandle);
250250

251-
SetAnonymousElementPosition(x-rw, y+h-rh-1, static_cast<nsIDOMElement*>(GetAsDOMNode(mBottomLeftHandle)));
252-
SetAnonymousElementPosition(x+w/2-rw, y+h-rh-1, static_cast<nsIDOMElement*>(GetAsDOMNode(mBottomHandle)));
253-
SetAnonymousElementPosition(x+w-rw-1, y+h-rh-1, static_cast<nsIDOMElement*>(GetAsDOMNode(mBottomRightHandle)));
251+
SetAnonymousElementPosition(x-rw, y+h-rh-1, mBottomLeftHandle);
252+
SetAnonymousElementPosition(x+w/2-rw, y+h-rh-1, mBottomHandle);
253+
SetAnonymousElementPosition(x+w-rw-1, y+h-rh-1, mBottomRightHandle);
254254

255255
return NS_OK;
256256
}
@@ -718,7 +718,7 @@ HTMLEditor::SetShadowPosition(Element* aShadow,
718718
int32_t aOriginalObjectX,
719719
int32_t aOriginalObjectY)
720720
{
721-
SetAnonymousElementPosition(aOriginalObjectX, aOriginalObjectY, static_cast<nsIDOMElement*>(GetAsDOMNode(aShadow)));
721+
SetAnonymousElementPosition(aOriginalObjectX, aOriginalObjectY, aShadow);
722722

723723
if (HTMLEditUtils::IsImage(aOriginalObject)) {
724724
nsAutoString imageSource;

editor/libeditor/HTMLInlineTableEditor.cpp

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@ HTMLEditor::ShowInlineTableEditingUI(nsIDOMElement* aCell)
6161
nsCOMPtr<nsIDOMElement> bodyElement = do_QueryInterface(GetRoot());
6262
NS_ENSURE_TRUE(bodyElement, NS_ERROR_NULL_POINTER);
6363

64-
CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
65-
NS_LITERAL_STRING("mozTableAddColumnBefore"),
66-
false, getter_AddRefs(mAddColumnBeforeButton));
67-
CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
68-
NS_LITERAL_STRING("mozTableRemoveColumn"),
69-
false, getter_AddRefs(mRemoveColumnButton));
70-
CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
71-
NS_LITERAL_STRING("mozTableAddColumnAfter"),
72-
false, getter_AddRefs(mAddColumnAfterButton));
73-
74-
CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
75-
NS_LITERAL_STRING("mozTableAddRowBefore"),
76-
false, getter_AddRefs(mAddRowBeforeButton));
77-
CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
78-
NS_LITERAL_STRING("mozTableRemoveRow"),
79-
false, getter_AddRefs(mRemoveRowButton));
80-
CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
81-
NS_LITERAL_STRING("mozTableAddRowAfter"),
82-
false, getter_AddRefs(mAddRowAfterButton));
64+
mAddColumnBeforeButton =
65+
CreateAnonymousElement(nsGkAtoms::a, bodyElement,
66+
NS_LITERAL_STRING("mozTableAddColumnBefore"), false);
67+
mRemoveColumnButton =
68+
CreateAnonymousElement(nsGkAtoms::a, bodyElement,
69+
NS_LITERAL_STRING("mozTableRemoveColumn"), false);
70+
mAddColumnAfterButton =
71+
CreateAnonymousElement(nsGkAtoms::a, bodyElement,
72+
NS_LITERAL_STRING("mozTableAddColumnAfter"), false);
73+
74+
mAddRowBeforeButton =
75+
CreateAnonymousElement(nsGkAtoms::a, bodyElement,
76+
NS_LITERAL_STRING("mozTableAddRowBefore"), false);
77+
mRemoveRowButton =
78+
CreateAnonymousElement(nsGkAtoms::a, bodyElement,
79+
NS_LITERAL_STRING("mozTableRemoveRow"), false);
80+
mAddRowAfterButton =
81+
CreateAnonymousElement(nsGkAtoms::a, bodyElement,
82+
NS_LITERAL_STRING("mozTableAddRowAfter"), false);
8383

8484
AddMouseClickListener(mAddColumnBeforeButton);
8585
AddMouseClickListener(mRemoveColumnButton);
@@ -188,7 +188,7 @@ HTMLEditor::DoInlineTableEditingAction(nsIDOMElement* aElement)
188188
}
189189

190190
void
191-
HTMLEditor::AddMouseClickListener(nsIDOMElement* aElement)
191+
HTMLEditor::AddMouseClickListener(Element* aElement)
192192
{
193193
nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(aElement));
194194
if (evtTarget) {
@@ -198,7 +198,7 @@ HTMLEditor::AddMouseClickListener(nsIDOMElement* aElement)
198198
}
199199

200200
void
201-
HTMLEditor::RemoveMouseClickListener(nsIDOMElement* aElement)
201+
HTMLEditor::RemoveMouseClickListener(Element* aElement)
202202
{
203203
nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(aElement));
204204
if (evtTarget) {
@@ -234,17 +234,12 @@ HTMLEditor::RefreshInlineTableEditingUI()
234234

235235
SetAnonymousElementPosition(xHoriz-10, yCell-7, mAddColumnBeforeButton);
236236
#ifdef DISABLE_TABLE_DELETION
237-
NS_NAMED_LITERAL_STRING(classStr, "class");
238-
239237
if (colCount== 1) {
240-
mRemoveColumnButton->SetAttribute(classStr,
241-
NS_LITERAL_STRING("hidden"));
242-
}
243-
else {
244-
bool hasClass = false;
245-
rv = mRemoveColumnButton->HasAttribute(classStr, &hasClass);
246-
if (NS_SUCCEEDED(rv) && hasClass) {
247-
mRemoveColumnButton->RemoveAttribute(classStr);
238+
mRemoveColumnButton->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
239+
NS_LITERAL_STRING("hidden"), true);
240+
} else {
241+
if (mRemoveColumnButton->HasAttr(kNameSpaceID_None, nsGkAtoms::_class)) {
242+
mRemoveColumnButton->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class);
248243
}
249244
#endif
250245
SetAnonymousElementPosition(xHoriz-4, yCell-7, mRemoveColumnButton);
@@ -256,14 +251,11 @@ HTMLEditor::RefreshInlineTableEditingUI()
256251
SetAnonymousElementPosition(xCell-7, yVert-10, mAddRowBeforeButton);
257252
#ifdef DISABLE_TABLE_DELETION
258253
if (rowCount== 1) {
259-
mRemoveRowButton->SetAttribute(classStr,
260-
NS_LITERAL_STRING("hidden"));
261-
}
262-
else {
263-
bool hasClass = false;
264-
rv = mRemoveRowButton->HasAttribute(classStr, &hasClass);
265-
if (NS_SUCCEEDED(rv) && hasClass) {
266-
mRemoveRowButton->RemoveAttribute(classStr);
254+
mRemoveRowButton->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
255+
NS_LITERAL_STRING("hidden"), true);
256+
} else {
257+
if (mRemoveRowButton->HasAttr(kNameSpaceID_None, nsGkAtoms::_class)) {
258+
mRemoveRowButton->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
267259
}
268260
#endif
269261
SetAnonymousElementPosition(xCell-7, yVert-4, mRemoveRowButton);

0 commit comments

Comments
 (0)