| 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 |
| 11 #include <richedit.h> | 11 #include <richedit.h> |
| 12 #include <textserv.h> | 12 #include <textserv.h> |
| 13 | 13 |
| 14 #include "base/auto_reset.h" | 14 #include "base/auto_reset.h" |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/i18n/rtl.h" | 16 #include "base/i18n/rtl.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/property_bag.h" | 19 #include "base/property_bag.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "base/win/iat_patch_function.h" | 22 #include "base/win/iat_patch_function.h" |
| 23 #include "base/win/scoped_hdc.h" |
| 24 #include "base/win/scoped_select_object.h" |
| 23 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
| 24 #include "chrome/app/chrome_command_ids.h" | 26 #include "chrome/app/chrome_command_ids.h" |
| 25 #include "chrome/browser/autocomplete/autocomplete_match.h" | 27 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 26 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 28 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 27 #include "chrome/browser/autocomplete/keyword_provider.h" | 29 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 28 #include "chrome/browser/browser_process.h" | 30 #include "chrome/browser/browser_process.h" |
| 29 #include "chrome/browser/command_updater.h" | 31 #include "chrome/browser/command_updater.h" |
| 30 #include "chrome/browser/net/url_fixer_upper.h" | 32 #include "chrome/browser/net/url_fixer_upper.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/ui/browser.h" | 34 #include "chrome/browser/ui/browser.h" |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 if (keyboard_ != NULL) | 487 if (keyboard_ != NULL) |
| 486 keyboard_->put_AttachedEditWindow(m_hWnd); | 488 keyboard_->put_AttachedEditWindow(m_hWnd); |
| 487 } | 489 } |
| 488 | 490 |
| 489 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as | 491 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as |
| 490 // of Rich Edit 2.0 onward. | 492 // of Rich Edit 2.0 onward. |
| 491 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, | 493 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, |
| 492 reinterpret_cast<LPARAM>(&WordBreakProc)); | 494 reinterpret_cast<LPARAM>(&WordBreakProc)); |
| 493 | 495 |
| 494 // Get the metrics for the font. | 496 // Get the metrics for the font. |
| 495 HDC hdc = ::GetDC(NULL); | 497 base::win::ScopedGetDC screen_dc(NULL); |
| 496 HGDIOBJ old_font = SelectObject(hdc, font_.GetNativeFont()); | 498 base::win::ScopedSelectObject(screen_dc, font_.GetNativeFont()); |
| 497 TEXTMETRIC tm = {0}; | 499 TEXTMETRIC tm = {0}; |
| 498 GetTextMetrics(hdc, &tm); | 500 GetTextMetrics(screen_dc, &tm); |
| 499 int cap_height = font_.GetBaseline() - tm.tmInternalLeading; | 501 int cap_height = font_.GetBaseline() - tm.tmInternalLeading; |
| 500 // The ratio of a font's x-height to its cap height. Sadly, Windows | 502 // The ratio of a font's x-height to its cap height. Sadly, Windows |
| 501 // doesn't provide a true value for a font's x-height in its text | 503 // doesn't provide a true value for a font's x-height in its text |
| 502 // metrics, so we approximate. | 504 // metrics, so we approximate. |
| 503 const float kXHeightRatio = 0.7f; | 505 const float kXHeightRatio = 0.7f; |
| 504 font_x_height_ = static_cast<int>( | 506 font_x_height_ = static_cast<int>( |
| 505 (static_cast<float>(cap_height) * kXHeightRatio) + 0.5); | 507 (static_cast<float>(cap_height) * kXHeightRatio) + 0.5); |
| 506 | 508 |
| 507 // We set font_y_adjustment_ so that the ascender of the font gets | 509 // We set font_y_adjustment_ so that the ascender of the font gets |
| 508 // centered on the available height of the view. | 510 // centered on the available height of the view. |
| 509 font_y_adjustment_ = | 511 font_y_adjustment_ = |
| 510 (parent_view->GetInternalHeight(true) - cap_height) / 2 - | 512 (parent_view->GetInternalHeight(true) - cap_height) / 2 - |
| 511 tm.tmInternalLeading; | 513 tm.tmInternalLeading; |
| 512 | 514 |
| 513 // Get the number of twips per pixel, which we need below to offset our text | 515 // Get the number of twips per pixel, which we need below to offset our text |
| 514 // by the desired number of pixels. | 516 // by the desired number of pixels. |
| 515 const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(hdc, LOGPIXELSY); | 517 const long kTwipsPerPixel = |
| 516 // It's unsafe to delete a DC with a non-stock object selected, so restore the | 518 kTwipsPerInch / GetDeviceCaps(screen_dc, LOGPIXELSY); |
| 517 // original font. | |
| 518 SelectObject(hdc, old_font); | |
| 519 ::ReleaseDC(NULL, hdc); | |
| 520 | 519 |
| 521 // Set the default character style -- adjust to our desired baseline. | 520 // Set the default character style -- adjust to our desired baseline. |
| 522 CHARFORMAT cf = {0}; | 521 CHARFORMAT cf = {0}; |
| 523 cf.dwMask = CFM_OFFSET; | 522 cf.dwMask = CFM_OFFSET; |
| 524 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; | 523 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; |
| 525 SetDefaultCharFormat(cf); | 524 SetDefaultCharFormat(cf); |
| 526 | 525 |
| 527 SetBackgroundColor(background_color_); | 526 SetBackgroundColor(background_color_); |
| 528 | 527 |
| 529 // By default RichEdit has a drop target. Revoke it so that we can install our | 528 // By default RichEdit has a drop target. Revoke it so that we can install our |
| (...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2704 bool popup_window_mode, | 2703 bool popup_window_mode, |
| 2705 LocationBarView* location_bar) { | 2704 LocationBarView* location_bar) { |
| 2706 return new OmniboxViewWin(controller, | 2705 return new OmniboxViewWin(controller, |
| 2707 toolbar_model, | 2706 toolbar_model, |
| 2708 location_bar, | 2707 location_bar, |
| 2709 command_updater, | 2708 command_updater, |
| 2710 popup_window_mode, | 2709 popup_window_mode, |
| 2711 location_bar); | 2710 location_bar); |
| 2712 } | 2711 } |
| 2713 #endif | 2712 #endif |
| OLD | NEW |