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 | 7 |
| 8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
| 9 #include <atlbase.h> // NOLINT | 9 #include <atlbase.h> // NOLINT |
| 10 #include <atlwin.h> // NOLINT | 10 #include <atlwin.h> // NOLINT |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 14 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
| 15 | 15 |
| 16 #include <limits.h> | 16 #include <limits.h> |
| 17 | 17 |
| 18 #include <algorithm> // NOLINT | 18 #include <algorithm> // NOLINT |
| 19 | 19 |
| 20 #include "base/i18n/bidi_line_iterator.h" | 20 #include "base/i18n/bidi_line_iterator.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 23 #include "chrome/browser/ui/layout_constants.h" | 23 #include "chrome/browser/ui/layout_constants.h" |
| 24 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | |
| 25 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" | |
| 24 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 26 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 25 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" | 27 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" |
| 26 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 27 #include "components/omnibox/browser/omnibox_popup_model.h" | 29 #include "components/omnibox/browser/omnibox_popup_model.h" |
| 28 #include "grit/components_scaled_resources.h" | 30 #include "grit/components_scaled_resources.h" |
| 29 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
| 30 #include "third_party/skia/include/core/SkColor.h" | 32 #include "third_party/skia/include/core/SkColor.h" |
| 31 #include "ui/accessibility/ax_view_state.h" | 33 #include "ui/accessibility/ax_view_state.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/base/material_design/material_design_controller.h" | 35 #include "ui/base/material_design/material_design_controller.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
| 35 #include "ui/base/theme_provider.h" | 37 #include "ui/base/theme_provider.h" |
| 36 #include "ui/gfx/canvas.h" | 38 #include "ui/gfx/canvas.h" |
| 37 #include "ui/gfx/color_palette.h" | 39 #include "ui/gfx/color_palette.h" |
| 38 #include "ui/gfx/color_utils.h" | 40 #include "ui/gfx/color_utils.h" |
| 39 #include "ui/gfx/image/image.h" | 41 #include "ui/gfx/image/image.h" |
| 40 #include "ui/gfx/paint_vector_icon.h" | 42 #include "ui/gfx/paint_vector_icon.h" |
| 41 #include "ui/gfx/range/range.h" | 43 #include "ui/gfx/range/range.h" |
| 42 #include "ui/gfx/render_text.h" | 44 #include "ui/gfx/render_text.h" |
| 45 #include "ui/gfx/scoped_canvas.h" | |
| 43 #include "ui/gfx/text_utils.h" | 46 #include "ui/gfx/text_utils.h" |
| 44 #include "ui/gfx/vector_icons_public.h" | 47 #include "ui/gfx/vector_icons_public.h" |
| 45 #include "ui/native_theme/native_theme.h" | 48 #include "ui/native_theme/native_theme.h" |
| 46 | 49 |
| 47 using ui::NativeTheme; | 50 using ui::NativeTheme; |
| 48 | 51 |
| 49 namespace { | 52 namespace { |
| 50 | 53 |
| 51 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to | 54 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to |
| 52 // NativeTheme colors. | 55 // NativeTheme colors. |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 631 | 634 |
| 632 void OmniboxResultView::InitContentsRenderTextIfNecessary() const { | 635 void OmniboxResultView::InitContentsRenderTextIfNecessary() const { |
| 633 if (!contents_rendertext_) { | 636 if (!contents_rendertext_) { |
| 634 contents_rendertext_.reset( | 637 contents_rendertext_.reset( |
| 635 CreateClassifiedRenderText( | 638 CreateClassifiedRenderText( |
| 636 match_.contents, match_.contents_class, false).release()); | 639 match_.contents, match_.contents_class, false).release()); |
| 637 } | 640 } |
| 638 } | 641 } |
| 639 | 642 |
| 640 void OmniboxResultView::Layout() { | 643 void OmniboxResultView::Layout() { |
| 641 const int horizontal_padding = | 644 int horizontal_padding = |
| 642 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 645 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| 643 const int start_x = StartMargin() + horizontal_padding; | 646 // In non-material, the horizontal bounds we're given are indented inside the |
| 644 const int end_x = width() - EndMargin() - horizontal_padding; | 647 // omnibox border. In material, we're given the outside bounds, so we can |
| 648 // match the omnibox border outline shape exactly in OnPaint(). So we have to | |
| 649 // inset here to keep the icons lined up. | |
| 650 const int border_padding = ui::MaterialDesignController::IsModeMaterial() ? | |
| 651 GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) : 0; | |
| 652 const int start_x = border_padding + horizontal_padding; | |
| 653 const int end_x = width() - border_padding - horizontal_padding; | |
| 645 | 654 |
| 646 const gfx::ImageSkia icon = GetIcon(); | 655 const gfx::ImageSkia icon = GetIcon(); |
| 647 // Pre-MD, normal icons are 19 px wide, while extension icons are 16 px wide. | 656 // Pre-MD, normal icons are 19 px wide, while extension icons are 16 px wide. |
| 648 // The code in IconLabelBubbleView::Layout() positions these icons in the | 657 // The code in IconLabelBubbleView::Layout() positions these icons in the |
| 649 // omnibox using ICON_LABEL_VIEW_TRAILING_PADDING, so we use that here as well | 658 // omnibox using ICON_LABEL_VIEW_TRAILING_PADDING, so we use that here as well |
| 650 // so the icons will line up. | 659 // so the icons will line up. |
| 651 // | 660 // |
| 652 // Technically we don't need the IsModeMaterial() check here, but it will make | 661 // Technically we don't need the IsModeMaterial() check here, but it will make |
| 653 // it easier to see that all this code is dead once we switch to MD. | 662 // it easier to see that all this code is dead once we switch to MD. |
| 654 int icon_x = start_x; | 663 int icon_x = start_x; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 670 keyword_text_bounds_.SetRect( | 679 keyword_text_bounds_.SetRect( |
| 671 kw_text_x, 0, std::max(end_x - kw_text_x, 0), height()); | 680 kw_text_x, 0, std::max(end_x - kw_text_x, 0), height()); |
| 672 keyword_icon_->SetPosition( | 681 keyword_icon_->SetPosition( |
| 673 gfx::Point(kw_x, (height() - keyword_icon_->height()) / 2)); | 682 gfx::Point(kw_x, (height() - keyword_icon_->height()) / 2)); |
| 674 } | 683 } |
| 675 | 684 |
| 676 text_bounds_.SetRect(text_x, 0, std::max(text_width, 0), height()); | 685 text_bounds_.SetRect(text_x, 0, std::max(text_width, 0), height()); |
| 677 } | 686 } |
| 678 | 687 |
| 679 void OmniboxResultView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 688 void OmniboxResultView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 680 animation_->SetSlideDuration((width() - StartMargin() - EndMargin()) / 4); | 689 animation_->SetSlideDuration(width() / 4); |
| 681 } | 690 } |
| 682 | 691 |
| 683 void OmniboxResultView::OnPaint(gfx::Canvas* canvas) { | 692 void OmniboxResultView::OnPaint(gfx::Canvas* canvas) { |
| 684 const ResultViewState state = GetState(); | 693 const ResultViewState state = GetState(); |
| 685 if (state != NORMAL) | 694 if (state != NORMAL) { |
| 686 canvas->DrawColor(GetColor(state, BACKGROUND)); | 695 const SkColor background_color = GetColor(state, BACKGROUND); |
| 696 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 697 SkPaint paint; | |
| 698 paint.setAntiAlias(true); | |
| 699 paint.setColor(background_color); | |
| 700 | |
| 701 // This is similar to the code in BackgroundWith1PxBorder, except that | |
| 702 // instead of stroking along a path offset by 0.5 px, we're filling to | |
| 703 // where the edge of that stroke would be (i.e. on a whole-pixel | |
| 704 // boundary). | |
| 705 gfx::RectF rect(GetLocalBounds()); | |
| 706 gfx::ScopedCanvas scoped_canvas(canvas); | |
| 707 const float scale = canvas->UndoDeviceScaleFactor(); | |
| 708 rect.Scale(scale); | |
| 709 rect.Inset(GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) * scale - 1, | |
| 710 0); | |
| 711 canvas->DrawRoundRect( | |
| 712 rect, BackgroundWith1PxBorder::kCornerRadius * scale + 1, paint); | |
|
Evan Stade
2016/06/16 16:11:32
Would it be possible to set a bgwith1pxborder on |
Peter Kasting
2016/06/16 17:57:13
Yes, although doing it right took more effort than
| |
| 713 } else { | |
| 714 canvas->DrawColor(background_color); | |
| 715 } | |
| 716 } | |
| 687 | 717 |
| 688 // NOTE: While animating the keyword match, both matches may be visible. | 718 // NOTE: While animating the keyword match, both matches may be visible. |
| 689 | 719 |
| 690 if (!ShowOnlyKeywordMatch()) { | 720 if (!ShowOnlyKeywordMatch()) { |
| 691 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), | 721 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), |
| 692 icon_bounds_.y()); | 722 icon_bounds_.y()); |
| 693 int x = GetMirroredXForRect(text_bounds_); | 723 int x = GetMirroredXForRect(text_bounds_); |
| 694 mirroring_context_->Initialize(x, text_bounds_.width()); | 724 mirroring_context_->Initialize(x, text_bounds_.width()); |
| 695 InitContentsRenderTextIfNecessary(); | 725 InitContentsRenderTextIfNecessary(); |
| 696 | 726 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 destination->AppendText(text); | 852 destination->AppendText(text); |
| 823 const TextStyle& text_style = GetTextStyle(text_type); | 853 const TextStyle& text_style = GetTextStyle(text_type); |
| 824 // TODO(dschuyler): follow up on the problem of different font sizes within | 854 // TODO(dschuyler): follow up on the problem of different font sizes within |
| 825 // one RenderText. Maybe with destination->SetFontList(...). | 855 // one RenderText. Maybe with destination->SetFontList(...). |
| 826 destination->ApplyWeight( | 856 destination->ApplyWeight( |
| 827 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); | 857 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); |
| 828 destination->ApplyColor( | 858 destination->ApplyColor( |
| 829 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); | 859 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); |
| 830 destination->ApplyBaselineStyle(text_style.baseline, range); | 860 destination->ApplyBaselineStyle(text_style.baseline, range); |
| 831 } | 861 } |
| 832 | |
| 833 int OmniboxResultView::StartMargin() const { | |
| 834 return ui::MaterialDesignController::IsModeMaterial() ? | |
| 835 model_->start_margin() : 0; | |
| 836 } | |
| 837 | |
| 838 int OmniboxResultView::EndMargin() const { | |
| 839 return ui::MaterialDesignController::IsModeMaterial() ? | |
| 840 model_->end_margin() : 0; | |
| 841 } | |
| OLD | NEW |