Commit 7ae88a32 authored by sdefresne's avatar sdefresne Committed by Commit bot

Revert of Delete pre-MD code from OmniboxResultView (patchset #9 id:160001 of...

Revert of Delete pre-MD code from OmniboxResultView (patchset #9 id:160001 of https://codereview.chromium.org/2365263006/ )

Reason for revert:
The downstream Chrome on iOS code has never been ported to the new vector icon and still use MD raster icon. This CL breaks Chrome on iOS downstream (due to missing resources and removal of GetIcon() method).

Original issue's description:
> Delete pre-MD code from OmniboxResultView
>
> BUG=648281
>
> Committed: https://crrev.com/255d6d6d2bbc0e8715ad0985d239897f80a4b707
> Cr-Commit-Position: refs/heads/master@{#423690}

TBR=pkasting@chromium.org,blundell@chromium.org,sky@chromium.org,estade@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=648281

Review-Url: https://codereview.chromium.org/2399333002
Cr-Commit-Position: refs/heads/master@{#423819}
parent b419b459
...@@ -360,6 +360,8 @@ ...@@ -360,6 +360,8 @@
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_EV_BUBBLE_TOP_LEFT" file="common/omnibox_ev_bubble_top_left.png" /> <structure type="chrome_scaled_image" name="IDR_OMNIBOX_EV_BUBBLE_TOP_LEFT" file="common/omnibox_ev_bubble_top_left.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_EV_BUBBLE_TOP_RIGHT" file="common/omnibox_ev_bubble_top_right.png" /> <structure type="chrome_scaled_image" name="IDR_OMNIBOX_EV_BUBBLE_TOP_RIGHT" file="common/omnibox_ev_bubble_top_right.png" />
</if> </if>
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_EXTENSION_APP_SELECTED" file="common/omnibox_extension_app_selected.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HTTP_SELECTED" file="common/omnibox_http_selected.png" />
<if expr="is_macosx or is_ios"> <if expr="is_macosx or is_ios">
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_KEYWORD_HINT_TAB" file="mac/omnibox_keyword_hint_tab.png" /> <structure type="chrome_scaled_image" name="IDR_OMNIBOX_KEYWORD_HINT_TAB" file="mac/omnibox_keyword_hint_tab.png" />
</if> </if>
...@@ -384,7 +386,10 @@ ...@@ -384,7 +386,10 @@
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE_TOP" file="common/omnibox_selected_keyword_bubble_top.png" /> <structure type="chrome_scaled_image" name="IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE_TOP" file="common/omnibox_selected_keyword_bubble_top.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE_TOP_LEFT" file="common/omnibox_selected_keyword_bubble_top_left.png" /> <structure type="chrome_scaled_image" name="IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE_TOP_LEFT" file="common/omnibox_selected_keyword_bubble_top_left.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE_TOP_RIGHT" file="common/omnibox_selected_keyword_bubble_top_right.png" /> <structure type="chrome_scaled_image" name="IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE_TOP_RIGHT" file="common/omnibox_selected_keyword_bubble_top_right.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_STAR" file="common/omnibox_star.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_STAR_SELECTED" file="common/omnibox_star_selected.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_TTS" file="common/omnibox_tts.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_TTS_SELECTED" file="common/omnibox_tts_selected.png" />
<if expr="toolkit_views and not is_macosx"> <if expr="toolkit_views and not is_macosx">
<!-- This image is not used in Material Design and can be removed when that mode is default. --> <!-- This image is not used in Material Design and can be removed when that mode is default. -->
<if expr="not use_ash"> <if expr="not use_ash">
......
...@@ -20,22 +20,21 @@ ...@@ -20,22 +20,21 @@
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/grit/locale_settings.h" #include "chrome/grit/locale_settings.h"
#include "chrome/grit/theme_resources.h"
#include "chromeos/login/login_state.h" #include "chromeos/login/login_state.h"
#include "chromeos/network/network_state.h" #include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler.h"
#include "components/device_event_log/device_event_log.h" #include "components/device_event_log/device_event_log.h"
#include "components/grit/components_scaled_resources.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
#include "ui/accessibility/ax_view_state.h" #include "ui/accessibility/ax_view_state.h"
#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_event_dispatcher.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
#include "ui/views/controls/button/md_text_button.h" #include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_constants.h" #include "ui/views/layout/layout_constants.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -313,25 +312,49 @@ void ChildNetworkConfigView::GetShareStateForLoginState(bool* default_value, ...@@ -313,25 +312,49 @@ void ChildNetworkConfigView::GetShareStateForLoginState(bool* default_value,
// ControlledSettingIndicatorView // ControlledSettingIndicatorView
ControlledSettingIndicatorView::ControlledSettingIndicatorView()
: managed_(false), image_view_(nullptr) {
Init();
}
ControlledSettingIndicatorView::ControlledSettingIndicatorView( ControlledSettingIndicatorView::ControlledSettingIndicatorView(
const NetworkPropertyUIData& ui_data) const NetworkPropertyUIData& ui_data)
: managed_(ui_data.IsManaged()), image_view_(nullptr) { : managed_(false), image_view_(nullptr) {
image_view_ = new views::ImageView(); Init();
// Disable |image_view_| so mouse events propagate to the parent. Update(ui_data);
image_view_->SetEnabled(false);
image_view_->SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::BUSINESS, 16,
gfx::kChromeIconGrey));
image_view_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY));
AddChildView(image_view_);
SetLayoutManager(new views::FillLayout());
} }
ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {}
void ControlledSettingIndicatorView::Update(
const NetworkPropertyUIData& ui_data) {
if (managed_ == ui_data.IsManaged())
return;
managed_ = ui_data.IsManaged();
PreferredSizeChanged();
}
gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const { gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const {
return (managed_ && visible()) ? image_view_->GetPreferredSize() return (managed_ && visible()) ? image_view_->GetPreferredSize()
: gfx::Size(); : gfx::Size();
} }
void ControlledSettingIndicatorView::Layout() {
image_view_->SetBounds(0, 0, width(), height());
}
void ControlledSettingIndicatorView::Init() {
image_ = ResourceBundle::GetSharedInstance()
.GetImageNamed(IDR_OMNIBOX_HTTPS_POLICY_WARNING)
.ToImageSkia();
image_view_ = new views::ImageView();
// Disable |image_view_| so mouse events propagate to the parent.
image_view_->SetEnabled(false);
image_view_->SetImage(image_);
image_view_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY));
AddChildView(image_view_);
}
} // namespace chromeos } // namespace chromeos
...@@ -160,16 +160,25 @@ class ChildNetworkConfigView : public views::View { ...@@ -160,16 +160,25 @@ class ChildNetworkConfigView : public views::View {
// control. // control.
class ControlledSettingIndicatorView : public views::View { class ControlledSettingIndicatorView : public views::View {
public: public:
ControlledSettingIndicatorView();
explicit ControlledSettingIndicatorView(const NetworkPropertyUIData& ui_data); explicit ControlledSettingIndicatorView(const NetworkPropertyUIData& ui_data);
~ControlledSettingIndicatorView() override; ~ControlledSettingIndicatorView() override;
// Updates the view based on |ui_data|.
void Update(const NetworkPropertyUIData& ui_data);
protected: protected:
// views::View: // views::View:
gfx::Size GetPreferredSize() const override; gfx::Size GetPreferredSize() const override;
void Layout() override;
private: private:
// Initializes the view.
void Init();
bool managed_; bool managed_;
views::ImageView* image_view_; views::ImageView* image_view_;
const gfx::ImageSkia* image_;
DISALLOW_COPY_AND_ASSIGN(ControlledSettingIndicatorView); DISALLOW_COPY_AND_ASSIGN(ControlledSettingIndicatorView);
}; };
......
...@@ -43,10 +43,7 @@ ...@@ -43,10 +43,7 @@
#include "extensions/common/manifest_url_handlers.h" #include "extensions/common/manifest_url_handlers.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
namespace extensions { namespace extensions {
...@@ -330,8 +327,8 @@ void ExtensionContextMenuModel::InitMenu(const Extension* extension, ...@@ -330,8 +327,8 @@ void ExtensionContextMenuModel::InitMenu(const Extension* extension,
if (is_required_by_policy) { if (is_required_by_policy) {
int uninstall_index = GetIndexOfCommandId(UNINSTALL); int uninstall_index = GetIndexOfCommandId(UNINSTALL);
SetIcon(uninstall_index, SetIcon(uninstall_index,
gfx::Image(gfx::CreateVectorIcon(gfx::VectorIconId::BUSINESS, 16, ui::ResourceBundle::GetSharedInstance().GetImageNamed(
gfx::kChromeIconGrey))); IDR_OMNIBOX_HTTPS_POLICY_WARNING));
} }
} }
......
...@@ -12,10 +12,13 @@ ...@@ -12,10 +12,13 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/search/search_util.h" #include "chrome/browser/ui/app_list/search/search_util.h"
#include "chrome/grit/theme_resources.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/omnibox/browser/autocomplete_controller.h" #include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_match_type.h" #include "components/omnibox/browser/autocomplete_match_type.h"
#include "ui/app_list/app_list_constants.h" #include "ui/app_list/app_list_constants.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h" #include "ui/gfx/vector_icons_public.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -168,10 +171,18 @@ void OmniboxResult::UpdateIcon() { ...@@ -168,10 +171,18 @@ void OmniboxResult::UpdateIcon() {
bool is_bookmarked = bool is_bookmarked =
bookmark_model && bookmark_model->IsBookmarked(match_.destination_url); bookmark_model && bookmark_model->IsBookmarked(match_.destination_url);
gfx::VectorIconId icon_id = is_bookmarked ? if (ui::MaterialDesignController::IsModeMaterial()) {
gfx::VectorIconId::OMNIBOX_STAR : gfx::VectorIconId icon_id = is_bookmarked ?
AutocompleteMatch::TypeToVectorIcon(match_.type); gfx::VectorIconId::OMNIBOX_STAR :
SetIcon(gfx::CreateVectorIcon(icon_id, 16, app_list::kIconColor)); AutocompleteMatch::TypeToVectorIcon(match_.type);
SetIcon(gfx::CreateVectorIcon(icon_id, 16, app_list::kIconColor));
return;
}
int resource_id = is_bookmarked ? IDR_OMNIBOX_STAR
: AutocompleteMatch::TypeToIcon(match_.type);
SetIcon(
*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id));
} }
void OmniboxResult::UpdateTitleAndDetails() { void OmniboxResult::UpdateTitleAndDetails() {
......
...@@ -477,7 +477,8 @@ int OmniboxPopupContentsView::CalculatePopupHeight() { ...@@ -477,7 +477,8 @@ int OmniboxPopupContentsView::CalculatePopupHeight() {
OmniboxResultView* OmniboxPopupContentsView::CreateResultView( OmniboxResultView* OmniboxPopupContentsView::CreateResultView(
int model_index, int model_index,
const gfx::FontList& font_list) { const gfx::FontList& font_list) {
return new OmniboxResultView(this, model_index, font_list); return new OmniboxResultView(this, model_index, location_bar_view_,
font_list);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -22,14 +22,17 @@ ...@@ -22,14 +22,17 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/browser/ui/layout_constants.h" #include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
#include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/grit/components_scaled_resources.h" #include "components/grit/components_scaled_resources.h"
#include "components/omnibox/browser/omnibox_popup_model.h" #include "components/omnibox/browser/omnibox_popup_model.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/accessibility/ax_view_state.h" #include "ui/accessibility/ax_view_state.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/base/theme_provider.h" #include "ui/base/theme_provider.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
...@@ -39,6 +42,7 @@ ...@@ -39,6 +42,7 @@
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/range/range.h" #include "ui/gfx/range/range.h"
#include "ui/gfx/render_text.h" #include "ui/gfx/render_text.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/text_utils.h" #include "ui/gfx/text_utils.h"
#include "ui/gfx/vector_icons_public.h" #include "ui/gfx/vector_icons_public.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
...@@ -184,9 +188,11 @@ class OmniboxResultView::MirroringContext { ...@@ -184,9 +188,11 @@ class OmniboxResultView::MirroringContext {
OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model,
int model_index, int model_index,
LocationBarView* location_bar_view,
const gfx::FontList& font_list) const gfx::FontList& font_list)
: model_(model), : model_(model),
model_index_(model_index), model_index_(model_index),
location_bar_view_(location_bar_view),
font_list_(font_list), font_list_(font_list),
font_height_(std::max( font_height_(std::max(
font_list.GetHeight(), font_list.GetHeight(),
...@@ -195,10 +201,11 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, ...@@ -195,10 +201,11 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model,
keyword_icon_(new views::ImageView()), keyword_icon_(new views::ImageView()),
animation_(new gfx::SlideAnimation(this)) { animation_(new gfx::SlideAnimation(this)) {
CHECK_GE(model_index, 0); CHECK_GE(model_index, 0);
if (default_icon_size_ == 0)
default_icon_size_ = LocationBarView::kIconWidth;
keyword_icon_->set_owned_by_client(); keyword_icon_->set_owned_by_client();
keyword_icon_->EnableCanvasFlippingForRTLUI(true); keyword_icon_->EnableCanvasFlippingForRTLUI(true);
keyword_icon_->SetImage( keyword_icon_->SetImage(GetKeywordIcon());
GetVectorIcon(gfx::VectorIconId::OMNIBOX_KEYWORD_SEARCH));
keyword_icon_->SizeToPreferredSize(); keyword_icon_->SizeToPreferredSize();
} }
...@@ -246,14 +253,18 @@ void OmniboxResultView::ShowKeyword(bool show_keyword) { ...@@ -246,14 +253,18 @@ void OmniboxResultView::ShowKeyword(bool show_keyword) {
} }
void OmniboxResultView::Invalidate() { void OmniboxResultView::Invalidate() {
const ResultViewState state = GetState(); if (ui::MaterialDesignController::IsModeMaterial()) {
if (state == NORMAL) { const ResultViewState state = GetState();
set_background(nullptr); if (state == NORMAL) {
} else { set_background(nullptr);
const SkColor bg_color = GetColor(state, BACKGROUND); } else {
set_background(new BackgroundWith1PxBorder(bg_color, bg_color)); const SkColor bg_color = GetColor(state, BACKGROUND);
set_background(new BackgroundWith1PxBorder(bg_color, bg_color));
}
} }
keyword_icon_->SetImage(GetKeywordIcon());
// While the text in the RenderTexts may not have changed, the styling // While the text in the RenderTexts may not have changed, the styling
// (color/bold) may need to change. So we reset them to cause them to be // (color/bold) may need to change. So we reset them to cause them to be
// recomputed in OnPaint(). // recomputed in OnPaint().
...@@ -492,7 +503,7 @@ std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateClassifiedRenderText( ...@@ -492,7 +503,7 @@ std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateClassifiedRenderText(
ColorKind color_kind = TEXT; ColorKind color_kind = TEXT;
if (classifications[i].style & ACMatchClassification::URL) { if (classifications[i].style & ACMatchClassification::URL) {
color_kind = URL; color_kind = URL;
// Consider logical string for domain "ABC.com/hello" where ABC are // Consider logical string for domain "ABC.comי/hello" where ABC are
// Hebrew (RTL) characters. This string should ideally show as // Hebrew (RTL) characters. This string should ideally show as
// "CBA.com/hello". If we do not force LTR on URL, it will appear as // "CBA.com/hello". If we do not force LTR on URL, it will appear as
// "com/hello.CBA". // "com/hello.CBA".
...@@ -551,6 +562,9 @@ int OmniboxResultView::GetDisplayOffset( ...@@ -551,6 +562,9 @@ int OmniboxResultView::GetDisplayOffset(
(input_render_text->GetContentWidth() - start_padding) : start_padding; (input_render_text->GetContentWidth() - start_padding) : start_padding;
} }
// static
int OmniboxResultView::default_icon_size_ = 0;
const char* OmniboxResultView::GetClassName() const { const char* OmniboxResultView::GetClassName() const {
return "OmniboxResultView"; return "OmniboxResultView";
} }
...@@ -560,10 +574,51 @@ gfx::ImageSkia OmniboxResultView::GetIcon() const { ...@@ -560,10 +574,51 @@ gfx::ImageSkia OmniboxResultView::GetIcon() const {
if (!image.IsEmpty()) if (!image.IsEmpty())
return image.AsImageSkia(); return image.AsImageSkia();
return GetVectorIcon( if (ui::MaterialDesignController::IsModeMaterial()) {
model_->IsStarredMatch(match_) return GetVectorIcon(
? gfx::VectorIconId::OMNIBOX_STAR model_->IsStarredMatch(match_)
: AutocompleteMatch::TypeToVectorIcon(match_.type)); ? gfx::VectorIconId::OMNIBOX_STAR
: AutocompleteMatch::TypeToVectorIcon(match_.type));
}
int icon = model_->IsStarredMatch(match_) ?
IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type);
if (GetState() == SELECTED) {
switch (icon) {
case IDR_OMNIBOX_CALCULATOR:
icon = IDR_OMNIBOX_CALCULATOR_SELECTED;
break;
case IDR_OMNIBOX_EXTENSION_APP:
icon = IDR_OMNIBOX_EXTENSION_APP_SELECTED;
break;
case IDR_OMNIBOX_HTTP:
icon = IDR_OMNIBOX_HTTP_SELECTED;
break;
case IDR_OMNIBOX_SEARCH:
icon = IDR_OMNIBOX_SEARCH_SELECTED;
break;
case IDR_OMNIBOX_STAR:
icon = IDR_OMNIBOX_STAR_SELECTED;
break;
default:
NOTREACHED();
break;
}
}
return *location_bar_view_->GetThemeProvider()->GetImageSkiaNamed(icon);
}
gfx::ImageSkia OmniboxResultView::GetKeywordIcon() const {
if (ui::MaterialDesignController::IsModeMaterial())
return GetVectorIcon(gfx::VectorIconId::OMNIBOX_KEYWORD_SEARCH);
// NOTE: If we ever begin returning icons of varying size, then callers need
// to ensure that |keyword_icon_| is resized each time its image is reset.
int icon = IDR_OMNIBOX_TTS;
if (GetState() == SELECTED)
icon = IDR_OMNIBOX_TTS_SELECTED;
return *location_bar_view_->GetThemeProvider()->GetImageSkiaNamed(icon);
} }
gfx::ImageSkia OmniboxResultView::GetVectorIcon( gfx::ImageSkia OmniboxResultView::GetVectorIcon(
...@@ -591,18 +646,31 @@ void OmniboxResultView::InitContentsRenderTextIfNecessary() const { ...@@ -591,18 +646,31 @@ void OmniboxResultView::InitContentsRenderTextIfNecessary() const {
void OmniboxResultView::Layout() { void OmniboxResultView::Layout() {
int horizontal_padding = int horizontal_padding =
GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
// The horizontal bounds we're given are the outside bounds, so we can match // In non-material, the horizontal bounds we're given are indented inside the
// the omnibox border outline shape exactly in OnPaint(). We have to inset // omnibox border. In material, we're given the outside bounds, so we can
// here to keep the icons lined up. // match the omnibox border outline shape exactly in OnPaint(). So we have to
const int start_x = // inset here to keep the icons lined up.
GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) + horizontal_padding; const int border_padding = ui::MaterialDesignController::IsModeMaterial() ?
const int end_x = width() - start_x; GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) : 0;
const int start_x = border_padding + horizontal_padding;
const int end_x = width() - border_padding - horizontal_padding;
const gfx::ImageSkia icon = GetIcon(); const gfx::ImageSkia icon = GetIcon();
icon_bounds_.SetRect(start_x, (GetContentLineHeight() - icon.height()) / 2, // Pre-MD, normal icons are 19 px wide, while extension icons are 16 px wide.
// The code in IconLabelBubbleView::Layout() positions these icons in the
// omnibox using ICON_LABEL_VIEW_TRAILING_PADDING, so we use that here as well
// so the icons will line up.
//
// Technically we don't need the IsModeMaterial() check here, but it will make
// it easier to see that all this code is dead once we switch to MD.
int icon_x = start_x;
if (!ui::MaterialDesignController::IsModeMaterial() &&
(icon.width() != default_icon_size_))
icon_x += IconLabelBubbleView::kTrailingPaddingPreMd;
icon_bounds_.SetRect(icon_x, (GetContentLineHeight() - icon.height()) / 2,
icon.width(), icon.height()); icon.width(), icon.height());
const int text_x = start_x + LocationBarView::kIconWidth + horizontal_padding; const int text_x = start_x + default_icon_size_ + horizontal_padding;
int text_width = end_x - text_x; int text_width = end_x - text_x;
if (match_.associated_keyword.get()) { if (match_.associated_keyword.get()) {
...@@ -625,7 +693,13 @@ void OmniboxResultView::OnBoundsChanged(const gfx::Rect& previous_bounds) { ...@@ -625,7 +693,13 @@ void OmniboxResultView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
} }
void OmniboxResultView::OnPaint(gfx::Canvas* canvas) { void OmniboxResultView::OnPaint(gfx::Canvas* canvas) {
View::OnPaint(canvas); if (ui::MaterialDesignController::IsModeMaterial()) {
View::OnPaint(canvas);
} else {
const ResultViewState state = GetState();
if (state != NORMAL)
canvas->DrawColor(GetColor(state, BACKGROUND));
}
// NOTE: While animating the keyword match, both matches may be visible. // NOTE: While animating the keyword match, both matches may be visible.
...@@ -688,8 +762,7 @@ int OmniboxResultView::GetAnswerLineHeight() const { ...@@ -688,8 +762,7 @@ int OmniboxResultView::GetAnswerLineHeight() const {
int OmniboxResultView::GetContentLineHeight() const { int OmniboxResultView::GetContentLineHeight() const {
return std::max( return std::max(
LocationBarView::kIconWidth + default_icon_size_ + GetLayoutInsets(OMNIBOX_DROPDOWN_ICON).height(),
GetLayoutInsets(OMNIBOX_DROPDOWN_ICON).height(),
GetTextHeight() + GetLayoutInsets(OMNIBOX_DROPDOWN_TEXT).height()); GetTextHeight() + GetLayoutInsets(OMNIBOX_DROPDOWN_TEXT).height());
} }
......
...@@ -50,6 +50,7 @@ class OmniboxResultView : public views::View, ...@@ -50,6 +50,7 @@ class OmniboxResultView : public views::View,
OmniboxResultView(OmniboxPopupContentsView* model, OmniboxResultView(OmniboxPopupContentsView* model,
int model_index, int model_index,
LocationBarView* location_bar_view,
const gfx::FontList& font_list); const gfx::FontList& font_list);
~OmniboxResultView() override; ~OmniboxResultView() override;
...@@ -132,6 +133,8 @@ class OmniboxResultView : public views::View, ...@@ -132,6 +133,8 @@ class OmniboxResultView : public views::View,
gfx::ImageSkia GetIcon() const; gfx::ImageSkia GetIcon() const;
gfx::ImageSkia GetKeywordIcon() const;
// Utility function for creating vector icons. // Utility function for creating vector icons.
gfx::ImageSkia GetVectorIcon(gfx::VectorIconId icon_id) const; gfx::ImageSkia GetVectorIcon(gfx::VectorIconId icon_id) const;
...@@ -181,10 +184,14 @@ class OmniboxResultView : public views::View, ...@@ -181,10 +184,14 @@ class OmniboxResultView : public views::View,
int text_type, int text_type,
bool is_bold) const; bool is_bold) const;
static int default_icon_size_;
// This row's model and model index. // This row's model and model index.
OmniboxPopupContentsView* model_; OmniboxPopupContentsView* model_;
size_t model_index_; size_t model_index_;
LocationBarView* location_bar_view_;
const gfx::FontList font_list_; const gfx::FontList font_list_;
int font_height_; int font_height_;
......
...@@ -162,8 +162,8 @@ a { ...@@ -162,8 +162,8 @@ a {
#search-image { #search-image {
content: content:
-webkit-image-set( -webkit-image-set(
url(../../resources/default_100_percent/neterror/search_glass.png) 1x, url(../../resources/default_100_percent/omnibox/omnibox_search_button_loupe.png) 1x,
url(../../resources/default_200_percent/neterror/search_glass.png) 2x); url(../../resources/default_200_percent/omnibox/omnibox_search_button_loupe.png) 2x);
margin: auto; margin: auto;
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "components/search_engines/template_url.h" #include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/url_formatter/url_formatter.h" #include "components/url_formatter/url_formatter.h"
#include "grit/components_scaled_resources.h"
#include "ui/gfx/vector_icons_public.h" #include "ui/gfx/vector_icons_public.h"
namespace { namespace {
...@@ -165,6 +166,66 @@ AutocompleteMatch& AutocompleteMatch::operator=( ...@@ -165,6 +166,66 @@ AutocompleteMatch& AutocompleteMatch::operator=(
return *this; return *this;
} }
// static
int AutocompleteMatch::TypeToIcon(Type type) {
#if !defined(OS_IOS)
static const int kIcons[] = {
IDR_OMNIBOX_HTTP, // URL_WHAT_YOU_TYPE
IDR_OMNIBOX_HTTP, // HISTORY_URL
IDR_OMNIBOX_HTTP, // HISTORY_TITLE
IDR_OMNIBOX_HTTP, // HISTORY_BODY
IDR_OMNIBOX_HTTP, // HISTORY_KEYWORD
IDR_OMNIBOX_HTTP, // NAVSUGGEST
IDR_OMNIBOX_SEARCH, // SEARCH_WHAT_YOU_TYPED
IDR_OMNIBOX_SEARCH, // SEARCH_HISTORY
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_ENTITY
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_TAIL
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_PERSONALIZED
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_PROFILE
IDR_OMNIBOX_SEARCH, // SEARCH_OTHER_ENGINE
IDR_OMNIBOX_EXTENSION_APP, // EXTENSION_APP
IDR_OMNIBOX_SEARCH, // CONTACT_DEPRECATED
IDR_OMNIBOX_HTTP, // BOOKMARK_TITLE
IDR_OMNIBOX_HTTP, // NAVSUGGEST_PERSONALIZED
IDR_OMNIBOX_CALCULATOR, // CALCULATOR
IDR_OMNIBOX_HTTP, // CLIPBOARD
IDR_OMNIBOX_SEARCH, // VOICE_SEARCH
IDR_OMNIBOX_HTTP, // PHYSICAL_WEB
IDR_OMNIBOX_HTTP, // PHYSICAL_WEB_OVERFLOW
};
#else
static const int kIcons[] = {
IDR_OMNIBOX_HTTP, // URL_WHAT_YOU_TYPE
IDR_OMNIBOX_HISTORY, // HISTORY_URL
IDR_OMNIBOX_HISTORY, // HISTORY_TITLE
IDR_OMNIBOX_HISTORY, // HISTORY_BODY
IDR_OMNIBOX_HISTORY, // HISTORY_KEYWORD
IDR_OMNIBOX_HTTP, // NAVSUGGEST
IDR_OMNIBOX_SEARCH, // SEARCH_WHAT_YOU_TYPED
IDR_OMNIBOX_HISTORY, // SEARCH_HISTORY
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_ENTITY
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_TAIL
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_PERSONALIZED
IDR_OMNIBOX_SEARCH, // SEARCH_SUGGEST_PROFILE
IDR_OMNIBOX_SEARCH, // SEARCH_OTHER_ENGINE
IDR_OMNIBOX_EXTENSION_APP, // EXTENSION_APP
IDR_OMNIBOX_SEARCH, // CONTACT_DEPRECATED
IDR_OMNIBOX_HTTP, // BOOKMARK_TITLE
IDR_OMNIBOX_HTTP, // NAVSUGGEST_PERSONALIZED
IDR_OMNIBOX_CALCULATOR, // CALCULATOR
IDR_OMNIBOX_HTTP, // CLIPBOARD
IDR_OMNIBOX_SEARCH, // VOICE_SEARCH
IDR_OMNIBOX_HTTP, // PHYSICAL_WEB
IDR_OMNIBOX_HTTP, // PHYSICAL_WEB_OVERFLOW
};
#endif
static_assert(arraysize(kIcons) == AutocompleteMatchType::NUM_TYPES,
"icons array must have NUM_TYPES elements");
return kIcons[type];
}
// static // static
gfx::VectorIconId AutocompleteMatch::TypeToVectorIcon(Type type) { gfx::VectorIconId AutocompleteMatch::TypeToVectorIcon(Type type) {
#if !defined(OS_ANDROID) && !defined(OS_IOS) #if !defined(OS_ANDROID) && !defined(OS_IOS)
......
...@@ -108,6 +108,10 @@ struct AutocompleteMatch { ...@@ -108,6 +108,10 @@ struct AutocompleteMatch {
// Converts |type| to a string representation. Used in logging and debugging. // Converts |type| to a string representation. Used in logging and debugging.
AutocompleteMatch& operator=(const AutocompleteMatch& match); AutocompleteMatch& operator=(const AutocompleteMatch& match);
// Converts |type| to a resource identifier for the appropriate icon for this
// type to show in the completion popup.
static int TypeToIcon(Type type);
// Gets the vector icon identifier for the icon to be shown for |type|. // Gets the vector icon identifier for the icon to be shown for |type|.
static gfx::VectorIconId TypeToVectorIcon(Type type); static gfx::VectorIconId TypeToVectorIcon(Type type);
......
...@@ -79,13 +79,26 @@ bool OmniboxView::IsEditingOrEmpty() const { ...@@ -79,13 +79,26 @@ bool OmniboxView::IsEditingOrEmpty() const {
(GetOmniboxTextLength() == 0); (GetOmniboxTextLength() == 0);
} }
int OmniboxView::GetIcon() const {
if (!IsEditingOrEmpty())
return controller_->GetToolbarModel()->GetIcon();
int id = AutocompleteMatch::TypeToIcon(model_.get() ?
model_->CurrentTextType() : AutocompleteMatchType::URL_WHAT_YOU_TYPED);
return (id == IDR_OMNIBOX_HTTP) ? IDR_LOCATION_BAR_HTTP : id;
}
gfx::VectorIconId OmniboxView::GetVectorIcon() const { gfx::VectorIconId OmniboxView::GetVectorIcon() const {
#if !defined(OS_ANDROID) && !defined(OS_IOS)
if (!IsEditingOrEmpty()) if (!IsEditingOrEmpty())
return controller_->GetToolbarModel()->GetVectorIcon(); return controller_->GetToolbarModel()->GetVectorIcon();
return AutocompleteMatch::TypeToVectorIcon( return AutocompleteMatch::TypeToVectorIcon(
model_ ? model_->CurrentTextType() model_ ? model_->CurrentTextType()
: AutocompleteMatchType::URL_WHAT_YOU_TYPED); : AutocompleteMatchType::URL_WHAT_YOU_TYPED);
#else
NOTIMPLEMENTED();
return gfx::VectorIconId::VECTOR_ICON_NONE;
#endif
} }
void OmniboxView::SetUserText(const base::string16& text) { void OmniboxView::SetUserText(const base::string16& text) {
......
...@@ -90,6 +90,9 @@ class OmniboxView { ...@@ -90,6 +90,9 @@ class OmniboxView {
// the field is empty. // the field is empty.
bool IsEditingOrEmpty() const; bool IsEditingOrEmpty() const;
// Returns the resource ID of the icon to show for the current text.
int GetIcon() const;
// Like GetIcon(), but returns a vector icon identifier. // Like GetIcon(), but returns a vector icon identifier.
gfx::VectorIconId GetVectorIcon() const; gfx::VectorIconId GetVectorIcon() const;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<part file="crash_scaled_resources.grdp" /> <part file="crash_scaled_resources.grdp" />
<part file="flags_ui_scaled_resources.grdp" /> <part file="flags_ui_scaled_resources.grdp" />
<part file="neterror_scaled_resources.grdp" /> <part file="neterror_scaled_resources.grdp" />
<part file="omnibox_scaled_resources.grdp" />
<part file="version_ui_scaled_resources.grdp" /> <part file="version_ui_scaled_resources.grdp" />
<!-- Generic resources --> <!-- Generic resources -->
......
<?xml version="1.0" encoding="UTF-8"?>
<grit-part>
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_CALCULATOR" file="omnibox/omnibox_calculator.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_EXTENSION_APP" file="omnibox/omnibox_extension_app.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HTTPS_POLICY_WARNING" file="omnibox/controlled_setting_mandatory.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_SEARCH_BUTTON_LOUPE" file="omnibox/omnibox_search_button_loupe.png" />
<if expr="is_ios">
<structure type="chrome_scaled_image" name="IDR_LOCATION_BAR_HTTP" file="omnibox/ios/omnibox_http.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HISTORY" file="omnibox/ios/omnibox_history.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HISTORY_INCOGNITO" file="omnibox/ios/omnibox_history_incognito.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HTTP" file="omnibox/ios/omnibox_http.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HTTPS_INVALID" file="omnibox/ios/omnibox_https_invalid.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HTTPS_VALID" file="omnibox/ios/omnibox_https_valid.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HTTP_INCOGNITO" file="omnibox/ios/omnibox_http_incognito.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_SEARCH" file="omnibox/ios/omnibox_search.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_SEARCH_INCOGNITO" file="omnibox/ios/omnibox_search_incognito.png" />
</if>
<if expr="not is_ios">
<structure type="chrome_scaled_image" name="IDR_LOCATION_BAR_HTTP" file="omnibox/location_bar_http.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HTTP" file="omnibox/omnibox_http.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HTTPS_INVALID" file="omnibox/omnibox_https_invalid.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_HTTPS_VALID" file="omnibox/omnibox_https_valid.png" />
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_SEARCH" file="omnibox/omnibox_search.png" />
</if>
</grit-part>
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/toolbar/test_toolbar_model.h" #include "components/toolbar/test_toolbar_model.h"
#include "components/grit/components_scaled_resources.h"
#include "ui/gfx/vector_icons_public.h" #include "ui/gfx/vector_icons_public.h"
TestToolbarModel::TestToolbarModel() TestToolbarModel::TestToolbarModel()
...@@ -31,6 +32,11 @@ TestToolbarModel::GetSecurityLevel(bool ignore_editing) const { ...@@ -31,6 +32,11 @@ TestToolbarModel::GetSecurityLevel(bool ignore_editing) const {
return security_level_; return security_level_;
} }
int TestToolbarModel::GetIcon() const {
// This placeholder implementation should be removed when MD is default.
return IDR_LOCATION_BAR_HTTP;
}
gfx::VectorIconId TestToolbarModel::GetVectorIcon() const { gfx::VectorIconId TestToolbarModel::GetVectorIcon() const {
return icon_; return icon_;
} }
......
...@@ -27,6 +27,7 @@ class TestToolbarModel : public ToolbarModel { ...@@ -27,6 +27,7 @@ class TestToolbarModel : public ToolbarModel {
GURL GetURL() const override; GURL GetURL() const override;
security_state::SecurityStateModel::SecurityLevel GetSecurityLevel( security_state::SecurityStateModel::SecurityLevel GetSecurityLevel(
bool ignore_editing) const override; bool ignore_editing) const override;
int GetIcon() const override;
gfx::VectorIconId GetVectorIcon() const override; gfx::VectorIconId GetVectorIcon() const override;
base::string16 GetSecureVerboseText() const override; base::string16 GetSecureVerboseText() const override;
base::string16 GetEVCertName() const override; base::string16 GetEVCertName() const override;
......
...@@ -43,10 +43,13 @@ class ToolbarModel { ...@@ -43,10 +43,13 @@ class ToolbarModel {
virtual security_state::SecurityStateModel::SecurityLevel GetSecurityLevel( virtual security_state::SecurityStateModel::SecurityLevel GetSecurityLevel(
bool ignore_editing) const = 0; bool ignore_editing) const = 0;
// Returns the id of the icon to show to the left of the address, based on the // Returns the resource_id of the icon to show to the left of the address,
// current URL. When search term replacement is active, this returns a search // based on the current URL. When search term replacement is active, this
// icon. This doesn't cover specialized icons while the user is editing; see // returns a search icon. This doesn't cover specialized icons while the
// OmniboxView::GetVectorIcon(). // user is editing; see OmniboxView::GetIcon().
virtual int GetIcon() const = 0;
// Like GetIcon(), but gets the vector asset ID.
virtual gfx::VectorIconId GetVectorIcon() const = 0; virtual gfx::VectorIconId GetVectorIcon() const = 0;
// Returns text for the omnibox secure verbose chip. // Returns text for the omnibox secure verbose chip.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/grit/components_scaled_resources.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/security_state/security_state_model.h" #include "components/security_state/security_state_model.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
...@@ -69,6 +70,27 @@ SecurityStateModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( ...@@ -69,6 +70,27 @@ SecurityStateModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel(
: delegate_->GetSecurityLevel(); : delegate_->GetSecurityLevel();
} }
int ToolbarModelImpl::GetIcon() const {
switch (GetSecurityLevel(false)) {
case SecurityStateModel::NONE:
case SecurityStateModel::HTTP_SHOW_WARNING:
return IDR_LOCATION_BAR_HTTP;
case SecurityStateModel::EV_SECURE:
case SecurityStateModel::SECURE:
return IDR_OMNIBOX_HTTPS_VALID;
case SecurityStateModel::SECURITY_WARNING:
// Surface Dubious as Neutral.
return IDR_LOCATION_BAR_HTTP;
case SecurityStateModel::SECURE_WITH_POLICY_INSTALLED_CERT:
return IDR_OMNIBOX_HTTPS_POLICY_WARNING;
case SecurityStateModel::DANGEROUS:
return IDR_OMNIBOX_HTTPS_INVALID;
}
NOTREACHED();
return IDR_LOCATION_BAR_HTTP;
}
gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const { gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const {
#if !defined(OS_ANDROID) && !defined(OS_IOS) #if !defined(OS_ANDROID) && !defined(OS_IOS)
switch (GetSecurityLevel(false)) { switch (GetSecurityLevel(false)) {
...@@ -87,6 +109,7 @@ gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const { ...@@ -87,6 +109,7 @@ gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const {
return gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID; return gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID;
} }
#endif #endif
NOTREACHED(); NOTREACHED();
return gfx::VectorIconId::VECTOR_ICON_NONE; return gfx::VectorIconId::VECTOR_ICON_NONE;
} }
......
...@@ -32,6 +32,7 @@ class ToolbarModelImpl : public ToolbarModel { ...@@ -32,6 +32,7 @@ class ToolbarModelImpl : public ToolbarModel {
GURL GetURL() const override; GURL GetURL() const override;
security_state::SecurityStateModel::SecurityLevel GetSecurityLevel( security_state::SecurityStateModel::SecurityLevel GetSecurityLevel(
bool ignore_editing) const override; bool ignore_editing) const override;
int GetIcon() const override;
gfx::VectorIconId GetVectorIcon() const override; gfx::VectorIconId GetVectorIcon() const override;
base::string16 GetSecureVerboseText() const override; base::string16 GetSecureVerboseText() const override;
base::string16 GetEVCertName() const override; base::string16 GetEVCertName() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment