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;
24 @implementation ScrollbarPrefsObserver
26 + (void)registerAsObserver {
27 [[NSDistributedNotificationCenter defaultCenter]
29 selector:@selector(appearancePrefsChanged:)
30 name:@"AppleAquaScrollBarVariantChanged"
32 suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
34 [[NSDistributedNotificationCenter defaultCenter]
36 selector:@selector(behaviorPrefsChanged:)
37 name:@"AppleNoRedisplayAppearancePreferenceChanged"
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"],
66 ThemeHelperMac::ThemeHelperMac() {
67 [ScrollbarPrefsObserver registerAsObserver];
69 NOTIFICATION_RENDERER_PROCESS_CREATED,
70 NotificationService::AllSources());
73 ThemeHelperMac::~ThemeHelperMac() {
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"],
101 void ThemeHelperMac::SendThemeChangeToAllRenderers(
102 float initial_button_delay,
103 float autoscroll_button_delay,
104 bool jump_on_track_click,
106 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
109 it.GetCurrentValue()->Send(new ViewMsg_UpdateScrollbarTheme(
110 initial_button_delay,
111 autoscroll_button_delay,
117 } // namespace content