-
Notifications
You must be signed in to change notification settings - Fork 888
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Launched additional confirmation dialog to the end of support
fix brave/brave-browser#27649 When user closes infobar with checked state, additional dialog is launched to confirm user's choice again. Obsolete system infobar will not be shown again when user clicks OK. BraveConfirmDialog is introduced to support checkbox to upstream confirm dialog.
- Loading branch information
Showing
19 changed files
with
472 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_ | ||
#define BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_ | ||
|
||
#include <memory> | ||
|
||
class BraveConfirmInfoBarDelegate; | ||
|
||
namespace infobars { | ||
class InfoBar; | ||
} // namespace infobars | ||
|
||
std::unique_ptr<infobars::InfoBar> CreateBraveConfirmInfoBar( | ||
std::unique_ptr<BraveConfirmInfoBarDelegate> delegate); | ||
|
||
#endif // BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/ui/views/infobars/brave_confirm_infobar.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "base/bind.h" | ||
#include "ui/base/metadata/metadata_impl_macros.h" | ||
#include "ui/views/controls/button/checkbox.h" | ||
|
||
namespace { | ||
|
||
constexpr int kCheckboxSpacing = 20; | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<infobars::InfoBar> CreateBraveConfirmInfoBar( | ||
std::unique_ptr<BraveConfirmInfoBarDelegate> delegate) { | ||
return std::make_unique<BraveConfirmInfoBar>(std::move(delegate)); | ||
} | ||
|
||
BraveConfirmInfoBar::BraveConfirmInfoBar( | ||
std::unique_ptr<BraveConfirmInfoBarDelegate> delegate) | ||
: ConfirmInfoBar(std::move(delegate)) { | ||
auto* delegate_ptr = GetBraveDelegate(); | ||
DCHECK(delegate_ptr); | ||
|
||
if (delegate_ptr->HasCheckbox()) { | ||
// We don't consider case where ok/cancel button and check box exist | ||
// together. | ||
DCHECK(!ok_button_ && !cancel_button_); | ||
checkbox_ = AddChildView(std::make_unique<views::Checkbox>( | ||
delegate_ptr->GetCheckboxText(), | ||
base::BindRepeating(&BraveConfirmInfoBar::CheckboxPressed, | ||
base::Unretained(this)))); | ||
} | ||
} | ||
|
||
BraveConfirmInfoBar::~BraveConfirmInfoBar() = default; | ||
|
||
void BraveConfirmInfoBar::Layout() { | ||
ConfirmInfoBar::Layout(); | ||
|
||
// Early return when checkbox is not used. | ||
// This class is only valid when this infobar has checkbox now. | ||
// NOTE: Revisit when we want to use other buttons together with checkbox. | ||
if (!checkbox_) | ||
return; | ||
|
||
checkbox_->SizeToPreferredSize(); | ||
|
||
const int x = label_->bounds().right() + kCheckboxSpacing; | ||
checkbox_->SetPosition(gfx::Point(x, OffsetY(checkbox_))); | ||
} | ||
|
||
BraveConfirmInfoBarDelegate* BraveConfirmInfoBar::GetBraveDelegate() { | ||
return static_cast<BraveConfirmInfoBarDelegate*>( | ||
ConfirmInfoBar::GetDelegate()); | ||
} | ||
|
||
void BraveConfirmInfoBar::CheckboxPressed() { | ||
GetBraveDelegate()->SetCheckboxChecked(checkbox_->GetChecked()); | ||
} | ||
|
||
int BraveConfirmInfoBar::NonLabelWidth() const { | ||
const int width = ConfirmInfoBar::NonLabelWidth(); | ||
|
||
// Early return when checkbox is not used. | ||
// This class is only valid when this infobar has checkbox now. | ||
if (!checkbox_) | ||
return width; | ||
|
||
return width + checkbox_->width() + kCheckboxSpacing; | ||
} | ||
|
||
void BraveConfirmInfoBar::CloseButtonPressed() { | ||
if (GetBraveDelegate()->InterceptClosing()) | ||
return; | ||
|
||
ConfirmInfoBar::CloseButtonPressed(); | ||
} | ||
|
||
BEGIN_METADATA(BraveConfirmInfoBar, ConfirmInfoBar) | ||
END_METADATA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_CONFIRM_INFOBAR_H_ | ||
#define BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_CONFIRM_INFOBAR_H_ | ||
|
||
#include <memory> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "brave/components/infobars/core/brave_confirm_infobar_delegate.h" | ||
#include "chrome/browser/ui/views/infobars/confirm_infobar.h" | ||
#include "ui/base/metadata/metadata_header_macros.h" | ||
|
||
namespace views { | ||
class Checkbox; | ||
} // namespace views | ||
|
||
// Add checkbox to ConfirmInfoBar. | ||
// "Would you like to do X? [Checkbox] _Learn More_ [x]" | ||
class BraveConfirmInfoBar : public ConfirmInfoBar { | ||
public: | ||
METADATA_HEADER(BraveConfirmInfoBar); | ||
explicit BraveConfirmInfoBar( | ||
std::unique_ptr<BraveConfirmInfoBarDelegate> delegate); | ||
BraveConfirmInfoBar(const BraveConfirmInfoBar&) = delete; | ||
BraveConfirmInfoBar& operator=(const BraveConfirmInfoBar&) = delete; | ||
~BraveConfirmInfoBar() override; | ||
|
||
// ConfirmInfoBar overrides: | ||
void Layout() override; | ||
int NonLabelWidth() const override; | ||
void CloseButtonPressed() override; | ||
|
||
private: | ||
BraveConfirmInfoBarDelegate* GetBraveDelegate(); | ||
|
||
void CheckboxPressed(); | ||
|
||
raw_ptr<views::Checkbox> checkbox_ = nullptr; | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_CONFIRM_INFOBAR_H_ |
Oops, something went wrong.