content/base/src/nsGenConImageContent.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial