Commit 575f58ec authored by Kinuko Yasuda's avatar Kinuko Yasuda Committed by Commit Bot

Revert "Revert "[desktop-pwas] Add content setting indicators to Hosted App frame.""

This reverts commit 23985150.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> Revert "[desktop-pwas] Add content setting indicators to Hosted App frame."
> 
> This reverts commit 64ae7852.
> 
> Reason for revert: suspected to cause bunch of MSAN error
> 
> https://build.chromium.org/p/chromium.memory/builders/Linux%20ChromiumOS%20MSan%20Tests/builds/4406/steps/browser_tests
> 
> Original change's description:
> > [desktop-pwas] Add content setting indicators to Hosted App frame.
> >
> > This CL adds ContentSettingImageViews to the HostedAppButtonContainer by:
> > - Factoring out a Delegate for ContentSettingImageView which the
> >   HostedAppButtonContainer and LocationBarView implement
> > - Adding an icon color override to ContentSettingImageView
> > - Moving the HostedAppButtonContainer to BrowserNonClientView instead of
> >   BrowserNonClientViewAsh so that BrowserView can access it
> >   (which also prepares its addition to OpaqueBrowserFrameView).
> >
> > This all allows the content setting indicators to be embedded in the
> > hosted app frame, get notified of content setting changes, and respond
> > to active/inactive states.
> >
> > Bug: 762401
> > Change-Id: I3f65f022201740c8e5a066937d32c189f283a048
> > Reviewed-on: https://chromium-review.googlesource.com/756634
> > Commit-Queue: calamity <calamity@chromium.org>
> > Reviewed-by: James Cook <jamescook@chromium.org>
> > Reviewed-by: Trent Apted <tapted@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#519562}
> 
> TBR=jamescook@chromium.org,tapted@chromium.org,calamity@chromium.org
> 
> Change-Id: Id42cff75e0792818065a9a3fc9816011b7caa367
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 762401
> Reviewed-on: https://chromium-review.googlesource.com/792583
> Commit-Queue: Henrik Boström <hbos@chromium.org>
> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#519631}

TBR=jamescook@chromium.org,kinuko@chromium.org,tapted@chromium.org,calamity@chromium.org,hbos@chromium.org

