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

Side by Side Diff: views/controls/menu/menu_image_util_gtk.cc

Issue 7464027: Wayland support for views. views_desktop on Wayland. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated native_widget_wayland.cc to match compositor changes Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « views/controls/menu/menu_image_util_gtk.h ('k') | views/controls/menu/menu_image_util_linux.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "views/controls/menu/menu_image_util_gtk.h"
6
7 #include "base/i18n/rtl.h"
8 #include "grit/ui_resources.h"
9 #include "third_party/skia/include/effects/SkGradientShader.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/canvas_skia.h"
12
13 namespace {
14
15 // Size of the radio button inciator.
16 const int kSelectedIndicatorSize = 5;
17 const int kIndicatorSize = 10;
18
19 // Used for the radio indicator. See theme_draw for details.
20 const double kGradientStop = .5;
21 const SkColor kGradient0 = SkColorSetRGB(255, 255, 255);
22 const SkColor kGradient1 = SkColorSetRGB(255, 255, 255);
23 const SkColor kGradient2 = SkColorSetRGB(0xD8, 0xD8, 0xD8);
24 const SkColor kBaseStroke = SkColorSetRGB(0x8F, 0x8F, 0x8F);
25 const SkColor kRadioButtonIndicatorGradient0 = SkColorSetRGB(0, 0, 0);
26 const SkColor kRadioButtonIndicatorGradient1 = SkColorSetRGB(0x83, 0x83, 0x83);
27 const SkColor kIndicatorStroke = SkColorSetRGB(0, 0, 0);
28
29 SkBitmap* CreateRadioButtonImage(bool selected) {
30 // + 2 (1px on each side) to cover rounding error.
31 gfx::CanvasSkia canvas(kIndicatorSize + 2, kIndicatorSize + 2, false);
32 canvas.TranslateInt(1, 1);
33
34 SkPoint gradient_points[3];
35 gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0));
36 gradient_points[1].set(
37 SkIntToScalar(0),
38 SkIntToScalar(static_cast<int>(kIndicatorSize * kGradientStop)));
39 gradient_points[2].set(SkIntToScalar(0), SkIntToScalar(kIndicatorSize));
40 SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 };
41 SkShader* shader = SkGradientShader::CreateLinear(
42 gradient_points, gradient_colors, NULL, arraysize(gradient_points),
43 SkShader::kClamp_TileMode, NULL);
44 SkPaint paint;
45 paint.setStyle(SkPaint::kFill_Style);
46 paint.setAntiAlias(true);
47 paint.setShader(shader);
48 shader->unref();
49 int radius = kIndicatorSize / 2;
50 canvas.drawCircle(radius, radius, radius, paint);
51
52 paint.setStrokeWidth(SkIntToScalar(0));
53 paint.setShader(NULL);
54 paint.setStyle(SkPaint::kStroke_Style);
55 paint.setColor(kBaseStroke);
56 canvas.drawCircle(radius, radius, radius, paint);
57
58 if (selected) {
59 SkPoint selected_gradient_points[2];
60 selected_gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0));
61 selected_gradient_points[1].set(
62 SkIntToScalar(0),
63 SkIntToScalar(kSelectedIndicatorSize));
64 SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0,
65 kRadioButtonIndicatorGradient1 };
66 shader = SkGradientShader::CreateLinear(
67 selected_gradient_points, selected_gradient_colors, NULL,
68 arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL);
69 paint.setShader(shader);
70 shader->unref();
71 paint.setStyle(SkPaint::kFill_Style);
72 canvas.drawCircle(radius, radius,
73 kSelectedIndicatorSize / 2, paint);
74
75 paint.setStrokeWidth(SkIntToScalar(0));
76 paint.setShader(NULL);
77 paint.setStyle(SkPaint::kStroke_Style);
78 paint.setColor(kIndicatorStroke);
79 canvas.drawCircle(radius, radius,
80 kSelectedIndicatorSize / 2, paint);
81 }
82 return new SkBitmap(canvas.ExtractBitmap());
83 }
84
85 SkBitmap* GetRtlSubmenuArrowImage() {
86 static SkBitmap* kRtlArrow = NULL;
87 if (!kRtlArrow) {
88 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
89 SkBitmap* r = rb.GetBitmapNamed(IDR_MENU_ARROW);
90 gfx::CanvasSkia canvas(r->width(), r->height(), false);
91 canvas.ScaleInt(-1, 1);
92 canvas.DrawBitmapInt(*r, - r->width(), 0);
93 kRtlArrow = new SkBitmap(canvas.ExtractBitmap());
94 }
95 return kRtlArrow;
96 }
97
98 } // namespace
99
100 namespace views {
101
102 const SkBitmap* GetRadioButtonImage(bool selected) {
103 static const SkBitmap* kRadioOn = CreateRadioButtonImage(true);
104 static const SkBitmap* kRadioOff = CreateRadioButtonImage(false);
105
106 return selected ? kRadioOn : kRadioOff;
107 }
108
109 const SkBitmap* GetSubmenuArrowImage() {
110 return base::i18n::IsRTL() ?
111 GetRtlSubmenuArrowImage() :
112 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_MENU_ARROW);
113 }
114
115 } // namespace views;
OLDNEW
« no previous file with comments | « views/controls/menu/menu_image_util_gtk.h ('k') | views/controls/menu/menu_image_util_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698