Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_win.cc

Issue 9985012: Adjust location of text in omnibox edit control for Metro. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as 489 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as
490 // of Rich Edit 2.0 onward. 490 // of Rich Edit 2.0 onward.
491 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, 491 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0,
492 reinterpret_cast<LPARAM>(&WordBreakProc)); 492 reinterpret_cast<LPARAM>(&WordBreakProc));
493 493
494 // Get the metrics for the font. 494 // Get the metrics for the font.
495 HDC hdc = ::GetDC(NULL); 495 HDC hdc = ::GetDC(NULL);
496 HGDIOBJ old_font = SelectObject(hdc, font_.GetNativeFont()); 496 HGDIOBJ old_font = SelectObject(hdc, font_.GetNativeFont());
497 TEXTMETRIC tm = {0}; 497 TEXTMETRIC tm = {0};
498 GetTextMetrics(hdc, &tm); 498 GetTextMetrics(hdc, &tm);
499 const float kXHeightRatio = 0.7f; // The ratio of a font's x-height to its 499 int cap_height = font_.GetBaseline() - tm.tmInternalLeading;
500 // cap height. Sadly, Windows doesn't 500 // The ratio of a font's x-height to its cap height. Sadly, Windows
501 // provide a true value for a font's 501 // doesn't provide a true value for a font's x-height in its text
502 // x-height in its text metrics, so we 502 // metrics, so we approximate.
503 // approximate. 503 const float kXHeightRatio = 0.7f;
504 font_x_height_ = static_cast<int>((static_cast<float>(font_.GetBaseline() - 504 font_x_height_ = static_cast<int>(
505 tm.tmInternalLeading) * kXHeightRatio) + 0.5); 505 (static_cast<float>(cap_height) * kXHeightRatio) + 0.5);
506 // The distance from the top of the field to the desired baseline of the 506
507 // rendered text. 507 // We set font_y_adjustment_ so that the ascender of the font gets
508 const int kTextBaseline = popup_window_mode_ ? 15 : 18; 508 // centered on the available height of the view.
509 font_y_adjustment_ = kTextBaseline - font_.GetBaseline(); 509 font_y_adjustment_ = (parent_view->GetHeight() - cap_height) / 2 -
510 tm.tmInternalLeading;
510 511
511 // Get the number of twips per pixel, which we need below to offset our text 512 // Get the number of twips per pixel, which we need below to offset our text
512 // by the desired number of pixels. 513 // by the desired number of pixels.
513 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(hdc, LOGPIXELSY); 514 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(hdc, LOGPIXELSY);
514 // It's unsafe to delete a DC with a non-stock object selected, so restore the 515 // It's unsafe to delete a DC with a non-stock object selected, so restore the
515 // original font. 516 // original font.
516 SelectObject(hdc, old_font); 517 SelectObject(hdc, old_font);
517 ::ReleaseDC(NULL, hdc); 518 ::ReleaseDC(NULL, hdc);
518 519
519 // Set the default character style -- adjust to our desired baseline. 520 // Set the default character style -- adjust to our desired baseline.
(...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 bool popup_window_mode, 2685 bool popup_window_mode,
2685 LocationBarView* location_bar) { 2686 LocationBarView* location_bar) {
2686 return new OmniboxViewWin(controller, 2687 return new OmniboxViewWin(controller,
2687 toolbar_model, 2688 toolbar_model,
2688 location_bar, 2689 location_bar,
2689 command_updater, 2690 command_updater,
2690 popup_window_mode, 2691 popup_window_mode,
2691 location_bar); 2692 location_bar);
2692 } 2693 }
2693 #endif 2694 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698