| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // FIXME: There are repainting problems due to Aqua scroll bar buttons' visual o
verflow. | 49 // FIXME: There are repainting problems due to Aqua scroll bar buttons' visual o
verflow. |
| 50 | 50 |
| 51 using namespace blink; | 51 using namespace blink; |
| 52 | 52 |
| 53 @interface NSColor (WebNSColorDetails) | 53 @interface NSColor (WebNSColorDetails) |
| 54 + (NSImage *)_linenPatternImage; | 54 + (NSImage *)_linenPatternImage; |
| 55 @end | 55 @end |
| 56 | 56 |
| 57 namespace blink { | 57 namespace blink { |
| 58 | 58 |
| 59 typedef HashSet<ScrollbarThemeClient*> ScrollbarSet; | 59 typedef HashSet<ScrollbarThemeClient&> ScrollbarSet; |
| 60 | 60 |
| 61 static ScrollbarSet& scrollbarSet() | 61 static ScrollbarSet& scrollbarSet() |
| 62 { | 62 { |
| 63 DEFINE_STATIC_LOCAL(ScrollbarSet, set, ()); | 63 DEFINE_STATIC_LOCAL(ScrollbarSet, set, ()); |
| 64 return set; | 64 return set; |
| 65 } | 65 } |
| 66 | 66 |
| 67 static float gInitialButtonDelay = 0.5f; | 67 static float gInitialButtonDelay = 0.5f; |
| 68 static float gAutoscrollButtonDelay = 0.05f; | 68 static float gAutoscrollButtonDelay = 0.05f; |
| 69 static NSScrollerStyle gPreferredScrollerStyle = NSScrollerStyleLegacy; | 69 static NSScrollerStyle gPreferredScrollerStyle = NSScrollerStyleLegacy; |
| 70 static bool gScrollAnimationEnabledForSystem = false; | 70 static bool gScrollAnimationEnabledForSystem = false; |
| 71 | 71 |
| 72 ScrollbarTheme* ScrollbarTheme::nativeTheme() | 72 ScrollbarTheme* ScrollbarTheme::nativeTheme() |
| 73 { | 73 { |
| 74 static ScrollbarThemeMacCommon* theme = NULL; | |
| 75 if (theme) | |
| 76 return theme; | |
| 77 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { | 74 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { |
| 78 DEFINE_STATIC_LOCAL(ScrollbarThemeMacOverlayAPI, overlayTheme, ()); | 75 DEFINE_STATIC_LOCAL(ScrollbarThemeMacOverlayAPI, overlayTheme, ()); |
| 79 theme = &overlayTheme; | 76 return overlayTheme; |
| 80 } else { | 77 } |
| 78 { |
| 81 DEFINE_STATIC_LOCAL(ScrollbarThemeMacNonOverlayAPI, nonOverlayTheme, ())
; | 79 DEFINE_STATIC_LOCAL(ScrollbarThemeMacNonOverlayAPI, nonOverlayTheme, ())
; |
| 82 theme = &nonOverlayTheme; | 80 return nonOverlayTheme; |
| 83 } | 81 } |
| 84 return theme; | |
| 85 } | 82 } |
| 86 | 83 |
| 87 void ScrollbarThemeMacCommon::registerScrollbar(ScrollbarThemeClient* scrollbar) | 84 void ScrollbarThemeMacCommon::registerScrollbar(ScrollbarThemeClient& scrollbar) |
| 88 { | 85 { |
| 89 scrollbarSet().add(scrollbar); | 86 scrollbarSet().add(scrollbar); |
| 90 } | 87 } |
| 91 | 88 |
| 92 void ScrollbarThemeMacCommon::unregisterScrollbar(ScrollbarThemeClient* scrollba
r) | 89 void ScrollbarThemeMacCommon::unregisterScrollbar(ScrollbarThemeClient& scrollba
r) |
| 93 { | 90 { |
| 94 scrollbarSet().remove(scrollbar); | 91 scrollbarSet().remove(scrollbar); |
| 95 } | 92 } |
| 96 | 93 |
| 97 void ScrollbarThemeMacCommon::paintGivenTickmarks(SkCanvas* canvas, const Scroll
barThemeClient* scrollbar, const IntRect& rect, const Vector<IntRect>& tickmarks
) | 94 void ScrollbarThemeMacCommon::paintGivenTickmarks(SkCanvas* canvas, const Scroll
barThemeClient& scrollbar, const IntRect& rect, const Vector<IntRect>& tickmarks
) |
| 98 { | 95 { |
| 99 if (scrollbar->orientation() != VerticalScrollbar) | 96 if (scrollbar.orientation() != VerticalScrollbar) |
| 100 return; | 97 return; |
| 101 | 98 |
| 102 if (rect.height() <= 0 || rect.width() <= 0) | 99 if (rect.height() <= 0 || rect.width() <= 0) |
| 103 return; // nothing to draw on. | 100 return; // nothing to draw on. |
| 104 | 101 |
| 105 if (!tickmarks.size()) | 102 if (!tickmarks.size()) |
| 106 return; | 103 return; |
| 107 | 104 |
| 108 SkAutoCanvasRestore stateSaver(canvas, true); | 105 SkAutoCanvasRestore stateSaver(canvas, true); |
| 109 | 106 |
| 110 SkPaint strokePaint; | 107 SkPaint strokePaint; |
| 111 strokePaint.setAntiAlias(false); | 108 strokePaint.setAntiAlias(false); |
| 112 strokePaint.setColor(SkColorSetRGB(0xCC, 0xAA, 0x00)); | 109 strokePaint.setColor(SkColorSetRGB(0xCC, 0xAA, 0x00)); |
| 113 strokePaint.setStyle(SkPaint::kStroke_Style); | 110 strokePaint.setStyle(SkPaint::kStroke_Style); |
| 114 | 111 |
| 115 SkPaint fillPaint; | 112 SkPaint fillPaint; |
| 116 fillPaint.setAntiAlias(false); | 113 fillPaint.setAntiAlias(false); |
| 117 fillPaint.setColor(SkColorSetRGB(0xFF, 0xDD, 0x00)); | 114 fillPaint.setColor(SkColorSetRGB(0xFF, 0xDD, 0x00)); |
| 118 fillPaint.setStyle(SkPaint::kFill_Style); | 115 fillPaint.setStyle(SkPaint::kFill_Style); |
| 119 | 116 |
| 120 for (Vector<IntRect>::const_iterator i = tickmarks.begin(); i != tickmarks.e
nd(); ++i) { | 117 for (Vector<IntRect>::const_iterator i = tickmarks.begin(); i != tickmarks.e
nd(); ++i) { |
| 121 // Calculate how far down (in %) the tick-mark should appear. | 118 // Calculate how far down (in %) the tick-mark should appear. |
| 122 const float percent = static_cast<float>(i->y()) / scrollbar->totalSize(
); | 119 const float percent = static_cast<float>(i->y()) / scrollbar.totalSize()
; |
| 123 if (percent < 0.0 || percent > 1.0) | 120 if (percent < 0.0 || percent > 1.0) |
| 124 continue; | 121 continue; |
| 125 | 122 |
| 126 // Calculate how far down (in pixels) the tick-mark should appear. | 123 // Calculate how far down (in pixels) the tick-mark should appear. |
| 127 const int yPos = rect.y() + (rect.height() * percent); | 124 const int yPos = rect.y() + (rect.height() * percent); |
| 128 | 125 |
| 129 // Paint. | 126 // Paint. |
| 130 FloatRect tickRect(rect.x(), yPos, rect.width(), 2); | 127 FloatRect tickRect(rect.x(), yPos, rect.width(), 2); |
| 131 canvas->drawRect(tickRect, fillPaint); | 128 canvas->drawRect(tickRect, fillPaint); |
| 132 canvas->drawRect(tickRect, strokePaint); | 129 canvas->drawRect(tickRect, strokePaint); |
| 133 } | 130 } |
| 134 } | 131 } |
| 135 | 132 |
| 136 void ScrollbarThemeMacCommon::paintTickmarks(GraphicsContext* context, const Scr
ollbarThemeClient* scrollbar, const IntRect& rect) | 133 void ScrollbarThemeMacCommon::paintTickmarks(GraphicsContext& context, const Scr
ollbarThemeClient& scrollbar, const IntRect& rect) |
| 137 { | 134 { |
| 138 // Note: This is only used for css-styled scrollbars on mac. | 135 // Note: This is only used for css-styled scrollbars on mac. |
| 139 if (scrollbar->orientation() != VerticalScrollbar) | 136 if (scrollbar.orientation() != VerticalScrollbar) |
| 140 return; | 137 return; |
| 141 | 138 |
| 142 if (rect.height() <= 0 || rect.width() <= 0) | 139 if (rect.height() <= 0 || rect.width() <= 0) |
| 143 return; | 140 return; |
| 144 | 141 |
| 145 Vector<IntRect> tickmarks; | 142 Vector<IntRect> tickmarks; |
| 146 scrollbar->getTickmarks(tickmarks); | 143 scrollbar.getTickmarks(tickmarks); |
| 147 if (!tickmarks.size()) | 144 if (!tickmarks.size()) |
| 148 return; | 145 return; |
| 149 | 146 |
| 150 if (DrawingRecorder::useCachedDrawingIfPossible(*context, *scrollbar, Displa
yItem::ScrollbarTickmarks)) | 147 if (DrawingRecorder::useCachedDrawingIfPossible(*context, *scrollbar, Displa
yItem::ScrollbarTickmarks)) |
| 151 return; | 148 return; |
| 152 | 149 |
| 153 DrawingRecorder recorder(*context, *scrollbar, DisplayItem::ScrollbarTickmar
ks, rect); | 150 DrawingRecorder recorder(*context, *scrollbar, DisplayItem::ScrollbarTickmar
ks, rect); |
| 154 | 151 |
| 155 // Inset a bit. | 152 // Inset a bit. |
| 156 IntRect tickmarkTrackRect = rect; | 153 IntRect tickmarkTrackRect = rect; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 double ScrollbarThemeMacCommon::initialAutoscrollTimerDelay() | 191 double ScrollbarThemeMacCommon::initialAutoscrollTimerDelay() |
| 195 { | 192 { |
| 196 return gInitialButtonDelay; | 193 return gInitialButtonDelay; |
| 197 } | 194 } |
| 198 | 195 |
| 199 double ScrollbarThemeMacCommon::autoscrollTimerDelay() | 196 double ScrollbarThemeMacCommon::autoscrollTimerDelay() |
| 200 { | 197 { |
| 201 return gAutoscrollButtonDelay; | 198 return gAutoscrollButtonDelay; |
| 202 } | 199 } |
| 203 | 200 |
| 204 bool ScrollbarThemeMacCommon::shouldDragDocumentInsteadOfThumb(const ScrollbarTh
emeClient*, const PlatformMouseEvent& event) | 201 bool ScrollbarThemeMacCommon::shouldDragDocumentInsteadOfThumb(const ScrollbarTh
emeClient&, const PlatformMouseEvent& event) |
| 205 { | 202 { |
| 206 return event.altKey(); | 203 return event.altKey(); |
| 207 } | 204 } |
| 208 | 205 |
| 209 int ScrollbarThemeMacCommon::scrollbarPartToHIPressedState(ScrollbarPart part) | 206 int ScrollbarThemeMacCommon::scrollbarPartToHIPressedState(ScrollbarPart part) |
| 210 { | 207 { |
| 211 switch (part) { | 208 switch (part) { |
| 212 case BackButtonStartPart: | 209 case BackButtonStartPart: |
| 213 return kThemeTopOutsideArrowPressed; | 210 return kThemeTopOutsideArrowPressed; |
| 214 case BackButtonEndPart: | 211 case BackButtonEndPart: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 235 // static | 232 // static |
| 236 bool ScrollbarThemeMacCommon::isOverlayAPIAvailable() | 233 bool ScrollbarThemeMacCommon::isOverlayAPIAvailable() |
| 237 { | 234 { |
| 238 static bool apiAvailable = | 235 static bool apiAvailable = |
| 239 [NSClassFromString(@"NSScrollerImp") respondsToSelector:@selector(scroll
erImpWithStyle:controlSize:horizontal:replacingScrollerImp:)] | 236 [NSClassFromString(@"NSScrollerImp") respondsToSelector:@selector(scroll
erImpWithStyle:controlSize:horizontal:replacingScrollerImp:)] |
| 240 && [NSClassFromString(@"NSScrollerImpPair") instancesRespondToSelector:@
selector(scrollerStyle)]; | 237 && [NSClassFromString(@"NSScrollerImpPair") instancesRespondToSelector:@
selector(scrollerStyle)]; |
| 241 return apiAvailable; | 238 return apiAvailable; |
| 242 } | 239 } |
| 243 | 240 |
| 244 } // namespace blink | 241 } // namespace blink |
| OLD | NEW |