Bug 1700051: part 28) Refactor `WordSplitState<T>::GetDOMWordSeparatorOffset` to...
[gecko.git] / widget / cocoa / nsSound.mm
blobfb979f6f375e74c7d2ac4c639c424d331c227580
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  *
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsSound.h"
8 #include "nsContentUtils.h"
9 #include "nsObjCExceptions.h"
10 #include "nsNetUtil.h"
11 #include "nsCOMPtr.h"
12 #include "nsIURL.h"
13 #include "nsString.h"
15 #import <Cocoa/Cocoa.h>
17 NS_IMPL_ISUPPORTS(nsSound, nsISound, nsIStreamLoaderObserver)
19 nsSound::nsSound() {}
21 nsSound::~nsSound() {}
23 NS_IMETHODIMP
24 nsSound::Beep() {
25   NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
27   NSBeep();
28   return NS_OK;
30   NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
33 NS_IMETHODIMP
34 nsSound::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* context, nsresult aStatus,
35                           uint32_t dataLen, const uint8_t* data) {
36   NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
38   NSData* value = [NSData dataWithBytes:data length:dataLen];
40   NSSound* sound = [[NSSound alloc] initWithData:value];
42   [sound play];
44   [sound autorelease];
46   return NS_OK;
48   NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
51 NS_IMETHODIMP
52 nsSound::Play(nsIURL* aURL) {
53   nsCOMPtr<nsIURI> uri(aURL);
54   nsCOMPtr<nsIStreamLoader> loader;
55   return NS_NewStreamLoader(getter_AddRefs(loader), uri,
56                             this,  // aObserver
57                             nsContentUtils::GetSystemPrincipal(),
58                             nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
59                             nsIContentPolicy::TYPE_OTHER);
62 NS_IMETHODIMP
63 nsSound::Init() { return NS_OK; }
65 NS_IMETHODIMP
66 nsSound::PlayEventSound(uint32_t aEventId) {
67   // Mac doesn't have system sound settings for each user actions.
68   return NS_OK;