Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollbarThemeMac.mm

Issue 2478743003: add Tickmarks to aura overlay scrollbar (Closed)
Patch Set: typo Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollbarThemeMac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 [NSClassFromString(@"NSScrollerImp") 125 [NSClassFromString(@"NSScrollerImp")
126 instancesRespondToSelector:@selector(setExpanded:)]; 126 instancesRespondToSelector:@selector(setExpanded:)];
127 return globalSupportsExpandedScrollbars; 127 return globalSupportsExpandedScrollbars;
128 } 128 }
129 129
130 ScrollbarTheme& ScrollbarTheme::nativeTheme() { 130 ScrollbarTheme& ScrollbarTheme::nativeTheme() {
131 DEFINE_STATIC_LOCAL(ScrollbarThemeMac, overlayTheme, ()); 131 DEFINE_STATIC_LOCAL(ScrollbarThemeMac, overlayTheme, ());
132 return overlayTheme; 132 return overlayTheme;
133 } 133 }
134 134
135 void ScrollbarThemeMac::paintGivenTickmarks(SkCanvas* canvas,
136 const Scrollbar& scrollbar,
137 const IntRect& rect,
138 const Vector<IntRect>& tickmarks) {
139 if (scrollbar.orientation() != VerticalScrollbar)
140 return;
141
142 if (rect.height() <= 0 || rect.width() <= 0)
143 return; // nothing to draw on.
144
145 if (!tickmarks.size())
146 return;
147
148 SkAutoCanvasRestore stateSaver(canvas, true);
149
150 SkPaint strokePaint;
151 strokePaint.setAntiAlias(false);
152 strokePaint.setColor(SkColorSetRGB(0xCC, 0xAA, 0x00));
153 strokePaint.setStyle(SkPaint::kStroke_Style);
154
155 SkPaint fillPaint;
156 fillPaint.setAntiAlias(false);
157 fillPaint.setColor(SkColorSetRGB(0xFF, 0xDD, 0x00));
158 fillPaint.setStyle(SkPaint::kFill_Style);
159
160 for (Vector<IntRect>::const_iterator i = tickmarks.begin();
161 i != tickmarks.end(); ++i) {
162 // Calculate how far down (in %) the tick-mark should appear.
163 const float percent = static_cast<float>(i->y()) / scrollbar.totalSize();
164 if (percent < 0.0 || percent > 1.0)
165 continue;
166
167 // Calculate how far down (in pixels) the tick-mark should appear.
168 const int yPos = rect.y() + (rect.height() * percent);
169
170 // Paint.
171 FloatRect tickRect(rect.x(), yPos, rect.width(), 2);
172 canvas->drawRect(tickRect, fillPaint);
173 canvas->drawRect(tickRect, strokePaint);
174 }
175 }
176
177 void ScrollbarThemeMac::paintTickmarks(GraphicsContext& context, 135 void ScrollbarThemeMac::paintTickmarks(GraphicsContext& context,
178 const Scrollbar& scrollbar, 136 const Scrollbar& scrollbar,
179 const IntRect& rect) { 137 const IntRect& rect) {
180 // Note: This is only used for css-styled scrollbars on mac.
181 if (scrollbar.orientation() != VerticalScrollbar)
182 return;
183
184 if (rect.height() <= 0 || rect.width() <= 0)
185 return;
186
187 Vector<IntRect> tickmarks;
188 scrollbar.getTickmarks(tickmarks);
189 if (!tickmarks.size())
190 return;
191
192 if (DrawingRecorder::useCachedDrawingIfPossible(
193 context, scrollbar, DisplayItem::kScrollbarTickmarks))
194 return;
195
196 DrawingRecorder recorder(context, scrollbar, DisplayItem::kScrollbarTickmarks,
197 rect);
198
199 // Inset a bit.
200 IntRect tickmarkTrackRect = rect; 138 IntRect tickmarkTrackRect = rect;
201 tickmarkTrackRect.setX(tickmarkTrackRect.x() + 1); 139 tickmarkTrackRect.setX(tickmarkTrackRect.x() + 1);
202 tickmarkTrackRect.setWidth(tickmarkTrackRect.width() - 2); 140 tickmarkTrackRect.setWidth(tickmarkTrackRect.width() - 1);
203 paintGivenTickmarks(context.canvas(), scrollbar, tickmarkTrackRect, 141 ScrollbarTheme::paintTickmarks(context, scrollbar, tickmarkTrackRect);
204 tickmarks);
205 } 142 }
206 143
207 ScrollbarThemeMac::~ScrollbarThemeMac() {} 144 ScrollbarThemeMac::~ScrollbarThemeMac() {}
208 145
209 void ScrollbarThemeMac::preferencesChanged( 146 void ScrollbarThemeMac::preferencesChanged(
210 float initialButtonDelay, 147 float initialButtonDelay,
211 float autoscrollButtonDelay, 148 float autoscrollButtonDelay,
212 NSScrollerStyle preferredScrollerStyle, 149 NSScrollerStyle preferredScrollerStyle,
213 bool redraw, 150 bool redraw,
214 WebScrollbarButtonsPlacement buttonPlacement) { 151 WebScrollbarButtonsPlacement buttonPlacement) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } 400 }
464 401
465 // static 402 // static
466 NSScrollerStyle ScrollbarThemeMac::recommendedScrollerStyle() { 403 NSScrollerStyle ScrollbarThemeMac::recommendedScrollerStyle() {
467 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) 404 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled())
468 return NSScrollerStyleOverlay; 405 return NSScrollerStyleOverlay;
469 return gPreferredScrollerStyle; 406 return gPreferredScrollerStyle;
470 } 407 }
471 408
472 } // namespace blink 409 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollbarThemeMac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698