summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-17 02:21:47 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-17 02:21:47 +0000
commit48c48280d9bba44ff14c3c665e9ef63c32c0e173 (patch)
treeb0acedd152633f94cd5d9b803e6bdd1ded1dd5cf
parentfc43868654630100e0f5dd7beef20464ea434679 (diff)
downloadchromium_src-48c48280d9bba44ff14c3c665e9ef63c32c0e173.zip
chromium_src-48c48280d9bba44ff14c3c665e9ef63c32c0e173.tar.gz
chromium_src-48c48280d9bba44ff14c3c665e9ef63c32c0e173.tar.bz2
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
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc8
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.h3
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_win.cc23
3 files changed, 21 insertions, 13 deletions
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index 1f2823d..c107fbd 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -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() &&
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h
index 49a70c7..26cdfc8 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.h
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.h
@@ -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();
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
index 1607df0..782c9b0 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc
@@ -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.