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

Side by Side Diff: ui/native_theme/native_theme_base.cc

Issue 1911973002: Fix scrollbar buttons at hidpi when enable-use-zoom-for-dsf is on. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/native_theme/native_theme_base.h" 5 #include "ui/native_theme/native_theme_base.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 paint.setColor(OutlineColor(trackHSV, thumbHSV)); 351 paint.setColor(OutlineColor(trackHSV, thumbHSV));
352 canvas->drawPath(outline, paint); 352 canvas->drawPath(outline, paint);
353 353
354 PaintArrow(canvas, rect, direction, GetArrowColor(state)); 354 PaintArrow(canvas, rect, direction, GetArrowColor(state));
355 } 355 }
356 356
357 void NativeThemeBase::PaintArrow(SkCanvas* gc, 357 void NativeThemeBase::PaintArrow(SkCanvas* gc,
358 const gfx::Rect& rect, 358 const gfx::Rect& rect,
359 Part direction, 359 Part direction,
360 SkColor color) const { 360 SkColor color) const {
361 int width_middle, length_middle; 361 int width_middle = rect.width() / 2 + 1;
362 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { 362 int length_middle = rect.height() / 2 + 1;
Evan Stade 2016/04/25 02:35:59 confusing var name -- why not height_middle?
Bret 2016/04/25 23:24:32 No reason, it was named that before I messed with
363 width_middle = rect.width() / 2 + 1;
364 length_middle = rect.height() / 2 + 1;
365 } else {
366 length_middle = rect.width() / 2 + 1;
367 width_middle = rect.height() / 2 + 1;
368 }
369 363
370 SkPaint paint; 364 SkPaint paint;
371 paint.setColor(color); 365 paint.setColor(color);
372 paint.setAntiAlias(false); 366 paint.setAntiAlias(false);
373 paint.setStyle(SkPaint::kFill_Style); 367 paint.setStyle(SkPaint::kFill_Style);
374 368
369 int arrow_altitude;
370 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) {
371 arrow_altitude = length_middle / 2;
372 } else {
Evan Stade 2016/04/25 02:35:59 nit: no curlies also ternary assignment is probab
Bret 2016/04/25 23:24:32 Replaced with ternary.
373 arrow_altitude = width_middle / 2;
374 }
375 int arrow_base_length = arrow_altitude * 2 - 1;
Evan Stade 2016/04/25 02:35:59 seems a bit silly to divide by 2 then multiply by
Bret 2016/04/25 23:24:32 I guess it does look silly, but those are the valu
Evan Stade 2016/04/25 23:38:16 oops, this last bit of the comment was supposed to
376
375 SkPath path; 377 SkPath path;
376 // The constants in this block of code are hand-tailored to produce good 378 // The calculations in this block of code are hand-tailored to produce good
377 // looking arrows without anti-aliasing. 379 // looking arrows without anti-aliasing.
378 switch (direction) { 380 switch (direction) {
Evan Stade 2016/04/25 02:35:59 what if you just calculated the path once (for an
Bret 2016/04/25 23:24:32 Didn't work. The arrows still need to be centered
379 case kScrollbarUpArrow: 381 case kScrollbarUpArrow:
380 path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle + 2); 382 path.moveTo(rect.x() + width_middle - arrow_altitude,
381 path.rLineTo(7, 0); 383 rect.y() + length_middle + (arrow_altitude / 2));
Evan Stade 2016/04/25 02:35:59 the asymmetry here is weird. Why are you doing int
Bret 2016/04/25 23:24:32 I was making sure everything looked the same at 1x
382 path.rLineTo(-4, -4); 384 path.rLineTo(arrow_base_length, 0);
385 path.rLineTo(-arrow_altitude, -arrow_altitude);
383 break; 386 break;
384 case kScrollbarDownArrow: 387 case kScrollbarDownArrow:
385 path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle - 3); 388 path.moveTo(rect.x() + width_middle - arrow_altitude,
386 path.rLineTo(7, 0); 389 rect.y() + length_middle - ceil(arrow_altitude / 2.0));
387 path.rLineTo(-4, 4); 390 path.rLineTo(arrow_base_length, 0);
391 path.rLineTo(-arrow_altitude, arrow_altitude);
388 break; 392 break;
389 case kScrollbarRightArrow: 393 case kScrollbarRightArrow:
390 path.moveTo(rect.x() + length_middle - 3, rect.y() + width_middle - 4); 394 path.moveTo(rect.x() + width_middle - (arrow_altitude / 2),
391 path.rLineTo(0, 7); 395 rect.y() + length_middle - arrow_altitude);
392 path.rLineTo(4, -4); 396 path.rLineTo(0, arrow_base_length);
397 path.rLineTo(arrow_altitude, -arrow_altitude);
393 break; 398 break;
394 case kScrollbarLeftArrow: 399 case kScrollbarLeftArrow:
395 path.moveTo(rect.x() + length_middle + 1, rect.y() + width_middle - 5); 400 path.moveTo(rect.x() + width_middle + 1,
396 path.rLineTo(0, 9); 401 rect.y() + length_middle - (arrow_altitude + 1));
397 path.rLineTo(-4, -4); 402 path.rLineTo(0, arrow_base_length + 2);
Evan Stade 2016/04/25 02:35:59 can you leave comments explaining the magic consta
Bret 2016/04/25 23:24:32 To be honest, I'm not really sure why these consta
Evan Stade 2016/04/25 23:38:16 The new code is even kookier than the old, and I s
403 path.rLineTo(-arrow_altitude, -arrow_altitude);
398 break; 404 break;
399 default: 405 default:
400 break; 406 break;
401 } 407 }
402 path.close(); 408 path.close();
403 409
404 gc->drawPath(path, paint); 410 gc->drawPath(path, paint);
405 } 411 }
406 412
407 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, 413 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas,
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); 1031 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f);
1026 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); 1032 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f);
1027 1033
1028 if (hsv1[2] + hsv2[2] > 1.0) 1034 if (hsv1[2] + hsv2[2] > 1.0)
1029 diff = -diff; 1035 diff = -diff;
1030 1036
1031 return SaturateAndBrighten(hsv2, -0.2f, diff); 1037 return SaturateAndBrighten(hsv2, -0.2f, diff);
1032 } 1038 }
1033 1039
1034 } // namespace ui 1040 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698