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

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

Issue 2009733002: Draw nicer arrows when the scrollbar buttons are not square. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor edits Created 4 years, 6 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 SkPaint paint; 361 SkPaint paint;
362 paint.setColor(color); 362 paint.setColor(color);
363 363
364 SkPath path = PathForArrow(rect, direction); 364 SkPath path = PathForArrow(rect, direction);
365 365
366 gc->drawPath(path, paint); 366 gc->drawPath(path, paint);
367 } 367 }
368 368
369 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, 369 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect,
370 Part direction) const { 370 Part direction) const {
371 gfx::Rect bounding_rect(rect); 371 gfx::RectF bounding_rect = BoundingRectForArrow(rect);
372 const int padding_width = ceil(rect.width() / 4.f); 372 const gfx::PointF center = bounding_rect.CenterPoint();
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; 373 SkPath path;
378 SkMatrix transform; 374 SkMatrix transform;
379 transform.setIdentity(); 375 transform.setIdentity();
380 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { 376 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) {
381 int arrow_altitude = bounding_rect.height() / 2 + 1; 377 int arrow_altitude = bounding_rect.height() / 2 + 1;
382 path.moveTo(bounding_rect.x(), bounding_rect.bottom()); 378 path.moveTo(bounding_rect.x(), bounding_rect.bottom());
383 path.rLineTo(bounding_rect.width(), 0); 379 path.rLineTo(bounding_rect.width(), 0);
384 path.rLineTo(-bounding_rect.width() / 2.0f, -arrow_altitude); 380 path.rLineTo(-bounding_rect.width() / 2.0f, -arrow_altitude);
385 path.close(); 381 path.close();
386 path.offset(0, -arrow_altitude / 2 + 1); 382 path.offset(0, -arrow_altitude / 2 + 1);
387 if (direction == kScrollbarDownArrow) { 383 if (direction == kScrollbarDownArrow) {
388 path.offset(0, -1);
Peter Kasting 2016/06/10 01:03:23 What were these offsets for?
Bret 2016/06/11 00:11:43 Before this change the bounding box was an integer
389 transform.setScale(1, -1, center.x(), center.y()); 384 transform.setScale(1, -1, center.x(), center.y());
390 } 385 }
391 } else { 386 } else {
392 int arrow_altitude = bounding_rect.width() / 2 + 1; 387 int arrow_altitude = bounding_rect.width() / 2 + 1;
393 path.moveTo(bounding_rect.x(), bounding_rect.y()); 388 path.moveTo(bounding_rect.x(), bounding_rect.y());
394 path.rLineTo(0, bounding_rect.height()); 389 path.rLineTo(0, bounding_rect.height());
395 path.rLineTo(arrow_altitude, -bounding_rect.height() / 2.0f); 390 path.rLineTo(arrow_altitude, -bounding_rect.height() / 2.0f);
396 path.close(); 391 path.close();
397 path.offset(arrow_altitude / 2, 0); 392 path.offset(arrow_altitude / 2, 0);
398 if (direction == kScrollbarLeftArrow) { 393 if (direction == kScrollbarLeftArrow) {
399 path.offset(-1, 0);
400 transform.setScale(-1, 1, center.x(), center.y()); 394 transform.setScale(-1, 1, center.x(), center.y());
401 } 395 }
402 } 396 }
403 path.transform(transform); 397 path.transform(transform);
404 398
405 return path; 399 return path;
406 } 400 }
407 401
402 gfx::RectF NativeThemeBase::BoundingRectForArrow(const gfx::Rect& rect) const {
Peter Kasting 2016/06/10 01:03:23 It seems like this whole function just does someth
Bret 2016/06/11 00:11:43 I managed to synthesize your suggestion with what
403 gfx::RectF bounding_rect(rect);
404 int padding_width = ceil(rect.width() / 4.f);
405 int padding_height = ceil(rect.height() / 4.f);
406 bounding_rect.Inset(padding_width, padding_height);
407
408 // Ensure bounding_rect is a square.
409 if (bounding_rect.width() > bounding_rect.height()) {
410 float square_adjust =
411 (bounding_rect.width() - bounding_rect.height()) / 2.f;
412 bounding_rect.Inset(0, -square_adjust);
413 if (bounding_rect.height() > rect.height()) {
414 float clamp_adjust = (bounding_rect.height() - rect.height()) / 2.f;
415 bounding_rect.Inset(clamp_adjust, clamp_adjust);
416 }
417 } else if (bounding_rect.height() > bounding_rect.width()) {
418 float square_adjust =
419 (bounding_rect.height() - bounding_rect.width()) / 2.f;
420 bounding_rect.Inset(-square_adjust, 0);
421 if (bounding_rect.width() > rect.width()) {
422 float clamp_adjust = (bounding_rect.width() - rect.width()) / 2.f;
423 bounding_rect.Inset(clamp_adjust, clamp_adjust);
424 }
425 }
426
427 // Snap bounding_rect to whole pixels.
428 bounding_rect.set_x(ceil(bounding_rect.x()));
429 bounding_rect.set_y(ceil(bounding_rect.y()));
430 // Width and height are always aligned to whole pixels.
431
432 return bounding_rect;
433 }
434
408 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, 435 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas,
409 Part part, 436 Part part,
410 State state, 437 State state,
411 const ScrollbarTrackExtraParams& extra_params, 438 const ScrollbarTrackExtraParams& extra_params,
412 const gfx::Rect& rect) const { 439 const gfx::Rect& rect) const {
413 SkPaint paint; 440 SkPaint paint;
414 SkIRect skrect; 441 SkIRect skrect;
415 442
416 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); 443 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom());
417 SkScalar track_hsv[3]; 444 SkScalar track_hsv[3];
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); 1035 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f);
1009 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); 1036 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f);
1010 1037
1011 if (hsv1[2] + hsv2[2] > 1.0) 1038 if (hsv1[2] + hsv2[2] > 1.0)
1012 diff = -diff; 1039 diff = -diff;
1013 1040
1014 return SaturateAndBrighten(hsv2, -0.2f, diff); 1041 return SaturateAndBrighten(hsv2, -0.2f, diff);
1015 } 1042 }
1016 1043
1017 } // namespace ui 1044 } // namespace ui
OLDNEW
« ui/native_theme/native_theme_base.h ('K') | « ui/native_theme/native_theme_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698