Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "mozilla/Attributes.h" |
michael@0 | 6 | #include "mozilla/dom/Element.h" |
michael@0 | 7 | #include "mozilla/mozalloc.h" |
michael@0 | 8 | #include "nsAString.h" |
michael@0 | 9 | #include "nsAutoPtr.h" |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsComputedDOMStyle.h" |
michael@0 | 12 | #include "nsDebug.h" |
michael@0 | 13 | #include "nsEditProperty.h" |
michael@0 | 14 | #include "nsError.h" |
michael@0 | 15 | #include "nsHTMLCSSUtils.h" |
michael@0 | 16 | #include "nsHTMLEditor.h" |
michael@0 | 17 | #include "nsIAtom.h" |
michael@0 | 18 | #include "nsIContent.h" |
michael@0 | 19 | #include "nsID.h" |
michael@0 | 20 | #include "nsIDOMCSSPrimitiveValue.h" |
michael@0 | 21 | #include "nsIDOMCSSStyleDeclaration.h" |
michael@0 | 22 | #include "nsIDOMCSSValue.h" |
michael@0 | 23 | #include "nsIDOMElement.h" |
michael@0 | 24 | #include "nsIDOMEventTarget.h" |
michael@0 | 25 | #include "nsIDOMHTMLElement.h" |
michael@0 | 26 | #include "nsIDOMNode.h" |
michael@0 | 27 | #include "nsIDOMWindow.h" |
michael@0 | 28 | #include "nsIDocument.h" |
michael@0 | 29 | #include "nsIDocumentObserver.h" |
michael@0 | 30 | #include "nsIHTMLAbsPosEditor.h" |
michael@0 | 31 | #include "nsIHTMLEditor.h" |
michael@0 | 32 | #include "nsIHTMLInlineTableEditor.h" |
michael@0 | 33 | #include "nsIHTMLObjectResizer.h" |
michael@0 | 34 | #include "nsIMutationObserver.h" |
michael@0 | 35 | #include "nsINode.h" |
michael@0 | 36 | #include "nsIPresShell.h" |
michael@0 | 37 | #include "nsISupportsImpl.h" |
michael@0 | 38 | #include "nsISupportsUtils.h" |
michael@0 | 39 | #include "nsLiteralString.h" |
michael@0 | 40 | #include "nsPresContext.h" |
michael@0 | 41 | #include "nsReadableUtils.h" |
michael@0 | 42 | #include "nsString.h" |
michael@0 | 43 | #include "nsStringFwd.h" |
michael@0 | 44 | #include "nsUnicharUtils.h" |
michael@0 | 45 | #include "nscore.h" |
michael@0 | 46 | #include "nsContentUtils.h" // for nsAutoScriptBlocker |
michael@0 | 47 | |
michael@0 | 48 | class nsIDOMEventListener; |
michael@0 | 49 | class nsISelection; |
michael@0 | 50 | |
michael@0 | 51 | using namespace mozilla; |
michael@0 | 52 | |
michael@0 | 53 | // retrieve an integer stored into a CSS computed float value |
michael@0 | 54 | static int32_t GetCSSFloatValue(nsIDOMCSSStyleDeclaration * aDecl, |
michael@0 | 55 | const nsAString & aProperty) |
michael@0 | 56 | { |
michael@0 | 57 | MOZ_ASSERT(aDecl); |
michael@0 | 58 | |
michael@0 | 59 | nsCOMPtr<nsIDOMCSSValue> value; |
michael@0 | 60 | // get the computed CSSValue of the property |
michael@0 | 61 | nsresult res = aDecl->GetPropertyCSSValue(aProperty, getter_AddRefs(value)); |
michael@0 | 62 | if (NS_FAILED(res) || !value) return 0; |
michael@0 | 63 | |
michael@0 | 64 | // check the type of the returned CSSValue; we handle here only |
michael@0 | 65 | // pixel and enum types |
michael@0 | 66 | nsCOMPtr<nsIDOMCSSPrimitiveValue> val = do_QueryInterface(value); |
michael@0 | 67 | uint16_t type; |
michael@0 | 68 | val->GetPrimitiveType(&type); |
michael@0 | 69 | |
michael@0 | 70 | float f = 0; |
michael@0 | 71 | switch (type) { |
michael@0 | 72 | case nsIDOMCSSPrimitiveValue::CSS_PX: |
michael@0 | 73 | // the value is in pixels, just get it |
michael@0 | 74 | res = val->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_PX, &f); |
michael@0 | 75 | NS_ENSURE_SUCCESS(res, 0); |
michael@0 | 76 | break; |
michael@0 | 77 | case nsIDOMCSSPrimitiveValue::CSS_IDENT: { |
michael@0 | 78 | // the value is keyword, we have to map these keywords into |
michael@0 | 79 | // numeric values |
michael@0 | 80 | nsAutoString str; |
michael@0 | 81 | res = val->GetStringValue(str); |
michael@0 | 82 | if (str.EqualsLiteral("thin")) |
michael@0 | 83 | f = 1; |
michael@0 | 84 | else if (str.EqualsLiteral("medium")) |
michael@0 | 85 | f = 3; |
michael@0 | 86 | else if (str.EqualsLiteral("thick")) |
michael@0 | 87 | f = 5; |
michael@0 | 88 | break; |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | return (int32_t) f; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | class nsElementDeletionObserver MOZ_FINAL : public nsIMutationObserver |
michael@0 | 96 | { |
michael@0 | 97 | public: |
michael@0 | 98 | nsElementDeletionObserver(nsINode* aNativeAnonNode, nsINode* aObservedNode) |
michael@0 | 99 | : mNativeAnonNode(aNativeAnonNode), mObservedNode(aObservedNode) {} |
michael@0 | 100 | NS_DECL_ISUPPORTS |
michael@0 | 101 | NS_DECL_NSIMUTATIONOBSERVER |
michael@0 | 102 | protected: |
michael@0 | 103 | nsINode* mNativeAnonNode; |
michael@0 | 104 | nsINode* mObservedNode; |
michael@0 | 105 | }; |
michael@0 | 106 | |
michael@0 | 107 | NS_IMPL_ISUPPORTS(nsElementDeletionObserver, nsIMutationObserver) |
michael@0 | 108 | NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(nsElementDeletionObserver) |
michael@0 | 109 | |
michael@0 | 110 | void |
michael@0 | 111 | nsElementDeletionObserver::NodeWillBeDestroyed(const nsINode* aNode) |
michael@0 | 112 | { |
michael@0 | 113 | NS_ASSERTION(aNode == mNativeAnonNode || aNode == mObservedNode, |
michael@0 | 114 | "Wrong aNode!"); |
michael@0 | 115 | if (aNode == mNativeAnonNode) { |
michael@0 | 116 | mObservedNode->RemoveMutationObserver(this); |
michael@0 | 117 | } else { |
michael@0 | 118 | mNativeAnonNode->RemoveMutationObserver(this); |
michael@0 | 119 | static_cast<nsIContent*>(mNativeAnonNode)->UnbindFromTree(); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | NS_RELEASE_THIS(); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | // Returns in *aReturn an anonymous nsDOMElement of type aTag, |
michael@0 | 126 | // child of aParentNode. If aIsCreatedHidden is true, the class |
michael@0 | 127 | // "hidden" is added to the created element. If aAnonClass is not |
michael@0 | 128 | // the empty string, it becomes the value of the attribute "_moz_anonclass" |
michael@0 | 129 | nsresult |
michael@0 | 130 | nsHTMLEditor::CreateAnonymousElement(const nsAString & aTag, nsIDOMNode * aParentNode, |
michael@0 | 131 | const nsAString & aAnonClass, bool aIsCreatedHidden, |
michael@0 | 132 | nsIDOMElement ** aReturn) |
michael@0 | 133 | { |
michael@0 | 134 | NS_ENSURE_ARG_POINTER(aParentNode); |
michael@0 | 135 | NS_ENSURE_ARG_POINTER(aReturn); |
michael@0 | 136 | *aReturn = nullptr; |
michael@0 | 137 | |
michael@0 | 138 | nsCOMPtr<nsIContent> parentContent( do_QueryInterface(aParentNode) ); |
michael@0 | 139 | NS_ENSURE_TRUE(parentContent, NS_OK); |
michael@0 | 140 | |
michael@0 | 141 | nsCOMPtr<nsIDocument> doc = GetDocument(); |
michael@0 | 142 | NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER); |
michael@0 | 143 | |
michael@0 | 144 | // Get the pres shell |
michael@0 | 145 | nsCOMPtr<nsIPresShell> ps = GetPresShell(); |
michael@0 | 146 | NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 147 | |
michael@0 | 148 | // Create a new node through the element factory |
michael@0 | 149 | nsCOMPtr<dom::Element> newContent; |
michael@0 | 150 | nsresult res = CreateHTMLContent(aTag, getter_AddRefs(newContent)); |
michael@0 | 151 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 152 | |
michael@0 | 153 | nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(newContent); |
michael@0 | 154 | NS_ENSURE_TRUE(newElement, NS_ERROR_FAILURE); |
michael@0 | 155 | |
michael@0 | 156 | // add the "hidden" class if needed |
michael@0 | 157 | if (aIsCreatedHidden) { |
michael@0 | 158 | res = newElement->SetAttribute(NS_LITERAL_STRING("class"), |
michael@0 | 159 | NS_LITERAL_STRING("hidden")); |
michael@0 | 160 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | // add an _moz_anonclass attribute if needed |
michael@0 | 164 | if (!aAnonClass.IsEmpty()) { |
michael@0 | 165 | res = newElement->SetAttribute(NS_LITERAL_STRING("_moz_anonclass"), |
michael@0 | 166 | aAnonClass); |
michael@0 | 167 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | { |
michael@0 | 171 | nsAutoScriptBlocker scriptBlocker; |
michael@0 | 172 | |
michael@0 | 173 | // establish parenthood of the element |
michael@0 | 174 | newContent->SetIsNativeAnonymousRoot(); |
michael@0 | 175 | res = newContent->BindToTree(doc, parentContent, parentContent, true); |
michael@0 | 176 | if (NS_FAILED(res)) { |
michael@0 | 177 | newContent->UnbindFromTree(); |
michael@0 | 178 | return res; |
michael@0 | 179 | } |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | nsElementDeletionObserver* observer = |
michael@0 | 183 | new nsElementDeletionObserver(newContent, parentContent); |
michael@0 | 184 | NS_ADDREF(observer); // NodeWillBeDestroyed releases. |
michael@0 | 185 | parentContent->AddMutationObserver(observer); |
michael@0 | 186 | newContent->AddMutationObserver(observer); |
michael@0 | 187 | |
michael@0 | 188 | // display the element |
michael@0 | 189 | ps->RecreateFramesFor(newContent); |
michael@0 | 190 | |
michael@0 | 191 | newElement.forget(aReturn); |
michael@0 | 192 | return NS_OK; |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | // Removes event listener and calls DeleteRefToAnonymousNode. |
michael@0 | 196 | void |
michael@0 | 197 | nsHTMLEditor::RemoveListenerAndDeleteRef(const nsAString& aEvent, |
michael@0 | 198 | nsIDOMEventListener* aListener, |
michael@0 | 199 | bool aUseCapture, |
michael@0 | 200 | nsIDOMElement* aElement, |
michael@0 | 201 | nsIContent * aParentContent, |
michael@0 | 202 | nsIPresShell* aShell) |
michael@0 | 203 | { |
michael@0 | 204 | nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(aElement)); |
michael@0 | 205 | if (evtTarget) { |
michael@0 | 206 | evtTarget->RemoveEventListener(aEvent, aListener, aUseCapture); |
michael@0 | 207 | } |
michael@0 | 208 | DeleteRefToAnonymousNode(aElement, aParentContent, aShell); |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | // Deletes all references to an anonymous element |
michael@0 | 212 | void |
michael@0 | 213 | nsHTMLEditor::DeleteRefToAnonymousNode(nsIDOMElement* aElement, |
michael@0 | 214 | nsIContent* aParentContent, |
michael@0 | 215 | nsIPresShell* aShell) |
michael@0 | 216 | { |
michael@0 | 217 | // call ContentRemoved() for the anonymous content |
michael@0 | 218 | // node so its references get removed from the frame manager's |
michael@0 | 219 | // undisplay map, and its layout frames get destroyed! |
michael@0 | 220 | |
michael@0 | 221 | if (aElement) { |
michael@0 | 222 | nsCOMPtr<nsIContent> content = do_QueryInterface(aElement); |
michael@0 | 223 | if (content) { |
michael@0 | 224 | nsAutoScriptBlocker scriptBlocker; |
michael@0 | 225 | // Need to check whether aShell has been destroyed (but not yet deleted). |
michael@0 | 226 | // In that case presContext->GetPresShell() returns nullptr. |
michael@0 | 227 | // See bug 338129. |
michael@0 | 228 | if (aShell && aShell->GetPresContext() && |
michael@0 | 229 | aShell->GetPresContext()->GetPresShell() == aShell) { |
michael@0 | 230 | nsCOMPtr<nsIDocumentObserver> docObserver = do_QueryInterface(aShell); |
michael@0 | 231 | if (docObserver) { |
michael@0 | 232 | // Call BeginUpdate() so that the nsCSSFrameConstructor/PresShell |
michael@0 | 233 | // knows we're messing with the frame tree. |
michael@0 | 234 | nsCOMPtr<nsIDocument> document = GetDocument(); |
michael@0 | 235 | if (document) |
michael@0 | 236 | docObserver->BeginUpdate(document, UPDATE_CONTENT_MODEL); |
michael@0 | 237 | |
michael@0 | 238 | // XXX This is wrong (bug 439258). Once it's fixed, the NS_WARNING |
michael@0 | 239 | // in RestyleManager::RestyleForRemove should be changed back |
michael@0 | 240 | // to an assertion. |
michael@0 | 241 | docObserver->ContentRemoved(content->GetCurrentDoc(), |
michael@0 | 242 | aParentContent, content, -1, |
michael@0 | 243 | content->GetPreviousSibling()); |
michael@0 | 244 | if (document) |
michael@0 | 245 | docObserver->EndUpdate(document, UPDATE_CONTENT_MODEL); |
michael@0 | 246 | } |
michael@0 | 247 | } |
michael@0 | 248 | content->UnbindFromTree(); |
michael@0 | 249 | } |
michael@0 | 250 | } |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | // The following method is mostly called by a selection listener. When a |
michael@0 | 254 | // selection change is notified, the method is called to check if resizing |
michael@0 | 255 | // handles, a grabber and/or inline table editing UI need to be displayed |
michael@0 | 256 | // or refreshed |
michael@0 | 257 | NS_IMETHODIMP |
michael@0 | 258 | nsHTMLEditor::CheckSelectionStateForAnonymousButtons(nsISelection * aSelection) |
michael@0 | 259 | { |
michael@0 | 260 | NS_ENSURE_ARG_POINTER(aSelection); |
michael@0 | 261 | |
michael@0 | 262 | // early way out if all contextual UI extensions are disabled |
michael@0 | 263 | NS_ENSURE_TRUE(mIsObjectResizingEnabled || |
michael@0 | 264 | mIsAbsolutelyPositioningEnabled || |
michael@0 | 265 | mIsInlineTableEditingEnabled, NS_OK); |
michael@0 | 266 | |
michael@0 | 267 | // Don't change selection state if we're moving. |
michael@0 | 268 | if (mIsMoving) { |
michael@0 | 269 | return NS_OK; |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | nsCOMPtr<nsIDOMElement> focusElement; |
michael@0 | 273 | // let's get the containing element of the selection |
michael@0 | 274 | nsresult res = GetSelectionContainer(getter_AddRefs(focusElement)); |
michael@0 | 275 | NS_ENSURE_TRUE(focusElement, NS_OK); |
michael@0 | 276 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 277 | |
michael@0 | 278 | // If we're not in a document, don't try to add resizers |
michael@0 | 279 | nsCOMPtr<dom::Element> focusElementNode = do_QueryInterface(focusElement); |
michael@0 | 280 | NS_ENSURE_STATE(focusElementNode); |
michael@0 | 281 | if (!focusElementNode->IsInDoc()) { |
michael@0 | 282 | return NS_OK; |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | // what's its tag? |
michael@0 | 286 | nsAutoString focusTagName; |
michael@0 | 287 | res = focusElement->GetTagName(focusTagName); |
michael@0 | 288 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 289 | ToLowerCase(focusTagName); |
michael@0 | 290 | nsCOMPtr<nsIAtom> focusTagAtom = do_GetAtom(focusTagName); |
michael@0 | 291 | |
michael@0 | 292 | nsCOMPtr<nsIDOMElement> absPosElement; |
michael@0 | 293 | if (mIsAbsolutelyPositioningEnabled) { |
michael@0 | 294 | // Absolute Positioning support is enabled, is the selection contained |
michael@0 | 295 | // in an absolutely positioned element ? |
michael@0 | 296 | res = GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(absPosElement)); |
michael@0 | 297 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 298 | } |
michael@0 | 299 | |
michael@0 | 300 | nsCOMPtr<nsIDOMElement> cellElement; |
michael@0 | 301 | if (mIsObjectResizingEnabled || mIsInlineTableEditingEnabled) { |
michael@0 | 302 | // Resizing or Inline Table Editing is enabled, we need to check if the |
michael@0 | 303 | // selection is contained in a table cell |
michael@0 | 304 | res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), |
michael@0 | 305 | nullptr, |
michael@0 | 306 | getter_AddRefs(cellElement)); |
michael@0 | 307 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | if (mIsObjectResizingEnabled && cellElement) { |
michael@0 | 311 | // we are here because Resizing is enabled AND selection is contained in |
michael@0 | 312 | // a cell |
michael@0 | 313 | |
michael@0 | 314 | // get the enclosing table |
michael@0 | 315 | if (nsEditProperty::img != focusTagAtom) { |
michael@0 | 316 | // the element container of the selection is not an image, so we'll show |
michael@0 | 317 | // the resizers around the table |
michael@0 | 318 | nsCOMPtr<nsIDOMNode> tableNode = GetEnclosingTable(cellElement); |
michael@0 | 319 | focusElement = do_QueryInterface(tableNode); |
michael@0 | 320 | focusTagAtom = nsEditProperty::table; |
michael@0 | 321 | } |
michael@0 | 322 | } |
michael@0 | 323 | |
michael@0 | 324 | // we allow resizers only around images, tables, and absolutely positioned |
michael@0 | 325 | // elements. If we don't have image/table, let's look at the latter case. |
michael@0 | 326 | if (nsEditProperty::img != focusTagAtom && |
michael@0 | 327 | nsEditProperty::table != focusTagAtom) |
michael@0 | 328 | focusElement = absPosElement; |
michael@0 | 329 | |
michael@0 | 330 | // at this point, focusElement contains the element for Resizing, |
michael@0 | 331 | // cellElement contains the element for InlineTableEditing |
michael@0 | 332 | // absPosElement contains the element for Positioning |
michael@0 | 333 | |
michael@0 | 334 | // Note: All the Hide/Show methods below may change attributes on real |
michael@0 | 335 | // content which means a DOMAttrModified handler may cause arbitrary |
michael@0 | 336 | // side effects while this code runs (bug 420439). |
michael@0 | 337 | |
michael@0 | 338 | if (mIsAbsolutelyPositioningEnabled && mAbsolutelyPositionedObject && |
michael@0 | 339 | absPosElement != mAbsolutelyPositionedObject) { |
michael@0 | 340 | res = HideGrabber(); |
michael@0 | 341 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 342 | NS_ASSERTION(!mAbsolutelyPositionedObject, "HideGrabber failed"); |
michael@0 | 343 | } |
michael@0 | 344 | |
michael@0 | 345 | if (mIsObjectResizingEnabled && mResizedObject && |
michael@0 | 346 | mResizedObject != focusElement) { |
michael@0 | 347 | res = HideResizers(); |
michael@0 | 348 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 349 | NS_ASSERTION(!mResizedObject, "HideResizers failed"); |
michael@0 | 350 | } |
michael@0 | 351 | |
michael@0 | 352 | if (mIsInlineTableEditingEnabled && mInlineEditedCell && |
michael@0 | 353 | mInlineEditedCell != cellElement) { |
michael@0 | 354 | res = HideInlineTableEditingUI(); |
michael@0 | 355 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 356 | NS_ASSERTION(!mInlineEditedCell, "HideInlineTableEditingUI failed"); |
michael@0 | 357 | } |
michael@0 | 358 | |
michael@0 | 359 | // now, let's display all contextual UI for good |
michael@0 | 360 | nsIContent* hostContent = GetActiveEditingHost(); |
michael@0 | 361 | nsCOMPtr<nsIDOMNode> hostNode = do_QueryInterface(hostContent); |
michael@0 | 362 | |
michael@0 | 363 | if (mIsObjectResizingEnabled && focusElement && |
michael@0 | 364 | IsModifiableNode(focusElement) && focusElement != hostNode) { |
michael@0 | 365 | if (nsEditProperty::img == focusTagAtom) |
michael@0 | 366 | mResizedObjectIsAnImage = true; |
michael@0 | 367 | if (mResizedObject) |
michael@0 | 368 | res = RefreshResizers(); |
michael@0 | 369 | else |
michael@0 | 370 | res = ShowResizers(focusElement); |
michael@0 | 371 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 372 | } |
michael@0 | 373 | |
michael@0 | 374 | if (mIsAbsolutelyPositioningEnabled && absPosElement && |
michael@0 | 375 | IsModifiableNode(absPosElement) && absPosElement != hostNode) { |
michael@0 | 376 | if (mAbsolutelyPositionedObject) |
michael@0 | 377 | res = RefreshGrabber(); |
michael@0 | 378 | else |
michael@0 | 379 | res = ShowGrabberOnElement(absPosElement); |
michael@0 | 380 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | if (mIsInlineTableEditingEnabled && cellElement && |
michael@0 | 384 | IsModifiableNode(cellElement) && cellElement != hostNode) { |
michael@0 | 385 | if (mInlineEditedCell) |
michael@0 | 386 | res = RefreshInlineTableEditingUI(); |
michael@0 | 387 | else |
michael@0 | 388 | res = ShowInlineTableEditingUI(cellElement); |
michael@0 | 389 | } |
michael@0 | 390 | |
michael@0 | 391 | return res; |
michael@0 | 392 | } |
michael@0 | 393 | |
michael@0 | 394 | // Resizing and Absolute Positioning need to know everything about the |
michael@0 | 395 | // containing box of the element: position, size, margins, borders |
michael@0 | 396 | nsresult |
michael@0 | 397 | nsHTMLEditor::GetPositionAndDimensions(nsIDOMElement * aElement, |
michael@0 | 398 | int32_t & aX, int32_t & aY, |
michael@0 | 399 | int32_t & aW, int32_t & aH, |
michael@0 | 400 | int32_t & aBorderLeft, |
michael@0 | 401 | int32_t & aBorderTop, |
michael@0 | 402 | int32_t & aMarginLeft, |
michael@0 | 403 | int32_t & aMarginTop) |
michael@0 | 404 | { |
michael@0 | 405 | NS_ENSURE_ARG_POINTER(aElement); |
michael@0 | 406 | |
michael@0 | 407 | // Is the element positioned ? let's check the cheap way first... |
michael@0 | 408 | bool isPositioned = false; |
michael@0 | 409 | nsresult res = aElement->HasAttribute(NS_LITERAL_STRING("_moz_abspos"), &isPositioned); |
michael@0 | 410 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 411 | if (!isPositioned) { |
michael@0 | 412 | // hmmm... the expensive way now... |
michael@0 | 413 | nsAutoString positionStr; |
michael@0 | 414 | mHTMLCSSUtils->GetComputedProperty(aElement, nsEditProperty::cssPosition, |
michael@0 | 415 | positionStr); |
michael@0 | 416 | isPositioned = positionStr.EqualsLiteral("absolute"); |
michael@0 | 417 | } |
michael@0 | 418 | |
michael@0 | 419 | if (isPositioned) { |
michael@0 | 420 | // Yes, it is absolutely positioned |
michael@0 | 421 | mResizedObjectIsAbsolutelyPositioned = true; |
michael@0 | 422 | |
michael@0 | 423 | // Get the all the computed css styles attached to the element node |
michael@0 | 424 | nsRefPtr<nsComputedDOMStyle> cssDecl = |
michael@0 | 425 | mHTMLCSSUtils->GetComputedStyle(aElement); |
michael@0 | 426 | NS_ENSURE_STATE(cssDecl); |
michael@0 | 427 | |
michael@0 | 428 | aBorderLeft = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-left-width")); |
michael@0 | 429 | aBorderTop = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-top-width")); |
michael@0 | 430 | aMarginLeft = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("margin-left")); |
michael@0 | 431 | aMarginTop = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("margin-top")); |
michael@0 | 432 | |
michael@0 | 433 | aX = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("left")) + |
michael@0 | 434 | aMarginLeft + aBorderLeft; |
michael@0 | 435 | aY = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("top")) + |
michael@0 | 436 | aMarginTop + aBorderTop; |
michael@0 | 437 | aW = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("width")); |
michael@0 | 438 | aH = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("height")); |
michael@0 | 439 | } |
michael@0 | 440 | else { |
michael@0 | 441 | mResizedObjectIsAbsolutelyPositioned = false; |
michael@0 | 442 | nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(aElement); |
michael@0 | 443 | if (!htmlElement) { |
michael@0 | 444 | return NS_ERROR_NULL_POINTER; |
michael@0 | 445 | } |
michael@0 | 446 | GetElementOrigin(aElement, aX, aY); |
michael@0 | 447 | |
michael@0 | 448 | res = htmlElement->GetOffsetWidth(&aW); |
michael@0 | 449 | NS_ENSURE_SUCCESS(res, res); |
michael@0 | 450 | res = htmlElement->GetOffsetHeight(&aH); |
michael@0 | 451 | |
michael@0 | 452 | aBorderLeft = 0; |
michael@0 | 453 | aBorderTop = 0; |
michael@0 | 454 | aMarginLeft = 0; |
michael@0 | 455 | aMarginTop = 0; |
michael@0 | 456 | } |
michael@0 | 457 | return res; |
michael@0 | 458 | } |
michael@0 | 459 | |
michael@0 | 460 | // self-explanatory |
michael@0 | 461 | void |
michael@0 | 462 | nsHTMLEditor::SetAnonymousElementPosition(int32_t aX, int32_t aY, nsIDOMElement *aElement) |
michael@0 | 463 | { |
michael@0 | 464 | mHTMLCSSUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("left"), aX); |
michael@0 | 465 | mHTMLCSSUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("top"), aY); |
michael@0 | 466 | } |