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

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: no floats allowed 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
« no previous file with comments | « ui/native_theme/native_theme_base.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 // 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "third_party/skia/include/core/SkPaint.h" 12 #include "third_party/skia/include/core/SkPaint.h"
13 #include "third_party/skia/include/core/SkPath.h" 13 #include "third_party/skia/include/core/SkPath.h"
14 #include "third_party/skia/include/effects/SkGradientShader.h" 14 #include "third_party/skia/include/effects/SkGradientShader.h"
15 #include "ui/base/layout.h" 15 #include "ui/base/layout.h"
16 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/base/ui_base_switches.h" 17 #include "ui/base/ui_base_switches.h"
18 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/color_palette.h" 19 #include "ui/gfx/color_palette.h"
20 #include "ui/gfx/color_utils.h" 20 #include "ui/gfx/color_utils.h"
21 #include "ui/gfx/geometry/rect.h" 21 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/geometry/rect_f.h"
22 #include "ui/gfx/geometry/size.h" 23 #include "ui/gfx/geometry/size.h"
23 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
24 #include "ui/gfx/skia_util.h" 25 #include "ui/gfx/skia_util.h"
25 #include "ui/native_theme/common_theme.h" 26 #include "ui/native_theme/common_theme.h"
26 #include "ui/resources/grit/ui_resources.h" 27 #include "ui/resources/grit/ui_resources.h"
27 28
28 namespace { 29 namespace {
29 30
30 // These are the default dimensions of radio buttons and checkboxes. 31 // These are the default dimensions of radio buttons and checkboxes.
31 const int kCheckboxAndRadioWidth = 13; 32 const int kCheckboxAndRadioWidth = 13;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 SkPaint paint; 362 SkPaint paint;
362 paint.setColor(color); 363 paint.setColor(color);
363 364
364 SkPath path = PathForArrow(rect, direction); 365 SkPath path = PathForArrow(rect, direction);
365 366
366 gc->drawPath(path, paint); 367 gc->drawPath(path, paint);
367 } 368 }
368 369
369 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, 370 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect,
370 Part direction) const { 371 Part direction) const {
371 gfx::Rect bounding_rect(rect); 372 gfx::Rect bounding_rect = BoundingRectForArrow(rect);
372 const int padding_width = ceil(rect.width() / 4.f); 373 const gfx::PointF center = gfx::RectF(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; 374 SkPath path;
378 SkMatrix transform; 375 SkMatrix transform;
379 transform.setIdentity(); 376 transform.setIdentity();
380 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { 377 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) {
381 int arrow_altitude = bounding_rect.height() / 2 + 1; 378 int arrow_altitude = bounding_rect.height() / 2 + 1;
382 path.moveTo(bounding_rect.x(), bounding_rect.bottom()); 379 path.moveTo(bounding_rect.x(), bounding_rect.bottom());
383 path.rLineTo(bounding_rect.width(), 0); 380 path.rLineTo(bounding_rect.width(), 0);
384 path.rLineTo(-bounding_rect.width() / 2.0f, -arrow_altitude); 381 path.rLineTo(-bounding_rect.width() / 2.0f, -arrow_altitude);
385 path.close(); 382 path.close();
386 path.offset(0, -arrow_altitude / 2 + 1); 383 path.offset(0, -arrow_altitude / 2 + 1);
387 if (direction == kScrollbarDownArrow) { 384 if (direction == kScrollbarDownArrow) {
388 path.offset(0, -1);
389 transform.setScale(1, -1, center.x(), center.y()); 385 transform.setScale(1, -1, center.x(), center.y());
390 } 386 }
391 } else { 387 } else {
392 int arrow_altitude = bounding_rect.width() / 2 + 1; 388 int arrow_altitude = bounding_rect.width() / 2 + 1;
393 path.moveTo(bounding_rect.x(), bounding_rect.y()); 389 path.moveTo(bounding_rect.x(), bounding_rect.y());
394 path.rLineTo(0, bounding_rect.height()); 390 path.rLineTo(0, bounding_rect.height());
395 path.rLineTo(arrow_altitude, -bounding_rect.height() / 2.0f); 391 path.rLineTo(arrow_altitude, -bounding_rect.height() / 2.0f);
396 path.close(); 392 path.close();
397 path.offset(arrow_altitude / 2, 0); 393 path.offset(arrow_altitude / 2, 0);
398 if (direction == kScrollbarLeftArrow) { 394 if (direction == kScrollbarLeftArrow) {
399 path.offset(-1, 0);
400 transform.setScale(-1, 1, center.x(), center.y()); 395 transform.setScale(-1, 1, center.x(), center.y());
401 } 396 }
402 } 397 }
403 path.transform(transform); 398 path.transform(transform);
404 399
405 return path; 400 return path;
406 } 401 }
407 402
403 gfx::Rect NativeThemeBase::BoundingRectForArrow(const gfx::Rect& rect) const {
404 const std::pair<int, int> rect_sides =
405 std::minmax(rect.width(), rect.height());
406 const int side_length_inset = 2 * std::ceil(rect_sides.second / 4.f);
407 const int side_length =
408 std::min(rect_sides.first, rect_sides.second - side_length_inset);
409 // When there are an odd number of pixels, put the extra on the top/left.
410 return gfx::Rect(rect.x() + (rect.width() - side_length + 1) / 2,
411 rect.y() + (rect.height() - side_length + 1) / 2,
412 side_length, side_length);
413 }
414
408 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, 415 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas,
409 Part part, 416 Part part,
410 State state, 417 State state,
411 const ScrollbarTrackExtraParams& extra_params, 418 const ScrollbarTrackExtraParams& extra_params,
412 const gfx::Rect& rect) const { 419 const gfx::Rect& rect) const {
413 SkPaint paint; 420 SkPaint paint;
414 SkIRect skrect; 421 SkIRect skrect;
415 422
416 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); 423 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom());
417 SkScalar track_hsv[3]; 424 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); 1015 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); 1016 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f);
1010 1017
1011 if (hsv1[2] + hsv2[2] > 1.0) 1018 if (hsv1[2] + hsv2[2] > 1.0)
1012 diff = -diff; 1019 diff = -diff;
1013 1020
1014 return SaturateAndBrighten(hsv2, -0.2f, diff); 1021 return SaturateAndBrighten(hsv2, -0.2f, diff);
1015 } 1022 }
1016 1023
1017 } // namespace ui 1024 } // namespace ui
OLDNEW
« no previous file with comments | « 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