Chromium Code Reviews| 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 const int kTwipsPerInch = 1440; | 442 const int kTwipsPerInch = 1440; |
| 443 | 443 |
| 444 } // namespace | 444 } // namespace |
| 445 | 445 |
| 446 HMODULE OmniboxViewWin::loaded_library_module_ = NULL; | 446 HMODULE OmniboxViewWin::loaded_library_module_ = NULL; |
| 447 | 447 |
| 448 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, | 448 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, |
| 449 LocationBarView* location_bar, | 449 LocationBarView* location_bar, |
| 450 CommandUpdater* command_updater, | 450 CommandUpdater* command_updater, |
| 451 bool popup_window_mode, | 451 bool popup_window_mode, |
| 452 const gfx::FontList& font_list, | 452 const gfx::FontList& font_list) |
| 453 int font_y_offset) | |
| 454 : OmniboxView(location_bar->profile(), controller, command_updater), | 453 : OmniboxView(location_bar->profile(), controller, command_updater), |
| 455 popup_view_(OmniboxPopupContentsView::Create( | 454 popup_view_(OmniboxPopupContentsView::Create( |
| 456 font_list, this, model(), location_bar)), | 455 font_list, this, model(), location_bar)), |
| 457 location_bar_(location_bar), | 456 location_bar_(location_bar), |
| 458 popup_window_mode_(popup_window_mode), | 457 popup_window_mode_(popup_window_mode), |
| 459 force_hidden_(false), | 458 force_hidden_(false), |
| 460 tracking_click_(), | 459 tracking_click_(), |
| 461 tracking_double_click_(false), | 460 tracking_double_click_(false), |
| 462 double_click_time_(0), | 461 double_click_time_(0), |
| 463 can_discard_mousemove_(false), | 462 can_discard_mousemove_(false), |
| 464 ignore_ime_messages_(false), | 463 ignore_ime_messages_(false), |
| 465 delete_at_end_pressed_(false), | 464 delete_at_end_pressed_(false), |
| 466 font_list_(font_list), | 465 font_list_(font_list), |
| 467 font_y_adjustment_(font_y_offset), | 466 font_y_adjustment_(0), |
| 468 possible_drag_(false), | 467 possible_drag_(false), |
| 469 in_drag_(false), | 468 in_drag_(false), |
| 470 initiated_drag_(false), | 469 initiated_drag_(false), |
| 471 drop_highlight_position_(-1), | 470 drop_highlight_position_(-1), |
| 472 ime_candidate_window_open_(false), | 471 ime_candidate_window_open_(false), |
| 473 background_color_(skia::SkColorToCOLORREF(location_bar->GetColor( | 472 background_color_(skia::SkColorToCOLORREF(location_bar->GetColor( |
| 474 ToolbarModel::NONE, LocationBarView::BACKGROUND))), | 473 ToolbarModel::NONE, LocationBarView::BACKGROUND))), |
| 475 security_level_(ToolbarModel::NONE), | 474 security_level_(ToolbarModel::NONE), |
| 476 text_object_model_(NULL), | 475 text_object_model_(NULL), |
| 477 tsf_event_router_(base::win::IsTSFAwareRequired() ? | 476 tsf_event_router_(base::win::IsTSFAwareRequired() ? |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 base::win::ScopedSelectObject font_in_dc(screen_dc, native_font); | 514 base::win::ScopedSelectObject font_in_dc(screen_dc, native_font); |
| 516 TEXTMETRIC tm = {0}; | 515 TEXTMETRIC tm = {0}; |
| 517 GetTextMetrics(screen_dc, &tm); | 516 GetTextMetrics(screen_dc, &tm); |
| 518 int cap_height = font_list_.GetBaseline() - tm.tmInternalLeading; | 517 int cap_height = font_list_.GetBaseline() - tm.tmInternalLeading; |
| 519 // 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 |
| 520 // 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 |
| 521 // metrics, so we approximate. | 520 // metrics, so we approximate. |
| 522 const float kXHeightRatio = 0.7f; | 521 const float kXHeightRatio = 0.7f; |
| 523 font_x_height_ = static_cast<int>( | 522 font_x_height_ = static_cast<int>( |
| 524 (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. | |
| 525 const int location_height = location_bar_->GetInternalHeight(true); | |
| 526 font_y_adjustment_ = std::max(0, | |
|
Peter Kasting
2013/11/05 19:22:39
Nit: All lines of args to a function call should b
Yuki
2013/11/06 05:35:10
Done.
| |
| 527 int((location_height - cap_height) / 2 - tm.tmInternalLeading)); | |
|
Peter Kasting
2013/11/05 19:22:39
Why is the int cast needed here? I don't think th
Yuki
2013/11/06 05:35:10
Done.
A template function std::max(T, T) requires
| |
| 525 | 528 |
| 526 // Get the number of twips per pixel, which we need below to offset our text | 529 // Get the number of twips per pixel, which we need below to offset our text |
| 527 // by the desired number of pixels. | 530 // by the desired number of pixels. |
| 528 const long kTwipsPerPixel = | 531 const long kTwipsPerPixel = |
| 529 kTwipsPerInch / GetDeviceCaps(screen_dc, LOGPIXELSY); | 532 kTwipsPerInch / GetDeviceCaps(screen_dc, LOGPIXELSY); |
| 530 | 533 |
| 531 // Set the default character style -- adjust to our desired baseline. | 534 // Set the default character style -- adjust to our desired baseline. |
| 532 CHARFORMAT cf = {0}; | 535 CHARFORMAT cf = {0}; |
| 533 cf.dwMask = CFM_OFFSET; | 536 cf.dwMask = CFM_OFFSET; |
| 534 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; | 537 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; |
| (...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2799 } | 2802 } |
| 2800 | 2803 |
| 2801 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2804 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
| 2802 // Use font_list_.GetPrimaryFont().GetStringWidth() instead of | 2805 // Use font_list_.GetPrimaryFont().GetStringWidth() instead of |
| 2803 // PosFromChar(GetTextLength()) because PosFromChar() is apparently buggy. | 2806 // PosFromChar(GetTextLength()) because PosFromChar() is apparently buggy. |
| 2804 // In both LTR UI and RTL UI with left-to-right layout, PosFromChar(i) might | 2807 // In both LTR UI and RTL UI with left-to-right layout, PosFromChar(i) might |
| 2805 // return 0 when i is greater than 1. | 2808 // return 0 when i is greater than 1. |
| 2806 return font_list_.GetPrimaryFont().GetStringWidth(text) + | 2809 return font_list_.GetPrimaryFont().GetStringWidth(text) + |
| 2807 GetHorizontalMargin(); | 2810 GetHorizontalMargin(); |
| 2808 } | 2811 } |
| OLD | NEW |