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 @@
<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" />
</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">
<structure type="chrome_scaled_image" name="IDR_OMNIBOX_KEYWORD_HINT_TAB" file="mac/omnibox_keyword_hint_tab.png" />
</if>
......@@ -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_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_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">
<!-- This image is not used in Material Design and can be removed when that mode is default. -->
<if expr="not use_ash">
......
......@@ -20,22 +20,21 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/locale_settings.h"
#include "chrome/grit/theme_resources.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "components/device_event_log/device_event_log.h"
#include "components/grit/components_scaled_resources.h"
#include "components/user_manager/user.h"
#include "ui/accessibility/ax_view_state.h"
#include "ui/aura/window_event_dispatcher.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/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/image_view.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_constants.h"
#include "ui/views/widget/widget.h"
......@@ -313,25 +312,49 @@ void ChildNetworkConfigView::GetShareStateForLoginState(bool* default_value,
// ControlledSettingIndicatorView
ControlledSettingIndicatorView::ControlledSettingIndicatorView()
: managed_(false), image_view_(nullptr) {
Init();
}
ControlledSettingIndicatorView::ControlledSettingIndicatorView(
const NetworkPropertyUIData& ui_data)
: managed_(ui_data.IsManaged()), image_view_(nullptr) {
image_view_ = new views::ImageView();
// Disable |image_view_| so mouse events propagate to the parent.
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());
: managed_(false), image_view_(nullptr) {
Init();
Update(ui_data);
}
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 {
return (managed_ && visible()) ? image_view_->GetPreferredSize()
: 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
......@@ -160,16 +160,25 @@ class ChildNetworkConfigView : public views::View {
// control.
class ControlledSettingIndicatorView : public views::View {
public:
ControlledSettingIndicatorView();
explicit ControlledSettingIndicatorView(const NetworkPropertyUIData& ui_data);
~ControlledSettingIndicatorView() override;
// Updates the view based on |ui_data|.
void Update(const NetworkPropertyUIData& ui_data);
protected:
// views::View:
gfx::Size GetPreferredSize() const override;
void Layout() override;
private:
// Initializes the view.
void Init();
bool managed_;
views::ImageView* image_view_;
const gfx::ImageSkia* image_;
DISALLOW_COPY_AND_ASSIGN(ControlledSettingIndicatorView);
};
......
......@@ -43,10 +43,7 @@
#include "extensions/common/manifest_url_handlers.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
namespace extensions {
......@@ -330,8 +327,8 @@ void ExtensionContextMenuModel::InitMenu(const Extension* extension,
if (is_required_by_policy) {
int uninstall_index = GetIndexOfCommandId(UNINSTALL);
SetIcon(uninstall_index,
gfx::Image(gfx::CreateVectorIcon(gfx::VectorIconId::BUSINESS, 16,
gfx::kChromeIconGrey)));
ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_OMNIBOX_HTTPS_POLICY_WARNING));
}
}
......
......@@ -12,10 +12,13 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.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/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_match_type.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/vector_icons_public.h"
#include "url/gurl.h"
......@@ -168,10 +171,18 @@ void OmniboxResult::UpdateIcon() {
bool is_bookmarked =
bookmark_model && bookmark_model->IsBookmarked(match_.destination_url);
gfx::VectorIconId icon_id = is_bookmarked ?
gfx::VectorIconId::OMNIBOX_STAR :
AutocompleteMatch::TypeToVectorIcon(match_.type);
SetIcon(gfx::CreateVectorIcon(icon_id, 16, app_list::kIconColor));
if (ui::MaterialDesignController::IsModeMaterial()) {
gfx::VectorIconId icon_id = is_bookmarked ?
gfx::VectorIconId::OMNIBOX_STAR :
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() {
......
......@@ -477,7 +477,8 @@ int OmniboxPopupContentsView::CalculatePopupHeight() {
OmniboxResultView* OmniboxPopupContentsView::CreateResultView(
int model_index,
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 @@
#include "base/strings/string_util.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/icon_label_bubble_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/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/grit/components_scaled_resources.h"
#include "components/omnibox/browser/omnibox_popup_model.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/accessibility/ax_view_state.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/theme_provider.h"
#include "ui/gfx/canvas.h"
......@@ -39,6 +42,7 @@
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/range/range.h"
#include "ui/gfx/render_text.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/text_utils.h"
#include "ui/gfx/vector_icons_public.h"
#include "ui/native_theme/native_theme.h"
......@@ -184,9 +188,11 @@ class OmniboxResultView::MirroringContext {
OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model,
int model_index,
LocationBarView* location_bar_view,
const gfx::FontList& font_list)
: model_(model),
model_index_(model_index),
location_bar_view_(location_bar_view),
font_list_(font_list),
font_height_(std::max(
font_list.GetHeight(),
......@@ -195,10 +201,11 @@ OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model,
keyword_icon_(new views::ImageView()),
animation_(new gfx::SlideAnimation(this)) {
CHECK_GE(model_index, 0);
if (default_icon_size_ == 0)
default_icon_size_ = LocationBarView::kIconWidth;
keyword_icon_->set_owned_by_client();
keyword_icon_->EnableCanvasFlippingForRTLUI(true);
keyword_icon_->SetImage(
GetVectorIcon(gfx::VectorIconId::OMNIBOX_KEYWORD_SEARCH));
keyword_icon_->SetImage(GetKeywordIcon());
keyword_icon_->SizeToPreferredSize();
}
......@@ -246,14 +253,18 @@ void OmniboxResultView::ShowKeyword(bool show_keyword) {
}
void OmniboxResultView::Invalidate() {
const ResultViewState state = GetState();
if (state == NORMAL) {
set_background(nullptr);
} else {
const SkColor bg_color = GetColor(state, BACKGROUND);
set_background(new BackgroundWith1PxBorder(bg_color, bg_color));
if (ui::MaterialDesignController::IsModeMaterial()) {
const ResultViewState state = GetState();
if (state == NORMAL) {
set_background(nullptr);
} else {
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
// (color/bold) may need to change. So we reset them to cause them to be
// recomputed in OnPaint().
......@@ -492,7 +503,7 @@ std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateClassifiedRenderText(
ColorKind color_kind = TEXT;
if (classifications[i].style & ACMatchClassification::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
// "CBA.com/hello". If we do not force LTR on URL, it will appear as
// "com/hello.CBA".
......@@ -551,6 +562,9 @@ int OmniboxResultView::GetDisplayOffset(
(input_render_text->GetContentWidth() - start_padding) : start_padding;
}
// static
int OmniboxResultView::default_icon_size_ = 0;
const char* OmniboxResultView::GetClassName() const {
return "OmniboxResultView";
}
......@@ -560,10 +574,51 @@ gfx::ImageSkia OmniboxResultView::GetIcon() const {
if (!image.IsEmpty())
return image.AsImageSkia();
return GetVectorIcon(
model_->IsStarredMatch(match_)
? gfx::VectorIconId::OMNIBOX_STAR
: AutocompleteMatch::TypeToVectorIcon(match_.type));
if (ui::MaterialDesignController::IsModeMaterial()) {
return GetVectorIcon(
model_->IsStarredMatch(match_)
? 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(
......@@ -591,18 +646,31 @@ void OmniboxResultView::InitContentsRenderTextIfNecessary() const {
void OmniboxResultView::Layout() {
int horizontal_padding =
GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
// The horizontal bounds we're given are the outside bounds, so we can match
// the omnibox border outline shape exactly in OnPaint(). We have to inset
// here to keep the icons lined up.
const int start_x =
GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) + horizontal_padding;
const int end_x = width() - start_x;
// In non-material, the horizontal bounds we're given are indented inside the
// omnibox border. In material, we're given the outside bounds, so we can
// match the omnibox border outline shape exactly in OnPaint(). So we have to
// inset here to keep the icons lined up.
const int border_padding = ui::MaterialDesignController::IsModeMaterial() ?
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();
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());
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;
if (match_.associated_keyword.get()) {
......@@ -625,7 +693,13 @@ void OmniboxResultView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
}
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.
......@@ -688,8 +762,7 @@ int OmniboxResultView::GetAnswerLineHeight() const {
int OmniboxResultView::GetContentLineHeight() const {
return std::max(
LocationBarView::kIconWidth +
GetLayoutInsets(OMNIBOX_DROPDOWN_ICON).height(),
default_icon_size_ + GetLayoutInsets(OMNIBOX_DROPDOWN_ICON).height(),
GetTextHeight() + GetLayoutInsets(OMNIBOX_DROPDOWN_TEXT).height());
}
......
......@@ -50,6 +50,7 @@ class OmniboxResultView : public views::View,
OmniboxResultView(OmniboxPopupContentsView* model,
int model_index,
LocationBarView* location_bar_view,
const gfx::FontList& font_list);
~OmniboxResultView() override;
......@@ -132,6 +133,8 @@ class OmniboxResultView : public views::View,
gfx::ImageSkia GetIcon() const;
gfx::ImageSkia GetKeywordIcon() const;
// Utility function for creating vector icons.
gfx::ImageSkia GetVectorIcon(gfx::VectorIconId icon_id) const;
......@@ -181,10 +184,14 @@ class OmniboxResultView : public views::View,
int text_type,
bool is_bold) const;
static int default_icon_size_;
// This row's model and model index.
OmniboxPopupContentsView* model_;
size_t model_index_;
LocationBarView* location_bar_view_;
const gfx::FontList font_list_;
int font_height_;
......
......@@ -162,8 +162,8 @@ a {
#search-image {
content:
-webkit-image-set(
url(../../resources/default_100_percent/neterror/search_glass.png) 1x,
url(../../resources/default_200_percent/neterror/search_glass.png) 2x);
url(../../resources/default_100_percent/omnibox/omnibox_search_button_loupe.png) 1x,
url(../../resources/default_200_percent/omnibox/omnibox_search_button_loupe.png) 2x);
margin: auto;
}
......
......@@ -20,6 +20,7 @@
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "components/url_formatter/url_formatter.h"
#include "grit/components_scaled_resources.h"
#include "ui/gfx/vector_icons_public.h"
namespace {
......@@ -165,6 +166,66 @@ AutocompleteMatch& AutocompleteMatch::operator=(
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
gfx::VectorIconId AutocompleteMatch::TypeToVectorIcon(Type type) {
#if !defined(OS_ANDROID) && !defined(OS_IOS)
......
......@@ -108,6 +108,10 @@ struct AutocompleteMatch {
// Converts |type| to a string representation. Used in logging and debugging.
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|.
static gfx::VectorIconId TypeToVectorIcon(Type type);
......
......@@ -79,13 +79,26 @@ bool OmniboxView::IsEditingOrEmpty() const {
(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 {
#if !defined(OS_ANDROID) && !defined(OS_IOS)
if (!IsEditingOrEmpty())
return controller_->GetToolbarModel()->GetVectorIcon();
return AutocompleteMatch::TypeToVectorIcon(
model_ ? model_->CurrentTextType()
: AutocompleteMatchType::URL_WHAT_YOU_TYPED);
#else
NOTIMPLEMENTED();
return gfx::VectorIconId::VECTOR_ICON_NONE;
#endif
}
void OmniboxView::SetUserText(const base::string16& text) {
......
......@@ -90,6 +90,9 @@ class OmniboxView {
// the field is empty.
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.
gfx::VectorIconId GetVectorIcon() const;
......
......@@ -16,6 +16,7 @@
<part file="crash_scaled_resources.grdp" />
<part file="flags_ui_scaled_resources.grdp" />
<part file="neterror_scaled_resources.grdp" />
<part file="omnibox_scaled_resources.grdp" />
<part file="version_ui_scaled_resources.grdp" />
<!-- 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 @@
#include "components/toolbar/test_toolbar_model.h"
#include "components/grit/components_scaled_resources.h"
#include "ui/gfx/vector_icons_public.h"
TestToolbarModel::TestToolbarModel()
......@@ -31,6 +32,11 @@ TestToolbarModel::GetSecurityLevel(bool ignore_editing) const {
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 {
return icon_;
}
......
......@@ -27,6 +27,7 @@ class TestToolbarModel : public ToolbarModel {
GURL GetURL() const override;
security_state::SecurityStateModel::SecurityLevel GetSecurityLevel(
bool ignore_editing) const override;
int GetIcon() const override;
gfx::VectorIconId GetVectorIcon() const override;
base::string16 GetSecureVerboseText() const override;
base::string16 GetEVCertName() const override;
......
......@@ -43,10 +43,13 @@ class ToolbarModel {
virtual security_state::SecurityStateModel::SecurityLevel GetSecurityLevel(
bool ignore_editing) const = 0;
// Returns the id of the icon to show to the left of the address, based on the
// current URL. When search term replacement is active, this returns a search
// icon. This doesn't cover specialized icons while the user is editing; see
// OmniboxView::GetVectorIcon().
// Returns the resource_id of the icon to show to the left of the address,
// based on the current URL. When search term replacement is active, this
// returns a search icon. This doesn't cover specialized icons while the
// 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;
// Returns text for the omnibox secure verbose chip.
......
......@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/grit/components_scaled_resources.h"
#include "components/prefs/pref_service.h"
#include "components/security_state/security_state_model.h"
#include "components/strings/grit/components_strings.h"
......@@ -69,6 +70,27 @@ SecurityStateModel::SecurityLevel ToolbarModelImpl::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 {
#if !defined(OS_ANDROID) && !defined(OS_IOS)
switch (GetSecurityLevel(false)) {
......@@ -87,6 +109,7 @@ gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const {
return gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID;
}
#endif
NOTREACHED();
return gfx::VectorIconId::VECTOR_ICON_NONE;
}
......
......@@ -32,6 +32,7 @@ class ToolbarModelImpl : public ToolbarModel {
GURL GetURL() const override;
security_state::SecurityStateModel::SecurityLevel GetSecurityLevel(
bool ignore_editing) const override;
int GetIcon() const override;
gfx::VectorIconId GetVectorIcon() const override;
base::string16 GetSecureVerboseText() 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