Skip to content

Commit

Permalink
Added deps and refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulsnkr committed Jun 9, 2021
1 parent 649091e commit c5e9dd5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 46 deletions.
2 changes: 2 additions & 0 deletions browser/ui/views/infobars/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ source_set("brave_wayback_machine") {
"//brave/app:brave_generated_resources_grit",
"//brave/app/vector_icons",
"//brave/components/brave_wayback_machine",
"//components/prefs:prefs",
"//components/resources",
"//components/user_prefs",
"//content/public/browser",
"//ui/base",
"//ui/gfx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,12 @@ constexpr int kInsetOffsetsForThrobber = kThrobberDiameter;

BraveWaybackMachineInfoBarButtonContainer::
BraveWaybackMachineInfoBarButtonContainer(
ButtonID button_id,
views::Button::PressedCallback callback) {
std::unique_ptr<views::MdTextButton> button;
switch (button_id) {
case ButtonID::BUTTON_ID_FETCH_URL: {
button = std::make_unique<views::MdTextButton>(
std::move(callback),
l10n_util::GetStringUTF16(
IDS_BRAVE_WAYBACK_MACHINE_CHECK_BUTTON_TEXT));
button->SetProminent(true);
break;
}
case ButtonID::BUTTON_ID_DONT_ASK: {
button = std::make_unique<views::MdTextButton>(
std::move(callback),
l10n_util::GetStringUTF16(
IDS_BRAVE_WAYBACK_MACHINE_DONT_ASK_AGAIN_TEXT));
break;
}
}
auto button = std::make_unique<views::MdTextButton>(
std::move(callback),
l10n_util::GetStringUTF16(IDS_BRAVE_WAYBACK_MACHINE_CHECK_BUTTON_TEXT));
button_ = button.get();
button->SetProminent(true);
button->SizeToPreferredSize();
AddChildView(button.release());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class BraveWaybackMachineInfoBarThrobber;
// on that area.
class BraveWaybackMachineInfoBarButtonContainer : public views::View {
public:
enum class ButtonID { BUTTON_ID_FETCH_URL, BUTTON_ID_DONT_ASK };
explicit BraveWaybackMachineInfoBarButtonContainer(
ButtonID button_id,
views::Button::PressedCallback callback);
~BraveWaybackMachineInfoBarButtonContainer() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void BraveWaybackMachineInfoBarContentsView::OnWaybackURLFetched(
DCHECK(wayback_url_fetch_requested_);
wayback_url_fetch_requested_ = false;

fetch_url_button->StopThrobber();
fetch_url_button_->StopThrobber();
Layout();

if (latest_wayback_url.is_empty()) {
Expand Down Expand Up @@ -119,7 +119,7 @@ void BraveWaybackMachineInfoBarContentsView::FetchURLButtonPressed() {
if (wayback_url_fetch_requested_)
return;
wayback_url_fetch_requested_ = true;
dont_ask_button->SetVisible(false);
dont_ask_button_->SetVisible(false);
FetchWaybackURL();
}

Expand Down Expand Up @@ -186,54 +186,54 @@ void BraveWaybackMachineInfoBarContentsView::InitializeChildren() {
0));
AddChildView(label);

dont_ask_button = new BraveWaybackMachineInfoBarButtonContainer(
BraveWaybackMachineInfoBarButtonContainer::ButtonID::BUTTON_ID_DONT_ASK,
auto dont_ask_button = std::make_unique<views::MdTextButton>(
base::BindRepeating(
&BraveWaybackMachineInfoBarContentsView::DontAskButtonPressed,
base::Unretained(this)));
views_visible_before_checking_.push_back(dont_ask_button);
base::Unretained(this)),
l10n_util::GetStringUTF16(IDS_BRAVE_WAYBACK_MACHINE_DONT_ASK_AGAIN_TEXT));
dont_ask_button_ = dont_ask_button.get();
views_visible_before_checking_.push_back(dont_ask_button_);

fetch_url_button = new BraveWaybackMachineInfoBarButtonContainer(
BraveWaybackMachineInfoBarButtonContainer::ButtonID::BUTTON_ID_FETCH_URL,
base::BindRepeating(
fetch_url_button_ =
new BraveWaybackMachineInfoBarButtonContainer(base::BindRepeating(
&BraveWaybackMachineInfoBarContentsView::FetchURLButtonPressed,
base::Unretained(this)));
views_visible_before_checking_.push_back(fetch_url_button);
views_visible_before_checking_.push_back(fetch_url_button_);

if (views::PlatformStyle::kIsOkButtonLeading) {
fetch_url_button->SetProperty(
fetch_url_button_->SetProperty(
views::kMarginsKey,
gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_TOAST_CONTROL_VERTICAL),
ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_RELATED_CONTROL_HORIZONTAL_SMALL)));
fetch_url_button->SizeToPreferredSize();
AddChildView(fetch_url_button);
fetch_url_button_->SizeToPreferredSize();
AddChildView(fetch_url_button_);

dont_ask_button->SetProperty(
dont_ask_button_->SetProperty(
views::kMarginsKey,
gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_TOAST_CONTROL_VERTICAL),
0));
dont_ask_button->SizeToPreferredSize();
AddChildView(dont_ask_button);
dont_ask_button_->SizeToPreferredSize();
AddChildView(dont_ask_button.release());
} else {
dont_ask_button->SetProperty(
dont_ask_button_->SetProperty(
views::kMarginsKey,
gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_TOAST_CONTROL_VERTICAL),
ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_RELATED_CONTROL_HORIZONTAL_SMALL)));
dont_ask_button->SizeToPreferredSize();
AddChildView(dont_ask_button);
dont_ask_button_->SizeToPreferredSize();
AddChildView(dont_ask_button.release());

fetch_url_button->SetProperty(
fetch_url_button_->SetProperty(
views::kMarginsKey,
gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_TOAST_CONTROL_VERTICAL),
0));
fetch_url_button->SizeToPreferredSize();
AddChildView(fetch_url_button);
fetch_url_button_->SizeToPreferredSize();
AddChildView(fetch_url_button_);
}

UpdateChildrenVisibility(true);
Expand Down Expand Up @@ -265,7 +265,7 @@ SkColor BraveWaybackMachineInfoBarContentsView::GetColor(int id) const {
}

void BraveWaybackMachineInfoBarContentsView::FetchWaybackURL() {
fetch_url_button->StartThrobber();
fetch_url_button_->StartThrobber();
wayback_machine_url_fetcher_.Fetch(contents_->GetVisibleURL());
Layout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class BraveWaybackMachineInfoBarContentsView
content::WebContents* contents_;
WaybackMachineURLFetcher wayback_machine_url_fetcher_;

BraveWaybackMachineInfoBarButtonContainer* fetch_url_button = nullptr;
BraveWaybackMachineInfoBarButtonContainer* dont_ask_button = nullptr;
BraveWaybackMachineInfoBarButtonContainer* fetch_url_button_ = nullptr;
views::View* dont_ask_button_ = nullptr;
PrefService* pref_service_ = nullptr;
views::ImageView* wayback_spot_graphic_ = nullptr;
bool wayback_url_fetch_requested_ = false;
Expand Down

0 comments on commit c5e9dd5

Please sign in to comment.