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 // For WinDDK ATL compatibility, these ATL headers must come first. | 5 // For WinDDK ATL compatibility, these ATL headers must come first. |
6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <atlbase.h> // NOLINT | 8 #include <atlbase.h> // NOLINT |
9 #include <atlwin.h> // NOLINT | 9 #include <atlwin.h> // NOLINT |
10 #endif | 10 #endif |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 int center_; | 100 int center_; |
101 int right_; | 101 int right_; |
102 | 102 |
103 DISALLOW_COPY_AND_ASSIGN(MirroringContext); | 103 DISALLOW_COPY_AND_ASSIGN(MirroringContext); |
104 }; | 104 }; |
105 | 105 |
106 OmniboxResultView::OmniboxResultView( | 106 OmniboxResultView::OmniboxResultView( |
107 OmniboxResultViewModel* model, | 107 OmniboxResultViewModel* model, |
108 int model_index, | 108 int model_index, |
109 LocationBarView* location_bar_view, | 109 LocationBarView* location_bar_view, |
110 const gfx::Font& font) | 110 const gfx::FontList& font_list) |
111 : edge_item_padding_(LocationBarView::GetItemPadding()), | 111 : edge_item_padding_(LocationBarView::GetItemPadding()), |
112 item_padding_(LocationBarView::GetItemPadding()), | 112 item_padding_(LocationBarView::GetItemPadding()), |
113 minimum_text_vertical_padding_(kMinimumTextVerticalPadding), | 113 minimum_text_vertical_padding_(kMinimumTextVerticalPadding), |
114 model_(model), | 114 model_(model), |
115 model_index_(model_index), | 115 model_index_(model_index), |
116 location_bar_view_(location_bar_view), | 116 location_bar_view_(location_bar_view), |
117 font_(font), | 117 font_list_(font_list), |
118 font_height_(std::max(font.GetHeight(), | 118 font_height_(std::max(font_list.GetHeight(), |
119 font.DeriveFont(0, gfx::BOLD).GetHeight())), | 119 font_list.DeriveFontList(gfx::BOLD).GetHeight())), |
120 ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), | 120 ellipsis_width_(font_list.GetPrimaryFont().GetStringWidth( |
| 121 string16(kEllipsis))), |
121 mirroring_context_(new MirroringContext()), | 122 mirroring_context_(new MirroringContext()), |
122 keyword_icon_(new views::ImageView()), | 123 keyword_icon_(new views::ImageView()), |
123 animation_(new ui::SlideAnimation(this)) { | 124 animation_(new ui::SlideAnimation(this)) { |
124 CHECK_GE(model_index, 0); | 125 CHECK_GE(model_index, 0); |
125 if (default_icon_size_ == 0) { | 126 if (default_icon_size_ == 0) { |
126 default_icon_size_ = | 127 default_icon_size_ = |
127 location_bar_view_->GetThemeProvider()->GetImageSkiaNamed( | 128 location_bar_view_->GetThemeProvider()->GetImageSkiaNamed( |
128 AutocompleteMatch::TypeToIcon( | 129 AutocompleteMatch::TypeToIcon( |
129 AutocompleteMatchType::URL_WHAT_YOU_TYPED))->width(); | 130 AutocompleteMatchType::URL_WHAT_YOU_TYPED))->width(); |
130 } | 131 } |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 397 |
397 const size_t text_end = (i < (classifications.size() - 1)) ? | 398 const size_t text_end = (i < (classifications.size() - 1)) ? |
398 std::min(classifications[i + 1].offset, run_end) : run_end; | 399 std::min(classifications[i + 1].offset, run_end) : run_end; |
399 if (text_end <= current_run->run_start) | 400 if (text_end <= current_run->run_start) |
400 continue; // We haven't reached the first classification in the run. | 401 continue; // We haven't reached the first classification in the run. |
401 | 402 |
402 render_texts.push_back(gfx::RenderText::CreateInstance()); | 403 render_texts.push_back(gfx::RenderText::CreateInstance()); |
403 gfx::RenderText* render_text = render_texts.back(); | 404 gfx::RenderText* render_text = render_texts.back(); |
404 current_run->classifications.push_back(render_text); | 405 current_run->classifications.push_back(render_text); |
405 render_text->SetText(text.substr(text_start, text_end - text_start)); | 406 render_text->SetText(text.substr(text_start, text_end - text_start)); |
406 render_text->SetFont(font_); | 407 render_text->SetFontList(font_list_); |
407 | 408 |
408 // Calculate style-related data. | 409 // Calculate style-related data. |
409 if (classifications[i].style & ACMatchClassification::MATCH) | 410 if (classifications[i].style & ACMatchClassification::MATCH) |
410 render_text->SetStyle(gfx::BOLD, true); | 411 render_text->SetStyle(gfx::BOLD, true); |
411 const ResultViewState state = GetState(); | 412 const ResultViewState state = GetState(); |
412 if (classifications[i].style & ACMatchClassification::URL) | 413 if (classifications[i].style & ACMatchClassification::URL) |
413 render_text->SetColor(GetColor(state, URL)); | 414 render_text->SetColor(GetColor(state, URL)); |
414 else if (classifications[i].style & ACMatchClassification::DIM) | 415 else if (classifications[i].style & ACMatchClassification::DIM) |
415 render_text->SetColor(GetColor(state, DIMMED_TEXT)); | 416 render_text->SetColor(GetColor(state, DIMMED_TEXT)); |
416 else | 417 else |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 for (Runs::iterator i(runs.begin()); i != runs.end(); ++i) { | 465 for (Runs::iterator i(runs.begin()); i != runs.end(); ++i) { |
465 const bool reverse_visible_order = (i->is_rtl != base::i18n::IsRTL()); | 466 const bool reverse_visible_order = (i->is_rtl != base::i18n::IsRTL()); |
466 if (reverse_visible_order) | 467 if (reverse_visible_order) |
467 std::reverse(i->classifications.begin(), i->classifications.end()); | 468 std::reverse(i->classifications.begin(), i->classifications.end()); |
468 for (Classifications::const_iterator j(i->classifications.begin()); | 469 for (Classifications::const_iterator j(i->classifications.begin()); |
469 j != i->classifications.end(); ++j) { | 470 j != i->classifications.end(); ++j) { |
470 const gfx::Size size = (*j)->GetStringSize(); | 471 const gfx::Size size = (*j)->GetStringSize(); |
471 // Align the text runs to a common baseline. | 472 // Align the text runs to a common baseline. |
472 const gfx::Rect rect( | 473 const gfx::Rect rect( |
473 mirroring_context_->mirrored_left_coord(x, x + size.width()), | 474 mirroring_context_->mirrored_left_coord(x, x + size.width()), |
474 y + font_.GetBaseline() - (*j)->GetBaseline(), | 475 y + font_list_.GetBaseline() - (*j)->GetBaseline(), |
475 size.width(), size.height()); | 476 size.width(), size.height()); |
476 (*j)->SetDisplayRect(rect); | 477 (*j)->SetDisplayRect(rect); |
477 (*j)->Draw(canvas); | 478 (*j)->Draw(canvas); |
478 x += size.width(); | 479 x += size.width(); |
479 } | 480 } |
480 } | 481 } |
481 | 482 |
482 return x; | 483 return x; |
483 } | 484 } |
484 | 485 |
(...skipping 21 matching lines...) Expand all Loading... |
506 | 507 |
507 // For all but the first classification we consider, we need to append | 508 // For all but the first classification we consider, we need to append |
508 // an ellipsis, since there isn't enough room to draw it after this | 509 // an ellipsis, since there isn't enough room to draw it after this |
509 // classification. | 510 // classification. |
510 (*j)->SetText((*j)->text() + kEllipsis); | 511 (*j)->SetText((*j)->text() + kEllipsis); |
511 } | 512 } |
512 first_classification = false; | 513 first_classification = false; |
513 | 514 |
514 // Can we fit at least an ellipsis? | 515 // Can we fit at least an ellipsis? |
515 gfx::Font font((*j)->GetStyle(gfx::BOLD) ? | 516 gfx::Font font((*j)->GetStyle(gfx::BOLD) ? |
516 (*j)->GetFont().DeriveFont(0, gfx::Font::BOLD) : (*j)->GetFont()); | 517 (*j)->GetPrimaryFont().DeriveFont(0, gfx::Font::BOLD) : |
| 518 (*j)->GetPrimaryFont()); |
517 string16 elided_text( | 519 string16 elided_text( |
518 ui::ElideText((*j)->text(), font, remaining_width, ui::ELIDE_AT_END)); | 520 ui::ElideText((*j)->text(), font, remaining_width, ui::ELIDE_AT_END)); |
519 Classifications::reverse_iterator prior(j + 1); | 521 Classifications::reverse_iterator prior(j + 1); |
520 const bool on_first_classification = (prior == i->classifications.rend()); | 522 const bool on_first_classification = (prior == i->classifications.rend()); |
521 if (elided_text.empty() && (remaining_width >= ellipsis_width_) && | 523 if (elided_text.empty() && (remaining_width >= ellipsis_width_) && |
522 on_first_classification) { | 524 on_first_classification) { |
523 // Edge case: This classification is bold, we can't fit a bold ellipsis | 525 // Edge case: This classification is bold, we can't fit a bold ellipsis |
524 // but we can fit a normal one, and this is the first classification in | 526 // but we can fit a normal one, and this is the first classification in |
525 // the run. We should display a lone normal ellipsis, because appending | 527 // the run. We should display a lone normal ellipsis, because appending |
526 // one to the end of the previous run might put it in the wrong visual | 528 // one to the end of the previous run might put it in the wrong visual |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 int x = GetMirroredXForRect(keyword_text_bounds_); | 624 int x = GetMirroredXForRect(keyword_text_bounds_); |
623 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); | 625 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); |
624 PaintMatch(canvas, *match_.associated_keyword.get(), x); | 626 PaintMatch(canvas, *match_.associated_keyword.get(), x); |
625 } | 627 } |
626 } | 628 } |
627 | 629 |
628 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) { | 630 void OmniboxResultView::AnimationProgressed(const ui::Animation* animation) { |
629 Layout(); | 631 Layout(); |
630 SchedulePaint(); | 632 SchedulePaint(); |
631 } | 633 } |
OLD | NEW |