Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | c4e78d7 | 2012-03-24 22:55:41 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 5 | #include "content/shell/browser/shell_application_mac.h" |
[email protected] | c4e78d7 | 2012-03-24 22:55:41 | [diff] [blame] | 6 | |
[email protected] | a670807 | 2012-03-27 14:10:45 | [diff] [blame] | 7 | #include "base/auto_reset.h" |
erikchen | 7d5f0ee | 2018-08-02 22:15:40 | [diff] [blame] | 8 | #include "base/observer_list.h" |
9 | #include "content/public/browser/native_event_processor_mac.h" | ||||
10 | #include "content/public/browser/native_event_processor_observer_mac.h" | ||||
[email protected] | 685c8af | 2013-08-06 03:10:15 | [diff] [blame] | 11 | #include "content/public/common/url_constants.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 12 | #include "content/shell/browser/shell.h" |
13 | #include "content/shell/browser/shell_browser_context.h" | ||||
14 | #include "content/shell/browser/shell_content_browser_client.h" | ||||
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 15 | #include "url/gurl.h" |
[email protected] | a670807 | 2012-03-27 14:10:45 | [diff] [blame] | 16 | |
Avi Drissman | 49e8c2b3 | 2023-04-25 20:52:13 | [diff] [blame] | 17 | @interface ShellCrApplication () <NativeEventProcessor> |
erikchen | 7d5f0ee | 2018-08-02 22:15:40 | [diff] [blame] | 18 | @end |
19 | |||||
Avi Drissman | 49e8c2b3 | 2023-04-25 20:52:13 | [diff] [blame] | 20 | @implementation ShellCrApplication { |
21 | base::ObserverList<content::NativeEventProcessorObserver>::Unchecked | ||||
22 | _observers; | ||||
23 | |||||
24 | BOOL _handlingSendEvent; | ||||
25 | } | ||||
[email protected] | c4e78d7 | 2012-03-24 22:55:41 | [diff] [blame] | 26 | |
27 | - (BOOL)isHandlingSendEvent { | ||||
Robert Liao | b641dca | 2019-12-11 16:31:39 | [diff] [blame] | 28 | return _handlingSendEvent; |
[email protected] | c4e78d7 | 2012-03-24 22:55:41 | [diff] [blame] | 29 | } |
30 | |||||
31 | - (void)sendEvent:(NSEvent*)event { | ||||
Robert Liao | b641dca | 2019-12-11 16:31:39 | [diff] [blame] | 32 | base::AutoReset<BOOL> scoper(&_handlingSendEvent, YES); |
erikchen | 7d5f0ee | 2018-08-02 22:15:40 | [diff] [blame] | 33 | |
34 | content::ScopedNotifyNativeEventProcessorObserver scopedObserverNotifier( | ||||
Robert Liao | b641dca | 2019-12-11 16:31:39 | [diff] [blame] | 35 | &_observers, event); |
[email protected] | c4e78d7 | 2012-03-24 22:55:41 | [diff] [blame] | 36 | [super sendEvent:event]; |
[email protected] | c4e78d7 | 2012-03-24 22:55:41 | [diff] [blame] | 37 | } |
38 | |||||
39 | - (void)setHandlingSendEvent:(BOOL)handlingSendEvent { | ||||
Robert Liao | b641dca | 2019-12-11 16:31:39 | [diff] [blame] | 40 | _handlingSendEvent = handlingSendEvent; |
[email protected] | c4e78d7 | 2012-03-24 22:55:41 | [diff] [blame] | 41 | } |
42 | |||||
[email protected] | f3474bb5 | 2012-04-02 16:32:36 | [diff] [blame] | 43 | - (IBAction)newDocument:(id)sender { |
[email protected] | 3560b57 | 2012-04-04 20:47:32 | [diff] [blame] | 44 | content::ShellBrowserContext* browserContext = |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 45 | content::ShellContentBrowserClient::Get()->browser_context(); |
kylechar | de57aa35 | 2019-10-31 02:24:29 | [diff] [blame] | 46 | content::Shell::CreateNewWindow(browserContext, GURL(url::kAboutBlankURL), |
47 | nullptr, gfx::Size()); | ||||
[email protected] | f3474bb5 | 2012-04-02 16:32:36 | [diff] [blame] | 48 | } |
49 | |||||
erikchen | 7d5f0ee | 2018-08-02 22:15:40 | [diff] [blame] | 50 | - (void)addNativeEventProcessorObserver: |
51 | (content::NativeEventProcessorObserver*)observer { | ||||
Robert Liao | b641dca | 2019-12-11 16:31:39 | [diff] [blame] | 52 | _observers.AddObserver(observer); |
erikchen | 7d5f0ee | 2018-08-02 22:15:40 | [diff] [blame] | 53 | } |
54 | |||||
55 | - (void)removeNativeEventProcessorObserver: | ||||
56 | (content::NativeEventProcessorObserver*)observer { | ||||
Robert Liao | b641dca | 2019-12-11 16:31:39 | [diff] [blame] | 57 | _observers.RemoveObserver(observer); |
erikchen | 7d5f0ee | 2018-08-02 22:15:40 | [diff] [blame] | 58 | } |
59 | |||||
[email protected] | c4e78d7 | 2012-03-24 22:55:41 | [diff] [blame] | 60 | @end |