Make the Origin Info Bubble discoverable by focus traversal on Views platforms.
Make the LocationIconView focusable and respond to certain keyboard events.
Refactor to fold PageInfoHelper and the EVBubbleView into LocationIconView.
BUG=536257
TBR=sky
Review URL: https://codereview.chromium.org/1373823004
Cr-Commit-Position: refs/heads/master@{#364757}
diff --git a/chrome/browser/ui/browser_focus_uitest.cc b/chrome/browser/ui/browser_focus_uitest.cc
index dd51bde..a9f7a94 100644
--- a/chrome/browser/ui/browser_focus_uitest.cc
+++ b/chrome/browser/ui/browser_focus_uitest.cc
@@ -119,6 +119,13 @@
}
#endif
+ if (reverse) {
+ ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
+ browser(), key, false, reverse, false, false,
+ content::NOTIFICATION_ALL,
+ content::NotificationService::AllSources()));
+ }
+
for (size_t j = 0; j < arraysize(kExpectedIDs); ++j) {
SCOPED_TRACE(base::StringPrintf("focus inner loop %" PRIuS, j));
const size_t index = reverse ? arraysize(kExpectedIDs) - 1 - j : j;
@@ -147,9 +154,23 @@
browser(), key, false, reverse, false, false,
chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
content::Source<Browser>(browser())));
+ EXPECT_TRUE(
+ IsViewFocused(reverse ? VIEW_ID_OMNIBOX : VIEW_ID_LOCATION_ICON));
+
+ ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
+ browser(), key, false, reverse, false, false,
+ content::NOTIFICATION_ALL,
+ content::NotificationService::AllSources()));
#endif
content::RunAllPendingInMessageLoop();
- EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
+ EXPECT_TRUE(
+ IsViewFocused(reverse ? VIEW_ID_LOCATION_ICON : VIEW_ID_OMNIBOX));
+ if (reverse) {
+ ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
+ browser(), key, false, false, false, false,
+ content::NOTIFICATION_ALL,
+ content::NotificationService::AllSources()));
+ }
}
}
};
diff --git a/chrome/browser/ui/cocoa/view_id_util_browsertest.mm b/chrome/browser/ui/cocoa/view_id_util_browsertest.mm
index 24cc6c21..20a888a 100644
--- a/chrome/browser/ui/cocoa/view_id_util_browsertest.mm
+++ b/chrome/browser/ui/cocoa/view_id_util_browsertest.mm
@@ -27,7 +27,7 @@
using content::OpenURLParams;
using content::Referrer;
-// Basic sanity check of ViewID use on the mac.
+// Basic sanity check of ViewID use on the Mac.
class ViewIDTest : public InProcessBrowserTest {
public:
ViewIDTest() : root_window_(nil) {
@@ -69,13 +69,15 @@
for (int i = VIEW_ID_TOOLBAR; i < VIEW_ID_PREDEFINED_COUNT; ++i) {
// Mac implementation does not support following ids yet.
+ // TODO(palmer): crbug.com/536257: Enable VIEW_ID_LOCATION_ICON.
if (i == VIEW_ID_STAR_BUTTON ||
i == VIEW_ID_CONTENTS_SPLIT ||
i == VIEW_ID_BROWSER_ACTION ||
i == VIEW_ID_FEEDBACK_BUTTON ||
i == VIEW_ID_SCRIPT_BUBBLE ||
i == VIEW_ID_SAVE_CREDIT_CARD_BUTTON ||
- i == VIEW_ID_TRANSLATE_BUTTON) {
+ i == VIEW_ID_TRANSLATE_BUTTON ||
+ i == VIEW_ID_LOCATION_ICON) {
continue;
}
diff --git a/chrome/browser/ui/view_ids.h b/chrome/browser/ui/view_ids.h
index f02d601..a8be3f1 100644
--- a/chrome/browser/ui/view_ids.h
+++ b/chrome/browser/ui/view_ids.h
@@ -57,6 +57,7 @@
VIEW_ID_BROWSER_ACTION_TOOLBAR,
VIEW_ID_BROWSER_ACTION,
VIEW_ID_FEEDBACK_BUTTON,
+ VIEW_ID_LOCATION_ICON,
VIEW_ID_OMNIBOX,
VIEW_ID_SCRIPT_BUBBLE,
VIEW_ID_SAVE_CREDIT_CARD_BUTTON,
diff --git a/chrome/browser/ui/views/location_bar/ev_bubble_view.cc b/chrome/browser/ui/views/location_bar/ev_bubble_view.cc
deleted file mode 100644
index a8c2f3ab..0000000
--- a/chrome/browser/ui/views/location_bar/ev_bubble_view.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
-#include "grit/theme_resources.h"
-#include "ui/base/resource/material_design/material_design_controller.h"
-#include "ui/gfx/paint_vector_icon.h"
-#include "ui/gfx/vector_icons_public.h"
-#include "ui/views/controls/label.h"
-#include "ui/views/painter.h"
-
-EVBubbleView::EVBubbleView(const gfx::FontList& font_list,
- SkColor text_color,
- SkColor parent_background_color,
- LocationBarView* location_bar)
- : IconLabelBubbleView(ui::MaterialDesignController::IsModeMaterial()
- ? 0
- : IDR_OMNIBOX_HTTPS_VALID,
- font_list,
- text_color,
- parent_background_color,
- true),
- text_color_(text_color),
- page_info_helper_(this, location_bar) {
- if (!ui::MaterialDesignController::IsModeMaterial()) {
- static const int kBackgroundImages[] = IMAGE_GRID(IDR_OMNIBOX_EV_BUBBLE);
- SetBackgroundImageGrid(kBackgroundImages);
- }
-}
-
-EVBubbleView::~EVBubbleView() {
-}
-
-SkColor EVBubbleView::GetTextColor() const {
- return text_color_;
-}
-
-SkColor EVBubbleView::GetBorderColor() const {
- return GetTextColor();
-}
-
-gfx::Size EVBubbleView::GetMinimumSize() const {
- return GetMinimumSizeForPreferredSize(GetPreferredSize());
-}
-
-bool EVBubbleView::OnMousePressed(const ui::MouseEvent& event) {
- // We want to show the dialog on mouse release; that is the standard behavior
- // for buttons.
- return true;
-}
-
-void EVBubbleView::OnMouseReleased(const ui::MouseEvent& event) {
- page_info_helper_.ProcessEvent(event);
-}
-
-void EVBubbleView::OnGestureEvent(ui::GestureEvent* event) {
- if (event->type() == ui::ET_GESTURE_TAP) {
- page_info_helper_.ProcessEvent(*event);
- event->SetHandled();
- }
-}
-
-void EVBubbleView::OnNativeThemeChanged(const ui::NativeTheme* native_theme) {
- if (ui::MaterialDesignController::IsModeMaterial()) {
- SetImage(gfx::CreateVectorIcon(
- gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP, 16,
- GetTextColor()));
- }
-
- IconLabelBubbleView::OnNativeThemeChanged(native_theme);
-}
-
-gfx::Size EVBubbleView::GetMinimumSizeForLabelText(
- const base::string16& text) const {
- views::Label label(text, font_list());
- return GetMinimumSizeForPreferredSize(
- GetSizeForLabelWidth(label.GetPreferredSize().width()));
-}
-
-gfx::Size EVBubbleView::GetMinimumSizeForPreferredSize(gfx::Size size) const {
- const int kMinCharacters = 10;
- size.SetToMin(
- GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters)));
- return size;
-}
diff --git a/chrome/browser/ui/views/location_bar/ev_bubble_view.h b/chrome/browser/ui/views/location_bar/ev_bubble_view.h
deleted file mode 100644
index 1e5d74a1..0000000
--- a/chrome/browser/ui/views/location_bar/ev_bubble_view.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_EV_BUBBLE_VIEW_H_
-#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_EV_BUBBLE_VIEW_H_
-
-#include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
-#include "chrome/browser/ui/views/location_bar/page_info_helper.h"
-
-class LocationBarView;
-
-// EVBubbleView displays the EV Bubble in the LocationBarView.
-class EVBubbleView : public IconLabelBubbleView {
- public:
- EVBubbleView(const gfx::FontList& font_list,
- SkColor text_color,
- SkColor parent_background_color,
- LocationBarView* parent);
- ~EVBubbleView() override;
-
- // IconLabelBubbleView:
- SkColor GetTextColor() const override;
- SkColor GetBorderColor() const override;
-
- // views::View:
- gfx::Size GetMinimumSize() const override;
- bool OnMousePressed(const ui::MouseEvent& event) override;
- void OnMouseReleased(const ui::MouseEvent& event) override;
- void OnGestureEvent(ui::GestureEvent* event) override;
- void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override;
-
- // Returns what the minimum size would be if the label text were |text|.
- gfx::Size GetMinimumSizeForLabelText(const base::string16& text) const;
-
- private:
- // Returns what the minimum size would be if the preferred size were |size|.
- gfx::Size GetMinimumSizeForPreferredSize(gfx::Size size) const;
-
- // TODO(estade): this should be gleaned from the theme instead of hardcoded in
- // location_bar_view.cc and cached here.
- SkColor text_color_;
-
- PageInfoHelper page_info_helper_;
-
- DISALLOW_COPY_AND_ASSIGN(EVBubbleView);
-};
-
-#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_EV_BUBBLE_VIEW_H_
diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
index 9befb257..5f047212 100644
--- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
+++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc
@@ -62,8 +62,11 @@
void IconLabelBubbleView::SetBackgroundImageGrid(
const int background_images[]) {
- background_painter_.reset(
- views::Painter::CreateImageGridPainter(background_images));
+ should_show_background_ = true;
+ if (!background_painter_.get()) {
+ background_painter_.reset(
+ views::Painter::CreateImageGridPainter(background_images));
+ }
// Use the middle image of the background to represent the color of the entire
// background.
gfx::ImageSkia* background_image =
@@ -72,6 +75,11 @@
SetLabelBackgroundColor(CalculateImageColor(background_image));
}
+void IconLabelBubbleView::UnsetBackgroundImageGrid() {
+ should_show_background_ = false;
+ SetLabelBackgroundColor(SK_ColorTRANSPARENT);
+}
+
void IconLabelBubbleView::SetLabel(const base::string16& label) {
label_->SetText(label);
}
@@ -80,8 +88,26 @@
image_->SetImage(image_skia);
}
+void IconLabelBubbleView::SetLabelBackgroundColor(
+ SkColor chip_background_color) {
+ // The background images are painted atop |parent_background_color_|.
+ // Alpha-blend |chip_background_color| with |parent_background_color_| to
+ // determine the actual color the label text will sit atop.
+ // Tricky bit: We alpha blend an opaque version of |chip_background_color|
+ // against |parent_background_color_| using the original image grid color's
+ // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged
+ // even if |a| is a color with non-255 alpha.
+ label_->SetBackgroundColor(color_utils::AlphaBlend(
+ SkColorSetA(chip_background_color, 255), GetParentBackgroundColor(),
+ SkColorGetA(chip_background_color)));
+}
+
+void IconLabelBubbleView::SetLabelForegroundColor(SkColor color) {
+ label_->SetEnabledColor(color);
+}
+
bool IconLabelBubbleView::ShouldShowBackground() const {
- return true;
+ return should_show_background_;
}
double IconLabelBubbleView::WidthMultiplier() const {
@@ -91,7 +117,7 @@
int IconLabelBubbleView::GetImageAndPaddingWidth() const {
const int image_width = image_->GetPreferredSize().width();
return image_width
- ? image_width + GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING)
+ ? image_width - GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING)
: 0;
}
@@ -171,20 +197,6 @@
return 2;
}
-void IconLabelBubbleView::SetLabelBackgroundColor(
- SkColor chip_background_color) {
- // The background images are painted atop |parent_background_color_|.
- // Alpha-blend |chip_background_color| with |parent_background_color_| to
- // determine the actual color the label text will sit atop.
- // Tricky bit: We alpha blend an opaque version of |chip_background_color|
- // against |parent_background_color_| using the original image grid color's
- // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged
- // even if |a| is a color with non-255 alpha.
- label_->SetBackgroundColor(color_utils::AlphaBlend(
- SkColorSetA(chip_background_color, 255), GetParentBackgroundColor(),
- SkColorGetA(chip_background_color)));
-}
-
const char* IconLabelBubbleView::GetClassName() const {
return "IconLabelBubbleView";
}
diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h
index ebe4ed59..7b6bfbbc7 100644
--- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h
+++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h
@@ -10,8 +10,8 @@
#include "base/strings/string16.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
+#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
-#include "ui/views/view.h"
namespace gfx {
class Canvas;
@@ -20,15 +20,14 @@
}
namespace views {
-class ImageView;
class Label;
class Painter;
}
-// View used to draw a bubble, containing an icon and a label. We use this as a
-// base for the classes that handle the EV bubble, tab-to-search UI, and
-// content settings.
-class IconLabelBubbleView : public views::View {
+// View used to draw a bubble, containing an icon and a label. We use this as a
+// base for the classes that handle the location icon (including the EV bubble),
+// tab-to-search UI, and content settings.
+class IconLabelBubbleView : public views::ImageView {
public:
// TODO(estade): remove |text_color| which is not used for MD.
IconLabelBubbleView(int contained_image,
@@ -39,9 +38,9 @@
~IconLabelBubbleView() override;
// Sets a background that paints |background_images| in a scalable grid.
- // Subclasses are required to call this or SetBackgroundImageWithInsets during
- // construction.
+ // Subclasses must call this during construction.
void SetBackgroundImageGrid(const int background_images[]);
+ void UnsetBackgroundImageGrid();
void SetLabel(const base::string16& label);
void SetImage(const gfx::ImageSkia& image);
@@ -49,6 +48,12 @@
is_extension_icon_ = is_extension_icon;
}
+ // Sets a background color on |label_| based on |chip_background_color| and
+ // the parent's bg color.
+ void SetLabelBackgroundColor(SkColor chip_background_color);
+
+ void SetLabelForegroundColor(SkColor color);
+
protected:
views::ImageView* image() { return image_; }
views::Label* label() { return label_; }
@@ -56,8 +61,8 @@
// Gets the color for displaying text.
virtual SkColor GetTextColor() const = 0;
- // Gets the color for the border (a more transparent version of
- // which is used for the background).
+ // Gets the color for the border (a more transparent version of which is used
+ // for the background).
virtual SkColor GetBorderColor() const = 0;
// Returns true when the background should be rendered.
@@ -92,10 +97,6 @@
// As above, but for Material Design. TODO(estade): remove/replace the above.
int GetBubbleOuterPaddingMd(bool leading) const;
- // Sets a background color on |label_| based on |chip_background_color| and
- // the parent's bg color.
- void SetLabelBackgroundColor(SkColor chip_background_color);
-
// views::View:
const char* GetClassName() const override;
void OnPaint(gfx::Canvas* canvas) override;
@@ -114,6 +115,8 @@
// remove when MD is default.
SkColor parent_background_color_;
+ bool should_show_background_;
+
DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView);
};
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index b1e3cda..dc609309 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -40,7 +40,6 @@
#include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
-#include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
#include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_layout.h"
#include "chrome/browser/ui/views/location_bar/location_icon_view.h"
@@ -126,20 +125,19 @@
: LocationBar(profile),
ChromeOmniboxEditController(command_updater),
browser_(browser),
- omnibox_view_(NULL),
+ omnibox_view_(nullptr),
delegate_(delegate),
- location_icon_view_(NULL),
- ev_bubble_view_(NULL),
- ime_inline_autocomplete_view_(NULL),
- selected_keyword_view_(NULL),
- suggested_text_view_(NULL),
- keyword_hint_view_(NULL),
- zoom_view_(NULL),
- open_pdf_in_reader_view_(NULL),
- manage_passwords_icon_view_(NULL),
+ location_icon_view_(nullptr),
+ ime_inline_autocomplete_view_(nullptr),
+ selected_keyword_view_(nullptr),
+ suggested_text_view_(nullptr),
+ keyword_hint_view_(nullptr),
+ zoom_view_(nullptr),
+ open_pdf_in_reader_view_(nullptr),
+ manage_passwords_icon_view_(nullptr),
save_credit_card_icon_view_(nullptr),
- translate_icon_view_(NULL),
- star_view_(NULL),
+ translate_icon_view_(nullptr),
+ star_view_(nullptr),
size_animation_(this),
is_popup_mode_(is_popup_mode),
show_focus_rect_(false),
@@ -184,10 +182,6 @@
}
}
- location_icon_view_ = new LocationIconView(this);
- location_icon_view_->set_drag_controller(this);
- AddChildView(location_icon_view_);
-
// Determine the main font.
gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList(
ResourceBundle::BaseFont);
@@ -214,12 +208,12 @@
gfx::FontList bubble_font_list =
font_list.DeriveWithHeightUpperBound(bubble_height);
- const SkColor background_color = GetColor(LocationBarView::BACKGROUND);
- const SkColor ev_text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER);
- ev_bubble_view_ =
- new EVBubbleView(bubble_font_list, ev_text_color, background_color, this);
- ev_bubble_view_->set_drag_controller(this);
- AddChildView(ev_bubble_view_);
+ const SkColor background_color = GetColor(BACKGROUND);
+ const SkColor text_color = GetColor(TEXT);
+ location_icon_view_ = new LocationIconView(bubble_font_list, text_color,
+ background_color, this);
+ location_icon_view_->set_drag_controller(this);
+ AddChildView(location_icon_view_);
// Initialize the Omnibox view.
omnibox_view_ = new OmniboxViewViews(
@@ -261,7 +255,6 @@
GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color);
AddChildView(keyword_hint_view_);
- const SkColor text_color = GetColor(TEXT);
ScopedVector<ContentSettingImageModel> models =
ContentSettingImageModel::GenerateContentSettingImageModels();
for (ContentSettingImageModel* model : models.get()) {
@@ -298,13 +291,13 @@
// Initialize the location entry. We do this to avoid a black flash which is
// visible when the location entry has just been initialized.
- Update(NULL);
+ Update(nullptr);
size_animation_.Reset(1);
}
bool LocationBarView::IsInitialized() const {
- return omnibox_view_ != NULL;
+ return omnibox_view_ != nullptr;
}
SkColor LocationBarView::GetColor(
@@ -411,7 +404,7 @@
if ((*i)->image_view()->extension_action() == page_action)
return *i;
}
- return NULL;
+ return nullptr;
}
void LocationBarView::SetStarToggled(bool on) {
@@ -541,8 +534,9 @@
// The selected keyword view can collapse completely.
} else if (ShouldShowEVBubble()) {
leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) +
- ev_bubble_view_->GetMinimumSizeForLabelText(
- GetToolbarModel()->GetEVCertName()).width();
+ location_icon_view_->GetMinimumSizeForLabelText(
+ GetToolbarModel()->GetEVCertName())
+ .width();
} else {
leading_width += padding + location_icon_view_->GetMinimumSize().width();
}
@@ -574,7 +568,6 @@
selected_keyword_view_->SetVisible(false);
location_icon_view_->SetVisible(false);
- ev_bubble_view_->SetVisible(false);
keyword_hint_view_->SetVisible(false);
const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
@@ -605,6 +598,10 @@
GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING);
const int location_height = GetInternalHeight(false);
const int vertical_padding = VerticalPadding();
+
+ location_icon_view_->SetLabel(base::string16());
+ location_icon_view_->SetBackground(false);
+ location_icon_view_->SetLabelForegroundColor(GetColor(TEXT));
if (ShouldShowKeywordBubble()) {
leading_decorations.AddDecoration(bubble_vertical_padding, bubble_height,
true, 0, bubble_horizontal_padding,
@@ -626,12 +623,15 @@
}
}
} else if (ShouldShowEVBubble()) {
- ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName());
+ location_icon_view_->SetLabel(GetToolbarModel()->GetEVCertName());
+ location_icon_view_->SetBackground(true);
+ location_icon_view_->SetLabelForegroundColor(
+ GetColor(EV_BUBBLE_TEXT_AND_BORDER));
// The largest fraction of the omnibox that can be taken by the EV bubble.
const double kMaxBubbleFraction = 0.5;
leading_decorations.AddDecoration(
bubble_vertical_padding, bubble_height, false, kMaxBubbleFraction,
- bubble_horizontal_padding, item_padding, ev_bubble_view_);
+ bubble_horizontal_padding, item_padding, location_icon_view_);
} else {
leading_decorations.AddDecoration(vertical_padding, location_height,
location_icon_view_);
@@ -706,11 +706,11 @@
leading_decorations.LayoutPass3(&location_bounds, &available_width);
trailing_decorations.LayoutPass3(&location_bounds, &available_width);
- // Layout out the suggested text view right aligned to the location
- // entry. Only show the suggested text if we can fit the text from one
- // character before the end of the selection to the end of the text and the
- // suggested text. If we can't it means either the suggested text is too big,
- // or the user has scrolled.
+ // Lay out the suggested text view right-aligned to the location entry. Only
+ // show the suggested text if we can fit the text from one character before
+ // the end of the selection to the end of the text and the suggested text. If
+ // we can't it means either the suggested text is too big, or the user has
+ // scrolled.
// TODO(sky): We could potentially adjust this to take into account suggested
// text to force using minimum size if necessary, but currently the chance of
@@ -803,7 +803,7 @@
RefreshSaveCreditCardIconView();
RefreshManagePasswordsIconView();
content::WebContents* web_contents_for_sub_views =
- GetToolbarModel()->input_in_progress() ? NULL : GetWebContents();
+ GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents();
open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
if (star_view_)
@@ -878,8 +878,8 @@
for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
i != content_setting_views_.end(); ++i) {
const bool was_visible = (*i)->visible();
- (*i)->Update(GetToolbarModel()->input_in_progress() ?
- NULL : GetWebContents());
+ (*i)->Update(GetToolbarModel()->input_in_progress() ? nullptr
+ : GetWebContents());
if (was_visible != (*i)->visible())
visibility_changed = true;
}
@@ -908,7 +908,7 @@
extensions_tab_helper->location_bar_controller();
new_page_actions = controller->GetCurrentActions();
}
- web_contents_null_at_last_refresh_ = web_contents == NULL;
+ web_contents_null_at_last_refresh_ = web_contents == nullptr;
// On startup we sometimes haven't loaded any extensions. This makes sure
// we catch up when the extensions (and any page actions) load.
@@ -943,7 +943,7 @@
i != page_action_views_.end(); ++i) {
bool old_visibility = (*i)->visible();
(*i)->UpdateVisibility(
- GetToolbarModel()->input_in_progress() ? NULL : web_contents);
+ GetToolbarModel()->input_in_progress() ? nullptr : web_contents);
changed |= old_visibility != (*i)->visible();
}
return changed;
@@ -1161,7 +1161,7 @@
void LocationBarView::UpdateOpenPDFInReaderPrompt() {
open_pdf_in_reader_view_->Update(
- GetToolbarModel()->input_in_progress() ? NULL : GetWebContents());
+ GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents());
Layout();
SchedulePaint();
}
@@ -1199,7 +1199,7 @@
return page_action_views_[index]->image_view()->extension_action();
NOTREACHED();
- return NULL;
+ return nullptr;
}
ExtensionAction* LocationBarView::GetVisiblePageAction(size_t index) {
@@ -1214,7 +1214,7 @@
}
NOTREACHED();
- return NULL;
+ return nullptr;
}
void LocationBarView::TestPageActionPressed(size_t index) {
@@ -1321,16 +1321,13 @@
favicon::ContentFaviconDriver::FromWebContents(web_contents);
gfx::ImageSkia favicon = favicon_driver->GetFavicon().AsImageSkia();
button_drag_utils::SetURLAndDragImage(web_contents->GetURL(),
- web_contents->GetTitle(),
- favicon,
- NULL,
- data,
- sender->GetWidget());
+ web_contents->GetTitle(), favicon,
+ nullptr, data, sender->GetWidget());
}
int LocationBarView::GetDragOperationsForView(views::View* sender,
const gfx::Point& p) {
- DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_));
+ DCHECK_EQ(location_icon_view_, sender);
WebContents* web_contents = delegate_->GetWebContents();
return (web_contents && web_contents->GetURL().is_valid() &&
(!GetOmniboxView()->IsEditingOrEmpty())) ?
@@ -1360,7 +1357,6 @@
void LocationBarView::OnChanged() {
RefreshLocationIcon();
location_icon_view_->ShowTooltip(!GetOmniboxView()->IsEditingOrEmpty());
-
Layout();
SchedulePaint();
}
@@ -1385,7 +1381,7 @@
void LocationBarView::OnTemplateURLServiceChanged() {
template_url_service_->RemoveObserver(this);
- template_url_service_ = NULL;
+ template_url_service_ = nullptr;
// If the browser is no longer active, let's not show the info bubble, as this
// would make the browser the active window again.
if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h
index f9a94427..68cf65b 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.h
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.h
@@ -31,7 +31,6 @@
class CommandUpdater;
class ContentSettingBubbleModelDelegate;
class ContentSettingImageView;
-class EVBubbleView;
class ExtensionAction;
class GURL;
class InstantController;
@@ -403,12 +402,10 @@
// Object used to paint the border. Not used for material design.
scoped_ptr<views::Painter> border_painter_;
- // An icon to the left of the edit field.
+ // An icon to the left of the edit field: the HTTPS lock, blank page icon,
+ // search icon, EV HTTPS bubble, etc.
LocationIconView* location_icon_view_;
- // A bubble displayed for EV HTTPS sites.
- EVBubbleView* ev_bubble_view_;
-
// A view to show inline autocompletion when an IME is active. In this case,
// we shouldn't change the text or selection inside the OmniboxView itself,
// since this will conflict with the IME's control over the text. So instead
diff --git a/chrome/browser/ui/views/location_bar/location_icon_view.cc b/chrome/browser/ui/views/location_bar/location_icon_view.cc
index b40af8d..1c6db94c 100644
--- a/chrome/browser/ui/views/location_bar/location_icon_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_icon_view.cc
@@ -5,15 +5,61 @@
#include "chrome/browser/ui/views/location_bar/location_icon_view.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/ssl/chrome_security_state_model_client.h"
+#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h"
#include "chrome/grit/generated_resources.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/web_contents.h"
+#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/material_design/material_design_controller.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/painter.h"
-LocationIconView::LocationIconView(LocationBarView* location_bar)
- : suppress_mouse_released_action_(false),
- page_info_helper_(this, location_bar) {
- SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON));
+using content::NavigationController;
+using content::NavigationEntry;
+using content::WebContents;
+
+namespace {
+
+void ProcessEventInternal(LocationBarView* view) {
+ WebContents* contents = view->GetWebContents();
+ if (!contents)
+ return;
+
+ // Important to use GetVisibleEntry to match what's showing in the omnibox.
+ NavigationEntry* entry = contents->GetController().GetVisibleEntry();
+ // The visible entry can be nullptr in the case of window.open("").
+ if (!entry)
+ return;
+
+ ChromeSecurityStateModelClient* model_client =
+ ChromeSecurityStateModelClient::FromWebContents(contents);
+ DCHECK(model_client);
+
+ view->delegate()->ShowWebsiteSettings(contents, entry->GetURL(),
+ model_client->GetSecurityInfo());
+}
+
+} // namespace
+
+LocationIconView::LocationIconView(const gfx::FontList& font_list,
+ SkColor text_color,
+ SkColor parent_background_color,
+ LocationBarView* location_bar)
+ : IconLabelBubbleView(IDR_OMNIBOX_HTTPS_INVALID,
+ font_list,
+ text_color,
+ parent_background_color,
+ true),
+ suppress_mouse_released_action_(false),
+ location_bar_(location_bar) {
+ set_id(VIEW_ID_LOCATION_ICON);
+ SetFocusable(true);
+ SetBackground(false);
}
LocationIconView::~LocationIconView() {
@@ -26,8 +72,7 @@
ui::Clipboard::GetForCurrentThread()->ReadText(
ui::CLIPBOARD_TYPE_SELECTION, &text);
text = OmniboxView::SanitizeTextForPaste(text);
- OmniboxEditModel* model =
- page_info_helper_.location_bar()->GetOmniboxView()->model();
+ OmniboxEditModel* model = location_bar_->GetOmniboxView()->model();
if (model->CanPasteAndGo(text))
model->PasteAndGo(text);
}
@@ -52,10 +97,21 @@
}
bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) {
- page_info_helper_.location_bar()->GetOmniboxView()->CloseOmniboxPopup();
+ location_bar_->GetOmniboxView()->CloseOmniboxPopup();
return false;
}
+bool LocationIconView::OnKeyPressed(const ui::KeyEvent& event) {
+ return false;
+}
+
+bool LocationIconView::OnKeyReleased(const ui::KeyEvent& event) {
+ if (event.key_code() != ui::VKEY_RETURN && event.key_code() != ui::VKEY_SPACE)
+ return false;
+ ProcessEvent(event);
+ return true;
+}
+
void LocationIconView::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() != ui::ET_GESTURE_TAP)
return;
@@ -66,13 +122,59 @@
void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) {
// Do not show page info if the user has been editing the location bar or the
// location bar is at the NTP.
- if (page_info_helper_.location_bar()->GetOmniboxView()->IsEditingOrEmpty())
+ if (location_bar_->GetOmniboxView()->IsEditingOrEmpty())
return;
-
- page_info_helper_.ProcessEvent(event);
+ ProcessEvent(event);
}
void LocationIconView::ShowTooltip(bool show) {
SetTooltipText(show ?
l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON) : base::string16());
}
+
+void LocationIconView::ProcessEvent(const ui::LocatedEvent& event) {
+ if (!HitTestPoint(event.location()))
+ return;
+ ProcessEventInternal(location_bar_);
+}
+
+void LocationIconView::ProcessEvent(const ui::KeyEvent& event) {
+ ProcessEventInternal(location_bar_);
+}
+
+gfx::Size LocationIconView::GetMinimumSize() const {
+ return GetMinimumSizeForPreferredSize(GetPreferredSize());
+}
+
+gfx::Size LocationIconView::GetMinimumSizeForLabelText(
+ const base::string16& text) const {
+ views::Label label(text, font_list());
+ return GetMinimumSizeForPreferredSize(
+ GetSizeForLabelWidth(label.GetPreferredSize().width()));
+}
+
+SkColor LocationIconView::GetTextColor() const {
+ return location_bar_->GetColor(LocationBarView::TEXT);
+}
+
+SkColor LocationIconView::GetBorderColor() const {
+ return location_bar_->GetColor(LocationBarView::TEXT);
+}
+
+gfx::Size LocationIconView::GetMinimumSizeForPreferredSize(
+ gfx::Size size) const {
+ const int kMinCharacters = 10;
+ size.SetToMin(
+ GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters)));
+ return size;
+}
+
+void LocationIconView::SetBackground(bool should_show_ev) {
+ static const int kEvBackgroundImages[] = IMAGE_GRID(IDR_OMNIBOX_EV_BUBBLE);
+ if (!ui::MaterialDesignController::IsModeMaterial()) {
+ if (should_show_ev)
+ SetBackgroundImageGrid(kEvBackgroundImages);
+ else
+ UnsetBackgroundImageGrid();
+ }
+}
diff --git a/chrome/browser/ui/views/location_bar/location_icon_view.h b/chrome/browser/ui/views/location_bar/location_icon_view.h
index 0936d11f..6e25c96 100644
--- a/chrome/browser/ui/views/location_bar/location_icon_view.h
+++ b/chrome/browser/ui/views/location_bar/location_icon_view.h
@@ -5,33 +5,56 @@
#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_ICON_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_ICON_VIEW_H_
-#include "chrome/browser/ui/views/location_bar/page_info_helper.h"
-#include "ui/views/controls/image_view.h"
+#include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
class LocationBarView;
-// LocationIconView is used to display an icon to the left of the edit field.
-// This shows the user's current action while editing, the page security
-// status on https pages, or a globe for other URLs.
-class LocationIconView : public views::ImageView {
+namespace ui {
+class KeyEvent;
+class LocatedEvent;
+}
+
+// Use a LocationIconView to display an icon on the leading side of the edit
+// field. It shows the user's current action (while the user is editing), or the
+// page security status (after navigation has completed).
+class LocationIconView : public IconLabelBubbleView {
public:
- explicit LocationIconView(LocationBarView* location_bar);
+ LocationIconView(const gfx::FontList& font_list,
+ SkColor text_color,
+ SkColor parent_background_color,
+ LocationBarView* location_bar);
~LocationIconView() override;
- // views::ImageView:
+ // IconLabelBubbleView:
+ gfx::Size GetMinimumSize() const override;
bool OnMousePressed(const ui::MouseEvent& event) override;
- void OnMouseReleased(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override;
-
- // ui::EventHandler:
+ void OnMouseReleased(const ui::MouseEvent& event) override;
+ bool OnKeyPressed(const ui::KeyEvent& event) override;
+ bool OnKeyReleased(const ui::KeyEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
+ SkColor GetTextColor() const override;
+ SkColor GetBorderColor() const override;
// Whether we should show the tooltip for this icon or not.
void ShowTooltip(bool show);
- PageInfoHelper* page_info_helper() { return &page_info_helper_; }
+ // Returns what the minimum size would be if the label text were |text|.
+ gfx::Size GetMinimumSizeForLabelText(const base::string16& text) const;
+
+ const gfx::FontList& GetFontList() const { return font_list(); }
+
+ // Set the background image. Pass false for |should_show_ev| for all non-EV
+ // HTTPS contexts.
+ void SetBackground(bool should_show_ev);
private:
+ void ProcessEvent(const ui::LocatedEvent& event);
+ void ProcessEvent(const ui::KeyEvent& event);
+
+ // Returns what the minimum size would be if the preferred size were |size|.
+ gfx::Size GetMinimumSizeForPreferredSize(gfx::Size size) const;
+
// Handles both click and gesture events by delegating to the page info
// helper in the appropriate circumstances.
void OnClickOrTap(const ui::LocatedEvent& event);
@@ -41,7 +64,7 @@
// clicking the icon repeatedly will appear to toggle the bubble on and off.
bool suppress_mouse_released_action_;
- PageInfoHelper page_info_helper_;
+ LocationBarView* location_bar_;
DISALLOW_COPY_AND_ASSIGN(LocationIconView);
};
diff --git a/chrome/browser/ui/views/location_bar/page_info_helper.cc b/chrome/browser/ui/views/location_bar/page_info_helper.cc
deleted file mode 100644
index e61d82b0..0000000
--- a/chrome/browser/ui/views/location_bar/page_info_helper.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/views/location_bar/page_info_helper.h"
-
-#include "chrome/browser/search/search.h"
-#include "chrome/browser/ssl/chrome_security_state_model_client.h"
-#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
-#include "components/omnibox/browser/omnibox_view.h"
-#include "content/public/browser/navigation_controller.h"
-#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/web_contents.h"
-#include "ui/views/view.h"
-
-using content::NavigationController;
-using content::NavigationEntry;
-using content::WebContents;
-
-PageInfoHelper::PageInfoHelper(const views::View* owner,
- LocationBarView* location_bar)
- : owner_(owner),
- location_bar_(location_bar) {
-}
-
-void PageInfoHelper::ProcessEvent(const ui::LocatedEvent& event) {
- if (!owner_->HitTestPoint(event.location()))
- return;
-
- WebContents* tab = location_bar_->GetWebContents();
- if (!tab)
- return;
-
- // Important to use GetVisibleEntry to match what's showing in the omnibox.
- NavigationEntry* nav_entry = tab->GetController().GetVisibleEntry();
- // The visible entry can be NULL in the case of window.open("").
- if (!nav_entry)
- return;
-
- ChromeSecurityStateModelClient* security_model_client =
- ChromeSecurityStateModelClient::FromWebContents(tab);
- DCHECK(security_model_client);
-
- location_bar_->delegate()->ShowWebsiteSettings(
- tab, nav_entry->GetURL(), security_model_client->GetSecurityInfo());
-}
diff --git a/chrome/browser/ui/views/location_bar/page_info_helper.h b/chrome/browser/ui/views/location_bar/page_info_helper.h
deleted file mode 100644
index b411c2b..0000000
--- a/chrome/browser/ui/views/location_bar/page_info_helper.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_INFO_HELPER_H_
-#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_INFO_HELPER_H_
-
-#include "base/basictypes.h"
-
-class LocationBarView;
-
-namespace ui {
-class LocatedEvent;
-}
-
-namespace views {
-class View;
-}
-
-// This helper class is kept as a member by classes that need to show the Page
-// Info bubble on click, to encapsulate that logic in one place.
-class PageInfoHelper {
- public:
- PageInfoHelper(const views::View* owner, LocationBarView* location_bar);
-
- void ProcessEvent(const ui::LocatedEvent& event);
-
- LocationBarView* location_bar() const { return location_bar_; }
-
- private:
- const views::View* owner_;
- LocationBarView* location_bar_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(PageInfoHelper);
-};
-
-#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_INFO_HELPER_H_
-
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 39ebf0a..b543bdd 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -2314,8 +2314,6 @@
'browser/ui/views/location_bar/bubble_icon_view.h',
'browser/ui/views/location_bar/content_setting_image_view.cc',
'browser/ui/views/location_bar/content_setting_image_view.h',
- 'browser/ui/views/location_bar/ev_bubble_view.cc',
- 'browser/ui/views/location_bar/ev_bubble_view.h',
'browser/ui/views/location_bar/icon_label_bubble_view.cc',
'browser/ui/views/location_bar/icon_label_bubble_view.h',
'browser/ui/views/location_bar/keyword_hint_view.cc',
@@ -2336,8 +2334,6 @@
'browser/ui/views/location_bar/page_action_image_view.h',
'browser/ui/views/location_bar/page_action_with_badge_view.cc',
'browser/ui/views/location_bar/page_action_with_badge_view.h',
- 'browser/ui/views/location_bar/page_info_helper.cc',
- 'browser/ui/views/location_bar/page_info_helper.h',
'browser/ui/views/location_bar/selected_keyword_view.cc',
'browser/ui/views/location_bar/selected_keyword_view.h',
'browser/ui/views/location_bar/star_view.cc',
diff --git a/ui/base/nine_image_painter_factory.h b/ui/base/nine_image_painter_factory.h
index d09f95c8..5978c0f1 100644
--- a/ui/base/nine_image_painter_factory.h
+++ b/ui/base/nine_image_painter_factory.h
@@ -13,8 +13,8 @@
x ## _LEFT, x ## _CENTER, x ## _RIGHT, \
x ## _BOTTOM_LEFT, x ## _BOTTOM, x ## _BOTTOM_RIGHT, }
-// Defines a empty image for used in macro for creating image grid for a ring of
-// eight images.
+// Defines an empty image for use in macros for creating an image grid for a
+// ring of eight images.
#define EMPTY_IMAGE 0
// A macro to define arrays of IDR constants used with CreateImageGridPainter