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

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

Issue 1399253005: Fix layout of omnibox rows for material design (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 years, 2 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
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.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) 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
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Set the display rect to trigger eliding. 458 // Set the display rect to trigger eliding.
459 const int height = (render_text_type == DESCRIPTION && match.answer) ?
460 GetAnswerLineHeight() : GetContentLineHeight();
459 render_text->SetDisplayRect( 461 render_text->SetDisplayRect(
460 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, 462 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y,
461 right_x - x, GetContentLineHeight())); 463 right_x - x, height));
462 render_text->Draw(canvas); 464 render_text->Draw(canvas);
463 return right_x; 465 return right_x;
464 } 466 }
465 467
466 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( 468 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText(
467 const base::string16& text) const { 469 const base::string16& text) const {
468 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); 470 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance());
469 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); 471 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0)));
470 render_text->SetCursorEnabled(false); 472 render_text->SetCursorEnabled(false);
471 render_text->SetElideBehavior(gfx::ELIDE_TAIL); 473 render_text->SetElideBehavior(gfx::ELIDE_TAIL);
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 805
804 int OmniboxResultView::StartMargin() const { 806 int OmniboxResultView::StartMargin() const {
805 return ui::MaterialDesignController::IsModeMaterial() ? 807 return ui::MaterialDesignController::IsModeMaterial() ?
806 model_->start_margin() : 0; 808 model_->start_margin() : 0;
807 } 809 }
808 810
809 int OmniboxResultView::EndMargin() const { 811 int OmniboxResultView::EndMargin() const {
810 return ui::MaterialDesignController::IsModeMaterial() ? 812 return ui::MaterialDesignController::IsModeMaterial() ?
811 model_->end_margin() : 0; 813 model_->end_margin() : 0;
812 } 814 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698