Commit 43080bd1 authored by Peter Kasting's avatar Peter Kasting Committed by Chromium LUCI CQ

Add metadata for bare files in c/b/ui/views/.

Also adds a builder for TabIconView and converts to using it.

Bug: 1159562,1159563
Change-Id: Ib4f10159a609b676571ea9cb9f8250a82e3f6a38
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2613010
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840816}
parent d8164b98
...@@ -128,10 +128,10 @@ void BrowserNonClientFrameViewChromeOS::Init() { ...@@ -128,10 +128,10 @@ void BrowserNonClientFrameViewChromeOS::Init() {
// Initializing the TabIconView is expensive, so only do it if we need to. // Initializing the TabIconView is expensive, so only do it if we need to.
if (browser_view()->ShouldShowWindowIcon()) { if (browser_view()->ShouldShowWindowIcon()) {
window_icon_ = new TabIconView(this, views::Button::PressedCallback()); AddChildView(views::Builder<TabIconView>()
window_icon_->set_is_light(true); .CopyAddressTo(&window_icon_)
AddChildView(window_icon_); .SetModel(this)
window_icon_->Update(); .Build());
} }
UpdateProfileIcons(); UpdateProfileIcons();
......
...@@ -95,14 +95,16 @@ GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, ...@@ -95,14 +95,16 @@ GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame,
if (browser_view->CanShowWindowIcon()) { if (browser_view->CanShowWindowIcon()) {
InitThrobberIcons(); InitThrobberIcons();
window_icon_ = new TabIconView(this, views::Button::PressedCallback()); AddChildView(views::Builder<TabIconView>()
window_icon_->set_is_light(true); .CopyAddressTo(&window_icon_)
window_icon_->SetID(VIEW_ID_WINDOW_ICON); .SetModel(this)
// Stop the icon from intercepting clicks intended for the HTSYSMENU region .SetID(VIEW_ID_WINDOW_ICON)
// of the window. Even though it does nothing on click, it will still // Stop the icon from intercepting clicks intended for the
// prevent us from giving the event back to Windows to handle properly. // HTSYSMENU region of the window. Even though it does
window_icon_->SetCanProcessEventsWithinSubtree(false); // nothing on click, it will still prevent us from giving
AddChildView(window_icon_); // the event back to Windows to handle properly.
.SetCanProcessEventsWithinSubtree(false)
.Build());
} }
web_app::AppBrowserController* controller = web_app::AppBrowserController* controller =
...@@ -368,7 +370,8 @@ void GlassBrowserFrameView::ResetWindowControls() { ...@@ -368,7 +370,8 @@ void GlassBrowserFrameView::ResetWindowControls() {
} }
bool GlassBrowserFrameView::ShouldTabIconViewAnimate() const { bool GlassBrowserFrameView::ShouldTabIconViewAnimate() const {
DCHECK(ShouldShowWindowIcon(TitlebarType::kCustom)); if (!ShouldShowWindowIcon(TitlebarType::kCustom))
return false;
content::WebContents* current_tab = browser_view()->GetActiveWebContents(); content::WebContents* current_tab = browser_view()->GetActiveWebContents();
return current_tab && current_tab->IsLoading(); return current_tab && current_tab->IsLoading();
} }
......
...@@ -179,13 +179,14 @@ void OpaqueBrowserFrameView::InitViews() { ...@@ -179,13 +179,14 @@ void OpaqueBrowserFrameView::InitViews() {
// Initializing the TabIconView is expensive, so only do it if we need to. // Initializing the TabIconView is expensive, so only do it if we need to.
if (browser_view()->ShouldShowWindowIcon()) { if (browser_view()->ShouldShowWindowIcon()) {
window_icon_ = new TabIconView( AddChildView(views::Builder<TabIconView>()
this, base::BindRepeating(&OpaqueBrowserFrameView::WindowIconPressed, .CopyAddressTo(&window_icon_)
base::Unretained(this))); .SetModel(this)
window_icon_->set_is_light(true); .SetCallback(base::BindRepeating(
window_icon_->SetID(VIEW_ID_WINDOW_ICON); &OpaqueBrowserFrameView::WindowIconPressed,
AddChildView(window_icon_); base::Unretained(this)))
window_icon_->Update(); .SetID(VIEW_ID_WINDOW_ICON)
.Build());
} }
web_app::AppBrowserController* controller = web_app::AppBrowserController* controller =
......
...@@ -151,10 +151,10 @@ class OpaqueBrowserFrameViewLayoutTest ...@@ -151,10 +151,10 @@ class OpaqueBrowserFrameViewLayoutTest
} }
void AddWindowTitleIcons() { void AddWindowTitleIcons() {
tab_icon_view_ = new TabIconView(nullptr, views::Button::PressedCallback()); root_view_->AddChildView(views::Builder<TabIconView>()
tab_icon_view_->set_is_light(true); .CopyAddressTo(&tab_icon_view_)
tab_icon_view_->SetID(VIEW_ID_WINDOW_ICON); .SetID(VIEW_ID_WINDOW_ICON)
root_view_->AddChildView(tab_icon_view_); .Build());
window_title_ = new views::Label(delegate_->GetWindowTitle()); window_title_ = new views::Label(delegate_->GetWindowTitle());
window_title_->SetVisible(delegate_->ShouldShowWindowTitle()); window_title_->SetVisible(delegate_->ShouldShowWindowTitle());
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/grid_layout.h" #include "ui/views/layout/grid_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
namespace { namespace {
...@@ -112,6 +113,7 @@ void LoginView::OnLoginModelDestroying() { ...@@ -112,6 +113,7 @@ void LoginView::OnLoginModelDestroying() {
http_auth_manager_ = nullptr; http_auth_manager_ = nullptr;
} }
const char* LoginView::GetClassName() const { BEGIN_METADATA(LoginView, views::View)
return "LoginView"; ADD_READONLY_PROPERTY_METADATA(base::string16, Username)
} ADD_READONLY_PROPERTY_METADATA(base::string16, Password)
END_METADATA
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
#ifndef CHROME_BROWSER_UI_VIEWS_LOGIN_VIEW_H_ #ifndef CHROME_BROWSER_UI_VIEWS_LOGIN_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_LOGIN_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_LOGIN_VIEW_H_
#include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/ui/login/login_handler.h" #include "chrome/browser/ui/login/login_handler.h"
#include "components/password_manager/core/browser/http_auth_observer.h" #include "components/password_manager/core/browser/http_auth_observer.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace views { namespace views {
...@@ -24,12 +24,15 @@ class HttpAuthManager; ...@@ -24,12 +24,15 @@ class HttpAuthManager;
class LoginView : public views::View, class LoginView : public views::View,
public password_manager::HttpAuthObserver { public password_manager::HttpAuthObserver {
public: public:
METADATA_HEADER(LoginView);
// |login_model_data->model| is observed for the entire lifetime of the // |login_model_data->model| is observed for the entire lifetime of the
// LoginView. Therefore |login_model_data->model| should not be destroyed // LoginView. Therefore |login_model_data->model| should not be destroyed
// before the LoginView object. |login_model_data| may be null. // before the LoginView object. |login_model_data| may be null.
LoginView(const base::string16& authority, LoginView(const base::string16& authority,
const base::string16& explanation, const base::string16& explanation,
LoginHandler::LoginModelData* login_model_data); LoginHandler::LoginModelData* login_model_data);
LoginView(const LoginView&) = delete;
LoginView& operator=(const LoginView&) = delete;
~LoginView() override; ~LoginView() override;
// Access the data in the username/password text fields. // Access the data in the username/password text fields.
...@@ -45,9 +48,6 @@ class LoginView : public views::View, ...@@ -45,9 +48,6 @@ class LoginView : public views::View,
views::View* GetInitiallyFocusedView(); views::View* GetInitiallyFocusedView();
private: private:
// views::View:
const char* GetClassName() const override;
// Non-owning refs to the input text fields. // Non-owning refs to the input text fields.
views::Textfield* username_field_; views::Textfield* username_field_;
views::Textfield* password_field_; views::Textfield* password_field_;
...@@ -55,8 +55,6 @@ class LoginView : public views::View, ...@@ -55,8 +55,6 @@ class LoginView : public views::View,
// If not null, points to a model we need to notify of our own destruction // If not null, points to a model we need to notify of our own destruction
// so it doesn't try and access this when its too late. // so it doesn't try and access this when its too late.
password_manager::HttpAuthManager* http_auth_manager_; password_manager::HttpAuthManager* http_auth_manager_;
DISALLOW_COPY_AND_ASSIGN(LoginView);
}; };
#endif // CHROME_BROWSER_UI_VIEWS_LOGIN_VIEW_H_ #endif // CHROME_BROWSER_UI_VIEWS_LOGIN_VIEW_H_
...@@ -32,6 +32,8 @@ class Widget; ...@@ -32,6 +32,8 @@ class Widget;
// to allow users to see where hovered links point to. // to allow users to see where hovered links point to.
class StatusBubbleViews : public StatusBubble { class StatusBubbleViews : public StatusBubble {
public: public:
class StatusView;
// How wide the bubble's shadow is. // How wide the bubble's shadow is.
static const int kShadowThickness; static const int kShadowThickness;
...@@ -79,7 +81,6 @@ class StatusBubbleViews : public StatusBubble { ...@@ -79,7 +81,6 @@ class StatusBubbleViews : public StatusBubble {
void MouseMovedAt(const gfx::Point& location, bool left_content); void MouseMovedAt(const gfx::Point& location, bool left_content);
private: private:
class StatusView;
class StatusViewAnimation; class StatusViewAnimation;
class StatusViewExpander; class StatusViewExpander;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "ui/gfx/favicon_size.h" #include "ui/gfx/favicon_size.h"
#include "ui/gfx/paint_throbber.h" #include "ui/gfx/paint_throbber.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "chrome/browser/win/app_icon.h" #include "chrome/browser/win/app_icon.h"
...@@ -67,10 +68,8 @@ class DefaultFavicon { ...@@ -67,10 +68,8 @@ class DefaultFavicon {
} // namespace } // namespace
TabIconView::TabIconView(TabIconViewModel* model, TabIconView::TabIconView() {
views::Button::PressedCallback callback) // Inheriting from Button causes this View to be focusable, but it is
: views::MenuButton(std::move(callback)), model_(model), is_light_(false) {
// Inheriting from Button causes this View to be focusable, but it us
// purely decorative and should not be exposed as focusable in accessibility. // purely decorative and should not be exposed as focusable in accessibility.
SetFocusBehavior(FocusBehavior::NEVER); SetFocusBehavior(FocusBehavior::NEVER);
} }
...@@ -78,8 +77,13 @@ TabIconView::TabIconView(TabIconViewModel* model, ...@@ -78,8 +77,13 @@ TabIconView::TabIconView(TabIconViewModel* model,
TabIconView::~TabIconView() { TabIconView::~TabIconView() {
} }
void TabIconView::SetModel(TabIconViewModel* model) {
model_ = model;
Update();
}
void TabIconView::Update() { void TabIconView::Update() {
if (!model_->ShouldTabIconViewAnimate()) if (!model_ || !model_->ShouldTabIconViewAnimate())
throbber_start_time_ = base::TimeTicks(); throbber_start_time_ = base::TimeTicks();
SchedulePaint(); SchedulePaint();
...@@ -89,12 +93,10 @@ void TabIconView::PaintThrobber(gfx::Canvas* canvas) { ...@@ -89,12 +93,10 @@ void TabIconView::PaintThrobber(gfx::Canvas* canvas) {
if (throbber_start_time_ == base::TimeTicks()) if (throbber_start_time_ == base::TimeTicks())
throbber_start_time_ = base::TimeTicks::Now(); throbber_start_time_ = base::TimeTicks::Now();
gfx::PaintThrobberSpinning( gfx::PaintThrobberSpinning(canvas, GetLocalBounds(),
canvas, GetLocalBounds(), GetNativeTheme()->GetSystemColor(
GetNativeTheme()->GetSystemColor( ui::NativeTheme::kColorId_ThrobberLightColor),
is_light_ ? ui::NativeTheme::kColorId_ThrobberLightColor base::TimeTicks::Now() - throbber_start_time_);
: ui::NativeTheme::kColorId_ThrobberSpinningColor),
base::TimeTicks::Now() - throbber_start_time_);
} }
void TabIconView::PaintFavicon(gfx::Canvas* canvas, void TabIconView::PaintFavicon(gfx::Canvas* canvas,
...@@ -129,24 +131,22 @@ gfx::Size TabIconView::CalculatePreferredSize() const { ...@@ -129,24 +131,22 @@ gfx::Size TabIconView::CalculatePreferredSize() const {
return gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); return gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize);
} }
const char* TabIconView::GetClassName() const {
return "TabIconView";
}
void TabIconView::PaintButtonContents(gfx::Canvas* canvas) { void TabIconView::PaintButtonContents(gfx::Canvas* canvas) {
bool rendered = false; if (model_) {
if (model_->ShouldTabIconViewAnimate()) {
PaintThrobber(canvas);
return;
}
if (model_->ShouldTabIconViewAnimate()) {
rendered = true;
PaintThrobber(canvas);
} else {
gfx::ImageSkia favicon = model_->GetFaviconForTabIconView(); gfx::ImageSkia favicon = model_->GetFaviconForTabIconView();
if (!favicon.isNull()) { if (!favicon.isNull()) {
rendered = true;
PaintFavicon(canvas, favicon); PaintFavicon(canvas, favicon);
return;
} }
} }
if (!rendered) PaintFavicon(canvas, DefaultFavicon::GetInstance().icon());
PaintFavicon(canvas, DefaultFavicon::GetInstance().icon());
} }
BEGIN_METADATA(TabIconView, views::MenuButton)
END_METADATA
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
#ifndef CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_ #ifndef CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_
#include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/views/controls/button/menu_button.h" #include "ui/views/controls/button/menu_button.h"
#include "ui/views/metadata/metadata_header_macros.h"
class TabIconViewModel; class TabIconViewModel;
...@@ -18,19 +18,20 @@ class ImageSkia; ...@@ -18,19 +18,20 @@ class ImageSkia;
// A view to display a tab favicon or a throbber. // A view to display a tab favicon or a throbber.
class TabIconView : public views::MenuButton { class TabIconView : public views::MenuButton {
public: public:
TabIconView(TabIconViewModel* model, views::Button::PressedCallback callback); METADATA_HEADER(TabIconView);
TabIconView();
TabIconView(const TabIconView&) = delete;
TabIconView& operator=(const TabIconView&) = delete;
~TabIconView() override; ~TabIconView() override;
void SetModel(TabIconViewModel* model);
// Invoke whenever the tab state changes or the throbber should update. // Invoke whenever the tab state changes or the throbber should update.
void Update(); void Update();
// Set the throbber to the light style (for use on dark backgrounds).
void set_is_light(bool is_light) { is_light_ = is_light; }
private: private:
// views::MenuButton: // views::MenuButton:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
const char* GetClassName() const override;
void PaintButtonContents(gfx::Canvas* canvas) override; void PaintButtonContents(gfx::Canvas* canvas) override;
void PaintThrobber(gfx::Canvas* canvas); void PaintThrobber(gfx::Canvas* canvas);
...@@ -39,14 +40,15 @@ class TabIconView : public views::MenuButton { ...@@ -39,14 +40,15 @@ class TabIconView : public views::MenuButton {
// Our model. // Our model.
TabIconViewModel* model_; TabIconViewModel* model_;
// Whether we should display our light or dark style.
bool is_light_;
// Time we painted the first frame of the current throbber animation, or // Time we painted the first frame of the current throbber animation, or
// 0 if not painting the throbber. // 0 if not painting the throbber.
base::TimeTicks throbber_start_time_; base::TimeTicks throbber_start_time_;
DISALLOW_COPY_AND_ASSIGN(TabIconView);
}; };
BEGIN_VIEW_BUILDER(/* no export */, TabIconView, views::MenuButton)
VIEW_BUILDER_PROPERTY(TabIconViewModel*, Model)
END_VIEW_BUILDER
DEFINE_VIEW_BUILDER(/* no export */, TabIconView)
#endif // CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_ #endif // CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_
...@@ -5,9 +5,10 @@ ...@@ -5,9 +5,10 @@
#ifndef UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ #ifndef UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_
#define UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ #define UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_
#include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/view_factory.h"
namespace views { namespace views {
...@@ -23,10 +24,11 @@ class MenuButtonController; ...@@ -23,10 +24,11 @@ class MenuButtonController;
class VIEWS_EXPORT MenuButton : public LabelButton { class VIEWS_EXPORT MenuButton : public LabelButton {
public: public:
METADATA_HEADER(MenuButton); METADATA_HEADER(MenuButton);
explicit MenuButton(PressedCallback callback = PressedCallback(), explicit MenuButton(PressedCallback callback = PressedCallback(),
const base::string16& text = base::string16(), const base::string16& text = base::string16(),
int button_context = style::CONTEXT_BUTTON); int button_context = style::CONTEXT_BUTTON);
MenuButton(const MenuButton&) = delete;
MenuButton& operator=(const MenuButton&) = delete;
~MenuButton() override; ~MenuButton() override;
MenuButtonController* button_controller() const { MenuButtonController* button_controller() const {
...@@ -41,10 +43,13 @@ class VIEWS_EXPORT MenuButton : public LabelButton { ...@@ -41,10 +43,13 @@ class VIEWS_EXPORT MenuButton : public LabelButton {
private: private:
MenuButtonController* menu_button_controller_; MenuButtonController* menu_button_controller_;
DISALLOW_COPY_AND_ASSIGN(MenuButton);
}; };
BEGIN_VIEW_BUILDER(VIEWS_EXPORT, MenuButton, LabelButton)
END_VIEW_BUILDER
} // namespace views } // namespace views
DEFINE_VIEW_BUILDER(VIEWS_EXPORT, MenuButton)
#endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ #endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_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