| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <locale> | 8 #include <locale> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 GetTextMetrics(screen_dc, &tm); | 516 GetTextMetrics(screen_dc, &tm); |
| 517 int cap_height = font_list_.GetBaseline() - tm.tmInternalLeading; | 517 int cap_height = font_list_.GetBaseline() - tm.tmInternalLeading; |
| 518 // The ratio of a font's x-height to its cap height. Sadly, Windows | 518 // The ratio of a font's x-height to its cap height. Sadly, Windows |
| 519 // doesn't provide a true value for a font's x-height in its text | 519 // doesn't provide a true value for a font's x-height in its text |
| 520 // metrics, so we approximate. | 520 // metrics, so we approximate. |
| 521 const float kXHeightRatio = 0.7f; | 521 const float kXHeightRatio = 0.7f; |
| 522 font_x_height_ = static_cast<int>( | 522 font_x_height_ = static_cast<int>( |
| 523 (static_cast<float>(cap_height) * kXHeightRatio) + 0.5); | 523 (static_cast<float>(cap_height) * kXHeightRatio) + 0.5); |
| 524 // Determine the y offset centering cap height. | 524 // Determine the y offset centering cap height. |
| 525 const int location_height = location_bar_->GetInternalHeight(true); | 525 const int location_height = location_bar_->GetInternalHeight(true); |
| 526 font_y_adjustment_ = std::max(0, | 526 font_y_adjustment_ = std::max( |
| 527 int((location_height - cap_height) / 2 - tm.tmInternalLeading)); | 527 0, |
| 528 static_cast<int>((location_height - cap_height) / 2 - |
| 529 tm.tmInternalLeading)); |
| 528 | 530 |
| 529 // Get the number of twips per pixel, which we need below to offset our text | 531 // Get the number of twips per pixel, which we need below to offset our text |
| 530 // by the desired number of pixels. | 532 // by the desired number of pixels. |
| 531 const long kTwipsPerPixel = | 533 const long kTwipsPerPixel = |
| 532 kTwipsPerInch / GetDeviceCaps(screen_dc, LOGPIXELSY); | 534 kTwipsPerInch / GetDeviceCaps(screen_dc, LOGPIXELSY); |
| 533 | 535 |
| 534 // Set the default character style -- adjust to our desired baseline. | 536 // Set the default character style -- adjust to our desired baseline. |
| 535 CHARFORMAT cf = {0}; | 537 CHARFORMAT cf = {0}; |
| 536 cf.dwMask = CFM_OFFSET; | 538 cf.dwMask = CFM_OFFSET; |
| 537 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; | 539 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; |
| (...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2802 } | 2804 } |
| 2803 | 2805 |
| 2804 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2806 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
| 2805 // Use font_list_.GetPrimaryFont().GetStringWidth() instead of | 2807 // Use font_list_.GetPrimaryFont().GetStringWidth() instead of |
| 2806 // PosFromChar(GetTextLength()) because PosFromChar() is apparently buggy. | 2808 // PosFromChar(GetTextLength()) because PosFromChar() is apparently buggy. |
| 2807 // In both LTR UI and RTL UI with left-to-right layout, PosFromChar(i) might | 2809 // In both LTR UI and RTL UI with left-to-right layout, PosFromChar(i) might |
| 2808 // return 0 when i is greater than 1. | 2810 // return 0 when i is greater than 1. |
| 2809 return font_list_.GetPrimaryFont().GetStringWidth(text) + | 2811 return font_list_.GetPrimaryFont().GetStringWidth(text) + |
| 2810 GetHorizontalMargin(); | 2812 GetHorizontalMargin(); |
| 2811 } | 2813 } |
| OLD | NEW |