OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008, 2009 Google, Inc. | 3 * Copyright (C) 2008, 2009 Google, Inc. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #import "core/layout/LayoutThemeMac.h" | 21 #import "core/layout/LayoutThemeMac.h" |
22 | 22 |
| 23 #import <AvailabilityMacros.h> |
| 24 #import <Carbon/Carbon.h> |
| 25 #import <Cocoa/Cocoa.h> |
| 26 #import <math.h> |
23 #import "core/CSSValueKeywords.h" | 27 #import "core/CSSValueKeywords.h" |
24 #import "core/HTMLNames.h" | 28 #import "core/HTMLNames.h" |
25 #import "core/fileapi/FileList.h" | 29 #import "core/fileapi/FileList.h" |
26 #import "core/layout/LayoutProgress.h" | 30 #import "core/layout/LayoutProgress.h" |
27 #import "core/layout/LayoutView.h" | 31 #import "core/layout/LayoutView.h" |
28 #import "core/paint/MediaControlsPainter.h" | 32 #import "core/paint/MediaControlsPainter.h" |
29 #import "core/style/ShadowList.h" | 33 #import "core/style/ShadowList.h" |
30 #import "platform/LayoutTestSupport.h" | 34 #import "platform/LayoutTestSupport.h" |
31 #import "platform/PlatformResourceLoader.h" | 35 #import "platform/PlatformResourceLoader.h" |
| 36 #import "platform/RuntimeEnabledFeatures.h" |
32 #import "platform/Theme.h" | 37 #import "platform/Theme.h" |
33 #import "platform/graphics/BitmapImage.h" | 38 #import "platform/graphics/BitmapImage.h" |
34 #import "platform/mac/ColorMac.h" | 39 #import "platform/mac/ColorMac.h" |
35 #import "platform/mac/ThemeMac.h" | 40 #import "platform/mac/ThemeMac.h" |
36 #import "platform/mac/VersionUtilMac.h" | 41 #import "platform/mac/VersionUtilMac.h" |
37 #import "platform/mac/WebCoreNSCellExtras.h" | 42 #import "platform/mac/WebCoreNSCellExtras.h" |
38 #import "platform/text/PlatformLocale.h" | 43 #import "platform/text/PlatformLocale.h" |
39 #import "platform/text/StringTruncator.h" | 44 #import "platform/text/StringTruncator.h" |
40 #import <AvailabilityMacros.h> | |
41 #import <Carbon/Carbon.h> | |
42 #import <Cocoa/Cocoa.h> | |
43 #import <math.h> | |
44 | 45 |
45 // The methods in this file are specific to the Mac OS X platform. | 46 // The methods in this file are specific to the Mac OS X platform. |
46 | 47 |
47 @interface BlinkLayoutThemeNotificationObserver : NSObject { | 48 @interface BlinkLayoutThemeNotificationObserver : NSObject { |
48 blink::LayoutTheme* _theme; | 49 blink::LayoutTheme* _theme; |
49 } | 50 } |
50 | 51 |
51 - (id)initWithTheme:(blink::LayoutTheme*)theme; | 52 - (id)initWithTheme:(blink::LayoutTheme*)theme; |
52 - (void)systemColorsDidChange:(NSNotification*)notification; | 53 - (void)systemColorsDidChange:(NSNotification*)notification; |
53 | 54 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 int font_size = style.FontSize(); | 122 int font_size = style.FontSize(); |
122 if (font_size == [NSFont systemFontSizeForControlSize:NSRegularControlSize]) | 123 if (font_size == [NSFont systemFontSizeForControlSize:NSRegularControlSize]) |
123 return true; | 124 return true; |
124 if (font_size == [NSFont systemFontSizeForControlSize:NSSmallControlSize]) | 125 if (font_size == [NSFont systemFontSizeForControlSize:NSSmallControlSize]) |
125 return true; | 126 return true; |
126 if (font_size == [NSFont systemFontSizeForControlSize:NSMiniControlSize]) | 127 if (font_size == [NSFont systemFontSizeForControlSize:NSMiniControlSize]) |
127 return true; | 128 return true; |
128 return false; | 129 return false; |
129 } | 130 } |
130 | 131 |
| 132 NSColor* ColorInColorSpace(NSColor* color) { |
| 133 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { |
| 134 return [color colorUsingColorSpace:[NSColorSpace sRGBColorSpace]]; |
| 135 } else { |
| 136 return [color colorUsingColorSpaceName:NSDeviceRGBColorSpace]; |
| 137 } |
| 138 } |
| 139 |
131 } // namespace | 140 } // namespace |
132 | 141 |
133 using namespace HTMLNames; | 142 using namespace HTMLNames; |
134 | 143 |
135 LayoutThemeMac::LayoutThemeMac() | 144 LayoutThemeMac::LayoutThemeMac() |
136 : LayoutTheme(PlatformTheme()), | 145 : LayoutTheme(PlatformTheme()), |
137 notification_observer_( | 146 notification_observer_( |
138 kAdoptNS, | 147 kAdoptNS, |
139 [[BlinkLayoutThemeNotificationObserver alloc] initWithTheme:this]), | 148 [[BlinkLayoutThemeNotificationObserver alloc] initWithTheme:this]), |
140 painter_(*this) { | 149 painter_(*this) { |
141 [[NSNotificationCenter defaultCenter] | 150 [[NSNotificationCenter defaultCenter] |
142 addObserver:notification_observer_.Get() | 151 addObserver:notification_observer_.Get() |
143 selector:@selector(systemColorsDidChange:) | 152 selector:@selector(systemColorsDidChange:) |
144 name:NSSystemColorsDidChangeNotification | 153 name:NSSystemColorsDidChangeNotification |
145 object:nil]; | 154 object:nil]; |
146 } | 155 } |
147 | 156 |
148 LayoutThemeMac::~LayoutThemeMac() { | 157 LayoutThemeMac::~LayoutThemeMac() { |
149 [[NSNotificationCenter defaultCenter] | 158 [[NSNotificationCenter defaultCenter] |
150 removeObserver:notification_observer_.Get()]; | 159 removeObserver:notification_observer_.Get()]; |
151 } | 160 } |
152 | 161 |
153 Color LayoutThemeMac::PlatformActiveSelectionBackgroundColor() const { | 162 Color LayoutThemeMac::PlatformActiveSelectionBackgroundColor() const { |
154 NSColor* color = [[NSColor selectedTextBackgroundColor] | 163 NSColor* color = ColorInColorSpace([NSColor selectedTextBackgroundColor]); |
155 colorUsingColorSpaceName:NSDeviceRGBColorSpace]; | |
156 return Color(static_cast<int>(255.0 * [color redComponent]), | 164 return Color(static_cast<int>(255.0 * [color redComponent]), |
157 static_cast<int>(255.0 * [color greenComponent]), | 165 static_cast<int>(255.0 * [color greenComponent]), |
158 static_cast<int>(255.0 * [color blueComponent])); | 166 static_cast<int>(255.0 * [color blueComponent])); |
159 } | 167 } |
160 | 168 |
161 Color LayoutThemeMac::PlatformInactiveSelectionBackgroundColor() const { | 169 Color LayoutThemeMac::PlatformInactiveSelectionBackgroundColor() const { |
162 NSColor* color = [[NSColor secondarySelectedControlColor] | 170 NSColor* color = ColorInColorSpace([NSColor secondarySelectedControlColor]); |
163 colorUsingColorSpaceName:NSDeviceRGBColorSpace]; | |
164 return Color(static_cast<int>(255.0 * [color redComponent]), | 171 return Color(static_cast<int>(255.0 * [color redComponent]), |
165 static_cast<int>(255.0 * [color greenComponent]), | 172 static_cast<int>(255.0 * [color greenComponent]), |
166 static_cast<int>(255.0 * [color blueComponent])); | 173 static_cast<int>(255.0 * [color blueComponent])); |
167 } | 174 } |
168 | 175 |
169 Color LayoutThemeMac::PlatformActiveSelectionForegroundColor() const { | 176 Color LayoutThemeMac::PlatformActiveSelectionForegroundColor() const { |
170 return Color::kBlack; | 177 return Color::kBlack; |
171 } | 178 } |
172 | 179 |
173 Color LayoutThemeMac::PlatformActiveListBoxSelectionBackgroundColor() const { | 180 Color LayoutThemeMac::PlatformActiveListBoxSelectionBackgroundColor() const { |
174 NSColor* color = [[NSColor alternateSelectedControlColor] | 181 NSColor* color = ColorInColorSpace([NSColor alternateSelectedControlColor]); |
175 colorUsingColorSpaceName:NSDeviceRGBColorSpace]; | |
176 return Color(static_cast<int>(255.0 * [color redComponent]), | 182 return Color(static_cast<int>(255.0 * [color redComponent]), |
177 static_cast<int>(255.0 * [color greenComponent]), | 183 static_cast<int>(255.0 * [color greenComponent]), |
178 static_cast<int>(255.0 * [color blueComponent])); | 184 static_cast<int>(255.0 * [color blueComponent])); |
179 } | 185 } |
180 | 186 |
181 Color LayoutThemeMac::PlatformActiveListBoxSelectionForegroundColor() const { | 187 Color LayoutThemeMac::PlatformActiveListBoxSelectionForegroundColor() const { |
182 return Color::kWhite; | 188 return Color::kWhite; |
183 } | 189 } |
184 | 190 |
185 Color LayoutThemeMac::PlatformInactiveListBoxSelectionForegroundColor() const { | 191 Color LayoutThemeMac::PlatformInactiveListBoxSelectionForegroundColor() const { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 262 } |
257 | 263 |
258 bool LayoutThemeMac::NeedsHackForTextControlWithFontFamily( | 264 bool LayoutThemeMac::NeedsHackForTextControlWithFontFamily( |
259 const AtomicString& family) const { | 265 const AtomicString& family) const { |
260 // This hack is only applied on OSX 10.9. | 266 // This hack is only applied on OSX 10.9. |
261 // https://code.google.com/p/chromium/issues/detail?id=515989#c8 | 267 // https://code.google.com/p/chromium/issues/detail?id=515989#c8 |
262 return IsOS10_9() && family == FontFamilyNames::system_ui; | 268 return IsOS10_9() && family == FontFamilyNames::system_ui; |
263 } | 269 } |
264 | 270 |
265 static RGBA32 ConvertNSColorToColor(NSColor* color) { | 271 static RGBA32 ConvertNSColorToColor(NSColor* color) { |
266 NSColor* color_in_color_space = | 272 NSColor* color_in_color_space = ColorInColorSpace(color); |
267 [color colorUsingColorSpaceName:NSDeviceRGBColorSpace]; | |
268 if (color_in_color_space) { | 273 if (color_in_color_space) { |
269 static const double kScaleFactor = nextafter(256.0, 0.0); | 274 static const double kScaleFactor = nextafter(256.0, 0.0); |
270 return MakeRGB( | 275 return MakeRGB( |
271 static_cast<int>(kScaleFactor * [color_in_color_space redComponent]), | 276 static_cast<int>(kScaleFactor * [color_in_color_space redComponent]), |
272 static_cast<int>(kScaleFactor * [color_in_color_space greenComponent]), | 277 static_cast<int>(kScaleFactor * [color_in_color_space greenComponent]), |
273 static_cast<int>(kScaleFactor * [color_in_color_space blueComponent])); | 278 static_cast<int>(kScaleFactor * [color_in_color_space blueComponent])); |
274 } | 279 } |
275 | 280 |
276 // This conversion above can fail if the NSColor in question is an | 281 // This conversion above can fail if the NSColor in question is an |
277 // NSPatternColor | 282 // NSPatternColor (as many system colors are). These colors are actually a |
278 // (as many system colors are). These colors are actually a repeating pattern | 283 // repeating pattern not just a solid color. To work around this we simply |
279 // not just a solid color. To work around this we simply draw a 1x1 image of | 284 // draw a 1x1 image of the color and use that pixel's color. It might be |
280 // the color and use that pixel's color. It might be better to use an average | 285 // better to use an average of the colors in the pattern instead. |
281 // of | |
282 // the colors in the pattern instead. | |
283 NSBitmapImageRep* offscreen_rep = | 286 NSBitmapImageRep* offscreen_rep = |
284 [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil | 287 [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil |
285 pixelsWide:1 | 288 pixelsWide:1 |
286 pixelsHigh:1 | 289 pixelsHigh:1 |
287 bitsPerSample:8 | 290 bitsPerSample:8 |
288 samplesPerPixel:4 | 291 samplesPerPixel:4 |
289 hasAlpha:YES | 292 hasAlpha:YES |
290 isPlanar:NO | 293 isPlanar:NO |
291 colorSpaceName:NSDeviceRGBColorSpace | 294 colorSpaceName:NSDeviceRGBColorSpace |
292 bytesPerRow:4 | 295 bytesPerRow:4 |
293 bitsPerPixel:32]; | 296 bitsPerPixel:32]; |
294 | 297 |
295 [NSGraphicsContext saveGraphicsState]; | 298 [NSGraphicsContext saveGraphicsState]; |
296 [NSGraphicsContext | 299 [NSGraphicsContext |
297 setCurrentContext:[NSGraphicsContext | 300 setCurrentContext:[NSGraphicsContext |
298 graphicsContextWithBitmapImageRep:offscreen_rep]]; | 301 graphicsContextWithBitmapImageRep:offscreen_rep]]; |
299 NSEraseRect(NSMakeRect(0, 0, 1, 1)); | 302 NSEraseRect(NSMakeRect(0, 0, 1, 1)); |
300 [color drawSwatchInRect:NSMakeRect(0, 0, 1, 1)]; | 303 [color drawSwatchInRect:NSMakeRect(0, 0, 1, 1)]; |
301 [NSGraphicsContext restoreGraphicsState]; | 304 [NSGraphicsContext restoreGraphicsState]; |
302 | 305 |
303 NSUInteger pixel[4]; | 306 NSUInteger pixel[4]; |
304 [offscreen_rep getPixel:pixel atX:0 y:0]; | 307 [offscreen_rep getPixel:pixel atX:0 y:0]; |
305 | |
306 [offscreen_rep release]; | 308 [offscreen_rep release]; |
307 | 309 // This recursive call will not recurse again, because the color space |
308 return MakeRGB(pixel[0], pixel[1], pixel[2]); | 310 // the second time around is NSDeviceRGBColorSpace. |
| 311 return ConvertNSColorToColor([NSColor colorWithDeviceRed:pixel[0] / 255. |
| 312 green:pixel[1] / 255. |
| 313 blue:pixel[2] / 255. |
| 314 alpha:1.]); |
309 } | 315 } |
310 | 316 |
311 static RGBA32 MenuBackgroundColor() { | 317 static RGBA32 MenuBackgroundColor() { |
312 NSBitmapImageRep* offscreen_rep = | 318 NSBitmapImageRep* offscreen_rep = |
313 [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil | 319 [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil |
314 pixelsWide:1 | 320 pixelsWide:1 |
315 pixelsHigh:1 | 321 pixelsHigh:1 |
316 bitsPerSample:8 | 322 bitsPerSample:8 |
317 samplesPerPixel:4 | 323 samplesPerPixel:4 |
318 hasAlpha:YES | 324 hasAlpha:YES |
319 isPlanar:NO | 325 isPlanar:NO |
320 colorSpaceName:NSDeviceRGBColorSpace | 326 colorSpaceName:NSDeviceRGBColorSpace |
321 bytesPerRow:4 | 327 bytesPerRow:4 |
322 bitsPerPixel:32]; | 328 bitsPerPixel:32]; |
323 | 329 |
324 CGContextRef context = static_cast<CGContextRef>([[NSGraphicsContext | 330 CGContextRef context = static_cast<CGContextRef>([[NSGraphicsContext |
325 graphicsContextWithBitmapImageRep:offscreen_rep] graphicsPort]); | 331 graphicsContextWithBitmapImageRep:offscreen_rep] graphicsPort]); |
326 CGRect rect = CGRectMake(0, 0, 1, 1); | 332 CGRect rect = CGRectMake(0, 0, 1, 1); |
327 HIThemeMenuDrawInfo draw_info; | 333 HIThemeMenuDrawInfo draw_info; |
328 draw_info.version = 0; | 334 draw_info.version = 0; |
329 draw_info.menuType = kThemeMenuTypePopUp; | 335 draw_info.menuType = kThemeMenuTypePopUp; |
330 HIThemeDrawMenuBackground(&rect, &draw_info, context, | 336 HIThemeDrawMenuBackground(&rect, &draw_info, context, |
331 kHIThemeOrientationInverted); | 337 kHIThemeOrientationInverted); |
332 | 338 |
333 NSUInteger pixel[4]; | 339 NSUInteger pixel[4]; |
334 [offscreen_rep getPixel:pixel atX:0 y:0]; | 340 [offscreen_rep getPixel:pixel atX:0 y:0]; |
335 | |
336 [offscreen_rep release]; | 341 [offscreen_rep release]; |
337 | 342 return ConvertNSColorToColor([NSColor colorWithDeviceRed:pixel[0] / 255. |
338 return MakeRGB(pixel[0], pixel[1], pixel[2]); | 343 green:pixel[1] / 255. |
| 344 blue:pixel[2] / 255. |
| 345 alpha:1.]); |
339 } | 346 } |
340 | 347 |
341 void LayoutThemeMac::PlatformColorsDidChange() { | 348 void LayoutThemeMac::PlatformColorsDidChange() { |
342 system_color_cache_.clear(); | 349 system_color_cache_.clear(); |
343 LayoutTheme::PlatformColorsDidChange(); | 350 LayoutTheme::PlatformColorsDidChange(); |
344 } | 351 } |
345 | 352 |
346 Color LayoutThemeMac::SystemColor(CSSValueID css_value_id) const { | 353 Color LayoutThemeMac::SystemColor(CSSValueID css_value_id) const { |
347 { | 354 { |
348 HashMap<int, RGBA32>::iterator it = system_color_cache_.find(css_value_id); | 355 HashMap<int, RGBA32>::iterator it = system_color_cache_.find(css_value_id); |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 } | 1115 } |
1109 | 1116 |
1110 bool LayoutThemeMac::ShouldUseFallbackTheme(const ComputedStyle& style) const { | 1117 bool LayoutThemeMac::ShouldUseFallbackTheme(const ComputedStyle& style) const { |
1111 ControlPart part = style.Appearance(); | 1118 ControlPart part = style.Appearance(); |
1112 if (part == kCheckboxPart || part == kRadioPart) | 1119 if (part == kCheckboxPart || part == kRadioPart) |
1113 return style.EffectiveZoom() != 1; | 1120 return style.EffectiveZoom() != 1; |
1114 return false; | 1121 return false; |
1115 } | 1122 } |
1116 | 1123 |
1117 } // namespace blink | 1124 } // namespace blink |
OLD | NEW |