dom/events/ClipboardEvent.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.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 #include "mozilla/dom/ClipboardEvent.h"
michael@0 7 #include "mozilla/ContentEvents.h"
michael@0 8 #include "mozilla/dom/DataTransfer.h"
michael@0 9 #include "nsIClipboard.h"
michael@0 10
michael@0 11 namespace mozilla {
michael@0 12 namespace dom {
michael@0 13
michael@0 14 ClipboardEvent::ClipboardEvent(EventTarget* aOwner,
michael@0 15 nsPresContext* aPresContext,
michael@0 16 InternalClipboardEvent* aEvent)
michael@0 17 : Event(aOwner, aPresContext,
michael@0 18 aEvent ? aEvent : new InternalClipboardEvent(false, 0))
michael@0 19 {
michael@0 20 if (aEvent) {
michael@0 21 mEventIsInternal = false;
michael@0 22 } else {
michael@0 23 mEventIsInternal = true;
michael@0 24 mEvent->time = PR_Now();
michael@0 25 }
michael@0 26 }
michael@0 27
michael@0 28 NS_INTERFACE_MAP_BEGIN(ClipboardEvent)
michael@0 29 NS_INTERFACE_MAP_ENTRY(nsIDOMClipboardEvent)
michael@0 30 NS_INTERFACE_MAP_END_INHERITING(Event)
michael@0 31
michael@0 32 NS_IMPL_ADDREF_INHERITED(ClipboardEvent, Event)
michael@0 33 NS_IMPL_RELEASE_INHERITED(ClipboardEvent, Event)
michael@0 34
michael@0 35 nsresult
michael@0 36 ClipboardEvent::InitClipboardEvent(const nsAString& aType,
michael@0 37 bool aCanBubble,
michael@0 38 bool aCancelable,
michael@0 39 nsIDOMDataTransfer* aClipboardData)
michael@0 40 {
michael@0 41 nsCOMPtr<DataTransfer> clipboardData = do_QueryInterface(aClipboardData);
michael@0 42 // Null clipboardData is OK
michael@0 43
michael@0 44 ErrorResult rv;
michael@0 45 InitClipboardEvent(aType, aCanBubble, aCancelable, clipboardData, rv);
michael@0 46
michael@0 47 return rv.ErrorCode();
michael@0 48 }
michael@0 49
michael@0 50 void
michael@0 51 ClipboardEvent::InitClipboardEvent(const nsAString& aType, bool aCanBubble,
michael@0 52 bool aCancelable,
michael@0 53 DataTransfer* aClipboardData,
michael@0 54 ErrorResult& aError)
michael@0 55 {
michael@0 56 aError = Event::InitEvent(aType, aCanBubble, aCancelable);
michael@0 57 if (aError.Failed()) {
michael@0 58 return;
michael@0 59 }
michael@0 60
michael@0 61 mEvent->AsClipboardEvent()->clipboardData = aClipboardData;
michael@0 62 }
michael@0 63
michael@0 64 already_AddRefed<ClipboardEvent>
michael@0 65 ClipboardEvent::Constructor(const GlobalObject& aGlobal,
michael@0 66 const nsAString& aType,
michael@0 67 const ClipboardEventInit& aParam,
michael@0 68 ErrorResult& aRv)
michael@0 69 {
michael@0 70 nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
michael@0 71 nsRefPtr<ClipboardEvent> e = new ClipboardEvent(t, nullptr, nullptr);
michael@0 72 bool trusted = e->Init(t);
michael@0 73
michael@0 74 nsRefPtr<DataTransfer> clipboardData;
michael@0 75 if (e->mEventIsInternal) {
michael@0 76 InternalClipboardEvent* event = e->mEvent->AsClipboardEvent();
michael@0 77 if (event) {
michael@0 78 // Always create a clipboardData for the copy event. If this is changed to
michael@0 79 // support other types of events, make sure that read/write privileges are
michael@0 80 // checked properly within DataTransfer.
michael@0 81 clipboardData = new DataTransfer(ToSupports(e), NS_COPY, false, -1);
michael@0 82 clipboardData->SetData(aParam.mDataType, aParam.mData);
michael@0 83 }
michael@0 84 }
michael@0 85
michael@0 86 e->InitClipboardEvent(aType, aParam.mBubbles, aParam.mCancelable,
michael@0 87 clipboardData, aRv);
michael@0 88 e->SetTrusted(trusted);
michael@0 89 return e.forget();
michael@0 90 }
michael@0 91
michael@0 92 NS_IMETHODIMP
michael@0 93 ClipboardEvent::GetClipboardData(nsIDOMDataTransfer** aClipboardData)
michael@0 94 {
michael@0 95 NS_IF_ADDREF(*aClipboardData = GetClipboardData());
michael@0 96 return NS_OK;
michael@0 97 }
michael@0 98
michael@0 99 DataTransfer*
michael@0 100 ClipboardEvent::GetClipboardData()
michael@0 101 {
michael@0 102 InternalClipboardEvent* event = mEvent->AsClipboardEvent();
michael@0 103
michael@0 104 if (!event->clipboardData) {
michael@0 105 if (mEventIsInternal) {
michael@0 106 event->clipboardData =
michael@0 107 new DataTransfer(ToSupports(this), NS_COPY, false, -1);
michael@0 108 } else {
michael@0 109 event->clipboardData =
michael@0 110 new DataTransfer(ToSupports(this), event->message,
michael@0 111 event->message == NS_PASTE,
michael@0 112 nsIClipboard::kGlobalClipboard);
michael@0 113 }
michael@0 114 }
michael@0 115
michael@0 116 return event->clipboardData;
michael@0 117 }
michael@0 118
michael@0 119 } // namespace dom
michael@0 120 } // namespace mozilla
michael@0 121
michael@0 122 using namespace mozilla;
michael@0 123 using namespace mozilla::dom;
michael@0 124
michael@0 125 nsresult
michael@0 126 NS_NewDOMClipboardEvent(nsIDOMEvent** aInstancePtrResult,
michael@0 127 EventTarget* aOwner,
michael@0 128 nsPresContext* aPresContext,
michael@0 129 InternalClipboardEvent* aEvent)
michael@0 130 {
michael@0 131 ClipboardEvent* it = new ClipboardEvent(aOwner, aPresContext, aEvent);
michael@0 132 NS_ADDREF(it);
michael@0 133 *aInstancePtrResult = static_cast<Event*>(it);
michael@0 134 return NS_OK;
michael@0 135 }

mercurial