OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/mac/mac_util.h" | 5 #include "base/mac/mac_util.h" |
| 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" |
| 8 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
6 #include "chrome/browser/ui/panels/display_settings_provider.h" | 9 #include "chrome/browser/ui/panels/display_settings_provider.h" |
7 #include "ui/base/work_area_watcher_observer.h" | |
8 #import "chrome/browser/app_controller_mac.h" | 10 #import "chrome/browser/app_controller_mac.h" |
9 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
10 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
11 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
12 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
13 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 16 #include "ui/base/work_area_watcher_observer.h" |
14 | 17 |
15 namespace { | 18 namespace { |
16 | 19 |
| 20 enum ChromeFullScreenState { |
| 21 FULLSCREEN_UNKNOWN, |
| 22 FULLSCREEN_ON, |
| 23 FULLSCREEN_OFF |
| 24 }; |
| 25 |
17 class DisplaySettingsProviderCocoa : public DisplaySettingsProvider, | 26 class DisplaySettingsProviderCocoa : public DisplaySettingsProvider, |
18 public ui::WorkAreaWatcherObserver, | 27 public ui::WorkAreaWatcherObserver, |
19 public content::NotificationObserver { | 28 public content::NotificationObserver { |
20 public: | 29 public: |
21 DisplaySettingsProviderCocoa(); | 30 DisplaySettingsProviderCocoa(); |
22 virtual ~DisplaySettingsProviderCocoa(); | 31 virtual ~DisplaySettingsProviderCocoa(); |
23 | 32 |
24 protected: | 33 protected: |
25 // Overridden from DisplaySettingsProvider: | 34 // Overridden from DisplaySettingsProvider: |
26 virtual bool NeedsPeriodicFullScreenCheck() const OVERRIDE; | 35 virtual bool NeedsPeriodicFullScreenCheck() const OVERRIDE; |
27 virtual bool IsFullScreen() const OVERRIDE; | 36 virtual bool IsFullScreen() OVERRIDE; |
28 | 37 |
29 // Overridden from ui::WorkAreaWatcherObserver: | 38 // Overridden from ui::WorkAreaWatcherObserver: |
30 virtual void WorkAreaChanged() OVERRIDE; | 39 virtual void WorkAreaChanged() OVERRIDE; |
31 | 40 |
32 // Overridden from content::NotificationObserver: | 41 // Overridden from content::NotificationObserver: |
33 virtual void Observe(int type, | 42 virtual void Observe(int type, |
34 const content::NotificationSource& source, | 43 const content::NotificationSource& source, |
35 const content::NotificationDetails& details) OVERRIDE; | 44 const content::NotificationDetails& details) OVERRIDE; |
36 | 45 |
37 private: | 46 private: |
38 content::NotificationRegistrar registrar_; | 47 content::NotificationRegistrar registrar_; |
39 bool is_chrome_fullscreen_; | 48 ChromeFullScreenState chrome_fullscreen_state_; |
40 | 49 |
41 DISALLOW_COPY_AND_ASSIGN(DisplaySettingsProviderCocoa); | 50 DISALLOW_COPY_AND_ASSIGN(DisplaySettingsProviderCocoa); |
42 }; | 51 }; |
43 | 52 |
44 DisplaySettingsProviderCocoa::DisplaySettingsProviderCocoa() | 53 DisplaySettingsProviderCocoa::DisplaySettingsProviderCocoa() |
45 // Ideally we should initialize the value below with current state. However, | 54 // Ideally we should initialize the value below with current state. However, |
46 // there is not a centralized place we can pull the state from and we need | 55 // there is not a centralized place we can pull the state from and we need |
47 // to query all chrome browser windows to find it out. | 56 // to query all chrome browser windows to find it out. |
48 // This will get automatically fixed when DisplaySettingsProvider is changed | 57 // This will get automatically fixed when DisplaySettingsProvider is changed |
49 // to be initialized before any chrome window is created with planning | 58 // to be initialized before any chrome window is created with planning |
50 // refactor effort to move it out of panel scope. | 59 // refactor effort to move it out of panel scope. |
51 : is_chrome_fullscreen_(false) { | 60 : chrome_fullscreen_state_(FULLSCREEN_UNKNOWN) { |
52 AppController* appController = static_cast<AppController*>([NSApp delegate]); | 61 AppController* appController = static_cast<AppController*>([NSApp delegate]); |
53 [appController addObserverForWorkAreaChange:this]; | 62 [appController addObserverForWorkAreaChange:this]; |
54 | 63 |
55 registrar_.Add( | 64 registrar_.Add( |
56 this, | 65 this, |
57 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 66 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
58 content::NotificationService::AllSources()); | 67 content::NotificationService::AllSources()); |
59 } | 68 } |
60 | 69 |
61 DisplaySettingsProviderCocoa::~DisplaySettingsProviderCocoa() { | 70 DisplaySettingsProviderCocoa::~DisplaySettingsProviderCocoa() { |
62 AppController* appController = static_cast<AppController*>([NSApp delegate]); | 71 AppController* appController = static_cast<AppController*>([NSApp delegate]); |
63 [appController removeObserverForWorkAreaChange:this]; | 72 [appController removeObserverForWorkAreaChange:this]; |
64 } | 73 } |
65 | 74 |
66 bool DisplaySettingsProviderCocoa::NeedsPeriodicFullScreenCheck() const { | 75 bool DisplaySettingsProviderCocoa::NeedsPeriodicFullScreenCheck() const { |
67 // Lion system introduces fullscreen support. When a window of an application | 76 // Lion system introduces fullscreen support. When a window of an application |
68 // enters fullscreen mode, the system will automatically hide all other | 77 // enters fullscreen mode, the system will automatically hide all other |
69 // windows, even including topmost windows that come from other applications. | 78 // windows, even including topmost windows that come from other applications. |
70 // So we don't need to do anything when any other application enters | 79 // So we don't need to do anything when any other application enters |
71 // fullscreen mode. We still need to handle the case when chrome enters | 80 // fullscreen mode. We still need to handle the case when chrome enters |
72 // fullscreen mode and our topmost windows will not get hided by the system. | 81 // fullscreen mode and our topmost windows will not get hided by the system. |
73 return !base::mac::IsOSLionOrLater(); | 82 return !base::mac::IsOSLionOrLater(); |
74 } | 83 } |
75 | 84 |
76 bool DisplaySettingsProviderCocoa::IsFullScreen() const { | 85 bool DisplaySettingsProviderCocoa::IsFullScreen() { |
77 // For Lion and later, we only need to check if chrome enters fullscreen mode | 86 // For Lion and later, we only need to check if chrome enters fullscreen mode |
78 // (see detailed reason above in NeedsPeriodicFullScreenCheck). | 87 // (see detailed reason above in NeedsPeriodicFullScreenCheck). |
79 return base::mac::IsOSLionOrLater() ? is_chrome_fullscreen_ : | 88 if (!base::mac::IsOSLionOrLater()) |
80 DisplaySettingsProvider::IsFullScreen(); | 89 return DisplaySettingsProvider::IsFullScreen(); |
| 90 |
| 91 if (chrome_fullscreen_state_ == FULLSCREEN_UNKNOWN) { |
| 92 Browser* browser = chrome::GetLastActiveBrowser(); |
| 93 chrome_fullscreen_state_ = |
| 94 browser && browser->fullscreen_controller()->IsFullscreenForBrowser() ? |
| 95 FULLSCREEN_ON : FULLSCREEN_OFF; |
| 96 } |
| 97 |
| 98 return chrome_fullscreen_state_ == FULLSCREEN_ON; |
81 } | 99 } |
82 | 100 |
83 void DisplaySettingsProviderCocoa::WorkAreaChanged() { | 101 void DisplaySettingsProviderCocoa::WorkAreaChanged() { |
84 OnDisplaySettingsChanged(); | 102 OnDisplaySettingsChanged(); |
85 } | 103 } |
86 | 104 |
87 void DisplaySettingsProviderCocoa::Observe( | 105 void DisplaySettingsProviderCocoa::Observe( |
88 int type, | 106 int type, |
89 const content::NotificationSource& source, | 107 const content::NotificationSource& source, |
90 const content::NotificationDetails& details) { | 108 const content::NotificationDetails& details) { |
91 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 109 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
92 is_chrome_fullscreen_ = *(content::Details<bool>(details)).ptr(); | 110 chrome_fullscreen_state_ = *(content::Details<bool>(details)).ptr() ? |
| 111 FULLSCREEN_ON : FULLSCREEN_OFF; |
93 CheckFullScreenMode(); | 112 CheckFullScreenMode(); |
94 } | 113 } |
95 | 114 |
96 } // namespace | 115 } // namespace |
97 | 116 |
98 // static | 117 // static |
99 DisplaySettingsProvider* DisplaySettingsProvider::Create() { | 118 DisplaySettingsProvider* DisplaySettingsProvider::Create() { |
100 return new DisplaySettingsProviderCocoa(); | 119 return new DisplaySettingsProviderCocoa(); |
101 } | 120 } |
OLD | NEW |