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

Side by Side Diff: Source/platform/scroll/ScrollbarThemeMacNonOverlayAPI.mm

Issue 1245323002: Pass scroll bar placement as an enum instead of std::string (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updates per code review Created 5 years, 5 months 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 static int cButtonHitInset[] = { 3, 2 }; 49 static int cButtonHitInset[] = { 3, 2 };
50 // cRealButtonLength - cButtonInset 50 // cRealButtonLength - cButtonInset
51 static int cButtonLength[] = { 14, 10 }; 51 static int cButtonLength[] = { 14, 10 };
52 static int cScrollbarThickness[] = { 15, 11 }; 52 static int cScrollbarThickness[] = { 15, 11 };
53 static int cButtonInset[] = { 14, 11 }; 53 static int cButtonInset[] = { 14, 11 };
54 static int cThumbMinLength[] = { 26, 20 }; 54 static int cThumbMinLength[] = { 26, 20 };
55 55
56 static int cOuterButtonLength[] = { 16, 14 }; // The outer button in a double bu tton pair is a bit bigger. 56 static int cOuterButtonLength[] = { 16, 14 }; // The outer button in a double bu tton pair is a bit bigger.
57 static int cOuterButtonOverlap = 2; 57 static int cOuterButtonOverlap = 2;
58 58
59 static ScrollbarButtonsPlacement gButtonPlacement = ScrollbarButtonsDoubleEnd; 59 static ScrollbarButtonsPlacement gButtonPlacement = ScrollbarButtonsPlacementDou bleEnd;
60 60
61 void ScrollbarThemeMacNonOverlayAPI::updateButtonPlacement(const std::string& bu ttonPlacement) 61 void ScrollbarThemeMacNonOverlayAPI::updateButtonPlacement(ScrollbarButtonsPlace ment buttonPlacement)
62 { 62 {
63 if (buttonPlacement == "Single") 63 gButtonPlacement = buttonPlacement;
64 gButtonPlacement = ScrollbarButtonsSingle;
65 else if (buttonPlacement == "DoubleMin")
66 gButtonPlacement = ScrollbarButtonsDoubleStart;
67 else if (buttonPlacement == "DoubleBoth")
68 gButtonPlacement = ScrollbarButtonsDoubleBoth;
69 else
70 gButtonPlacement = ScrollbarButtonsDoubleEnd;
71 } 64 }
72 65
73 // Override ScrollbarThemeMacCommon::paint() to add support for the following: 66 // Override ScrollbarThemeMacCommon::paint() to add support for the following:
74 // - drawing using WebThemeEngine functions 67 // - drawing using WebThemeEngine functions
75 // - drawing tickmarks 68 // - drawing tickmarks
76 // - Skia specific changes 69 // - Skia specific changes
77 bool ScrollbarThemeMacNonOverlayAPI::paint(ScrollbarThemeClient* scrollbar, Grap hicsContext* context, const IntRect& damageRect) 70 bool ScrollbarThemeMacNonOverlayAPI::paint(ScrollbarThemeClient* scrollbar, Grap hicsContext* context, const IntRect& damageRect)
78 { 71 {
79 DisplayItem::Type displayItemType = scrollbar->orientation() == HorizontalSc rollbar ? DisplayItem::ScrollbarHorizontal : DisplayItem::ScrollbarVertical; 72 DisplayItem::Type displayItemType = scrollbar->orientation() == HorizontalSc rollbar ? DisplayItem::ScrollbarHorizontal : DisplayItem::ScrollbarVertical;
80 if (DrawingRecorder::useCachedDrawingIfPossible(*context, *scrollbar, displa yItemType)) 73 if (DrawingRecorder::useCachedDrawingIfPossible(*context, *scrollbar, displa yItemType))
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return cScrollbarThickness[controlSize]; 160 return cScrollbarThickness[controlSize];
168 } 161 }
169 162
170 ScrollbarButtonsPlacement ScrollbarThemeMacNonOverlayAPI::buttonsPlacement() con st 163 ScrollbarButtonsPlacement ScrollbarThemeMacNonOverlayAPI::buttonsPlacement() con st
171 { 164 {
172 return gButtonPlacement; 165 return gButtonPlacement;
173 } 166 }
174 167
175 bool ScrollbarThemeMacNonOverlayAPI::hasButtons(ScrollbarThemeClient* scrollbar) 168 bool ScrollbarThemeMacNonOverlayAPI::hasButtons(ScrollbarThemeClient* scrollbar)
176 { 169 {
177 return scrollbar->enabled() && buttonsPlacement() != ScrollbarButtonsNone 170 return scrollbar->enabled() && buttonsPlacement() != ScrollbarButtonsPlaceme ntNone
178 && (scrollbar->orientation() == HorizontalScrollbar 171 && (scrollbar->orientation() == HorizontalScrollbar
179 ? scrollbar->width() 172 ? scrollbar->width()
180 : scrollbar->height()) >= 2 * (cRealButtonLength[scrollbar->control Size()] - cButtonHitInset[scrollbar->controlSize()]); 173 : scrollbar->height()) >= 2 * (cRealButtonLength[scrollbar->control Size()] - cButtonHitInset[scrollbar->controlSize()]);
181 } 174 }
182 175
183 bool ScrollbarThemeMacNonOverlayAPI::hasThumb(ScrollbarThemeClient* scrollbar) 176 bool ScrollbarThemeMacNonOverlayAPI::hasThumb(ScrollbarThemeClient* scrollbar)
184 { 177 {
185 int minLengthForThumb = 2 * cButtonInset[scrollbar->controlSize()] + cThumbM inLength[scrollbar->controlSize()] + 1; 178 int minLengthForThumb = 2 * cButtonInset[scrollbar->controlSize()] + cThumbM inLength[scrollbar->controlSize()] + 1;
186 return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScroll bar ? 179 return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScroll bar ?
187 scrollbar->width() : 180 scrollbar->width() :
188 scrollbar->height()) >= minLengthForThumb; 181 scrollbar->height()) >= minLengthForThumb;
189 } 182 }
190 183
191 static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation orientation, ScrollbarControlSize controlSize, bool start) 184 static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation orientation, ScrollbarControlSize controlSize, bool start)
192 { 185 {
193 ASSERT(gButtonPlacement != ScrollbarButtonsNone); 186 ASSERT(gButtonPlacement != ScrollbarButtonsPlacementNone);
194 187
195 IntRect paintRect(buttonRect); 188 IntRect paintRect(buttonRect);
196 if (orientation == HorizontalScrollbar) { 189 if (orientation == HorizontalScrollbar) {
197 paintRect.setWidth(cRealButtonLength[controlSize]); 190 paintRect.setWidth(cRealButtonLength[controlSize]);
198 if (!start) 191 if (!start)
199 paintRect.setX(buttonRect.x() - (cRealButtonLength[controlSize] - bu ttonRect.width())); 192 paintRect.setX(buttonRect.x() - (cRealButtonLength[controlSize] - bu ttonRect.width()));
200 } else { 193 } else {
201 paintRect.setHeight(cRealButtonLength[controlSize]); 194 paintRect.setHeight(cRealButtonLength[controlSize]);
202 if (!start) 195 if (!start)
203 paintRect.setY(buttonRect.y() - (cRealButtonLength[controlSize] - bu ttonRect.height())); 196 paintRect.setY(buttonRect.y() - (cRealButtonLength[controlSize] - bu ttonRect.height()));
204 } 197 }
205 198
206 return paintRect; 199 return paintRect;
207 } 200 }
208 201
209 IntRect ScrollbarThemeMacNonOverlayAPI::backButtonRect(ScrollbarThemeClient* scr ollbar, ScrollbarPart part, bool painting) 202 IntRect ScrollbarThemeMacNonOverlayAPI::backButtonRect(ScrollbarThemeClient* scr ollbar, ScrollbarPart part, bool painting)
210 { 203 {
211 IntRect result; 204 IntRect result;
212 205
213 if (part == BackButtonStartPart && (buttonsPlacement() == ScrollbarButtonsNo ne || buttonsPlacement() == ScrollbarButtonsDoubleEnd)) 206 if (part == BackButtonStartPart && (buttonsPlacement() == ScrollbarButtonsPl acementNone || buttonsPlacement() == ScrollbarButtonsPlacementDoubleEnd))
214 return result; 207 return result;
215 208
216 if (part == BackButtonEndPart && (buttonsPlacement() == ScrollbarButtonsNone || buttonsPlacement() == ScrollbarButtonsDoubleStart || buttonsPlacement() == S crollbarButtonsSingle)) 209 if (part == BackButtonEndPart && (buttonsPlacement() == ScrollbarButtonsPlac ementNone || buttonsPlacement() == ScrollbarButtonsPlacementDoubleStart || butto nsPlacement() == ScrollbarButtonsPlacementSingle))
217 return result; 210 return result;
218 211
219 int thickness = scrollbarThickness(scrollbar->controlSize()); 212 int thickness = scrollbarThickness(scrollbar->controlSize());
220 bool outerButton = part == BackButtonStartPart && (buttonsPlacement() == Scr ollbarButtonsDoubleStart || buttonsPlacement() == ScrollbarButtonsDoubleBoth); 213 bool outerButton = part == BackButtonStartPart && (buttonsPlacement() == Scr ollbarButtonsPlacementDoubleStart || buttonsPlacement() == ScrollbarButtonsPlace mentDoubleBoth);
221 if (outerButton) { 214 if (outerButton) {
222 if (scrollbar->orientation() == HorizontalScrollbar) 215 if (scrollbar->orientation() == HorizontalScrollbar)
223 result = IntRect(scrollbar->x(), scrollbar->y(), cOuterButtonLength[ scrollbar->controlSize()] + (painting ? cOuterButtonOverlap : 0), thickness); 216 result = IntRect(scrollbar->x(), scrollbar->y(), cOuterButtonLength[ scrollbar->controlSize()] + (painting ? cOuterButtonOverlap : 0), thickness);
224 else 217 else
225 result = IntRect(scrollbar->x(), scrollbar->y(), thickness, cOuterBu ttonLength[scrollbar->controlSize()] + (painting ? cOuterButtonOverlap : 0)); 218 result = IntRect(scrollbar->x(), scrollbar->y(), thickness, cOuterBu ttonLength[scrollbar->controlSize()] + (painting ? cOuterButtonOverlap : 0));
226 return result; 219 return result;
227 } 220 }
228 221
229 // Our repaint rect is slightly larger, since we are a button that is adjace nt to the track. 222 // Our repaint rect is slightly larger, since we are a button that is adjace nt to the track.
230 if (scrollbar->orientation() == HorizontalScrollbar) { 223 if (scrollbar->orientation() == HorizontalScrollbar) {
231 int start = part == BackButtonStartPart ? scrollbar->x() : scrollbar->x( ) + scrollbar->width() - cOuterButtonLength[scrollbar->controlSize()] - cButtonL ength[scrollbar->controlSize()]; 224 int start = part == BackButtonStartPart ? scrollbar->x() : scrollbar->x( ) + scrollbar->width() - cOuterButtonLength[scrollbar->controlSize()] - cButtonL ength[scrollbar->controlSize()];
232 result = IntRect(start, scrollbar->y(), cButtonLength[scrollbar->control Size()], thickness); 225 result = IntRect(start, scrollbar->y(), cButtonLength[scrollbar->control Size()], thickness);
233 } else { 226 } else {
234 int start = part == BackButtonStartPart ? scrollbar->y() : scrollbar->y( ) + scrollbar->height() - cOuterButtonLength[scrollbar->controlSize()] - cButton Length[scrollbar->controlSize()]; 227 int start = part == BackButtonStartPart ? scrollbar->y() : scrollbar->y( ) + scrollbar->height() - cOuterButtonLength[scrollbar->controlSize()] - cButton Length[scrollbar->controlSize()];
235 result = IntRect(scrollbar->x(), start, thickness, cButtonLength[scrollb ar->controlSize()]); 228 result = IntRect(scrollbar->x(), start, thickness, cButtonLength[scrollb ar->controlSize()]);
236 } 229 }
237 230
238 if (painting) 231 if (painting)
239 return buttonRepaintRect(result, scrollbar->orientation(), scrollbar->co ntrolSize(), part == BackButtonStartPart); 232 return buttonRepaintRect(result, scrollbar->orientation(), scrollbar->co ntrolSize(), part == BackButtonStartPart);
240 return result; 233 return result;
241 } 234 }
242 235
243 IntRect ScrollbarThemeMacNonOverlayAPI::forwardButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart part, bool painting) 236 IntRect ScrollbarThemeMacNonOverlayAPI::forwardButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart part, bool painting)
244 { 237 {
245 IntRect result; 238 IntRect result;
246 239
247 if (part == ForwardButtonEndPart && (buttonsPlacement() == ScrollbarButtonsN one || buttonsPlacement() == ScrollbarButtonsDoubleStart)) 240 if (part == ForwardButtonEndPart && (buttonsPlacement() == ScrollbarButtonsP lacementNone || buttonsPlacement() == ScrollbarButtonsPlacementDoubleStart))
248 return result; 241 return result;
249 242
250 if (part == ForwardButtonStartPart && (buttonsPlacement() == ScrollbarButton sNone || buttonsPlacement() == ScrollbarButtonsDoubleEnd || buttonsPlacement() = = ScrollbarButtonsSingle)) 243 if (part == ForwardButtonStartPart && (buttonsPlacement() == ScrollbarButton sPlacementNone || buttonsPlacement() == ScrollbarButtonsPlacementDoubleEnd || bu ttonsPlacement() == ScrollbarButtonsPlacementSingle))
251 return result; 244 return result;
252 245
253 int thickness = scrollbarThickness(scrollbar->controlSize()); 246 int thickness = scrollbarThickness(scrollbar->controlSize());
254 int outerButtonLength = cOuterButtonLength[scrollbar->controlSize()]; 247 int outerButtonLength = cOuterButtonLength[scrollbar->controlSize()];
255 int buttonLength = cButtonLength[scrollbar->controlSize()]; 248 int buttonLength = cButtonLength[scrollbar->controlSize()];
256 249
257 bool outerButton = part == ForwardButtonEndPart && (buttonsPlacement() == Sc rollbarButtonsDoubleEnd || buttonsPlacement() == ScrollbarButtonsDoubleBoth); 250 bool outerButton = part == ForwardButtonEndPart && (buttonsPlacement() == Sc rollbarButtonsPlacementDoubleEnd || buttonsPlacement() == ScrollbarButtonsPlacem entDoubleBoth);
258 if (outerButton) { 251 if (outerButton) {
259 if (scrollbar->orientation() == HorizontalScrollbar) { 252 if (scrollbar->orientation() == HorizontalScrollbar) {
260 result = IntRect(scrollbar->x() + scrollbar->width() - outerButtonLe ngth, scrollbar->y(), outerButtonLength, thickness); 253 result = IntRect(scrollbar->x() + scrollbar->width() - outerButtonLe ngth, scrollbar->y(), outerButtonLength, thickness);
261 if (painting) 254 if (painting)
262 result.inflateX(cOuterButtonOverlap); 255 result.inflateX(cOuterButtonOverlap);
263 } else { 256 } else {
264 result = IntRect(scrollbar->x(), scrollbar->y() + scrollbar->height( ) - outerButtonLength, thickness, outerButtonLength); 257 result = IntRect(scrollbar->x(), scrollbar->y() + scrollbar->height( ) - outerButtonLength, thickness, outerButtonLength);
265 if (painting) 258 if (painting)
266 result.inflateY(cOuterButtonOverlap); 259 result.inflateY(cOuterButtonOverlap);
267 } 260 }
(...skipping 18 matching lines...) Expand all
286 return scrollbar->frameRect(); 279 return scrollbar->frameRect();
287 280
288 IntRect result; 281 IntRect result;
289 int thickness = scrollbarThickness(scrollbar->controlSize()); 282 int thickness = scrollbarThickness(scrollbar->controlSize());
290 int startWidth = 0; 283 int startWidth = 0;
291 int endWidth = 0; 284 int endWidth = 0;
292 int outerButtonLength = cOuterButtonLength[scrollbar->controlSize()]; 285 int outerButtonLength = cOuterButtonLength[scrollbar->controlSize()];
293 int buttonLength = cButtonLength[scrollbar->controlSize()]; 286 int buttonLength = cButtonLength[scrollbar->controlSize()];
294 int doubleButtonLength = outerButtonLength + buttonLength; 287 int doubleButtonLength = outerButtonLength + buttonLength;
295 switch (buttonsPlacement()) { 288 switch (buttonsPlacement()) {
296 case ScrollbarButtonsSingle: 289 case ScrollbarButtonsPlacementSingle:
297 startWidth = buttonLength; 290 startWidth = buttonLength;
298 endWidth = buttonLength; 291 endWidth = buttonLength;
299 break; 292 break;
300 case ScrollbarButtonsDoubleStart: 293 case ScrollbarButtonsPlacementDoubleStart:
301 startWidth = doubleButtonLength; 294 startWidth = doubleButtonLength;
302 break; 295 break;
303 case ScrollbarButtonsDoubleEnd: 296 case ScrollbarButtonsPlacementDoubleEnd:
304 endWidth = doubleButtonLength; 297 endWidth = doubleButtonLength;
305 break; 298 break;
306 case ScrollbarButtonsDoubleBoth: 299 case ScrollbarButtonsPlacementDoubleBoth:
307 startWidth = doubleButtonLength; 300 startWidth = doubleButtonLength;
308 endWidth = doubleButtonLength; 301 endWidth = doubleButtonLength;
309 break; 302 break;
310 default: 303 default:
311 break; 304 break;
312 } 305 }
313 306
314 int totalWidth = startWidth + endWidth; 307 int totalWidth = startWidth + endWidth;
315 if (scrollbar->orientation() == HorizontalScrollbar) 308 if (scrollbar->orientation() == HorizontalScrollbar)
316 return IntRect(scrollbar->x() + startWidth, scrollbar->y(), scrollbar->w idth() - totalWidth, thickness); 309 return IntRect(scrollbar->x() + startWidth, scrollbar->y(), scrollbar->w idth() - totalWidth, thickness);
317 return IntRect(scrollbar->x(), scrollbar->y() + startWidth, thickness, scrol lbar->height() - totalWidth); 310 return IntRect(scrollbar->x(), scrollbar->y() + startWidth, thickness, scrol lbar->height() - totalWidth);
318 } 311 }
319 312
320 int ScrollbarThemeMacNonOverlayAPI::minimumThumbLength(ScrollbarThemeClient* scr ollbar) 313 int ScrollbarThemeMacNonOverlayAPI::minimumThumbLength(ScrollbarThemeClient* scr ollbar)
321 { 314 {
322 return cThumbMinLength[scrollbar->controlSize()]; 315 return cThumbMinLength[scrollbar->controlSize()];
323 } 316 }
324 317
325 } 318 }
OLDNEW
« no previous file with comments | « Source/platform/scroll/ScrollbarThemeMacNonOverlayAPI.h ('k') | Source/platform/scroll/ScrollbarThemeMacOverlayAPI.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698