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

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

Issue 19666006: Supports FontList in Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removes ResourceBundle::Delegate::GetFontList. Created 7 years, 4 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 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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 457
458 } // namespace 458 } // namespace
459 459
460 HMODULE OmniboxViewWin::loaded_library_module_ = NULL; 460 HMODULE OmniboxViewWin::loaded_library_module_ = NULL;
461 461
462 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, 462 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller,
463 ToolbarModel* toolbar_model, 463 ToolbarModel* toolbar_model,
464 LocationBarView* location_bar, 464 LocationBarView* location_bar,
465 CommandUpdater* command_updater, 465 CommandUpdater* command_updater,
466 bool popup_window_mode, 466 bool popup_window_mode,
467 const gfx::Font& font, 467 const gfx::FontList& font_list,
468 int font_y_offset) 468 int font_y_offset)
469 : OmniboxView(location_bar->profile(), controller, toolbar_model, 469 : OmniboxView(location_bar->profile(), controller, toolbar_model,
470 command_updater), 470 command_updater),
471 popup_view_( 471 popup_view_(OmniboxPopupContentsView::Create(
472 OmniboxPopupContentsView::Create(font, this, model(), location_bar)), 472 font_list, this, model(), location_bar)),
473 location_bar_(location_bar), 473 location_bar_(location_bar),
474 popup_window_mode_(popup_window_mode), 474 popup_window_mode_(popup_window_mode),
475 force_hidden_(false), 475 force_hidden_(false),
476 tracking_click_(), 476 tracking_click_(),
477 tracking_double_click_(false), 477 tracking_double_click_(false),
478 double_click_time_(0), 478 double_click_time_(0),
479 can_discard_mousemove_(false), 479 can_discard_mousemove_(false),
480 ignore_ime_messages_(false), 480 ignore_ime_messages_(false),
481 delete_at_end_pressed_(false), 481 delete_at_end_pressed_(false),
482 font_(font), 482 font_list_(font_list),
483 font_y_adjustment_(font_y_offset), 483 font_y_adjustment_(font_y_offset),
484 possible_drag_(false), 484 possible_drag_(false),
485 in_drag_(false), 485 in_drag_(false),
486 initiated_drag_(false), 486 initiated_drag_(false),
487 drop_highlight_position_(-1), 487 drop_highlight_position_(-1),
488 ime_candidate_window_open_(false), 488 ime_candidate_window_open_(false),
489 background_color_(skia::SkColorToCOLORREF(location_bar->GetColor( 489 background_color_(skia::SkColorToCOLORREF(location_bar->GetColor(
490 ToolbarModel::NONE, LocationBarView::BACKGROUND))), 490 ToolbarModel::NONE, LocationBarView::BACKGROUND))),
491 security_level_(ToolbarModel::NONE), 491 security_level_(ToolbarModel::NONE),
492 text_object_model_(NULL), 492 text_object_model_(NULL),
493 tsf_event_router_(base::win::IsTSFAwareRequired() ? 493 tsf_event_router_(base::win::IsTSFAwareRequired() ?
494 new ui::TSFEventRouter(this) : NULL) { 494 new ui::TSFEventRouter(this) : NULL) {
495 if (!loaded_library_module_) 495 if (!loaded_library_module_)
496 loaded_library_module_ = LoadLibrary(kRichEditDLLName); 496 loaded_library_module_ = LoadLibrary(kRichEditDLLName);
497 // RichEdit should be available; rare exceptions should use the Views omnibox. 497 // RichEdit should be available; rare exceptions should use the Views omnibox.
498 DCHECK(loaded_library_module_); 498 DCHECK(loaded_library_module_);
499 499
500 saved_selection_for_focus_change_.cpMin = -1; 500 saved_selection_for_focus_change_.cpMin = -1;
501 501
502 g_paint_patcher.Pointer()->RefPatch(); 502 g_paint_patcher.Pointer()->RefPatch();
503 503
504 Create(location_bar->GetWidget()->GetNativeView(), 0, 0, 0, 504 Create(location_bar->GetWidget()->GetNativeView(), 0, 0, 0,
505 l10n_util::GetExtendedStyles()); 505 l10n_util::GetExtendedStyles());
506 SetReadOnly(popup_window_mode_); 506 SetReadOnly(popup_window_mode_);
507 gfx::NativeFont native_font(font_.GetNativeFont()); 507 gfx::NativeFont native_font(font_list_.GetPrimaryFont().GetNativeFont());
508 SetFont(native_font); 508 SetFont(native_font);
509 509
510 // IMF_DUALFONT (on by default) is supposed to use one font for ASCII text 510 // IMF_DUALFONT (on by default) is supposed to use one font for ASCII text
511 // and a different one for Asian text. In some cases, ASCII characters may 511 // and a different one for Asian text. In some cases, ASCII characters may
512 // be mis-marked as Asian, e.g. because input from the keyboard may be 512 // be mis-marked as Asian, e.g. because input from the keyboard may be
513 // auto-stamped with the keyboard language. As a result adjacent characters 513 // auto-stamped with the keyboard language. As a result adjacent characters
514 // can render in different fonts, which looks bizarre. To fix this we 514 // can render in different fonts, which looks bizarre. To fix this we
515 // disable dual-font mode, which forces the control to use a single font for 515 // disable dual-font mode, which forces the control to use a single font for
516 // everything. 516 // everything.
517 // Note that we should not disable the very similar IMF_AUTOFONT flag, which 517 // Note that we should not disable the very similar IMF_AUTOFONT flag, which
518 // allows the control to hunt for fonts that can display all the current 518 // allows the control to hunt for fonts that can display all the current
519 // characters; doing this results in "missing glyph" boxes when the user 519 // characters; doing this results in "missing glyph" boxes when the user
520 // enters characters not available in the currently-chosen font. 520 // enters characters not available in the currently-chosen font.
521 const LRESULT lang_options = SendMessage(m_hWnd, EM_GETLANGOPTIONS, 0, 0); 521 const LRESULT lang_options = SendMessage(m_hWnd, EM_GETLANGOPTIONS, 0, 0);
522 SendMessage(m_hWnd, EM_SETLANGOPTIONS, 0, lang_options & ~IMF_DUALFONT); 522 SendMessage(m_hWnd, EM_SETLANGOPTIONS, 0, lang_options & ~IMF_DUALFONT);
523 523
524 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as 524 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as
525 // of Rich Edit 2.0 onward. 525 // of Rich Edit 2.0 onward.
526 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, 526 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0,
527 reinterpret_cast<LPARAM>(&WordBreakProc)); 527 reinterpret_cast<LPARAM>(&WordBreakProc));
528 528
529 // Get the metrics for the font. 529 // Get the metrics for the font.
530 base::win::ScopedGetDC screen_dc(NULL); 530 base::win::ScopedGetDC screen_dc(NULL);
531 base::win::ScopedSelectObject font_in_dc(screen_dc, native_font); 531 base::win::ScopedSelectObject font_in_dc(screen_dc, native_font);
532 TEXTMETRIC tm = {0}; 532 TEXTMETRIC tm = {0};
533 GetTextMetrics(screen_dc, &tm); 533 GetTextMetrics(screen_dc, &tm);
534 int cap_height = font_.GetBaseline() - tm.tmInternalLeading; 534 int cap_height = font_list_.GetBaseline() - tm.tmInternalLeading;
535 // The ratio of a font's x-height to its cap height. Sadly, Windows 535 // The ratio of a font's x-height to its cap height. Sadly, Windows
536 // doesn't provide a true value for a font's x-height in its text 536 // doesn't provide a true value for a font's x-height in its text
537 // metrics, so we approximate. 537 // metrics, so we approximate.
538 const float kXHeightRatio = 0.7f; 538 const float kXHeightRatio = 0.7f;
539 font_x_height_ = static_cast<int>( 539 font_x_height_ = static_cast<int>(
540 (static_cast<float>(cap_height) * kXHeightRatio) + 0.5); 540 (static_cast<float>(cap_height) * kXHeightRatio) + 0.5);
541 541
542 // Get the number of twips per pixel, which we need below to offset our text 542 // Get the number of twips per pixel, which we need below to offset our text
543 // by the desired number of pixels. 543 // by the desired number of pixels.
544 const long kTwipsPerPixel = 544 const long kTwipsPerPixel =
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 // window resize will effectively restore caret visibility, regardless of 807 // window resize will effectively restore caret visibility, regardless of
808 // whether HideCaret() was called before. While we do catch and handle these 808 // whether HideCaret() was called before. While we do catch and handle these
809 // paint events (see OnPaint()), it doesn't seem to be enough to simply call 809 // paint events (see OnPaint()), it doesn't seem to be enough to simply call
810 // HideCaret() while handling them because of the unpredictability of this 810 // HideCaret() while handling them because of the unpredictability of this
811 // Windows API. According to the documentation, it should be a cumulative call 811 // Windows API. According to the documentation, it should be a cumulative call
812 // e.g. 5 hide calls should be balanced by 5 show calls. We have not found 812 // e.g. 5 hide calls should be balanced by 5 show calls. We have not found
813 // this to be true, which may be explained by the fact that this API is called 813 // this to be true, which may be explained by the fact that this API is called
814 // internally in Windows, as well. 814 // internally in Windows, as well.
815 ::DestroyCaret(); 815 ::DestroyCaret();
816 if (model()->is_caret_visible()) { 816 if (model()->is_caret_visible()) {
817 ::CreateCaret(m_hWnd, (HBITMAP) NULL, 1, font_.GetHeight()); 817 ::CreateCaret(m_hWnd, (HBITMAP) NULL, 1, font_list_.GetHeight());
818 // According to the Windows API documentation, a newly created caret needs 818 // According to the Windows API documentation, a newly created caret needs
819 // ShowCaret to be visible. 819 // ShowCaret to be visible.
820 ShowCaret(); 820 ShowCaret();
821 } 821 }
822 } 822 }
823 823
824 void OmniboxViewWin::SetDropHighlightPosition(int position) { 824 void OmniboxViewWin::SetDropHighlightPosition(int position) {
825 if (drop_highlight_position_ != position) { 825 if (drop_highlight_position_ != position) {
826 RepaintDropHighlight(drop_highlight_position_); 826 RepaintDropHighlight(drop_highlight_position_);
827 drop_highlight_position_ = position; 827 drop_highlight_position_ = position;
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 2512
2513 // Calculate the rect, in window coordinates, containing the portion of the 2513 // Calculate the rect, in window coordinates, containing the portion of the
2514 // scheme where we'll be drawing the slash. Vertically, we draw across one 2514 // scheme where we'll be drawing the slash. Vertically, we draw across one
2515 // x-height of text, plus an additional 3 stroke diameters (the stroke width 2515 // x-height of text, plus an additional 3 stroke diameters (the stroke width
2516 // plus a half-stroke width of space between the stroke and the text, both 2516 // plus a half-stroke width of space between the stroke and the text, both
2517 // above and below the text). 2517 // above and below the text).
2518 const int font_top = client_rect.top + font_y_adjustment_; 2518 const int font_top = client_rect.top + font_y_adjustment_;
2519 const SkScalar kStrokeWidthPixels = SkIntToScalar(2); 2519 const SkScalar kStrokeWidthPixels = SkIntToScalar(2);
2520 const int kAdditionalSpaceOutsideFont = 2520 const int kAdditionalSpaceOutsideFont =
2521 static_cast<int>(ceil(kStrokeWidthPixels * 1.5f)); 2521 static_cast<int>(ceil(kStrokeWidthPixels * 1.5f));
2522 const int font_ascent = font_.GetBaseline(); 2522 const int font_ascent = font_list_.GetBaseline();
2523 const CRect scheme_rect( 2523 const CRect scheme_rect(
2524 PosFromChar(insecure_scheme_component_.begin).x, 2524 PosFromChar(insecure_scheme_component_.begin).x,
2525 font_top + font_ascent - font_x_height_ - kAdditionalSpaceOutsideFont, 2525 font_top + font_ascent - font_x_height_ - kAdditionalSpaceOutsideFont,
2526 PosFromChar(insecure_scheme_component_.end()).x, 2526 PosFromChar(insecure_scheme_component_.end()).x,
2527 font_top + font_ascent + kAdditionalSpaceOutsideFont); 2527 font_top + font_ascent + kAdditionalSpaceOutsideFont);
2528 2528
2529 // Clip to the portion we care about and translate to canvas coordinates 2529 // Clip to the portion we care about and translate to canvas coordinates
2530 // (see the canvas creation below) for use later. 2530 // (see the canvas creation below) for use later.
2531 CRect canvas_clip_rect, canvas_paint_clip_rect; 2531 CRect canvas_clip_rect, canvas_paint_clip_rect;
2532 canvas_clip_rect.IntersectRect(scheme_rect, client_rect); 2532 canvas_clip_rect.IntersectRect(scheme_rect, client_rect);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2600 void OmniboxViewWin::DrawDropHighlight(HDC hdc, 2600 void OmniboxViewWin::DrawDropHighlight(HDC hdc,
2601 const CRect& client_rect, 2601 const CRect& client_rect,
2602 const CRect& paint_clip_rect) { 2602 const CRect& paint_clip_rect) {
2603 DCHECK_NE(-1, drop_highlight_position_); 2603 DCHECK_NE(-1, drop_highlight_position_);
2604 2604
2605 const int highlight_y = client_rect.top + font_y_adjustment_; 2605 const int highlight_y = client_rect.top + font_y_adjustment_;
2606 const int highlight_x = PosFromChar(drop_highlight_position_).x - 1; 2606 const int highlight_x = PosFromChar(drop_highlight_position_).x - 1;
2607 const CRect highlight_rect(highlight_x, 2607 const CRect highlight_rect(highlight_x,
2608 highlight_y, 2608 highlight_y,
2609 highlight_x + 1, 2609 highlight_x + 1,
2610 highlight_y + font_.GetHeight()); 2610 highlight_y + font_list_.GetHeight());
2611 2611
2612 // Clip the highlight to the region being painted. 2612 // Clip the highlight to the region being painted.
2613 CRect clip_rect; 2613 CRect clip_rect;
2614 clip_rect.IntersectRect(highlight_rect, paint_clip_rect); 2614 clip_rect.IntersectRect(highlight_rect, paint_clip_rect);
2615 if (clip_rect.IsRectNull()) 2615 if (clip_rect.IsRectNull())
2616 return; 2616 return;
2617 2617
2618 HGDIOBJ last_pen = SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0, 0, 0))); 2618 HGDIOBJ last_pen = SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0, 0, 0)));
2619 MoveToEx(hdc, clip_rect.left, clip_rect.top, NULL); 2619 MoveToEx(hdc, clip_rect.left, clip_rect.top, NULL);
2620 LineTo(hdc, clip_rect.left, clip_rect.bottom); 2620 LineTo(hdc, clip_rect.left, clip_rect.bottom);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2755 // a drag regardless of the y-coordinate. 2755 // a drag regardless of the y-coordinate.
2756 possible_drag_ = (point.x >= min_sel_location.x) && 2756 possible_drag_ = (point.x >= min_sel_location.x) &&
2757 (point.x < max_sel_location.x); 2757 (point.x < max_sel_location.x);
2758 } 2758 }
2759 } 2759 }
2760 2760
2761 void OmniboxViewWin::RepaintDropHighlight(int position) { 2761 void OmniboxViewWin::RepaintDropHighlight(int position) {
2762 if ((position != -1) && (position <= GetTextLength())) { 2762 if ((position != -1) && (position <= GetTextLength())) {
2763 const POINT min_loc(PosFromChar(position)); 2763 const POINT min_loc(PosFromChar(position));
2764 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, 2764 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_,
2765 min_loc.x + 2, font_.GetHeight() + font_y_adjustment_}; 2765 min_loc.x + 2, font_list_.GetHeight() + font_y_adjustment_};
2766 InvalidateRect(&highlight_bounds, false); 2766 InvalidateRect(&highlight_bounds, false);
2767 } 2767 }
2768 } 2768 }
2769 2769
2770 void OmniboxViewWin::BuildContextMenu() { 2770 void OmniboxViewWin::BuildContextMenu() {
2771 if (context_menu_contents_.get()) 2771 if (context_menu_contents_.get())
2772 return; 2772 return;
2773 2773
2774 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); 2774 context_menu_contents_.reset(new ui::SimpleMenuModel(this));
2775 // Set up context menu. 2775 // Set up context menu.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2820 2820
2821 int OmniboxViewWin::GetHorizontalMargin() const { 2821 int OmniboxViewWin::GetHorizontalMargin() const {
2822 RECT rect; 2822 RECT rect;
2823 GetRect(&rect); 2823 GetRect(&rect);
2824 RECT client_rect; 2824 RECT client_rect;
2825 GetClientRect(&client_rect); 2825 GetClientRect(&client_rect);
2826 return (rect.left - client_rect.left) + (client_rect.right - rect.right); 2826 return (rect.left - client_rect.left) + (client_rect.right - rect.right);
2827 } 2827 }
2828 2828
2829 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { 2829 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const {
2830 // Use font_.GetStringWidth() instead of PosFromChar(GetTextLength()) because 2830 // Use font_list_.GetPrimaryFont().GetStringWidth() instead of
2831 // PosFromChar() is apparently buggy. In both LTR UI and RTL UI with 2831 // PosFromChar(GetTextLength()) because PosFromChar() is apparently buggy.
2832 // left-to-right layout, PosFromChar(i) might return 0 when i is greater than 2832 // In both LTR UI and RTL UI with left-to-right layout, PosFromChar(i) might
2833 // 1. 2833 // return 0 when i is greater than 1.
2834 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2834 return font_list_.GetPrimaryFont().GetStringWidth(text) +
2835 GetHorizontalMargin();
2835 } 2836 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698