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

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: native_theme_base edits Created 4 years, 7 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;
362 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) {
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
370 SkPaint paint; 361 SkPaint paint;
371 paint.setColor(color); 362 paint.setColor(color);
372 paint.setAntiAlias(false);
373 paint.setStyle(SkPaint::kFill_Style);
374 363
375 SkPath path; 364 SkPath path = PathForArrow(rect, direction);
376 // The constants in this block of code are hand-tailored to produce good
377 // looking arrows without anti-aliasing.
378 switch (direction) {
379 case kScrollbarUpArrow:
380 path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle + 2);
381 path.rLineTo(7, 0);
382 path.rLineTo(-4, -4);
383 break;
384 case kScrollbarDownArrow:
385 path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle - 3);
386 path.rLineTo(7, 0);
387 path.rLineTo(-4, 4);
388 break;
389 case kScrollbarRightArrow:
390 path.moveTo(rect.x() + length_middle - 3, rect.y() + width_middle - 4);
391 path.rLineTo(0, 7);
392 path.rLineTo(4, -4);
393 break;
394 case kScrollbarLeftArrow:
395 path.moveTo(rect.x() + length_middle + 1, rect.y() + width_middle - 5);
396 path.rLineTo(0, 9);
397 path.rLineTo(-4, -4);
398 break;
399 default:
400 break;
401 }
402 path.close();
403 365
404 gc->drawPath(path, paint); 366 gc->drawPath(path, paint);
405 } 367 }
406 368
369 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect,
370 Part direction) const {
371 gfx::Rect bounding_rect(rect);
372 const int padding_width = ceil(rect.width() / 4.f);
373 const int padding_height = ceil(rect.height() / 4.f);
374 bounding_rect.Inset(padding_width, padding_height);
375 const gfx::Point center = bounding_rect.CenterPoint();
376
377 SkPath path;
378 SkMatrix transform;
379 transform.setIdentity();
380 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) {
381 int arrow_altitude = bounding_rect.height() / 2 + 1;
382 path.moveTo(bounding_rect.x(), bounding_rect.bottom());
383 path.rLineTo(bounding_rect.width(), 0);
384 path.rLineTo(-bounding_rect.width() / 2.0f, -arrow_altitude);
385 path.close();
386 path.offset(0, -arrow_altitude / 2 + 1);
387 if (direction == kScrollbarDownArrow) {
388 path.offset(0, -1);
389 transform.setScale(1, -1, center.x(), center.y());
390 }
391 } else {
392 int arrow_altitude = bounding_rect.width() / 2 + 1;
393 path.moveTo(bounding_rect.x(), bounding_rect.y());
394 path.rLineTo(0, bounding_rect.height());
395 path.rLineTo(arrow_altitude, -bounding_rect.height() / 2.0f);
396 path.close();
397 path.offset(arrow_altitude / 2, 0);
398 if (direction == kScrollbarLeftArrow) {
399 path.offset(-1, 0);
400 transform.setScale(-1, 1, center.x(), center.y());
401 }
402 }
403 path.transform(transform);
404
405 return path;
406 }
407
407 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, 408 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas,
408 Part part, 409 Part part,
409 State state, 410 State state,
410 const ScrollbarTrackExtraParams& extra_params, 411 const ScrollbarTrackExtraParams& extra_params,
411 const gfx::Rect& rect) const { 412 const gfx::Rect& rect) const {
412 SkPaint paint; 413 SkPaint paint;
413 SkIRect skrect; 414 SkIRect skrect;
414 415
415 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); 416 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom());
416 SkScalar track_hsv[3]; 417 SkScalar track_hsv[3];
(...skipping 608 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); 1026 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); 1027 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f);
1027 1028
1028 if (hsv1[2] + hsv2[2] > 1.0) 1029 if (hsv1[2] + hsv2[2] > 1.0)
1029 diff = -diff; 1030 diff = -diff;
1030 1031
1031 return SaturateAndBrighten(hsv2, -0.2f, diff); 1032 return SaturateAndBrighten(hsv2, -0.2f, diff);
1032 } 1033 }
1033 1034
1034 } // namespace ui 1035 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698