Commit e90f4a7b authored by erg@chromium.org's avatar erg@chromium.org

linux_aura: Use the previous font sizes on the browser actions badge.

The #ifdefs in badge_util.cc had the chromeos code behind OS_LINUX &&
TOOLKIT_VIEWS, which is no longer just chromeos. Switch that block to
OS_CHROMEOS and use the old GTK+ hard coded settings in the Linux aura
build.

BUG=376335

Review URL: https://codereview.chromium.org/295263002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272674 0039d316-1c4b-4281-b951-d872f2087c98
parent b67aa0ef
......@@ -18,31 +18,31 @@
namespace {
// Different platforms need slightly different constants to look good.
#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
const float kTextSize = 9.0;
#if defined(OS_WIN)
const float kTextSize = 10;
const int kBottomMarginBrowserAction = 0;
const int kBottomMarginPageAction = 2;
const int kPadding = 2;
// The padding between the top of the badge and the top of the text.
const int kTopTextPadding = -1;
#elif defined(OS_MACOSX)
const float kTextSize = 9.0;
const int kBottomMarginBrowserAction = 5;
const int kBottomMarginPageAction = 2;
const int kPadding = 2;
const int kTopTextPadding = 0;
#elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
#elif defined(OS_CHROMEOS)
const float kTextSize = 8.0;
const int kBottomMarginBrowserAction = 0;
const int kBottomMarginPageAction = 2;
const int kPadding = 2;
const int kTopTextPadding = 1;
#elif defined(OS_MACOSX)
#elif defined(OS_POSIX)
const float kTextSize = 9.0;
const int kBottomMarginBrowserAction = 5;
const int kBottomMarginPageAction = 2;
const int kPadding = 2;
const int kTopTextPadding = 0;
#else
const float kTextSize = 10;
const int kBottomMarginBrowserAction = 0;
const int kBottomMarginPageAction = 2;
const int kPadding = 2;
// The padding between the top of the badge and the top of the text.
const int kTopTextPadding = -1;
const int kTopTextPadding = 0;
#endif
const int kBadgeHeight = 11;
......@@ -92,53 +92,6 @@ SkPaint* GetBadgeTextPaintSingleton() {
return text_paint;
}
SkBitmap DrawBadgeIconOverlay(const SkBitmap& icon,
float font_size,
const base::string16& text,
const base::string16& fallback) {
const int kMinPadding = 1;
// Calculate the proper style/text overlay to render on the badge.
SkPaint* paint = badge_util::GetBadgeTextPaintSingleton();
paint->setTextSize(SkFloatToScalar(font_size));
paint->setColor(SK_ColorWHITE);
std::string badge_text = base::UTF16ToUTF8(text);
// See if the text will fit - otherwise use a default.
SkScalar text_width = paint->measureText(badge_text.c_str(),
badge_text.size());
if (SkScalarRoundToInt(text_width) > (icon.width() - kMinPadding * 2)) {
// String is too large - use the alternate text.
badge_text = base::UTF16ToUTF8(fallback);
text_width = paint->measureText(badge_text.c_str(), badge_text.size());
}
// When centering the text, we need to make sure there are an equal number
// of pixels on each side as otherwise the text looks off-center. So if the
// padding would be uneven, clip one pixel off the right side.
int badge_width = icon.width();
if ((SkScalarRoundToInt(text_width) % 1) != (badge_width % 1))
badge_width--;
// Render the badge bitmap and overlay into a canvas.
scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas(
gfx::Size(badge_width, icon.height()), 1.0f, false));
canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(icon), 0, 0);
// Draw the text overlay centered horizontally and vertically. Skia expects
// us to specify the lower left coordinate of the text box, which is why we
// add 'font_size - 1' to the height.
SkScalar x = (badge_width - text_width)/2;
SkScalar y = (icon.height() - font_size)/2 + font_size - 1;
canvas->sk_canvas()->drawText(
badge_text.c_str(), badge_text.size(), x, y, *paint);
// Return the generated image.
return canvas->ExtractImageRep().sk_bitmap();
}
void PaintBadge(gfx::Canvas* canvas,
const gfx::Rect& bounds,
const std::string& text,
......
......@@ -26,14 +26,6 @@ namespace badge_util {
// rendering badge overlay text (correct font, typeface, etc).
SkPaint* GetBadgeTextPaintSingleton();
// Given an |icon|, renders the |text| centered on the |icon|. If |text| is
// too large to fit within the bounds of the image, the |fallback| string is
// rendered instead (or nothing, if |fallback| is empty).
SkBitmap DrawBadgeIconOverlay(const SkBitmap& icon,
float font_size_in_pixels,
const base::string16& text,
const base::string16& fallback);
// Paints badge with specified parameters to |canvas|.
void PaintBadge(gfx::Canvas* canvas,
const gfx::Rect& bounds,
......@@ -43,6 +35,6 @@ void PaintBadge(gfx::Canvas* canvas,
int icon_width,
extensions::ActionInfo::Type action_type);
} // namespace badge_util;
} // namespace badge_util
#endif // CHROME_COMMON_BADGE_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment