Commit 02246bba authored by Peter Kasting's avatar Peter Kasting Committed by Chromium LUCI CQ

Add metadata for classes in c/b/ui/views/location_bar.

Bug: 1159562
Change-Id: Ie757c300fe2f4c6ab30173d777b1abdacd979feb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625960
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843570}
parent e324bd69
......@@ -26,6 +26,7 @@
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/widget/widget.h"
namespace {
......@@ -136,14 +137,17 @@ void ContentSettingImageView::Update() {
content_setting_image_model_->SetAnimationHasRun(web_contents);
}
void ContentSettingImageView::SetIconColor(SkColor color) {
void ContentSettingImageView::SetIconColor(base::Optional<SkColor> color) {
if (icon_color_ == color)
return;
icon_color_ = color;
if (content_setting_image_model_->is_visible())
UpdateImage();
OnPropertyChanged(&icon_color_, views::kPropertyEffectsNone);
}
const char* ContentSettingImageView::GetClassName() const {
return "ContentSettingsImageView";
base::Optional<SkColor> ContentSettingImageView::GetIconColor() const {
return icon_color_;
}
bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) {
......@@ -247,3 +251,7 @@ void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
promo_controller->ShowCriticalPromo(bubble_params);
}
}
BEGIN_METADATA(ContentSettingImageView, IconLabelBubbleView)
ADD_PROPERTY_METADATA(base::Optional<SkColor>, IconColor)
END_METADATA
......@@ -7,12 +7,12 @@
#include <memory>
#include "base/macros.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model.h"
#include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/painter.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
......@@ -38,6 +38,8 @@ class BubbleDialogDelegateView;
class ContentSettingImageView : public IconLabelBubbleView,
public views::WidgetObserver {
public:
METADATA_HEADER(ContentSettingImageView);
class Delegate {
public:
// Delegate should return true if the content setting icon should be hidden.
......@@ -60,20 +62,22 @@ class ContentSettingImageView : public IconLabelBubbleView,
IconLabelBubbleView::Delegate* parent_delegate,
Delegate* delegate,
const gfx::FontList& font_list);
ContentSettingImageView(const ContentSettingImageView&) = delete;
ContentSettingImageView& operator=(const ContentSettingImageView&) = delete;
~ContentSettingImageView() override;
// Updates the decoration from the shown WebContents.
void Update();
// Set the color of the button icon. Based on the text color by default.
void SetIconColor(SkColor color);
void SetIconColor(base::Optional<SkColor> color);
base::Optional<SkColor> GetIconColor() const;
void disable_animation() { can_animate_ = false; }
bool ShowBubbleImpl();
// IconLabelBubbleView:
const char* GetClassName() const override;
bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnKeyPressed(const ui::KeyEvent& event) override;
void OnThemeChanged() override;
......@@ -100,8 +104,6 @@ class ContentSettingImageView : public IconLabelBubbleView,
base::ScopedObservation<views::Widget, views::WidgetObserver> observation_{
this};
bool can_animate_ = true;
DISALLOW_COPY_AND_ASSIGN(ContentSettingImageView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_
......@@ -18,6 +18,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/metadata/metadata_impl_macros.h"
CookieControlsIconView::CookieControlsIconView(
IconLabelBubbleView::Delegate* icon_label_bubble_delegate,
......@@ -77,7 +78,7 @@ bool CookieControlsIconView::ShouldBeVisible() const {
if (delegate()->ShouldHidePageActionIcons())
return false;
if (HasAssociatedBubble())
if (GetAssociatedBubble())
return true;
if (!delegate()->GetWebContentsForPageActionIconView())
......@@ -94,15 +95,11 @@ bool CookieControlsIconView::ShouldBeVisible() const {
}
}
bool CookieControlsIconView::HasAssociatedBubble() const {
if (!GetBubble())
return false;
bool CookieControlsIconView::GetAssociatedBubble() const {
// There may be multiple icons but only a single bubble can be displayed
// at a time. Check if the bubble belongs to this icon.
if (!GetBubble()->GetAnchorView())
return false;
return GetBubble()->GetAnchorView()->GetWidget() == GetWidget();
return GetBubble() && GetBubble()->GetAnchorView() &&
GetBubble()->GetAnchorView()->GetWidget() == GetWidget();
}
void CookieControlsIconView::OnExecuting(
......@@ -122,11 +119,11 @@ const gfx::VectorIcon& CookieControlsIconView::GetVectorIcon() const {
return kEyeCrossedIcon;
}
const char* CookieControlsIconView::GetClassName() const {
return "CookieControlsIconView";
}
base::string16 CookieControlsIconView::GetTextForTooltipAndAccessibleName()
const {
return l10n_util::GetStringUTF16(IDS_COOKIE_CONTROLS_TOOLTIP);
}
BEGIN_METADATA(CookieControlsIconView, PageActionIconView)
ADD_READONLY_PROPERTY_METADATA(bool, AssociatedBubble)
END_METADATA
......@@ -6,21 +6,24 @@
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_COOKIE_CONTROLS_ICON_VIEW_H_
#include <memory>
#include "base/macros.h"
#include "base/scoped_observation.h"
#include "chrome/browser/ui/views/location_bar/cookie_controls_bubble_view.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "components/content_settings/browser/ui/cookie_controls_controller.h"
#include "components/content_settings/browser/ui/cookie_controls_view.h"
#include "components/content_settings/core/common/cookie_controls_status.h"
#include "ui/views/metadata/metadata_header_macros.h"
// View for the cookie control icon in the Omnibox.
class CookieControlsIconView : public PageActionIconView,
public content_settings::CookieControlsView {
public:
METADATA_HEADER(CookieControlsIconView);
CookieControlsIconView(
IconLabelBubbleView::Delegate* icon_label_bubble_delegate,
PageActionIconView::Delegate* page_action_icon_delegate);
CookieControlsIconView(const CookieControlsIconView&) = delete;
CookieControlsIconView& operator=(const CookieControlsIconView&) = delete;
~CookieControlsIconView() override;
// CookieControlsUI:
......@@ -38,10 +41,9 @@ class CookieControlsIconView : public PageActionIconView,
protected:
void OnExecuting(PageActionIconView::ExecuteSource source) override;
const gfx::VectorIcon& GetVectorIcon() const override;
const char* GetClassName() const override;
private:
bool HasAssociatedBubble() const;
bool GetAssociatedBubble() const;
bool ShouldBeVisible() const;
CookieControlsStatus status_ = CookieControlsStatus::kUninitialized;
......@@ -51,8 +53,6 @@ class CookieControlsIconView : public PageActionIconView,
base::ScopedObservation<content_settings::CookieControlsController,
content_settings::CookieControlsView>
observation_{this};
DISALLOW_COPY_AND_ASSIGN(CookieControlsIconView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_COOKIE_CONTROLS_ICON_VIEW_H_
......@@ -42,6 +42,7 @@
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/style/typography.h"
#include "ui/views/style/typography_provider.h"
#include "ui/views/view_class_properties.h"
......@@ -190,9 +191,6 @@ class CustomTabBarTitleOriginView : public views::View {
views::Label* location_label_ = nullptr;
};
// static
const char CustomTabBarView::kViewClassName[] = "CustomTabBarView";
CustomTabBarView::CustomTabBarView(BrowserView* browser_view,
LocationBarView::Delegate* delegate)
: delegate_(delegate), browser_(browser_view->browser()) {
......@@ -215,7 +213,7 @@ CustomTabBarView::CustomTabBarView(BrowserView* browser_view,
AddChildView(std::make_unique<LocationIconView>(font_list, this, this));
auto title_origin_view = std::make_unique<CustomTabBarTitleOriginView>(
background_color_, ShouldShowTitle());
background_color_, GetShowTitle());
title_origin_view->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum,
......@@ -256,10 +254,6 @@ gfx::Rect CustomTabBarView::GetAnchorBoundsInScreen() const {
title_origin_view_->GetAnchorBoundsInScreen());
}
const char* CustomTabBarView::GetClassName() const {
return kViewClassName;
}
void CustomTabBarView::SetVisible(bool visible) {
if (!GetVisible() && visible) {
UpdateContents();
......@@ -536,6 +530,12 @@ base::Optional<SkColor> CustomTabBarView::GetThemeColor() const {
: base::nullopt;
}
bool CustomTabBarView::ShouldShowTitle() const {
bool CustomTabBarView::GetShowTitle() const {
return app_controller() != nullptr;
}
BEGIN_METADATA(CustomTabBarView, views::AccessiblePaneView)
ADD_READONLY_PROPERTY_METADATA(SkColor, DefaultFrameColor)
ADD_READONLY_PROPERTY_METADATA(base::Optional<SkColor>, ThemeColor)
ADD_READONLY_PROPERTY_METADATA(bool, ShowTitle)
END_METADATA
......@@ -5,7 +5,6 @@
#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CUSTOM_TAB_BAR_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CUSTOM_TAB_BAR_VIEW_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
......@@ -14,6 +13,7 @@
#include "ui/base/models/simple_menu_model.h"
#include "ui/views/accessible_pane_view.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/metadata/metadata_header_macros.h"
namespace gfx {
class Rect;
......@@ -41,10 +41,11 @@ class CustomTabBarView : public views::AccessiblePaneView,
public IconLabelBubbleView::Delegate,
public LocationIconView::Delegate {
public:
static const char kViewClassName[];
METADATA_HEADER(CustomTabBarView);
CustomTabBarView(BrowserView* browser_view,
LocationBarView::Delegate* delegate);
CustomTabBarView(const CustomTabBarView&) = delete;
CustomTabBarView& operator=(const CustomTabBarView&) = delete;
~CustomTabBarView() override;
LocationIconView* location_icon_view() { return location_icon_view_; }
......@@ -52,7 +53,6 @@ class CustomTabBarView : public views::AccessiblePaneView,
// views::AccessiblePaneView:
gfx::Rect GetAnchorBoundsInScreen() const override;
const char* GetClassName() const override;
void SetVisible(bool visible) override;
gfx::Size CalculatePreferredSize() const override;
void OnPaintBackground(gfx::Canvas* canvas) override;
......@@ -91,9 +91,7 @@ class CustomTabBarView : public views::AccessiblePaneView,
bool IsShowingOriginForTesting() const;
private:
// Calculate the view's background and frame color from the current theme
// provider.
SkColor GetBackgroundColor() const;
// Calculate the view's frame color from the current theme provider.
SkColor GetDefaultFrameColor() const;
// Takes the web contents for the custom tab bar back to the app scope.
......@@ -123,7 +121,7 @@ class CustomTabBarView : public views::AccessiblePaneView,
// Populates child elements with page details from the current WebContents.
void UpdateContents();
bool ShouldShowTitle() const;
bool GetShowTitle() const;
SkColor title_bar_color_;
SkColor background_color_;
......@@ -146,8 +144,6 @@ class CustomTabBarView : public views::AccessiblePaneView,
views::FlexLayout* layout_manager_;
base::WeakPtrFactory<CustomTabBarView> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(CustomTabBarView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CUSTOM_TAB_BAR_VIEW_H_
......@@ -11,6 +11,7 @@
#include "components/omnibox/browser/vector_icons.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/metadata/metadata_impl_macros.h"
FindBarIcon::FindBarIcon(
Browser* browser,
......@@ -45,10 +46,6 @@ base::string16 FindBarIcon::GetTextForTooltipAndAccessibleName() const {
return l10n_util::GetStringUTF16(IDS_TOOLTIP_FIND);
}
const char* FindBarIcon::GetClassName() const {
return "FindBarIcon";
}
void FindBarIcon::OnExecuting(ExecuteSource execute_source) {}
views::BubbleDialogDelegate* FindBarIcon::GetBubble() const {
......@@ -69,3 +66,6 @@ void FindBarIcon::UpdateImpl() {
SetVisible(browser_->GetFindBarController()->find_bar()->IsFindBarVisible());
SetActive(GetVisible(), was_visible != GetVisible());
}
BEGIN_METADATA(FindBarIcon, PageActionIconView)
END_METADATA
......@@ -5,17 +5,20 @@
#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_FIND_BAR_ICON_H_
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_FIND_BAR_ICON_H_
#include "base/macros.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "ui/views/metadata/metadata_header_macros.h"
class Browser;
// The find icon to show when the find bar is visible.
class FindBarIcon : public PageActionIconView {
public:
METADATA_HEADER(FindBarIcon);
FindBarIcon(Browser* browser,
IconLabelBubbleView::Delegate* icon_label_bubble_delegate,
PageActionIconView::Delegate* page_action_icon_delegate);
FindBarIcon(const FindBarIcon&) = delete;
FindBarIcon& operator=(const FindBarIcon&) = delete;
~FindBarIcon() override;
void SetActive(bool activate, bool should_animate);
......@@ -27,11 +30,8 @@ class FindBarIcon : public PageActionIconView {
views::BubbleDialogDelegate* GetBubble() const override;
const gfx::VectorIcon& GetVectorIcon() const override;
base::string16 GetTextForTooltipAndAccessibleName() const override;
const char* GetClassName() const override;
private:
DISALLOW_COPY_AND_ASSIGN(FindBarIcon);
Browser* browser_ = nullptr;
};
......
......@@ -15,6 +15,7 @@
#include "chrome/grit/generated_resources.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/metadata/metadata_impl_macros.h"
namespace content {
class WebContents;
......@@ -35,7 +36,7 @@ IntentPickerView::~IntentPickerView() = default;
void IntentPickerView::UpdateImpl() {
bool was_visible = GetVisible();
SetVisible(ShouldShowIcon());
SetVisible(GetShowIcon());
if (was_visible && !GetVisible())
IntentPickerBubbleView::CloseCurrentBubble();
......@@ -43,7 +44,7 @@ void IntentPickerView::UpdateImpl() {
void IntentPickerView::OnExecuting(
PageActionIconView::ExecuteSource execute_source) {
DCHECK(ShouldShowIcon());
DCHECK(GetShowIcon());
content::WebContents* web_contents = GetWebContents();
const GURL& url = chrome::GetURLToBookmark(web_contents);
apps::ShowIntentPickerBubble(web_contents, url);
......@@ -53,14 +54,8 @@ views::BubbleDialogDelegate* IntentPickerView::GetBubble() const {
return IntentPickerBubbleView::intent_picker_bubble();
}
bool IntentPickerView::IsIncognitoMode() const {
DCHECK(browser_);
return browser_->profile()->IsOffTheRecord();
}
bool IntentPickerView::ShouldShowIcon() const {
if (IsIncognitoMode())
bool IntentPickerView::GetShowIcon() const {
if (browser_->profile()->IsOffTheRecord())
return false;
content::WebContents* web_contents = GetWebContents();
......@@ -69,11 +64,7 @@ bool IntentPickerView::ShouldShowIcon() const {
IntentPickerTabHelper* tab_helper =
IntentPickerTabHelper::FromWebContents(web_contents);
if (!tab_helper)
return false;
return tab_helper->should_show_icon();
return tab_helper && tab_helper->should_show_icon();
}
const gfx::VectorIcon& IntentPickerView::GetVectorIcon() const {
......@@ -84,6 +75,6 @@ base::string16 IntentPickerView::GetTextForTooltipAndAccessibleName() const {
return l10n_util::GetStringUTF16(IDS_TOOLTIP_INTENT_PICKER_ICON);
}
const char* IntentPickerView::GetClassName() const {
return "IntentPickerView";
}
BEGIN_METADATA(IntentPickerView, PageActionIconView)
ADD_READONLY_PROPERTY_METADATA(bool, ShowIcon)
END_METADATA
......@@ -6,15 +6,19 @@
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_INTENT_PICKER_VIEW_H_
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "ui/views/metadata/metadata_header_macros.h"
class Browser;
// The entry point for the intent picker.
class IntentPickerView : public PageActionIconView {
public:
METADATA_HEADER(IntentPickerView);
IntentPickerView(Browser* browser,
IconLabelBubbleView::Delegate* icon_label_bubble_delegate,
PageActionIconView::Delegate* page_action_icon_delegate);
IntentPickerView(const IntentPickerView&) = delete;
IntentPickerView& operator=(const IntentPickerView&) = delete;
~IntentPickerView() override;
// PageActionIconView:
......@@ -26,15 +30,11 @@ class IntentPickerView : public PageActionIconView {
views::BubbleDialogDelegate* GetBubble() const override;
const gfx::VectorIcon& GetVectorIcon() const override;
base::string16 GetTextForTooltipAndAccessibleName() const override;
const char* GetClassName() const override;
private:
bool IsIncognitoMode() const;
bool ShouldShowIcon() const;
bool GetShowIcon() const;
Browser* const browser_;
DISALLOW_COPY_AND_ASSIGN(IntentPickerView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_INTENT_PICKER_VIEW_H_
......@@ -31,6 +31,7 @@
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/view_class_properties.h"
namespace {
......@@ -93,6 +94,10 @@ KeywordHintView::KeywordHintView(PressedCallback callback, Profile* profile)
KeywordHintView::~KeywordHintView() {}
base::string16 KeywordHintView::GetKeyword() const {
return keyword_;
}
void KeywordHintView::SetKeyword(const base::string16& keyword) {
// When the virtual keyboard is visible, we show a modified touch UI
// containing only the chip and no surrounding labels.
......@@ -103,6 +108,9 @@ void KeywordHintView::SetKeyword(const base::string16& keyword) {
return;
keyword_ = keyword;
OnPropertyChanged(&keyword_, views::kPropertyEffectsNone);
// TODO(pkasting): Arguably, much of the code below would be better as
// property change handlers in file-scope subclasses of Label etc.
if (keyword_.empty())
return;
DCHECK(profile_);
......@@ -181,10 +189,6 @@ gfx::Size KeywordHintView::GetMinimumSize() const {
return chip_size;
}
const char* KeywordHintView::GetClassName() const {
return "KeywordHintView";
}
void KeywordHintView::OnThemeChanged() {
views::Button::OnThemeChanged();
const ui::ThemeProvider* theme_provider = GetThemeProvider();
......@@ -217,3 +221,7 @@ void KeywordHintView::OnThemeChanged() {
trailing_label_->SetEnabledColor(text_color);
trailing_label_->SetBackgroundColor(background_color);
}
BEGIN_METADATA(KeywordHintView, views::Button)
ADD_PROPERTY_METADATA(base::string16, Keyword)
END_METADATA
......@@ -8,10 +8,10 @@
#include <string>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/metadata/metadata_header_macros.h"
class Profile;
......@@ -30,16 +30,19 @@ class Label;
// couldn't bring myself to use such a long name.
class KeywordHintView : public views::Button {
public:
METADATA_HEADER(KeywordHintView);
KeywordHintView(PressedCallback callback, Profile* profile);
KeywordHintView(const KeywordHintView&) = delete;
KeywordHintView& operator=(const KeywordHintView&) = delete;
~KeywordHintView() override;
base::string16 GetKeyword() const;
void SetKeyword(const base::string16& keyword);
// views::View:
gfx::Insets GetInsets() const override;
// The minimum size is just big enough to show the tab.
gfx::Size GetMinimumSize() const override;
const char* GetClassName() const override;
void OnThemeChanged() override;
......@@ -53,8 +56,6 @@ class KeywordHintView : public views::Button {
views::Label* trailing_label_ = nullptr;
base::string16 keyword_;
DISALLOW_COPY_AND_ASSIGN(KeywordHintView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_KEYWORD_HINT_VIEW_H_
......@@ -118,7 +118,9 @@
#include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/label.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/style/typography.h"
#include "ui/views/view_utils.h"
#include "ui/views/widget/widget.h"
namespace {
......@@ -135,9 +137,6 @@ using views::View;
// LocationBarView -----------------------------------------------------------
// static
const char LocationBarView::kViewClassName[] = "LocationBarView";
LocationBarView::LocationBarView(Browser* browser,
Profile* profile,
CommandUpdater* command_updater,
......@@ -152,7 +151,7 @@ LocationBarView::LocationBarView(Browser* browser,
if (!is_popup_mode_) {
focus_ring_ = views::FocusRing::Install(this);
focus_ring_->SetHasFocusPredicate([](View* view) -> bool {
DCHECK_EQ(view->GetClassName(), LocationBarView::kViewClassName);
DCHECK(views::IsViewClass<LocationBarView>(view));
auto* v = static_cast<LocationBarView*>(view);
// Show focus ring when the Omnibox is visibly focused and the popup is
......@@ -237,8 +236,8 @@ void LocationBarView::Init() {
AddChildView(std::move(omnibox_additional_text_view));
}
selected_keyword_view_ =
AddChildView(std::make_unique<SelectedKeywordView>(this, font_list));
selected_keyword_view_ = AddChildView(std::make_unique<SelectedKeywordView>(
this, TemplateURLServiceFactory::GetForProfile(profile_), font_list));
keyword_hint_view_ = AddChildView(std::make_unique<KeywordHintView>(
base::BindRepeating(&LocationBarView::KeywordHintViewPressed,
......@@ -371,8 +370,16 @@ gfx::Point LocationBarView::GetOmniboxViewOrigin() const {
}
void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) {
if (text == GetImeInlineAutocompletion())
return;
ime_inline_autocomplete_view_->SetText(text);
ime_inline_autocomplete_view_->SetVisible(!text.empty());
OnPropertyChanged(&ime_inline_autocomplete_view_,
views::kPropertyEffectsLayout);
}
base::string16 LocationBarView::GetImeInlineAutocompletion() const {
return ime_inline_autocomplete_view_->GetText();
}
void LocationBarView::SelectAll() {
......@@ -524,8 +531,8 @@ void LocationBarView::Layout() {
leading_decorations.AddDecoration(vertical_padding, location_height, false,
kLeadingDecorationMaxFraction,
edge_padding, selected_keyword_view_);
if (selected_keyword_view_->keyword() != keyword) {
selected_keyword_view_->SetKeyword(keyword, profile_);
if (selected_keyword_view_->GetKeyword() != keyword) {
selected_keyword_view_->SetKeyword(keyword);
const TemplateURL* template_url =
TemplateURLServiceFactory::GetForProfile(profile_)
->GetTemplateURLForKeyword(keyword);
......@@ -628,7 +635,7 @@ void LocationBarView::Layout() {
// Layout |ime_inline_autocomplete_view_| next to the user input.
if (ime_inline_autocomplete_view_->GetVisible()) {
int width =
gfx::GetStringWidth(ime_inline_autocomplete_view_->GetText(),
gfx::GetStringWidth(GetImeInlineAutocompletion(),
ime_inline_autocomplete_view_->font_list()) +
ime_inline_autocomplete_view_->GetInsets().width();
// All the target languages (IMEs) are LTR, and we do not need to support
......@@ -705,10 +712,20 @@ void LocationBarView::SetOmniboxAdditionalText(const base::string16& text) {
if (!OmniboxFieldTrial::RichAutocompletionShowAdditionalText())
return;
auto wrapped_text =
text.empty() ? text
text.empty()
? text
// TODO(pkasting): This should use a localizable string constant.
: base::UTF8ToUTF16("(") + text + base::UTF8ToUTF16(")");
if (wrapped_text == GetOmniboxAdditionalText())
return;
omnibox_additional_text_view_->SetText(wrapped_text);
omnibox_additional_text_view_->SetVisible(!wrapped_text.empty());
OnPropertyChanged(&omnibox_additional_text_view_,
views::kPropertyEffectsLayout);
}
base::string16 LocationBarView::GetOmniboxAdditionalText() const {
return omnibox_additional_text_view_->GetText();
}
void LocationBarView::Update(WebContents* contents) {
......@@ -1052,10 +1069,6 @@ bool LocationBarView::IsContentSettingBubbleShowing(size_t index) {
content_setting_views_[index]->IsBubbleShowing();
}
const char* LocationBarView::GetClassName() const {
return kViewClassName;
}
void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
RefreshBackground();
}
......@@ -1334,3 +1347,20 @@ ui::MouseEvent LocationBarView::AdjustMouseEventLocationForOmniboxView(
adjusted.ConvertLocationToTarget<View>(this, omnibox_view_);
return adjusted;
}
bool LocationBarView::GetPopupMode() const {
return is_popup_mode_;
}
BEGIN_METADATA(LocationBarView, views::View)
ADD_READONLY_PROPERTY_METADATA(int, BorderRadius)
ADD_READONLY_PROPERTY_METADATA(SkColor, OpaqueBorderColor)
ADD_READONLY_PROPERTY_METADATA(gfx::Point, OmniboxViewOrigin)
ADD_PROPERTY_METADATA(base::string16, ImeInlineAutocompletion)
ADD_PROPERTY_METADATA(base::string16, OmniboxAdditionalText)
ADD_READONLY_PROPERTY_METADATA(int, MinimumLeadingWidth)
ADD_READONLY_PROPERTY_METADATA(int, MinimumTrailingWidth)
ADD_READONLY_PROPERTY_METADATA(SkColor, BorderColor)
ADD_READONLY_PROPERTY_METADATA(gfx::Rect, LocalBoundsWithoutEndcaps)
ADD_READONLY_PROPERTY_METADATA(bool, PopupMode)
END_METADATA
......@@ -13,7 +13,6 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/extensions/extension_context_menu_model.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
......@@ -36,6 +35,7 @@
#include "ui/views/animation/animation_delegate_views.h"
#include "ui/views/controls/focus_ring.h"
#include "ui/views/drag_controller.h"
#include "ui/views/metadata/metadata_header_macros.h"
class CommandUpdater;
class ContentSettingBubbleModelDelegate;
......@@ -74,6 +74,8 @@ class LocationBarView : public LocationBar,
public ContentSettingImageView::Delegate,
public PageActionIconView::Delegate {
public:
METADATA_HEADER(LocationBarView);
class Delegate {
public:
// Should return the current web contents.
......@@ -90,15 +92,13 @@ class LocationBarView : public LocationBar,
virtual ~Delegate() {}
};
// The location bar view's class name.
static const char kViewClassName[];
LocationBarView(Browser* browser,
Profile* profile,
CommandUpdater* command_updater,
Delegate* delegate,
bool is_popup_mode);
LocationBarView(const LocationBarView&) = delete;
LocationBarView& operator=(const LocationBarView&) = delete;
~LocationBarView() override;
// Returns the location bar border radius in DIPs.
......@@ -141,6 +141,7 @@ class LocationBarView : public LocationBar,
// we can't show the autocompletion inside the actual OmniboxView. See
// comments on |ime_inline_autocomplete_view_|.
void SetImeInlineAutocompletion(const base::string16& text);
base::string16 GetImeInlineAutocompletion() const;
// Select all of the text. Needed when the user tabs through controls
// in the toolbar in full keyboard accessibility mode.
......@@ -157,6 +158,7 @@ class LocationBarView : public LocationBar,
// Sets the additional omnibox text. E.g. the title corresponding to the URL
// displayed in the OmniboxView.
void SetOmniboxAdditionalText(const base::string16& text);
base::string16 GetOmniboxAdditionalText() const;
// Updates the controller, and, if |contents| is non-null, restores saved
// state that the tab holds.
......@@ -296,7 +298,6 @@ class LocationBarView : public LocationBar,
bool IsContentSettingBubbleShowing(size_t index) override;
// views::View:
const char* GetClassName() const override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
bool GetNeedsNotificationWhenVisibleBoundsChange() const override;
void OnVisibleBoundsChanged() override;
......@@ -360,6 +361,8 @@ class LocationBarView : public LocationBar,
ui::MouseEvent AdjustMouseEventLocationForOmniboxView(
const ui::MouseEvent& event) const;
bool GetPopupMode() const;
// The Browser this LocationBarView is in. Note that at least
// chromeos::SimpleWebViewDialog uses a LocationBarView outside any browser
// window, so this may be NULL.
......@@ -437,8 +440,6 @@ class LocationBarView : public LocationBar,
base::Unretained(this)));
base::WeakPtrFactory<LocationBarView> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(LocationBarView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_LOCATION_BAR_VIEW_H_
......@@ -5,8 +5,6 @@
#include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
#include "base/check.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
......@@ -18,6 +16,7 @@
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/metadata/metadata_impl_macros.h"
// static
SelectedKeywordView::KeywordLabelNames
......@@ -36,10 +35,13 @@ SelectedKeywordView::GetKeywordLabelNames(const base::string16& keyword,
return names;
}
SelectedKeywordView::SelectedKeywordView(LocationBarView* location_bar,
SelectedKeywordView::SelectedKeywordView(
LocationBarView* location_bar,
TemplateURLService* template_url_service,
const gfx::FontList& font_list)
: IconLabelBubbleView(font_list, location_bar),
location_bar_(location_bar) {
location_bar_(location_bar),
template_url_service_(template_url_service) {
full_label_.SetFontList(font_list);
full_label_.SetVisible(false);
partial_label_.SetFontList(font_list);
......@@ -84,19 +86,18 @@ void SelectedKeywordView::OnThemeChanged() {
SetCustomImage(gfx::Image());
}
void SelectedKeywordView::SetKeyword(const base::string16& keyword,
Profile* profile) {
keyword_ = keyword;
if (keyword.empty())
void SelectedKeywordView::SetKeyword(const base::string16& keyword) {
if (keyword_ == keyword)
return;
DCHECK(profile);
TemplateURLService* service =
TemplateURLServiceFactory::GetForProfile(profile);
if (!service)
keyword_ = keyword;
OnPropertyChanged(&keyword_, views::kPropertyEffectsNone);
// TODO(pkasting): Arguably, much of the code below would be better as
// property change handlers in file-scope subclasses of Label etc.
if (keyword.empty() || !template_url_service_)
return;
KeywordLabelNames names = GetKeywordLabelNames(keyword, service);
KeywordLabelNames names =
GetKeywordLabelNames(keyword, template_url_service_);
full_label_.SetText(names.full_name);
partial_label_.SetText(names.short_name);
......@@ -107,15 +108,15 @@ void SelectedKeywordView::SetKeyword(const base::string16& keyword,
NotifyAccessibilityEvent(ax::mojom::Event::kLiveRegionChanged, true);
}
const base::string16& SelectedKeywordView::GetKeyword() const {
return keyword_;
}
int SelectedKeywordView::GetExtraInternalSpacing() const {
// Align the label text with the suggestion text.
return 11;
}
const char* SelectedKeywordView::GetClassName() const {
return "SelectedKeywordView";
}
void SelectedKeywordView::SetLabelForCurrentWidth() {
// Keep showing the full label as long as there's more than enough width for
// the partial label. Otherwise there will be empty space displayed next to
......@@ -125,3 +126,7 @@ void SelectedKeywordView::SetLabelForCurrentWidth() {
GetSizeForLabelWidth(partial_label_.GetPreferredSize().width()).width();
SetLabel(use_full_label ? full_label_.GetText() : partial_label_.GetText());
}
BEGIN_METADATA(SelectedKeywordView, IconLabelBubbleView)
ADD_PROPERTY_METADATA(base::string16, Keyword)
END_METADATA
......@@ -8,13 +8,12 @@
#include <string>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/views/controls/label.h"
#include "ui/views/metadata/metadata_header_macros.h"
class LocationBarView;
class Profile;
class TemplateURLService;
namespace gfx {
......@@ -25,6 +24,8 @@ class Size;
// SelectedKeywordView displays the tab-to-search UI in the location bar view.
class SelectedKeywordView : public IconLabelBubbleView {
public:
METADATA_HEADER(SelectedKeywordView);
struct KeywordLabelNames {
base::string16 short_name;
base::string16 full_name;
......@@ -37,7 +38,10 @@ class SelectedKeywordView : public IconLabelBubbleView {
TemplateURLService* service);
SelectedKeywordView(LocationBarView* location_bar,
TemplateURLService* template_url_service,
const gfx::FontList& font_list);
SelectedKeywordView(const SelectedKeywordView&) = delete;
SelectedKeywordView& operator=(const SelectedKeywordView&) = delete;
~SelectedKeywordView() override;
// Sets the icon for this chip to |image|. If there is no custom image (i.e.
......@@ -51,8 +55,8 @@ class SelectedKeywordView : public IconLabelBubbleView {
SkColor GetForegroundColor() const override;
// The current keyword, or an empty string if no keyword is displayed.
void SetKeyword(const base::string16& keyword, Profile* profile);
const base::string16& keyword() const { return keyword_; }
void SetKeyword(const base::string16& keyword);
const base::string16& GetKeyword() const;
using IconLabelBubbleView::label;
......@@ -60,11 +64,11 @@ class SelectedKeywordView : public IconLabelBubbleView {
// IconLabelBubbleView:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
int GetExtraInternalSpacing() const override;
const char* GetClassName() const override;
void SetLabelForCurrentWidth();
LocationBarView* location_bar_;
TemplateURLService* template_url_service_;
// The keyword we're showing. If empty, no keyword is selected.
// NOTE: we don't cache the TemplateURL as it is possible for it to get
......@@ -80,8 +84,6 @@ class SelectedKeywordView : public IconLabelBubbleView {
// True when the chip icon has been changed via SetCustomImage().
bool using_custom_image_ = false;
DISALLOW_COPY_AND_ASSIGN(SelectedKeywordView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_SELECTED_KEYWORD_VIEW_H_
......@@ -32,6 +32,7 @@
#include "ui/gfx/color_utils.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/metadata/metadata_impl_macros.h"
namespace {
......@@ -125,10 +126,6 @@ base::string16 StarView::GetTextForTooltipAndAccessibleName() const {
: IDS_TOOLTIP_STAR);
}
const char* StarView::GetClassName() const {
return "StarView";
}
void StarView::EditBookmarksPrefUpdated() {
Update();
}
......@@ -162,3 +159,6 @@ void StarView::MenuClosed(ui::SimpleMenuModel* source) {
}
menu_runner_.reset();
}
BEGIN_METADATA(StarView, PageActionIconView)
END_METADATA
......@@ -7,10 +7,10 @@
#include <memory>
#include "base/macros.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "components/prefs/pref_member.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/views/metadata/metadata_header_macros.h"
class Browser;
class CommandUpdater;
......@@ -20,10 +20,13 @@ class StarMenuModel;
class StarView : public PageActionIconView,
public ui::SimpleMenuModel::Delegate {
public:
METADATA_HEADER(StarView);
StarView(CommandUpdater* command_updater,
Browser* browser,
IconLabelBubbleView::Delegate* icon_label_bubble_delegate,
PageActionIconView::Delegate* page_action_icon_delegate);
StarView(const StarView&) = delete;
StarView& operator=(const StarView&) = delete;
~StarView() override;
StarMenuModel* menu_model_for_test() { return menu_model_.get(); }
......@@ -36,11 +39,9 @@ class StarView : public PageActionIconView,
views::BubbleDialogDelegate* GetBubble() const override;
const gfx::VectorIcon& GetVectorIcon() const override;
base::string16 GetTextForTooltipAndAccessibleName() const override;
const char* GetClassName() const override;
private:
void EditBookmarksPrefUpdated();
bool IsBookmarkStarHiddenByExtension() const;
// ui::SimpleMenuModel::Delegate:
void ExecuteCommand(int command_id, int event_flags) override;
......@@ -52,8 +53,6 @@ class StarView : public PageActionIconView,
std::unique_ptr<StarMenuModel> menu_model_;
BooleanPrefMember edit_bookmarks_enabled_;
DISALLOW_COPY_AND_ASSIGN(StarView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_STAR_VIEW_H_
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