Change-Id: I90d290ed7c70afb695c2f8b2b11cf1dbb9265db7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 762401
Reviewed-on: https://chromium-review.googlesource.com/792584Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519637}
parent 65e985d7
......@@ -51,12 +51,16 @@ FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener,
FrameCaptionButton::~FrameCaptionButton() = default;
// static
SkColor FrameCaptionButton::GetButtonColor(bool use_light_images) {
return use_light_images ? SK_ColorWHITE : gfx::kChromeIconGrey;
}
void FrameCaptionButton::SetImage(CaptionButtonIcon icon,
Animate animate,
const gfx::VectorIcon& icon_definition) {
gfx::ImageSkia new_icon_image = gfx::CreateVectorIcon(
icon_definition,
use_light_images_ ? SK_ColorWHITE : gfx::kChromeIconGrey);
gfx::ImageSkia new_icon_image =
gfx::CreateVectorIcon(icon_definition, GetButtonColor(use_light_images_));
// The early return is dependent on |animate| because callers use SetImage()
// with ANIMATE_NO to progress the crossfade animation to the end.
......
......@@ -31,6 +31,9 @@ class ASH_EXPORT FrameCaptionButton : public views::Button {
FrameCaptionButton(views::ButtonListener* listener, CaptionButtonIcon icon);
~FrameCaptionButton() override;
// Gets the color to use for a frame caption button.
static SkColor GetButtonColor(bool use_light_images);
// Sets the image to use to paint the button. If |animate| is ANIMATE_YES,
// the button crossfades to the new visuals. If the image matches the one
// currently used by the button and |animate| is ANIMATE_NO, the crossfade
......
......@@ -282,7 +282,8 @@ void DefaultFrameHeader::PaintTitleBar(gfx::Canvas* canvas) {
gfx::Rect title_bounds = GetAvailableTitleBounds();
title_bounds.set_x(view_->GetMirroredXForRect(title_bounds));
canvas->DrawStringRect(frame_->widget_delegate()->GetWindowTitle(),
GetTitleFontList(), GetTitleColor(), title_bounds);
views::NativeWidgetAura::GetWindowTitleFontList(),
GetTitleColor(), title_bounds);
}
void DefaultFrameHeader::PaintHeaderContentSeparator(gfx::Canvas* canvas) {
......@@ -327,7 +328,8 @@ gfx::Rect DefaultFrameHeader::GetLocalBounds() const {
gfx::Rect DefaultFrameHeader::GetAvailableTitleBounds() const {
views::View* left_view = left_header_view_ ? left_header_view_ : back_button_;
return FrameHeaderUtil::GetAvailableTitleBounds(
left_view, caption_button_container_, GetTitleFontList());
left_view, caption_button_container_,
views::NativeWidgetAura::GetWindowTitleFontList());
}
bool DefaultFrameHeader::UsesCustomFrameColors() const {
......
......@@ -17,7 +17,6 @@
#include "ui/gfx/animation/animation_delegate.h"
namespace gfx {
class FontList;
class Rect;
class SlideAnimation;
} // namespace gfx
......@@ -75,9 +74,6 @@ class ASH_EXPORT DefaultFrameHeader : public FrameHeader,
bool ShouldUseLightImages() const;
protected:
// Returns the FontList to use for the title.
static const gfx::FontList& GetTitleFontList();
// Paints the title bar, primarily the title string.
virtual void PaintTitleBar(gfx::Canvas* canvas);
......
......@@ -568,13 +568,7 @@ void ContentSettingDownloadsImageModel::UpdateFromWebContents(
// Base class ------------------------------------------------------------------
gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const {
#if defined(OS_MACOSX)
SkColor icon_color = nearby_text_color;
#else
SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color);
#endif
gfx::Image ContentSettingImageModel::GetIcon(SkColor icon_color) const {
return gfx::Image(
gfx::CreateVectorIconWithBadge(*icon_, 16, icon_color, *icon_badge_));
}
......
......@@ -62,7 +62,7 @@ class ContentSettingImageModel {
content::WebContents* web_contents);
#endif
gfx::Image GetIcon(SkColor nearby_text_color) const;
gfx::Image GetIcon(SkColor icon_color) const;
// Returns the resource ID of a string to show when the icon appears, or 0 if
// we don't wish to show anything.
......
......@@ -244,6 +244,8 @@ void BrowserNonClientFrameViewAsh::GetWindowMask(const gfx::Size& size,
void BrowserNonClientFrameViewAsh::ResetWindowControls() {
caption_button_container_->SetVisible(true);
caption_button_container_->ResetWindowControls();
if (hosted_app_button_container_)
hosted_app_button_container_->RefreshContentSettingViews();
}
void BrowserNonClientFrameViewAsh::UpdateWindowIcon() {
......@@ -512,12 +514,13 @@ BrowserNonClientFrameViewAsh::CreateFrameHeader() {
caption_button_container_);
// Add the container for extra hosted app buttons (e.g app menu button).
SkColor text_color = default_frame_header->GetTitleColor();
SkColor button_color = ash::FrameCaptionButton::GetButtonColor(
default_frame_header->ShouldUseLightImages());
hosted_app_button_container_ = new HostedAppButtonContainer(
browser_view(), text_color,
SkColorSetA(text_color, 255 * ash::kInactiveFrameButtonIconAlphaRatio));
browser_view(), button_color,
SkColorSetA(button_color,
255 * ash::kInactiveFrameButtonIconAlphaRatio));
caption_button_container_->AddChildViewAt(hosted_app_button_container_, 0);
} else {
default_frame_header = std::make_unique<ash::DefaultFrameHeader>(
frame(), this, caption_button_container_);
......
......@@ -43,7 +43,10 @@
#include "chrome/common/chrome_features.h"
#include "chrome/common/web_application_info.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/signin/core/account_id/account_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/env_test_helper.h"
#include "ui/base/hit_test.h"
......@@ -463,15 +466,20 @@ IN_PROC_BROWSER_TEST_F(ImmersiveModeBrowserViewTest,
// Creates a browser for a bookmark app and verifies the window frame is
// correct.
IN_PROC_BROWSER_TEST_F(HostedAppNonClientFrameViewAshTest, HostedAppFrame) {
const GURL kAppStartURL("http://example.org/");
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kDesktopPWAWindowing);
WebApplicationInfo web_app_info;
web_app_info.app_url = GURL("http://example.org/");
web_app_info.app_url = kAppStartURL;
web_app_info.theme_color = SK_ColorBLUE;
const extensions::Extension* app = InstallBookmarkApp(web_app_info);
Browser* app_browser = LaunchAppBrowser(app);
chrome::NavigateParams params(app_browser, kAppStartURL,
ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
BrowserView* browser_view =
BrowserView::GetBrowserViewForBrowser(app_browser);
......@@ -500,6 +508,26 @@ IN_PROC_BROWSER_TEST_F(HostedAppNonClientFrameViewAshTest, HostedAppFrame) {
menu_button->OnMousePressed(e);
EXPECT_TRUE(menu_button->menu()->IsShowing());
// Show a content setting icon.
const auto& content_setting_views =
frame_view->hosted_app_button_container_->content_setting_views_;
for (auto* v : content_setting_views)
EXPECT_FALSE(v->visible());
content::RenderFrameHost* frame =
app_browser->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::GetForFrame(frame->GetProcess()->GetID(),
frame->GetRoutingID());
content_settings->OnGeolocationPermissionSet(kAppStartURL.GetOrigin(), true);
int visible = std::count_if(
content_setting_views.begin(), content_setting_views.end(),
[](const ContentSettingImageView* v) { return v->visible(); });
EXPECT_EQ(1, visible);
// The app and domain should render next to the window title.
frame_header->LayoutRenderTexts(gfx::Rect(300, 30), 100, 100);
EXPECT_EQ(gfx::Rect(100, 30),
......
......@@ -5,14 +5,25 @@
#include "chrome/browser/ui/views/frame/hosted_app_button_container.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model.h"
#include "chrome/browser/ui/extensions/hosted_app_menu_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "chrome/browser/ui/views/toolbar/app_menu.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/native_widget_aura.h"
namespace {
// Padding around content setting icons.
constexpr int kContentSettingIconInteriorPadding = 4;
} // namespace
HostedAppButtonContainer::AppMenuButton::AppMenuButton(
BrowserView* browser_view)
......@@ -49,19 +60,57 @@ HostedAppButtonContainer::HostedAppButtonContainer(BrowserView* browser_view,
active_icon_color_(active_icon_color),
inactive_icon_color_(inactive_icon_color),
app_menu_button_(new AppMenuButton(browser_view)) {
DCHECK(browser_view_);
auto layout =
std::make_unique<views::BoxLayout>(views::BoxLayout::kHorizontal);
layout->set_cross_axis_alignment(
views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
SetLayoutManager(layout.release());
std::vector<std::unique_ptr<ContentSettingImageModel>> models =
ContentSettingImageModel::GenerateContentSettingImageModels();
for (auto& model : models) {
auto image_view = std::make_unique<ContentSettingImageView>(
std::move(model), this,
views::NativeWidgetAura::GetWindowTitleFontList());
image_view->SetIconColor(active_icon_color);
image_view->set_next_element_interior_padding(
kContentSettingIconInteriorPadding);
image_view->SetVisible(false);
image_view->disable_animation();
content_setting_views_.push_back(image_view.get());
AddChildView(image_view.release());
}
app_menu_button_->SetIconColor(active_icon_color);
AddChildView(app_menu_button_);
}
HostedAppButtonContainer::~HostedAppButtonContainer() {}
content::WebContents* HostedAppButtonContainer::GetContentSettingWebContents() {
return browser_view_->GetActiveWebContents();
}
ContentSettingBubbleModelDelegate*
HostedAppButtonContainer::GetContentSettingBubbleModelDelegate() {
return browser_view_->browser()->content_setting_bubble_model_delegate();
}
void HostedAppButtonContainer::RefreshContentSettingViews() {
for (auto* v : content_setting_views_)
v->Update();
}
void HostedAppButtonContainer::ChildVisibilityChanged(views::View* child) {
// Changes to layout need to be taken into account by the frame view.
browser_view_->frame()->GetFrameView()->Layout();
}
void HostedAppButtonContainer::SetPaintAsActive(bool active) {
for (auto* v : content_setting_views_)
v->SetIconColor(active ? active_icon_color_ : inactive_icon_color_);
app_menu_button_->SetIconColor(active ? active_icon_color_
: inactive_icon_color_);
}
......@@ -8,6 +8,7 @@
#include <memory>
#include "base/macros.h"
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/menu_button_listener.h"
#include "ui/views/view.h"
......@@ -17,7 +18,8 @@ class HostedAppMenuModel;
class BrowserView;
// A container for hosted app buttons in the title bar.
class HostedAppButtonContainer : public views::View {
class HostedAppButtonContainer : public views::View,
public ContentSettingImageView::Delegate {
public:
// |active_icon_color| and |inactive_icon_color| indicate the colors to use
// for button icons when the window is focused and blurred respectively.
......@@ -26,6 +28,9 @@ class HostedAppButtonContainer : public views::View {
SkColor inactive_icon_color);
~HostedAppButtonContainer() override;
// Updates the visibility of each content setting view.
void RefreshContentSettingViews();
// Sets the container to paints its buttons the active/inactive color.
void SetPaintAsActive(bool active);
......@@ -62,6 +67,14 @@ class HostedAppButtonContainer : public views::View {
DISALLOW_COPY_AND_ASSIGN(AppMenuButton);
};
// ContentSettingsImageView::Delegate:
content::WebContents* GetContentSettingWebContents() override;
ContentSettingBubbleModelDelegate* GetContentSettingBubbleModelDelegate()
override;
// views::View:
void ChildVisibilityChanged(views::View* child) override;
// The containing browser view.
BrowserView* browser_view_;
......@@ -71,6 +84,7 @@ class HostedAppButtonContainer : public views::View {
// Owned by the views hierarchy.
AppMenuButton* app_menu_button_;
std::vector<ContentSettingImageView*> content_setting_views_;
DISALLOW_COPY_AND_ASSIGN(HostedAppButtonContainer);
};
......
......@@ -11,6 +11,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/render_text.h"
#include "ui/views/view.h"
#include "ui/views/widget/native_widget_aura.h"
HostedAppFrameHeaderAsh::HostedAppFrameHeaderAsh(
extensions::HostedAppBrowserController* app_controller,
......@@ -42,7 +43,7 @@ HostedAppFrameHeaderAsh::~HostedAppFrameHeaderAsh() {}
std::unique_ptr<gfx::RenderText> HostedAppFrameHeaderAsh::CreateRenderText() {
std::unique_ptr<gfx::RenderText> render_text(
gfx::RenderText::CreateInstance());
render_text->SetFontList(GetTitleFontList());
render_text->SetFontList(views::NativeWidgetAura::GetWindowTitleFontList());
render_text->SetCursorEnabled(false);
render_text->SetColor(GetTitleColor());
render_text->SetElideBehavior(gfx::FADE_TAIL);
......
......@@ -5,11 +5,11 @@
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model.h"
#include "chrome/browser/ui/views/content_setting_bubble_contents.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/theme_provider.h"
......@@ -33,16 +33,16 @@ const int ContentSettingImageView::kAnimationDurationMS =
ContentSettingImageView::ContentSettingImageView(
std::unique_ptr<ContentSettingImageModel> image_model,
LocationBarView* parent,
Delegate* delegate,
const gfx::FontList& font_list)
: IconLabelBubbleView(font_list),
parent_(parent),
delegate_(delegate),
content_setting_image_model_(std::move(image_model)),
slide_animator_(this),
pause_animation_(false),
pause_animation_state_(0.0),
bubble_view_(nullptr) {
set_next_element_interior_padding(LocationBarView::kIconInteriorPadding);
DCHECK(delegate_);
SetInkDropMode(InkDropMode::ON);
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
image()->EnableCanvasFlippingForRTLUI(true);
......@@ -58,7 +58,9 @@ ContentSettingImageView::~ContentSettingImageView() {
bubble_view_->GetWidget()->RemoveObserver(this);
}
void ContentSettingImageView::Update(content::WebContents* web_contents) {
void ContentSettingImageView::Update() {
content::WebContents* web_contents =
delegate_->GetContentSettingWebContents();
// Note: We explicitly want to call this even if |web_contents| is NULL, so we
// get hidden properly while the user is editing the omnibox.
content_setting_image_model_->UpdateFromWebContents(web_contents);
......@@ -73,8 +75,10 @@ void ContentSettingImageView::Update(content::WebContents* web_contents) {
// If the content usage or blockage should be indicated to the user, start the
// animation and record that the icon has been shown.
if (!content_setting_image_model_->ShouldRunAnimation(web_contents))
if (!can_animate_ ||
!content_setting_image_model_->ShouldRunAnimation(web_contents)) {
return;
}
// We just ignore this blockage if we're already showing some other string to
// the user. If this becomes a problem, we could design some sort of queueing
......@@ -90,6 +94,12 @@ void ContentSettingImageView::Update(content::WebContents* web_contents) {
content_setting_image_model_->SetAnimationHasRun(web_contents);
}
void ContentSettingImageView::SetIconColor(SkColor color) {
icon_color_ = color;
if (content_setting_image_model_->is_visible())
UpdateImage();
}
const char* ContentSettingImageView::GetClassName() const {
return "ContentSettingsImageView";
}
......@@ -164,16 +174,17 @@ bool ContentSettingImageView::ShowBubble(const ui::Event& event) {
slide_animator_.Reset();
}
content::WebContents* web_contents = parent_->GetWebContents();
content::WebContents* web_contents =
delegate_->GetContentSettingWebContents();
if (web_contents && !bubble_view_) {
views::View* anchor = this;
if (ui::MaterialDesignController::IsSecondaryUiMaterial())
anchor = parent_;
anchor = parent();
bubble_view_ = new ContentSettingBubbleContents(
content_setting_image_model_->CreateBubbleModel(
parent_->delegate()->GetContentSettingBubbleModelDelegate(),
web_contents, parent_->profile()),
web_contents, anchor, views::BubbleBorder::TOP_RIGHT);
content_setting_image_model_->CreateBubbleModel(
delegate_->GetContentSettingBubbleModelDelegate(), web_contents,
Profile::FromBrowserContext(web_contents->GetBrowserContext())),
web_contents, anchor, views::BubbleBorder::TOP_RIGHT);
views::Widget* bubble_widget =
views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
bubble_widget->AddObserver(this);
......@@ -197,12 +208,17 @@ bool ContentSettingImageView::IsBubbleShowing() const {
return bubble_view_ != nullptr;
}
SkColor ContentSettingImageView::GetInkDropBaseColor() const {
return icon_color_ ? icon_color_.value()
: IconLabelBubbleView::GetInkDropBaseColor();
}
void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
slide_animator_.Reset();
if (!pause_animation_) {
label()->SetVisible(false);
parent_->Layout();
parent_->SchedulePaint();
parent()->Layout();
parent()->SchedulePaint();
}
GetInkDrop()->SetShowHighlightOnHover(true);
......@@ -212,8 +228,8 @@ void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
void ContentSettingImageView::AnimationProgressed(
const gfx::Animation* animation) {
if (!pause_animation_) {
parent_->Layout();
parent_->SchedulePaint();
parent()->Layout();
parent()->SchedulePaint();
}
}
......@@ -243,7 +259,11 @@ void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget,
}
void ContentSettingImageView::UpdateImage() {
SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
SetImage(content_setting_image_model_
->GetIcon(icon_color_ ? icon_color_.value()
: color_utils::DeriveDefaultIconColor(
GetTextColor()))
.AsImageSkia());
}
void ContentSettingImageView::AnimateIn() {
......
......@@ -17,7 +17,6 @@
#include "ui/views/view.h"
class ContentSettingImageModel;
class LocationBarView;
namespace content {
class WebContents;
......@@ -36,13 +35,32 @@ class BubbleDialogDelegateView;
// blocking, geolocation).
class ContentSettingImageView : public IconLabelBubbleView {
public:
class Delegate {
public:
// Gets the web contents the ContentSettingImageView is for.
virtual content::WebContents* GetContentSettingWebContents() = 0;
// Gets the ContentSettingBubbleModelDelegate for this
// ContentSettingImageView.
virtual ContentSettingBubbleModelDelegate*
GetContentSettingBubbleModelDelegate() = 0;
protected:
virtual ~Delegate() {}
};
ContentSettingImageView(std::unique_ptr<ContentSettingImageModel> image_model,
LocationBarView* parent,
Delegate* delegate,
const gfx::FontList& font_list);
~ContentSettingImageView() override;
// Updates the decoration from the shown WebContents.
void Update(content::WebContents* web_contents);
void Update();
// Set the color of the button icon. Based on the text color by default.
void SetIconColor(SkColor color);
void disable_animation() { can_animate_ = false; }
private:
// The total animation time, including open and close as well as an
......@@ -55,6 +73,7 @@ class ContentSettingImageView : public IconLabelBubbleView {
bool GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const override;
void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override;
SkColor GetInkDropBaseColor() const override;
SkColor GetTextColor() const override;
bool ShouldShowLabel() const override;
double WidthMultiplier() const override;
......@@ -80,12 +99,15 @@ class ContentSettingImageView : public IconLabelBubbleView {
// animation is running.
void AnimateIn();
LocationBarView* parent_; // Weak, owns us.
Delegate* delegate_; // Weak.
std::unique_ptr<ContentSettingImageModel> content_setting_image_model_;
gfx::SlideAnimation slide_animator_;
bool pause_animation_;
double pause_animation_state_;
views::BubbleDialogDelegateView* bubble_view_;
base::Optional<SkColor> icon_color_;
bool can_animate_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingImageView);
};
......
......@@ -81,6 +81,10 @@ class IconLabelBubbleView : public views::InkDropObserver,
// Exposed for testing.
SeparatorView* separator_view() const { return separator_view_; }
void set_next_element_interior_padding(int padding) {
next_element_interior_padding_ = padding;
}
protected:
static constexpr int kOpenTimeMS = 150;
......@@ -92,10 +96,6 @@ class IconLabelBubbleView : public views::InkDropObserver,
return ink_drop_container_;
}
void set_next_element_interior_padding(int padding) {
next_element_interior_padding_ = padding;
}
// Gets the color for displaying text.
virtual SkColor GetTextColor() const = 0;
......
......@@ -30,6 +30,7 @@
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/layout_constants.h"
......@@ -224,6 +225,7 @@ void LocationBarView::Init() {
ContentSettingImageView* image_view =
new ContentSettingImageView(std::move(model), this, font_list);
content_setting_views_.push_back(image_view);
image_view->set_next_element_interior_padding(kIconInteriorPadding);
image_view->SetVisible(false);
AddChildView(image_view);
}
......@@ -655,6 +657,18 @@ WebContents* LocationBarView::GetWebContents() {
return delegate_->GetWebContents();
}
////////////////////////////////////////////////////////////////////////////////
// LocationBarView, public ContentSettingImageView::Delegate implementation:
content::WebContents* LocationBarView::GetContentSettingWebContents() {
return GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents();
}
ContentSettingBubbleModelDelegate*
LocationBarView::GetContentSettingBubbleModelDelegate() {
return delegate_->GetContentSettingBubbleModelDelegate();
}
////////////////////////////////////////////////////////////////////////////////
// LocationBarView, private:
......@@ -698,13 +712,18 @@ void LocationBarView::RefreshLocationIcon() {
}
bool LocationBarView::RefreshContentSettingViews() {
if (extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
browser_)) {
// For hosted apps, the location bar is normally hidden and icons appear in
// the window frame instead.
GetWidget()->non_client_view()->ResetWindowControls();
}
bool visibility_changed = false;
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() ? nullptr
: GetWebContents());
if (was_visible != (*i)->visible())
for (auto* v : content_setting_views_) {
const bool was_visible = v->visible();
v->Update();
if (was_visible != v->visible())
visibility_changed = true;
}
return visibility_changed;
......
......@@ -18,6 +18,7 @@
#include "chrome/browser/ui/views/dropdown_bar_host.h"
#include "chrome/browser/ui/views/dropdown_bar_host_delegate.h"
#include "chrome/browser/ui/views/extensions/extension_popup.h"
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "components/prefs/pref_member.h"
#include "components/security_state/core/security_state.h"
......@@ -31,7 +32,6 @@
class CommandUpdater;
class ContentSettingBubbleModelDelegate;
class ContentSettingImageView;
class FindBarIcon;
class GURL;
class IntentPickerView;
......@@ -69,7 +69,8 @@ class LocationBarView : public LocationBar,
public ChromeOmniboxEditController,
public DropdownBarHostDelegate,
public zoom::ZoomEventManagerObserver,
public views::ButtonListener {
public views::ButtonListener,
public ContentSettingImageView::Delegate {
public:
class Delegate {
public:
......@@ -237,6 +238,11 @@ class LocationBarView : public LocationBar,
ToolbarModel* GetToolbarModel() override;
content::WebContents* GetWebContents() override;
// ContentSettingImageView::Delegate:
content::WebContents* GetContentSettingWebContents() override;
ContentSettingBubbleModelDelegate* GetContentSettingBubbleModelDelegate()
override;
// ZoomEventManagerObserver:
// Updates the view for the zoom icon when default zoom levels change.
void OnDefaultZoomLevelChanged() 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