Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "content/browser/theme_helper_mac.h" | |
| 6 | |
| 7 #include <Foundation/Foundation.h> | |
| 8 | |
| 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" | |
| 14 #include "content/public/common/process_type.h" | |
|
jam
2013/11/06 22:34:43
nit: not needed now
Avi (use Gerrit)
2013/11/07 15:47:52
Done.
| |
| 15 | |
| 16 @interface ScrollbarPrefsObserver : NSObject | |
| 17 | |
| 18 + (void)registerAsObserver; | |
| 19 + (void)appearancePrefsChanged:(NSNotification*)notification; | |
| 20 + (void)behaviorPrefsChanged:(NSNotification*)notification; | |
| 21 + (void)notifyPrefsChangedWithRedraw:(BOOL)redraw; | |
| 22 | |
| 23 @end | |
| 24 | |
| 25 @implementation ScrollbarPrefsObserver | |
| 26 | |
| 27 + (void)registerAsObserver { | |
| 28 [[NSDistributedNotificationCenter defaultCenter] | |
| 29 addObserver:self | |
| 30 selector:@selector(appearancePrefsChanged:) | |
| 31 name:@"AppleAquaScrollBarVariantChanged" | |
| 32 object:nil | |
| 33 suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately]; | |
| 34 | |
| 35 [[NSDistributedNotificationCenter defaultCenter] | |
| 36 addObserver:self | |
| 37 selector:@selector(behaviorPrefsChanged:) | |
| 38 name:@"AppleNoRedisplayAppearancePreferenceChanged" | |
| 39 object:nil | |
| 40 suspensionBehavior:NSNotificationSuspensionBehaviorCoalesce]; | |
| 41 } | |
| 42 | |
| 43 + (void)appearancePrefsChanged:(NSNotification*)notification { | |
| 44 [self notifyPrefsChangedWithRedraw:YES]; | |
| 45 } | |
| 46 | |
| 47 + (void)behaviorPrefsChanged:(NSNotification*)notification { | |
| 48 [self notifyPrefsChangedWithRedraw:NO]; | |
| 49 } | |
| 50 | |
| 51 + (void)notifyPrefsChangedWithRedraw:(BOOL)redraw { | |
| 52 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 53 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | |
| 54 [defaults synchronize]; | |
| 55 | |
| 56 content::ThemeHelperMac::SendThemeChangeToAllRenderers( | |
| 57 [defaults floatForKey:@"NSScrollerButtonDelay"], | |
| 58 [defaults floatForKey:@"NSScrollerButtonPeriod"], | |
| 59 [defaults boolForKey:@"AppleScrollerPagingBehavior"], | |
| 60 redraw); | |
| 61 } | |
| 62 | |
| 63 @end | |
| 64 | |
| 65 namespace content { | |
| 66 | |
| 67 ThemeHelperMac::ThemeHelperMac() { | |
| 68 [ScrollbarPrefsObserver registerAsObserver]; | |
| 69 registrar_.Add(this, | |
| 70 NOTIFICATION_RENDERER_PROCESS_CREATED, | |
| 71 NotificationService::AllSources()); | |
| 72 } | |
| 73 | |
| 74 ThemeHelperMac::~ThemeHelperMac() { | |
| 75 } | |
| 76 | |
| 77 // static | |
| 78 ThemeHelperMac* ThemeHelperMac::GetInstance() { | |
| 79 return Singleton<ThemeHelperMac, | |
| 80 LeakySingletonTraits<ThemeHelperMac> >::get(); | |
| 81 } | |
| 82 | |
| 83 | |
| 84 void ThemeHelperMac::Observe(int type, | |
| 85 const NotificationSource& source, | |
| 86 const NotificationDetails& details) { | |
| 87 DCHECK_EQ(NOTIFICATION_RENDERER_PROCESS_CREATED, type); | |
| 88 | |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 90 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | |
| 91 [defaults synchronize]; | |
| 92 | |
| 93 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); | |
| 94 rph->Send(new ViewMsg_UpdateScrollbarTheme( | |
| 95 [defaults floatForKey:@"NSScrollerButtonDelay"], | |
| 96 [defaults floatForKey:@"NSScrollerButtonPeriod"], | |
| 97 [defaults boolForKey:@"AppleScrollerPagingBehavior"], | |
| 98 false)); | |
| 99 } | |
| 100 | |
| 101 // static | |
| 102 void ThemeHelperMac::SendThemeChangeToAllRenderers( | |
| 103 float initial_button_delay, | |
| 104 float autoscroll_button_delay, | |
| 105 bool jump_on_track_click, | |
| 106 bool redraw) { | |
| 107 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | |
| 108 !it.IsAtEnd(); | |
| 109 it.Advance()) { | |
| 110 it.GetCurrentValue()->Send(new ViewMsg_UpdateScrollbarTheme( | |
| 111 initial_button_delay, | |
| 112 autoscroll_button_delay, | |
| 113 jump_on_track_click, | |
| 114 redraw)); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 } // namespace content | |
| OLD | NEW |