1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
// Copyright 2012 The Chromium Authors
// 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_CONTENT_SETTING_IMAGE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_
#include <memory>
#include <string>
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model_states.h"
#include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
#include "components/user_education/common/help_bubble/help_bubble.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
class Browser;
class ContentSettingImageModel;
namespace content {
class WebContents;
}
namespace gfx {
class FontList;
}
namespace views {
class BubbleDialogDelegateView;
}
// The ContentSettingImageView displays an icon and optional text label for
// various content settings affordances in the location bar (i.e. plugin
// blocking, geolocation).
class ContentSettingImageView : public IconLabelBubbleView,
public views::WidgetObserver {
METADATA_HEADER(ContentSettingImageView, IconLabelBubbleView)
public:
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kMediaActivityIndicatorElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kMidiActivityIndicatorElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kMidiSysexActivityIndicatorElementId);
class Delegate {
public:
// Delegate should return true if the content setting icon should be hidden.
virtual bool ShouldHideContentSettingImage() = 0;
// Gets the web contents the ContentSettingImageView is for.
virtual content::WebContents* GetContentSettingWebContents() = 0;
// Gets the ContentSettingBubbleModelDelegate for this
// ContentSettingImageView.
virtual ContentSettingBubbleModelDelegate*
GetContentSettingBubbleModelDelegate() = 0;
// Invoked when a bubble is shown.
virtual void OnContentSettingImageBubbleShown(
ContentSettingImageModel::ImageType type) const {}
};
ContentSettingImageView(std::unique_ptr<ContentSettingImageModel> image_model,
IconLabelBubbleView::Delegate* parent_delegate,
Delegate* delegate,
Browser* browser,
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(std::optional<SkColor> color);
std::optional<SkColor> GetIconColor() const;
void disable_animation() { can_animate_ = false; }
bool ShowBubbleImpl();
// IconLabelBubbleView:
bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnKeyPressed(const ui::KeyEvent& event) override;
void OnThemeChanged() override;
bool ShouldShowSeparator() const override;
bool ShowBubble(const ui::Event& event) override;
bool IsBubbleShowing() const override;
void AnimationEnded(const gfx::Animation* animation) override;
// Returns a type that current ContentSettingImageView represents.
ContentSettingImageModel::ImageType GetType() const;
views::Widget* GetBubbleWidgetForTesting() const;
ContentSettingImageModel* content_setting_image_model() const {
return content_setting_image_model_.get();
}
Delegate* delegate() const { return delegate_; }
void reset_animation_for_testing() {
IconLabelBubbleView::ResetSlideAnimation(true);
}
const gfx::VectorIcon* get_icon_for_testing() const {
return content_setting_image_model_->icon();
}
const gfx::VectorIcon* get_icon_badge_for_testing() const {
return content_setting_image_model_->get_icon_badge();
}
const std::u16string& get_tooltip_text_for_testing() const {
return content_setting_image_model_->get_tooltip();
}
private:
// views::WidgetObserver:
void OnWidgetDestroying(views::Widget* widget) override;
// Updates the image and tooltip to match the current model state.
void UpdateImage();
void UpdateElementIdentifier();
raw_ptr<Delegate> delegate_ = nullptr; // Weak.
std::unique_ptr<ContentSettingImageModel> content_setting_image_model_;
raw_ptr<views::BubbleDialogDelegateView> bubble_view_ = nullptr;
std::optional<SkColor> icon_color_;
raw_ptr<Browser> browser_;
// Observes destruction of bubble's Widgets spawned by this ImageView.
base::ScopedObservation<views::Widget, views::WidgetObserver> observation_{
this};
bool can_animate_ = true;
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_CONTENT_SETTING_IMAGE_VIEW_H_
|