Commit 48c48280 authored by joi@chromium.org's avatar joi@chromium.org

Adjust location of text in omnibox edit control for Metro.

BUG=126132


Review URL: https://chromiumcodereview.appspot.com/9985012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137616 0039d316-1c4b-4281-b951-d872f2087c98
parent fc438686
......@@ -179,8 +179,7 @@ void LocationBarView::Init() {
}
// If this makes the font too big, try to make it smaller so it will fit.
const int height =
std::max(GetPreferredSize().height() - (kVerticalEdgeThickness * 2), 0);
const int height = GetHeight();
while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1))
font_ = font_.DeriveFont(-1);
......@@ -1277,6 +1276,11 @@ void LocationBarView::Observe(int type,
}
}
int LocationBarView::GetHeight() {
return std::max(
GetPreferredSize().height() - (kVerticalEdgeThickness * 2), 0);
}
#if defined(OS_WIN) || defined(USE_AURA)
bool LocationBarView::HasValidSuggestText() const {
return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
......
......@@ -311,6 +311,9 @@ class LocationBarView : public LocationBar,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Calculates the height of the view.
int GetHeight();
// Space between items in the location bar.
static int GetItemPadding();
......
......@@ -496,17 +496,18 @@ OmniboxViewWin::OmniboxViewWin(AutocompleteEditController* controller,
HGDIOBJ old_font = SelectObject(hdc, font_.GetNativeFont());
TEXTMETRIC tm = {0};
GetTextMetrics(hdc, &tm);
const float kXHeightRatio = 0.7f; // The ratio of a font's x-height to its
// cap height. Sadly, Windows doesn't
// provide a true value for a font's
// x-height in its text metrics, so we
// approximate.
font_x_height_ = static_cast<int>((static_cast<float>(font_.GetBaseline() -
tm.tmInternalLeading) * kXHeightRatio) + 0.5);
// The distance from the top of the field to the desired baseline of the
// rendered text.
const int kTextBaseline = popup_window_mode_ ? 15 : 18;
font_y_adjustment_ = kTextBaseline - font_.GetBaseline();
int cap_height = font_.GetBaseline() - tm.tmInternalLeading;
// The ratio of a font's x-height to its cap height. Sadly, Windows
// doesn't provide a true value for a font's x-height in its text
// metrics, so we approximate.
const float kXHeightRatio = 0.7f;
font_x_height_ = static_cast<int>(
(static_cast<float>(cap_height) * kXHeightRatio) + 0.5);
// We set font_y_adjustment_ so that the ascender of the font gets
// centered on the available height of the view.
font_y_adjustment_ = (parent_view->GetHeight() - cap_height) / 2 -
tm.tmInternalLeading;
// Get the number of twips per pixel, which we need below to offset our text
// by the desired number of pixels.
......
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