IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / theme_helper_mac.mm
blob3b952cc79b8e48d39e86bb6e6ce6b72d474d8001
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/theme_helper_mac.h"
7 #include <Foundation/Foundation.h>
9 #include "content/common/view_messages.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/render_process_host.h"
15 @interface ScrollbarPrefsObserver : NSObject
17 + (void)registerAsObserver;
18 + (void)appearancePrefsChanged:(NSNotification*)notification;
19 + (void)behaviorPrefsChanged:(NSNotification*)notification;
20 + (void)notifyPrefsChangedWithRedraw:(BOOL)redraw;
22 @end
24 @implementation ScrollbarPrefsObserver
26 + (void)registerAsObserver {
27   [[NSDistributedNotificationCenter defaultCenter]
28       addObserver:self
29          selector:@selector(appearancePrefsChanged:)
30              name:@"AppleAquaScrollBarVariantChanged"
31            object:nil
32 suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
34   [[NSDistributedNotificationCenter defaultCenter]
35       addObserver:self
36          selector:@selector(behaviorPrefsChanged:)
37              name:@"AppleNoRedisplayAppearancePreferenceChanged"
38            object:nil
39 suspensionBehavior:NSNotificationSuspensionBehaviorCoalesce];
42 + (void)appearancePrefsChanged:(NSNotification*)notification {
43   [self notifyPrefsChangedWithRedraw:YES];
46 + (void)behaviorPrefsChanged:(NSNotification*)notification {
47   [self notifyPrefsChangedWithRedraw:NO];
50 + (void)notifyPrefsChangedWithRedraw:(BOOL)redraw {
51   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
52   NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
53   [defaults synchronize];
55   content::ThemeHelperMac::SendThemeChangeToAllRenderers(
56       [defaults floatForKey:@"NSScrollerButtonDelay"],
57       [defaults floatForKey:@"NSScrollerButtonPeriod"],
58       [defaults boolForKey:@"AppleScrollerPagingBehavior"],
59       redraw);
62 @end
64 namespace content {
66 ThemeHelperMac::ThemeHelperMac() {
67   [ScrollbarPrefsObserver registerAsObserver];
68   registrar_.Add(this,
69                  NOTIFICATION_RENDERER_PROCESS_CREATED,
70                  NotificationService::AllSources());
73 ThemeHelperMac::~ThemeHelperMac() {
76 // static
77 ThemeHelperMac* ThemeHelperMac::GetInstance() {
78   return Singleton<ThemeHelperMac,
79       LeakySingletonTraits<ThemeHelperMac> >::get();
83 void ThemeHelperMac::Observe(int type,
84                              const NotificationSource& source,
85                              const NotificationDetails& details) {
86   DCHECK_EQ(NOTIFICATION_RENDERER_PROCESS_CREATED, type);
88   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
89   NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
90   [defaults synchronize];
92   RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr();
93   rph->Send(new ViewMsg_UpdateScrollbarTheme(
94       [defaults floatForKey:@"NSScrollerButtonDelay"],
95       [defaults floatForKey:@"NSScrollerButtonPeriod"],
96       [defaults boolForKey:@"AppleScrollerPagingBehavior"],
97       false));
100 // static
101 void ThemeHelperMac::SendThemeChangeToAllRenderers(
102     float initial_button_delay,
103     float autoscroll_button_delay,
104     bool jump_on_track_click,
105     bool redraw) {
106   for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
107        !it.IsAtEnd();
108        it.Advance()) {
109     it.GetCurrentValue()->Send(new ViewMsg_UpdateScrollbarTheme(
110         initial_button_delay,
111         autoscroll_button_delay,
112         jump_on_track_click,
113         redraw));
114   }
117 }  // namespace content