Thu, 15 Jan 2015 21:03:48 +0100
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 | /* -*- 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 "nsAutoWindowStateHelper.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/dom/Event.h" |
michael@0 | 9 | #include "nsIDocument.h" |
michael@0 | 10 | #include "nsIDOMEvent.h" |
michael@0 | 11 | #include "nsIDOMWindow.h" |
michael@0 | 12 | #include "nsPIDOMWindow.h" |
michael@0 | 13 | #include "nsString.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla; |
michael@0 | 16 | using namespace mozilla::dom; |
michael@0 | 17 | |
michael@0 | 18 | /**************************************************************** |
michael@0 | 19 | ****************** nsAutoWindowStateHelper ********************* |
michael@0 | 20 | ****************************************************************/ |
michael@0 | 21 | |
michael@0 | 22 | nsAutoWindowStateHelper::nsAutoWindowStateHelper(nsPIDOMWindow *aWindow) |
michael@0 | 23 | : mWindow(aWindow), |
michael@0 | 24 | mDefaultEnabled(DispatchEventToChrome("DOMWillOpenModalDialog")) |
michael@0 | 25 | { |
michael@0 | 26 | if (mWindow) { |
michael@0 | 27 | mWindow->EnterModalState(); |
michael@0 | 28 | } |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | nsAutoWindowStateHelper::~nsAutoWindowStateHelper() |
michael@0 | 32 | { |
michael@0 | 33 | if (mWindow) { |
michael@0 | 34 | mWindow->LeaveModalState(); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | if (mDefaultEnabled) { |
michael@0 | 38 | DispatchEventToChrome("DOMModalDialogClosed"); |
michael@0 | 39 | } |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | bool |
michael@0 | 43 | nsAutoWindowStateHelper::DispatchEventToChrome(const char *aEventName) |
michael@0 | 44 | { |
michael@0 | 45 | // XXXbz should we skip dispatching the event if the inner changed? |
michael@0 | 46 | // That is, should we store both the inner and the outer? |
michael@0 | 47 | if (!mWindow) { |
michael@0 | 48 | return true; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | // The functions of nsContentUtils do not provide the required behavior, |
michael@0 | 52 | // so the following is inlined. |
michael@0 | 53 | nsIDocument* doc = mWindow->GetExtantDoc(); |
michael@0 | 54 | if (!doc) { |
michael@0 | 55 | return true; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | ErrorResult rv; |
michael@0 | 59 | nsRefPtr<Event> event = doc->CreateEvent(NS_LITERAL_STRING("Events"), rv); |
michael@0 | 60 | if (rv.Failed()) { |
michael@0 | 61 | return false; |
michael@0 | 62 | } |
michael@0 | 63 | NS_ENSURE_TRUE(NS_SUCCEEDED(event->InitEvent(NS_ConvertASCIItoUTF16(aEventName), true, true)), false); |
michael@0 | 64 | event->SetTrusted(true); |
michael@0 | 65 | event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; |
michael@0 | 66 | |
michael@0 | 67 | nsCOMPtr<EventTarget> target = do_QueryInterface(mWindow); |
michael@0 | 68 | bool defaultActionEnabled; |
michael@0 | 69 | target->DispatchEvent(event, &defaultActionEnabled); |
michael@0 | 70 | return defaultActionEnabled; |
michael@0 | 71 | } |