Chromium Code Reviews| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 int contents_max_width, description_max_width; | 352 int contents_max_width, description_max_width; |
| 353 OmniboxPopupModel::ComputeMatchMaxWidths( | 353 OmniboxPopupModel::ComputeMatchMaxWidths( |
| 354 contents->GetContentWidth(), | 354 contents->GetContentWidth(), |
| 355 separator_width_, | 355 separator_width_, |
| 356 description ? description->GetContentWidth() : 0, | 356 description ? description->GetContentWidth() : 0, |
| 357 mirroring_context_->remaining_width(x), | 357 mirroring_context_->remaining_width(x), |
| 358 !AutocompleteMatch::IsSearchType(match.type), | 358 !AutocompleteMatch::IsSearchType(match.type), |
| 359 &contents_max_width, | 359 &contents_max_width, |
| 360 &description_max_width); | 360 &description_max_width); |
| 361 | 361 |
| 362 int after_contents_x = | 362 int after_contents_x = DrawRenderText(match, contents, CONTENTS, canvas, |
| 363 DrawRenderText(match, contents, true, canvas, x, y, contents_max_width); | 363 x, y, contents_max_width); |
| 364 | 364 |
| 365 if (description_max_width != 0) { | 365 if (description_max_width != 0) { |
| 366 if (match.answer) { | 366 if (match.answer) { |
| 367 y += GetContentLineHeight(); | 367 y += GetContentLineHeight(); |
| 368 if (!answer_image_.isNull()) { | 368 if (!answer_image_.isNull()) { |
| 369 int answer_icon_size = GetAnswerLineHeight(); | 369 int answer_icon_size = GetAnswerLineHeight(); |
| 370 canvas->DrawImageInt( | 370 canvas->DrawImageInt( |
| 371 answer_image_, | 371 answer_image_, |
| 372 0, 0, answer_image_.width(), answer_image_.height(), | 372 0, 0, answer_image_.width(), answer_image_.height(), |
| 373 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true); | 373 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true); |
| 374 // See TODO in Layout(). | 374 // See TODO in Layout(). |
| 375 x += answer_icon_size + | 375 x += answer_icon_size + |
| 376 GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING); | 376 GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING); |
| 377 } | 377 } |
| 378 } else { | 378 } else { |
| 379 x = DrawRenderText(match, separator_rendertext_.get(), false, canvas, | 379 x = DrawRenderText(match, separator_rendertext_.get(), SEPARATOR, canvas, |
| 380 after_contents_x, y, separator_width_); | 380 after_contents_x, y, separator_width_); |
| 381 } | 381 } |
| 382 | 382 |
| 383 DrawRenderText(match, description, false, canvas, x, y, | 383 DrawRenderText(match, description, DESCRIPTION, canvas, x, y, |
| 384 description_max_width); | 384 description_max_width); |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 | 387 |
| 388 int OmniboxResultView::DrawRenderText( | 388 int OmniboxResultView::DrawRenderText( |
| 389 const AutocompleteMatch& match, | 389 const AutocompleteMatch& match, |
| 390 gfx::RenderText* render_text, | 390 gfx::RenderText* render_text, |
| 391 bool contents, | 391 RenderTextType render_text_type, |
| 392 gfx::Canvas* canvas, | 392 gfx::Canvas* canvas, |
| 393 int x, | 393 int x, |
| 394 int y, | 394 int y, |
| 395 int max_width) const { | 395 int max_width) const { |
| 396 DCHECK(!render_text->text().empty()); | 396 DCHECK(!render_text->text().empty()); |
| 397 | 397 |
| 398 const int remaining_width = mirroring_context_->remaining_width(x); | 398 const int remaining_width = mirroring_context_->remaining_width(x); |
| 399 int right_x = x + max_width; | 399 int right_x = x + max_width; |
| 400 | 400 |
| 401 // Infinite suggestions should appear with the leading ellipses vertically | 401 // Infinite suggestions should appear with the leading ellipses vertically |
| 402 // stacked. | 402 // stacked. |
| 403 if (contents && | 403 if (render_text_type == CONTENTS && |
| 404 (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL)) { | 404 match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { |
| 405 // When the directionality of suggestion doesn't match the UI, we try to | 405 // When the directionality of suggestion doesn't match the UI, we try to |
| 406 // vertically stack the ellipsis by restricting the end edge (right_x). | 406 // vertically stack the ellipsis by restricting the end edge (right_x). |
| 407 const bool is_ui_rtl = base::i18n::IsRTL(); | 407 const bool is_ui_rtl = base::i18n::IsRTL(); |
| 408 const bool is_match_contents_rtl = | 408 const bool is_match_contents_rtl = |
| 409 (render_text->GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT); | 409 (render_text->GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT); |
| 410 const int offset = | 410 const int offset = |
| 411 GetDisplayOffset(match, is_ui_rtl, is_match_contents_rtl); | 411 GetDisplayOffset(match, is_ui_rtl, is_match_contents_rtl); |
| 412 | 412 |
| 413 scoped_ptr<gfx::RenderText> prefix_render_text( | 413 scoped_ptr<gfx::RenderText> prefix_render_text( |
| 414 CreateRenderText(base::UTF8ToUTF16( | 414 CreateRenderText(base::UTF8ToUTF16( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); | 448 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); |
| 449 prefix_render_text->SetHorizontalAlignment( | 449 prefix_render_text->SetHorizontalAlignment( |
| 450 is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); | 450 is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); |
| 451 prefix_render_text->SetDisplayRect( | 451 prefix_render_text->SetDisplayRect( |
| 452 gfx::Rect(mirroring_context_->mirrored_left_coord( | 452 gfx::Rect(mirroring_context_->mirrored_left_coord( |
| 453 prefix_x, prefix_x + prefix_width), | 453 prefix_x, prefix_x + prefix_width), |
| 454 y, prefix_width, GetContentLineHeight())); | 454 y, prefix_width, GetContentLineHeight())); |
| 455 prefix_render_text->Draw(canvas); | 455 prefix_render_text->Draw(canvas); |
| 456 } | 456 } |
| 457 | 457 |
| 458 int height = (render_text_type == DESCRIPTION && match.answer) ? | |
|
Peter Kasting
2015/10/19 20:47:11
Nit: const
I'd probably also place this line just
tdanderson
2015/10/20 14:20:15
Done.
| |
| 459 GetAnswerLineHeight() : GetContentLineHeight(); | |
| 460 | |
| 458 // Set the display rect to trigger eliding. | 461 // Set the display rect to trigger eliding. |
| 459 render_text->SetDisplayRect( | 462 render_text->SetDisplayRect( |
| 460 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, | 463 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, |
| 461 right_x - x, GetContentLineHeight())); | 464 right_x - x, height)); |
|
Peter Kasting
2015/10/19 20:47:11
Wow, wouldn't this have made the non-MD answer con
tdanderson
2015/10/20 14:20:15
Yes, without MD GetContentsLineHeight() was return
| |
| 462 render_text->Draw(canvas); | 465 render_text->Draw(canvas); |
| 463 return right_x; | 466 return right_x; |
| 464 } | 467 } |
| 465 | 468 |
| 466 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( | 469 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( |
| 467 const base::string16& text) const { | 470 const base::string16& text) const { |
| 468 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); | 471 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); |
| 469 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); | 472 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); |
| 470 render_text->SetCursorEnabled(false); | 473 render_text->SetCursorEnabled(false); |
| 471 render_text->SetElideBehavior(gfx::ELIDE_TAIL); | 474 render_text->SetElideBehavior(gfx::ELIDE_TAIL); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 | 806 |
| 804 int OmniboxResultView::StartMargin() const { | 807 int OmniboxResultView::StartMargin() const { |
| 805 return ui::MaterialDesignController::IsModeMaterial() ? | 808 return ui::MaterialDesignController::IsModeMaterial() ? |
| 806 model_->start_margin() : 0; | 809 model_->start_margin() : 0; |
| 807 } | 810 } |
| 808 | 811 |
| 809 int OmniboxResultView::EndMargin() const { | 812 int OmniboxResultView::EndMargin() const { |
| 810 return ui::MaterialDesignController::IsModeMaterial() ? | 813 return ui::MaterialDesignController::IsModeMaterial() ? |
| 811 model_->end_margin() : 0; | 814 model_->end_margin() : 0; |
| 812 } | 815 } |
| OLD | NEW |