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

Side by Side Diff: chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc

Issue 384018: Added a flag to the Canvas class which allows forcing an RTL directionality... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/autocomplete/autocomplete.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" 5 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/gfx/color_utils.h" 8 #include "app/gfx/color_utils.h"
9 #include "app/gfx/insets.h" 9 #include "app/gfx/insets.h"
10 #include "app/gfx/path.h" 10 #include "app/gfx/path.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 bool force_dim, 140 bool force_dim,
141 int x, 141 int x,
142 int y); 142 int y);
143 143
144 // Draws an individual sub-fragment with the specified style. Returns the x 144 // Draws an individual sub-fragment with the specified style. Returns the x
145 // position to the right of the fragment. 145 // position to the right of the fragment.
146 int DrawStringFragment(gfx::Canvas* canvas, 146 int DrawStringFragment(gfx::Canvas* canvas,
147 const std::wstring& text, 147 const std::wstring& text,
148 int style, 148 int style,
149 int x, 149 int x,
150 int y); 150 int y,
151 bool force_rtl_directionality);
151 152
152 // Gets the font and text color for a fragment with the specified style. 153 // Gets the font and text color for a fragment with the specified style.
153 gfx::Font GetFragmentFont(int style) const; 154 gfx::Font GetFragmentFont(int style) const;
154 SkColor GetFragmentTextColor(int style) const; 155 SkColor GetFragmentTextColor(int style) const;
155 156
156 // This row's model and model index. 157 // This row's model and model index.
157 AutocompleteResultViewModel* model_; 158 AutocompleteResultViewModel* model_;
158 size_t model_index_; 159 size_t model_index_;
159 160
160 // The font used to derive fonts for rendering the text in this row. 161 // The font used to derive fonts for rendering the text in this row.
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 size_t i = mirroring_context_->GetClassification( 507 size_t i = mirroring_context_->GetClassification(
507 classification, classifications.size(), run_direction == UBIDI_RTL); 508 classification, classifications.size(), run_direction == UBIDI_RTL);
508 size_t text_start = std::max(static_cast<size_t>(run_start), 509 size_t text_start = std::max(static_cast<size_t>(run_start),
509 classifications[i].offset); 510 classifications[i].offset);
510 size_t text_end = std::min(static_cast<size_t>(run_end), 511 size_t text_end = std::min(static_cast<size_t>(run_end),
511 i < classifications.size() - 1 ? 512 i < classifications.size() - 1 ?
512 classifications[i + 1].offset : run_end); 513 classifications[i + 1].offset : run_end);
513 int style = classifications[i].style; 514 int style = classifications[i].style;
514 if (force_dim) 515 if (force_dim)
515 style |= ACMatchClassification::DIM; 516 style |= ACMatchClassification::DIM;
517
518 // We specify RTL directionlity explicitly only if the run is an RTL run
519 // and we can't specify the string directionlaity using an LRE/PDF pair.
520 // Note that URLs are always displayed using LTR directionality
521 // (regardless of the locale) and therefore they are excluded.
522 const bool force_rtl_directionality =
523 !(classifications[i].style & ACMatchClassification::URL) &&
524 (run_direction == UBIDI_RTL) &&
525 (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT);
526
516 if (text_start < text_end) { 527 if (text_start < text_end) {
517 x += DrawStringFragment(canvas, 528 x += DrawStringFragment(canvas,
518 text.substr(text_start, text_end - text_start), 529 text.substr(text_start, text_end - text_start),
519 style, x, y); 530 style, x, y, force_rtl_directionality);
520 } 531 }
521 } 532 }
522 } 533 }
523 return x; 534 return x;
524 } 535 }
525 536
526 int AutocompleteResultView::DrawStringFragment( 537 int AutocompleteResultView::DrawStringFragment(
527 gfx::Canvas* canvas, 538 gfx::Canvas* canvas,
528 const std::wstring& text, 539 const std::wstring& text,
529 int style, 540 int style,
530 int x, 541 int x,
531 int y) { 542 int y,
543 bool force_rtl_directionality) {
532 gfx::Font display_font = GetFragmentFont(style); 544 gfx::Font display_font = GetFragmentFont(style);
533 // Clamp text width to the available width within the popup so we elide if 545 // Clamp text width to the available width within the popup so we elide if
534 // necessary. 546 // necessary.
535 int string_width = std::min(display_font.GetStringWidth(text), 547 int string_width = std::min(display_font.GetStringWidth(text),
536 width() - kRowRightPadding - x); 548 width() - kRowRightPadding - x);
537 int string_left = mirroring_context_->GetLeft(x, x + string_width); 549 int string_left = mirroring_context_->GetLeft(x, x + string_width);
550 const int flags = force_rtl_directionality ?
551 gfx::Canvas::FORCE_RTL_DIRECTIONALITY : 0;
538 canvas->DrawStringInt(text, GetFragmentFont(style), 552 canvas->DrawStringInt(text, GetFragmentFont(style),
539 GetFragmentTextColor(style), string_left, y, 553 GetFragmentTextColor(style), string_left, y,
540 string_width, display_font.height()); 554 string_width, display_font.height(), flags);
541 return string_width; 555 return string_width;
542 } 556 }
543 557
544 gfx::Font AutocompleteResultView::GetFragmentFont(int style) const { 558 gfx::Font AutocompleteResultView::GetFragmentFont(int style) const {
545 return (style & ACMatchClassification::MATCH) ? 559 return (style & ACMatchClassification::MATCH) ?
546 font_.DeriveFont(0, gfx::Font::BOLD) : font_; 560 font_.DeriveFont(0, gfx::Font::BOLD) : font_;
547 } 561 }
548 562
549 SkColor AutocompleteResultView::GetFragmentTextColor(int style) const { 563 SkColor AutocompleteResultView::GetFragmentTextColor(int style) const {
550 const ResultViewState state = GetState(); 564 const ResultViewState state = GetState();
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 // static 889 // static
876 AutocompletePopupView* AutocompletePopupView::CreatePopupView( 890 AutocompletePopupView* AutocompletePopupView::CreatePopupView(
877 const gfx::Font& font, 891 const gfx::Font& font,
878 AutocompleteEditView* edit_view, 892 AutocompleteEditView* edit_view,
879 AutocompleteEditModel* edit_model, 893 AutocompleteEditModel* edit_model,
880 Profile* profile, 894 Profile* profile,
881 const BubblePositioner* bubble_positioner) { 895 const BubblePositioner* bubble_positioner) {
882 return new AutocompletePopupContentsView(font, edit_view, edit_model, 896 return new AutocompletePopupContentsView(font, edit_view, edit_model,
883 profile, bubble_positioner); 897 profile, bubble_positioner);
884 } 898 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698