content/base/src/nsGenConImageContent.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /**
michael@0 7 * A fake content node class so that the image frame for
michael@0 8 * content: url(foo);
michael@0 9 * in CSS can have an nsIImageLoadingContent but use an
michael@0 10 * imgIRequest that's already been loaded from the style system.
michael@0 11 */
michael@0 12
michael@0 13 #include "nsContentCreatorFunctions.h"
michael@0 14 #include "nsXMLElement.h"
michael@0 15 #include "nsImageLoadingContent.h"
michael@0 16 #include "imgIRequest.h"
michael@0 17 #include "mozilla/BasicEvents.h"
michael@0 18 #include "mozilla/EventDispatcher.h"
michael@0 19 #include "mozilla/EventStates.h"
michael@0 20
michael@0 21 using namespace mozilla;
michael@0 22
michael@0 23 class nsGenConImageContent MOZ_FINAL : public nsXMLElement,
michael@0 24 public nsImageLoadingContent
michael@0 25 {
michael@0 26 public:
michael@0 27 nsGenConImageContent(already_AddRefed<nsINodeInfo>& aNodeInfo)
michael@0 28 : nsXMLElement(aNodeInfo)
michael@0 29 {
michael@0 30 // nsImageLoadingContent starts out broken, so we start out
michael@0 31 // suppressed to match it.
michael@0 32 AddStatesSilently(NS_EVENT_STATE_SUPPRESSED);
michael@0 33 }
michael@0 34
michael@0 35 nsresult Init(imgRequestProxy* aImageRequest)
michael@0 36 {
michael@0 37 // No need to notify, since we have no frame.
michael@0 38 return UseAsPrimaryRequest(aImageRequest, false);
michael@0 39 }
michael@0 40
michael@0 41 // nsIContent overrides
michael@0 42 virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
michael@0 43 nsIContent* aBindingParent,
michael@0 44 bool aCompileEventHandlers);
michael@0 45 virtual void UnbindFromTree(bool aDeep, bool aNullParent);
michael@0 46 virtual EventStates IntrinsicState() const;
michael@0 47
michael@0 48 virtual nsresult PreHandleEvent(EventChainPreVisitor& aVisitor)
michael@0 49 {
michael@0 50 MOZ_ASSERT(IsInNativeAnonymousSubtree());
michael@0 51 if (aVisitor.mEvent->message == NS_LOAD ||
michael@0 52 aVisitor.mEvent->message == NS_LOAD_ERROR) {
michael@0 53 // Don't propagate the events to the parent.
michael@0 54 return NS_OK;
michael@0 55 }
michael@0 56 return nsXMLElement::PreHandleEvent(aVisitor);
michael@0 57 }
michael@0 58
michael@0 59 private:
michael@0 60 virtual ~nsGenConImageContent();
michael@0 61
michael@0 62 public:
michael@0 63 NS_DECL_ISUPPORTS_INHERITED
michael@0 64 };
michael@0 65
michael@0 66 NS_IMPL_ISUPPORTS_INHERITED(nsGenConImageContent,
michael@0 67 nsXMLElement,
michael@0 68 nsIImageLoadingContent,
michael@0 69 imgINotificationObserver,
michael@0 70 imgIOnloadBlocker)
michael@0 71
michael@0 72 nsresult
michael@0 73 NS_NewGenConImageContent(nsIContent** aResult, already_AddRefed<nsINodeInfo>&& aNodeInfo,
michael@0 74 imgRequestProxy* aImageRequest)
michael@0 75 {
michael@0 76 NS_PRECONDITION(aImageRequest, "Must have request!");
michael@0 77 nsGenConImageContent *it = new nsGenConImageContent(aNodeInfo);
michael@0 78 if (!it)
michael@0 79 return NS_ERROR_OUT_OF_MEMORY;
michael@0 80 NS_ADDREF(*aResult = it);
michael@0 81 nsresult rv = it->Init(aImageRequest);
michael@0 82 if (NS_FAILED(rv))
michael@0 83 NS_RELEASE(*aResult);
michael@0 84 return rv;
michael@0 85 }
michael@0 86
michael@0 87 nsGenConImageContent::~nsGenConImageContent()
michael@0 88 {
michael@0 89 DestroyImageLoadingContent();
michael@0 90 }
michael@0 91
michael@0 92 nsresult
michael@0 93 nsGenConImageContent::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
michael@0 94 nsIContent* aBindingParent,
michael@0 95 bool aCompileEventHandlers)
michael@0 96 {
michael@0 97 nsresult rv;
michael@0 98 rv = nsXMLElement::BindToTree(aDocument, aParent, aBindingParent,
michael@0 99 aCompileEventHandlers);
michael@0 100 NS_ENSURE_SUCCESS(rv, rv);
michael@0 101
michael@0 102 nsImageLoadingContent::BindToTree(aDocument, aParent, aBindingParent,
michael@0 103 aCompileEventHandlers);
michael@0 104 return NS_OK;
michael@0 105 }
michael@0 106
michael@0 107 void
michael@0 108 nsGenConImageContent::UnbindFromTree(bool aDeep, bool aNullParent)
michael@0 109 {
michael@0 110 nsImageLoadingContent::UnbindFromTree(aDeep, aNullParent);
michael@0 111 nsXMLElement::UnbindFromTree(aDeep, aNullParent);
michael@0 112 }
michael@0 113
michael@0 114 EventStates
michael@0 115 nsGenConImageContent::IntrinsicState() const
michael@0 116 {
michael@0 117 EventStates state = nsXMLElement::IntrinsicState();
michael@0 118
michael@0 119 EventStates imageState = nsImageLoadingContent::ImageState();
michael@0 120 if (imageState.HasAtLeastOneOfStates(NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED)) {
michael@0 121 // We should never be in an error state; if the image fails to load, we
michael@0 122 // just go to the suppressed state.
michael@0 123 imageState |= NS_EVENT_STATE_SUPPRESSED;
michael@0 124 imageState &= ~NS_EVENT_STATE_BROKEN;
michael@0 125 }
michael@0 126 imageState &= ~NS_EVENT_STATE_LOADING;
michael@0 127 return state | imageState;
michael@0 128 }

mercurial