From 9d722ada61e1d80f0900a9ed7293b8da6e6153e8 Mon Sep 17 00:00:00 2001 From: "davemoore@chromium.org" Date: Fri, 23 Oct 2009 21:11:14 +0000 Subject: Get the About panel to align its links correctly, but undo a previous change to the way we measure strings in pango. Review URL: http://codereview.chromium.org/338001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29943 0039d316-1c4b-4281-b951-d872f2087c98 --- app/gfx/canvas_linux.cc | 10 ++-------- app/gfx/font_skia.cc | 1 - chrome/browser/chromeos/status_area_view.cc | 6 ------ chrome/browser/views/about_chrome_view.cc | 9 +++++++-- views/controls/label.cc | 7 ++++++- 5 files changed, 15 insertions(+), 18 deletions(-) mode change 100644 => 100755 app/gfx/canvas_linux.cc mode change 100644 => 100755 app/gfx/font_skia.cc mode change 100644 => 100755 chrome/browser/chromeos/status_area_view.cc mode change 100644 => 100755 chrome/browser/views/about_chrome_view.cc mode change 100644 => 100755 views/controls/label.cc diff --git a/app/gfx/canvas_linux.cc b/app/gfx/canvas_linux.cc old mode 100644 new mode 100755 index b08b4ce..e658c6a --- a/app/gfx/canvas_linux.cc +++ b/app/gfx/canvas_linux.cc @@ -154,11 +154,7 @@ void Canvas::SizeStringInt(const std::wstring& text, std::string utf8 = WideToUTF8(text); pango_layout_set_text(layout, utf8.data(), utf8.size()); - int chars_height; - pango_layout_get_size(layout, width, &chars_height); - *width /= PANGO_SCALE; - // Pango returns the height of the characters, not the height of the font. - *height = font.height(); + pango_layout_get_pixel_size(layout, width, height); g_object_unref(layout); cairo_destroy(cr); @@ -187,9 +183,7 @@ void Canvas::DrawStringInt(const std::wstring& text, pango_layout_set_text(layout, utf8.data(), utf8.size()); int width, height; - pango_layout_get_size(layout, &width, &height); - width /= PANGO_SCALE; - height /= PANGO_SCALE; + pango_layout_get_pixel_size(layout, &width, &height); if (flags & Canvas::TEXT_VALIGN_TOP) { // Cairo should draw from the top left corner already. diff --git a/app/gfx/font_skia.cc b/app/gfx/font_skia.cc old mode 100644 new mode 100755 index 37cbe8d..8f6ccc1 --- a/app/gfx/font_skia.cc +++ b/app/gfx/font_skia.cc @@ -187,7 +187,6 @@ double Font::avg_width() { int text_width = GetStringWidth( L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); double dialog_units = (text_width / 26 + 1) / 2; - avg_width_ = std::min(pango_width, dialog_units); pango_font_metrics_unref(pango_metrics); pango_font_description_free(pango_desc); diff --git a/chrome/browser/chromeos/status_area_view.cc b/chrome/browser/chromeos/status_area_view.cc old mode 100644 new mode 100755 index 59f4f9c..5b268dd --- a/chrome/browser/chromeos/status_area_view.cc +++ b/chrome/browser/chromeos/status_area_view.cc @@ -33,8 +33,6 @@ namespace { const int kLeftBorder = 1; // Number of pixels to separate the clock from the next item on the right. const int kClockSeparation = 4; -// Number of pixels to adjust the y value of the clock. -const int kClockYAdjustment = 2; // BrowserWindowGtk tiles its image with this offset const int kCustomFrameBackgroundVerticalOffset = 15; @@ -173,10 +171,6 @@ void StatusAreaView::Layout() { // Handle odd number of pixels. cur_y += (height() - cur_size.height()) % 2; - // Adjustment to make clock line up right. - if (cur == clock_view_) - cur_y += kClockYAdjustment; - // Put next in row horizontally, and center vertically. cur->SetBounds(cur_x, cur_y, cur_size.width(), cur_size.height()); diff --git a/chrome/browser/views/about_chrome_view.cc b/chrome/browser/views/about_chrome_view.cc old mode 100644 new mode 100755 index 63fabce..c4b2fdd --- a/chrome/browser/views/about_chrome_view.cc +++ b/chrome/browser/views/about_chrome_view.cc @@ -486,8 +486,13 @@ void AboutChromeView::DrawTextAndPositionUrl(gfx::Canvas* canvas, gfx::Size sz = link->GetPreferredSize(); gfx::Insets insets = link->GetInsets(); WrapIfWordDoesntFit(sz.width(), font.height(), position, bounds); - *rect = gfx::Rect(position->width(), position->height() - insets.top(), - sz.width(), sz.height()); + int x = position->width(); + int y = position->height(); + + // Links have a border to allow them to be focused. + y -= insets.top(); + + *rect = gfx::Rect(x, y, sz.width(), sz.height()); // Go from relative pixel coordinates (within the label we are drawing on) // to absolute pixel coordinates (relative to the top left corner of the diff --git a/views/controls/label.cc b/views/controls/label.cc old mode 100644 new mode 100755 index 6da6c48..6b17338 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -264,7 +264,12 @@ const GURL Label::GetURL() const { gfx::Size Label::GetTextSize() { if (!text_size_valid_) { - text_size_.SetSize(font_.GetStringWidth(text_), font_.height()); + int w = 0, h = 0; + gfx::Canvas cc(0, 0, true); + int flags = is_multi_line_ ? ComputeMultiLineFlags() : 0; + + cc.SizeStringInt(text_, font_, &w, &h, flags); + text_size_.SetSize(w, h); if (highlighted_) text_size_.Enlarge(1, 1); text_size_valid_ = true; -- cgit v1.1