Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 // to set offsets. | 429 // to set offsets. |
| 430 const int kTwipsPerInch = 1440; | 430 const int kTwipsPerInch = 1440; |
| 431 | 431 |
| 432 } // namespace | 432 } // namespace |
| 433 | 433 |
| 434 OmniboxViewWin::OmniboxViewWin(AutocompleteEditController* controller, | 434 OmniboxViewWin::OmniboxViewWin(AutocompleteEditController* controller, |
| 435 ToolbarModel* toolbar_model, | 435 ToolbarModel* toolbar_model, |
| 436 LocationBarView* parent_view, | 436 LocationBarView* parent_view, |
| 437 CommandUpdater* command_updater, | 437 CommandUpdater* command_updater, |
| 438 bool popup_window_mode, | 438 bool popup_window_mode, |
| 439 int height, | |
| 439 views::View* location_bar) | 440 views::View* location_bar) |
| 440 : model_(new AutocompleteEditModel(this, controller, | 441 : model_(new AutocompleteEditModel(this, controller, |
| 441 parent_view->profile())), | 442 parent_view->profile())), |
| 442 popup_view_(AutocompletePopupContentsView::CreateForEnvironment( | 443 popup_view_(AutocompletePopupContentsView::CreateForEnvironment( |
| 443 parent_view->font(), this, model_.get(), location_bar)), | 444 parent_view->font(), this, model_.get(), location_bar)), |
| 444 controller_(controller), | 445 controller_(controller), |
| 445 parent_view_(parent_view), | 446 parent_view_(parent_view), |
| 446 toolbar_model_(toolbar_model), | 447 toolbar_model_(toolbar_model), |
| 447 command_updater_(command_updater), | 448 command_updater_(command_updater), |
| 448 popup_window_mode_(popup_window_mode), | 449 popup_window_mode_(popup_window_mode), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as | 490 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as |
| 490 // of Rich Edit 2.0 onward. | 491 // of Rich Edit 2.0 onward. |
| 491 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, | 492 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, |
| 492 reinterpret_cast<LPARAM>(&WordBreakProc)); | 493 reinterpret_cast<LPARAM>(&WordBreakProc)); |
| 493 | 494 |
| 494 // Get the metrics for the font. | 495 // Get the metrics for the font. |
| 495 HDC hdc = ::GetDC(NULL); | 496 HDC hdc = ::GetDC(NULL); |
| 496 HGDIOBJ old_font = SelectObject(hdc, font_.GetNativeFont()); | 497 HGDIOBJ old_font = SelectObject(hdc, font_.GetNativeFont()); |
| 497 TEXTMETRIC tm = {0}; | 498 TEXTMETRIC tm = {0}; |
| 498 GetTextMetrics(hdc, &tm); | 499 GetTextMetrics(hdc, &tm); |
| 499 const float kXHeightRatio = 0.7f; // The ratio of a font's x-height to its | 500 int cap_height = font_.GetBaseline() - tm.tmInternalLeading; |
| 500 // cap height. Sadly, Windows doesn't | 501 // The ratio of a font's x-height to its cap height. Sadly, Windows |
| 501 // provide a true value for a font's | 502 // doesn't provide a true value for a font's x-height in its text |
| 502 // x-height in its text metrics, so we | 503 // metrics, so we approximate. |
| 503 // approximate. | 504 const float kXHeightRatio = 0.7f; |
| 504 font_x_height_ = static_cast<int>((static_cast<float>(font_.GetBaseline() - | 505 font_x_height_ = static_cast<int>( |
| 505 tm.tmInternalLeading) * kXHeightRatio) + 0.5); | 506 (static_cast<float>(cap_height) * kXHeightRatio) + 0.5); |
| 506 // The distance from the top of the field to the desired baseline of the | 507 |
| 507 // rendered text. | 508 // We set font_y_adjustment_ so that the ascender of the font gets |
| 508 const int kTextBaseline = popup_window_mode_ ? 15 : 18; | 509 // centered on the available height of the view. |
|
Peter Kasting
2012/05/16 23:19:50
You did check that this produces identical results
| |
| 509 font_y_adjustment_ = kTextBaseline - font_.GetBaseline(); | 510 font_y_adjustment_ = |
| 511 (height - cap_height) / 2 + cap_height - font_.GetBaseline(); | |
|
Peter Kasting
2012/05/16 23:19:50
Nit: Simpler:
font_y_adjustment_ = ((height - c
| |
| 510 | 512 |
| 511 // Get the number of twips per pixel, which we need below to offset our text | 513 // Get the number of twips per pixel, which we need below to offset our text |
| 512 // by the desired number of pixels. | 514 // by the desired number of pixels. |
| 513 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(hdc, LOGPIXELSY); | 515 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(hdc, LOGPIXELSY); |
| 514 // It's unsafe to delete a DC with a non-stock object selected, so restore the | 516 // It's unsafe to delete a DC with a non-stock object selected, so restore the |
| 515 // original font. | 517 // original font. |
| 516 SelectObject(hdc, old_font); | 518 SelectObject(hdc, old_font); |
| 517 ::ReleaseDC(NULL, hdc); | 519 ::ReleaseDC(NULL, hdc); |
| 518 | 520 |
| 519 // Set the default character style -- adjust to our desired baseline. | 521 // Set the default character style -- adjust to our desired baseline. |
| (...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2675 } | 2677 } |
| 2676 | 2678 |
| 2677 #if !defined(USE_AURA) | 2679 #if !defined(USE_AURA) |
| 2678 // static | 2680 // static |
| 2679 OmniboxView* OmniboxView::CreateOmniboxView( | 2681 OmniboxView* OmniboxView::CreateOmniboxView( |
| 2680 AutocompleteEditController* controller, | 2682 AutocompleteEditController* controller, |
| 2681 ToolbarModel* toolbar_model, | 2683 ToolbarModel* toolbar_model, |
| 2682 Profile* profile, | 2684 Profile* profile, |
| 2683 CommandUpdater* command_updater, | 2685 CommandUpdater* command_updater, |
| 2684 bool popup_window_mode, | 2686 bool popup_window_mode, |
| 2687 int height, | |
| 2685 LocationBarView* location_bar) { | 2688 LocationBarView* location_bar) { |
| 2686 return new OmniboxViewWin(controller, | 2689 return new OmniboxViewWin(controller, |
| 2687 toolbar_model, | 2690 toolbar_model, |
| 2688 location_bar, | 2691 location_bar, |
| 2689 command_updater, | 2692 command_updater, |
| 2690 popup_window_mode, | 2693 popup_window_mode, |
| 2694 height, | |
| 2691 location_bar); | 2695 location_bar); |
| 2692 } | 2696 } |
| 2693 #endif | 2697 #endif |
| OLD | NEW |