summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/shell/app_list.cc1
-rw-r--r--ui/gfx/canvas.h21
-rw-r--r--ui/gfx/canvas_skia.cc44
-rw-r--r--ui/gfx/pango_util.cc55
-rw-r--r--ui/gfx/pango_util.h7
-rw-r--r--ui/views/controls/menu/menu_item_view.cc2
-rw-r--r--ui/views/controls/menu/menu_item_view_views.cc2
-rw-r--r--ui/views/controls/menu/menu_item_view_win.cc2
-rw-r--r--ui/views/examples/text_example.cc28
-rw-r--r--ui/views/examples/text_example.h3
10 files changed, 43 insertions, 122 deletions
diff --git a/ash/shell/app_list.cc b/ash/shell/app_list.cc
index c18d9da..b7f915d 100644
--- a/ash/shell/app_list.cc
+++ b/ash/shell/app_list.cc
@@ -210,7 +210,6 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
SK_ColorBLACK,
0, 0, icon_size.width(), icon_size.height(),
gfx::Canvas::TEXT_ALIGN_CENTER |
- gfx::Canvas::TEXT_VALIGN_MIDDLE |
gfx::Canvas::NO_SUBPIXEL_RENDERING);
return gfx::ImageSkia(canvas.ExtractImageRep());
diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h
index 0e080fa..75a19ca 100644
--- a/ui/gfx/canvas.h
+++ b/ui/gfx/canvas.h
@@ -50,28 +50,25 @@ class UI_EXPORT Canvas {
enum {
TEXT_ALIGN_LEFT = 1 << 0,
TEXT_ALIGN_CENTER = 1 << 1,
- TEXT_ALIGN_RIGHT = 1 << 2 ,
- TEXT_VALIGN_TOP = 1 << 3,
- TEXT_VALIGN_MIDDLE = 1 << 4,
- TEXT_VALIGN_BOTTOM = 1 << 5,
+ TEXT_ALIGN_RIGHT = 1 << 2,
// Specifies the text consists of multiple lines.
- MULTI_LINE = 1 << 6,
+ MULTI_LINE = 1 << 3,
// By default DrawStringInt does not process the prefix ('&') character
// specially. That is, the string "&foo" is rendered as "&foo". When
// rendering text from a resource that uses the prefix character for
// mnemonics, the prefix should be processed and can be rendered as an
// underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX).
- SHOW_PREFIX = 1 << 7,
- HIDE_PREFIX = 1 << 8,
+ SHOW_PREFIX = 1 << 4,
+ HIDE_PREFIX = 1 << 5,
// Prevent ellipsizing
- NO_ELLIPSIS = 1 << 9,
+ NO_ELLIPSIS = 1 << 6,
// Specifies if words can be split by new lines.
// This only works with MULTI_LINE.
- CHARACTER_BREAK = 1 << 10,
+ CHARACTER_BREAK = 1 << 7,
// Instructs DrawStringInt() to render the text using RTL directionality.
// In most cases, passing this flag is not necessary because information
@@ -81,16 +78,16 @@ class UI_EXPORT Canvas {
// platforms (for example, an English Windows XP with no RTL fonts
// installed) don't support these characters. Thus, this flag should be
// used to render text using RTL directionality when the locale is LTR.
- FORCE_RTL_DIRECTIONALITY = 1 << 11,
+ FORCE_RTL_DIRECTIONALITY = 1 << 8,
// Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right.
// See FORCE_RTL_DIRECTIONALITY for details.
- FORCE_LTR_DIRECTIONALITY = 1 << 12,
+ FORCE_LTR_DIRECTIONALITY = 1 << 9,
// Instructs DrawStringInt() to not use subpixel rendering. This is useful
// when rendering text onto a fully- or partially-transparent background
// that will later be blended with another image.
- NO_SUBPIXEL_RENDERING = 1 << 13,
+ NO_SUBPIXEL_RENDERING = 1 << 10,
};
// Creates an empty canvas with scale factor of 1x.
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index 6748c6a..baa4db9 100644
--- a/ui/gfx/canvas_skia.cc
+++ b/ui/gfx/canvas_skia.cc
@@ -80,20 +80,6 @@ bool PixelShouldGetHalo(const SkBitmap& bitmap,
return false;
}
-// Apply vertical alignment per |flags|. Returns y-coordinate delta.
-int VAlignText(int text_height,
- int flags,
- int available_height) {
- if (flags & gfx::Canvas::TEXT_VALIGN_TOP)
- return 0;
-
- if (flags & gfx::Canvas::TEXT_VALIGN_BOTTOM)
- return available_height - text_height;
-
- // Default case: TEXT_VALIGN_MIDDLE.
- return (available_height - text_height) / 2;
-}
-
// Strips accelerator character prefixes in |text| if needed, based on |flags|.
// Returns a range in |text| to underline or ui::Range::InvalidRange() if
// underlining is not needed.
@@ -262,15 +248,6 @@ void Canvas::DrawStringWithShadows(const string16& text,
flags = AdjustPlatformSpecificFlags(text, flags);
-#if defined(OS_WIN)
- // TODO(asvitkine): On Windows, MULTI_LINE implies top alignment.
- // http://crbug.com/107357
- if (flags & MULTI_LINE) {
- flags &= ~(TEXT_VALIGN_MIDDLE | TEXT_VALIGN_BOTTOM);
- flags |= TEXT_VALIGN_TOP;
- }
-#endif
-
gfx::Rect clip_rect(text_bounds);
clip_rect.Inset(ShadowValue::GetMargin(shadows));
@@ -304,16 +281,17 @@ void Canvas::DrawStringWithShadows(const string16& text,
for (size_t i = 0; i < strings.size(); i++) {
ui::Range range = StripAcceleratorChars(flags, &strings[i]);
UpdateRenderText(rect, strings[i], font, flags, color, render_text.get());
-
- // Apply vertical alignment over the block of text using the height of the
- // first line. This may not be correct if different lines in the text have
- // different heights, but avoids needing to do two passes.
const int line_height = render_text->GetStringSize().height();
+
+ // TODO(msw|asvitkine): Center Windows multi-line text: crbug.com/107357
+#if !defined(OS_WIN)
if (i == 0) {
- rect.Offset(0, VAlignText(strings.size() * line_height,
- flags,
- text_bounds.height()));
+ // TODO(msw|asvitkine): Support multi-line text with varied heights.
+ const int aggregate_height = strings.size() * line_height;
+ rect.Offset(0, (text_bounds.height() - aggregate_height) / 2);
}
+#endif
+
rect.set_height(line_height);
ApplyUnderlineStyle(range, render_text.get());
@@ -348,7 +326,8 @@ void Canvas::DrawStringWithShadows(const string16& text,
render_text.get());
const int line_height = render_text->GetStringSize().height();
- rect.Offset(0, VAlignText(line_height, flags, text_bounds.height()));
+ // Center the text vertically.
+ rect.Offset(0, (text_bounds.height() - line_height) / 2);
rect.set_height(line_height);
render_text->SetDisplayRect(rect);
@@ -466,7 +445,8 @@ void Canvas::DrawFadeTruncatingString(
UpdateRenderText(rect, clipped_text, font, flags, color, render_text.get());
const int line_height = render_text->GetStringSize().height();
- rect.Offset(0, VAlignText(line_height, flags, display_rect.height()));
+ // Center the text vertically.
+ rect.Offset(0, (display_rect.height() - line_height) / 2);
rect.set_height(line_height);
render_text->SetDisplayRect(rect);
diff --git a/ui/gfx/pango_util.cc b/ui/gfx/pango_util.cc
index 638f77c..b3e102e 100644
--- a/ui/gfx/pango_util.cc
+++ b/ui/gfx/pango_util.cc
@@ -27,6 +27,8 @@
#include <gdk/gdk.h>
#endif
+namespace gfx {
+
namespace {
// Marker for accelerators in the text.
@@ -49,23 +51,23 @@ cairo_font_options_t* GetCairoFontOptions() {
cairo_font_options = cairo_font_options_create();
- const gfx::FontRenderParams& params = gfx::GetDefaultFontRenderParams();
- gfx::FontRenderParams::SubpixelRendering subpixel = params.subpixel_rendering;
+ const FontRenderParams& params = GetDefaultFontRenderParams();
+ FontRenderParams::SubpixelRendering subpixel = params.subpixel_rendering;
if (!params.antialiasing) {
cairo_font_options_set_antialias(cairo_font_options, CAIRO_ANTIALIAS_NONE);
- } else if (subpixel == gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE) {
+ } else if (subpixel == FontRenderParams::SUBPIXEL_RENDERING_NONE) {
cairo_font_options_set_antialias(cairo_font_options, CAIRO_ANTIALIAS_GRAY);
} else {
cairo_font_options_set_antialias(cairo_font_options,
CAIRO_ANTIALIAS_SUBPIXEL);
cairo_subpixel_order_t cairo_subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
- if (subpixel == gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB)
+ if (subpixel == FontRenderParams::SUBPIXEL_RENDERING_RGB)
cairo_subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
- else if (subpixel == gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR)
+ else if (subpixel == FontRenderParams::SUBPIXEL_RENDERING_BGR)
cairo_subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
- else if (subpixel == gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB)
+ else if (subpixel == FontRenderParams::SUBPIXEL_RENDERING_VRGB)
cairo_subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
- else if (subpixel == gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR)
+ else if (subpixel == FontRenderParams::SUBPIXEL_RENDERING_VBGR)
cairo_subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
else
NOTREACHED() << "Unhandled subpixel rendering type " << subpixel;
@@ -73,7 +75,7 @@ cairo_font_options_t* GetCairoFontOptions() {
cairo_subpixel_order);
}
- if (params.hinting == gfx::FontRenderParams::HINTING_NONE ||
+ if (params.hinting == FontRenderParams::HINTING_NONE ||
params.subpixel_positioning) {
cairo_font_options_set_hint_style(cairo_font_options,
CAIRO_HINT_STYLE_NONE);
@@ -81,11 +83,11 @@ cairo_font_options_t* GetCairoFontOptions() {
CAIRO_HINT_METRICS_OFF);
} else {
cairo_hint_style_t cairo_hint_style = CAIRO_HINT_STYLE_DEFAULT;
- if (params.hinting == gfx::FontRenderParams::HINTING_SLIGHT)
+ if (params.hinting == FontRenderParams::HINTING_SLIGHT)
cairo_hint_style = CAIRO_HINT_STYLE_SLIGHT;
- else if (params.hinting == gfx::FontRenderParams::HINTING_MEDIUM)
+ else if (params.hinting == FontRenderParams::HINTING_MEDIUM)
cairo_hint_style = CAIRO_HINT_STYLE_MEDIUM;
- else if (params.hinting == gfx::FontRenderParams::HINTING_FULL)
+ else if (params.hinting == FontRenderParams::HINTING_FULL)
cairo_hint_style = CAIRO_HINT_STYLE_FULL;
else
NOTREACHED() << "Unhandled hinting style " << params.hinting;
@@ -108,7 +110,7 @@ float GetPixelsInPoint() {
// http://goo.gl/UIh5m: "This is a scale factor between points specified in
// a PangoFontDescription and Cairo units. The default value is 96, meaning
// that a 10 point font will be 13 units high. (10 * 96. / 72. = 13.3)."
- double pango_dpi = gfx::GetPangoResolution();
+ double pango_dpi = GetPangoResolution();
if (pango_dpi <= 0)
pango_dpi = 96.0;
pixels_in_point = pango_dpi / 72.0; // 72 points in an inch
@@ -120,8 +122,6 @@ float GetPixelsInPoint() {
} // namespace
-namespace gfx {
-
PangoContext* GetPangoContext() {
#if defined(USE_AURA)
PangoFontMap* font_map = pango_cairo_font_map_get_default();
@@ -153,7 +153,6 @@ void DrawTextOntoCairoSurface(cairo_t* cr,
PangoLayout* layout = pango_cairo_create_layout(cr);
base::i18n::TextDirection text_direction =
base::i18n::GetFirstStrongCharacterDirection(text);
- Rect text_rect(bounds.x(), bounds.y(), 0, 0);
DCHECK(!bounds.IsEmpty());
gfx::SetupPangoLayout(
@@ -165,7 +164,11 @@ void DrawTextOntoCairoSurface(cairo_t* cr,
cairo_rectangle(cr, clip.x(), clip.y(), clip.width(), clip.height());
cairo_clip(cr);
- AdjustTextRectBasedOnLayout(layout, bounds, flags, &text_rect);
+ int width = 0, height = 0;
+ pango_layout_get_pixel_size(layout, &width, &height);
+ Rect text_rect(bounds.x(), bounds.y(), width, height);
+ // Vertically center |text_rect| in |bounds|.
+ text_rect.Offset(0, (bounds.height() - text_rect.height()) / 2);
DrawPangoLayout(cr, layout, font, bounds, text_rect,
text_color, text_direction, flags);
@@ -301,26 +304,6 @@ void SetupPangoLayoutWithFontDescription(
pango_layout_set_font_description(layout, desc.get());
}
-void AdjustTextRectBasedOnLayout(PangoLayout* layout,
- const gfx::Rect& bounds,
- int flags,
- gfx::Rect* text_rect) {
- int text_width, text_height;
- pango_layout_get_pixel_size(layout, &text_width, &text_height);
- text_rect->set_width(text_width);
- text_rect->set_height(text_height);
-
- if (flags & gfx::Canvas::TEXT_VALIGN_TOP) {
- // Cairo should draw from the top left corner already.
- } else if (flags & gfx::Canvas::TEXT_VALIGN_BOTTOM) {
- text_rect->set_y(text_rect->y() + bounds.height() - text_rect->height());
- } else {
- // Vertically centered.
- text_rect->set_y(text_rect->y() +
- ((bounds.height() - text_rect->height()) / 2));
- }
-}
-
void DrawPangoLayout(cairo_t* cr,
PangoLayout* layout,
const Font& font,
diff --git a/ui/gfx/pango_util.h b/ui/gfx/pango_util.h
index 533d2b0..a672135 100644
--- a/ui/gfx/pango_util.h
+++ b/ui/gfx/pango_util.h
@@ -84,13 +84,6 @@ void SetupPangoLayoutWithFontDescription(
base::i18n::TextDirection text_direction,
int flags);
-// Get Pango's calculated size of |layout| and modify |text_rect| within
-// |bounds|.
-void AdjustTextRectBasedOnLayout(PangoLayout* layout,
- const gfx::Rect& bounds,
- int flags,
- gfx::Rect* text_rect);
-
// Draws the |layout| (pango tuple of font, actual text, etc) onto |cr| using
// |text_color| as the cairo pattern.
void DrawPangoLayout(cairo_t* cr,
diff --git a/ui/views/controls/menu/menu_item_view.cc b/ui/views/controls/menu/menu_item_view.cc
index 1b258e5..af1fd1e 100644
--- a/ui/views/controls/menu/menu_item_view.cc
+++ b/ui/views/controls/menu/menu_item_view.cc
@@ -747,7 +747,7 @@ void MenuItemView::PaintAccelerator(gfx::Canvas* canvas) {
gfx::Rect accel_bounds(width() - accel_right_margin - max_accel_width,
GetTopMargin(), max_accel_width, available_height);
accel_bounds.set_x(GetMirroredXForRect(accel_bounds));
- int flags = GetDrawStringFlags() | gfx::Canvas::TEXT_VALIGN_MIDDLE;
+ int flags = GetDrawStringFlags();
flags &= ~(gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT);
if (base::i18n::IsRTL())
flags |= gfx::Canvas::TEXT_ALIGN_LEFT;
diff --git a/ui/views/controls/menu/menu_item_view_views.cc b/ui/views/controls/menu/menu_item_view_views.cc
index e158d6f..79fe29b 100644
--- a/ui/views/controls/menu/menu_item_view_views.cc
+++ b/ui/views/controls/menu/menu_item_view_views.cc
@@ -75,7 +75,7 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
int width = this->width() - item_right_margin_ - label_start_ - accel_width;
gfx::Rect text_bounds(label_start_, top_margin, width, available_height);
text_bounds.set_x(GetMirroredXForRect(text_bounds));
- int flags = GetDrawStringFlags() | gfx::Canvas::TEXT_VALIGN_MIDDLE;
+ int flags = GetDrawStringFlags();
if (mode == PB_FOR_DRAG)
flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
canvas->DrawStringInt(title(), font, fg_color,
diff --git a/ui/views/controls/menu/menu_item_view_win.cc b/ui/views/controls/menu/menu_item_view_win.cc
index 54bfd90..a8b56e4 100644
--- a/ui/views/controls/menu/menu_item_view_win.cc
+++ b/ui/views/controls/menu/menu_item_view_win.cc
@@ -89,7 +89,7 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width();
int width = this->width() - item_right_margin_ - label_start_ - accel_width;
int height = this->height() - GetTopMargin() - GetBottomMargin();
- int flags = gfx::Canvas::TEXT_VALIGN_MIDDLE | GetDrawStringFlags();
+ int flags = GetDrawStringFlags();
gfx::Rect text_bounds(label_start_, top_margin, width, height);
text_bounds.set_x(GetMirroredXForRect(text_bounds));
if (mode == PB_FOR_DRAG) {
diff --git a/ui/views/examples/text_example.cc b/ui/views/examples/text_example.cc
index e6298e2..5fb6662 100644
--- a/ui/views/examples/text_example.cc
+++ b/ui/views/examples/text_example.cc
@@ -68,13 +68,6 @@ const char* kHorizontalAligments[] = {
"Right",
};
-const char* kVerticalAlignments[] = {
- "Default",
- "Top",
- "Middle",
- "Bottom",
-};
-
// Toggles bit |flag| on |flags| based on state of |checkbox|.
void SetFlagFromCheckbox(Checkbox* checkbox, int* flags, int flag) {
if (checkbox->checked())
@@ -222,10 +215,6 @@ void TextExample::CreateExampleView(View* container) {
"H-Align",
kHorizontalAligments,
arraysize(kHorizontalAligments));
- v_align_cb_ = AddCombobox(layout,
- "V-Align",
- kVerticalAlignments,
- arraysize(kVerticalAlignments));
eliding_cb_ = AddCombobox(layout,
"Eliding",
kElidingBehaviors,
@@ -293,23 +282,6 @@ void TextExample::OnSelectedIndexChanged(Combobox* combobox) {
text_flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
break;
}
- } else if (combobox == v_align_cb_) {
- text_flags &= ~(gfx::Canvas::TEXT_VALIGN_TOP |
- gfx::Canvas::TEXT_VALIGN_MIDDLE |
- gfx::Canvas::TEXT_VALIGN_BOTTOM);
- switch (combobox->selected_index()) {
- case 0:
- break;
- case 1:
- text_flags |= gfx::Canvas::TEXT_VALIGN_TOP;
- break;
- case 2:
- text_flags |= gfx::Canvas::TEXT_VALIGN_MIDDLE;
- break;
- case 3:
- text_flags |= gfx::Canvas::TEXT_VALIGN_BOTTOM;
- break;
- }
} else if (combobox == text_cb_) {
switch (combobox->selected_index()) {
case 0:
diff --git a/ui/views/examples/text_example.h b/ui/views/examples/text_example.h
index 3284990..007f519 100644
--- a/ui/views/examples/text_example.h
+++ b/ui/views/examples/text_example.h
@@ -53,9 +53,6 @@ class TextExample : public ExampleBase,
// Combo box for horizontal text alignment.
Combobox* h_align_cb_;
- // Combo box for vertical text alignment.
- Combobox* v_align_cb_;
-
// Combo box for text eliding style.
Combobox* eliding_cb_;