OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/theme_helper_mac.h" | 5 #include "content/browser/theme_helper_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
11 #include "base/mac/sdk_forward_declarations.h" | 11 #include "base/mac/sdk_forward_declarations.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "content/browser/renderer_host/render_process_host_impl.h" | |
13 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
16 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
19 | 20 |
20 using content::RenderProcessHost; | 21 using content::RenderProcessHost; |
22 using content::RenderProcessHostImpl; | |
21 using content::ThemeHelperMac; | 23 using content::ThemeHelperMac; |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 bool GetScrollAnimationEnabled() { | |
26 bool enabled = false; | |
27 id value = nil; | |
28 if (base::mac::IsOSMountainLionOrLater()) { | |
29 value = [[NSUserDefaults standardUserDefaults] | |
30 objectForKey:@"NSScrollAnimationEnabled"]; | |
31 } else { | |
32 value = [[NSUserDefaults standardUserDefaults] | |
33 objectForKey:@"AppleScrollAnimationEnabled"]; | |
34 } | |
35 if (value) | |
36 enabled = [value boolValue]; | |
37 return enabled; | |
38 } | |
39 | |
40 blink::WebScrollbarButtonsPlacement GetButtonPlacement() { | 27 blink::WebScrollbarButtonsPlacement GetButtonPlacement() { |
41 NSString* scrollbar_variant = [[NSUserDefaults standardUserDefaults] | 28 NSString* scrollbar_variant = [[NSUserDefaults standardUserDefaults] |
42 objectForKey:@"AppleScrollBarVariant"]; | 29 objectForKey:@"AppleScrollBarVariant"]; |
43 if ([scrollbar_variant isEqualToString:@"Single"]) | 30 if ([scrollbar_variant isEqualToString:@"Single"]) |
44 return blink::WebScrollbarButtonsPlacementSingle; | 31 return blink::WebScrollbarButtonsPlacementSingle; |
45 else if ([scrollbar_variant isEqualToString:@"DoubleMin"]) | 32 else if ([scrollbar_variant isEqualToString:@"DoubleMin"]) |
46 return blink::WebScrollbarButtonsPlacementDoubleStart; | 33 return blink::WebScrollbarButtonsPlacementDoubleStart; |
47 else if ([scrollbar_variant isEqualToString:@"DoubleBoth"]) | 34 else if ([scrollbar_variant isEqualToString:@"DoubleBoth"]) |
48 return blink::WebScrollbarButtonsPlacementDoubleBoth; | 35 return blink::WebScrollbarButtonsPlacementDoubleBoth; |
49 else | 36 else |
50 return blink::WebScrollbarButtonsPlacementDoubleEnd; | 37 return blink::WebScrollbarButtonsPlacementDoubleEnd; |
51 } | 38 } |
52 | 39 |
53 void FillScrollbarThemeParams(ViewMsg_UpdateScrollbarTheme_Params* params) { | 40 void FillScrollbarThemeParams(ViewMsg_UpdateScrollbarTheme_Params* params) { |
54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
55 | 42 |
56 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | 43 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
57 [defaults synchronize]; | 44 [defaults synchronize]; |
58 | 45 |
59 params->initial_button_delay = | 46 params->initial_button_delay = |
60 [defaults floatForKey:@"NSScrollerButtonDelay"]; | 47 [defaults floatForKey:@"NSScrollerButtonDelay"]; |
61 params->autoscroll_button_delay = | 48 params->autoscroll_button_delay = |
62 [defaults floatForKey:@"NSScrollerButtonPeriod"]; | 49 [defaults floatForKey:@"NSScrollerButtonPeriod"]; |
63 params->jump_on_track_click = | 50 params->jump_on_track_click = |
64 [defaults boolForKey:@"AppleScrollerPagingBehavior"]; | 51 [defaults boolForKey:@"AppleScrollerPagingBehavior"]; |
65 params->preferred_scroller_style = | 52 params->preferred_scroller_style = |
66 ThemeHelperMac::GetPreferredScrollerStyle(); | 53 ThemeHelperMac::GetPreferredScrollerStyle(); |
67 params->scroll_animation_enabled = GetScrollAnimationEnabled(); | |
68 params->button_placement = GetButtonPlacement(); | 54 params->button_placement = GetButtonPlacement(); |
69 } | 55 } |
70 | 56 |
71 ViewMsg_SystemColorsChanged* CreateSystemColorsChangedMessage() { | 57 ViewMsg_SystemColorsChanged* CreateSystemColorsChangedMessage() { |
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
73 | 59 |
74 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | 60 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
75 [defaults synchronize]; | 61 [defaults synchronize]; |
76 | 62 |
77 return new ViewMsg_SystemColorsChanged( | 63 return new ViewMsg_SystemColorsChanged( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 } | 156 } |
171 | 157 |
172 + (void)notifyPrefsChangedWithRedraw:(BOOL)redraw { | 158 + (void)notifyPrefsChangedWithRedraw:(BOOL)redraw { |
173 ViewMsg_UpdateScrollbarTheme_Params params; | 159 ViewMsg_UpdateScrollbarTheme_Params params; |
174 FillScrollbarThemeParams(¶ms); | 160 FillScrollbarThemeParams(¶ms); |
175 params.redraw = redraw; | 161 params.redraw = redraw; |
176 | 162 |
177 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | 163 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
178 !it.IsAtEnd(); | 164 !it.IsAtEnd(); |
179 it.Advance()) { | 165 it.Advance()) { |
180 it.GetCurrentValue()->Send(new ViewMsg_UpdateScrollbarTheme(params)); | 166 RenderProcessHostImpl* rphi = |
167 static_cast<RenderProcessHostImpl*>(it.GetCurrentValue()); | |
bokan
2016/02/02 19:45:39
In particular, I'm not sure if this is kosher - wi
| |
168 rphi->RecomputeAndUpdateWebKitPreferences(); | |
169 rphi->Send(new ViewMsg_UpdateScrollbarTheme(params)); | |
181 } | 170 } |
182 } | 171 } |
183 | 172 |
184 @end | 173 @end |
185 | 174 |
186 namespace content { | 175 namespace content { |
187 | 176 |
188 // static | 177 // static |
189 ThemeHelperMac* ThemeHelperMac::GetInstance() { | 178 ThemeHelperMac* ThemeHelperMac::GetInstance() { |
190 return base::Singleton<ThemeHelperMac, | 179 return base::Singleton<ThemeHelperMac, |
(...skipping 21 matching lines...) Expand all Loading... | |
212 const NotificationSource& source, | 201 const NotificationSource& source, |
213 const NotificationDetails& details) { | 202 const NotificationDetails& details) { |
214 DCHECK_EQ(NOTIFICATION_RENDERER_PROCESS_CREATED, type); | 203 DCHECK_EQ(NOTIFICATION_RENDERER_PROCESS_CREATED, type); |
215 | 204 |
216 // When a new RenderProcess is created, send it the initial preference | 205 // When a new RenderProcess is created, send it the initial preference |
217 // parameters. | 206 // parameters. |
218 ViewMsg_UpdateScrollbarTheme_Params params; | 207 ViewMsg_UpdateScrollbarTheme_Params params; |
219 FillScrollbarThemeParams(¶ms); | 208 FillScrollbarThemeParams(¶ms); |
220 params.redraw = false; | 209 params.redraw = false; |
221 | 210 |
222 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); | 211 RenderProcessHostImpl* rphi = |
bokan
2016/02/02 19:45:39
Ditto here
| |
223 rph->Send(new ViewMsg_UpdateScrollbarTheme(params)); | 212 Source<content::RenderProcessHostImpl>(source).ptr(); |
224 rph->Send(CreateSystemColorsChangedMessage()); | 213 rphi->RecomputeAndUpdateWebKitPreferences(); |
214 rphi->Send(new ViewMsg_UpdateScrollbarTheme(params)); | |
215 rphi->Send(CreateSystemColorsChangedMessage()); | |
225 } | 216 } |
226 | 217 |
227 } // namespace content | 218 } // namespace content |
OLD | NEW |