Commit e99830ba authored by Brett Wilson's avatar Brett Wilson Committed by Commit Bot

C++11 updates in views toolbar code.

Updates some enums to enum classes, uses class member initializers, add
unique_ptr to more cases.

Change-Id: Iddca37cfba27a1fe7e2d74d73ced4c360769562f
Reviewed-on: https://chromium-review.googlesource.com/822524
Commit-Queue: Brett Wilson <brettw@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523651}
parent 60726a37
...@@ -126,11 +126,6 @@ class StubBubbleModelDelegate : public ContentSettingBubbleModelDelegate { ...@@ -126,11 +126,6 @@ class StubBubbleModelDelegate : public ContentSettingBubbleModelDelegate {
SimpleWebViewDialog::SimpleWebViewDialog(Profile* profile) SimpleWebViewDialog::SimpleWebViewDialog(Profile* profile)
: profile_(profile), : profile_(profile),
back_(NULL),
forward_(NULL),
reload_(NULL),
location_bar_(NULL),
web_view_(NULL),
bubble_model_delegate_(new StubBubbleModelDelegate) { bubble_model_delegate_(new StubBubbleModelDelegate) {
command_updater_.reset(new CommandUpdater(this)); command_updater_.reset(new CommandUpdater(this));
command_updater_->UpdateCommandEnabled(IDC_BACK, true); command_updater_->UpdateCommandEnabled(IDC_BACK, true);
...@@ -143,7 +138,7 @@ SimpleWebViewDialog::SimpleWebViewDialog(Profile* profile) ...@@ -143,7 +138,7 @@ SimpleWebViewDialog::SimpleWebViewDialog(Profile* profile)
SimpleWebViewDialog::~SimpleWebViewDialog() { SimpleWebViewDialog::~SimpleWebViewDialog() {
if (web_view_ && web_view_->web_contents()) if (web_view_ && web_view_->web_contents())
web_view_->web_contents()->SetDelegate(NULL); web_view_->web_contents()->SetDelegate(nullptr);
} }
void SimpleWebViewDialog::StartLoad(const GURL& url) { void SimpleWebViewDialog::StartLoad(const GURL& url) {
...@@ -192,8 +187,8 @@ void SimpleWebViewDialog::Init() { ...@@ -192,8 +187,8 @@ void SimpleWebViewDialog::Init() {
forward_->set_id(VIEW_ID_FORWARD_BUTTON); forward_->set_id(VIEW_ID_FORWARD_BUTTON);
// Location bar. // Location bar.
location_bar_ = location_bar_ = new LocationBarView(nullptr, profile_, command_updater_.get(),
new LocationBarView(NULL, profile_, command_updater_.get(), this, true); this, true);
// Reload button. // Reload button.
reload_ = new ReloadButton(profile_, command_updater_.get()); reload_ = new ReloadButton(profile_, command_updater_.get());
...@@ -260,14 +255,14 @@ content::WebContents* SimpleWebViewDialog::OpenURL( ...@@ -260,14 +255,14 @@ content::WebContents* SimpleWebViewDialog::OpenURL(
const content::OpenURLParams& params) { const content::OpenURLParams& params) {
// As there are no Browsers right now, this could not actually ever work. // As there are no Browsers right now, this could not actually ever work.
NOTIMPLEMENTED(); NOTIMPLEMENTED();
return NULL; return nullptr;
} }
void SimpleWebViewDialog::NavigationStateChanged( void SimpleWebViewDialog::NavigationStateChanged(
WebContents* source, WebContents* source,
content::InvalidateTypes changed_flags) { content::InvalidateTypes changed_flags) {
if (location_bar_) { if (location_bar_) {
location_bar_->Update(NULL); location_bar_->Update(nullptr);
UpdateButtons(); UpdateButtons();
} }
} }
...@@ -280,7 +275,7 @@ void SimpleWebViewDialog::LoadingStateChanged(WebContents* source, ...@@ -280,7 +275,7 @@ void SimpleWebViewDialog::LoadingStateChanged(WebContents* source,
} }
WebContents* SimpleWebViewDialog::GetWebContents() { WebContents* SimpleWebViewDialog::GetWebContents() {
return NULL; return nullptr;
} }
ToolbarModel* SimpleWebViewDialog::GetToolbarModel() { ToolbarModel* SimpleWebViewDialog::GetToolbarModel() {
...@@ -365,7 +360,7 @@ void SimpleWebViewDialog::UpdateButtons() { ...@@ -365,7 +360,7 @@ void SimpleWebViewDialog::UpdateButtons() {
void SimpleWebViewDialog::UpdateReload(bool is_loading, bool force) { void SimpleWebViewDialog::UpdateReload(bool is_loading, bool force) {
if (reload_) { if (reload_) {
reload_->ChangeMode( reload_->ChangeMode(
is_loading ? ReloadButton::MODE_STOP : ReloadButton::MODE_RELOAD, is_loading ? ReloadButton::Mode::kStop : ReloadButton::Mode::kReload,
force); force);
} }
} }
......
...@@ -97,11 +97,11 @@ class SimpleWebViewDialog : public views::ButtonListener, ...@@ -97,11 +97,11 @@ class SimpleWebViewDialog : public views::ButtonListener,
std::unique_ptr<CommandUpdater> command_updater_; std::unique_ptr<CommandUpdater> command_updater_;
// Controls // Controls
views::ImageButton* back_; views::ImageButton* back_ = nullptr;
views::ImageButton* forward_; views::ImageButton* forward_ = nullptr;
ReloadButton* reload_; ReloadButton* reload_ = nullptr;
LocationBarView* location_bar_; LocationBarView* location_bar_ = nullptr;
views::WebView* web_view_; views::WebView* web_view_ = nullptr;
// Contains |web_view_| while it isn't owned by the view. // Contains |web_view_| while it isn't owned by the view.
std::unique_ptr<views::WebView> web_view_container_; std::unique_ptr<views::WebView> web_view_container_;
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
typedef BackForwardMenuModel::ModelType BackForwardMenuType; typedef BackForwardMenuModel::ModelType BackForwardMenuType;
const BackForwardMenuType BACK_FORWARD_MENU_TYPE_BACK = const BackForwardMenuType BACK_FORWARD_MENU_TYPE_BACK =
BackForwardMenuModel::BACKWARD_MENU; BackForwardMenuModel::ModelType::kBackward;
const BackForwardMenuType BACK_FORWARD_MENU_TYPE_FORWARD = const BackForwardMenuType BACK_FORWARD_MENU_TYPE_FORWARD =
BackForwardMenuModel::FORWARD_MENU; BackForwardMenuModel::ModelType::kForward;
// A class that manages the back/forward menu (and delayed-menu button, and // A class that manages the back/forward menu (and delayed-menu button, and
// model). // model).
......
...@@ -42,14 +42,9 @@ static const int kMaxWidth = 700; ...@@ -42,14 +42,9 @@ static const int kMaxWidth = 700;
BackForwardMenuModel::BackForwardMenuModel(Browser* browser, BackForwardMenuModel::BackForwardMenuModel(Browser* browser,
ModelType model_type) ModelType model_type)
: browser_(browser), : browser_(browser), model_type_(model_type) {}
test_web_contents_(NULL),
model_type_(model_type),
menu_model_delegate_(NULL) {
}
BackForwardMenuModel::~BackForwardMenuModel() { BackForwardMenuModel::~BackForwardMenuModel() {}
}
bool BackForwardMenuModel::HasIcons() const { bool BackForwardMenuModel::HasIcons() const {
return true; return true;
...@@ -154,7 +149,7 @@ bool BackForwardMenuModel::GetIconAt(int index, gfx::Image* icon) { ...@@ -154,7 +149,7 @@ bool BackForwardMenuModel::GetIconAt(int index, gfx::Image* icon) {
ui::ButtonMenuItemModel* BackForwardMenuModel::GetButtonMenuItemAt( ui::ButtonMenuItemModel* BackForwardMenuModel::GetButtonMenuItemAt(
int index) const { int index) const {
return NULL; return nullptr;
} }
bool BackForwardMenuModel::IsEnabledAt(int index) const { bool BackForwardMenuModel::IsEnabledAt(int index) const {
...@@ -162,7 +157,7 @@ bool BackForwardMenuModel::IsEnabledAt(int index) const { ...@@ -162,7 +157,7 @@ bool BackForwardMenuModel::IsEnabledAt(int index) const {
} }
ui::MenuModel* BackForwardMenuModel::GetSubmenuModelAt(int index) const { ui::MenuModel* BackForwardMenuModel::GetSubmenuModelAt(int index) const {
return NULL; return nullptr;
} }
void BackForwardMenuModel::HighlightChangedTo(int index) { void BackForwardMenuModel::HighlightChangedTo(int index) {
...@@ -263,7 +258,7 @@ void BackForwardMenuModel::OnFavIconDataAvailable( ...@@ -263,7 +258,7 @@ void BackForwardMenuModel::OnFavIconDataAvailable(
const favicon_base::FaviconImageResult& image_result) { const favicon_base::FaviconImageResult& image_result) {
if (!image_result.image.IsEmpty()) { if (!image_result.image.IsEmpty()) {
// Find the current model_index for the unique id. // Find the current model_index for the unique id.
NavigationEntry* entry = NULL; NavigationEntry* entry = nullptr;
int model_index = -1; int model_index = -1;
for (int i = 0; i < GetItemCount() - 1; i++) { for (int i = 0; i < GetItemCount() - 1; i++) {
if (IsSeparator(i)) if (IsSeparator(i))
...@@ -296,7 +291,7 @@ int BackForwardMenuModel::GetHistoryItemCount() const { ...@@ -296,7 +291,7 @@ int BackForwardMenuModel::GetHistoryItemCount() const {
WebContents* contents = GetWebContents(); WebContents* contents = GetWebContents();
int items = 0; int items = 0;
if (model_type_ == FORWARD_MENU) { if (model_type_ == ModelType::kForward) {
// Only count items from n+1 to end (if n is current entry) // Only count items from n+1 to end (if n is current entry)
items = contents->GetController().GetEntryCount() - items = contents->GetController().GetEntryCount() -
contents->GetController().GetCurrentEntryIndex() - 1; contents->GetController().GetCurrentEntryIndex() - 1;
...@@ -320,15 +315,15 @@ int BackForwardMenuModel::GetChapterStopCount(int history_items) const { ...@@ -320,15 +315,15 @@ int BackForwardMenuModel::GetChapterStopCount(int history_items) const {
if (history_items == kMaxHistoryItems) { if (history_items == kMaxHistoryItems) {
int chapter_id = current_entry; int chapter_id = current_entry;
if (model_type_ == FORWARD_MENU) { if (model_type_ == ModelType::kForward) {
chapter_id += history_items; chapter_id += history_items;
} else { } else {
chapter_id -= history_items; chapter_id -= history_items;
} }
do { do {
chapter_id = GetIndexOfNextChapterStop(chapter_id, chapter_id = GetIndexOfNextChapterStop(
model_type_ == FORWARD_MENU); chapter_id, model_type_ == ModelType::kForward);
if (chapter_id != -1) if (chapter_id != -1)
++chapter_stops; ++chapter_stops;
} while (chapter_id != -1 && chapter_stops < kMaxChapterStops); } while (chapter_id != -1 && chapter_stops < kMaxChapterStops);
...@@ -428,7 +423,7 @@ int BackForwardMenuModel::MenuIndexToNavEntryIndex(int index) const { ...@@ -428,7 +423,7 @@ int BackForwardMenuModel::MenuIndexToNavEntryIndex(int index) const {
// Convert anything above the History items separator. // Convert anything above the History items separator.
if (index < history_items) { if (index < history_items) {
if (model_type_ == FORWARD_MENU) { if (model_type_ == ModelType::kForward) {
index += contents->GetController().GetCurrentEntryIndex() + 1; index += contents->GetController().GetCurrentEntryIndex() + 1;
} else { } else {
// Back menu is reverse. // Back menu is reverse.
...@@ -443,8 +438,7 @@ int BackForwardMenuModel::MenuIndexToNavEntryIndex(int index) const { ...@@ -443,8 +438,7 @@ int BackForwardMenuModel::MenuIndexToNavEntryIndex(int index) const {
return -1; // This is beyond the last chapter stop so we abort. return -1; // This is beyond the last chapter stop so we abort.
// This menu item is a chapter stop located between the two separators. // This menu item is a chapter stop located between the two separators.
index = FindChapterStop(history_items, index = FindChapterStop(history_items, model_type_ == ModelType::kForward,
model_type_ == FORWARD_MENU,
index - history_items - 1); index - history_items - 1);
return index; return index;
...@@ -457,7 +451,7 @@ NavigationEntry* BackForwardMenuModel::GetNavigationEntry(int index) const { ...@@ -457,7 +451,7 @@ NavigationEntry* BackForwardMenuModel::GetNavigationEntry(int index) const {
return controller.GetEntryAtIndex(controller_index); return controller.GetEntryAtIndex(controller_index);
NOTREACHED(); NOTREACHED();
return NULL; return nullptr;
} }
std::string BackForwardMenuModel::BuildActionName( std::string BackForwardMenuModel::BuildActionName(
...@@ -465,7 +459,7 @@ std::string BackForwardMenuModel::BuildActionName( ...@@ -465,7 +459,7 @@ std::string BackForwardMenuModel::BuildActionName(
DCHECK(!action.empty()); DCHECK(!action.empty());
DCHECK_GE(index, -1); DCHECK_GE(index, -1);
std::string metric_string; std::string metric_string;
if (model_type_ == FORWARD_MENU) if (model_type_ == ModelType::kForward)
metric_string += "ForwardMenu_"; metric_string += "ForwardMenu_";
else else
metric_string += "BackMenu_"; metric_string += "BackMenu_";
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
#ifndef CHROME_BROWSER_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_ #ifndef CHROME_BROWSER_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_
#define CHROME_BROWSER_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_ #define CHROME_BROWSER_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_
#include <set>
#include <string> #include <string>
#include "base/containers/flat_set.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
...@@ -42,10 +42,7 @@ class BackForwardMenuModel : public ui::MenuModel { ...@@ -42,10 +42,7 @@ class BackForwardMenuModel : public ui::MenuModel {
public: public:
// These are IDs used to identify individual UI elements within the // These are IDs used to identify individual UI elements within the
// browser window using View::GetViewByID. // browser window using View::GetViewByID.
enum ModelType { enum class ModelType { kForward = 1, kBackward = 2 };
FORWARD_MENU = 1,
BACKWARD_MENU = 2
};
BackForwardMenuModel(Browser* browser, ModelType model_type); BackForwardMenuModel(Browser* browser, ModelType model_type);
~BackForwardMenuModel() override; ~BackForwardMenuModel() override;
...@@ -190,7 +187,7 @@ class BackForwardMenuModel : public ui::MenuModel { ...@@ -190,7 +187,7 @@ class BackForwardMenuModel : public ui::MenuModel {
Browser* const browser_; Browser* const browser_;
// The unit tests will provide their own WebContents to use. // The unit tests will provide their own WebContents to use.
content::WebContents* test_web_contents_; content::WebContents* test_web_contents_ = nullptr;
// Represents whether this is the delegate for the forward button or the // Represents whether this is the delegate for the forward button or the
// back button. // back button.
...@@ -199,13 +196,13 @@ class BackForwardMenuModel : public ui::MenuModel { ...@@ -199,13 +196,13 @@ class BackForwardMenuModel : public ui::MenuModel {
// Keeps track of which favicons have already been requested from the history // Keeps track of which favicons have already been requested from the history
// to prevent duplicate requests, identified by // to prevent duplicate requests, identified by
// NavigationEntry->GetUniqueID(). // NavigationEntry->GetUniqueID().
std::set<int> requested_favicons_; base::flat_set<int> requested_favicons_;
// Used for loading favicons. // Used for loading favicons.
base::CancelableTaskTracker cancelable_task_tracker_; base::CancelableTaskTracker cancelable_task_tracker_;
// Used for receiving notifications when an icon is changed. // Used for receiving notifications when an icon is changed.
ui::MenuModelDelegate* menu_model_delegate_; ui::MenuModelDelegate* menu_model_delegate_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(BackForwardMenuModel); DISALLOW_COPY_AND_ASSIGN(BackForwardMenuModel);
}; };
......
...@@ -100,12 +100,12 @@ class BackFwdMenuModelTest : public ChromeRenderViewHostTestHarness { ...@@ -100,12 +100,12 @@ class BackFwdMenuModelTest : public ChromeRenderViewHostTestHarness {
}; };
TEST_F(BackFwdMenuModelTest, BasicCase) { TEST_F(BackFwdMenuModelTest, BasicCase) {
std::unique_ptr<BackForwardMenuModel> back_model( std::unique_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel(
new BackForwardMenuModel(NULL, BackForwardMenuModel::BACKWARD_MENU)); nullptr, BackForwardMenuModel::ModelType::kBackward));
back_model->set_test_web_contents(web_contents()); back_model->set_test_web_contents(web_contents());
std::unique_ptr<BackForwardMenuModel> forward_model( std::unique_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel(
new BackForwardMenuModel(NULL, BackForwardMenuModel::FORWARD_MENU)); nullptr, BackForwardMenuModel::ModelType::kForward));
forward_model->set_test_web_contents(web_contents()); forward_model->set_test_web_contents(web_contents());
EXPECT_EQ(0, back_model->GetItemCount()); EXPECT_EQ(0, back_model->GetItemCount());
...@@ -168,12 +168,12 @@ TEST_F(BackFwdMenuModelTest, BasicCase) { ...@@ -168,12 +168,12 @@ TEST_F(BackFwdMenuModelTest, BasicCase) {
} }
TEST_F(BackFwdMenuModelTest, MaxItemsTest) { TEST_F(BackFwdMenuModelTest, MaxItemsTest) {
std::unique_ptr<BackForwardMenuModel> back_model( std::unique_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel(
new BackForwardMenuModel(NULL, BackForwardMenuModel::BACKWARD_MENU)); nullptr, BackForwardMenuModel::ModelType::kBackward));
back_model->set_test_web_contents(web_contents()); back_model->set_test_web_contents(web_contents());
std::unique_ptr<BackForwardMenuModel> forward_model( std::unique_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel(
new BackForwardMenuModel(NULL, BackForwardMenuModel::FORWARD_MENU)); nullptr, BackForwardMenuModel::ModelType::kForward));
forward_model->set_test_web_contents(web_contents()); forward_model->set_test_web_contents(web_contents());
// Seed the controller with 32 URLs // Seed the controller with 32 URLs
...@@ -250,12 +250,12 @@ TEST_F(BackFwdMenuModelTest, MaxItemsTest) { ...@@ -250,12 +250,12 @@ TEST_F(BackFwdMenuModelTest, MaxItemsTest) {
} }
TEST_F(BackFwdMenuModelTest, ChapterStops) { TEST_F(BackFwdMenuModelTest, ChapterStops) {
std::unique_ptr<BackForwardMenuModel> back_model( std::unique_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel(
new BackForwardMenuModel(NULL, BackForwardMenuModel::BACKWARD_MENU)); nullptr, BackForwardMenuModel::ModelType::kBackward));
back_model->set_test_web_contents(web_contents()); back_model->set_test_web_contents(web_contents());
std::unique_ptr<BackForwardMenuModel> forward_model( std::unique_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel(
new BackForwardMenuModel(NULL, BackForwardMenuModel::FORWARD_MENU)); nullptr, BackForwardMenuModel::ModelType::kForward));
forward_model->set_test_web_contents(web_contents()); forward_model->set_test_web_contents(web_contents());
// Seed the controller with 32 URLs. // Seed the controller with 32 URLs.
...@@ -461,8 +461,8 @@ TEST_F(BackFwdMenuModelTest, ChapterStops) { ...@@ -461,8 +461,8 @@ TEST_F(BackFwdMenuModelTest, ChapterStops) {
} }
TEST_F(BackFwdMenuModelTest, EscapeLabel) { TEST_F(BackFwdMenuModelTest, EscapeLabel) {
std::unique_ptr<BackForwardMenuModel> back_model( std::unique_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel(
new BackForwardMenuModel(NULL, BackForwardMenuModel::BACKWARD_MENU)); nullptr, BackForwardMenuModel::ModelType::kBackward));
back_model->set_test_web_contents(web_contents()); back_model->set_test_web_contents(web_contents());
EXPECT_EQ(0, back_model->GetItemCount()); EXPECT_EQ(0, back_model->GetItemCount());
...@@ -499,8 +499,8 @@ TEST_F(BackFwdMenuModelTest, FaviconLoadTest) { ...@@ -499,8 +499,8 @@ TEST_F(BackFwdMenuModelTest, FaviconLoadTest) {
CreateBrowserWithTestWindowForParams(&native_params)); CreateBrowserWithTestWindowForParams(&native_params));
FaviconDelegate favicon_delegate; FaviconDelegate favicon_delegate;
BackForwardMenuModel back_model( BackForwardMenuModel back_model(browser.get(),
browser.get(), BackForwardMenuModel::BACKWARD_MENU); BackForwardMenuModel::ModelType::kBackward);
back_model.set_test_web_contents(controller().GetWebContents()); back_model.set_test_web_contents(controller().GetWebContents());
back_model.SetMenuModelDelegate(&favicon_delegate); back_model.SetMenuModelDelegate(&favicon_delegate);
......
...@@ -1003,7 +1003,7 @@ void BrowserView::SetFocusToLocationBar(bool select_all) { ...@@ -1003,7 +1003,7 @@ void BrowserView::SetFocusToLocationBar(bool select_all) {
void BrowserView::UpdateReloadStopState(bool is_loading, bool force) { void BrowserView::UpdateReloadStopState(bool is_loading, bool force) {
if (toolbar_->reload_button()) { if (toolbar_->reload_button()) {
toolbar_->reload_button()->ChangeMode( toolbar_->reload_button()->ChangeMode(
is_loading ? ReloadButton::MODE_STOP : ReloadButton::MODE_RELOAD, is_loading ? ReloadButton::Mode::kStop : ReloadButton::Mode::kReload,
force); force);
} }
} }
......
...@@ -341,9 +341,8 @@ class AppMenuView : public views::View, ...@@ -341,9 +341,8 @@ class AppMenuView : public views::View,
// Should only be invoked during construction when |menu_| is valid. // Should only be invoked during construction when |menu_| is valid.
DCHECK(menu_); DCHECK(menu_);
InMenuButton* button = new InMenuButton( InMenuButton* button = new InMenuButton(
this, this, gfx::RemoveAcceleratorChar(l10n_util::GetStringUTF16(string_id),
gfx::RemoveAcceleratorChar( '&', nullptr, nullptr));
l10n_util::GetStringUTF16(string_id), '&', NULL, NULL));
button->Init(type); button->Init(type);
button->SetAccessibleName(GetAccessibleNameForAppMenuItem( button->SetAccessibleName(GetAccessibleNameForAppMenuItem(
menu_model_, index, acc_string_id, !role_is_button)); menu_model_, index, acc_string_id, !role_is_button));
...@@ -361,8 +360,8 @@ class AppMenuView : public views::View, ...@@ -361,8 +360,8 @@ class AppMenuView : public views::View,
// Overridden from AppMenuObserver: // Overridden from AppMenuObserver:
void AppMenuDestroyed() override { void AppMenuDestroyed() override {
menu_->RemoveObserver(this); menu_->RemoveObserver(this);
menu_ = NULL; menu_ = nullptr;
menu_model_ = NULL; menu_model_ = nullptr;
} }
protected: protected:
...@@ -372,11 +371,11 @@ class AppMenuView : public views::View, ...@@ -372,11 +371,11 @@ class AppMenuView : public views::View,
private: private:
// Hosting AppMenu. // Hosting AppMenu.
// WARNING: this may be NULL during shutdown. // WARNING: this may be nullptr during shutdown.
AppMenu* menu_; AppMenu* menu_;
// The menu model containing the increment/decrement/reset items. // The menu model containing the increment/decrement/reset items.
// WARNING: this may be NULL during shutdown. // WARNING: this may be nullptr during shutdown.
ButtonMenuItemModel* menu_model_; ButtonMenuItemModel* menu_model_;
DISALLOW_COPY_AND_ASSIGN(AppMenuView); DISALLOW_COPY_AND_ASSIGN(AppMenuView);
...@@ -482,10 +481,10 @@ class AppMenu::ZoomView : public AppMenuView { ...@@ -482,10 +481,10 @@ class AppMenu::ZoomView : public AppMenuView {
int fullscreen_index) int fullscreen_index)
: AppMenuView(menu, menu_model), : AppMenuView(menu, menu_model),
fullscreen_index_(fullscreen_index), fullscreen_index_(fullscreen_index),
increment_button_(NULL), increment_button_(nullptr),
zoom_label_(NULL), zoom_label_(nullptr),
decrement_button_(NULL), decrement_button_(nullptr),
fullscreen_button_(NULL), fullscreen_button_(nullptr),
zoom_label_max_width_(0), zoom_label_max_width_(0),
zoom_label_max_width_valid_(false) { zoom_label_max_width_valid_(false) {
browser_zoom_subscription_ = browser_zoom_subscription_ =
...@@ -534,7 +533,7 @@ class AppMenu::ZoomView : public AppMenuView { ...@@ -534,7 +533,7 @@ class AppMenu::ZoomView : public AppMenuView {
AddChildView(fullscreen_button_); AddChildView(fullscreen_button_);
// Need to set a font list for the zoom label width calculations. // Need to set a font list for the zoom label width calculations.
OnNativeThemeChanged(NULL); OnNativeThemeChanged(nullptr);
UpdateZoomControls(); UpdateZoomControls();
} }
...@@ -723,7 +722,7 @@ class AppMenu::RecentTabsMenuModelDelegate : public ui::MenuModelDelegate { ...@@ -723,7 +722,7 @@ class AppMenu::RecentTabsMenuModelDelegate : public ui::MenuModelDelegate {
} }
~RecentTabsMenuModelDelegate() override { ~RecentTabsMenuModelDelegate() override {
model_->SetMenuModelDelegate(NULL); model_->SetMenuModelDelegate(nullptr);
} }
const gfx::FontList* GetLabelFontListAt(int index) const { const gfx::FontList* GetLabelFontListAt(int index) const {
...@@ -781,15 +780,7 @@ class AppMenu::RecentTabsMenuModelDelegate : public ui::MenuModelDelegate { ...@@ -781,15 +780,7 @@ class AppMenu::RecentTabsMenuModelDelegate : public ui::MenuModelDelegate {
// AppMenu ------------------------------------------------------------------ // AppMenu ------------------------------------------------------------------
AppMenu::AppMenu(Browser* browser, int run_flags) AppMenu::AppMenu(Browser* browser, int run_flags)
: root_(nullptr), : browser_(browser), run_flags_(run_flags) {
browser_(browser),
selected_menu_model_(nullptr),
selected_index_(0),
bookmark_menu_(nullptr),
feedback_menu_item_(nullptr),
screenshot_menu_item_(nullptr),
extension_toolbar_(nullptr),
run_flags_(run_flags) {
registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
content::Source<Profile>(browser_->profile())); content::Source<Profile>(browser_->profile()));
} }
...@@ -853,7 +844,7 @@ const gfx::FontList* AppMenu::GetLabelFontList(int command_id) const { ...@@ -853,7 +844,7 @@ const gfx::FontList* AppMenu::GetLabelFontList(int command_id) const {
return recent_tabs_menu_model_delegate_->GetLabelFontListAt( return recent_tabs_menu_model_delegate_->GetLabelFontListAt(
ModelIndexFromCommandId(command_id)); ModelIndexFromCommandId(command_id));
} }
return NULL; return nullptr;
} }
bool AppMenu::GetShouldUseNormalForegroundColor(int command_id) const { bool AppMenu::GetShouldUseNormalForegroundColor(int command_id) const {
......
...@@ -151,7 +151,7 @@ class AppMenu : public views::MenuDelegate, ...@@ -151,7 +151,7 @@ class AppMenu : public views::MenuDelegate,
int ModelIndexFromCommandId(int command_id) const; int ModelIndexFromCommandId(int command_id) const;
// The views menu. Owned by |menu_runner_|. // The views menu. Owned by |menu_runner_|.
views::MenuItemView* root_; views::MenuItemView* root_ = nullptr;
std::unique_ptr<views::MenuRunner> menu_runner_; std::unique_ptr<views::MenuRunner> menu_runner_;
...@@ -166,24 +166,24 @@ class AppMenu : public views::MenuDelegate, ...@@ -166,24 +166,24 @@ class AppMenu : public views::MenuDelegate,
// If |selected_menu_model_| is non-null after the menu completes // If |selected_menu_model_| is non-null after the menu completes
// ActivatedAt is invoked. This is done so that ActivatedAt isn't invoked // ActivatedAt is invoked. This is done so that ActivatedAt isn't invoked
// while the message loop is nested. // while the message loop is nested.
ui::ButtonMenuItemModel* selected_menu_model_; ui::ButtonMenuItemModel* selected_menu_model_ = nullptr;
int selected_index_; int selected_index_ = 0;
// Used for managing the bookmark menu items. // Used for managing the bookmark menu items.
std::unique_ptr<BookmarkMenuDelegate> bookmark_menu_delegate_; std::unique_ptr<BookmarkMenuDelegate> bookmark_menu_delegate_;
// Menu corresponding to IDC_BOOKMARKS_MENU. // Menu corresponding to IDC_BOOKMARKS_MENU.
views::MenuItemView* bookmark_menu_; views::MenuItemView* bookmark_menu_ = nullptr;
// Menu corresponding to IDC_FEEDBACK. // Menu corresponding to IDC_FEEDBACK.
views::MenuItemView* feedback_menu_item_; views::MenuItemView* feedback_menu_item_ = nullptr;
// Menu corresponding to IDC_TAKE_SCREENSHOT. // Menu corresponding to IDC_TAKE_SCREENSHOT.
views::MenuItemView* screenshot_menu_item_; views::MenuItemView* screenshot_menu_item_ = nullptr;
// The view within the IDC_EXTENSIONS_OVERFLOW_MENU item (only present with // The view within the IDC_EXTENSIONS_OVERFLOW_MENU item (only present with
// the toolbar action redesign enabled). // the toolbar action redesign enabled).
ExtensionToolbarMenuView* extension_toolbar_; ExtensionToolbarMenuView* extension_toolbar_ = nullptr;
// Used for managing "Recent tabs" menu items. // Used for managing "Recent tabs" menu items.
std::unique_ptr<RecentTabsMenuModelDelegate> recent_tabs_menu_model_delegate_; std::unique_ptr<RecentTabsMenuModelDelegate> recent_tabs_menu_model_delegate_;
......
...@@ -75,16 +75,10 @@ BrowserActionsContainer::BrowserActionsContainer( ...@@ -75,16 +75,10 @@ BrowserActionsContainer::BrowserActionsContainer(
: toolbar_actions_bar_(new ToolbarActionsBar( : toolbar_actions_bar_(new ToolbarActionsBar(
this, this,
browser, browser,
main_container ? main_container ? main_container->toolbar_actions_bar_.get()
main_container->toolbar_actions_bar_.get() : nullptr)), : nullptr)),
browser_(browser), browser_(browser),
main_container_(main_container), main_container_(main_container) {
resize_area_(NULL),
added_to_view_(false),
resize_starting_width_(-1),
resize_amount_(0),
animation_target_size_(0),
active_bubble_(nullptr) {
set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR);
if (!ShownInsideMenu()) { if (!ShownInsideMenu()) {
......
...@@ -250,7 +250,7 @@ class BrowserActionsContainer : public views::View, ...@@ -250,7 +250,7 @@ class BrowserActionsContainer : public views::View,
BrowserActionsContainer* main_container_; BrowserActionsContainer* main_container_;
// The resize area for the container. // The resize area for the container.
views::ResizeArea* resize_area_; views::ResizeArea* resize_area_ = nullptr;
// The painter used when we are highlighting a subset of extensions. // The painter used when we are highlighting a subset of extensions.
std::unique_ptr<views::Painter> warning_highlight_painter_; std::unique_ptr<views::Painter> warning_highlight_painter_;
...@@ -259,27 +259,27 @@ class BrowserActionsContainer : public views::View, ...@@ -259,27 +259,27 @@ class BrowserActionsContainer : public views::View,
std::unique_ptr<gfx::SlideAnimation> resize_animation_; std::unique_ptr<gfx::SlideAnimation> resize_animation_;
// True if the container has been added to the parent view. // True if the container has been added to the parent view.
bool added_to_view_; bool added_to_view_ = false;
// When the container is resizing, this is the width at which it started. // When the container is resizing, this is the width at which it started.
// If the container is not resizing, -1. // If the container is not resizing, -1.
int resize_starting_width_; int resize_starting_width_ = -1;
// This is used while the user is resizing (and when the animations are in // This is used while the user is resizing (and when the animations are in
// progress) to know how wide the delta is between the current state and what // progress) to know how wide the delta is between the current state and what
// we should draw. // we should draw.
int resize_amount_; int resize_amount_ = 0;
// Keeps track of the absolute pixel width the container should have when we // Keeps track of the absolute pixel width the container should have when we
// are done animating. // are done animating.
int animation_target_size_; int animation_target_size_ = 0;
// The DropPosition for the current drag-and-drop operation, or NULL if there // The DropPosition for the current drag-and-drop operation, or NULL if there
// is none. // is none.
std::unique_ptr<DropPosition> drop_position_; std::unique_ptr<DropPosition> drop_position_;
// The extension bubble that is actively showing, if any. // The extension bubble that is actively showing, if any.
views::BubbleDialogDelegateView* active_bubble_; views::BubbleDialogDelegateView* active_bubble_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer);
}; };
......
...@@ -31,8 +31,6 @@ ExtensionToolbarMenuView::ExtensionToolbarMenuView( ...@@ -31,8 +31,6 @@ ExtensionToolbarMenuView::ExtensionToolbarMenuView(
: browser_(browser), : browser_(browser),
app_menu_(app_menu), app_menu_(app_menu),
menu_item_(menu_item), menu_item_(menu_item),
container_(nullptr),
max_height_(0),
toolbar_actions_bar_observer_(this), toolbar_actions_bar_observer_(this),
weak_factory_(this) { weak_factory_(this) {
// Use a transparent background so that the menu's background shows through. // Use a transparent background so that the menu's background shows through.
......
...@@ -71,10 +71,10 @@ class ExtensionToolbarMenuView : public views::ScrollView, ...@@ -71,10 +71,10 @@ class ExtensionToolbarMenuView : public views::ScrollView,
views::MenuItemView* menu_item_; views::MenuItemView* menu_item_;
// The overflow BrowserActionsContainer which is nested in this view. // The overflow BrowserActionsContainer which is nested in this view.
BrowserActionsContainer* container_; BrowserActionsContainer* container_ = nullptr;
// The maximum allowed height for the view. // The maximum allowed height for the view.
int max_height_; int max_height_ = 0;
ScopedObserver<ToolbarActionsBar, ToolbarActionsBarObserver> ScopedObserver<ToolbarActionsBar, ToolbarActionsBarObserver>
toolbar_actions_bar_observer_; toolbar_actions_bar_observer_;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h" #include "components/user_prefs/user_prefs.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/menu_model.h"
#include "ui/views/bubble/bubble_dialog_delegate.h" #include "ui/views/bubble/bubble_dialog_delegate.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
#include "ui/views/controls/styled_label_listener.h" #include "ui/views/controls/styled_label_listener.h"
...@@ -60,7 +61,7 @@ class HomePageUndoBubble : public views::BubbleDialogDelegateView, ...@@ -60,7 +61,7 @@ class HomePageUndoBubble : public views::BubbleDialogDelegateView,
}; };
// static // static
HomePageUndoBubble* HomePageUndoBubble::home_page_undo_bubble_ = NULL; HomePageUndoBubble* HomePageUndoBubble::home_page_undo_bubble_ = nullptr;
void HomePageUndoBubble::ShowBubble(Browser* browser, void HomePageUndoBubble::ShowBubble(Browser* browser,
bool undo_value_is_ntp, bool undo_value_is_ntp,
...@@ -138,7 +139,7 @@ void HomePageUndoBubble::WindowClosing() { ...@@ -138,7 +139,7 @@ void HomePageUndoBubble::WindowClosing() {
// window is hidden but not destroyed, GetWidget()->Close() would be // window is hidden but not destroyed, GetWidget()->Close() would be
// called twice. // called twice.
DCHECK_EQ(this, home_page_undo_bubble_); DCHECK_EQ(this, home_page_undo_bubble_);
home_page_undo_bubble_ = NULL; home_page_undo_bubble_ = nullptr;
} }
} // namespace } // namespace
......
...@@ -41,14 +41,9 @@ const char ReloadButton::kViewClassName[] = "ReloadButton"; ...@@ -41,14 +41,9 @@ const char ReloadButton::kViewClassName[] = "ReloadButton";
ReloadButton::ReloadButton(Profile* profile, CommandUpdater* command_updater) ReloadButton::ReloadButton(Profile* profile, CommandUpdater* command_updater)
: ToolbarButton(profile, this, CreateMenuModel()), : ToolbarButton(profile, this, CreateMenuModel()),
command_updater_(command_updater), command_updater_(command_updater),
intended_mode_(MODE_RELOAD),
visible_mode_(MODE_RELOAD),
double_click_timer_delay_( double_click_timer_delay_(
base::TimeDelta::FromMilliseconds(views::GetDoubleClickInterval())), base::TimeDelta::FromMilliseconds(views::GetDoubleClickInterval())),
mode_switch_timer_delay_(base::TimeDelta::FromMilliseconds(1350)), mode_switch_timer_delay_(base::TimeDelta::FromMilliseconds(1350)) {}
menu_enabled_(false),
testing_mouse_hovered_(false),
testing_reload_count_(0) {}
ReloadButton::~ReloadButton() {} ReloadButton::~ReloadButton() {}
...@@ -59,8 +54,8 @@ void ReloadButton::ChangeMode(Mode mode, bool force) { ...@@ -59,8 +54,8 @@ void ReloadButton::ChangeMode(Mode mode, bool force) {
// safe to change it to the other image type, make the change immediately; // safe to change it to the other image type, make the change immediately;
// otherwise we'll let it happen later. // otherwise we'll let it happen later.
if (force || (!IsMouseHovered() && !testing_mouse_hovered_) || if (force || (!IsMouseHovered() && !testing_mouse_hovered_) ||
((mode == MODE_STOP) ? !double_click_timer_.IsRunning() ((mode == Mode::kStop) ? !double_click_timer_.IsRunning()
: (visible_mode_ != MODE_STOP))) { : (visible_mode_ != Mode::kStop))) {
double_click_timer_.Stop(); double_click_timer_.Stop();
mode_switch_timer_.Stop(); mode_switch_timer_.Stop();
if (mode != visible_mode_) if (mode != visible_mode_)
...@@ -72,7 +67,7 @@ void ReloadButton::ChangeMode(Mode mode, bool force) { ...@@ -72,7 +67,7 @@ void ReloadButton::ChangeMode(Mode mode, bool force) {
// reload to stop due to the double-click timer running. (Disabled reload // reload to stop due to the double-click timer running. (Disabled reload
// state is only applicable when instant extended API is enabled and mode // state is only applicable when instant extended API is enabled and mode
// is NTP, which is handled just above.) // is NTP, which is handled just above.)
} else if (visible_mode_ != MODE_RELOAD) { } else if (visible_mode_ != Mode::kReload) {
SetEnabled(false); SetEnabled(false);
// Go ahead and change to reload after a bit, which allows repeated // Go ahead and change to reload after a bit, which allows repeated
...@@ -101,8 +96,8 @@ bool ReloadButton::GetTooltipText(const gfx::Point& p, ...@@ -101,8 +96,8 @@ bool ReloadButton::GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const { base::string16* tooltip) const {
int reload_tooltip = menu_enabled_ ? int reload_tooltip = menu_enabled_ ?
IDS_TOOLTIP_RELOAD_WITH_MENU : IDS_TOOLTIP_RELOAD; IDS_TOOLTIP_RELOAD_WITH_MENU : IDS_TOOLTIP_RELOAD;
int text_id = (visible_mode_ == MODE_RELOAD) ? int text_id =
reload_tooltip : IDS_TOOLTIP_STOP; (visible_mode_ == Mode::kReload) ? reload_tooltip : IDS_TOOLTIP_STOP;
tooltip->assign(l10n_util::GetStringUTF16(text_id)); tooltip->assign(l10n_util::GetStringUTF16(text_id));
return true; return true;
} }
...@@ -119,7 +114,7 @@ void ReloadButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -119,7 +114,7 @@ void ReloadButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
} }
bool ReloadButton::ShouldShowMenu() { bool ReloadButton::ShouldShowMenu() {
return menu_enabled_ && (visible_mode_ == MODE_RELOAD); return menu_enabled_ && (visible_mode_ == Mode::kReload);
} }
void ReloadButton::ShowDropDownMenu(ui::MenuSourceType source_type) { void ReloadButton::ShowDropDownMenu(ui::MenuSourceType source_type) {
...@@ -131,13 +126,13 @@ void ReloadButton::ButtonPressed(views::Button* /* button */, ...@@ -131,13 +126,13 @@ void ReloadButton::ButtonPressed(views::Button* /* button */,
const ui::Event& event) { const ui::Event& event) {
ClearPendingMenu(); ClearPendingMenu();
if (visible_mode_ == MODE_STOP) { if (visible_mode_ == Mode::kStop) {
if (command_updater_) if (command_updater_)
command_updater_->ExecuteCommandWithDisposition( command_updater_->ExecuteCommandWithDisposition(
IDC_STOP, WindowOpenDisposition::CURRENT_TAB); IDC_STOP, WindowOpenDisposition::CURRENT_TAB);
// The user has clicked, so we can feel free to update the button, even if // The user has clicked, so we can feel free to update the button, even if
// the mouse is still hovering. // the mouse is still hovering.
ChangeMode(MODE_RELOAD, true); ChangeMode(Mode::kReload, true);
return; return;
} }
...@@ -155,7 +150,7 @@ void ReloadButton::ButtonPressed(views::Button* /* button */, ...@@ -155,7 +150,7 @@ void ReloadButton::ButtonPressed(views::Button* /* button */,
} }
// Start a timer - while this timer is running, the reload button cannot be // Start a timer - while this timer is running, the reload button cannot be
// changed to a stop button. We do not set |intended_mode_| to MODE_STOP // changed to a stop button. We do not set |intended_mode_| to Mode::kStop
// here as the browser will do that when it actually starts loading (which // here as the browser will do that when it actually starts loading (which
// may happen synchronously, thus the need to do this before telling the // may happen synchronously, thus the need to do this before telling the
// browser to execute the reload command). // browser to execute the reload command).
...@@ -211,11 +206,10 @@ void ReloadButton::ExecuteCommand(int command_id, int event_flags) { ...@@ -211,11 +206,10 @@ void ReloadButton::ExecuteCommand(int command_id, int event_flags) {
ExecuteBrowserCommand(browser_command, event_flags); ExecuteBrowserCommand(browser_command, event_flags);
} }
ui::SimpleMenuModel* ReloadButton::CreateMenuModel() { std::unique_ptr<ui::SimpleMenuModel> ReloadButton::CreateMenuModel() {
ui::SimpleMenuModel* menu_model = new ui::SimpleMenuModel(this); auto menu_model = std::make_unique<ui::SimpleMenuModel>(this);
for (size_t i = 0; i < arraysize(kReloadMenuItems); ++i) for (size_t i = 0; i < arraysize(kReloadMenuItems); ++i)
menu_model->AddItemWithStringId(kReloadMenuItems[i], kReloadMenuItems[i]); menu_model->AddItemWithStringId(kReloadMenuItems[i], kReloadMenuItems[i]);
return menu_model; return menu_model;
} }
...@@ -231,7 +225,7 @@ void ReloadButton::ChangeModeInternal(Mode mode) { ...@@ -231,7 +225,7 @@ void ReloadButton::ChangeModeInternal(Mode mode) {
// |tp| can be NULL in unit tests. // |tp| can be NULL in unit tests.
if (tp) { if (tp) {
const gfx::VectorIcon& icon = const gfx::VectorIcon& icon =
(mode == MODE_RELOAD) ? vector_icons::kReloadIcon : kNavigateStopIcon; (mode == Mode::kReload) ? vector_icons::kReloadIcon : kNavigateStopIcon;
const SkColor normal_color = const SkColor normal_color =
tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
const SkColor disabled_color = const SkColor disabled_color =
......
...@@ -27,7 +27,7 @@ class ReloadButton : public ToolbarButton, ...@@ -27,7 +27,7 @@ class ReloadButton : public ToolbarButton,
public views::ButtonListener, public views::ButtonListener,
public ui::SimpleMenuModel::Delegate { public ui::SimpleMenuModel::Delegate {
public: public:
enum Mode { MODE_RELOAD = 0, MODE_STOP }; enum class Mode { kReload = 0, kStop };
// The button's class name. // The button's class name.
static const char kViewClassName[]; static const char kViewClassName[];
...@@ -68,7 +68,7 @@ class ReloadButton : public ToolbarButton, ...@@ -68,7 +68,7 @@ class ReloadButton : public ToolbarButton,
private: private:
friend class ReloadButtonTest; friend class ReloadButtonTest;
ui::SimpleMenuModel* CreateMenuModel(); std::unique_ptr<ui::SimpleMenuModel> CreateMenuModel();
void ExecuteBrowserCommand(int command, int event_flags); void ExecuteBrowserCommand(int command, int event_flags);
void ChangeModeInternal(Mode mode); void ChangeModeInternal(Mode mode);
...@@ -86,10 +86,10 @@ class ReloadButton : public ToolbarButton, ...@@ -86,10 +86,10 @@ class ReloadButton : public ToolbarButton,
CommandUpdater* command_updater_; CommandUpdater* command_updater_;
// The mode we should be in assuming no timers are running. // The mode we should be in assuming no timers are running.
Mode intended_mode_; Mode intended_mode_ = Mode::kReload;
// The currently-visible mode - this may differ from the intended mode. // The currently-visible mode - this may differ from the intended mode.
Mode visible_mode_; Mode visible_mode_ = Mode::kReload;
// The delay times for the timers. These are members so that tests can modify // The delay times for the timers. These are members so that tests can modify
// them. // them.
...@@ -97,14 +97,14 @@ class ReloadButton : public ToolbarButton, ...@@ -97,14 +97,14 @@ class ReloadButton : public ToolbarButton,
base::TimeDelta mode_switch_timer_delay_; base::TimeDelta mode_switch_timer_delay_;
// Indicates if reload menu is enabled. // Indicates if reload menu is enabled.
bool menu_enabled_; bool menu_enabled_ = false;
// TESTING ONLY // TESTING ONLY
// True if we should pretend the button is hovered. // True if we should pretend the button is hovered.
bool testing_mouse_hovered_; bool testing_mouse_hovered_ = false;
// Increments when we would tell the browser to "reload", so // Increments when we would tell the browser to "reload", so
// test code can tell whether we did so (as there may be no |browser_|). // test code can tell whether we did so (as there may be no |browser_|).
int testing_reload_count_; int testing_reload_count_ = 0;
DISALLOW_COPY_AND_ASSIGN(ReloadButton); DISALLOW_COPY_AND_ASSIGN(ReloadButton);
}; };
......
...@@ -60,26 +60,26 @@ void ReloadButtonTest::CheckState(bool enabled, ...@@ -60,26 +60,26 @@ void ReloadButtonTest::CheckState(bool enabled,
TEST_F(ReloadButtonTest, Basic) { TEST_F(ReloadButtonTest, Basic) {
// The stop/reload button starts in the "enabled reload" state with no timers // The stop/reload button starts in the "enabled reload" state with no timers
// running. // running.
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, CheckState(true, ReloadButton::Mode::kReload, ReloadButton::Mode::kReload,
false); false, false);
// Press the button. This should start the double-click timer. // Press the button. This should start the double-click timer.
ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
reload()->ButtonPressed(reload(), e); reload()->ButtonPressed(reload(), e);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, CheckState(true, ReloadButton::Mode::kReload, ReloadButton::Mode::kReload,
false); true, false);
// Now change the mode (as if the browser had started loading the page). This // Now change the mode (as if the browser had started loading the page). This
// should cancel the double-click timer since the button is not hovered. // should cancel the double-click timer since the button is not hovered.
reload()->ChangeMode(ReloadButton::MODE_STOP, false); reload()->ChangeMode(ReloadButton::Mode::kStop, false);
CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, CheckState(true, ReloadButton::Mode::kStop, ReloadButton::Mode::kStop, false,
false); false);
// Press the button again. This should change back to reload. // Press the button again. This should change back to reload.
reload()->ButtonPressed(reload(), e); reload()->ButtonPressed(reload(), e);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, CheckState(true, ReloadButton::Mode::kReload, ReloadButton::Mode::kReload,
false); false, false);
} }
TEST_F(ReloadButtonTest, DoubleClickTimer) { TEST_F(ReloadButtonTest, DoubleClickTimer) {
...@@ -92,20 +92,20 @@ TEST_F(ReloadButtonTest, DoubleClickTimer) { ...@@ -92,20 +92,20 @@ TEST_F(ReloadButtonTest, DoubleClickTimer) {
// running. // running.
int original_reload_count = reload_count(); int original_reload_count = reload_count();
reload()->ButtonPressed(reload(), e); reload()->ButtonPressed(reload(), e);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, CheckState(true, ReloadButton::Mode::kReload, ReloadButton::Mode::kReload,
false); true, false);
EXPECT_EQ(original_reload_count, reload_count()); EXPECT_EQ(original_reload_count, reload_count());
// Hover the button, and change mode. The visible mode should not change, // Hover the button, and change mode. The visible mode should not change,
// again because the timer is running. // again because the timer is running.
set_mouse_hovered(true); set_mouse_hovered(true);
reload()->ChangeMode(ReloadButton::MODE_STOP, false); reload()->ChangeMode(ReloadButton::Mode::kStop, false);
CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_RELOAD, true, CheckState(true, ReloadButton::Mode::kStop, ReloadButton::Mode::kReload, true,
false); false);
// Now fire the timer. This should complete the mode change. // Now fire the timer. This should complete the mode change.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, CheckState(true, ReloadButton::Mode::kStop, ReloadButton::Mode::kStop, false,
false); false);
} }
...@@ -114,22 +114,22 @@ TEST_F(ReloadButtonTest, DisableOnHover) { ...@@ -114,22 +114,22 @@ TEST_F(ReloadButtonTest, DisableOnHover) {
ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
reload()->ButtonPressed(reload(), e); reload()->ButtonPressed(reload(), e);
reload()->ChangeMode(ReloadButton::MODE_STOP, false); reload()->ChangeMode(ReloadButton::Mode::kStop, false);
set_mouse_hovered(true); set_mouse_hovered(true);
// Now change back to reload. This should result in a disabled stop button // Now change back to reload. This should result in a disabled stop button
// due to the hover. // due to the hover.
reload()->ChangeMode(ReloadButton::MODE_RELOAD, false); reload()->ChangeMode(ReloadButton::Mode::kReload, false);
CheckState(false, ReloadButton::MODE_RELOAD, ReloadButton::MODE_STOP, false, CheckState(false, ReloadButton::Mode::kReload, ReloadButton::Mode::kStop,
true); false, true);
// Un-hover the button, which should allow it to reset. // Un-hover the button, which should allow it to reset.
set_mouse_hovered(false); set_mouse_hovered(false);
ui::MouseEvent e2(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::MouseEvent e2(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
reload()->OnMouseExited(e2); reload()->OnMouseExited(e2);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, CheckState(true, ReloadButton::Mode::kReload, ReloadButton::Mode::kReload,
false); false, false);
} }
TEST_F(ReloadButtonTest, ResetOnClick) { TEST_F(ReloadButtonTest, ResetOnClick) {
...@@ -137,14 +137,14 @@ TEST_F(ReloadButtonTest, ResetOnClick) { ...@@ -137,14 +137,14 @@ TEST_F(ReloadButtonTest, ResetOnClick) {
ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
reload()->ButtonPressed(reload(), e); reload()->ButtonPressed(reload(), e);
reload()->ChangeMode(ReloadButton::MODE_STOP, false); reload()->ChangeMode(ReloadButton::Mode::kStop, false);
set_mouse_hovered(true); set_mouse_hovered(true);
// Press the button. This should change back to reload despite the hover, // Press the button. This should change back to reload despite the hover,
// because it's a direct user action. // because it's a direct user action.
reload()->ButtonPressed(reload(), e); reload()->ButtonPressed(reload(), e);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, CheckState(true, ReloadButton::Mode::kReload, ReloadButton::Mode::kReload,
false); false, false);
} }
TEST_F(ReloadButtonTest, ResetOnTimer) { TEST_F(ReloadButtonTest, ResetOnTimer) {
...@@ -152,12 +152,12 @@ TEST_F(ReloadButtonTest, ResetOnTimer) { ...@@ -152,12 +152,12 @@ TEST_F(ReloadButtonTest, ResetOnTimer) {
ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
reload()->ButtonPressed(reload(), e); reload()->ButtonPressed(reload(), e);
reload()->ChangeMode(ReloadButton::MODE_STOP, false); reload()->ChangeMode(ReloadButton::Mode::kStop, false);
set_mouse_hovered(true); set_mouse_hovered(true);
reload()->ChangeMode(ReloadButton::MODE_RELOAD, false); reload()->ChangeMode(ReloadButton::Mode::kReload, false);
// Now fire the stop-to-reload timer. This should reset the button. // Now fire the stop-to-reload timer. This should reset the button.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, CheckState(true, ReloadButton::Mode::kReload, ReloadButton::Mode::kReload,
false); false, false);
} }
...@@ -29,9 +29,6 @@ ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews( ...@@ -29,9 +29,6 @@ ToolbarActionsBarBubbleViews::ToolbarActionsBarBubbleViews(
: views::BubbleDialogDelegateView(anchor_view, : views::BubbleDialogDelegateView(anchor_view,
views::BubbleBorder::TOP_RIGHT), views::BubbleBorder::TOP_RIGHT),
delegate_(std::move(delegate)), delegate_(std::move(delegate)),
delegate_notified_of_close_(false),
item_list_(nullptr),
link_(nullptr),
anchored_to_action_(anchored_to_action) { anchored_to_action_(anchored_to_action) {
set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate()); set_close_on_deactivate(delegate_->ShouldCloseOnDeactivate());
if (!anchor_view) if (!anchor_view)
...@@ -62,7 +59,7 @@ views::View* ToolbarActionsBarBubbleViews::CreateExtraView() { ...@@ -62,7 +59,7 @@ views::View* ToolbarActionsBarBubbleViews::CreateExtraView() {
std::unique_ptr<views::ImageView> icon; std::unique_ptr<views::ImageView> icon;
if (extra_view_info->resource) { if (extra_view_info->resource) {
icon.reset(new views::ImageView); icon = std::make_unique<views::ImageView>();
icon->SetImage(gfx::CreateVectorIcon(*extra_view_info->resource, kIconSize, icon->SetImage(gfx::CreateVectorIcon(*extra_view_info->resource, kIconSize,
gfx::kChromeIconGrey)); gfx::kChromeIconGrey));
} }
...@@ -75,7 +72,7 @@ views::View* ToolbarActionsBarBubbleViews::CreateExtraView() { ...@@ -75,7 +72,7 @@ views::View* ToolbarActionsBarBubbleViews::CreateExtraView() {
link_->set_listener(this); link_->set_listener(this);
label.reset(link_); label.reset(link_);
} else { } else {
label.reset(new views::Label(text)); label = std::make_unique<views::Label>(text);
} }
} }
......
...@@ -55,9 +55,9 @@ class ToolbarActionsBarBubbleViews : public views::BubbleDialogDelegateView, ...@@ -55,9 +55,9 @@ class ToolbarActionsBarBubbleViews : public views::BubbleDialogDelegateView,
void LinkClicked(views::Link* source, int event_flags) override; void LinkClicked(views::Link* source, int event_flags) override;
std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate_; std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate_;
bool delegate_notified_of_close_; bool delegate_notified_of_close_ = false;
views::Label* item_list_; views::Label* item_list_ = nullptr;
views::Link* link_; views::Link* link_ = nullptr;
const bool anchored_to_action_; const bool anchored_to_action_;
DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarBubbleViews); DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarBubbleViews);
......
...@@ -26,12 +26,10 @@ ...@@ -26,12 +26,10 @@
ToolbarButton::ToolbarButton(Profile* profile, ToolbarButton::ToolbarButton(Profile* profile,
views::ButtonListener* listener, views::ButtonListener* listener,
ui::MenuModel* model) std::unique_ptr<ui::MenuModel> model)
: views::ImageButton(listener), : views::ImageButton(listener),
profile_(profile), profile_(profile),
model_(model), model_(std::move(model)),
menu_showing_(false),
y_position_on_lbuttondown_(0),
show_menu_factory_(this) { show_menu_factory_(this) {
set_has_ink_drop_action_on_click(true); set_has_ink_drop_action_on_click(true);
set_context_menu_controller(this); set_context_menu_controller(this);
......
...@@ -36,11 +36,11 @@ class ToolbarButton : public views::ImageButton, ...@@ -36,11 +36,11 @@ class ToolbarButton : public views::ImageButton,
// Padding inside the border (around the image). // Padding inside the border (around the image).
static constexpr int kInteriorPadding = 6; static constexpr int kInteriorPadding = 6;
// Takes ownership of the |model|, which can be null if no menu // The profile and listener pointers must outlive this class. The model can
// is to be shown. // be null if no menu is to be shown.
ToolbarButton(Profile* profile, ToolbarButton(Profile* profile,
views::ButtonListener* listener, views::ButtonListener* listener,
ui::MenuModel* model); std::unique_ptr<ui::MenuModel> model);
~ToolbarButton() override; ~ToolbarButton() override;
// Set up basic mouseover border behavior. // Set up basic mouseover border behavior.
...@@ -93,10 +93,10 @@ class ToolbarButton : public views::ImageButton, ...@@ -93,10 +93,10 @@ class ToolbarButton : public views::ImageButton,
std::unique_ptr<ui::MenuModel> model_; std::unique_ptr<ui::MenuModel> model_;
// Indicates if menu is currently showing. // Indicates if menu is currently showing.
bool menu_showing_; bool menu_showing_ = false;
// Y position of mouse when left mouse button is pressed. // Y position of mouse when left mouse button is pressed.
int y_position_on_lbuttondown_; int y_position_on_lbuttondown_ = 0;
// The model adapter for the drop down menu. // The model adapter for the drop down menu.
std::unique_ptr<views::MenuModelAdapter> menu_model_adapter_; std::unique_ptr<views::MenuModelAdapter> menu_model_adapter_;
......
...@@ -36,9 +36,9 @@ class ToolbarButtonUITest : public ViewEventTestBase { ...@@ -36,9 +36,9 @@ class ToolbarButtonUITest : public ViewEventTestBase {
// Usually a BackForwardMenuModel is used, but that needs a Browser*. Make // Usually a BackForwardMenuModel is used, but that needs a Browser*. Make
// something simple with at least one item so a menu gets shown. Note that // something simple with at least one item so a menu gets shown. Note that
// ToolbarButton takes ownership of the |model|. // ToolbarButton takes ownership of the |model|.
ui::SimpleMenuModel* model = new ui::SimpleMenuModel(nullptr); auto model = std::make_unique<ui::SimpleMenuModel>(nullptr);
model->AddItem(0, base::string16()); model->AddItem(0, base::string16());
button_ = new ToolbarButton(&profile_, nullptr, model); button_ = new ToolbarButton(&profile_, nullptr, std::move(model));
return button_; return button_;
} }
void DoTestOnMessageLoop() override {} void DoTestOnMessageLoop() override {}
......
...@@ -102,14 +102,7 @@ const char ToolbarView::kViewClassName[] = "ToolbarView"; ...@@ -102,14 +102,7 @@ const char ToolbarView::kViewClassName[] = "ToolbarView";
// ToolbarView, public: // ToolbarView, public:
ToolbarView::ToolbarView(Browser* browser) ToolbarView::ToolbarView(Browser* browser)
: back_(nullptr), : browser_(browser),
forward_(nullptr),
reload_(nullptr),
home_(nullptr),
location_bar_(nullptr),
browser_actions_(nullptr),
app_menu_button_(nullptr),
browser_(browser),
app_menu_icon_controller_(browser->profile(), this), app_menu_icon_controller_(browser->profile(), this),
display_mode_(browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) display_mode_(browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)
? DISPLAYMODE_NORMAL ? DISPLAYMODE_NORMAL
...@@ -147,7 +140,8 @@ void ToolbarView::Init() { ...@@ -147,7 +140,8 @@ void ToolbarView::Init() {
back_ = new ToolbarButton( back_ = new ToolbarButton(
browser_->profile(), this, browser_->profile(), this,
new BackForwardMenuModel(browser_, BackForwardMenuModel::BACKWARD_MENU)); std::make_unique<BackForwardMenuModel>(
browser_, BackForwardMenuModel::ModelType::kBackward));
back_->set_hide_ink_drop_when_showing_context_menu(false); back_->set_hide_ink_drop_when_showing_context_menu(false);
back_->set_triggerable_event_flags( back_->set_triggerable_event_flags(
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
...@@ -159,7 +153,8 @@ void ToolbarView::Init() { ...@@ -159,7 +153,8 @@ void ToolbarView::Init() {
forward_ = new ToolbarButton( forward_ = new ToolbarButton(
browser_->profile(), this, browser_->profile(), this,
new BackForwardMenuModel(browser_, BackForwardMenuModel::FORWARD_MENU)); std::make_unique<BackForwardMenuModel>(
browser_, BackForwardMenuModel::ModelType::kForward));
forward_->set_hide_ink_drop_when_showing_context_menu(false); forward_->set_hide_ink_drop_when_showing_context_menu(false);
forward_->set_triggerable_event_flags( forward_->set_triggerable_event_flags(
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
...@@ -189,7 +184,7 @@ void ToolbarView::Init() { ...@@ -189,7 +184,7 @@ void ToolbarView::Init() {
browser_actions_ = new BrowserActionsContainer( browser_actions_ = new BrowserActionsContainer(
browser_, browser_,
NULL); // No master container for this one (it is master). nullptr); // No master container for this one (it is master).
app_menu_button_ = new AppMenuButton(this); app_menu_button_ = new AppMenuButton(this);
app_menu_button_->EnableCanvasFlippingForRTLUI(true); app_menu_button_->EnableCanvasFlippingForRTLUI(true);
...@@ -388,7 +383,7 @@ ToolbarView::GetContentSettingBubbleModelDelegate() { ...@@ -388,7 +383,7 @@ ToolbarView::GetContentSettingBubbleModelDelegate() {
// ToolbarView, CommandObserver implementation: // ToolbarView, CommandObserver implementation:
void ToolbarView::EnabledStateChangedForCommand(int id, bool enabled) { void ToolbarView::EnabledStateChangedForCommand(int id, bool enabled) {
views::Button* button = NULL; views::Button* button = nullptr;
switch (id) { switch (id) {
case IDC_BACK: case IDC_BACK:
button = back_; button = back_;
......
...@@ -193,14 +193,15 @@ class ToolbarView : public views::AccessiblePaneView, ...@@ -193,14 +193,15 @@ class ToolbarView : public views::AccessiblePaneView,
void OnShowHomeButtonChanged(); void OnShowHomeButtonChanged();
// Controls. Most of these can be null, e.g. in popup windows. Only // Controls. Most of these can be null, e.g. in popup windows. Only
// |location_bar_| is guaranteed to exist. // |location_bar_| is guaranteed to exist. These pointers are owned by the
ToolbarButton* back_; // view hierarchy.
ToolbarButton* forward_; ToolbarButton* back_ = nullptr;
ReloadButton* reload_; ToolbarButton* forward_ = nullptr;
HomeButton* home_; ReloadButton* reload_ = nullptr;
LocationBarView* location_bar_; HomeButton* home_ = nullptr;
BrowserActionsContainer* browser_actions_; LocationBarView* location_bar_ = nullptr;
AppMenuButton* app_menu_button_; BrowserActionsContainer* browser_actions_ = nullptr;
AppMenuButton* app_menu_button_ = nullptr;
Browser* const browser_; Browser* const browser_;
......
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